zrg
2025-04-08 d54613ce0b6960dafcbd28454172f21a2d0bb6d1
WebAPI/Controllers/SCGL/Èռƻ®¹ÜÀí/Sc_JIT_ComplementGoodBillController.cs
@@ -1,4 +1,5 @@
using DBUtility;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
@@ -21,6 +22,7 @@
        private json objJsonResult = new json();
        SQLHelper.ClsCN oCN = new SQLHelper.ClsCN();
        DataSet ds;
        Pub_Class.ClsXt_SystemParameter oSystemParameter = new Pub_Class.ClsXt_SystemParameter();
        #region æ—¥è®¡åˆ’平台基础资料 è½¦é—´ä»“库对照
@@ -31,6 +33,7 @@
        {
            try
            {
                List<object> a = new List<object>();
                //查询权限
                if (!DBUtility.ClsPub.Security_Log_second("JIT_ComplementGoodBill_Query", 1, false, user))
                {
@@ -42,11 +45,17 @@
                }
                ds = oCN.RunProcReturn("select * from h_v_JIT_Gy_WorkWarehouseBillList where 1=1 " + sWhere + " order by hmainid desc ", "h_v_JIT_Gy_WorkWarehouseBillList");
                foreach (DataColumn col in ds.Tables[0].Columns)//遍历ds中第一个表(Tables[0])的所有列(Columns)每次循环中,col变量会持有当前列的引用
                {
                    Type dataType = col.DataType; //获取当前数据类型传入 è‡ªå®šä¹‰å˜é‡datadataType
                    string ColmString = "{\"ColmCols\":\"" + col.ColumnName + "\",\"ColmType\":\"" + dataType.Name + "\"}"; //字符串拼接         // å°†åˆ—名和数据类型信息拼接成一个JSON格式的字符串
                    a.Add(JsonConvert.DeserializeObject(ColmString));//获取到DataColumn列对象的列名
                }
                objJsonResult.code = "1";
                objJsonResult.count = 1;
                objJsonResult.Message = "Sucess!";
                objJsonResult.data = ds.Tables[0];
                objJsonResult.list = a;
                return objJsonResult;
            }
            catch (Exception e)
@@ -291,6 +300,7 @@
        {
            try
            {
                List<object> A = new List<object>();
                //查询权限
                if (!DBUtility.ClsPub.Security_Log_second("Cg_PODemandPlanConfigBill_Query", 1, false, user))
                {
@@ -302,11 +312,18 @@
                }
                ds = oCN.RunProcReturn("select * from h_v_JIT_Cg_PODemandPlanConfigBillList where 1=1 " + sWhere + " order by hmainid desc ", "h_v_JIT_Cg_PODemandPlanConfigBillList");
                foreach (DataColumn col in ds.Tables[0].Columns)//遍历ds中第一个表(Tables[0])的所有列(Columns)每次循环中,col变量会持有当前列的引用
                {
                    Type dataType = col.DataType; //获取当前数据类型传入 è‡ªå®šä¹‰å˜é‡datadataType
                    string ColmString = "{\"ColmCols\":\"" + col.ColumnName + "\",\"ColmType\":\"" + dataType.Name + "\"}"; //字符串拼接         // å°†åˆ—名和数据类型信息拼接成一个JSON格式的字符串
                    A.Add(JsonConvert.DeserializeObject(ColmString));//获取到DataColumn列对象的列名
                }
                objJsonResult.code = "1";
                objJsonResult.count = 1;
                objJsonResult.Message = "Sucess!";
                objJsonResult.data = ds.Tables[0];
                objJsonResult.list = A;
                return objJsonResult;
            }
            catch (Exception e)
@@ -419,6 +436,8 @@
        public json AddPODBillSub(string msg3)
        {
            string Ret = "";
            oSystemParameter.ShowBill(ref Ret);
            omodelPODsub = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Cg_PODemandPlanConfigBillSub>>(msg3);
            foreach (Models.Cg_PODemandPlanConfigBillSub oSub in omodelPODsub)
@@ -447,21 +466,25 @@
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                if (oSub.HLeadTime_Sec == 0 || oSub.HLeadTime_Sec == null)
                if (oSystemParameter.omodel.WMS_CampanyName != "帅威"&& oSystemParameter.omodel.WMS_CampanyName != "宝工" && oSystemParameter.omodel.WMS_CampanyName != "三升")
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = " JIT到货前置期不能为空";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                if (oSub.HDeliveryDaysCtrl == 0 || oSub.HDeliveryDaysCtrl == null)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = " JIT送货控制天数不能为空";
                    objJsonResult.data = null;
                    return objJsonResult;
                    if (oSub.HLeadTime_Sec == 0 || oSub.HLeadTime_Sec == null)
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = " JIT到货前置期不能为空";
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                    if (oSub.HDeliveryDaysCtrl == 0 || oSub.HDeliveryDaysCtrl == null)
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = " JIT送货控制天数不能为空";
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                }
            }
@@ -601,7 +624,15 @@
                    {
                        row[j] = ExcelDs.Tables[0].Rows[i][j].ToString();
                    }
                    tb2.Rows.Add(row);
                    //如果表格第i行的第一列为空,则判断为这一行的数据为空,跳出循环并且不把数据写入 tb2
                    if (ExcelDs.Tables[0].Rows[i][0].ToString() == "")
                    {
                        continue;
                    }
                    else
                    {
                        tb2.Rows.Add(row);
                    }
                }
