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.

529 lines
24 KiB
C#

10 months ago
using System;
using System.Text;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Data;
using DSWeb.Models;
//using DSWeb.DataAccess;
using WebSqlHelper;
using System.Configuration;
using System.Collections;
namespace DSWeb.EntityDA
{
public class ImportReceiptListDA
{
public bool Exists(int id)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select count(1) from Import_receipt");
strSql.Append(" where ");
strSql.Append(" id = @id ");
SqlParameter[] parameters = {
new SqlParameter("@id", SqlDbType.Int,4)
};
parameters[0].Value = id;
DataSet ds = SqlHelper.ExecuteDataset(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, strSql.ToString());
if (ds.Tables[0].Rows.Count != 0)
{
return true;
}
else
{
return false;
}
}
/// <summary>
/// 增加一条数据
/// </summary>
public int Add(ImportReceiptListEntity model)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("insert into Import_receipt(");
strSql.Append("trancNo,remark,RECEIPTTYPE,RECEIPTSTATE,BSNO,CORPID,CREATEUSER,CREATETIME,MODIFIEDUSER,MODIFIEDTIME,ContractNo,Receiptid,ReceiptNo,state,Send_date,receive_date,repeat_date,trancer");
strSql.Append(") values (");
strSql.Append("@trancNo,@remark,@RECEIPTTYPE,@RECEIPTSTATE,@BSNO,@CORPID,@CREATEUSER,@CREATETIME,@MODIFIEDUSER,@MODIFIEDTIME,@ContractNo,@Receiptid,@ReceiptNo,@state,@Send_date,@receive_date,@repeat_date,@trancer");
strSql.Append(") ");
strSql.Append(";select @@IDENTITY");
SqlParameter[] parameters = {
new SqlParameter("@trancNo", SqlDbType.VarChar,50) ,
new SqlParameter("@remark", SqlDbType.VarChar,150) ,
new SqlParameter("@RECEIPTTYPE", SqlDbType.VarChar,100) ,
new SqlParameter("@RECEIPTSTATE", SqlDbType.VarChar,100) ,
new SqlParameter("@BSNO", SqlDbType.VarChar,100) ,
new SqlParameter("@CORPID", SqlDbType.VarChar,100) ,
new SqlParameter("@CREATEUSER", SqlDbType.VarChar,100) ,
new SqlParameter("@CREATETIME", SqlDbType.DateTime) ,
new SqlParameter("@MODIFIEDUSER", SqlDbType.VarChar,100) ,
new SqlParameter("@MODIFIEDTIME", SqlDbType.DateTime) ,
new SqlParameter("@ContractNo", SqlDbType.VarChar,50) ,
new SqlParameter("@Receiptid", SqlDbType.TinyInt,1) ,
new SqlParameter("@ReceiptNo", SqlDbType.VarChar,50) ,
new SqlParameter("@state", SqlDbType.TinyInt,1) ,
new SqlParameter("@Send_date", SqlDbType.DateTime) ,
new SqlParameter("@receive_date", SqlDbType.DateTime) ,
new SqlParameter("@repeat_date", SqlDbType.DateTime) ,
new SqlParameter("@trancer", SqlDbType.VarChar,50)
};
parameters[0].Value = model.trancNo;
parameters[1].Value = model.remark;
parameters[2].Value = model.RECEIPTTYPE;
parameters[3].Value = model.RECEIPTSTATE;
parameters[4].Value = model.BSNO;
parameters[5].Value = model.CORPID;
parameters[6].Value = model.CREATEUSER;
parameters[7].Value = model.CREATETIME;
parameters[8].Value = model.MODIFIEDUSER;
parameters[9].Value = model.MODIFIEDTIME;
parameters[10].Value = model.ContractNo;
parameters[11].Value = model.Receiptid;
parameters[12].Value = model.ReceiptNo;
parameters[13].Value = model.state;
parameters[14].Value = model.Send_date;
parameters[15].Value = model.receive_date;
parameters[16].Value = model.repeat_date;
parameters[17].Value = model.trancer;
//
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) value('增加信息','增加操作','GID=" + model.GID.ToString() + "','" + model.MODIFIEDUSER.ToString() + "')";
//bool bl0 = SqlHelper.ExecuteSqlCommand(SqlHelper.ConnectionStringLocalTransaction, str0);
}
else
{
iResult = -1;//执行异常
}
}
return iResult;
}
/// <summary>
/// 更新一条数据
/// </summary>
public int Update(ImportReceiptListEntity model)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("update Import_receipt set ");
strSql.Append(" trancNo = @trancNo , ");
strSql.Append(" remark = @remark , ");
strSql.Append(" RECEIPTTYPE = @RECEIPTTYPE , ");
strSql.Append(" RECEIPTSTATE = @RECEIPTSTATE , ");
strSql.Append(" BSNO = @BSNO , ");
strSql.Append(" CORPID = @CORPID , ");
strSql.Append(" CREATEUSER = @CREATEUSER , ");
strSql.Append(" CREATETIME = @CREATETIME , ");
strSql.Append(" MODIFIEDUSER = @MODIFIEDUSER , ");
strSql.Append(" MODIFIEDTIME = @MODIFIEDTIME , ");
strSql.Append(" ContractNo = @ContractNo , ");
strSql.Append(" Receiptid = @Receiptid , ");
strSql.Append(" ReceiptNo = @ReceiptNo , ");
strSql.Append(" state = @state , ");
strSql.Append(" Send_date = @Send_date , ");
strSql.Append(" receive_date = @receive_date , ");
strSql.Append(" repeat_date = @repeat_date , ");
strSql.Append(" trancer = @trancer ");
strSql.Append(" where id=@id ");
SqlParameter[] parameters = {
new SqlParameter("@id", SqlDbType.Int,4) ,
new SqlParameter("@trancNo", SqlDbType.VarChar,50) ,
new SqlParameter("@remark", SqlDbType.VarChar,150) ,
new SqlParameter("@RECEIPTTYPE", SqlDbType.VarChar,100) ,
new SqlParameter("@RECEIPTSTATE", SqlDbType.VarChar,100) ,
new SqlParameter("@BSNO", SqlDbType.VarChar,100) ,
new SqlParameter("@CORPID", SqlDbType.VarChar,100) ,
new SqlParameter("@CREATEUSER", SqlDbType.VarChar,100) ,
new SqlParameter("@CREATETIME", SqlDbType.DateTime) ,
new SqlParameter("@MODIFIEDUSER", SqlDbType.VarChar,100) ,
new SqlParameter("@MODIFIEDTIME", SqlDbType.DateTime) ,
new SqlParameter("@ContractNo", SqlDbType.VarChar,50) ,
new SqlParameter("@Receiptid", SqlDbType.TinyInt,1) ,
new SqlParameter("@ReceiptNo", SqlDbType.VarChar,50) ,
new SqlParameter("@state", SqlDbType.TinyInt,1) ,
new SqlParameter("@Send_date", SqlDbType.DateTime) ,
new SqlParameter("@receive_date", SqlDbType.DateTime) ,
new SqlParameter("@repeat_date", SqlDbType.DateTime) ,
new SqlParameter("@trancer", SqlDbType.VarChar,50)
};
parameters[0].Value = model.id;
parameters[1].Value = model.trancNo;
parameters[2].Value = model.remark;
parameters[3].Value = model.RECEIPTTYPE;
parameters[4].Value = model.RECEIPTSTATE;
parameters[5].Value = model.BSNO;
parameters[6].Value = model.CORPID;
parameters[7].Value = model.CREATEUSER;
parameters[8].Value = model.CREATETIME;
parameters[9].Value = model.MODIFIEDUSER;
parameters[10].Value = model.MODIFIEDTIME;
parameters[11].Value = model.ContractNo;
parameters[12].Value = model.Receiptid;
parameters[13].Value = model.ReceiptNo;
parameters[14].Value = model.state;
parameters[15].Value = model.Send_date;
parameters[16].Value = model.receive_date;
parameters[17].Value = model.repeat_date;
parameters[18].Value = model.trancer;
//
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) value('更新信息表','更新操作','GID=" + model.GID.ToString() + "','" + model.MODIFIEDUSER.ToString() + "')";
//bool bl0 = SqlHelper.ExecuteSqlCommand(SqlHelper.ConnectionStringLocalTransaction, str0);
}
else
{
iResult = -1;//执行异常
}
}
return iResult;
}
/// <summary>
/// 删除一条数据
/// </summary>
public int Delete(int id)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("delete from Import_receipt ");
strSql.Append(" where id=@id");
SqlParameter[] parameters = {
new SqlParameter("@id", SqlDbType.Int,4)
};
parameters[0].Value = id;
//
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 int DeleteList(string idlist)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("delete from Import_receipt ");
strSql.Append(" where ID in (" + idlist + ") ");
//
int iResult = 0;
using (SqlTransaction sqlTran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction))
{
try
{
SqlHelper.ExecuteNonQuery(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, strSql.ToString(), null);
iResult = 1;//状态为1表示删除成功
sqlTran.Commit();
}
catch (Exception execError)
{
iResult = -1;//有异常,删除失败
sqlTran.Rollback();
iResult = -2;//插入异常,事务已回滚成功
throw execError;
}
finally
{
SqlHelper.CloseConnection();
}
}
return iResult;
}
/// <summary>
/// 得到一个对象实体
/// </summary>
public ImportReceiptListEntity GetModel(int id)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select id, trancNo, remark, RECEIPTTYPE, RECEIPTSTATE, BSNO, CORPID, CREATEUSER, CREATETIME, MODIFIEDUSER, MODIFIEDTIME, ContractNo, Receiptid, ReceiptNo, state, Send_date, receive_date, repeat_date, trancer ");
strSql.Append(" from Import_receipt ");
strSql.Append(" where id=" + id);
ImportReceiptListEntity model = new ImportReceiptListEntity();
DataSet ds = SqlHelper.Query(strSql.ToString(), null);
if (ds.Tables[0].Rows.Count > 0)
{
if (ds.Tables[0].Rows[0]["id"].ToString() != "")
{
model.id = int.Parse(ds.Tables[0].Rows[0]["id"].ToString());
}
model.trancNo = ds.Tables[0].Rows[0]["trancNo"].ToString();
model.remark = ds.Tables[0].Rows[0]["remark"].ToString();
model.RECEIPTTYPE = ds.Tables[0].Rows[0]["RECEIPTTYPE"].ToString();
model.RECEIPTSTATE = ds.Tables[0].Rows[0]["RECEIPTSTATE"].ToString();
model.BSNO = ds.Tables[0].Rows[0]["BSNO"].ToString();
model.CORPID = ds.Tables[0].Rows[0]["CORPID"].ToString();
model.CREATEUSER = ds.Tables[0].Rows[0]["CREATEUSER"].ToString();
if (ds.Tables[0].Rows[0]["CREATETIME"].ToString() != "")
{
model.CREATETIME = DateTime.Parse(ds.Tables[0].Rows[0]["CREATETIME"].ToString());
}
model.MODIFIEDUSER = ds.Tables[0].Rows[0]["MODIFIEDUSER"].ToString();
if (ds.Tables[0].Rows[0]["MODIFIEDTIME"].ToString() != "")
{
model.MODIFIEDTIME = DateTime.Parse(ds.Tables[0].Rows[0]["MODIFIEDTIME"].ToString());
}
model.ContractNo = ds.Tables[0].Rows[0]["ContractNo"].ToString();
if (ds.Tables[0].Rows[0]["Receiptid"].ToString() != "")
{
model.Receiptid = int.Parse(ds.Tables[0].Rows[0]["Receiptid"].ToString());
}
model.ReceiptNo = ds.Tables[0].Rows[0]["ReceiptNo"].ToString();
if (ds.Tables[0].Rows[0]["state"].ToString() != "")
{
model.state = int.Parse(ds.Tables[0].Rows[0]["state"].ToString());
}
if (ds.Tables[0].Rows[0]["Send_date"].ToString() != "")
{
model.Send_date = DateTime.Parse(ds.Tables[0].Rows[0]["Send_date"].ToString());
}
if (ds.Tables[0].Rows[0]["receive_date"].ToString() != "")
{
model.receive_date = DateTime.Parse(ds.Tables[0].Rows[0]["receive_date"].ToString());
}
if (ds.Tables[0].Rows[0]["repeat_date"].ToString() != "")
{
model.repeat_date = DateTime.Parse(ds.Tables[0].Rows[0]["repeat_date"].ToString());
}
model.trancer = ds.Tables[0].Rows[0]["trancer"].ToString();
return model;
}
else
{
return null;
}
}
/// <summary>
/// 得到一个对象实体
/// </summary>
public ImportReceiptListEntity GetModel(string strBSNO)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select top 1 id, trancNo, remark, RECEIPTTYPE, RECEIPTSTATE, BSNO, CORPID, CREATEUSER, CREATETIME, MODIFIEDUSER, MODIFIEDTIME, ContractNo, Receiptid, ReceiptNo, state, Send_date, receive_date, repeat_date, trancer ");
strSql.Append(" from Import_receipt ");
strSql.Append(" where BSNO='" + strBSNO + "'");
ImportReceiptListEntity model = new ImportReceiptListEntity();
DataSet ds = SqlHelper.Query(strSql.ToString(), null);
if (ds.Tables[0].Rows.Count > 0)
{
if (ds.Tables[0].Rows[0]["id"].ToString() != "")
{
model.id = int.Parse(ds.Tables[0].Rows[0]["id"].ToString());
}
model.trancNo = ds.Tables[0].Rows[0]["trancNo"].ToString();
model.remark = ds.Tables[0].Rows[0]["remark"].ToString();
model.RECEIPTTYPE = ds.Tables[0].Rows[0]["RECEIPTTYPE"].ToString();
model.RECEIPTSTATE = ds.Tables[0].Rows[0]["RECEIPTSTATE"].ToString();
model.BSNO = ds.Tables[0].Rows[0]["BSNO"].ToString();
model.CORPID = ds.Tables[0].Rows[0]["CORPID"].ToString();
model.CREATEUSER = ds.Tables[0].Rows[0]["CREATEUSER"].ToString();
if (ds.Tables[0].Rows[0]["CREATETIME"].ToString() != "")
{
model.CREATETIME = DateTime.Parse(ds.Tables[0].Rows[0]["CREATETIME"].ToString());
}
model.MODIFIEDUSER = ds.Tables[0].Rows[0]["MODIFIEDUSER"].ToString();
if (ds.Tables[0].Rows[0]["MODIFIEDTIME"].ToString() != "")
{
model.MODIFIEDTIME = DateTime.Parse(ds.Tables[0].Rows[0]["MODIFIEDTIME"].ToString());
}
model.ContractNo = ds.Tables[0].Rows[0]["ContractNo"].ToString();
if (ds.Tables[0].Rows[0]["Receiptid"].ToString() != "")
{
model.Receiptid = int.Parse(ds.Tables[0].Rows[0]["Receiptid"].ToString());
}
model.ReceiptNo = ds.Tables[0].Rows[0]["ReceiptNo"].ToString();
if (ds.Tables[0].Rows[0]["state"].ToString() != "")
{
model.state = int.Parse(ds.Tables[0].Rows[0]["state"].ToString());
}
if (ds.Tables[0].Rows[0]["Send_date"].ToString() != "")
{
model.Send_date = DateTime.Parse(ds.Tables[0].Rows[0]["Send_date"].ToString());
}
if (ds.Tables[0].Rows[0]["receive_date"].ToString() != "")
{
model.receive_date = DateTime.Parse(ds.Tables[0].Rows[0]["receive_date"].ToString());
}
if (ds.Tables[0].Rows[0]["repeat_date"].ToString() != "")
{
model.repeat_date = DateTime.Parse(ds.Tables[0].Rows[0]["repeat_date"].ToString());
}
model.trancer = ds.Tables[0].Rows[0]["trancer"].ToString();
return model;
}
else
{
return null;
}
}
/// <summary>
/// 获得数据列表
/// </summary>
public DataSet GetList(string strWhere)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select * ");
strSql.Append(" FROM Import_receipt ");
if (strWhere.Trim() != "")
{
strSql.Append(" where " + strWhere);
}
return SqlHelper.ExecuteDataset(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, strSql.ToString());
}
/// <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;
}
/// <summary>
/// 获得前几行数据
/// </summary>
public DataSet GetList(int Top, string strWhere, string filedOrder)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select ");
if (Top > 0)
{
strSql.Append(" top " + Top.ToString());
}
strSql.Append(" * ");
strSql.Append(" FROM Import_receipt ");
if (strWhere.Trim() != "")
{
strSql.Append(" where " + strWhere);
}
strSql.Append(" order by " + filedOrder);
return SqlHelper.ExecuteDataset(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, strSql.ToString());
}
#region 更新账户列表信息
/// <summary>
/// 更新账户列表信息
/// </summary>
/// <param name="sqlList">更新SQL语句组,将所有要执行的更新语句写入ArrayList,每个索引对应一条SQL语句,执行时需要遍历操作</param>
/// <returns>返回状态值 为1表示更新完成;为-1更新出现异常但未正确回滚事务;为-2更新异常,事务已经成功回滚;默认状态为0</returns>
public int UpdateFromGrid(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 InsertFromGrid(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
//
}
}