From fa1340e960776dbc9638957b04fc346fab6bf1f9 Mon Sep 17 00:00:00 2001 From: "DESKTOP-DIHMM3I\\22375" Date: Tue, 26 Apr 2022 15:23:42 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=B0=E8=B4=A7=E5=8D=95=E5=A4=9A=E7=AB=99?= =?UTF-8?q?=E7=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ICSSoft.DataProject/CreatePOArrive.cs | 261 +++++++++++------- .../ICSSoft.ERP.WebAPI/Web.config | 2 +- .../ICSSoft.Entity/ICSPOArrive.cs | 1 + 3 files changed, 158 insertions(+), 106 deletions(-) diff --git a/ICSSoft.ERP.WebAPI/ICSSoft.DataProject/CreatePOArrive.cs b/ICSSoft.ERP.WebAPI/ICSSoft.DataProject/CreatePOArrive.cs index ecf05c1..4980924 100644 --- a/ICSSoft.ERP.WebAPI/ICSSoft.DataProject/CreatePOArrive.cs +++ b/ICSSoft.ERP.WebAPI/ICSSoft.DataProject/CreatePOArrive.cs @@ -15,6 +15,7 @@ namespace ICSSoft.DataProject { private static log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); private static string connString = System.Configuration.ConfigurationManager.AppSettings["ERPConnStr"]; + private static string ConnStr = System.Configuration.ConfigurationManager.AppSettings["ConnStr"]; private static string ERPDB = System.Configuration.ConfigurationManager.AppSettings["ERPDB"]; private static string Type = System.Configuration.ConfigurationManager.AppSettings["Type"]; //参数示例 @@ -49,17 +50,24 @@ namespace ICSSoft.DataProject throw new Exception("传送数据为空!"); } string res = string.Empty; - SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString); - conn.Open(); - SqlTransaction sqlTran = conn.BeginTransaction(); + SqlConnection conn = new SqlConnection(); + SqlCommand cmd = new SqlCommand(); - cmd.Transaction = sqlTran; - cmd.Connection = conn; - try + + string sql = string.Empty; + foreach (ICSPOArrive info in infos) { - string sql = string.Empty; - foreach (ICSPOArrive info in infos) + + try { + connString = string.Format(connString, info.WorkPoint); + conn = new System.Data.SqlClient.SqlConnection(connString); + conn.Open(); + SqlTransaction sqlTran = conn.BeginTransaction(); + cmd = new SqlCommand(); + cmd.Transaction = sqlTran; + cmd.Connection = conn; + if (info.MTime < new DateTime(2000, 01, 01)) throw new Exception("请输入正确的操作时间:" + info.MTime); sql = @" SELECT A.ID,A.cCode,A.cVenCode,D.cVenName,C.CDEPNAME,A.cDepCode,C.cDepName,A.cpocode,A.cMaker,A.cMakeTime,A.cverifier,A.caudittime, @@ -83,24 +91,26 @@ namespace ICSSoft.DataProject sql = string.Format(sql, info.DNCode, info.MTime, info.User); dt = DBHelper.SQlReturnData(sql, cmd); json = JsonConvert.SerializeObject(dt); + cmd.Transaction.Commit(); } - cmd.Transaction.Commit(); - return json; - } - catch (Exception ex) - { - cmd.Transaction.Rollback(); - log.Error(ex.Message); - throw new Exception(ex.Message); - } - finally - { - if (conn.State == ConnectionState.Open) + catch (Exception ex) { - conn.Close(); + cmd.Transaction.Rollback(); + log.Error(ex.Message); + throw new Exception(ex.Message); + } + finally + { + if (conn.State == ConnectionState.Open) + { + conn.Close(); + } + conn.Dispose(); } - conn.Dispose(); } + + return json; + } /// /// 生成到货单 @@ -114,7 +124,7 @@ namespace ICSSoft.DataProject throw new Exception("传送数据为空!"); } string res = string.Empty; - SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString); + SqlConnection conn = new System.Data.SqlClient.SqlConnection(ConnStr); conn.Open(); SqlTransaction sqlTran = conn.BeginTransaction(); SqlCommand cmd = new SqlCommand(); @@ -125,23 +135,23 @@ namespace ICSSoft.DataProject string sql = string.Empty; foreach (ICSPOArrive info in infos) { - if (info.MTime0) + sql = @"IF EXISTS(SELECT LOTNO FROM ICSASNDETAIL WHERE LOTNO='{1}' AND STNO='{2}' AND ISNULL(RECEIVEQTY,0)>0) and WorkPoint='{3}' RAISERROR('条码:{1},已到货不能重复到货!',16,1) - UPDATE ICSASNDETAIL SET RECEIVEQTY=ISNULL(RECEIVEQTY,0)+{0} WHERE LOTNO='{1}' AND STNO='{2}' + UPDATE ICSASNDETAIL SET RECEIVEQTY=ISNULL(RECEIVEQTY,0)+{0} WHERE LOTNO='{1}' AND STNO='{2}' and WorkPoint='{3}' --IF EXISTS(SELECT LOTNO FROM ICSASNDETAIL WHERE LOTNO='{1}' AND STNO='{2}' AND RECEIVEQTY>PLANQTY) -- RAISERROR('条码:{1},到货数量不能大于送货数量!',16,1)"; - sql = string.Format(sql, detail.Quantity, detail.LOTNO,info.ASNNO); - DBHelper.CmdExecuteNonQuery(sql, cmd, "送货单号:"+ info.ASNNO+",条码:"+ detail.LOTNO+"未查询到对应数据!"); + sql = string.Format(sql, detail.Quantity, detail.LOTNO, info.ASNNO, info.WorkPoint); + DBHelper.CmdExecuteNonQuery(sql, cmd, "送货单号:" + info.ASNNO + ",条码:" + detail.LOTNO + "未查询到对应数据!"); Lotnos += "'" + detail.LOTNO + "',"; } if (string.IsNullOrWhiteSpace(Lotnos)) - throw new Exception("送货单号:" + info.ASNNO+",无条码信息!"); - CreatePUArrive( infos); + throw new Exception("送货单号:" + info.ASNNO + ",无条码信息!"); + CreatePUArrive(infos); } cmd.Transaction.Commit(); return res; @@ -168,52 +178,75 @@ namespace ICSSoft.DataProject /// /// /// - public string CreatePUArrive(List Bills) + public string CreatePUArrive(List Bills) { string res = string.Empty; - SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString); - conn.Open(); + string str = ""; DataTable dt = null; - SqlTransaction sqlTran = conn.BeginTransaction(); + + + SqlConnection conn = new SqlConnection(); + SqlCommand cmd = new SqlCommand(); - cmd.Transaction = sqlTran; - cmd.Connection = conn; + + + int num = 0; foreach (ICSPOArrive head in Bills) { - num= head.details.Count(); + num = head.details.Count(); + } - DateTime time = DateTime.Now; - Dictionary dic = DBHelper.GetAllCode("" + ERPDB + "", "PuArrival", "" + num + ""); - int iFatherId = Convert.ToInt32(dic["iFatherId"].ToString()); - int iChildId = Convert.ToInt32( dic["iChildId"].ToString()); - DateTime date=DateTime.Now; - string iBaseCodeLen = DBHelper.GetAllRDCode("26", "" + time + "","admin"); + //int iBaseCodeLen = Convert.ToInt32(dic["iBaseCodeLen"].ToString()); //int cVouchCodeBase = Convert.ToInt32(dic["cVouchCodeBase"].ToString()); List datas = new List(); string sql = ""; int irowno = 0; - try - { - foreach (ICSPOArrive head in Bills) + + foreach (ICSPOArrive head in Bills) + { + try { + connString = string.Format(connString, head.WorkPoint); + conn = new System.Data.SqlClient.SqlConnection(connString); + conn.Open(); + SqlTransaction sqlTran = conn.BeginTransaction(); + cmd = new SqlCommand(); + cmd.Transaction = sqlTran; + cmd.Connection = conn; + + + string[] ss = head.WorkPoint.Split('_'); + ERPDB = ss[1]; + + DateTime time = DateTime.Now; + Dictionary dic = DBHelper.GetAllCode("" + ERPDB + "", "PuArrival", "" + num + ""); + int iFatherId = Convert.ToInt32(dic["iFatherId"].ToString()); + int iChildId = Convert.ToInt32(dic["iChildId"].ToString()); + DateTime date = DateTime.Now; + string iBaseCodeLen = DBHelper.GetAllRDCode("26", "" + time + "", "admin"); + + + string DEF_ID = DBHelper.GetDefaultTemplate(Type, cmd); #region 主表 - sql = @"INSERT INTO PU_ArrivalVouch + sql = @"INSERT INTO dbo.PU_ArrivalVouch (iVTid, ID, cCode, cPTCode, dDate, cVenCode, cDepCode, cPersonCode, cPayCode, cexch_name, iExchRate, iTaxRate, cMemo, cBusType, cMaker, bNegative, iDiscountTaxType, iBillType, cMakeTime, cAuditDate, caudittime, cverifier, iverifystateex, IsWfControlled, iflowid, iPrintCount, cpocode) SELECT @iVTid, @ID, @cCode, cPTCode, CONVERT(NVARCHAR(10), GETDATE(), 23), cVenCode, cDepCode, cPersonCode, cPayCode, cexch_name, nflat, iTaxRate, cMemo, '普通采购', @User, 0, iDiscountTaxType, 0, GETDATE(), CONVERT(NVARCHAR(10), GETDATE(), 23), GETDATE(), @User, 2, 0, 0, iPrintCount, cPOID FROM PO_Pomain WHERE 1=1 AND POID = @POID "; + cmd.Parameters.Clear(); cmd.Parameters.Add(new SqlParameter("@iVTid", DEF_ID)); cmd.Parameters.Add(new SqlParameter("@ID", iFatherId)); cmd.Parameters.Add(new SqlParameter("@cCode", iBaseCodeLen)); cmd.Parameters.Add(new SqlParameter("@User", head.User)); cmd.Parameters.Add(new SqlParameter("@POID", head.POCode)); + //cmd.Parameters.Add(new SqlParameter("@dDate", data.dMate)); cmd.CommandText = sql; try @@ -252,7 +285,7 @@ FROM PO_Pomain WHERE 1=1 AND POID = @POID "; irowno += 1; sql = @" -INSERT INTO PU_ArrivalVouchs +INSERT INTO dbo.PU_ArrivalVouchs (Autoid, ID, cInvCode, iQuantity, iOriCost, iOriTaxCost, iOriMoney, iOriTaxPrice, iOriSum, iCost, iMoney, iTaxPrice, iSum, iTaxRate, iPOsID, fValidInQuan, fRealQuantity, fValidQuantity, fRetQuantity, fInValidInQuan, bGsp, fValidNum, fValidInNum, fRealNum, bTaxCost, SoType, fInvalidInNum, iinvexchrate, cordercode, RejectSource, iExpiratDateCalcu, iordertype, ivouchrowno, bgift, @@ -268,6 +301,7 @@ pd.ID, 0, @iQuantity, @iQuantity, 0, 0, 0, null, null, null, 1, @Batch, @cDefine37, null, null, null, null, null FROM PO_Podetails pd left join po_pomain b on pd.poid=b.poid WHERE pd.ID = @iPOsID "; + cmd.Parameters.Clear(); cmd.Parameters.Add(new SqlParameter("@iPOsID", body.PODetailID)); cmd.Parameters.Add(new SqlParameter("@Autoid", iChildId)); @@ -277,6 +311,7 @@ WHERE pd.ID = @iPOsID "; cmd.Parameters.Add(new SqlParameter("@cordercode", head.POCode)); cmd.Parameters.Add(new SqlParameter("@ivouchrowno", irowno)); cmd.Parameters.Add(new SqlParameter("@dPDate", head.MTime)); + if (cMassUnit == 1) { cmd.Parameters.Add(new SqlParameter("@dVDate", head.MTime.AddYears(iMassDate).Date)); @@ -332,21 +367,22 @@ LEFT JOIN dbo.Department C ON A.cDepCode = C.cDepCode LEFT JOIN dbo.Vendor D ON LEFT JOIN dbo.PO_Podetails E ON B.iPOsID = E.ID WHERE A.cverifier IS NOT NULL AND A.ID = '{0}' "; sql = string.Format(sql, iFatherId); dt = DBHelper.SQlReturnData(sql, cmd); - + str += JsonConvert.SerializeObject(dt); + cmd.Transaction.Commit(); + } + catch (Exception ex) + { + cmd.Transaction.Rollback(); + log.Error(ex.Message); + throw new Exception(ex.Message); } - str = JsonConvert.SerializeObject(dt); - cmd.Transaction.Commit(); - - } - catch (Exception ex) - { - cmd.Transaction.Rollback(); - log.Error(ex.Message); - throw new Exception(ex.Message); } + + + return str; } - + public string Approve(List infos) { List szJson = new List(); @@ -357,41 +393,49 @@ LEFT JOIN dbo.PO_Podetails E ON B.iPOsID = E.ID WHERE A.cverifier IS NOT NULL AN throw new Exception("传送数据为空!"); } string res = string.Empty; - SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString); - conn.Open(); - SqlTransaction sqlTran = conn.BeginTransaction(); + SqlConnection conn = new SqlConnection(); + SqlCommand cmd = new SqlCommand(); - cmd.Transaction = sqlTran; - cmd.Connection = conn; - try + + + string sql = string.Empty; + foreach (ICSPOArrive info in infos) { - string sql = string.Empty; - foreach (ICSPOArrive info in infos) + try { + connString = string.Format(connString, info.WorkPoint); + conn = new System.Data.SqlClient.SqlConnection(connString); + conn.Open(); + SqlTransaction sqlTran = conn.BeginTransaction(); + cmd = new SqlCommand(); + cmd.Transaction = sqlTran; + cmd.Connection = conn; if (info.MTime < new DateTime(2000, 01, 01)) throw new Exception("请输入正确的操作时间:" + info.MTime); sql = @"UPDATE dbo.PU_ArrivalVouch SET cVerifier ='" + info.User + @"' , cAuditTime=CONVERT(VARCHAR(50),GETDATE(),112),cAuditDate=GETDATE() WHERE ID='{0}'"; - sql = string.Format(sql,info.ID); + sql = string.Format(sql, info.ID); DBHelper.CmdExecuteNonQuery(sql, cmd, "未查询到对应数据!"); + cmd.Transaction.Commit(); } - cmd.Transaction.Commit(); - return json; - } - catch (Exception ex) - { - cmd.Transaction.Rollback(); - log.Error(ex.Message); - throw new Exception(ex.Message); - } - finally - { - if (conn.State == ConnectionState.Open) + catch (Exception ex) { - conn.Close(); + cmd.Transaction.Rollback(); + log.Error(ex.Message); + throw new Exception(ex.Message); + } + finally + { + if (conn.State == ConnectionState.Open) + { + conn.Close(); + } + conn.Dispose(); } - conn.Dispose(); } + + return json; + } /// /// 删除请购单 @@ -406,42 +450,49 @@ LEFT JOIN dbo.PO_Podetails E ON B.iPOsID = E.ID WHERE A.cverifier IS NOT NULL AN throw new Exception("传送数据为空!"); } string res = string.Empty; - SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString); - conn.Open(); - SqlTransaction sqlTran = conn.BeginTransaction(); + SqlConnection conn = new SqlConnection(); + SqlCommand cmd = new SqlCommand(); - cmd.Transaction = sqlTran; - cmd.Connection = conn; - try + + string sql = string.Empty; + foreach (ICSPOArrive info in infos) { - string sql = string.Empty; - foreach (ICSPOArrive info in infos) + try { + connString = string.Format(connString, info.WorkPoint); + conn = new System.Data.SqlClient.SqlConnection(connString); + conn.Open(); + SqlTransaction sqlTran = conn.BeginTransaction(); + cmd = new SqlCommand(); + cmd.Transaction = sqlTran; + cmd.Connection = conn; if (info.MTime < new DateTime(2000, 01, 01)) throw new Exception("请输入正确的操作时间:" + info.MTime); sql = @" DELETE dbo.PU_ArrivalVouch WHERE ID='{0}'"; sql = string.Format(sql, info.ID); DBHelper.CmdExecuteNonQuery(sql, cmd, "未查询到对应数据!"); + cmd.Transaction.Commit(); } - cmd.Transaction.Commit(); - return res; - ; - } - catch (Exception ex) - { - cmd.Transaction.Rollback(); - log.Error(ex.Message); - throw new Exception(ex.Message); - } - finally - { - if (conn.State == ConnectionState.Open) + catch (Exception ex) { - conn.Close(); + cmd.Transaction.Rollback(); + log.Error(ex.Message); + throw new Exception(ex.Message); + } + finally + { + if (conn.State == ConnectionState.Open) + { + conn.Close(); + } + conn.Dispose(); } - conn.Dispose(); } + + return res; + } + } } diff --git a/ICSSoft.ERP.WebAPI/ICSSoft.ERP.WebAPI/Web.config b/ICSSoft.ERP.WebAPI/ICSSoft.ERP.WebAPI/Web.config index 15e7147..d739a6f 100644 --- a/ICSSoft.ERP.WebAPI/ICSSoft.ERP.WebAPI/Web.config +++ b/ICSSoft.ERP.WebAPI/ICSSoft.ERP.WebAPI/Web.config @@ -9,7 +9,7 @@ - + diff --git a/ICSSoft.ERP.WebAPI/ICSSoft.Entity/ICSPOArrive.cs b/ICSSoft.ERP.WebAPI/ICSSoft.Entity/ICSPOArrive.cs index b3d7af1..274c9e4 100644 --- a/ICSSoft.ERP.WebAPI/ICSSoft.Entity/ICSPOArrive.cs +++ b/ICSSoft.ERP.WebAPI/ICSSoft.Entity/ICSPOArrive.cs @@ -11,6 +11,7 @@ namespace ICSSoft.Entity public string DNCode;//到货单 public string WHCode;//仓库 public string POCode;//采购订单 + public string WorkPoint;//采购订单 public string User; public string ID; public DateTime MTime;