From 807bb9a2b4d6db408ebdded1cff41f3094eac11e Mon Sep 17 00:00:00 2001
From: wtt <1985833171@qq.com>
Date: 星期二, 24 三月 2026 15:00:40 +0800
Subject: [PATCH] 1

---
 WebAPI/Controllers/CJGL/Cj_SingleStationController.cs |  536 ++++++++++++++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 476 insertions(+), 60 deletions(-)

diff --git a/WebAPI/Controllers/CJGL/Cj_SingleStationController.cs b/WebAPI/Controllers/CJGL/Cj_SingleStationController.cs
index f0d731d..8b3b977 100644
--- a/WebAPI/Controllers/CJGL/Cj_SingleStationController.cs
+++ b/WebAPI/Controllers/CJGL/Cj_SingleStationController.cs
@@ -7,6 +7,7 @@
 using System.Data;
 using System.Data.SqlClient;
 using System.Web.Http;
+using WebAPI.Controllers.SCGL;
 using WebAPI.Models;
 
 namespace WebAPI.Controllers.CJGL
@@ -16,7 +17,7 @@
         private json objJsonResult = new json();
         SQLHelper.ClsCN oCN = new SQLHelper.ClsCN();
         Pub_Class.ClsXt_SystemParameter oSystemParameter = new Pub_Class.ClsXt_SystemParameter();
-        DataSet ds;
+        DataSet ds,ds2;
 
         #region 宸ュ簭鍗曞搧涓嶈壇閲囬泦  鐢ㄦ埛鏌ヨ鍏宠仈瀛楁
         [Route("Cj_SingleStation/Cj_CollectionOfSingleProductDefectsUserList")]
@@ -375,23 +376,33 @@
                 {
                     if (oSystemParameter.omodel.WMS_CampanyName == "鏉窞鏂帿灏�")
                     {
-                       
-                        //鍒ゆ柇褰撳墠娴佽浆鍗� 褰撳墠宸ュ簭鏄惁鏄紑宸�
-                        ds = oCN.RunProcReturn("select  * from Sc_ICMOBillStatus_Tmp where HSourceBillNo='" + HBarCode + "' and HICMOStatus<>'0' and HProcID='"+ HProcID + "'", "Sc_ICMOBillStatus_Tmp");
-                        //鏌ヤ笉鍒拌瘉鏄庢病鏈夊紑宸ヨ繘鍏ヤ笅涓�鍙ユ煡璇�
-                        if (ds.Tables[0].Rows.Count == 0)
+                        if (HProcID == "90")  //娓呮磥宸ュ簭杩涘叆鑷姩寮�宸ユā寮�
                         {
-                            //鍒ゆ柇褰撳墠娴佽浆鍗℃槸鍚﹀ⅷ瑗垮摜鐨�
-                            ds = oCN.RunProcReturn("select HPRDORGID from Sc_ProcessExchangeBillMain with(nolock) where HBillNo = '" + HBarCode + "' ", "Sc_ProcessExchangeBillMain");
-                            if (ds.Tables[0].Rows[0]["HPRDORGID"].ToString() != "7667152")
+                            //鍒ゆ柇褰撳墠娴佽浆鍗� 褰撳墠宸ュ簭鏄惁鏄紑宸�
+                            ds = oCN.RunProcReturn("select  * from Sc_ICMOBillStatus_Tmp where HSourceBillNo='" + HBarCode + "' and HICMOStatus<>'0' and HProcID='" + HProcID + "'", "Sc_ICMOBillStatus_Tmp");
+                            //鏌ヤ笉鍒拌瘉鏄庢病鏈夊紑宸ヨ繘鍏ヤ笅涓�鍙ユ煡璇�
+                            if (ds.Tables[0].Rows.Count == 0)
                             {
-                                objJsonResult.code = "0";
-                                objJsonResult.count = 0;
-                                objJsonResult.Message = "[3791-2-018]鍗″彿:" + HBarCode + ",娴佽浆鍗℃湭寮�宸�!";
-                                objJsonResult.data = null;
-                                return objJsonResult;
-                            }                                                 
-                        }   
+                                //鍒ゆ柇褰撳墠娴佽浆鍗℃槸鍚﹀ⅷ瑗垮摜鐨�
+                                ds2 = oCN.RunProcReturn("select HPRDORGID from Sc_ProcessExchangeBillMain with(nolock) where HBillNo = '" + HBarCode + "' ", "Sc_ProcessExchangeBillMain");
+                                if (ds2.Tables[0].Rows[0]["HPRDORGID"].ToString() != "7667152")
+                                {
+                                    //鑾峰彇鐢熶骇鐘舵�佷复鏃惰〃鏁版嵁
+                                    ds = oCN.RunProcReturn("select  * from Sc_ICMOBillStatus_Tmp where HSourceBillNo='" + HBarCode + "' and HProcID='" + HProcID + "'", "Sc_ICMOBillStatus_Tmp");
+                                    //浼犲叆 鐢熶骇鐘舵�佷复鏃惰ˉ 鍗曟嵁绫诲瀷銆佷富id銆佹簮鍗曞瓙ID銆佹簮鍗曞崟鍙枫�佸綋鍓嶇櫥褰曚汉銆佹簮鍗曞崟鎹被鍨�
+                                    objJsonResult = SaveMESBeginWorkFrom_ZD(ds.Tables[0].Rows[0]["HBillType"].ToString(), ds.Tables[0].Rows[0]["HInterID"].ToString(), ds.Tables[0].Rows[0]["HSourceEntryID"].ToString(), ds.Tables[0].Rows[0]["HSourceBillNo"].ToString(), user, ds.Tables[0].Rows[0]["HSourceBillType"].ToString());
+                                    if (objJsonResult.code == "0")
+                                    {
+                                        objJsonResult.code = "0";
+                                        objJsonResult.count = 0;
+                                        objJsonResult.Message = objJsonResult.Message;
+                                        objJsonResult.data = null;
+                                        return objJsonResult;
+                                    }
+                                }
+                            }
+                        }
+                        
                     }
                 }
 
