yusijie
2024-12-17 797c91a77f908359e6d6fadad3d1b07406260c73
WebAPI/Controllers/SCGL/Èռƻ®¹ÜÀí/JIT_DayPlanPlatFormImportController.cs
@@ -20,6 +20,8 @@
        SQLHelper.ClsCN oCN = new SQLHelper.ClsCN();
        public static string BillType = "4610";
        Sc_WorkBillSortBillMain omdelMian = new Sc_WorkBillSortBillMain();
        Pub_Class.ClsXt_SystemParameter oSystemParameter = new Pub_Class.ClsXt_SystemParameter();
        #region ç”Ÿäº§æ—¥è®¡åˆ’ æ–‡ä»¶ä¸Šä¼ 
        [Route("JIT_DayPlanPlatFormImport/JIT_DayPlanPlatFormImport_DR")]
@@ -55,21 +57,51 @@
                tb2.Columns.Add("单据号", typeof(string));
                tb2.Columns.Add("HWorkShopID", typeof(Int32));//生产车间
                tb2.Columns.Add("HEmpID", typeof(Int32));//职员
                tb2.Columns.Add("员工", typeof(string));//职员
                tb2.Columns.Add("HUnitID", typeof(Int32));//计量单位
                tb2.Columns.Add("HSourceID", typeof(Int32));//生产资源id
                tb2.Columns.Add("ICMOBillHInterID", typeof(Int32));//生产订单主id
                tb2.Columns.Add("ICMOBillHEntryID", typeof(Int32));//生产订单子id
                tb2.Columns.Add("HProdORGID", typeof(Int32));//组织id
                tb2.Columns.Add("HSeOrderBillNo", typeof(string));//销售订单号
                //获取系统参数
                string Ret = "";
                oSystemParameter.ShowBill(ref Ret);
                LogService.Write("excel值:" + ExcelDs.Tables[0].Rows[1][15].ToString());//2024-11-26
                //添加数据
                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.Rows.Add(row);
                    //如果表格第i行的第一列为空,则判断为这一行的数据为空,跳出循环并且不把数据写入 tb2
                    if (ExcelDs.Tables[0].Rows[i][0].ToString() == "" && ExcelDs.Tables[0].Rows[i][1].ToString() == "")
                    {
                        continue;
                    }
                    //else if (oSystemParameter.omodel.JIT_DayPlan_TimeFrame != "0" && oSystemParameter.omodel.JIT_DayPlan_TimeFrame != "")
                    //{
                    //    Int32 HDays = Convert.ToInt32(oSystemParameter.omodel.JIT_DayPlan_TimeFrame) * 7;
                    //    for (int j = 0; j < ExcelDs.Tables[0].Columns.Count; j++)
                    //    {
                    //        if (Convert.ToInt32(ExcelDs.Tables[0].Rows[i][j].ToString()) > 0 )
                    //        {
                    //            continue;
                    //        }
                    //    }
                    //}
                    else
                    {
                        tb2.Rows.Add(row);
                    }
                }
                var error = "";
