using System; using System.Data; using System.Configuration; using System.Data.SqlClient; using System.Text; using System.Collections; using System.Collections.Generic; using DSWeb.Models; using DSWeb.DataAccess; namespace DSWeb.EntityDA { public class OpStatusListDA { private const string PARM_OpStatusList_GID = "@ST_ID"; private const string SQL_SELECT_OpStatusList_ALL = " SELECT ST_ID,BSNO,STATUS,ISCOMP,COMPTIME,COMPOP,REMARK,INPUTBY,ORDNO,STATUS_OPSEAE FROM op_status order by STATUS"; private const string SQL_SELECT_OpStatusList_BYGID = " SELECT ST_ID,BSNO,STATUS,ISCOMP,COMPTIME,COMPOP,REMARK,INPUTBY,ORDNO,STATUS_OPSEAE FROM op_status WHERE ST_ID = @ST_ID"; private const string SQL_SELECT_OpStatusList_TOP1 = " SELECT top 1 ST_ID,BSNO,STATUS,ISCOMP,COMPTIME,COMPOP,REMARK,INPUTBY,ORDNO,STATUS_OPSEAE FROM op_status order by STATUS"; private string strSqlInsertInfo = "insert into [op_status](ST_ID,BSNO,STATUS,{0}COMPOP,REMARK,INPUTBY) values(@ST_ID,@BSNO,@STATUS,{1}@COMPOP,@REMARK,@INPUTBY)"; private string strSqlUpdateInfo = "update [op_status] set STATUS=@STATUS,{0}COMPOP=@COMPOP,REMARK=@REMARK where ST_ID=@ST_ID and BSNO=@BSNO"; private const string SQL_DELETE_OpStatusList_BY_GID = "DELETE FROM op_status WHERE ST_ID = @ST_ID"; #region 获取所有业务状态信息信息 /// /// 获取所有业务状态信息信息 /// /// List public IList GetAllOpStatusList() { IList OpStatusListEntites = new List(); OpStatusListEntity OpStatusListEntity = null; using (SqlDataReader sqlRead = SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, SQL_SELECT_OpStatusList_ALL, null)) { try { while (sqlRead.Read()) { OpStatusListEntity = new OpStatusListEntity(); if (!sqlRead.IsDBNull(0)) { OpStatusListEntity.ST_ID = sqlRead.GetString(0); } if (!sqlRead.IsDBNull(1)) { OpStatusListEntity.BSNO = sqlRead.GetString(1); } if (!sqlRead.IsDBNull(2)) { OpStatusListEntity.STATUS = sqlRead.GetString(2); } if (!sqlRead.IsDBNull(3)) { OpStatusListEntity.ISCOMP = sqlRead.GetString(3); } if (!sqlRead.IsDBNull(4)) { OpStatusListEntity.COMPTIME = sqlRead.GetDateTime(4); } if (!sqlRead.IsDBNull(5)) { OpStatusListEntity.COMPOP = sqlRead.GetString(5); } if (!sqlRead.IsDBNull(6)) { OpStatusListEntity.REMARK = sqlRead.GetString(6); } if (!sqlRead.IsDBNull(7)) { OpStatusListEntity.INPUTBY = sqlRead.GetString(7); } if (!sqlRead.IsDBNull(8)) { OpStatusListEntity.ORDNO = sqlRead.GetString(8); } if (!sqlRead.IsDBNull(9)) { OpStatusListEntity.STATUS_OPSEAE = sqlRead.GetString(9); } OpStatusListEntites.Add(OpStatusListEntity); } } catch (Exception execError) { throw execError; } } return OpStatusListEntites; } #endregion #region 根据业务状态信息GID获取业务状态信息信息 /// /// 根据业务状态信息GID获取业务状态信息信息 /// /// /// public OpStatusListEntity GetOpStatusListByID(string strGid) { OpStatusListEntity OpStatusListEntity = null; SqlParameter parm = new SqlParameter(PARM_OpStatusList_GID, SqlDbType.VarChar, 36); parm.Value = strGid; using (SqlDataReader sqlRead = SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, SQL_SELECT_OpStatusList_BYGID, parm)) { try { while (sqlRead.Read()) { OpStatusListEntity = new OpStatusListEntity(); if (!sqlRead.IsDBNull(0)) { OpStatusListEntity.ST_ID = sqlRead.GetString(0); } if (!sqlRead.IsDBNull(1)) { OpStatusListEntity.BSNO = sqlRead.GetString(1); } if (!sqlRead.IsDBNull(2)) { OpStatusListEntity.STATUS = sqlRead.GetString(2); } if (!sqlRead.IsDBNull(3)) { OpStatusListEntity.ISCOMP = sqlRead.GetString(3); } if (!sqlRead.IsDBNull(4)) { OpStatusListEntity.COMPTIME = sqlRead.GetDateTime(4); } if (!sqlRead.IsDBNull(5)) { OpStatusListEntity.COMPOP = sqlRead.GetString(5); } if (!sqlRead.IsDBNull(6)) { OpStatusListEntity.REMARK = sqlRead.GetString(6); } if (!sqlRead.IsDBNull(7)) { OpStatusListEntity.INPUTBY = sqlRead.GetString(7); } if (!sqlRead.IsDBNull(8)) { OpStatusListEntity.ORDNO = sqlRead.GetString(8); } if (!sqlRead.IsDBNull(9)) { OpStatusListEntity.STATUS_OPSEAE = sqlRead.GetString(9); } } } catch (Exception execError) { throw execError; } } return OpStatusListEntity; } #endregion #region 根据业务状态信息GID获取业务状态信息信息 /// /// 根据业务状态信息GID获取业务状态信息信息 /// /// /// public OpStatusListEntity GetOpStatusListTop1() { OpStatusListEntity OpStatusListEntity = null; using (SqlDataReader sqlRead = SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, SQL_SELECT_OpStatusList_TOP1, null)) { try { while (sqlRead.Read()) { OpStatusListEntity = new OpStatusListEntity(); if (!sqlRead.IsDBNull(0)) { OpStatusListEntity.ST_ID = sqlRead.GetString(0); } if (!sqlRead.IsDBNull(1)) { OpStatusListEntity.BSNO = sqlRead.GetString(1); } if (!sqlRead.IsDBNull(2)) { OpStatusListEntity.STATUS = sqlRead.GetString(2); } if (!sqlRead.IsDBNull(3)) { OpStatusListEntity.ISCOMP = sqlRead.GetString(3); } if (!sqlRead.IsDBNull(4)) { OpStatusListEntity.COMPTIME = sqlRead.GetDateTime(4); } if (!sqlRead.IsDBNull(5)) { OpStatusListEntity.COMPOP = sqlRead.GetString(5); } if (!sqlRead.IsDBNull(6)) { OpStatusListEntity.REMARK = sqlRead.GetString(6); } if (!sqlRead.IsDBNull(7)) { OpStatusListEntity.INPUTBY = sqlRead.GetString(7); } if (!sqlRead.IsDBNull(8)) { OpStatusListEntity.ORDNO = sqlRead.GetString(8); } if (!sqlRead.IsDBNull(9)) { OpStatusListEntity.STATUS_OPSEAE = sqlRead.GetString(9); } } } catch (Exception execError) { throw execError; } } return OpStatusListEntity; } #endregion /// /// 插入信息 /// /// 实体类 /// 值为1插入数据正常,-1操作异常 public int InserInfo(OpStatusListEntity infoEntity) { int iResult = 0; //获取参数 SqlParameter[] parms = GetInsertParms(); parms[0].Value = infoEntity.ST_ID;//惟一编号 parms[1].Value = infoEntity.BSNO;//业务编号 parms[2].Value = infoEntity.STATUS;//业务状态 parms[3].Value = infoEntity.COMPOP;//完成人 parms[4].Value = infoEntity.REMARK;//备注 parms[5].Value = infoEntity.INPUTBY;//录入人 //parms[3].Value = infoEntity.COMPTIME;//完成时间 // string strCOMPTIME = infoEntity.COMPTIME.ToString().IndexOf("0001")>-1 ? "" : "'" + infoEntity.COMPTIME.ToString() + "',"; string strCOMPTIME_name = strCOMPTIME.Equals("") ? "" : "COMPTIME,"; // strSqlInsertInfo = String.Format(strSqlInsertInfo, strCOMPTIME_name, strCOMPTIME); // using (SqlConnection conn = new SqlConnection(SqlHelper.ConnectionStringLocalTransaction)) { int existVal = SqlHelper.ExecuteNonQuery(conn, CommandType.Text, strSqlInsertInfo, parms); if (existVal > 0) { iResult = 1; } else { iResult = -1;//执行异常 } } return iResult; } /// /// 更新信息 /// /// 实体类 /// 值为1更新数据正常,-1操作异常 public int UpdateInfo(OpStatusListEntity infoEntity) { int iResult = 0; //获取参数 SqlParameter[] parms = GetUpdateParms(); parms[0].Value = infoEntity.ST_ID;//惟一编号 parms[1].Value = infoEntity.BSNO;//业务编号 parms[2].Value = infoEntity.STATUS;//业务状态 parms[3].Value = infoEntity.COMPOP;//完成人 parms[4].Value = infoEntity.REMARK;//备注 //parms[3].Value = infoEntity.COMPOP;//完成时间 // string strCOMPTIME = infoEntity.COMPTIME.ToString().IndexOf("0001")>-1 ? "" : "COMPTIME='" + infoEntity.COMPTIME.ToString() + "',"; // strSqlUpdateInfo = String.Format(strSqlUpdateInfo, strCOMPTIME); // using (SqlConnection conn = new SqlConnection(SqlHelper.ConnectionStringLocalTransaction)) { int existVal = SqlHelper.ExecuteNonQuery(conn, CommandType.Text, strSqlUpdateInfo, parms); if (existVal > 0) { iResult = 1; } else { iResult = -1;//执行异常 } } return iResult; } #region 生成插入语句参数 /// /// 生成插入语句参数 /// /// 返回SqlParameter数组 private SqlParameter[] GetInsertParms() { SqlParameter[] parms = new SqlParameter[] { new SqlParameter("@ST_ID",SqlDbType.VarChar,36),//惟一编号 new SqlParameter("@BSNO",SqlDbType.VarChar,100),//业务编号 new SqlParameter("@STATUS",SqlDbType.VarChar,20),//业务状态 new SqlParameter("@COMPOP",SqlDbType.VarChar,10),//完成人 new SqlParameter("@REMARK",SqlDbType.VarChar,100),//备注 new SqlParameter("@INPUTBY",SqlDbType.VarChar,36),//录入人 //new SqlParameter("@COMPOP",SqlDbType.datetime),//完成时间 }; return parms; } #endregion #region 生成更新语句参数 /// /// 生成更新语句参数 /// /// 返回SqlParameter数组 private SqlParameter[] GetUpdateParms() { SqlParameter[] parms = new SqlParameter[]{ new SqlParameter("@ST_ID",SqlDbType.VarChar,36),//惟一编号 new SqlParameter("@BSNO",SqlDbType.VarChar,100),//业务编号 new SqlParameter("@STATUS",SqlDbType.VarChar,20),//业务状态 new SqlParameter("@COMPOP",SqlDbType.VarChar,10),//完成人 new SqlParameter("@REMARK",SqlDbType.VarChar,100)//备注 //new SqlParameter("@COMPOP",SqlDbType.datetime),//完成时间 }; return parms; } #endregion #region 返回数据集 业务状态信息表(OpStatusList)信息 /// /// 返回 业务状态信息表(OpStatusList)信息 /// /// public DataSet GetOpStatusListSQL(string strSQL) { string str = "select * from [op_status] where 1=1 " + strSQL; DataSet DS = SqlHelper.OpenSqlDataSet(SqlHelper.ConnectionStringLocalTransaction, str); try { if (DS.Tables[0].Rows.Count <= 0) { DS = null; } } catch { DS = null; } return DS; } #endregion #region 返回数据集 业务状态信息表(OpStatusList)信息 /// 返回 业务状态信息表(OpStatusList)删除 /// /// /// public String GetOpStatusListDel(string strGid, string strUserID) { string alt = ""; string str = "delete from op_status where ST_ID='" + strGid + "'"; bool bl = SqlHelper.ExecuteSqlCommand(SqlHelper.ConnectionStringLocalTransaction, str); if (bl == false) { alt = "账户表(op_status)删除操作出错!"; return alt; } else { //string str1 = "insert into sys_log(NAME,LOGTYPE,LOGCONTENT,STATUS_OPSEAE) values('删除账户表(op_status)的信息','更新操作','" + str + "','" + strUserID + "')"; //bool bl1 = SqlHelper.ExecuteSqlCommand(SqlHelper.ConnectionStringLocalTransaction, str1); } return alt; } #endregion /// /// 根据SQL语句查询账户数据集 /// /// /// public DataSet GetExcuteSql(string strSql) { DataSet userSet = new DataSet(); userSet = SqlHelper.ExecuteDataset(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, strSql); return userSet; } #region 插入账户列表信息 /// /// 插入账户列表信息 /// /// 插入SQL语句组,将所有要执行的插入语句写入ArrayList,每个索引对应一条SQL语句,执行时需要遍历操作 /// 返回状态值 为1表示插入完成;为-1插入出现异常但未正确回滚事务;为-2插入异常,事务已经成功回滚;默认状态为0 public int InsertOpStatusListFromGrid(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语句组,将所有要执行的更新语句写入ArrayList,每个索引对应一条SQL语句,执行时需要遍历操作 /// 返回状态值 为1表示更新完成;为-1更新出现异常但未正确回滚事务;为-2更新异常,事务已经成功回滚;默认状态为0 public int UpdateOpStatusListFromGrid(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 通过关联编号BSNO与账户类型获取账户信息 /// /// 通过关联编号BSNO与账户类型获取账户信息 /// /// /// public OpStatusListEntity GetOpStatusListByBSNOAndType(string strBSNO) { OpStatusListEntity OpStatusListEntity = null; string strSql = " SELECT top 1 ST_ID,BSNO,STATUS,ISCOMP,COMPTIME,COMPOP,REMARK,INPUTBY,ORDNO,STATUS_OPSEAE FROM op_status WHERE BSNO = '" + strBSNO + "'"; using (SqlDataReader sqlRead = SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, strSql, null)) { try { while (sqlRead.Read()) { OpStatusListEntity = new OpStatusListEntity(); if (!sqlRead.IsDBNull(0)) { OpStatusListEntity.ST_ID = sqlRead.GetString(0); } if (!sqlRead.IsDBNull(1)) { OpStatusListEntity.BSNO = sqlRead.GetString(1); } if (!sqlRead.IsDBNull(2)) { OpStatusListEntity.STATUS = sqlRead.GetString(2); } if (!sqlRead.IsDBNull(3)) { OpStatusListEntity.ISCOMP = sqlRead.GetString(3); } if (!sqlRead.IsDBNull(4)) { OpStatusListEntity.COMPTIME = sqlRead.GetDateTime(4); } if (!sqlRead.IsDBNull(5)) { OpStatusListEntity.COMPOP = sqlRead.GetString(5); } if (!sqlRead.IsDBNull(6)) { OpStatusListEntity.REMARK = sqlRead.GetString(6); } if (!sqlRead.IsDBNull(7)) { OpStatusListEntity.INPUTBY = sqlRead.GetString(7); } if (!sqlRead.IsDBNull(8)) { OpStatusListEntity.ORDNO = sqlRead.GetString(8); } if (!sqlRead.IsDBNull(9)) { OpStatusListEntity.STATUS_OPSEAE = sqlRead.GetString(9); } } } catch (Exception execError) { throw execError; } } return OpStatusListEntity; } #endregion #region 通过账户GID删除单条账户 public int DeleteOpStatusListByGid(string tempGid) { int result = 0; SqlParameter parm = new SqlParameter(PARM_OpStatusList_GID, SqlDbType.VarChar, 36); parm.Value = tempGid; using (SqlTransaction sqlTran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction)) { try { SqlHelper.ExecuteNonQuery(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, SQL_DELETE_OpStatusList_BY_GID, parm); result = 1;//状态为1表示删除成功 sqlTran.Commit(); } catch (Exception execError) { result = -1;//有异常,插入失败 sqlTran.Rollback(); result = -2;//插入异常,事务已回滚成功 throw execError; } finally { SqlHelper.CloseConnection(); } } return result; } #endregion } }