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/Areas/OA/DAL/CwVouchers/CwVouchersDAL.cs

441 lines
24 KiB
C#

2 years ago
using System;
using System.Data;
using System.Collections.Generic;
using System.Text;
using DSWeb.Areas.Import.Models.CwVouchers;
using DSWeb.Areas.Import.Models.CwVouitems;
using DSWeb.Areas.Import.Models.CwDesign;
using DSWeb.Areas.Import.Models.CWAccitems;
using Microsoft.Practices.EnterpriseLibrary.Data;
using System.Data.SqlClient;
using WebSqlHelper;
using HcUtility.Comm;
using DSWeb.EntityDA;
namespace DSWeb.Areas.OA.DAL.CwVouchersDAL
{
public class CwVouchersDAL
{
#region GetCwDesign
static public CwDesign GetCwDesign()
{
var strSql = new StringBuilder();
strSql.Append("Select GID,FSOFTCODE,TVW,CPVW,CRTW,BPVW,BRTW,ISTCOIIED,ISUAPGE,AMCODE,CANAME,SANAME,DANAME,PANAEM,AFFIXNO,ISATTNOTCVVGV ");
strSql.Append(",ISATBGV,ISMGSC,ISVBM,ISCLIENTNAME,ISCOTCODE,ISCUSTNO,ISMBLNO,ISVESSEL,ISVOYNO,ISETD,ISRPCLIENTNAME,ISRPCOTCODE");
strSql.Append(",ISRPMBLNO,ISRPCUSTNO,ISRPVESSEL,ISRPVOYNO,ISRPETD,AR,ARFC,AP,APFC,MBINCOME,MBSPENDING,TMFCI,TMSFC");
strSql.Append(",AABWI,AMBS,AMFCI,AMSFC,OTHERR,OTHERP,EGOL,APMBSPENDING,ISAPMBSPENDING,APTMSFC,ISAPTMSFC,ISSETTLEMENTS");
strSql.Append(" from cw_design ");
Database db = DatabaseFactory.CreateDatabase();
var evData = new CwDesign();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
evData.GID = Convert.ToString(reader["GID"]);
evData.FSOFTCODE = Convert.ToInt16(reader["FSOFTCODE"]);
evData.TVW = Convert.ToString(reader["TVW"]);
evData.CPVW = Convert.ToString(reader["CPVW"]);
evData.CRTW = Convert.ToString(reader["CRTW"]);
evData.BPVW = Convert.ToString(reader["BPVW"]);
evData.BRTW = Convert.ToString(reader["BRTW"]);
evData.ISTCOIIED = Convert.ToBoolean(reader["ISTCOIIED"]);
evData.ISUAPGE = Convert.ToBoolean(reader["ISUAPGE"]);
evData.AMCODE = Convert.ToInt16(reader["AMCODE"]);
evData.CANAME = Convert.ToString(reader["CANAME"]);
evData.SANAME = Convert.ToString(reader["SANAME"]);
evData.DANAME = Convert.ToString(reader["DANAME"]);
evData.PANAEM = Convert.ToString(reader["PANAEM"]);
evData.AFFIXNO = Convert.ToInt16(reader["AFFIXNO"]);
evData.ISATTNOTCVVGV = Convert.ToBoolean(reader["ISATTNOTCVVGV"]);
evData.ISATBGV = Convert.ToBoolean(reader["ISATBGV"]);
evData.ISCLIENTNAME = Convert.ToBoolean(reader["ISCLIENTNAME"]);
evData.ISCOTCODE = Convert.ToBoolean(reader["ISCOTCODE"]);
evData.ISCUSTNO = Convert.ToBoolean(reader["ISCUSTNO"]);
evData.ISMBLNO = Convert.ToBoolean(reader["ISMBLNO"]);
evData.ISVESSEL = Convert.ToBoolean(reader["ISVESSEL"]);
evData.ISVOYNO = Convert.ToBoolean(reader["ISVOYNO"]);
evData.ISETD = Convert.ToBoolean(reader["ISETD"]);
evData.ISRPCLIENTNAME = Convert.ToBoolean(reader["ISRPCLIENTNAME"]);
evData.ISRPCOTCODE = Convert.ToBoolean(reader["ISRPCOTCODE"]);
evData.ISRPMBLNO = Convert.ToBoolean(reader["ISRPMBLNO"]);
evData.ISRPCUSTNO = Convert.ToBoolean(reader["ISRPCUSTNO"]);
evData.ISRPVESSEL = Convert.ToBoolean(reader["ISRPVESSEL"]);
evData.ISRPVOYNO = Convert.ToBoolean(reader["ISRPVOYNO"]);
evData.ISRPETD = Convert.ToBoolean(reader["ISRPETD"]);
evData.ISAPMBSPENDING = Convert.ToBoolean(reader["ISAPMBSPENDING"]);
evData.ISAPTMSFC = Convert.ToBoolean(reader["ISAPTMSFC"]);
evData.ISSETTLEMENTS = Convert.ToBoolean(reader["ISSETTLEMENTS"]);
evData.AR = Convert.ToString(reader["AR"]);
evData.ARFC = Convert.ToString(reader["ARFC"]);
evData.AP = Convert.ToString(reader["AP"]);
evData.APFC = Convert.ToString(reader["APFC"]);
evData.MBINCOME = Convert.ToString(reader["MBINCOME"]);
evData.MBSPENDING = Convert.ToString(reader["MBSPENDING"]);
evData.TMFCI = Convert.ToString(reader["TMFCI"]);
evData.AABWI = Convert.ToString(reader["AABWI"]);
evData.AMBS = Convert.ToString(reader["AMBS"]);
evData.AMFCI = Convert.ToString(reader["AMFCI"]);
evData.AMSFC = Convert.ToString(reader["AMSFC"]);
evData.OTHERR = Convert.ToString(reader["OTHERR"]);
evData.OTHERP = Convert.ToString(reader["OTHERP"]);
evData.EGOL = Convert.ToString(reader["EGOL"]);
evData.APMBSPENDING = Convert.ToString(reader["APMBSPENDING"]);
evData.APTMSFC = Convert.ToString(reader["APTMSFC"]);
}
reader.Close();
}
return evData;
}
#endregion
#region GetCwAccitems
static public CWAccitems GetCwAccitems(string accid)
{
var strSql = new StringBuilder();
strSql.Append("Select GID,ACCID,ACCNAME,DC,DETAILED,ISFCY,ISDEPTACC,ISEMPLACC,ISCORPACC,ISITEMACC,REMARKS");
strSql.Append(" from cw_accitems ");
strSql.Append(" where ACCID='" + accid + "'");
Database db = DatabaseFactory.CreateDatabase();
var evData = new CWAccitems();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
evData.GID = Convert.ToString(reader["GID"]);
evData.ACCID = Convert.ToString(reader["ACCID"]);
evData.ACCNAME = Convert.ToString(reader["ACCNAME"]);
evData.DC = Convert.ToString(reader["DC"]);
evData.DETAILED = Convert.ToBoolean(reader["DETAILED"]);
evData.ISFCY = Convert.ToBoolean(reader["ISFCY"]);
evData.ISDEPTACC = Convert.ToBoolean(reader["ISDEPTACC"]);
evData.ISEMPLACC = Convert.ToBoolean(reader["ISEMPLACC"]);
evData.ISCORPACC = Convert.ToBoolean(reader["ISCORPACC"]);
evData.ISITEMACC = Convert.ToBoolean(reader["ISITEMACC"]);
evData.REMARKS = Convert.ToString(reader["REMARKS"]);
}
reader.Close();
}
return evData;
}
#endregion
//生成凭证 天津中物储 报销单用
static public DBResult InsertVoucher(CwVouchers CwVouchersEntity, List<CwVouitems> CwVouitemsEntities, string strTable, string strVOUALLNO, string strSel, string strUserID)
{
var result = new DBResult();
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 (CwVouitems 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
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);
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, sSql1, parameters1);
string sSql = "update " + strTable + " set ISVOU=1,VOUCHERNO='" + strVOUALLNO + "' where 1=1 " + strSel;
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, sSql, null);
//事务提交
sqlTran.Commit();
result.Success = true;
result.Message = "保存成功";
}
catch (Exception execError)
{
result.Success = false;
result.Message = "保存出现错误,请重试或联系系统管理员";
throw execError;
}
finally
{
SqlHelper.CloseConnection();
}
}
return result;
}
static public String getVOUNO(DataSet dsCwDesign, string strY, string strM)
{
T_ALL_DA T_ALL_DA = new EntityDA.T_ALL_DA();
string sVOUNO = "";
string strVOUNO = "select top 1 VOUNO from cw_vouchers where ACCYEAR='" + strY + "' and ACCMONTH='" + strM + "' order by VOUNO desc";
strVOUNO = T_ALL_DA.GetStrSQL("VOUNO", strVOUNO);
if (strVOUNO.Trim() == "")
{
strVOUNO = "0001";
DataSet ds = T_ALL_DA.GetAllSQL("select * from code_rule where RULENAME='凭证号' and RULETYPE=5");
if (ds != null)
{
if (ds.Tables[0].Rows.Count > 0)
{
if (ds.Tables[0].Rows[0]["RULENOSTART"].ToString().Trim() != "")
{
strVOUNO = ds.Tables[0].Rows[0]["RULENOSTART"].ToString().Trim();
}
}
}
}
else
{
string sljk = dsCwDesign.Tables[0].Rows[0]["ISFILLSERIALNO"].ToString().Trim();
if (dsCwDesign.Tables[0].Rows[0]["ISFILLSERIALNO"].ToString().Trim() == "True")
{
string strFILL = "select top 1 serialno from code_fill_serialno where ISDELETE=0 and tablename='cw_vouchers' and serialno like '%" + strY + strM + "%' and serialno not in (select VOUALLNO from cw_vouchers where (ISDELETE=0 or ISDELETE is null)) order by serialno";
strFILL = T_ALL_DA.GetStrSQL("serialno", strFILL);
if (strFILL.Trim() != "")
{
strVOUNO = strFILL.Trim().Substring(6);
return strVOUNO;
}
}
sVOUNO = (int.Parse(strVOUNO) + 1).ToString().Trim();
strVOUNO = sVOUNO;
for (int i = 0; i < 4 - sVOUNO.Length; i++)
{
strVOUNO = "0" + strVOUNO;
}
}
return strVOUNO;
}
static public DBResult SetFEEACCDATE(string ACCDATE, string strTable, string strSel)
{
var result = new DBResult();
using (SqlTransaction sqlTran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction))
{
try
{
var I_ACCDATE = "";
if (ACCDATE.Length >= 7)
{
I_ACCDATE = ACCDATE.Substring(0, 7);
}
string sSql = "update " + strTable + " set ACCDATE='" + I_ACCDATE + "' where 1=1 " + strSel;
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, sSql, null);
//事务提交
sqlTran.Commit();
result.Success = true;
result.Message = "保存成功";
}
catch (Exception execError)
{
result.Success = false;
result.Message = "保存出现错误,请重试或联系系统管理员";
throw execError;
}
finally
{
SqlHelper.CloseConnection();
}
}
return result;
}
#region 参照部分
#endregion
}
}