From 7bd73b5076dd3256e7c28187016e4b5c73d08e2c Mon Sep 17 00:00:00 2001
From: yusijie <ysj@hz-kingdee.com>
Date: 星期二, 21 十月 2025 09:31:02 +0800
Subject: [PATCH] excel导入送货信息;条码保存时生产日期、有效期调整
---
WebAPI/Controllers/MaterialHandingController.cs | 365 ++++++++++++++++++++++++++++++++++++++++++++++++++++
WebAPI/Controllers/SRM_MaterialBarCodeBillController.cs | 23 ++-
2 files changed, 380 insertions(+), 8 deletions(-)
diff --git a/WebAPI/Controllers/MaterialHandingController.cs b/WebAPI/Controllers/MaterialHandingController.cs
index 044dc29..98a85c5 100644
--- a/WebAPI/Controllers/MaterialHandingController.cs
+++ b/WebAPI/Controllers/MaterialHandingController.cs
@@ -4,6 +4,7 @@
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
+using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
@@ -736,5 +737,369 @@
}
#endregion
+ [Route("MaterialHandingController/list")]
+ [HttpGet]
+ public object list(string sWhere, string user, string Organization)
+ {
+ try
+ {
+ string sql1 = "";
+ List<object> columnNameList = new List<object>();
+ if (user == "admin")
+ {
+ sql1 = string.Format(@"select * from h_v_UserSupplierRelationMater where 1=1");
+ }
+ else
+ {
+ sql1 = string.Format(@"select * from h_v_UserSupplierRelationMater where 鐢ㄦ埛鍚嶇О='" + user + "'");
+ }
+
+ if (sWhere == null || sWhere.Equals(""))
+ {
+ ds = oCN.RunProcReturn(sql1 + sWhere, "h_v_UserSupplierRelationMater");
+ }
+ else
+ {
+ string sql = sql1 + sWhere;
+ ds = oCN.RunProcReturn(sql, "h_v_UserSupplierRelationMater");
+ }
+
+ //娣诲姞鍒楀悕
+ foreach (DataColumn col in ds.Tables[0].Columns)
+ {
+ Type dataType = col.DataType;
+ string ColmString = "{\"ColmCols\":\"" + col.ColumnName + "\",\"ColmType\":\"" + dataType.Name + "\"}";
+ columnNameList.Add(JsonConvert.DeserializeObject(ColmString));//鑾峰彇鍒癉ataColumn鍒楀璞$殑鍒楀悕
+ }
+
+ objJsonResult.code = "1";
+ objJsonResult.count = 1;
+ objJsonResult.Message = "Sucess锛�";
+ objJsonResult.data = ds.Tables[0];
+ objJsonResult.list = columnNameList;
+ return objJsonResult;
+ }
+ catch (Exception e)
+ {
+ objJsonResult.code = "0";
+ objJsonResult.count = 0;
+ objJsonResult.Message = "Exception锛�" + e.ToString();
+ objJsonResult.data = null;
+ return objJsonResult;
+ }
+ }
+
+ #region 閫佽揣鐗╂枡淇℃伅 鏂囦欢涓婁紶
+ [Route("Gy_SupMaterPack/SupMaterPack_Excel")]
+ [HttpPost]
+ public object SupMaterPack_Excel()
+ {
+ try
+ {
+ //鑾峰彇鏂囦欢鍚嶇О
+ var file = HttpContext.Current.Request.Files[0];
+ //鑾峰彇鏂囦欢鐗╃悊璺緞
+ string ExcelPath = HttpContext.Current.Server.MapPath("~/" + file.FileName);
+ //淇濆瓨鏂囦欢
+ file.SaveAs(ExcelPath);
+
+ NpoiHelper np = new NpoiHelper();
+ DataSet ExcelDs = np.ReadExcel(ExcelPath, 1, 1, "0");
+
+ //鍒犻櫎鏂囦欢
+ File.Delete(ExcelPath);
+
+ //鍒涘缓涓存椂琛�
+ DataTable tb2 = new DataTable("dt2");
+
+ //娣诲姞鍒楀悕
+ for (int i = 0; i < ExcelDs.Tables[0].Columns.Count; i++)
+ {
+ tb2.Columns.Add(ExcelDs.Tables[0].Rows[0][i].ToString());
+ }
+
+ //妯℃澘缂哄皯鍒� 浣嗛渶瑕佷粠鏁版嵁搴撲腑鏌ヨ鍑烘潵鏄剧ず鍦ㄩ〉闈㈢殑瀛楁
+ tb2.Columns.Add("HMaterID", typeof(Int32));//鐗╂枡ID
+ tb2.Columns.Add("HSupID", typeof(Int32));//渚涘簲鍟咺D
+ tb2.Columns.Add("HUSEORGID", typeof(Int32));//缁勭粐ID
+
+ //娣诲姞鏁版嵁
+ for (int i = 1; i < ExcelDs.Tables[0].Rows.Count; i++)
+ {
+ DataRow row = tb2.NewRow();
+ for (int j = 0; j < ExcelDs.Tables[0].Columns.Count; j++)
+ {
+ row[j] = ExcelDs.Tables[0].Rows[i][j].ToString();
+ }
+ //濡傛灉琛ㄦ牸绗琲琛岀殑绗竴鍒椾负绌猴紝鍒欏垽鏂负杩欎竴琛岀殑鏁版嵁涓虹┖锛岃烦鍑哄惊鐜苟涓斾笉鎶婃暟鎹啓鍏� tb2
+ if (ExcelDs.Tables[0].Rows[i][0].ToString() == "")
+ {
+ continue;
+ }
+ else
+ {
+ tb2.Rows.Add(row);
+ }
+ }
+
+ var error = "";
+
+ //鏌ヨ閫佽揣鐗╂枡淇℃伅涓病鏈夌殑鍒�
+ if (!tb2.Columns.Contains("缁勭粐浠g爜"))
+ error += "娌℃湁鎵惧埌銆愮粍缁囦唬鐮併�戠殑鏍囬,";
+
+ if (!tb2.Columns.Contains("缁勭粐鍚嶇О"))
+ error += "娌℃湁鎵惧埌銆愮粍缁囧悕绉般�戠殑鏍囬,";
+
+ if (!tb2.Columns.Contains("渚涘簲鍟嗕唬鐮�"))
+ error += "娌℃湁鎵惧埌銆愪緵搴斿晢浠g爜銆戠殑鏍囬,";
+
+ if (!tb2.Columns.Contains("渚涘簲鍟嗗悕绉�"))
+ error += "娌℃湁鎵惧埌銆愪緵搴斿晢鍚嶇О銆戠殑鏍囬,";
+
+ if (!tb2.Columns.Contains("鐗╂枡浠g爜"))
+ error += "娌℃湁鎵惧埌銆愮墿鏂欎唬鐮併�戠殑鏍囬,";
+
+ if (!tb2.Columns.Contains("鐗╂枡鍚嶇О"))
+ error += "娌℃湁鎵惧埌銆愮墿鏂欏悕绉般�戠殑鏍囬,";
+
+ if (!tb2.Columns.Contains("瑙勬牸鍨嬪彿"))
+ error += "娌℃湁鎵惧埌銆愯鏍煎瀷鍙枫�戠殑鏍囬,";
+
+ if (!tb2.Columns.Contains("鏍囧噯鍖呰鏁伴噺"))
+ error += "娌℃湁鎵惧埌銆愭爣鍑嗗寘瑁呮暟閲忋�戠殑鏍囬,";
+
+ if (!tb2.Columns.Contains("鏈�灏忓寘瑁呮暟閲�"))
+ error += "娌℃湁鎵惧埌銆愭渶灏忓寘瑁呮暟閲忋�戠殑鏍囬,";
+
+ if (error.Length > 0)
+ {
+ objJsonResult.code = "0";
+ objJsonResult.count = 0;
+ objJsonResult.Message = $"Excel妯℃澘瀛樺湪閿欒,{error}\r\n";
+ objJsonResult.data = null;
+ return objJsonResult;
+ }
+
+ string HOrgNumber = "";
+ string HOrgName = "";
+ string HSupNumber = "";
+ string HSupName = "";
+ string HMaterNumber = "";
+ string HMaterName = "";
+ string HMaterModel = "";
+ double HInBoxPackQty = 0;
+ double HMinPackQty = 0;
+
+ for (int i = 0; i <= tb2.Rows.Count - 1; i++)
+ {
+ HOrgNumber = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["缁勭粐浠g爜"].ToString());
+ HOrgName = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["缁勭粐鍚嶇О"].ToString());
+ HSupNumber = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["渚涘簲鍟嗕唬鐮�"].ToString());
+ HSupName = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["渚涘簲鍟嗗悕绉�"].ToString());
+ HMaterNumber = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["鐗╂枡浠g爜"].ToString());
+ HMaterName = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["鐗╂枡鍚嶇О"].ToString());
+ HMaterModel = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["瑙勬牸鍨嬪彿"].ToString());
+ HInBoxPackQty = DBUtility.ClsPub.isDoule(tb2.Rows[i]["鏍囧噯鍖呰鏁伴噺"].ToString());
+ HMinPackQty = DBUtility.ClsPub.isDoule(tb2.Rows[i]["鏈�灏忓寘瑁呮暟閲�"].ToString());
+
+ //妫�鏌ヨ〃鏍兼暟鎹�
+ int index = i + 1;
+
+ if (HOrgNumber != "" && HSupNumber != "" && HMaterNumber != "" && HInBoxPackQty != 0)
+ {
+ //鏌ヨ缁勭粐
+ ds = oCN.RunProcReturn("select HItemID from Xt_ORGANIZATIONS org with(nolock) where HNumber='" + HOrgNumber + "'", "Xt_ORGANIZATIONS");
+
+ if (ds.Tables[0].Rows.Count == 0)
+ {
+ objJsonResult.code = "0";
+ objJsonResult.count = 0;
+ objJsonResult.Message = "绗�" + index + "琛�,缁勭粐涓嶅瓨鍦紒" + "缁勭粐浠g爜锛�" + HOrgNumber;
+ objJsonResult.data = null;
+ return objJsonResult;
+ }
+ else
+ {
+ tb2.Rows[i]["HUSEORGID"] = ds.Tables[0].Rows[0]["HItemID"].ToString();
+ }
+
+
+ //鏌ヨ鐗╂枡
+ ds = oCN.RunProcReturn("select m.HItemID from Gy_Material m with(nolock) " +
+ "left join Xt_ORGANIZATIONS org with(nolock) on m.HUSEORGID = org.HItemID " +
+ "where m.HNumber='" + HMaterNumber + "' and org.HNumber='" + HOrgNumber + "'"
+ , "Gy_Material");
+
+ if (ds.Tables[0].Rows.Count == 0)
+ {
+ objJsonResult.code = "0";
+ objJsonResult.count = 0;
+ objJsonResult.Message = "绗�" + index + "琛�,鐗╂枡涓嶅瓨鍦紒" + "浣跨敤缁勭粐浠g爜锛�" + HOrgNumber + " 锛岀墿鏂欎唬鐮侊細" + HMaterNumber;
+ objJsonResult.data = null;
+ return objJsonResult;
+ }
+ else
+ {
+ tb2.Rows[i]["HMaterID"] = ds.Tables[0].Rows[0]["HItemID"].ToString();
+ }
+
+
+ //鏌ヨ渚涘簲鍟�
+ ds = oCN.RunProcReturn("select s.HItemID from Gy_Supplier s with(nolock) " +
+ "left join Xt_ORGANIZATIONS org with(nolock) on s.HUSEORGID = org.HItemID " +
+ "where s.HNumber='" + HSupNumber + "' and org.HNumber='" + HOrgNumber + "'"
+ , "Gy_Supplier");
+
+ if (ds.Tables[0].Rows.Count == 0)
+ {
+ objJsonResult.code = "0";
+ objJsonResult.count = 0;
+ objJsonResult.Message = "绗�" + index + "琛�,渚涘簲鍟嗕笉瀛樺湪锛�" + "浣跨敤缁勭粐浠g爜锛�" + HOrgNumber + " 锛屼緵搴斿晢浠g爜锛�" + HSupNumber; ;
+ objJsonResult.data = null;
+ return objJsonResult;
+ }
+ else
+ {
+ tb2.Rows[i]["HSupID"] = ds.Tables[0].Rows[0]["HItemID"].ToString();
+ }
+ }
+ else
+ {
+ objJsonResult.code = "0";
+ objJsonResult.count = 0;
+ objJsonResult.Message = "绗�" + index + "琛�,淇℃伅涓嶅叏锛堢粍缁囦唬鐮�,渚涘簲鍟嗕唬鐮�,鐗╂枡浠g爜,鏍囧噯鍖呰鏁伴噺锛�";
+ objJsonResult.data = null;
+ return objJsonResult;
+ }
+ }
+
+ objJsonResult.code = "1";
+ objJsonResult.count = 1;
+ objJsonResult.Message = error;
+ objJsonResult.data = tb2;
+ return objJsonResult;
+ }
+ catch (Exception e)
+ {
+ objJsonResult.code = "0";
+ objJsonResult.count = 0;
+ objJsonResult.Message = "Exception锛�" + e.ToString();
+ objJsonResult.data = null;
+ return objJsonResult;
+ }
+ }
+ #endregion
+
+ #region 閫佽揣鐗╂枡淇℃伅 瀵煎叆(淇濆瓨)
+ [Route("Gy_SupMaterPack/SupMaterPack_btnSave")]
+ [HttpPost]
+ public object SupMaterPack_btnSave([FromBody] JObject sMainSub)
+ {
+ var _value = sMainSub["sMainSub"].ToString();
+ string msg1 = _value.ToString();
+ string[] sArray = msg1.Split(new string[] { "&鍜�" }, StringSplitOptions.RemoveEmptyEntries);
+ string msg2 = sArray[0].ToString();
+ string user = sArray[1].ToString();
+ try
+ {
+ if (!DBUtility.ClsPub.Security_Log("Gy_SupMaterPack_Query", 1, false, user))
+ {
+ objJsonResult.code = "0";
+ objJsonResult.count = 0;
+ objJsonResult.Message = "鏃犱繚瀛樻潈闄愶紒";
+ objJsonResult.data = null;
+ return objJsonResult;
+ }
+
+ List<object> Excel = Newtonsoft.Json.JsonConvert.DeserializeObject<List<object>>(msg2);
+ List<Dictionary<string, string>> list = new List<Dictionary<string, string>>();
+
+ foreach (JObject item in Excel)
+ {
+ Dictionary<string, string> dic = new Dictionary<string, string>();
+ foreach (var itm in item.Properties())
+ {
+ dic.Add(itm.Name, itm.Value.ToString());
+ }
+ list.Add(dic);
+ }
+
+ oCN.BeginTran();
+ int i = 1;
+ foreach (Dictionary<string, string> item in list)
+ {
+ string HSupID = item["HSupID"].ToString();//渚涘簲鍟�
+ string HSupNumber = item["渚涘簲鍟嗕唬鐮�"].ToString();//渚涘簲鍟嗕唬鐮�
+ string HMaterID = item["HMaterID"].ToString();//鐗╂枡
+ string HUSEORGID = item["HUSEORGID"].ToString();//缁勭粐
+ string HInBoxPackQty = item["鏍囧噯鍖呰鏁伴噺"].ToString();//鏍囧噯鍖呰鏁伴噺
+ string HMinPackQty = item["鏈�灏忓寘瑁呮暟閲�"].ToString();//鏈�灏忓寘瑁呮暟閲�
+
+ //鎷兼帴鏂板璇彞
+ string sql = "insert into Gy_UserMaterRelation(HMaterID,HUserID,HMinPackQty,HInBoxPackQty,HUSEORGID,HUseFlag,HSupID,HMaker,HMakeTime)" +
+ $"values({HMaterID}, '{HSupNumber}',{HMinPackQty}, {HInBoxPackQty}, {HUSEORGID},'1',{HSupID}, '{user}',getdate())";
+
+ //鏌ヨ姝や緵搴斿晢鏄惁宸茬粡娣诲姞杩囬�佽揣鐗╂枡淇℃伅
+ ds = oCN.RunProcReturn("select HInBoxPackQty from Gy_UserMaterRelation with(nolock) where HSupID = " + HSupID + " and HMaterID = " + HMaterID + " and HUSEORGID = " + HUSEORGID, "Gy_UserMaterRelation");
+
+ if (ds.Tables[0].Rows.Count == 0)
+ {
+ //鎵ц鏂板璇彞
+ oCN.RunProc(sql);
+ }
+ else
+ {
+ var HIsReturn = "false";
+
+ for (var k = 0; k < ds.Tables[0].Rows.Count; k++)
+ {
+ if (Convert.ToDecimal(ds.Tables[0].Rows[k]["HInBoxPackQty"]) == Convert.ToDecimal(HInBoxPackQty))
+ {
+ HIsReturn = "true";
+ break;
+ }
+ }
+
+ if (HIsReturn == "true")
+ {
+ //鏈excel瀵煎叆鐨勭墿鏂欏寘瑁呮暟閲忓凡缁忔坊鍔犺繃锛屽垯璺宠繃鏈娣诲姞
+ continue;
+ }
+ else
+ {
+ //鏇存柊鍘熸潵鐨勯�佽揣鐗╂枡淇℃伅涓哄緟鍚敤鐘舵��
+ string sql2 = "update a set HUseFlag = 0,HUpDater = '" + user + "',HUpDateDate = getdate() from Gy_UserMaterRelation a with(nolock) where HSupID = " + HSupID + " and HMaterID = " + HMaterID + " and HUSEORGID = " + HUSEORGID;
+ //鎵ц鏇存柊璇彞
+ oCN.RunProc(sql2);
+
+ //鎵ц鏂板璇彞
+ oCN.RunProc(sql);
+ }
+ }
+
+ i++;
+ }
+
+ oCN.Commit();
+
+ objJsonResult.code = "1";
+ objJsonResult.count = 1;
+ objJsonResult.Message = "瀵煎叆鎴愬姛!";
+ objJsonResult.data = null;
+ return objJsonResult;
+ }
+ catch (Exception e)
+ {
+ LogService.Write(e);
+ objJsonResult.code = "0";
+ objJsonResult.count = 0;
+ objJsonResult.Message = "Exception锛�" + e.ToString();
+ objJsonResult.data = null;
+ return objJsonResult;
+ }
+ }
+ #endregion
+
}
}
\ No newline at end of file
diff --git a/WebAPI/Controllers/SRM_MaterialBarCodeBillController.cs b/WebAPI/Controllers/SRM_MaterialBarCodeBillController.cs
index e75a97c..ec627f1 100644
--- a/WebAPI/Controllers/SRM_MaterialBarCodeBillController.cs
+++ b/WebAPI/Controllers/SRM_MaterialBarCodeBillController.cs
@@ -97,6 +97,7 @@
string UserName = sArray[2].ToString();
string OrganizationID = sArray[3].ToString();
ListModels oListModels = new ListModels();
+ string error = "";
try
{
#region 鑾峰彇鐢ㄦ埛浠ュ強鐩稿叧鍙傛暟
@@ -226,7 +227,7 @@
TM = $"{oItemSub.HSupName}@{oItemSub.HMaterNumber}@{oItemSub.HSubjoin}@{currentQty}@{HBarCodeDate_1}@{LSH.ToString("D7")}";
//TM = $"{oItemSub.HSupName}@{oItemSub.HMaterID}@{oItemSub.HMaterName}@{oItemSub.biaoqianzhangshu}@{HKFDate_1}@{LSH}";
// 娣诲姞鍒扮敓鎴愮殑鏉$爜鍒楄〃
- generatedBarcodes.Add(TM);
+ //generatedBarcodes.Add(TM);
Model.ClsGy_BarCodeBill_WMS_Model bar = new Model.ClsGy_BarCodeBill_WMS_Model();
// var HBarCode_verify = TM.Split('@'); //鏍¢獙鏉$爜淇℃伅
@@ -253,14 +254,19 @@
// + HKFDate + "','" + HKFDQDate + "'," + HISKFPERIOD + ")";
sql = "INSERT INTO Gy_BarCodeBill (HInterID, HBarCode, HBarCodeType, HMaterID, HUnitID, HQty, HKFDate, HKFPeriod, HKFDQDate, " +
"HBatchNo, HBarcodeQtys, HBarcodeNo, HSupID, HGroupID, HMaker, HMakeDate, HPrintQty, HEndQty, HSupflag, " +
- "HSourceInterID, HSourceEntryID, HSourceBillNo, HSourceBillType, HMTONO, HProduceDate, HExpiryDate, HISKFPERIOD,HStatusMan,HBarCodeDate,HinitQty,HSTOCKORGID,HOWNERID) " +
+ "HSourceInterID, HSourceEntryID, HSourceBillNo, HSourceBillType, HMTONO, HISKFPERIOD,HStatusMan,HBarCodeDate,HinitQty,HSTOCKORGID,HOWNERID) " +
"VALUES (" +
- linterid.ToString() + ", '" + TM + "', '" + HBarCodeType + "', " + HMaterID + ", " + "0" + ", " + currentQty + ", '" + null + "', " + HKFPeriod + ", '" + null + "', " +
- "'" + HBatchNo + "', " + get_BarCodecount + ", '" + virtualCount + "', " + HSupID + ", " + "0" + ", '" + UserName + "',getdate()" + "," + "0" + ", " + "0" + ", 1, " +
- "0, 0, '', '" + HSourceBillType + "', '', '" +
- null + "', '" + null + "', " + HISKFPERIOD + ",'" + HStatusMan + "','" + HBarCodeDate + "','" + currentQty + "'," + OrganizationID + "," + OrganizationID + "," + null + ")";
+ linterid.ToString() + ", '" + TM + "', '" + HBarCodeType + "', " + HMaterID + ", " + "0" + ", " + currentQty + ", '" + null + "', " + HKFPeriod + ", '" + null + "', '"
+ + HBatchNo + "', " + get_BarCodecount + ", '" + virtualCount + "', " + HSupID + ", " + "0" + ", '" + UserName + "',getdate()" + "," + "0" + ", " + "0" + ", 1, " +
+ "0, 0, '', '" + HSourceBillType + "', ''," +
+ HISKFPERIOD + ",'" + HStatusMan + "','" + HBarCodeDate + "','" + currentQty + "'," + OrganizationID + "," + OrganizationID + ")";
LogService.Write("鐢熸垚鏉$爜锛� " + sql);
- oCn.RunProc(sql);
+ oCn.RunProc(sql);
+
+ DataSet getID = oCn.RunProcReturn("select HitemID from Gy_BarCodeBill with(nolock) where HBarCode='" + TM + "'", "Gy_BarCodeBill");
+ var getBarCodeID = (getID.Tables[0].Rows[0]["HitemID"]).ToString();
+ generatedBarcodes.Add(getBarCodeID);
+
oCn.RunProc("exec h_p_WMS_SetMaxNo '" + HSupID + "_" + HMaterID + "_" + HBarCodeDate + "'");
virtualCount++;
}
@@ -366,7 +372,8 @@
}
string inClause = string.Join(",", inValues);
- string sql = $"SELECT * FROM h_v_Gy_UserMaterRelationPrint WHERE HBarCode IN ({inClause})" + " order by 鐗╂枡浠g爜,cast(娴佹按鍙� as int)";
+
+ string sql = $"SELECT * FROM h_v_Gy_UserMaterRelationPrint WHERE HBarItemID IN ({inClause})" + " order by 鐗╂枡浠g爜,cast(娴佹按鍙� as int)";
// 鐩存帴鎵цSQL鏌ヨ
DataSet ds = oCn.RunProcReturn(sql, "h_v_Gy_UserMaterRelationPrint");
--
Gitblit v1.9.1