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.
DS7/DSWeb/EntityDA/ChequeBooksDA.cs

374 lines
16 KiB
C#

using System;
using System.Data;
using System.Data.SqlClient;
using DSWeb.Models;
using WebSqlHelper;
namespace DSWeb.EntityDA
{
public class ChequeBooksDA
{
//支票册主表
private string PARM_Cheque_BOOK_GID = "@gid";
private string PARM_Cheque_BOOK_NAME = "@name";
private string PARM_Cheque_BOOK_DESCRIPTION = "@description";
private string PARM_Cheque_BOOK_CREATE_USER = "@create_user";
private string PARM_Cheque_BOOK_Cheque_CODE = "@Cheque_code";
private string PARM_Cheque_BOOK_Cheque_NUM_START = "@Cheque_num_start";
private string PARM_Cheque_BOOK_Cheque_NUM_END = "@Cheque_num_end";
private string PARM_Cheque_BOOK_Cheque_TOTAL = "@Cheque_total";
private string PARM_Cheque_BOOK_IS_LOCK = "@is_lock";
private string PARM_Cheque_BOOK_COMPANY_ID = "@company_id";
private string PARM_Cheque_BOOK_TYPE = "@type";
//支票册从表
private string PARM_Cheque_BOOK_ITEM_GID = "@gid";
private string PARM_Cheque_BOOK_ITEM_BOOK_ID = "@book_id";
private string PARM_Cheque_BOOK_ITEM_Cheque_NUM = "@Cheque_num";
private string PARM_Cheque_BOOK_ITEM_CREATE_USER = "@create_user";
private string PARM_Cheque_BOOK_ITEM_IS_LOCK = "@is_lock";
private string PARM_Cheque_BOOK_ITEM_IS_MAKE_OUT = "@is_makeout";
private string SQL_SELECT_Cheque_BOOK_BY_GID = " SELECT GID, NAME, DESCRIPTION, CREATEUSER, CREATETIME, MODIFIEDUSER, MODIFIEDTIME, CHEQUECODE, CHEQUENUMSTART, CHEQUENUMEND, CHEQUETOTAL, ISLOCK, ISDELETE, DELETEUSER, DELETETIME,TYPE,COMPANYID,CURRENCY FROM ch_fee_chequebooks WHERE GID = @gid ";
private string SQL_INSERT_Cheque_BOOK = " INSERT INTO ch_fee_chequebooks(GID,NAME,DESCRIPTION,CREATEUSER,CREATETIME,CHEQUECODE,CHEQUENUMSTART,CHEQUENUMEND,CHEQUETOTAL,ISLOCK,COMPANYID,TYPE,CURRENCY) VALUES(@gid,@name,@description,@create_user,GETDATE(),@Cheque_code,@Cheque_num_start,@Cheque_num_end,@Cheque_total,@is_lock,@company_id,@type,@CURRENCY) ";
private string SQL_INSERT_Cheque_BOOK_ITEM = " INSERT INTO ch_fee_Chequeitems(GID, BOOKID,ChequeNUM, CREATEUSER, CREATETIME, ISLOCK, ISMAKEOUT,MAKEOUTUSER) VALUES(@gid,@book_id,@Cheque_num,@create_user,GETDATE(),@is_lock,@is_makeout,'')";
private string SQL_SELECT_SAME_Cheque_NUM = " SELECT COUNT(*) FROM ch_fee_Chequeitems WHERE ChequeNUM = @Cheque_num";
private string SQL_SELECT_CURRENT_Cheque_BOOK_ITEM = " SELECT TOP 1 GID, BOOKID, ChequeNUM, CREATEUSER, CREATETIME, ISLOCK, ISDELETE, DELETEUSER, DELETETIME, ISMAKEOUT,MAKEOUTUSER,MAKEOUTTIME FROM ch_fee_Chequeitems WHERE ISLOCK <> 1 AND ISDELETE <> 1 AND ISMAKEOUT <> 1 ORDER BY ChequeNUM ASC ";
#region 通过支票册GID获取支票信息
/// <summary>
/// 通过支票册GID获取支票信息
/// </summary>
/// <param name="tempChequeBookGID">支票GID</param>
/// <returns>返回实体类ChequeBooksEntity信息</returns>
public ChequeBooksEntity GetChequeBookByGID(string tempChequeBookGID)
{
ChequeBooksEntity ChequeBooksEntity = null;
SqlParameter parm = new SqlParameter(PARM_Cheque_BOOK_GID, SqlDbType.VarChar, 36);
parm.Value = tempChequeBookGID;
using (SqlDataReader sqlRead = SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, SQL_SELECT_Cheque_BOOK_BY_GID, parm))
{
try
{
while (sqlRead.Read())
{
ChequeBooksEntity = new ChequeBooksEntity();
if (!sqlRead.IsDBNull(0))
{
ChequeBooksEntity.GID = sqlRead.GetString(0);
}
if (!sqlRead.IsDBNull(1))
{
ChequeBooksEntity.Name = sqlRead.GetString(1);
}
if (!sqlRead.IsDBNull(2))
{
ChequeBooksEntity.Description = sqlRead.GetString(2);
}
if (!sqlRead.IsDBNull(3))
{
ChequeBooksEntity.CreateUser = sqlRead.GetString(3);
}
if (!sqlRead.IsDBNull(4))
{
ChequeBooksEntity.CreateTime = sqlRead.GetDateTime(4);
}
if (!sqlRead.IsDBNull(5))
{
ChequeBooksEntity.ModifiedUser = sqlRead.GetString(5);
}
if (!sqlRead.IsDBNull(6))
{
ChequeBooksEntity.ModifiedTime = sqlRead.GetDateTime(6);
}
if (!sqlRead.IsDBNull(7))
{
ChequeBooksEntity.CHEQUECODE = sqlRead.GetString(7);
}
if (!sqlRead.IsDBNull(8))
{
ChequeBooksEntity.CHEQUENUMSTART = sqlRead.GetString(8);
}
if (!sqlRead.IsDBNull(9))
{
ChequeBooksEntity.CHEQUENUMEND = sqlRead.GetString(9);
}
if (!sqlRead.IsDBNull(10))
{
ChequeBooksEntity.CHEQUETOTAL = sqlRead.GetInt32(10);
}
if (!sqlRead.IsDBNull(11))
{
ChequeBooksEntity.IsLock = sqlRead.GetBoolean(11);
}
if (!sqlRead.IsDBNull(12))
{
ChequeBooksEntity.IsDelete = sqlRead.GetBoolean(12);
}
if (!sqlRead.IsDBNull(13))
{
ChequeBooksEntity.DeleteUser = sqlRead.GetString(13);
}
if (!sqlRead.IsDBNull(14))
{
ChequeBooksEntity.DeleteTime = sqlRead.GetDateTime(14);
}
if (!sqlRead.IsDBNull(15))
{
ChequeBooksEntity.Type = sqlRead.GetInt32(15);
}
if (!sqlRead.IsDBNull(16))
{
ChequeBooksEntity.CompanyID = sqlRead.GetString(16);
}
if (!sqlRead.IsDBNull(17))
{
ChequeBooksEntity.CURRENCY = sqlRead.GetString(17);
}
}
}
catch (Exception execError)
{
throw execError;
}
}
return ChequeBooksEntity;
}
#endregion
#region 获取当前可开支票信息
/// <summary>
/// 获取当前可开支票信息
/// </summary>
/// <returns>返回实体类ChequeItemsEntity</returns>
public ChequeItemsEntity GetCurrentBookItem()
{
ChequeItemsEntity ChequeItemsEntity = null;
using (SqlDataReader sqlRead = SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, SQL_SELECT_CURRENT_Cheque_BOOK_ITEM, null))
{
try
{
while (sqlRead.Read())
{
ChequeItemsEntity = new ChequeItemsEntity();
if (!sqlRead.IsDBNull(0))
{
ChequeItemsEntity.GID = sqlRead.GetString(0);
}
if (!sqlRead.IsDBNull(1))
{
ChequeItemsEntity.BookID = sqlRead.GetString(1);
}
if (!sqlRead.IsDBNull(2))
{
ChequeItemsEntity.ChequeNum = sqlRead.GetString(2);
}
if (!sqlRead.IsDBNull(3))
{
ChequeItemsEntity.CreateUser = sqlRead.GetString(3);
}
if (!sqlRead.IsDBNull(4))
{
ChequeItemsEntity.CreateTime = sqlRead.GetDateTime(4);
}
if (!sqlRead.IsDBNull(5))
{
ChequeItemsEntity.IsLock = sqlRead.GetBoolean(5);
}
if (!sqlRead.IsDBNull(6))
{
ChequeItemsEntity.IsDelete = sqlRead.GetBoolean(6);
}
if (!sqlRead.IsDBNull(7))
{
ChequeItemsEntity.DeleteUser = sqlRead.GetString(7);
}
if (!sqlRead.IsDBNull(8))
{
ChequeItemsEntity.DeleteTime = sqlRead.GetDateTime(8);
}
if (!sqlRead.IsDBNull(9))
{
ChequeItemsEntity.IsMakeOut = sqlRead.GetBoolean(9);
}
if (!sqlRead.IsDBNull(10))
{
ChequeItemsEntity.MAKEOUTUSER = sqlRead.GetString(10);
}
if (!sqlRead.IsDBNull(11))
{
ChequeItemsEntity.MAKEOUTTIME = sqlRead.GetDateTime(11);
}
}
}
catch (Exception execError)
{
throw execError;
}
}
return ChequeItemsEntity;
}
#endregion
#region 插入支票信息(事务控制)
/// <summary>
/// 插入支票信息(事务控制)
/// </summary>
/// <param name="tempChequeBooksEntity">支票实体类</param>
/// <returns>值1表示插入成功 值不等于1表示插入失败</returns>
public int InsertChequeBook(ChequeBooksEntity tempChequeBooksEntity)
{
int iResult = 0;
using (SqlTransaction sqlTran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction))
{
try
{
SqlParameter[] bookParms = new SqlParameter[] {
new SqlParameter(PARM_Cheque_BOOK_GID,SqlDbType.VarChar,36),
new SqlParameter(PARM_Cheque_BOOK_NAME,SqlDbType.VarChar,50),
new SqlParameter(PARM_Cheque_BOOK_DESCRIPTION,SqlDbType.VarChar,50),
new SqlParameter(PARM_Cheque_BOOK_CREATE_USER,SqlDbType.VarChar,36),
new SqlParameter(PARM_Cheque_BOOK_Cheque_CODE,SqlDbType.VarChar,200),
new SqlParameter(PARM_Cheque_BOOK_Cheque_NUM_START,SqlDbType.VarChar,200),
new SqlParameter(PARM_Cheque_BOOK_Cheque_NUM_END,SqlDbType.VarChar,200),
new SqlParameter(PARM_Cheque_BOOK_Cheque_TOTAL,SqlDbType.Int),
new SqlParameter(PARM_Cheque_BOOK_IS_LOCK,SqlDbType.Bit),
new SqlParameter(PARM_Cheque_BOOK_COMPANY_ID,SqlDbType.VarChar,36),
new SqlParameter(PARM_Cheque_BOOK_TYPE,SqlDbType.Int),
new SqlParameter("@CURRENCY",SqlDbType.VarChar,20)
};
bookParms[0].Value = tempChequeBooksEntity.GID;
bookParms[1].Value = tempChequeBooksEntity.Name;
bookParms[2].Value = tempChequeBooksEntity.Description;
bookParms[3].Value = tempChequeBooksEntity.CreateUser;
bookParms[4].Value = tempChequeBooksEntity.CHEQUECODE;
bookParms[5].Value = tempChequeBooksEntity.CHEQUENUMSTART;
bookParms[6].Value = tempChequeBooksEntity.CHEQUENUMEND;
bookParms[7].Value = tempChequeBooksEntity.CHEQUETOTAL;
bookParms[8].Value = tempChequeBooksEntity.IsLock;
bookParms[9].Value = tempChequeBooksEntity.CompanyID;
bookParms[10].Value = tempChequeBooksEntity.Type;
bookParms[11].Value = tempChequeBooksEntity.CURRENCY;
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, SQL_INSERT_Cheque_BOOK, bookParms);
SqlParameter[] itemParms = new SqlParameter[] {
new SqlParameter(PARM_Cheque_BOOK_ITEM_GID,SqlDbType.VarChar,36),
new SqlParameter(PARM_Cheque_BOOK_ITEM_BOOK_ID,SqlDbType.VarChar,36),
new SqlParameter(PARM_Cheque_BOOK_ITEM_Cheque_NUM,SqlDbType.VarChar,200),
new SqlParameter(PARM_Cheque_BOOK_ITEM_CREATE_USER,SqlDbType.VarChar,36),
new SqlParameter(PARM_Cheque_BOOK_ITEM_IS_LOCK,SqlDbType.Bit),
new SqlParameter(PARM_Cheque_BOOK_ITEM_IS_MAKE_OUT,SqlDbType.Bit)
};
SqlParameter[] sameParms = new SqlParameter[] {
new SqlParameter(PARM_Cheque_BOOK_ITEM_Cheque_NUM,SqlDbType.VarChar,200)
};
foreach (ChequeItemsEntity itemEntity in tempChequeBooksEntity.ChequeItemsEntities)
{
sameParms[0].Value = itemEntity.ChequeNum;
int iSameStatus = (int)SqlHelper.ExecuteScalar(sqlTran, CommandType.Text, SQL_SELECT_SAME_Cheque_NUM, sameParms);
if (iSameStatus > 0)
{
throw new Exception();
}
itemParms[0].Value = itemEntity.GID;
itemParms[1].Value = itemEntity.BookID;
itemParms[2].Value = itemEntity.ChequeNum;
itemParms[3].Value = itemEntity.CreateUser;
itemParms[4].Value = itemEntity.IsLock;
itemParms[5].Value = itemEntity.IsMakeOut;
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, SQL_INSERT_Cheque_BOOK_ITEM, itemParms);
}
//事务提交
sqlTran.Commit();
iResult = 1;//状态为1表示插入成功
}
catch (Exception execError)
{
iResult = -1;//有异常,插入失败
sqlTran.Rollback();
iResult = -2;//插入异常,事务已回滚成功
throw execError;
}
finally
{
SqlHelper.CloseConnection();
}
}
return iResult;
}
#endregion
#region 获取SQL语句查询数据集
/// <summary>
/// 获取SQL语句查询数据集
/// </summary>
/// <param name="strSql"></param>
/// <returns></returns>
public DataSet GetExcuteSql(string strSql)
{
DataSet tempSet = new DataSet();
tempSet = SqlHelper.ExecuteDataset(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, strSql);
return tempSet;
}
#endregion
public int DeleteChequeBook(string tempBookID)
{
int iResult = 0;
return iResult;
}
}
}