@@ -424,10 +435,26 @@
                 }
                 else
                 {
-                    objJsonResult.code = "1";
-                    objJsonResult.count = 1;
-                    objJsonResult.Message = "[0000-1-037]";
-                    objJsonResult.data = ds.Tables[0];
+                    if (HProcID == "90" || HProcID== "102")
+                    {
+                        DataSet dataSet = oCN.RunProcReturn(@"exec h_p_Sc_ProcessExchangeBillList2 '" + HBarCode + "'," + HProcID, "h_p_Sc_ProcessExchangeBillList2");
+                        if (dataSet.Tables[0].Rows.Count > 0)
+                        {
+                            objJsonResult.code = "2";
+                            objJsonResult.count = 2;
+                            objJsonResult.Message = "[0000-1-037]";
+                            objJsonResult.data = dataSet.Tables[0];
+                            return objJsonResult;
+                        }
+                    }
+                    else
+                    {
+                        objJsonResult.code = "1";
+                        objJsonResult.count = 1;
+                        objJsonResult.Message = "[0000-1-037]";
+                        objJsonResult.data = ds.Tables[0];
+                    }
+                    
                 }
 
                 return objJsonResult;
@@ -504,7 +531,7 @@
                     "(HInterID,HEntryID,HBillNo_bak,HSourceBillNo,HSourceInterID,HSourceEntryID,HMaterID" +
                     ",HProdOrgID,HSourceBillType,HAuxPropID,HProcID,HQty,HBatchNo,HBarCode,HMTONo,HPlanMode) " +
                     " values(" + HInterID + "," + (i + 1) + ",'" + HBillNo + "','" + tempList[i].HProcExchBillNo + "'," + tempList[i].HProcExchInterID + "," + tempList[i].HProcExchEntryID + "," + tempList[i].HMaterID +
-                    ",'" + HOrgID + "','',0," + HProcID + "," + tempList[i].HQty + ",'"+ tempList[i].HBatchNo + "','" + tempList[i].HBarCode + "','','') ");
+                    ",'" + HOrgID + "','',0," + tempList[i].HProcID + "," + tempList[i].HQty + ",'"+ tempList[i].HBatchNo + "','" + tempList[i].HBarCode + "','','') ");
                 }
 
                 oCN.Commit();
@@ -592,72 +619,76 @@
                     objJsonResult.data = null;
                     return objJsonResult;
                 }
