using System; using System.Text; using System.Data.SqlClient; using System.Collections; using System.Collections.Generic; using System.Data; using DSWeb.Models; using DSWeb.DataAccess; namespace DSWeb.EntityDA { public class CwAccitemsSetDA { /// /// 增加一条数据 /// public int Add(ATCwAccitemsSetEntity model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into cw_accitems("); strSql.Append("GID,ISITEMACC,REMARKS,ACCID,ACCNAME,DETAILED,DC,ISFCY,ISDEPTACC,ISEMPLACC,ISCORPACC"); strSql.Append(") values ("); strSql.Append("@GID,@ISITEMACC,@REMARKS,@ACCID,@ACCNAME,@DETAILED,@DC,@ISFCY,@ISDEPTACC,@ISEMPLACC,@ISCORPACC"); strSql.Append(") "); SqlParameter[] parameters = { new SqlParameter("@GID", SqlDbType.VarChar,36) , new SqlParameter("@ISITEMACC", SqlDbType.Bit,1) , new SqlParameter("@REMARKS", SqlDbType.VarChar,200) , new SqlParameter("@ACCID", SqlDbType.VarChar,16) , new SqlParameter("@ACCNAME", SqlDbType.VarChar,60) , new SqlParameter("@DETAILED", SqlDbType.Bit,1) , new SqlParameter("@DC", SqlDbType.VarChar,10) , new SqlParameter("@ISFCY", SqlDbType.Bit,1) , new SqlParameter("@ISDEPTACC", SqlDbType.Bit,1) , new SqlParameter("@ISEMPLACC", SqlDbType.Bit,1) , new SqlParameter("@ISCORPACC", SqlDbType.Bit,1) }; parameters[0].Value = model.GID; parameters[1].Value = model.ISITEMACC; parameters[2].Value = model.REMARKS; parameters[3].Value = model.ACCID; parameters[4].Value = model.ACCNAME; parameters[5].Value = model.DETAILED; parameters[6].Value = model.DC; parameters[7].Value = model.ISFCY; parameters[8].Value = model.ISDEPTACC; parameters[9].Value = model.ISEMPLACC; parameters[10].Value = model.ISCORPACC; // 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; } /// /// 更新一条数据 /// public int Update(ATCwAccitemsSetEntity model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update cw_accitems set "); strSql.Append(" GID = @GID , "); strSql.Append(" ISITEMACC = @ISITEMACC , "); strSql.Append(" REMARKS = @REMARKS , "); strSql.Append(" ACCID = @ACCID , "); strSql.Append(" ACCNAME = @ACCNAME , "); strSql.Append(" DETAILED = @DETAILED , "); strSql.Append(" DC = @DC , "); strSql.Append(" ISFCY = @ISFCY , "); strSql.Append(" ISDEPTACC = @ISDEPTACC , "); strSql.Append(" ISEMPLACC = @ISEMPLACC , "); strSql.Append(" ISCORPACC = @ISCORPACC "); strSql.Append(" where GID=@GID "); SqlParameter[] parameters = { new SqlParameter("@GID", SqlDbType.VarChar,36) , new SqlParameter("@ISITEMACC", SqlDbType.Bit,1) , new SqlParameter("@REMARKS", SqlDbType.VarChar,200) , new SqlParameter("@ACCID", SqlDbType.VarChar,16) , new SqlParameter("@ACCNAME", SqlDbType.VarChar,60) , new SqlParameter("@DETAILED", SqlDbType.Bit,1) , new SqlParameter("@DC", SqlDbType.VarChar,10) , new SqlParameter("@ISFCY", SqlDbType.Bit,1) , new SqlParameter("@ISDEPTACC", SqlDbType.Bit,1) , new SqlParameter("@ISEMPLACC", SqlDbType.Bit,1) , new SqlParameter("@ISCORPACC", SqlDbType.Bit,1) }; parameters[0].Value = model.GID; parameters[1].Value = model.ISITEMACC; parameters[2].Value = model.REMARKS; parameters[3].Value = model.ACCID; parameters[4].Value = model.ACCNAME; parameters[5].Value = model.DETAILED; parameters[6].Value = model.DC; parameters[7].Value = model.ISFCY; parameters[8].Value = model.ISDEPTACC; parameters[9].Value = model.ISEMPLACC; parameters[10].Value = model.ISCORPACC; // 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; } /// /// 删除一条数据 /// public int Delete(string GID) { StringBuilder strSql = new StringBuilder(); strSql.Append("delete from cw_accitems "); 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; } /// /// 得到一个对象实体 /// public ATCwAccitemsSetEntity GetModel(string strGID) { StringBuilder strSql = new StringBuilder(); strSql.Append("select GID, ISITEMACC, REMARKS, ACCID, ACCNAME, DETAILED, DC, ISFCY, ISDEPTACC, ISEMPLACC, ISCORPACC "); strSql.Append(" from cw_accitems "); strSql.Append(" where GID='" + strGID + "' "); ATCwAccitemsSetEntity model = new ATCwAccitemsSetEntity(); DataSet ds = SqlHelper.OpenSqlDataSet(SqlHelper.ConnectionStringLocalTransaction, strSql.ToString()); if (ds.Tables[0].Rows.Count > 0) { model.GID = ds.Tables[0].Rows[0]["GID"].ToString(); if (ds.Tables[0].Rows[0]["ISITEMACC"].ToString() != "") { if ((ds.Tables[0].Rows[0]["ISITEMACC"].ToString() == "1") || (ds.Tables[0].Rows[0]["ISITEMACC"].ToString().ToLower() == "true")) { model.ISITEMACC = true; } else { model.ISITEMACC = false; } } model.REMARKS = ds.Tables[0].Rows[0]["REMARKS"].ToString(); model.ACCID = ds.Tables[0].Rows[0]["ACCID"].ToString(); model.ACCNAME = ds.Tables[0].Rows[0]["ACCNAME"].ToString(); if (ds.Tables[0].Rows[0]["DETAILED"].ToString() != "") { if ((ds.Tables[0].Rows[0]["DETAILED"].ToString() == "1") || (ds.Tables[0].Rows[0]["DETAILED"].ToString().ToLower() == "true")) { model.DETAILED = true; } else { model.DETAILED = false; } } model.DC = ds.Tables[0].Rows[0]["DC"].ToString(); if (ds.Tables[0].Rows[0]["ISFCY"].ToString() != "") { if ((ds.Tables[0].Rows[0]["ISFCY"].ToString() == "1") || (ds.Tables[0].Rows[0]["ISFCY"].ToString().ToLower() == "true")) { model.ISFCY = true; } else { model.ISFCY = false; } } if (ds.Tables[0].Rows[0]["ISDEPTACC"].ToString() != "") { if ((ds.Tables[0].Rows[0]["ISDEPTACC"].ToString() == "1") || (ds.Tables[0].Rows[0]["ISDEPTACC"].ToString().ToLower() == "true")) { model.ISDEPTACC = true; } else { model.ISDEPTACC = false; } } if (ds.Tables[0].Rows[0]["ISEMPLACC"].ToString() != "") { if ((ds.Tables[0].Rows[0]["ISEMPLACC"].ToString() == "1") || (ds.Tables[0].Rows[0]["ISEMPLACC"].ToString().ToLower() == "true")) { model.ISEMPLACC = true; } else { model.ISEMPLACC = false; } } if (ds.Tables[0].Rows[0]["ISCORPACC"].ToString() != "") { if ((ds.Tables[0].Rows[0]["ISCORPACC"].ToString() == "1") || (ds.Tables[0].Rows[0]["ISCORPACC"].ToString().ToLower() == "true")) { model.ISCORPACC = true; } else { model.ISCORPACC = false; } } return model; } else { return null; } } /// /// 获得数据列表 /// public DataSet GetList(string strWhere) { StringBuilder strSql = new StringBuilder(); strSql.Append("select * "); strSql.Append(" FROM cw_accitems "); 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; } /// /// 获得某GID数据列表 /// 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 获取SQL语句查询数据集 /// /// 获取SQL语句查询数据集 /// /// /// public DataSet GetExcuteSql(string strSql) { DataSet tempSet = new DataSet(); tempSet = SqlHelper.ExecuteDataset(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, strSql); return tempSet; } #endregion #region 更新账户列表信息 /// /// 更新账户列表信息 /// /// 更新SQL语句组,将所有要执行的更新语句写入ArrayList,每个索引对应一条SQL语句,执行时需要遍历操作 /// 返回状态值 为1表示更新完成;为-1更新出现异常但未正确回滚事务;为-2更新异常,事务已经成功回滚;默认状态为0 public int UpdateATCwAccitemsSetFromGrid(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 } }