@@ -100,9 +132,9 @@
                        return objJsonResult;
                    }
                    string sql1 = string.Format("select * from h_v_IF_ICMOBillList where å•据号='{0}' and ç”Ÿäº§è½¦é—´ä»£ç ='{1}' and äº§å“ä»£ç ='{2}' and æ˜Žç»†è¡Œå·={3} ",
                    string sql1 = string.Format("select * from h_v_JIT_ICMOBillList_DR where å•据号='{0}' and ç”Ÿäº§è½¦é—´ä»£ç ='{1}' and äº§å“ä»£ç ='{2}' and æ˜Žç»†è¡Œå·={3} ",
                        tb2.Rows[i]["生产订单号*"].ToString(), tb2.Rows[i]["生产车间编码*"].ToString(), tb2.Rows[i]["物料编码*"].ToString(), tb2.Rows[i]["生产订单明细行号*"].ToString());
                    ds = oCN.RunProcReturn(sql1, "h_v_IF_ICMOBillList");
                    ds = oCN.RunProcReturn(sql1, "h_v_JIT_ICMOBillList_DR");
                    if (ds.Tables[0].Rows.Count == 0)
                    {
@@ -127,12 +159,13 @@
                        tb2.Rows[i]["ICMOBillHInterID"] = ds.Tables[0].Rows[0]["hmainid"].ToString();//生产订单主id
                        tb2.Rows[i]["ICMOBillHEntryID"] = ds.Tables[0].Rows[0]["HEntryID"].ToString();//生产订单子id
                        tb2.Rows[i]["生产订单数量"] = ds.Tables[0].Rows[0]["生产任务单数量"].ToString();//生产订单数量
                        tb2.Rows[i]["HSeOrderBillNo"] = ds.Tables[0].Rows[0]["销售订单号"].ToString();//销售订单号
                    }
                    ds = oCN.RunProcReturn("select * from h_v_JIT_Sc_WorkBillSortBillList " +
                    ds = oCN.RunProcReturn("select * from h_v_JIT_WorkBillSortBillList_DR " +
                        $"where  ç”Ÿäº§è®¢å•号='{tb2.Rows[i]["生产订单号*"].ToString()}'  and ç”Ÿäº§è®¢å•明细行号='{tb2.Rows[i]["生产订单明细行号*"].ToString()}' " +
                        $"and ç”Ÿäº§è½¦é—´ç¼–码='{tb2.Rows[i]["生产车间编码*"].ToString()}' and ç‰©æ–™ä»£ç ='{tb2.Rows[i]["物料编码*"].ToString()}' " +
                        $"and ç”Ÿäº§èµ„源编码='{tb2.Rows[i]["生产资源编码*"].ToString()}' ", "h_v_JIT_Sc_WorkBillSortBillList");
                        $"and ç”Ÿäº§èµ„源编码='{tb2.Rows[i]["生产资源编码*"].ToString()}' ", "h_v_JIT_WorkBillSortBillList_DR");
                    //组织编码='{tb2.Rows[i]["组织编码*"].ToString()}' and
                    //and ç”Ÿäº§èµ„源编码='{tb2.Rows[i]["生产资源编码*"].ToString()}'
@@ -144,6 +177,7 @@
                        tb2.Rows[i]["HSourceID"] = ds.Tables[0].Rows[0]["HSourceID"].ToString();
                        tb2.Rows[i]["HEmpID"] = ds.Tables[0].Rows[0]["HEmpID"].ToString();
                        tb2.Rows[i]["员工编码"] = ds.Tables[0].Rows[0]["职员代码"].ToString();
                        tb2.Rows[i]["员工"] = ds.Tables[0].Rows[0]["职员"].ToString();
                        tb2.Rows[i]["HUnitID"] = ds.Tables[0].Rows[0]["HUnitID"].ToString();
                        tb2.Rows[i]["计量单位"] = ds.Tables[0].Rows[0]["计量单位"].ToString();
                        tb2.Rows[i]["批次号"] = ds.Tables[0].Rows[0]["批次"].ToString();
@@ -153,9 +187,10 @@
                    else
                    {
                        //员工
                        ds = oCN.RunProcReturn($"select * from Gy_Employee  where HNumber='{tb2.Rows[i]["员工编码"].ToString()}'", "Gy_Employee");
                        ds = oCN.RunProcReturn($"select * from Gy_Employee with(nolock) where HNumber='{tb2.Rows[i]["员工编码"].ToString()}'", "Gy_Employee");
                        if (ds.Tables[0].Rows.Count > 0) {
                            tb2.Rows[i]["员工编码"] = ds.Tables[0].Rows[0]["HItemID"].ToString();
                            tb2.Rows[i]["HEmpID"] = ds.Tables[0].Rows[0]["HItemID"].ToString();
                            tb2.Rows[i]["员工"] = ds.Tables[0].Rows[0]["HName"].ToString();
                        }
                        else
                        {
@@ -167,7 +202,7 @@
                        }
                        //计量单位
                        ds = oCN.RunProcReturn($"select * from Gy_Unit  where HNumber='{tb2.Rows[i]["计量单位"].ToString()}'", "Gy_Unit");
                        ds = oCN.RunProcReturn($"select * from Gy_Unit with(nolock) where HNumber='{tb2.Rows[i]["计量单位"].ToString()}'", "Gy_Unit");
                        if (ds.Tables[0].Rows.Count > 0)
                        {
                            tb2.Rows[i]["HUnitID"] = ds.Tables[0].Rows[0]["HItemID"].ToString();
@@ -182,7 +217,7 @@
                        }
                        //生产资源
                        ds = oCN.RunProcReturn($"select * from Gy_Source  where HNumber='{tb2.Rows[i]["生产资源编码*"].ToString()}'", "Gy_Source");
                        ds = oCN.RunProcReturn($"select * from Gy_Source with(nolock) where HNumber='{tb2.Rows[i]["生产资源编码*"].ToString()}'", "Gy_Source");
                        if (ds.Tables[0].Rows.Count > 0)
                        {
                            tb2.Rows[i]["HSourceID"] = ds.Tables[0].Rows[0]["HItemID"].ToString();
@@ -196,7 +231,7 @@
                        }
                    }
                    //组织
                    ds = oCN.RunProcReturn($"select * from Xt_ORGANIZATIONS  where HNumber='{tb2.Rows[i]["组织编码*"].ToString()}'", "Xt_ORGANIZATIONS");
                    ds = oCN.RunProcReturn($"select * from Xt_ORGANIZATIONS with(nolock) where HNumber='{tb2.Rows[i]["组织编码*"].ToString()}'", "Xt_ORGANIZATIONS");
                    if (ds.Tables[0].Rows.Count > 0)
                    {
                        tb2.Rows[i]["HProdORGID"] = ds.Tables[0].Rows[0]["HItemID"].ToString();
@@ -290,10 +325,11 @@
                }
              
                int TrueCount = 0, SumCount = 0;
                for (int i = 0; i < list.Count; i++)
                {
                    int TrueCount = 0, SumCount = 0;
                    long HInterID = 0;
                    var HBillNo = "";
                    if (list[i]["单据号"].ToString() == "" && list[i]["hmainid"].ToString() == "")
@@ -319,9 +355,12 @@
                        var HDate = omdelMian.HDate;
                        var HMainSourceInterID = list[i]["ICMOBillHInterID"].ToString();
                        var HMainSourceEntryID = list[i]["ICMOBillHEntryID"].ToString();
                        var HSeOrderBillNo = list[i]["HSeOrderBillNo"].ToString();
                        ds = oCN.RunProcReturn($"select * from  Sc_WorkBillSortBillMain where HMainSourceInterID={HMainSourceInterID}" +
                          $" and HMainSourceEntryID={HMainSourceEntryID} and HICMOBillNo='{HICMOBillNo}' and HICMOEntrySEQ={HICMOEntrySEQ} and HSourceID={HSourceID}", "Sc_WorkBillSortBillMain");
                        string sql = $"select * from  Sc_WorkBillSortBillMain where HMainSourceInterID={HMainSourceInterID}" +
                          $" and HMainSourceEntryID={HMainSourceEntryID} and HICMOBillNo='{HICMOBillNo}' and HICMOEntrySEQ={HICMOEntrySEQ} and HSourceID={HSourceID}";
                        LogService.Write("sql:" + sql);
                        ds = oCN.RunProcReturn(sql, "Sc_WorkBillSortBillMain");
                        if (ds.Tables[0].Rows.Count > 0)
                        {
                            objJsonResult.code = "0";
@@ -337,19 +376,23 @@
                            "HICMOEntrySEQ,HWorkShopID,HSourceID, HYX, HEmpID," +
                            " HMaterID, HMaterName, HMaterModel, HUnitID, HBatchNo," +
                            " HSeOrderBillQty, HPlanQty, HCompleteQty,HPreparatDate," +
                            "HMainSourceInterID,HMainSourceEntryID,HProdORGID,HICMOInterID_Sec,HICMOEntryID_Sec)values" +
                            "HMainSourceInterID,HMainSourceEntryID,HProdORGID,HICMOInterID_Sec,HICMOEntryID_Sec" +
                            ",HSeOrderBillNo)values" +
                            $"({HInterID},'{HBillNo}',{DateTime.Now.Year},{DateTime.Now.Month},'{BillType}'," +
                            $"'{BillType}',GETDATE(),1,'{user}','{HDate}','{HICMOBillNo}','{HOrderType}'," +
                            $"{(HICMOEntrySEQ == "" ? 0.ToString() : HICMOEntrySEQ)},{(HWorkShopID == "" ? 0.ToString() : HWorkShopID)},{(HSourceID == "" ? 0.ToString() : HSourceID)}, {(HYX == "" ? 0.ToString() : HYX)}, {(HEmpID == "" ? 0.ToString() : HEmpID)}," +
                            $" {(HMaterID == "" ? 0.ToString() : HMaterID)}, '{HMaterName}', '{HMaterModel}', {(HUnitID == "" ? 0.ToString() : HUnitID)}, '{HBatchNo}'," +
                            $" {(HSeOrderBillQty == "" ? 0.ToString() : HSeOrderBillQty)}, {(HPlanQty == "" ? 0.ToString() : HPlanQty)}, {(HCompleteQty == "" ? 0.ToString() : HCompleteQty)},getdate()," +
                            $" {HMainSourceInterID},{HMainSourceEntryID},{HProdORGID}, {HMainSourceInterID},{HMainSourceEntryID})");
                            $" {HMainSourceInterID},{HMainSourceEntryID},{HProdORGID}, {HMainSourceInterID},{HMainSourceEntryID}" +
                            $",'{HSeOrderBillNo}')");
                    }
                    int SumDay = 31; //动态两月之差 DateTime.Now.AddMonths(1).AddDays(-1).Subtract(DateTime.Now).Days;
                    for (int j = 0; j < SumDay; j++)
                    {
                        LogService.Write("1:" + list[i][DateTime.Now.AddDays(j).ToString("yyyy-MM-dd")].ToString());
                        LogService.Write("2:" + DateTime.Now.AddDays(j).ToString("yyyy-MM-dd"));
                        //主表子表都有数据
                        if (list[i][DateTime.Now.AddDays(j).ToString("yyyy-MM-dd")].ToString() != "")
                        {
@@ -371,16 +414,17 @@
                            objJsonResult = AddBillSub(HInterID.ToString(), HBillNo, DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd").ToString()), 0);
                        }
                    }
                    if (TrueCount != SumCount)
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = objJsonResult.Message;
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                }
                if (TrueCount != SumCount)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = objJsonResult.Message;
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                objJsonResult.code = "1";
                objJsonResult.count = 1;
@@ -402,7 +446,6 @@
        {
            //获取表格数据
            ds = oCN.RunProcReturn($"select * from  h_v_JIT_Sc_WorkBillSortBillList where å•据号='{HBillNo}'", "h_v_JIT_Sc_WorkBillSortBillList");
            int count = 0;
            if (ds.Tables[0].Rows.Count > 0)
            {