-
-                //澧炲姞浜х嚎缁勮杩芥函鍗�
-                DataSet ds1 = oCN.RunProcReturn("exec h_p_Gy_BarCodeBillBomList '" + omodel.HProcExchBillNo + "'," + omodel.HProcID, "h_p_Gy_BarCodeBillBomList");
-                if (ds1.Tables[0].Rows.Count > 0)
+                if (omodel.HProcID!=90)//鏂帿灏旀媿鐓ф竻娲佸伐搴忚繃婊�
                 {
-                    //鍒ら厤浠舵暟閲忔槸鍚︾瓑浜�0
-                    for (int i = 0; i < ds1.Tables[0].Rows.Count; i++)
+                    //澧炲姞浜х嚎缁勮杩芥函鍗�
+                    DataSet ds1 = oCN.RunProcReturn("exec h_p_Gy_BarCodeBillBomList '" + omodel.HProcExchBillNo + "'," + omodel.HProcID, "h_p_Gy_BarCodeBillBomList");
+                    if (ds1.Tables[0].Rows.Count > 0)
                     {
-                        double SYHQty = double.Parse(ds1.Tables[0].Rows[i]["閰嶄欢鏁伴噺"].ToString());
-                        string HMaterNamePJ = ds1.Tables[0].Rows[i]["閰嶄欢浠g爜"].ToString();
-                        if (SYHQty == 0)
+                        //鍒ら厤浠舵暟閲忔槸鍚︾瓑浜�0
+                        for (int i = 0; i < ds1.Tables[0].Rows.Count; i++)
                         {
-                            oCN.RollBack();
-                            objJsonResult.code = "0";
-                            objJsonResult.count = 0;
-                            objJsonResult.Message = "[3791-2-020]閰嶄欢浠g爜:" + HMaterNamePJ + ",鏁伴噺涓�0!";
-                            objJsonResult.data = null;
-                            return objJsonResult;
+                            double SYHQty = double.Parse(ds1.Tables[0].Rows[i]["閰嶄欢鏁伴噺"].ToString());
+                            string HMaterNamePJ = ds1.Tables[0].Rows[i]["閰嶄欢浠g爜"].ToString();
+                            if (SYHQty == 0)
+                            {
+                                oCN.RollBack();
+                                objJsonResult.code = "0";
+                                objJsonResult.count = 0;
+                                objJsonResult.Message = "[3791-2-020]閰嶄欢浠g爜:" + HMaterNamePJ + ",鏁伴噺涓�0!";
+                                objJsonResult.data = null;
+                                return objJsonResult;
+                            }
                         }
-                    }
 
 
-                    ds1 = oCN.RunProcReturn("select * from Sc_AssemblyBillMain WITH(NOLOCK) where HMainSourceInterID =" + omodel.HProcExchInterID + " and HMainSourceEntryID =" + omodel.HProcExchEntryID + " and HBarCode_P = '" + omodel.HBarCode_P + "'", "Sc_AssemblyBillMain");
+                        ds1 = oCN.RunProcReturn("select * from Sc_AssemblyBillMain WITH(NOLOCK) where HMainSourceInterID =" + omodel.HProcExchInterID + " and HMainSourceEntryID =" + omodel.HProcExchEntryID + " and HBarCode_P = '" + omodel.HBarCode_P + "'", "Sc_AssemblyBillMain");
 
-                    if (ds1.Tables[0].Rows.Count == 0)
-                    {
-                        Int64 HInterID1 = DBUtility.ClsPub.CreateBillID("3727", ref DBUtility.ClsPub.sExeReturnInfo);
-                        string HBillNo1 = DBUtility.ClsPub.CreateBillCode("3727", ref DBUtility.ClsPub.sExeReturnInfo, true);
-                        string prefix = omodel.HBarCode_P.Substring(0, 10); // 浠庣储寮�0寮�濮嬶紝鎴彇10涓瓧绗� 鍒ゆ柇姣忎釜椤圭洰鐨凮鏄熷湀閰嶄欢鏁伴噺
-                        
+                        if (ds1.Tables[0].Rows.Count == 0)
+                        {
+                            Int64 HInterID1 = DBUtility.ClsPub.CreateBillID("3727", ref DBUtility.ClsPub.sExeReturnInfo);
+                            string HBillNo1 = DBUtility.ClsPub.CreateBillCode("3727", ref DBUtility.ClsPub.sExeReturnInfo, true);
+                            string prefix = omodel.HBarCode_P.Substring(0, 10); // 浠庣储寮�0寮�濮嬶紝鎴彇10涓瓧绗� 鍒ゆ柇姣忎釜椤圭洰鐨凮鏄熷湀閰嶄欢鏁伴噺
+
                             //淇濆瓨鐢熶骇缁勮鍗曚富琛�
-                         string sql = $@"Insert Into Sc_AssemblyBillMain(HYear,HPeriod,HBillType,HBillSubType,HInterID,HDate
+                            string sql = $@"Insert Into Sc_AssemblyBillMain(HYear,HPeriod,HBillType,HBillSubType,HInterID,HDate
                         ,HBillNo,HBillStatus,HMaker,HMakeDate,HMainSourceInterID,HMainSourceEntryID,HMainSourceBillNo
                         ,HICMOInterID,HICMOBillNo,HBarCode_P,HMaterID,HUnitID,HAssemblyStatus,HProdOrgID)
                         values('{DateTime.Now.Year}','{DateTime.Now.Month}','3727','3727',{HInterID1},getdate()
                         ,'{HBillNo1}','1','{user}',getdate(),{omodel.HProcExchInterID.ToString()},{omodel.HProcExchEntryID.ToString()},'{omodel.HProcExchBillNo.ToString()}'
                         ,{omodel.HICMOInterID.ToString()},'{omodel.HICMOBillNo.ToString()}','{omodel.HBarCode_P.ToString()}',{omodel.HMaterID},0,'姹囨姤',{omodel.HProdOrgID})";
-                        oCN.RunProc(sql);
-                        if (prefix == "#0TE911124") {
-                            for (int i = 0; i < sub.Count; i++)
+                            oCN.RunProc(sql);
+                            if (prefix == "#0TE911124")
                             {
-                                //瀛愯〃瀛樺偍
-                             string sq2 = $@"Insert Into Sc_AssemblyBillSub(HInterID,HBillNo_bak,HEntryID,HSourceInterID,HSourceEntryID,HSourceBillNo
+                                for (int i = 0; i < sub.Count; i++)
+                                {
+                                    //瀛愯〃瀛樺偍
+                                    string sq2 = $@"Insert Into Sc_AssemblyBillSub(HInterID,HBillNo_bak,HEntryID,HSourceInterID,HSourceEntryID,HSourceBillNo
                             ,HSourceBillType,HMaterID,HSourceID,HEquipID,HUnitID,HQty
                             ,HGroupID,HWorkerID,HScanDate,HBarCode,HBarCode_P,HSNNumber)
                             values({HInterID1},'{HBillNo1}',{(i + 1)},0,0,''
                             ,'',{sub[i].HMaterID},0,0,0,3
                             ,0,0,getdate(),'{sub[i].HBarCode}','{omodel.HBarCode_P}','') ";
-                                oCN.RunProc(sq2);
+                                    oCN.RunProc(sq2);
+                                }
                             }
-                        }
-                        else
-                        {
-                            for (int i = 0; i < sub.Count; i++)
+                            else
                             {
-                                //瀛愯〃瀛樺偍
-                                string sq2 = $@"Insert Into Sc_AssemblyBillSub(HInterID,HBillNo_bak,HEntryID,HSourceInterID,HSourceEntryID,HSourceBillNo
+                                for (int i = 0; i < sub.Count; i++)
+                                {
+                                    //瀛愯〃瀛樺偍
+                                    string sq2 = $@"Insert Into Sc_AssemblyBillSub(HInterID,HBillNo_bak,HEntryID,HSourceInterID,HSourceEntryID,HSourceBillNo
                             ,HSourceBillType,HMaterID,HSourceID,HEquipID,HUnitID,HQty
                             ,HGroupID,HWorkerID,HScanDate,HBarCode,HBarCode_P,HSNNumber)
                             values({HInterID1},'{HBillNo1}',{(i + 1)},0,0,''
                             ,'',{sub[i].HMaterID},0,0,0,1
                             ,0,0,getdate(),'{sub[i].HBarCode}','{omodel.HBarCode_P}','') ";
-                                oCN.RunProc(sq2);
+                                    oCN.RunProc(sq2);
+                                }
                             }
+
                         }