@@ -729,7 +760,7 @@
                        //查询供应商
                        ds = oCN.RunProcReturn("select * from Gy_Supplier where  HNumber='" + HSupNumer + "' and HName='" + HSupName + "'  and HUSEORGID=" + HORGid + "", "Gy_Supplier");
                        ds = oCN.RunProcReturn("select * from Gy_Supplier where  HNumber='" + HSupNumer + "'  and HUSEORGID=" + HORGid + "", "Gy_Supplier");
                        if (ds.Tables[0].Rows.Count == 0)
                        {
@@ -745,7 +776,7 @@
                        }
                        //查询物料
                        ds = oCN.RunProcReturn("select * from Gy_Material where  HNumber='" + HMaterNumer + "' and HName='" + HMaterName + "' and HModel='" + HMaterModel + "'  and HUSEORGID=" + HORGid + "", "Gy_Material");
                        ds = oCN.RunProcReturn("select * from Gy_Material where  HNumber='" + HMaterNumer + "' and HUSEORGID=" + HORGid + "", "Gy_Material");
                        if (ds.Tables[0].Rows.Count == 0)
                        {
@@ -839,8 +870,8 @@
                    }
                    else
                    {
                        objJsonResult.code = "1";
                        objJsonResult.count = 1;
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "第" + index + "行,组织代码为空";
                        objJsonResult.data = null;
                        return objJsonResult;
@@ -871,7 +902,7 @@
        {
            var _value = sMainSub["sMainSub"].ToString();
            string msg1 = _value.ToString();
            string[] sArray = msg1.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
            string[] sArray = msg1.Split(new string[] { "&和" }, StringSplitOptions.RemoveEmptyEntries);
            string msg2 = sArray[0].ToString();
            string user = sArray[1].ToString();
            try
@@ -899,15 +930,13 @@
                }
                oCN.BeginTran();
                int i = 1;
                foreach (Dictionary<string, string> item in list)
                {
                    long HInterID = DBUtility.ClsPub.CreateBillID_Prod("4611", ref DBUtility.ClsPub.sExeReturnInfo);//获得一个新的id
                    string HBillNo = DBUtility.ClsPub.CreateBillCode_Prod("4611", ref DBUtility.ClsPub.sExeReturnInfo, true);//获得一个新的单据号
                    string HOrgID = item["HOrgID"].ToString();//组织ID
                    string HSupID = item["HSupID"].ToString();//供应商
                    string HSupplierName = item["供应商"].ToString();
                    string HMaterID = item["HMaterID"].ToString();//物料ID
                    string HOrgID = item["HOrgID"].ToString();//组织ID
                    string HSupplierName = item["供应商"].ToString();
                    string HMaterName = item["物料名称"].ToString();
                    string HMaterModel = item["规格型号"].ToString();
                    string HUnitID = item["HUnitID"].ToString();//计量单位
@@ -922,17 +951,34 @@
                    string JIMLC = item["JIT最小起送量"].ToString();
                    string HRemark = item["备注"].ToString();
                    int i = 1;
                    //主表
                    oCN.RunProc("insert into Cg_PODemandPlanConfigBillMain(HInterID,HBillNo,HYear,HPeriod,HBillType,HBillSubType,HDate,HBillStatus,HMaker,HMakeDate,HOrgId)" +
                        $"values({HInterID}, '{HBillNo}',{DateTime.Now.Year}, {DateTime.Now.Month}, '4611', '4611', GETDATE(), 1, '{user}', GETDATE(), {HOrgID})");
                    //子表
                    oCN.RunProc("insert into Cg_PODemandPlanConfigBillSub(HInterID,HEntryID,HRemark,HSupplierID,HSupplierName,HMaterID," +
                   "HMaterName, HMaterModel, HJITMaterGroup, HJITSafeStock, HJITMaterDemand, HJITBatchQty, HDeliveryPeriod, " +
                   "HLeadTime, HLeadTime_Sec, HDeliveryMode, HDeliveryDaysCtrl,HUnitID,HJITMinDeliveryQty)values" +
                   $"({HInterID}, {i}, '{HRemark}', {(HSupID == "" ? "0" : HSupID)}, '{HSupplierName}', {(HMaterID == "" ? "0" : HMaterID)}," +
                   $" '{HMaterName}', '{HMaterModel}', '{JITType}', {(JITPSL == "" ? "0" : JITPSL)}, {(JITMDSC == "" ? "0" : JITMDSC)},{(JIPEB == "" ? "0" : JIPEB)},{(JITPBCC == "" ? "0" : JITPBCC)}," +
                   $" {(JISLT == "" ? "0" : JISLT)}, {(JIDLT == "" ? "0" : JIDLT)}, '', {(JITDCD == "" ? "0" : JITDCD)} ,{HUnitID},{JIMLC})");
                    ds = oCN.RunProcReturn("select * from Cg_PODemandPlanConfigBillSub where HMaterID=" + HMaterID + " and HSupplierID=" + HSupID, "Cg_PODemandPlanConfigBillSub");
                    if (ds.Tables[0].Rows.Count == 0)
                    {
                        long HInterID = DBUtility.ClsPub.CreateBillID_Prod("4611", ref DBUtility.ClsPub.sExeReturnInfo);//获得一个新的id
                        string HBillNo = DBUtility.ClsPub.CreateBillCode_Prod("4611", ref DBUtility.ClsPub.sExeReturnInfo, true);//获得一个新的单据号
                        string sql = "insert into Cg_PODemandPlanConfigBillMain(HInterID,HBillNo,HYear,HPeriod,HBillType,HBillSubType,HDate,HBillStatus,HMaker,HMakeDate,HOrgId)" +
                            $"values({HInterID}, '{HBillNo}',{DateTime.Now.Year}, {DateTime.Now.Month}, '4611', '4611', GETDATE(), 1, '{user}', GETDATE(), {HOrgID})";
                        string sql1 = "insert into Cg_PODemandPlanConfigBillSub(HInterID,HEntryID,HRemark,HSupplierID,HSupplierName,HMaterID," +
                       "HMaterName, HMaterModel, HJITMaterGroup, HJITSafeStock, HJITMaterDemand, HJITBatchQty, HDeliveryPeriod, " +
                       "HLeadTime, HLeadTime_Sec, HDeliveryMode, HDeliveryDaysCtrl,HUnitID,HJITMinDeliveryQty)values" +
                       $"({HInterID}, 1, '{HRemark}', {(HSupID == "" ? "0" : HSupID)}, '{HSupplierName}', {(HMaterID == "" ? "0" : HMaterID)}," +
                       $" '{HMaterName}', '{HMaterModel}', '{JITType}', {(JITPSL == "" ? "0" : JITPSL)}, {(JITMDSC == "" ? "0" : JITMDSC)},{(JIPEB == "" ? "0" : JIPEB)},{(JITPBCC == "" ? "0" : JITPBCC)}," +
                       $" {(JISLT == "" ? "0" : JISLT)}, {(JIDLT == "" ? "0" : JIDLT)}, '', {(JITDCD == "" ? "0" : JITDCD)} ,{HUnitID},{JIMLC})";
                        //主表
                        oCN.RunProc(sql);
                        //子表
                        oCN.RunProc(sql1);
                    }
                    else
                    {
                        oCN.RunProc("   update  Cg_PODemandPlanConfigBillSub set HLeadTime=" + JISLT + "  where HMaterID=" + HMaterID + " and HSupplierID=" + HSupID);
                    }
                    i++;
                }
              
                oCN.Commit();
@@ -945,7 +991,7 @@
            }
            catch (Exception e)
            {
                oCN.RollBack();
                LogService.Write(e);
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "Exception!" + e.ToString();
@@ -1096,8 +1142,9 @@
        public json AddNeedBillSub(string msg3)
        {
            string Ret = "";
            omodelNeedsub = Newtonsoft.Json.JsonConvert.DeserializeObject<List<JIT_NeedMaterPlanConfigBillSub>>(msg3);
            oSystemParameter.ShowBill(ref Ret);
            foreach (Models.JIT_NeedMaterPlanConfigBillSub oSub in omodelNeedsub)
            {
                if (oSub.HWorkShopID == 0 || oSub.HWorkShopID == null)
@@ -1132,14 +1179,18 @@
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                if (oSub.HDeliveryDaysCtrl == 0 || oSub.HDeliveryDaysCtrl == null)
                if (oSystemParameter.omodel.WMS_CampanyName != "宝工"&& oSystemParameter.omodel.WMS_CampanyName != "三升")
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = " JIT送货控制天数不能为空";
                    objJsonResult.data = null;
                    return objJsonResult;
                    if (oSub.HDeliveryDaysCtrl == 0 || oSub.HDeliveryDaysCtrl == null)
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = " JIT送货控制天数不能为空";
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                }
            }
            //删除子表