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.

803 lines
46 KiB
C#

using System;
using System.Text;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Data;
using DSWeb.Models;
using DSWeb.DataAccess;
namespace DSWeb.EntityDA
{
public class CwVouchersDA
{
/// <summary>
/// 增加一条数据
/// </summary>
public int Add(CwVouchersEntity model)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("insert into cw_vouchers(");
strSql.Append("ORDNO,FCY,QTY,VOUPROP,PREPARED,CHECKED,ENTERED,ERRMSG,ISDELETE,VOUNO,VKNO,{0}ACCYEAR,ACCMONTH,ATTACHS,AMTDR,AMTCR,VOUALLNO");//,DELETEUSER,DELETETIME
strSql.Append(") values (");
strSql.Append("@ORDNO,@FCY,@QTY,@VOUPROP,@PREPARED,@CHECKED,@ENTERED,@ERRMSG,@ISDELETE,@VOUNO,@VKNO,{1}@ACCYEAR,@ACCMONTH,@ATTACHS,@AMTDR,@AMTCR,@VOUALLNO");//,@DELETEUSER,@DELETETIME
strSql.Append(") ");
SqlParameter[] parameters = {
new SqlParameter("@ORDNO", SqlDbType.VarChar,36) ,
new SqlParameter("@FCY", SqlDbType.VarChar,1) ,
new SqlParameter("@QTY", SqlDbType.VarChar,1) ,
new SqlParameter("@VOUPROP", SqlDbType.VarChar,1) ,
new SqlParameter("@PREPARED", SqlDbType.VarChar,10) ,
new SqlParameter("@CHECKED", SqlDbType.VarChar,10) ,
new SqlParameter("@ENTERED", SqlDbType.VarChar,10) ,
new SqlParameter("@ERRMSG", SqlDbType.VarChar,6) ,
new SqlParameter("@ISDELETE", SqlDbType.Bit,1) ,
//new SqlParameter("@DELETEUSER", SqlDbType.VarChar,36) ,
//new SqlParameter("@DELETETIME", SqlDbType.DateTime) ,
new SqlParameter("@VOUNO", SqlDbType.VarChar,16) ,
new SqlParameter("@VKNO", SqlDbType.VarChar,8) ,
//new SqlParameter("@VOUDATE", SqlDbType.DateTime) ,
new SqlParameter("@ACCYEAR", SqlDbType.VarChar,4) ,
new SqlParameter("@ACCMONTH", SqlDbType.VarChar,2) ,
new SqlParameter("@ATTACHS", SqlDbType.Int,4) ,
new SqlParameter("@AMTDR", SqlDbType.Decimal,9) ,
new SqlParameter("@AMTCR", SqlDbType.Decimal,9) ,
new SqlParameter("@VOUALLNO", SqlDbType.VarChar,16)
};
parameters[0].Value = model.ORDNO;
parameters[1].Value = model.FCY;
parameters[2].Value = model.QTY;
parameters[3].Value = model.VOUPROP;
parameters[4].Value = model.PREPARED;
parameters[5].Value = model.CHECKED;
parameters[6].Value = model.ENTERED;
parameters[7].Value = model.ERRMSG;
parameters[8].Value = model.ISDELETE;
//parameters[9].Value = model.DELETEUSER;
//parameters[10].Value = model.DELETETIME;
parameters[9].Value = model.VOUNO;
parameters[10].Value = model.VKNO;
//parameters[11].Value = model.VOUDATE;
parameters[11].Value = model.ACCYEAR;
parameters[12].Value = model.ACCMONTH;
parameters[13].Value = model.ATTACHS;
parameters[14].Value = model.AMTDR;
parameters[15].Value = model.AMTCR;
parameters[16].Value = model.VOUALLNO;
//
string strVOUDATE = model.VOUDATE.ToString().IndexOf("0001")>-1 ? "" : "'" + model.VOUDATE.ToString() + "',";
string strVOUDATE_name = strVOUDATE.Equals("") ? "" : "VOUDATE,";
string strSqlInsert = String.Format(strSql.ToString(), strVOUDATE_name, strVOUDATE);
//
int iResult = 0;
using (SqlConnection conn = new SqlConnection(SqlHelper.ConnectionStringLocalTransaction))
{
int existVal = SqlHelper.ExecuteNonQuery(conn, CommandType.Text, strSqlInsert, 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;
}
/// <summary>
/// 更新一条数据
/// </summary>
public int Update(CwVouchersEntity model)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("update cw_vouchers set ");
strSql.Append(" ORDNO = @ORDNO , ");
strSql.Append(" FCY = @FCY , ");
strSql.Append(" QTY = @QTY , ");
strSql.Append(" VOUPROP = @VOUPROP , ");
strSql.Append(" PREPARED = @PREPARED , ");
strSql.Append(" CHECKED = @CHECKED , ");
strSql.Append(" ENTERED = @ENTERED , ");
strSql.Append(" ERRMSG = @ERRMSG , ");
//strSql.Append(" ISDELETE = @ISDELETE , ");
//strSql.Append(" DELETEUSER = @DELETEUSER , ");
//strSql.Append(" DELETETIME = @DELETETIME , ");
strSql.Append(" VOUNO = @VOUNO , ");
strSql.Append(" VKNO = @VKNO , ");
strSql.Append(" {0}{1} ");
strSql.Append(" ACCYEAR = @ACCYEAR , ");
strSql.Append(" ACCMONTH = @ACCMONTH , ");
strSql.Append(" ATTACHS = @ATTACHS , ");
strSql.Append(" AMTDR = @AMTDR , ");
strSql.Append(" AMTCR = @AMTCR , ");
strSql.Append(" VOUALLNO = @VOUALLNO ");
strSql.Append(" where ORDNO=@ORDNO ");
SqlParameter[] parameters = {
new SqlParameter("@ORDNO", SqlDbType.VarChar,36) ,
new SqlParameter("@FCY", SqlDbType.VarChar,1) ,
new SqlParameter("@QTY", SqlDbType.VarChar,1) ,
new SqlParameter("@VOUPROP", SqlDbType.VarChar,1) ,
new SqlParameter("@PREPARED", SqlDbType.VarChar,10) ,
new SqlParameter("@CHECKED", SqlDbType.VarChar,10) ,
new SqlParameter("@ENTERED", SqlDbType.VarChar,10) ,
new SqlParameter("@ERRMSG", SqlDbType.VarChar,6) ,
//new SqlParameter("@ISDELETE", SqlDbType.Bit,1) ,
//new SqlParameter("@DELETEUSER", SqlDbType.VarChar,36) ,
//new SqlParameter("@DELETETIME", SqlDbType.DateTime) ,
new SqlParameter("@VOUNO", SqlDbType.VarChar,16) ,
new SqlParameter("@VKNO", SqlDbType.VarChar,8) ,
//new SqlParameter("@VOUDATE", SqlDbType.DateTime) ,
new SqlParameter("@ACCYEAR", SqlDbType.VarChar,4) ,
new SqlParameter("@ACCMONTH", SqlDbType.VarChar,2) ,
new SqlParameter("@ATTACHS", SqlDbType.Int,4) ,
new SqlParameter("@AMTDR", SqlDbType.Decimal,9) ,
new SqlParameter("@AMTCR", SqlDbType.Decimal,9) ,
new SqlParameter("@VOUALLNO", SqlDbType.VarChar,16)
};
parameters[0].Value = model.ORDNO;
parameters[1].Value = model.FCY;
parameters[2].Value = model.QTY;
parameters[3].Value = model.VOUPROP;
parameters[4].Value = model.PREPARED;
parameters[5].Value = model.CHECKED;
parameters[6].Value = model.ENTERED;
parameters[7].Value = model.ERRMSG;
//parameters[8].Value = model.ISDELETE;
//parameters[9].Value = model.DELETEUSER;
//parameters[10].Value = model.DELETETIME;
parameters[8].Value = model.VOUNO;
parameters[9].Value = model.VKNO;
//parameters[10].Value = model.VOUDATE;
parameters[10].Value = model.ACCYEAR;
parameters[11].Value = model.ACCMONTH;
parameters[12].Value = model.ATTACHS;
parameters[13].Value = model.AMTDR;
parameters[14].Value = model.AMTCR;
parameters[15].Value = model.VOUALLNO;
//
string strVOUDATE = model.VOUDATE.ToString().IndexOf("0001")>-1 ? "null," : "'" + model.VOUDATE.ToString() + "',";
string strVOUDATE_name = "VOUDATE=";
string strSqlUpdate = String.Format(strSql.ToString(), strVOUDATE_name, strVOUDATE);
//
int iResult = 0;
using (SqlConnection conn = new SqlConnection(SqlHelper.ConnectionStringLocalTransaction))
{
int existVal = SqlHelper.ExecuteNonQuery(conn, CommandType.Text, strSqlUpdate, 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;
}
/// <summary>
/// 更新 金额
/// </summary>
public int UpdateAMT(CwVouchersEntity model)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("update cw_vouchers set ");
strSql.Append(" AMTDR = @AMTDR , ");
strSql.Append(" AMTCR = @AMTCR ");
strSql.Append(" where ORDNO=@ORDNO ");
SqlParameter[] parameters = {
new SqlParameter("@ORDNO", SqlDbType.VarChar,36) ,
new SqlParameter("@AMTDR", SqlDbType.Decimal,9) ,
new SqlParameter("@AMTCR", SqlDbType.Decimal,9)
};
parameters[0].Value = model.ORDNO;
parameters[1].Value = model.AMTDR;
parameters[2].Value = model.AMTCR;
//
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;
}
/// <summary>
/// 更新 凭证日期、制单人等数据
/// </summary>
public int UpdateOPDate(CwVouchersEntity model, string oldVOUALLNO)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("update cw_vouchers set ");
strSql.Append(" VOUDATE = @VOUDATE , ");
strSql.Append(" VOUNO = @VOUNO , ");
strSql.Append(" ACCYEAR = @ACCYEAR , ");
strSql.Append(" ACCMONTH = @ACCMONTH , ");
strSql.Append(" VOUALLNO = @VOUALLNO , ");
strSql.Append(" PREPARED = @PREPARED ");
strSql.Append(" where ORDNO=@ORDNO ");
SqlParameter[] parameters = {
new SqlParameter("@ORDNO", SqlDbType.VarChar,36) ,
new SqlParameter("@VOUDATE", SqlDbType.DateTime) ,
new SqlParameter("@VOUNO", SqlDbType.VarChar,16) ,
new SqlParameter("@ACCYEAR", SqlDbType.VarChar,4) ,
new SqlParameter("@ACCMONTH", SqlDbType.VarChar,2) ,
new SqlParameter("@VOUALLNO", SqlDbType.VarChar,16) ,
new SqlParameter("@PREPARED", SqlDbType.VarChar,10)
};
parameters[0].Value = model.ORDNO;
parameters[1].Value = model.VOUDATE;
parameters[2].Value = model.VOUNO;
parameters[3].Value = model.ACCYEAR;
parameters[4].Value = model.ACCMONTH;
parameters[5].Value = model.VOUALLNO;
parameters[6].Value = model.PREPARED;
//
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 sSql = "update ch_fee_settlement set VOUNO='" + model.VOUALLNO + "' where 1=1 and VOUNO='" + oldVOUALLNO + "'";
iResult = -4;//更新业务表的凭证相关字段
SqlHelper.ExecuteNonQuery(conn, CommandType.Text, sSql, null);
//
//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;
}
/// <summary>
/// 删除一条数据
/// </summary>
public int Delete(string ORDNO)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("delete from cw_vouchers where ORDNO=@ORDNO ");
SqlParameter[] parameters = {
new SqlParameter("@ORDNO", SqlDbType.VarChar,36) };
parameters[0].Value = ORDNO;
//
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 CwVouchersEntity GetModel(string ORDNO)
{
//初始化返回变量
CwVouchersEntity model = null;
StringBuilder strSql = new StringBuilder();
strSql.Append("select ORDNO,VOUNO,VKNO,VOUDATE,ACCYEAR,ACCMONTH,ATTACHS,AMTDR,AMTCR,FCY,QTY,VOUPROP,PREPARED,CHECKED,ENTERED,ERRMSG,ISDELETE,DELETEUSER,DELETETIME,VOUALLNO from cw_vouchers ");
strSql.Append(" where ORDNO=@ORDNO ");
SqlParameter[] parameters = {
new SqlParameter("@ORDNO", SqlDbType.VarChar,36) };
parameters[0].Value = ORDNO;
//
using (SqlDataReader sqlRead = SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, strSql.ToString(), parameters))
{
try
{
model = new CwVouchersEntity();
//读取字段值
while (sqlRead.Read())
{
if (!sqlRead.IsDBNull(0)) { model.ORDNO = sqlRead.GetString(0); } // 唯一编码 newid()
if (!sqlRead.IsDBNull(1)) { model.VOUNO = sqlRead.GetString(1); } // 月初清零
if (!sqlRead.IsDBNull(2)) { model.VKNO = sqlRead.GetString(2); } // 凭证字
if (!sqlRead.IsDBNull(3)) { model.VOUDATE = sqlRead.GetDateTime(3); } // 凭证日期
if (!sqlRead.IsDBNull(4)) { model.ACCYEAR = sqlRead.GetString(4); } // 年
if (!sqlRead.IsDBNull(5)) { model.ACCMONTH = sqlRead.GetString(5); } // 月
if (!sqlRead.IsDBNull(6)) { model.ATTACHS = sqlRead.GetInt32(6); } // 附件(单据)数
if (!sqlRead.IsDBNull(7)) { model.AMTDR = sqlRead.GetDecimal(7); } // 本位币借方
if (!sqlRead.IsDBNull(8)) { model.AMTCR = sqlRead.GetDecimal(8); } // 本位币贷方
if (!sqlRead.IsDBNull(9)) { model.FCY = sqlRead.GetString(9); } // 是否含有外币科目
if (!sqlRead.IsDBNull(10)) { model.QTY = sqlRead.GetString(10); } // 是否含有数量科目
if (!sqlRead.IsDBNull(11)) { model.VOUPROP = sqlRead.GetString(11); } // 凭证属性
if (!sqlRead.IsDBNull(12)) { model.PREPARED = sqlRead.GetString(12); } // 制单人
if (!sqlRead.IsDBNull(13)) { model.CHECKED = sqlRead.GetString(13); } // 审核人
if (!sqlRead.IsDBNull(14)) { model.ENTERED = sqlRead.GetString(14); } // 记账人
if (!sqlRead.IsDBNull(15)) { model.ERRMSG = sqlRead.GetString(15); } // 错误信息
if (!sqlRead.IsDBNull(16)) { model.ISDELETE = sqlRead.GetBoolean(16); } // 是否废除
if (!sqlRead.IsDBNull(17)) { model.DELETEUSER = sqlRead.GetString(17); } // 废除操作人
if (!sqlRead.IsDBNull(18)) { model.DELETETIME = sqlRead.GetDateTime(18); } // 废除时间
if (!sqlRead.IsDBNull(19)) { model.VOUALLNO = sqlRead.GetString(19); } // 凭证号
}
}
catch (Exception exceError)
{
//抛出异常
throw exceError;
}
}
return model;
}
/// <summary>
/// 获得数据列表
/// </summary>
public DataSet GetList(string strWhere)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select * FROM cw_vouchers ");
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;
}
/// <summary>
/// 用事务执行保存流程
/// </summary>
/// <param name="CwVouchersEntity">一条主表信息</param>
/// <param name="CwVouitemsEntities">明细表列表</param>
/// <param name="strTable">业务表名例如op_seae</param>
/// <param name="strVOUNO">凭证号</param>
/// <param name="strSel">业务表更新条件</param>
/// <param name="strUserID">操作人</param>
/// <returns></returns>
public int setInsertAll(CwVouchersEntity CwVouchersEntity, IList<CwVouitemsEntity> CwVouitemsEntities, string strTable, string strVOUALLNO, string strSel, string strUserID, int iFeedo)
{
int iResult = 0;
using (SqlTransaction sqlTran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction))
{
try
{
//将明细插入表
StringBuilder strSql = new StringBuilder();
strSql.Append("insert into cw_vouitems(");
strSql.Append("GID,AMTDR,AMTCR,ISFCY,FCYNO,FCYEXRATE,FCYDR,FCYCR,QTYUNIT,QTYDR,QTYCR,ORDNO,EXPLAN,ISDEPTACC,ISEMPLACC,ISCORPACC,ISITEMACC,DEPTID,EMPLID,CORPID,PITEMID,ITEMID,ITEMNO,FIELD10,FIELD9,FIELD8,FIELD7,FIELD6,FIELD5,FIELD4,FIELD3,FIELD2,FIELD1,ACCID,ISSYS,FSETTLCODE,FSETTLENO,MODIFIEDUSER,MODIFIEDTIME,PACCID,ACCNAME,PROPERTY,GRADE,DC,CUSTOMERNAME,SALE,BLNO");
strSql.Append(") values (");
strSql.Append("newid(),@AMTDR,@AMTCR,@ISFCY,@FCYNO,@FCYEXRATE,@FCYDR,@FCYCR,@QTYUNIT,@QTYDR,@QTYCR,@ORDNO,@EXPLAN,@ISDEPTACC,@ISEMPLACC,@ISCORPACC,@ISITEMACC,@DEPTID,@EMPLID,@CORPID,@PITEMID,@ITEMID,@ITEMNO,@FIELD10,@FIELD9,@FIELD8,@FIELD7,@FIELD6,@FIELD5,@FIELD4,@FIELD3,@FIELD2,@FIELD1,@ACCID,@ISSYS,@FSETTLCODE,@FSETTLENO,@MODIFIEDUSER,getdate(),@PACCID,@ACCNAME,@PROPERTY,@GRADE,@DC,@CUSTOMERNAME,@SALE,@BLNO");
strSql.Append(") ");
#region 插入明细表
SqlParameter[] parameters = new SqlParameter[]{
new SqlParameter("@AMTDR", SqlDbType.Decimal,9) ,
new SqlParameter("@AMTCR", SqlDbType.Decimal,9) ,
new SqlParameter("@ISFCY", SqlDbType.Bit,1) ,
new SqlParameter("@FCYNO", SqlDbType.VarChar,8) ,
new SqlParameter("@FCYEXRATE", SqlDbType.Decimal,9) ,
new SqlParameter("@FCYDR", SqlDbType.Decimal,9) ,
new SqlParameter("@FCYCR", SqlDbType.Decimal,9) ,
new SqlParameter("@QTYUNIT", SqlDbType.VarChar,10) ,
new SqlParameter("@QTYDR", SqlDbType.Decimal,9) ,
new SqlParameter("@QTYCR", SqlDbType.Decimal,9) ,
new SqlParameter("@ORDNO", SqlDbType.VarChar,36) ,
new SqlParameter("@EXPLAN", SqlDbType.VarChar,60) ,
new SqlParameter("@ISDEPTACC", SqlDbType.Bit,1) ,
new SqlParameter("@ISEMPLACC", SqlDbType.Bit,1) ,
new SqlParameter("@ISCORPACC", SqlDbType.Bit,1) ,
new SqlParameter("@ISITEMACC", SqlDbType.Bit,1) ,
new SqlParameter("@DEPTID", SqlDbType.VarChar,18) ,
new SqlParameter("@EMPLID", SqlDbType.VarChar,18) ,
new SqlParameter("@CORPID", SqlDbType.VarChar,18) ,
new SqlParameter("@PITEMID", SqlDbType.Int,4) ,
new SqlParameter("@ITEMID", SqlDbType.VarChar,50) ,
new SqlParameter("@ITEMNO", SqlDbType.Int,4) ,
new SqlParameter("@FIELD10", SqlDbType.VarChar,50) ,
new SqlParameter("@FIELD9", SqlDbType.VarChar,50) ,
new SqlParameter("@FIELD8", SqlDbType.VarChar,50) ,
new SqlParameter("@FIELD7", SqlDbType.VarChar,50) ,
new SqlParameter("@FIELD6", SqlDbType.VarChar,50) ,
new SqlParameter("@FIELD5", SqlDbType.VarChar,50) ,
new SqlParameter("@FIELD4", SqlDbType.VarChar,50) ,
new SqlParameter("@FIELD3", SqlDbType.VarChar,50) ,
new SqlParameter("@FIELD2", SqlDbType.VarChar,50) ,
new SqlParameter("@FIELD1", SqlDbType.VarChar,50) ,
new SqlParameter("@ACCID", SqlDbType.VarChar,16) ,
new SqlParameter("@ISSYS", SqlDbType.Bit,1) ,
new SqlParameter("@FSETTLCODE", SqlDbType.VarChar,20) ,
new SqlParameter("@FSETTLENO", SqlDbType.VarChar,20) ,
new SqlParameter("@MODIFIEDUSER", SqlDbType.VarChar,36) ,
//new SqlParameter("@MODIFIEDTIME", SqlDbType.DateTime) ,
new SqlParameter("@PACCID", SqlDbType.VarChar,16) ,
new SqlParameter("@ACCNAME", SqlDbType.VarChar,60) ,
new SqlParameter("@PROPERTY", SqlDbType.Int,4) ,
new SqlParameter("@GRADE", SqlDbType.Int,4) ,
new SqlParameter("@DC", SqlDbType.VarChar,1),
new SqlParameter("@CUSTOMERNAME", SqlDbType.VarChar,20),
new SqlParameter("@SALE", SqlDbType.VarChar,10),
new SqlParameter("@BLNO", SqlDbType.VarChar,30)
};
#endregion
foreach (CwVouitemsEntity model in CwVouitemsEntities)
{
#region 插入明细表参数赋值
//parameters[0].Value = model.GID;
parameters[0].Value = model.AMTDR;
parameters[1].Value = model.AMTCR;
parameters[2].Value = model.ISFCY;
parameters[3].Value = model.FCYNO;
parameters[4].Value = model.FCYEXRATE;
parameters[5].Value = model.FCYDR;
parameters[6].Value = model.FCYCR;
parameters[7].Value = model.QTYUNIT;
parameters[8].Value = model.QTYDR;
parameters[9].Value = model.QTYCR;
parameters[10].Value = model.ORDNO;
parameters[11].Value = model.EXPLAN;
parameters[12].Value = model.ISDEPTACC;
parameters[13].Value = model.ISEMPLACC;
parameters[14].Value = model.ISCORPACC;
parameters[15].Value = model.ISITEMACC;
parameters[16].Value = model.DEPTID;
parameters[17].Value = model.EMPLID;
parameters[18].Value = model.CORPID;
parameters[19].Value = model.PITEMID;
parameters[20].Value = model.ITEMID;
parameters[21].Value = model.ITEMNO;
parameters[22].Value = model.FIELD10;
parameters[23].Value = model.FIELD9;
parameters[24].Value = model.FIELD8;
parameters[25].Value = model.FIELD7;
parameters[26].Value = model.FIELD6;
parameters[27].Value = model.FIELD5;
parameters[28].Value = model.FIELD4;
parameters[29].Value = model.FIELD3;
parameters[30].Value = model.FIELD2;
parameters[31].Value = model.FIELD1;
parameters[32].Value = model.ACCID;
parameters[33].Value = model.ISSYS;
parameters[34].Value = model.FSETTLCODE;
parameters[35].Value = model.FSETTLENO;
parameters[36].Value = model.MODIFIEDUSER;
//parameters[37].Value = model.MODIFIEDTIME;
parameters[37].Value = model.PACCID;
parameters[38].Value = model.ACCNAME;
parameters[39].Value = model.PROPERTY;
parameters[40].Value = model.GRADE;
parameters[41].Value = model.DC;
parameters[42].Value = model.CUSTOMERNAME;
parameters[43].Value = model.SALE;
parameters[44].Value = model.BLNO;
#endregion
iResult = -2;//插入明细表
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, strSql.ToString(), parameters);
}
//插入主表
StringBuilder strSql1 = new StringBuilder();
strSql1.Append("insert into cw_vouchers(");
strSql1.Append("ORDNO,FCY,QTY,VOUPROP,PREPARED,CHECKED,ENTERED,ERRMSG,ISDELETE,VOUNO,VKNO,{0}ACCYEAR,ACCMONTH,ATTACHS,AMTDR,AMTCR,VOUALLNO");//,DELETEUSER,DELETETIME
strSql1.Append(") values (");
strSql1.Append("@ORDNO,@FCY,@QTY,@VOUPROP,@PREPARED,@CHECKED,@ENTERED,@ERRMSG,@ISDELETE,@VOUNO,@VKNO,{1}@ACCYEAR,@ACCMONTH,@ATTACHS,@AMTDR,@AMTCR,@VOUALLNO");//,@DELETEUSER,@DELETETIME
strSql1.Append(") ");
#region 插入主表
SqlParameter[] parameters1 = {
new SqlParameter("@ORDNO", SqlDbType.VarChar,36) ,
new SqlParameter("@FCY", SqlDbType.VarChar,1) ,
new SqlParameter("@QTY", SqlDbType.VarChar,1) ,
new SqlParameter("@VOUPROP", SqlDbType.VarChar,1) ,
new SqlParameter("@PREPARED", SqlDbType.VarChar,10) ,
new SqlParameter("@CHECKED", SqlDbType.VarChar,10) ,
new SqlParameter("@ENTERED", SqlDbType.VarChar,10) ,
new SqlParameter("@ERRMSG", SqlDbType.VarChar,6) ,
new SqlParameter("@ISDELETE", SqlDbType.Bit,1) ,
//new SqlParameter("@DELETEUSER", SqlDbType.VarChar,36) ,
//new SqlParameter("@DELETETIME", SqlDbType.DateTime) ,
new SqlParameter("@VOUNO", SqlDbType.VarChar,16) ,
new SqlParameter("@VKNO", SqlDbType.VarChar,8) ,
//new SqlParameter("@VOUDATE", SqlDbType.DateTime) ,
new SqlParameter("@ACCYEAR", SqlDbType.VarChar,4) ,
new SqlParameter("@ACCMONTH", SqlDbType.VarChar,2) ,
new SqlParameter("@ATTACHS", SqlDbType.Int,4) ,
new SqlParameter("@AMTDR", SqlDbType.Decimal,9) ,
new SqlParameter("@AMTCR", SqlDbType.Decimal,9) ,
new SqlParameter("@VOUALLNO", SqlDbType.VarChar,16)
};
#endregion
#region 插入主表参数赋值
parameters1[0].Value = CwVouchersEntity.ORDNO;
parameters1[1].Value = CwVouchersEntity.FCY;
parameters1[2].Value = CwVouchersEntity.QTY;
parameters1[3].Value = CwVouchersEntity.VOUPROP;
parameters1[4].Value = CwVouchersEntity.PREPARED;
parameters1[5].Value = CwVouchersEntity.CHECKED;
parameters1[6].Value = CwVouchersEntity.ENTERED;
parameters1[7].Value = CwVouchersEntity.ERRMSG;
parameters1[8].Value = CwVouchersEntity.ISDELETE;
//parameters1[9].Value = CwVouchersEntity.DELETEUSER;
//parameters1[10].Value = CwVouchersEntity.DELETETIME;
parameters1[9].Value = CwVouchersEntity.VOUNO;
parameters1[10].Value = CwVouchersEntity.VKNO;
//parameters1[11].Value = CwVouchersEntity.VOUDATE;
parameters1[11].Value = CwVouchersEntity.ACCYEAR;
parameters1[12].Value = CwVouchersEntity.ACCMONTH;
parameters1[13].Value = CwVouchersEntity.ATTACHS;
parameters1[14].Value = CwVouchersEntity.AMTDR;
parameters1[15].Value = CwVouchersEntity.AMTCR;
parameters1[16].Value = CwVouchersEntity.VOUALLNO;
#endregion
string strVOUDATE = CwVouchersEntity.VOUDATE.ToString().IndexOf("0001")>-1 ? "" : "'" + CwVouchersEntity.VOUDATE.ToString() + "',";
string strVOUDATE_name = strVOUDATE.Equals("") ? "" : "VOUDATE,";
string sSql1 = String.Format(strSql1.ToString(), strVOUDATE_name, strVOUDATE);
iResult = -3;//插入主表
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, sSql1, parameters1);
if (iFeedo==3)
{
//更新业务表的凭证相关字段
string sSql = "update " + strTable + " set VOUCHERNO='" + strVOUALLNO + "' where 1=1 " + strSel;
iResult = -4;//更新业务表的凭证相关字段
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, sSql, null);
}
else if (iFeedo==2)
{
//更新业务表的凭证相关字段
string sSql = "update " + strTable + " set VOUNO='" + strVOUALLNO + "' where 1=1 " + strSel;
iResult = -4;//更新业务表的凭证相关字段
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, sSql, null);
}
else if (iFeedo == 1)
{
//更新业务表的凭证相关字段
if (strTable == "v_op_bill")
{
string sSql = "update op_amend set ISVOU=1,VOUNO='" + strVOUALLNO + "' where 1=1 " + strSel;
iResult = -4;//更新业务表的凭证相关字段
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, sSql, null);
sSql = "update op_seae set ISVOU=1,VOUNO='" + strVOUALLNO + "' where 1=1 " + strSel;
iResult = -4;//更新业务表的凭证相关字段
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, sSql, null);
sSql = "update op_seai set ISVOU=1,VOUNO='" + strVOUALLNO + "' where 1=1 " + strSel;
iResult = -4;//更新业务表的凭证相关字段
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, sSql, null);
sSql = "update op_aire set ISVOU=1,VOUNO='" + strVOUALLNO + "' where 1=1 " + strSel;
iResult = -4;//更新业务表的凭证相关字段
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, sSql, null);
sSql = "update op_airi set ISVOU=1,VOUNO='" + strVOUALLNO + "' where 1=1 " + strSel;
iResult = -4;//更新业务表的凭证相关字段
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, sSql, null);
sSql = "update op_other set ISVOU=1,VOUNO='" + strVOUALLNO + "' where 1=1 " + strSel;
iResult = -4;//更新业务表的凭证相关字段
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, sSql, null);
sSql = "update op_apply set ISVOU=1,VOUNO='" + strVOUALLNO + "' where 1=1 " + strSel;
iResult = -4;//更新业务表的凭证相关字段
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, sSql, null);
sSql = "update op_railway set ISVOU=1,VOUNO='" + strVOUALLNO + "' where 1=1 " + strSel;
iResult = -4;//更新业务表的凭证相关字段
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, sSql, null);
//sSql = "update WMS set ISVOU=1,VOUNO='" + strVOUALLNO + "' where 1=1 " + strSel;
//iResult = -4;//更新业务表的凭证相关字段
//SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, sSql, null);
//sSql = "update WMS_OUT set ISVOU=1,VOUNO='" + strVOUALLNO + "' where 1=1 " + strSel;
//iResult = -4;//更新业务表的凭证相关字段
//SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, sSql, null);
//sSql = "update WMS_IN set ISVOU=1,VOUNO='" + strVOUALLNO + "' where 1=1 " + strSel;
//iResult = -4;//更新业务表的凭证相关字段
//SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, sSql, null);
}
else
{
string sSql = "update " + strTable + " set ISVOU=1,VOUNO='" + strVOUALLNO + "' where 1=1 " + strSel;
iResult = -4;//更新业务表的凭证相关字段
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, sSql, null);
}
}
//把从序号的漏号补号表中调用的凭证号设为删除状态
if (strVOUALLNO != "")
{
string sSql2 = "update [code_fill_serialno] set ISDELETE=1,DELETEUSER='" + strUserID + "',DELETETIME=getdate() where SERIALNO='" + strVOUALLNO + "'";
iResult = -5;//把从序号的漏号补号表中调用的凭证号设为删除状态
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, sSql2, null);
}
//事务提交
sqlTran.Commit();
iResult = 1;//状态为1表示插入成功
}
catch (Exception execError)
{
iResult = -1;//有异常,插入失败
sqlTran.Rollback();
iResult = -2;//插入异常,事务已回滚成功
throw execError;
}
finally
{
SqlHelper.CloseConnection();
}
}
return iResult;
}
/// <summary>
/// 删除主表+明细表数据,用事务
/// </summary>
/// <param name="strGids">多个gid组成的字符串例如 111,222,333</param>
/// <returns></returns>
public int DeleteAll(string sGids, string strUserID)
{
int iResult = 0;
string strGids = "'" + sGids.Trim().Replace(",", "','") + "'";
using (SqlTransaction sqlTran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction))
{
try
{
#region 2018年2月13日14:31:00 鼎世 李进举
string chfeehexiaoDelSql = " update ch_fee_hexiao set vouno ='' where vouno IN (select VOUALLNO from cw_vouchers where ordno IN (" + strGids + "))";
iResult = -8;//更新ch_fee_hexiao
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, chfeehexiaoDelSql, null);
#endregion
//更新海运出口业务表的凭证相关字段
string sSql = "update op_seae set ISVOU=0,VOUNO='' where 1=1 and VOUNO in(select VOUALLNO from cw_vouchers where ORDNO in (" + strGids + "))";
iResult = -2;//更新业务表的凭证相关字段
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, sSql, null);
//更新更改单表的凭证相关字段
sSql = "update op_amend set ISVOU=0,VOUNO='' where 1=1 and VOUNO in(select VOUALLNO from cw_vouchers where ORDNO in (" + strGids + "))";
iResult = -4;//更新业务表的凭证相关字段
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, sSql, null);
//更新更改单表的凭证相关字段
sSql = "update op_aire set ISVOU=0,VOUNO='' where 1=1 and VOUNO in(select VOUALLNO from cw_vouchers where ORDNO in (" + strGids + "))";
iResult = -4;//更新业务表的凭证相关字段
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, sSql, null);
//更新更改单表的凭证相关字段
sSql = "update op_airi set ISVOU=0,VOUNO='' where 1=1 and VOUNO in(select VOUALLNO from cw_vouchers where ORDNO in (" + strGids + "))";
iResult = -4;//更新业务表的凭证相关字段
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, sSql, null);
//更新海运进口业务表的凭证相关字段
sSql = "update op_seai set ISVOU=0,VOUNO='' where 1=1 and VOUNO in(select VOUALLNO from cw_vouchers where ORDNO in (" + strGids + "))";
iResult = -3;//更新业务表的凭证相关字段
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, sSql, null);
//更新海运进口业务表的凭证相关字段
sSql = "update op_other set ISVOU=0,VOUNO='' where 1=1 and VOUNO in(select VOUALLNO from cw_vouchers where ORDNO in (" + strGids + "))";
iResult = -3;//更新业务表的凭证相关字段
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, sSql, null);
//更新进口贸易业务表的凭证相关字段
sSql = "update ch_fee set ISVOU=0,VOUCHERNO='' where 1=1 and VOUCHERNO in(select VOUALLNO from cw_vouchers where ORDNO in (" + strGids + "))";
iResult = -8;//更新业务表的凭证相关字段
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, sSql, null);
//更新管理费用表的凭证相关字段
sSql = "update ch_fee_management set ISVOU=0,VOUCHERNO='' where 1=1 and VOUCHERNO in(select VOUALLNO from cw_vouchers where ORDNO in (" + strGids + "))";
iResult = -8;//更新业务表的凭证相关字段
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, sSql, null);
sSql = "update ch_fee_advance_payment set ISVOU=0,VOUCHERNO='' where 1=1 and VOUCHERNO in(select VOUALLNO from cw_vouchers where ORDNO in (" + strGids + ")) and (ISDELETE=0 or ISDELETE is null)";
iResult = -8;//更新业务表的凭证相关字段
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, sSql, null);
//更新报销单凭证相关字段
sSql = "update OA_Baoxiao set ISVOU=0,VOUCHERNO='' where 1=1 and VOUCHERNO in(select VOUALLNO from cw_vouchers where ORDNO in (" + strGids + "))";
iResult = -8;//更新业务表的凭证相关字段
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, sSql, null);
//更新结算表的凭证相关字段
sSql = "update ch_fee_settlement set VOUNO='' where 1=1 and VOUNO in(select VOUALLNO from cw_vouchers where ORDNO in (" + strGids + "))";
iResult = -4;//更新结算表的凭证相关字段
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, sSql, null);
//更新发票表的凭证相关字段
sSql = "update ch_fee_invoice set VOUCHERNO='' where 1=1 and VOUCHERNO in(select VOUALLNO from cw_vouchers where ORDNO in (" + strGids + "))";
iResult = -5;//更新结算表的凭证相关字段
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, sSql, null);
//把删除的凭证号插入序号的漏号补号表
sSql = "INSERT INTO [code_fill_serialno]([GID],[TABLENAME],[SERIALNO],[CREATEUSER],[CREATETIME],[ISDELETE],[DELETEUSER],[DELETETIME],STARTGID) "
+ "select newid(),'cw_vouchers',VOUALLNO,'" + strUserID + "',getdate(),0,'',getdate(),'' from cw_vouchers where ORDNO in (" + strGids + ")";
iResult = -8;//把删除的凭证号插入序号的漏号补号表
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, sSql, null);
sSql = "delete from cw_vouitems where ORDNO in (" + strGids + ")";
iResult = -6;//删除明细表
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, sSql, null);
sSql = "delete from cw_vouchers where ORDNO in (" + strGids + ")";
iResult = -7;//删除主表
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, sSql, null);
//事务提交
sqlTran.Commit();
iResult = 1;//状态为1表示插入成功
}
catch (Exception execError)
{
iResult = -1;//有异常,插入失败
sqlTran.Rollback();
iResult = -2;//插入异常,事务已回滚成功
throw execError;
}
finally
{
SqlHelper.CloseConnection();
}
}
return iResult;
}
//
}
}