-                        
+
                     }
 
                 }
@@ -804,8 +835,24 @@
                     objJsonResult.data = null;
                     return objJsonResult;
                 }
-
                 oCN.Commit();
+                if (double.Parse(ds.Tables[0].Rows[0][0].ToString()) == 0)
+                {
+                    //浼犲叆娴佽浆鍗� 鍗曟嵁绫诲瀷銆佷富id銆佸瓙ID銆佸崟鍙枫�佸綋鍓嶇櫥褰曚汉銆佸崟鎹被鍨�
+                    objJsonResult = SaveMESEndWorkFrom_ZD("3772", HProcExchInterID, HProcExchEntryID, HProcExchBillNo, user, "");
+                    if (objJsonResult.code == "0")
+                    {
+                        objJsonResult.code = "0";
+                        objJsonResult.count = 0;
+                        objJsonResult.Message = "鍑虹珯鍗曚繚瀛樻垚鍔燂紝鑷姩瀹屽伐鐢熸垚澶辫触" + objJsonResult.Message;
+                        objJsonResult.data = null;
+                        return objJsonResult;
+                    }
+
+                }
+               
+
+              
 
                 objJsonResult.code = "1";
                 objJsonResult.count = 1;
@@ -1330,6 +1377,41 @@
                 }
 
                 ds = oCN.RunProcReturn(@"exec h_p_Gy_BadRecordsList " + HProcExchInterID + "," + HProcExchEntryID, "h_p_Gy_BadRecordsList");
