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.

591 lines
24 KiB
C#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

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 获取所有业务状态信息信息
/// <summary>
/// 获取所有业务状态信息信息
/// </summary>
/// <returns>List<OpStatusListEntity></returns>
public IList<OpStatusListEntity> GetAllOpStatusList()
{
IList<OpStatusListEntity> OpStatusListEntites = new List<OpStatusListEntity>();
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获取业务状态信息信息
/// <summary>
/// 根据业务状态信息GID获取业务状态信息信息
/// </summary>
/// <param name="strGid"></param>
/// <returns></returns>
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获取业务状态信息信息
/// <summary>
/// 根据业务状态信息GID获取业务状态信息信息
/// </summary>
/// <param name="strGid"></param>
/// <returns></returns>
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
/// <summary>
/// 插入信息
/// </summary>
/// <param name="OpStatusListEntity">实体类</param>
/// <returns>值为1插入数据正常,-1操作异常</returns>
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;
}
/// <summary>
/// 更新信息
/// </summary>
/// <param name="OpStatusListEntity">实体类</param>
/// <returns>值为1更新数据正常,-1操作异常</returns>
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 生成插入语句参数
/// <summary>
/// 生成插入语句参数
/// </summary>
/// <returns>返回SqlParameter数组</returns>
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 生成更新语句参数
/// <summary>
/// 生成更新语句参数
/// </summary>
/// <returns>返回SqlParameter数组</returns>
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信息
/// <summary>
/// 返回 业务状态信息表OpStatusList信息
/// </summary>
/// <returns></returns>
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删除
/// </summary>
/// <returns></returns>
/// <summary>
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
/// <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;
}
#region 插入账户列表信息
/// <summary>
/// 插入账户列表信息
/// </summary>
/// <param name="sqlList">插入SQL语句组,将所有要执行的插入语句写入ArrayList,每个索引对应一条SQL语句,执行时需要遍历操作</param>
/// <returns>返回状态值 为1表示插入完成;为-1插入出现异常但未正确回滚事务;为-2插入异常,事务已经成功回滚;默认状态为0</returns>
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 更新账户列表信息
/// <summary>
/// 更新账户列表信息
/// </summary>
/// <param name="sqlList">更新SQL语句组,将所有要执行的更新语句写入ArrayList,每个索引对应一条SQL语句,执行时需要遍历操作</param>
/// <returns>返回状态值 为1表示更新完成;为-1更新出现异常但未正确回滚事务;为-2更新异常,事务已经成功回滚;默认状态为0</returns>
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与账户类型获取账户信息
/// <summary>
/// 通过关联编号BSNO与账户类型获取账户信息
/// </summary>
/// <param name="strGID"></param>
/// <returns></returns>
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
}
}