You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
277 lines
9.9 KiB
C#
277 lines
9.9 KiB
C#
using System;
|
|
using System.Text;
|
|
using System.Data.SqlClient;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using DSWeb.Models;
|
|
using DSWeb.DataAccess;
|
|
using System.Configuration;
|
|
using System.Collections;
|
|
|
|
namespace DSWeb.EntityDA
|
|
{
|
|
public class CodeStlmodeSetDA
|
|
{
|
|
/// <summary>
|
|
/// 增加一条数据
|
|
/// </summary>
|
|
public int Add(CodeStlmodeSetEntity model)
|
|
{
|
|
StringBuilder strSql = new StringBuilder();
|
|
strSql.Append("insert into code_stlmode(");
|
|
strSql.Append("GID,STLCODE,STLNAME,FINANCESOFTCODE");
|
|
strSql.Append(") values (");
|
|
strSql.Append("@GID,@STLCODE,@STLNAME,@FINANCESOFTCODE");
|
|
strSql.Append(") ");
|
|
|
|
SqlParameter[] parameters = {
|
|
new SqlParameter("@GID", SqlDbType.VarChar,36) ,
|
|
new SqlParameter("@STLCODE", SqlDbType.VarChar,10) ,
|
|
new SqlParameter("@STLNAME", SqlDbType.VarChar,30) ,
|
|
new SqlParameter("@FINANCESOFTCODE", SqlDbType.VarChar,20)
|
|
};
|
|
|
|
parameters[0].Value = model.GID;
|
|
parameters[1].Value = model.STLCODE;
|
|
parameters[2].Value = model.STLNAME;
|
|
parameters[3].Value = model.FINANCESOFTCODE;
|
|
|
|
//
|
|
int iResult = 0;
|
|
using (SqlConnection conn = new SqlConnection(SqlHelper.ConnectionStringLocalTransaction))
|
|
{
|
|
int existVal = SqlHelper.ExecuteNonQuery(conn, CommandType.Text, strSql.ToString(), parameters);
|
|
if (existVal > 0)
|
|
{
|
|
iResult = 1;
|
|
//
|
|
//string str0 = "insert into sys_log(NAME,LOGTYPE,LOGCONTENT,CREATEUSER) values('增加信息','增加操作','GID=" + model.GID.ToString() + "','" + model.MODIFIEDUSER.ToString() + "')";
|
|
//bool bl0 = SqlHelper.ExecuteSqlCommand(SqlHelper.ConnectionStringLocalTransaction, str0);
|
|
}
|
|
else
|
|
{
|
|
iResult = -1;//执行异常
|
|
}
|
|
}
|
|
return iResult;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 更新一条数据
|
|
/// </summary>
|
|
public int Update(CodeStlmodeSetEntity model)
|
|
{
|
|
StringBuilder strSql = new StringBuilder();
|
|
strSql.Append("update code_stlmode set ");
|
|
|
|
strSql.Append(" GID = @GID , ");
|
|
strSql.Append(" STLCODE = @STLCODE , ");
|
|
strSql.Append(" STLNAME = @STLNAME , ");
|
|
strSql.Append(" FINANCESOFTCODE = @FINANCESOFTCODE ");
|
|
strSql.Append(" where GID=@GID ");
|
|
|
|
SqlParameter[] parameters = {
|
|
new SqlParameter("@GID", SqlDbType.VarChar,36) ,
|
|
new SqlParameter("@STLCODE", SqlDbType.VarChar,10) ,
|
|
new SqlParameter("@STLNAME", SqlDbType.VarChar,30) ,
|
|
new SqlParameter("@FINANCESOFTCODE", SqlDbType.VarChar,20)
|
|
|
|
};
|
|
|
|
parameters[0].Value = model.GID;
|
|
parameters[1].Value = model.STLCODE;
|
|
parameters[2].Value = model.STLNAME;
|
|
parameters[3].Value = model.FINANCESOFTCODE;
|
|
//
|
|
int iResult = 0;
|
|
using (SqlConnection conn = new SqlConnection(SqlHelper.ConnectionStringLocalTransaction))
|
|
{
|
|
int existVal = SqlHelper.ExecuteNonQuery(conn, CommandType.Text, strSql.ToString(), parameters);
|
|
if (existVal > 0)
|
|
{
|
|
iResult = 1;
|
|
//
|
|
//string str0 = "insert into sys_log(NAME,LOGTYPE,LOGCONTENT,CREATEUSER) values('更新信息表','更新操作','GID=" + model.GID.ToString() + "','" + model.MODIFIEDUSER.ToString() + "')";
|
|
//bool bl0 = SqlHelper.ExecuteSqlCommand(SqlHelper.ConnectionStringLocalTransaction, str0);
|
|
}
|
|
else
|
|
{
|
|
iResult = -1;//执行异常
|
|
}
|
|
}
|
|
return iResult;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 删除一条数据
|
|
/// </summary>
|
|
public int Delete(string GID)
|
|
{
|
|
|
|
StringBuilder strSql = new StringBuilder();
|
|
strSql.Append("delete from code_stlmode ");
|
|
strSql.Append(" where GID=@GID ");
|
|
SqlParameter[] parameters = {
|
|
new SqlParameter("@GID", SqlDbType.VarChar,36) };
|
|
parameters[0].Value = GID;
|
|
|
|
|
|
//
|
|
int iResult = 0;
|
|
using (SqlTransaction sqlTran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction))
|
|
{
|
|
try
|
|
{
|
|
SqlHelper.ExecuteNonQuery(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, strSql.ToString(), parameters);
|
|
iResult = 1;//状态为1表示删除成功
|
|
sqlTran.Commit();
|
|
}
|
|
catch (Exception execError)
|
|
{
|
|
iResult = -1;//有异常,删除失败
|
|
sqlTran.Rollback();
|
|
iResult = -2;//插入异常,事务已回滚成功
|
|
throw execError;
|
|
}
|
|
finally
|
|
{
|
|
SqlHelper.CloseConnection();
|
|
}
|
|
}
|
|
return iResult;
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// 得到一个对象实体
|
|
/// </summary>
|
|
public CodeStlmodeSetEntity GetModel(string strGID)
|
|
{
|
|
StringBuilder strSql = new StringBuilder();
|
|
strSql.Append("select GID, STLCODE, STLNAME, FINANCESOFTCODE ");
|
|
strSql.Append(" from code_stlmode ");
|
|
strSql.Append(" where GID='" + strGID + "' ");
|
|
|
|
CodeStlmodeSetEntity model = new CodeStlmodeSetEntity();
|
|
DataSet ds = SqlHelper.OpenSqlDataSet(SqlHelper.ConnectionStringLocalTransaction, strSql.ToString());
|
|
|
|
if (ds.Tables[0].Rows.Count > 0)
|
|
{
|
|
model.GID = ds.Tables[0].Rows[0]["GID"].ToString();
|
|
model.STLCODE = ds.Tables[0].Rows[0]["STLCODE"].ToString();
|
|
model.STLNAME = ds.Tables[0].Rows[0]["STLNAME"].ToString();
|
|
model.FINANCESOFTCODE = ds.Tables[0].Rows[0]["FINANCESOFTCODE"].ToString();
|
|
return model;
|
|
}
|
|
else
|
|
{
|
|
return null;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获得数据列表
|
|
/// </summary>
|
|
public DataSet GetList(string strWhere)
|
|
{
|
|
StringBuilder strSql = new StringBuilder();
|
|
strSql.Append("select * ");
|
|
strSql.Append(" FROM code_stlmode ");
|
|
if (strWhere.Trim() != "")
|
|
{
|
|
strSql.Append(" where " + strWhere);
|
|
}
|
|
//
|
|
DataSet DS = SqlHelper.OpenSqlDataSet(SqlHelper.ConnectionStringLocalTransaction, strSql.ToString());
|
|
try
|
|
{
|
|
if (DS.Tables[0].Rows.Count <= 0)
|
|
{
|
|
DS = null;
|
|
}
|
|
}
|
|
catch
|
|
{
|
|
DS = null;
|
|
}
|
|
return DS;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获得某GID数据列表
|
|
/// </summary>
|
|
public DataSet GetSQL(string strSQL)
|
|
{
|
|
DataSet DS = SqlHelper.OpenSqlDataSet(SqlHelper.ConnectionStringLocalTransaction, strSQL);
|
|
try
|
|
{
|
|
if (DS.Tables[0].Rows.Count <= 0)
|
|
{
|
|
DS = null;
|
|
}
|
|
}
|
|
catch
|
|
{
|
|
DS = null;
|
|
}
|
|
return DS;
|
|
}
|
|
|
|
#region 更新账户列表信息
|
|
/// <summary>
|
|
/// 更新账户列表信息
|
|
/// </summary>
|
|
/// <param name="sqlList">更新SQL语句组,将所有要执行的更新语句写入ArrayList,每个索引对应一条SQL语句,执行时需要遍历操作</param>
|
|
/// <returns>返回状态值 为1表示更新完成;为-1更新出现异常但未正确回滚事务;为-2更新异常,事务已经成功回滚;默认状态为0</returns>
|
|
public int UpdateCodeStlmodeSetFromGrid(ArrayList sqlList)
|
|
{
|
|
int result = 0;
|
|
using (SqlTransaction sqlTran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction))
|
|
{
|
|
try
|
|
{
|
|
for (int i = 0; i < sqlList.Count; i++)
|
|
{
|
|
string strUpdateSql = sqlList[i].ToString();
|
|
SqlHelper.ExecuteNonQuery(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, strUpdateSql, null);
|
|
}
|
|
|
|
sqlTran.Commit();
|
|
result = 1;//状态为1表示更新成功
|
|
}
|
|
catch (Exception execError)
|
|
{
|
|
result = -1;//有异常,更新失败
|
|
sqlTran.Rollback();
|
|
result = -2;//更新异常,事务已回滚成功
|
|
throw execError;
|
|
}
|
|
finally
|
|
{
|
|
SqlHelper.CloseConnection();
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
#endregion
|
|
|
|
#region 根据SQL语句查询费用数据集
|
|
/// <summary>
|
|
/// 根据SQL语句查询费用数据集
|
|
/// </summary>
|
|
/// <param name="strSql"></param>
|
|
/// <returns></returns>
|
|
public DataSet GetExcuteSql(string strSql)
|
|
{
|
|
DataSet userSet = new DataSet();
|
|
userSet = SqlHelper.ExecuteDataset(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, strSql);
|
|
return userSet;
|
|
}
|
|
#endregion
|
|
//
|
|
}
|
|
}
|