+
+                objJsonResult.code = "1";
+                objJsonResult.count = 1;
+                objJsonResult.Message = "[0000-1-037]";
+                objJsonResult.data = ds;
+                return objJsonResult;
+            }
+            catch (Exception e)
+            {
+
+                objJsonResult.code = "0";
+                objJsonResult.count = 0;
+                objJsonResult.Message = "[0000-1-010]娌℃湁杩斿洖浠讳綍璁板綍锛�" + e.ToString();
+                objJsonResult.data = null;
+                return objJsonResult;
+            }
+        }
+        //鏍规嵁涓籭d+宸ュ簭鏌�
+        [Route("Cj_SingleStation/BadRecordsList2")]
+        [HttpGet]
+        public object BadRecordsList2(string HProcExchInterID, string HProcID, string user)
+        {
+            try
+            {
+                //鍒ゆ柇鏄惁鏈夋煡璇㈡潈闄�
+                if (!DBUtility.ClsPub.Security_Log("Cj_StationOutBill_Query", 1, false, user))
+                {
+                    objJsonResult.code = "0";
+                    objJsonResult.count = 0;
+                    objJsonResult.Message = "[0000-1-068]鏃犳煡璇㈡潈闄�!";
+                    objJsonResult.data = null;
+                    return objJsonResult;
+                }
+
+                ds = oCN.RunProcReturn(@"exec h_p_Gy_BadRecordsList2 " + HProcExchInterID + "," + HProcID, "h_p_Gy_BadRecordsList2");
 
                 objJsonResult.code = "1";
                 objJsonResult.count = 1;
@@ -2446,6 +2528,340 @@
         }
         #endregion
 
+        #region 宸ュ簭鍗曞搧杩囩珯鑷姩寮�銆佸畬宸� 
+        //鑷姩寮�宸�
+        public json SaveMESBeginWorkFrom_ZD(string HBillType, string HSourceInterID, string HSourceEntryID, string HSourceBillNo, string user, string HSourceBillType)
+        {
+
+
+            //淇濆瓨鏉冮檺
+            if (!DBUtility.ClsPub.Security_Log_second("MES_MESBeginWorkBill_Edit", 1, false, user))
+            {
+                objJsonResult.code = "0";
+                objJsonResult.count = 0;
+                objJsonResult.Message = "鏃犱繚瀛樻潈闄愶紒";
+                objJsonResult.data = null;
+                return objJsonResult;
+            }
+            //鍒ゆ柇浼氳鏈熸槸鍚﹀悎鐞�
+            string s = "";
+            int sYear = 0;
+            int sPeriod = 0;
+            if (DBUtility.Xt_BaseBillFun.Fun_AllowYearPeriod(DateTime.Now, ref sYear, ref sPeriod, ref s) == false)
+            {
+                objJsonResult.code = "0";
+                objJsonResult.count = 0;
+                objJsonResult.Message = s;
+                objJsonResult.data = null;
+                return objJsonResult;
+            }
+
+
+            try
+            {
+
+                ds = oCN.RunProcReturn("exec h_p_JIT_GetInfoByICMOStatusInterID @HSourceInterID=" + HSourceInterID + ",@HSourceEntryID=" + HSourceEntryID + ",@HSourceBillNo='" + HSourceBillNo + "',@HSourceBillType='" + HBillType + "'", "h_p_JIT_GetInfoByICMOStatusInterID");
+
+                Models.ClsSc_MESBeginWorkBillMain ClsSc_MESBeginWorkBillMain = new Models.ClsSc_MESBeginWorkBillMain();
+                ClsSc_MESBeginWorkBillMain.HProcID = int.Parse(ds.Tables[0].Rows[0]["HProcID"].ToString());
+                ClsSc_MESBeginWorkBillMain.HMaterID = int.Parse(ds.Tables[0].Rows[0]["HMaterID"].ToString());
+                ClsSc_MESBeginWorkBillMain.HSourceID = int.Parse(ds.Tables[0].Rows[0]["HSourceID"].ToString());
+                ClsSc_MESBeginWorkBillMain.HMainSourceBillNo = ds.Tables[0].Rows[0]["HSourceBillNo"].ToString();
+                ClsSc_MESBeginWorkBillMain.HMainSourceInterID = int.Parse(ds.Tables[0].Rows[0]["HSourceInterID"].ToString());
+                ClsSc_MESBeginWorkBillMain.HMainSourceEntryID = ds.Tables[0].Rows[0]["HSourceEntryID"].ToString();
+                ClsSc_MESBeginWorkBillMain.HMainSourceBillType = HSourceBillType == null ? "" : HSourceBillType;
+                ClsSc_MESBeginWorkBillMain.HDeptID = int.Parse(ds.Tables[0].Rows[0]["HDeptID"].ToString());
+                ClsSc_MESBeginWorkBillMain.HICMOInterID = int.Parse(ds.Tables[0].Rows[0]["HICMOInterID"].ToString());
+                ClsSc_MESBeginWorkBillMain.HICMOEntryID = int.Parse(ds.Tables[0].Rows[0]["HICMOEntryID"].ToString());
+                ClsSc_MESBeginWorkBillMain.HICMOBillNo = ds.Tables[0].Rows[0]["HICMOBillNo"].ToString();
+                ClsSc_MESBeginWorkBillMain.HProcExchInterID = int.Parse(ds.Tables[0].Rows[0]["HProcExchInterID"].ToString());
+                ClsSc_MESBeginWorkBillMain.HProcExchEntryID = int.Parse(ds.Tables[0].Rows[0]["HProcExchEntryID"].ToString());
+                ClsSc_MESBeginWorkBillMain.HProcExchBillNo = ds.Tables[0].Rows[0]["HProcExchBillNo"].ToString();                
+                ClsSc_MESBeginWorkBillMain.HPeopleSum =1;
+
+                //鑾峰彇鐝
+                DataSet set = oCN.RunProcReturn("exec h_p_Gy_GetWorkShiftInfo " + int.Parse(ds.Tables[0].Rows[0]["HDeptID"].ToString()) + "," + int.Parse(ds.Tables[0].Rows[0]["HCenterID"].ToString()), "h_p_Gy_GetWorkShiftInfo");
+                if (set.Tables[0].Rows.Count > 0)
+                {
+                    ClsSc_MESBeginWorkBillMain.HWorkShiftID = int.Parse(set.Tables[0].Rows[0]["HInterID"].ToString());
+                }
+
+                ds = oCN.RunProcReturn("select * from h_v_xt_UserAssociationSelect where Czymc='" + user + "'", "h_v_xt_UserAssociationSelect");
+
+
+                if (ds.Tables[0].Rows[0]["HEmployeeID"].ToString() == "0")
+                {
+                    objJsonResult.code = "0";
+                    objJsonResult.count = 0;
+                    objJsonResult.Message = "鑷姩寮�宸ヤ繚瀛樺け璐ワ紒鐢ㄦ埛娌℃湁缁戝畾鑱屽憳!";
+                    objJsonResult.data = 1;
+                    return objJsonResult;
+                }
+              
+
+                ClsSc_MESBeginWorkBillMain.HGroupID = int.Parse(ds.Tables[0].Rows[0]["HGroupID"].ToString());
+                ClsSc_MESBeginWorkBillMain.HEmpID = int.Parse(ds.Tables[0].Rows[0]["HEmployeeID"].ToString());
+
+                DLL.ClsSc_MESBeginWorkBill oBill = new DLL.ClsSc_MESBeginWorkBill();
+                List<Models.ClsSc_MESBeginWorkBillMain> lsmain = new List<Models.ClsSc_MESBeginWorkBillMain>();
+                lsmain.Add(ClsSc_MESBeginWorkBillMain);
+                ClsXt_SystemParameter oClsXt_SystemParameter = new ClsXt_SystemParameter();
+
+                DBUtility.ClsPub.CurUserName = user;
+
+                foreach (Models.ClsSc_MESBeginWorkBillMain oItem in lsmain)
+                {
+                    oItem.HBillNo = DBUtility.ClsPub.CreateBillCode("3787", ref DBUtility.ClsPub.sExeReturnInfo, true);
+                   
+                    oItem.HBillType = "3787";
+                    oItem.HBillSubType = "3787";
+                    oItem.HBillStatus = 1;   //鍗曟嵁鐘舵�侊紙1鏈锛�2瀹℃牳閫氳繃锛�3鍏抽棴锛�4浣滃簾锛�5瀹℃牳閫�鍥�,6瀹℃牳涓�,7宸查槄锛�8宸插洖澶嶏紝9缁撴锛�10楠岃瘉,11涓嬭揪锛�12寮�宸�,13鐢宠瀹℃壒,15鐢宠妫�楠岋紝16 鍒ゅ畾鍚堟牸锛�17鍒ゅ畾涓嶅悎鏍硷級     
+                    oItem.HYear = DBUtility.ClsPub.isLong(DateTime.Now.Year);
+                    oItem.HPeriod = DBUtility.ClsPub.isLong(DateTime.Now.Month);
+                    oItem.HMaker = user;
+                    oItem.HMakeDate = DBUtility.ClsPub.isStrNull(DateTime.Now.ToString("yyyy-MM-dd"));
+                    oItem.HBarCodeMakeDate = Convert.ToDateTime(DBUtility.ClsPub.isStrNull(DateTime.Now.ToString("yyyy-MM-dd"))); //鎵弿鏃ユ湡锛堝勾-鏈�-鏃�-鏃�-鍒�-绉掞級
+                    oItem.HRemark = "鑷姩寮�宸�";
+                    oBill.omodel = oItem;
+                }
+
+                oCN.BeginTran();
+                //淇濆瓨
+                //淇濆瓨瀹屾瘯鍚庡鐞�
+                bool bResult = false;
+                if (oBill.omodel.HInterID == 0)
+                {
+
+                    bResult = oBill.AddBill(ref DBUtility.ClsPub.sExeReturnInfo);
+
+                }
+                ds = oCN.RunProcReturn("select * from Sc_MESBeginWorkBillMain where HBillNo='" + oBill.omodel.HBillNo + "'", "Sc_MESBeginWorkBillMain");
+                if (ds.Tables[0].Rows.Count == 0)
+                {
+                    oCN.RollBack();
+                    objJsonResult.code = "0";
+                    objJsonResult.count = 0;
+                    objJsonResult.Message = "鏌ユ棤鍗曟嵁!";
+                    objJsonResult.data = 1;
+                    return objJsonResult;
+                }
+
+                string sAutoCheck = oClsXt_SystemParameter.GetSingleSystemParameter("Sc_MESBeginWorkBill_AutoCheck", ref DBUtility.ClsPub.sExeReturnInfo);
+                if (sAutoCheck == "Y")
+                {
+
+                    if (!oBill.CheckBill(long.Parse(ds.Tables[0].Rows[0]["HInterID"].ToString()), ref DBUtility.ClsPub.sExeReturnInfo))
+                    {
+                        oCN.RollBack();
+                        objJsonResult.code = "0";
+                        objJsonResult.count = 0;
+                        objJsonResult.Message = "瀹℃牳澶辫触!";
+                        objJsonResult.data = 1;
+                        return objJsonResult;
+                    }
+                }
+
+                oCN.Commit();
+
+                if (bResult)
+                {
+
+                    objJsonResult.code = "0";
+                    objJsonResult.count = 1;
+                    objJsonResult.Message = "淇濆瓨鎴愬姛锛�";
+                    objJsonResult.data = 1;
+                    return objJsonResult;
+                }
+                else
+                {
+                    objJsonResult.code = "0";
+                    objJsonResult.count = 0;
+                    objJsonResult.Message = "淇濆瓨澶辫触锛�" + DBUtility.ClsPub.sExeReturnInfo;
+                    objJsonResult.data = 1;
+                    return objJsonResult;
+                }
+            }
+            catch (Exception e)
+            {
+                objJsonResult.code = "0";
+                objJsonResult.count = 0;
+                objJsonResult.Message = e.Message;
+                objJsonResult.data = 1;
+                return objJsonResult;
+            }
+        }
+
+        //鑷姩瀹屽伐
+        public json SaveMESEndWorkFrom_ZD(string HBillType, long HSourceInterID, long HSourceEntryID, string HSourceBillNo, string user, string HSourceBillType)
+        {
+
+            SQLHelper.ClsCN oCN = new SQLHelper.ClsCN();
+            //淇濆瓨鏉冮檺
+            if (!DBUtility.ClsPub.Security_Log_second("MES_MESEndWorkBill_Edit", 1, false, user))
+            {
+                objJsonResult.code = "0";
+                objJsonResult.count = 0;
+                objJsonResult.Message = "鏃犲畬宸ュ崟淇濆瓨鏉冮檺锛�";
+                objJsonResult.data = null;
+                return objJsonResult;
+            }
+            //鍒ゆ柇浼氳鏈熸槸鍚﹀悎鐞�
+            string s = "";
+            int sYear = 0;
+            int sPeriod = 0;
+            if (DBUtility.Xt_BaseBillFun.Fun_AllowYearPeriod(DateTime.Now, ref sYear, ref sPeriod, ref s) == false)
+            {
+                objJsonResult.code = "0";
+                objJsonResult.count = 0;
+                objJsonResult.Message = s;
+                objJsonResult.data = null;
+                return objJsonResult;
+            }
+
+            try
+            {
+
+                ds = oCN.RunProcReturn("exec h_p_JIT_GetInfoByICMOStatusInterID @HSourceInterID=" + HSourceInterID + ",@HSourceEntryID=" + HSourceEntryID + ",@HSourceBillNo='" + HSourceBillNo + "',@HSourceBillType='" + HBillType + "'", "h_p_JIT_GetInfoByICMOStatusInterID");
+
+                Models.ClsSc_MESEndWorkBillMain ClsSc_MESEndWorkBillMain = new Models.ClsSc_MESEndWorkBillMain();
+                ClsSc_MESEndWorkBillMain.HProcID = int.Parse(ds.Tables[0].Rows[0]["HProcID"].ToString());
+                ClsSc_MESEndWorkBillMain.HMaterID = int.Parse(ds.Tables[0].Rows[0]["HMaterID"].ToString());
+                ClsSc_MESEndWorkBillMain.HSourceID = int.Parse(ds.Tables[0].Rows[0]["HSourceID"].ToString());
+                ClsSc_MESEndWorkBillMain.HMainSourceBillNo = ds.Tables[0].Rows[0]["HSourceBillNo"].ToString();
+                ClsSc_MESEndWorkBillMain.HMainSourceInterID = int.Parse(ds.Tables[0].Rows[0]["HSourceInterID"].ToString());
+                ClsSc_MESEndWorkBillMain.HMainSourceEntryID = long.Parse(ds.Tables[0].Rows[0]["HSourceEntryID"].ToString());
+                ClsSc_MESEndWorkBillMain.HMainSourceBillType = HSourceBillType == null ? "" : HSourceBillType;
+                ClsSc_MESEndWorkBillMain.HDeptID = int.Parse(ds.Tables[0].Rows[0]["HDeptID"].ToString());
+                ClsSc_MESEndWorkBillMain.HICMOInterID = int.Parse(ds.Tables[0].Rows[0]["HICMOInterID"].ToString());
+                ClsSc_MESEndWorkBillMain.HICMOEntryID = int.Parse(ds.Tables[0].Rows[0]["HICMOEntryID"].ToString());
+                ClsSc_MESEndWorkBillMain.HICMOBillNo = ds.Tables[0].Rows[0]["HICMOBillNo"].ToString();
+                ClsSc_MESEndWorkBillMain.HProcExchInterID = int.Parse(ds.Tables[0].Rows[0]["HProcExchInterID"].ToString());
+                ClsSc_MESEndWorkBillMain.HProcExchEntryID = int.Parse(ds.Tables[0].Rows[0]["HProcExchEntryID"].ToString());
+                ClsSc_MESEndWorkBillMain.HProcExchBillNo = ds.Tables[0].Rows[0]["HProcExchBillNo"].ToString();
+
+
+                //鑾峰彇鐝
+                DataSet set = oCN.RunProcReturn("exec h_p_Gy_GetWorkShiftInfo " + int.Parse(ds.Tables[0].Rows[0]["HDeptID"].ToString()) + "," + int.Parse(ds.Tables[0].Rows[0]["HCenterID"].ToString()), "h_p_Gy_GetWorkShiftInfo");
+                if (set.Tables[0].Rows.Count > 0)
+                {
+                    ClsSc_MESEndWorkBillMain.HWorkShiftID = int.Parse(set.Tables[0].Rows[0]["HInterID"].ToString());
+                }
+
+                ds = oCN.RunProcReturn("select * from h_v_Cj_GetDefValByUser where 鐢ㄦ埛鍚嶇О='" + user + "'", "h_v_xt_UserAssociationSelect");
+
+                if (ds.Tables[0].Rows[0]["HEmpID"].ToString() == "0")
+                {
+                    objJsonResult.code = "0";
+                    objJsonResult.count = 0;
+                    objJsonResult.Message = "淇濆瓨澶辫触锛佺敤鎴锋病鏈夌粦瀹氳亴鍛�!";
+                    objJsonResult.data = 1;
+                    return objJsonResult;
+                }
+
+                ClsSc_MESEndWorkBillMain.HGroupID = int.Parse(ds.Tables[0].Rows[0]["HGroupID"].ToString());
+                ClsSc_MESEndWorkBillMain.HEmpID = int.Parse(ds.Tables[0].Rows[0]["HEmpID"].ToString());
+
+                DLL.ClsSc_MESEndWorkBill oBill = new DLL.ClsSc_MESEndWorkBill();
+                List<Models.ClsSc_MESEndWorkBillMain> lsmain = new List<Models.ClsSc_MESEndWorkBillMain>();
+                lsmain.Add(ClsSc_MESEndWorkBillMain);
+                ClsXt_SystemParameter oClsXt_SystemParameter = new ClsXt_SystemParameter();
+
+                DBUtility.ClsPub.CurUserName = user;
+
+                foreach (Models.ClsSc_MESEndWorkBillMain oItem in lsmain)
+                {
+                    oItem.HBillNo = DBUtility.ClsPub.CreateBillCode("3788", ref DBUtility.ClsPub.sExeReturnInfo, true);
+
+                    oItem.HBillType = "3788";
+                    oItem.HBillSubType = "3788";
+                    oItem.HReportType = "3";//锛�1鏉$爜鎵弿锛�2鏈哄櫒姹囨姤锛�3鎵嬪伐褰曞叆锛�
+                    oItem.HBillStatus = 1;   //鍗曟嵁鐘舵�侊紙1鏈锛�2瀹℃牳閫氳繃锛�3鍏抽棴锛�4浣滃簾锛�5瀹℃牳閫�鍥�,6瀹℃牳涓�,7宸查槄锛�8宸插洖澶嶏紝9缁撴锛�10楠岃瘉,11涓嬭揪锛�12寮�宸�,13鐢宠瀹℃壒,15鐢宠妫�楠岋紝16 鍒ゅ畾鍚堟牸锛�17鍒ゅ畾涓嶅悎鏍硷級     
+                    oItem.HYear = DBUtility.ClsPub.isLong(DateTime.Now.Year);
+                    oItem.HPeriod = DBUtility.ClsPub.isLong(DateTime.Now.Month);
+                    oItem.HMaker = user;
+                    oItem.HMakeDate = DBUtility.ClsPub.isStrNull(DateTime.Now.ToString("yyyy-MM-dd"));
+                    oItem.HBarCodeMakeDate = Convert.ToDateTime(DBUtility.ClsPub.isStrNull(DateTime.Now.ToString("yyyy-MM-dd"))); //鎵弿鏃ユ湡锛堝勾-鏈�-鏃�-鏃�-鍒�-绉掞級
+                    oItem.HRemark = "鑷姩瀹屽伐";
+                    oBill.omodel = oItem;
+                }
+
+                oCN.BeginTran();
+                //淇濆瓨
+                //淇濆瓨瀹屾瘯鍚庡鐞�
+                bool bResult = false;
+                if (oBill.omodel.HInterID == 0)
+                {
+
+                    bResult = oBill.AddBill(ref DBUtility.ClsPub.sExeReturnInfo);
+                    if (!bResult)
+                    {
+                        oCN.RollBack();
+                        objJsonResult.code = "0";
+                        objJsonResult.count = 0;
+                        objJsonResult.Message = "淇濆瓨澶辫触锛�" + DBUtility.ClsPub.sExeReturnInfo;
+                        objJsonResult.data = 1;
+                        return objJsonResult;
+                    }
+
+                }
+                ds = oCN.RunProcReturn("select * from Sc_MESEndWorkBillMain where HBillNo='" + oBill.omodel.HBillNo + "'", "Sc_MESEndWorkBillMain");
+                if (ds.Tables[0].Rows.Count == 0)
+                {
+                    oCN.RollBack();
+                    objJsonResult.code = "0";
+                    objJsonResult.count = 0;
+                    objJsonResult.Message = "鏌ユ棤鍗曟嵁!";
+                    objJsonResult.data = 1;
+                    return objJsonResult;
+                }
+
+                string sAutoCheck = oClsXt_SystemParameter.GetSingleSystemParameter("Sc_MESEndWorkBill_AutoCheck", ref DBUtility.ClsPub.sExeReturnInfo);
+                if (sAutoCheck == "Y")
+                {
+
+                    if (!oBill.CheckBill(long.Parse(ds.Tables[0].Rows[0]["HInterID"].ToString()), ref DBUtility.ClsPub.sExeReturnInfo))
+                    {
+                        oCN.RollBack();
+                        objJsonResult.code = "0";
+                        objJsonResult.count = 0;
+                        objJsonResult.Message = "瀹℃牳澶辫触!";
+                        objJsonResult.data = 1;
+                        return objJsonResult;
+                    }
+                }
+
+                oCN.Commit();
+
+                if (bResult)
+                {
+
+                    objJsonResult.code = "1";
+                    objJsonResult.count = 1;
+                    objJsonResult.Message = "淇濆瓨鎴愬姛锛�";
+                    objJsonResult.data = 1;
+                    return objJsonResult;
+                }
+                else
+                {
+                    objJsonResult.code = "0";
+                    objJsonResult.count = 0;
+                    objJsonResult.Message = "鑷姩瀹屽伐淇濆瓨澶辫触锛�" + DBUtility.ClsPub.sExeReturnInfo;
+                    objJsonResult.data = 1;
+                    return objJsonResult;
+                }
+            }
+            catch (Exception e)
+            {
+                objJsonResult.code = "0";
+                objJsonResult.count = 0;
+                objJsonResult.Message = e.Message;
+                objJsonResult.data = 1;
+                return objJsonResult;
+            }
+        }
+
+        #endregion
+
         #region 灏忓崼鍗曞搧杩囩珯鎺ュ彛
 
         #region  宸ュ簭鍗曞搧杩囩珯 鎵潯鐮佺爜鏍¢獙杩斿洖淇℃伅(鍙敤浜庨獙璇佹壒娆℃槸鍚﹀叆搴�)

--
Gitblit v1.9.1