From d145c38d85c1962e4564d6730695dacfa3116ccf Mon Sep 17 00:00:00 2001
From: llj <132905093+newwwwwwtree@users.noreply.github.com>
Date: 星期一, 03 十一月 2025 10:46:39 +0800
Subject: [PATCH] 供应商平台,添加新增送货物料信息的保存权限、删除权限,条码档案添加删除权限

---
 WebAPI/Controllers/MaterialHandingController.cs |  384 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 382 insertions(+), 2 deletions(-)

diff --git a/WebAPI/Controllers/MaterialHandingController.cs b/WebAPI/Controllers/MaterialHandingController.cs
index 044dc29..a6cea28 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;
@@ -34,6 +35,14 @@
                 string VsWhere = sWhere;
                 SQLHelper.ClsCN oCn = new SQLHelper.ClsCN();
                 DataSet ds;
+                if (!DBUtility.ClsPub.Security_Log("Gy_SupMaterPack_Query", 1, false, user))
+                {
+                    objJsonResult.code = "0";
+                    objJsonResult.count = 0;
+                    objJsonResult.Message = "鏃犱繚瀛樻潈闄愶紒";
+                    objJsonResult.data = null;
+                    return objJsonResult;
+                }
                 //鍏朵粬杩囨护
                 //string sql = " where 1 = 1 " + sqlWhere;
                 ////杞崲鐗规畩瀛楃
@@ -575,8 +584,15 @@
                         objJsonResult.data = null;
                         return objJsonResult;
                     }
-
-                    oCN.BeginTran();
+                if (!DBUtility.ClsPub.Security_Log("Gy_SupMaterPack_Delete", 1, false, user))
+                {
+                    objJsonResult.code = "0";
+                    objJsonResult.count = 0;
+                    objJsonResult.Message = "鏃犱繚瀛樻潈闄愶紒";
+                    objJsonResult.data = null;
+                    return objJsonResult;
+                }
+                oCN.BeginTran();
 
                    // oCN.RunProc("delete from Gy_UserMaterRelation where HInterID = " + HItemID);
                     oCN.RunProc("delete from Gy_UserMaterRelation where HItemID='" + HItemID + "'");
@@ -736,5 +752,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

--
Gitblit v1.9.1