yxj
2024-07-03 18bf65577b174d574b36c5fb5ab4364a14c7724a
WebAPI/Controllers/CJGL/Cj_StationOutBillController.cs
@@ -7,9 +7,11 @@
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Diagnostics;
using System.IO;
using System.Web;
using System.Web.Http;
using System.Windows.Forms;
using WebAPI.Models;
namespace WebAPI.Controllers
@@ -19,7 +21,7 @@
    {
        public DBUtility.ClsPub.Enum_BillStatus BillStatus;
        Pub_Class.ClsXt_SystemParameter oSystemParameter = new Pub_Class.ClsXt_SystemParameter();
        public DAL.ClsSc_ICMOBill BillOld = new DAL.ClsSc_ICMOBill();
        private json objJsonResult = new json();
        SQLHelper.ClsCN oCN = new SQLHelper.ClsCN();
        DataSet ds;
@@ -39,17 +41,36 @@
                //反序列化
                string msg2 = "[" + sArray[0].ToString() + "]";
                string user = sArray[1].ToString();//用户名
                string OperationType = sArray[2].ToString();//类型
                string HComputerName = SystemInformation.ComputerName; //设备名称
                //判断是否有编辑权限
                if (!DBUtility.ClsPub.Security_Log("Cj_StationOutBill_Edit", 1, false, user))
                if (OperationType == "5")
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "无编辑权限!";
                    objJsonResult.data = null;
                    return objJsonResult;
                    //判断是否有编辑权限
                    if (!DBUtility.ClsPub.Security_Log("Cj_StationOutBill_Sub_Edit", 1, false, user))
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "完工单无编辑权限!";
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                }
                else {
                    //判断是否有编辑权限
                    if (!DBUtility.ClsPub.Security_Log("Cj_StationOutBill_Edit", 1, false, user))
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "出站单无编辑权限!";
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                }
                Stopwatch sw = new Stopwatch();
                sw.Start();//开始计时
                List<StationBill> list = Newtonsoft.Json.JsonConvert.DeserializeObject<List<StationBill>>(msg2);
                long HMainInterID = 0;
@@ -62,8 +83,8 @@
                int HBillStatus = 0;
                string HMaker = user;//制单人
                string HMouldNum = list[0].HMouldNum;//模穴号
                int HYear = 2021;
                double HPeriod = 1;
                int HYear = DateTime.Now.Year;
                double HPeriod = DateTime.Now.Month;
                string HRemark = list[0].HRemark;//备注
                string HSourceName = list[0].HSourceName;//生产资源名称
                double HPieceQty = list[0].HPieceQty;//进站PCS数
@@ -119,6 +140,17 @@
                long HQCCheckID = list[0].HQCCheckID;//检验员ID
                long HPRDOrgID = list[0].HPRDOrgID;//组织ID
                double HmaterOutqty = list[0].HmaterOutqty;//白坯发布
                double HProcPriceRate = list[0].HProcPriceRate;//工价系数
                int HTemporaryAreaID = list[0].HTemporaryAreaID;//暂放区
                double HWasterQty_Work = list[0].HWasterQty_Work;//工废数量
                double HWasterQty_Mater = list[0].HWasterQty_Mater;//料废数量
                double HBackWorkQty = list[0].HBackWorkQty;//返工数量
                Int64 HShiftsID = list[0].HShiftsID;//生产班次
                double HToCheckQty = list[0].HToCheckQty;//取样数量
                double HLossQty = list[0].HLossQty;//遗失数量
                LogService.Write($"1.字段赋值,用时" + sw.Elapsed );
                //单据完整性判断
                if (HProcExchInterID <= 0)
                {
@@ -191,7 +223,7 @@
                if (oSystemParameter.ShowBill(ref Ret))
                {
                    //判断客户不为龙山汽配
                    if (oSystemParameter.omodel.WMS_CampanyName != "龙山汽配"&& oSystemParameter.omodel.WMS_CampanyName != "瑞与祺") //系统参数
                    if (oSystemParameter.omodel.WMS_CampanyName != "龙山汽配" && oSystemParameter.omodel.WMS_CampanyName != "瑞与祺") //系统参数
                    {
                        if (HSourceID == 0)
                        {
@@ -200,7 +232,7 @@
                            objJsonResult.Message = "生产资源没有选择!";
                            objJsonResult.data = null;
                            return objJsonResult;
                        }
                        }
                    }
                    //判断客户为龙山汽配
                    else if (oSystemParameter.omodel.WMS_CampanyName == "龙山汽配")
@@ -219,6 +251,40 @@
                            }
                        }
                    }
                    //判断客户为瑞与祺
                    else if (oSystemParameter.omodel.WMS_CampanyName == "瑞与祺")
                    {
                        if (HEmpID == 0)
                        {
                            objJsonResult.code = "0";
                            objJsonResult.count = 0;
                            objJsonResult.Message = "操作员没有选择!";
                            objJsonResult.data = null;
                            return objJsonResult;
                        }
                    }
                    //判断客户为斯莫尔
                    else if (oSystemParameter.omodel.WMS_CampanyName == "杭州斯莫尔")
                    {
                        if (HQty + HWasterQty + HBadCount <= 0)
                        {
                            objJsonResult.code = "0";
                            objJsonResult.count = 0;
                            objJsonResult.Message = "合格数量加报废数量加不良数量不能为0!";
                            objJsonResult.data = null;
                            return objJsonResult;
                        }
                    }
                    else {
                        if (HQty + HWasterQty <= 0)
                        {
                            objJsonResult.code = "0";
                            objJsonResult.count = 0;
                            objJsonResult.Message = "合格数量加报废数量不能为0!";
                            objJsonResult.data = null;
                            return objJsonResult;
                        }
                    }
                }
               
                //if (HCenterID == 0)
@@ -229,14 +295,7 @@
                //    objJsonResult.data = null;
                //    return objJsonResult;
                //}
                if (HQty + HWasterQty <= 0)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "合格数量加报废数量不能为0!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                //if (HWorkTimes <= 0)
                //{
@@ -278,7 +337,33 @@
                //    objJsonResult.data = null;
                //    return objJsonResult;
                //}
                //LogService.Write($"2.条件判断,用时" + sw.Elapsed);
                var num = 0;
                //LogService.Write($"3.事务开始,用时" + sw.Elapsed);
                //保存前控制=========================================
                string HBillNote = "";
                ds = oCN.RunProcReturn("Exec  h_p_Sc_StationOutBill_BeforeSaveCtrl  " + HInterID.ToString() + ", '" + HBillNo + "','" + HBillNote + "',1 ", " h_p_Sc_StationOutBill_BeforeSaveCtrl ");
                if (ds == null)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "保存前判断失败!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                if (DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[0]["HBack"]) != "0")
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "保存失败!" + DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[0]["HBackRemark"]);
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                //=========================================================
                //若MAINDI重复则重新获取
                oCN.BeginTran();
@@ -294,6 +379,7 @@
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                    LogService.Write($"3.1,用时" + sw.Elapsed);
                    oCN.RunProc("Insert Into Sc_StationOutBillMain " +
                    "(HBillType,HBillSubType,HInterID,HBillNo,HBillStatus,HDate,HMaker,HMakeDate,HMouldNum" +
                    ",HYear,HPeriod,HRemark,HSourceName,HPieceQty,HWasterQty,HPlanPieceQty,HBadPNL" +
@@ -303,9 +389,10 @@
                    ",HSupID,HQty,HPrice,HMoney,HBadCount,HCenterID,HProcNo,HOrderProcNO,HSourceNameList" +
                    ",HMainSourceInterID,HMainSourceBillNo,HMainSourceBillType,HLastSubProc" +
                    ",HEmpID2,HEmpID3,HEmpID4,HEmpID5,HDSQty,HChongQty,HPriceRate,HWorkTimes,HQCCheckID,HMainInterID,HPRDOrgID" +
                       ",HmaterOutqty" +
                    ",HmaterOutqty,HProcPriceRate,HTemporaryAreaID,HWasterQty_Work,HWasterQty_Mater,HBackWorkQty,HShiftsID" +
                    ",HToCheckQty,HLossQty" +
                    ") " +
                    " values('" + BillType + "','" + HBillSubType + "'," + HInterID + ",'" + HBillNo + "'," + HBillStatus + ",getdate(),'" + HMaker + "',getdate(),'" + HMouldNum + "'" +
                    " values('" + BillType + "','" + (OperationType == "5" ? "SUB" : HBillSubType)  + "'," + HInterID + ",'" + HBillNo + "'," + HBillStatus + ",getdate(),'" + HMaker + "',getdate(),'" + HMouldNum + "'" +
                    "," + HYear + "," + HPeriod + ",'" + HRemark + "','" + HSourceName + "'," + HPieceQty + "," + HWasterQty + "," + HPlanPieceQty + "," + HBadPNL +
                    "," + HICMOInterID + ",'" + HICMOBillNo + "'," + HProcPlanInterID + "," + HProcPlanEntryID + ",'" + HProcPlanBillNo + "'," + HProcExchInterID + "," + HProcExchEntryID +
                    ",'" + HProcExchBillNo + "'," + HMaterID + "," + HProcID + "," + HICMOQty + "," + HPlanQty + ",getdate()," + HSourceID + "," + HPayProcID +
@@ -313,7 +400,12 @@
                    "," + HSupID + "," + HQty + "," + HPrice + "," + HMoney + "," + HBadCount + "," + HCenterID + "," + HProcNo + ",'" + HOrderProcNO + "'" + ",'" + HSourceNameList + "'" +
                    "," + HMainSourceInterID + ",'" + HMainSourceBillNo + "','" + HMainSourceBillType + "'," + Convert.ToString(HLastSubProc ? 1 : 0) +
                    "," + HEmpID2 + "," + HEmpID3 + "," + HEmpID4 + "," + HEmpID5 + "," + HDSQty + "," + HChongQty + "," + HPriceRate + "," + HWorkTimes + "," + HQCCheckID + "," + HMainInterID + "," + HPRDOrgID +
                     ","+ HmaterOutqty + ") ");
                    "," + HmaterOutqty + "," + HProcPriceRate + "," + HTemporaryAreaID + "," + HWasterQty_Work + "," + HWasterQty_Mater + "," + HBackWorkQty +
                    "," + HShiftsID + "," + HToCheckQty + "," + HLossQty + ") ");
                    LogService.Write($"4.新增结束,用时" + sw.Elapsed);
                    LogService.Write("用户:" + user + ",日期:" + DateTime.Now + ",新增工序出站单据:" + HBillNo);
                    oCN.RunProc("Insert into System_log (GeginDate, userid, WorkstationName, WorkList, SystemName, NetuserName, State) select GETDATE(),'" + user + "','" + HComputerName + "','" + "新增工序出站单据:" + HBillNo + "','LMES-工序出站模块','" + DBUtility.ClsPub.IPAddress + "','新增单据'", ref DBUtility.ClsPub.sExeReturnInfo);
                }
                else if ("Modify".Equals(eventType))
                {
@@ -338,14 +430,24 @@
                    ",HWorkTimes=" + HWorkTimes +
                    ",HSaveBillFlag=0 " +
                    ",HPieceQty=" + HPieceQty +
                    ",HToCheckQty=" + HToCheckQty +
                    ",HLossQty=" + HLossQty +
                    ",HQty=" + HQty +
                    ",HDSQty=" + HDSQty +
                    ",HChongQty=" + HChongQty +
                    ",HTemporaryAreaID=" + HTemporaryAreaID +
                    ",HMouldNum='" + HMouldNum + "'" +
                    ",HSourceNameList='" + HSourceNameList + "'" +
                    ",HWasterQty=" + HWasterQty +
                    ",HLastSubProc=" + Convert.ToString(HLastSubProc ? 1 : 0) +
                    ",HWasterQty_Work=" + HWasterQty_Work +
                    ",HWasterQty_Mater=" + HWasterQty_Mater +
                    ",HBackWorkQty=" + HBackWorkQty +
                    ",HShiftsID=" + HShiftsID +
                    " where HInterID=" + HInterID);
                    LogService.Write("用户:" + user + ",日期:" + DateTime.Now + ",修改工序出站单据:" + HBillNo);
                    oCN.RunProc("Insert into System_log (GeginDate, userid, WorkstationName, WorkList, SystemName, NetuserName, State) select GETDATE(),'" + user + "','" + HComputerName + "','" + "修改工序出站单据:" + HBillNo + "','LMES-工序出站模块','" + DBUtility.ClsPub.IPAddress + "','修改单据'", ref DBUtility.ClsPub.sExeReturnInfo);
                }
                else
                {
@@ -358,41 +460,49 @@
                }
                //主表
                ds = oCN.RunProcReturn("exec h_p_MES_StationOutBill_QtyCtrl " + HInterID + "", "h_p_MES_StationOutBill_QtyCtrl");
                if (ds == null)
                {
                    oCN.RollBack();
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "判断数量失败!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                if (ds.Tables[0].Rows.Count == 0)
                {
                    oCN.RollBack();
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "判断数量失败!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                if (ClsPub.isStrNull(ds.Tables[0].Rows[0]["HBack"]) == "2")
                {
                    oCN.RollBack();
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "数量控制," + ClsPub.isStrNull(ds.Tables[0].Rows[0]["HBackRemark"]);
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                oCN.RunProc("exec h_p_Mes_ProcessExchangeRelationQty_Out " + HInterID + ","+ num + "");
                //LogService.Write($"5.系统控制查询判断,用时" + sw.Elapsed);
                //ds = oCN.RunProcReturn("exec h_p_MES_StationOutBill_QtyCtrl " + HInterID + "", "h_p_MES_StationOutBill_QtyCtrl");
                //if (ds == null)
                //{
                //    oCN.RollBack();
                //    objJsonResult.code = "0";
                //    objJsonResult.count = 0;
                //    objJsonResult.Message = "判断数量失败!";
                //    objJsonResult.data = null;
                //    return objJsonResult;
                //}
                //LogService.Write($"5.1,用时" + sw.Elapsed);
                //if (ds.Tables[0].Rows.Count == 0)
                //{
                //    oCN.RollBack();
                //    objJsonResult.code = "0";
                //    objJsonResult.count = 0;
                //    objJsonResult.Message = "判断数量失败!";
                //    objJsonResult.data = null;
                //    return objJsonResult;
                //}
                //LogService.Write($"5.2,用时" + sw.Elapsed);
                //if (ClsPub.isStrNull(ds.Tables[0].Rows[0]["HBack"]) == "2")
                //{
                //    oCN.RollBack();
                //    objJsonResult.code = "0";
                //    objJsonResult.count = 0;
                //    objJsonResult.Message = "数量控制," + ClsPub.isStrNull(ds.Tables[0].Rows[0]["HBackRemark"]);
                //    objJsonResult.data = null;
                //    return objJsonResult;
                //}
                LogService.Write($"6.判断结束,用时" + sw.Elapsed);
                oCN.RunProc("exec h_p_Mes_ProcessExchangeRelationQty_Out " + HInterID + "," + num + "");
                LogService.Write($"6.1,用时" + sw.Elapsed);
                oCN.RunProc("exec h_p_Mes_ProcessExchangeChangeStatus  " + HInterID + " ");
                LogService.Write($"6.2,用时" + sw.Elapsed);
                oCN.RunProc("exec h_p_Mes_StationOutBillBackBarCode  " + HInterID + " ");
                //判断是否是 末道工序
                LogService.Write($"7.存储过程结束,用时" + sw.Elapsed);
                //判断是否是 末道工序
                ds1 = oCN.RunProcReturn(" select HLastProc,HFstProc from Sc_ProcessExchangeBillMain a  " +
                                    " inner join Sc_ProcessExchangeBillSub b on a.HInterID=b.HInterID  " +
                                    " Where a.HInterID=" + HProcExchInterID + " and b.HEntryID=" + HProcExchEntryID + " ", "Sc_ProcessExchangeBillMain");
                LogService.Write($"7.1.查询,用时" + sw.Elapsed);
                //判断是否是新增
                if ("Add".Equals(eventType))
                {
@@ -406,8 +516,10 @@
                            //判断末道 生产汇报汇报 是否勾选
                            if (oSystemParameter.omodel.MES_StationOutBill_LastAutoICMOReport == "Y") //系统参数   
                            {
                                //LogService.Write($"7.1,用时" + sw.Elapsed);
                                //同步生产汇报单
                                objJsonResult= (json)SaveICMOReportBill(HInterID.ToString(), user, HBillNo, HPRDOrgID.ToString());
                                objJsonResult = (json)SaveICMOReportBill(HInterID.ToString(), user, HBillNo, HPRDOrgID.ToString());
                                //LogService.Write($"7.2,用时" + sw.Elapsed);
                                if (objJsonResult.count == 0)
                                {
                                    oCN.RollBack();
@@ -417,12 +529,15 @@
                                    objJsonResult.data = null;
                                    return objJsonResult;
                                }
                                //LogService.Write($"8.生产汇报结束,用时" + sw.Elapsed);
                            }
                            //判断末道 生产入库 是否勾选
                            else if (oSystemParameter.omodel.MES_StationOutBill_AutoStockIn == "Y") //系统参数   
                            {
                                //LogService.Write($"8.1,用时" + sw.Elapsed);
                                //同步生产入库单
                                objJsonResult=(json)SaveProcdutInBill(HBillNo);
                                objJsonResult =(json)SaveProcdutInBill(HBillNo);
                                //LogService.Write($"8.2,用时" + sw.Elapsed);
                                if (objJsonResult.count == 0)
                                {
                                    oCN.RollBack();
@@ -432,14 +547,301 @@
                                    objJsonResult.data = null;
                                    return objJsonResult;
                                }
                                //LogService.Write($"9.生产入库结束,用时" + sw.Elapsed);
                            }
                           
                        }
                    }
                }
                LogService.Write($"7.2.查询,用时" + sw.Elapsed);
                //=========================保存后控制
                DataSet ds2 = oCN.RunProcReturn("Exec h_p_Sc_StationOutBill_AfterSaveCtrl " + HInterID.ToString() + ", '" + HBillNo + "',1 ", "h_p_Sc_StationOutBill_AfterSaveCtrl");
                if (ds2 == null)
                {
                    oCN.RollBack();
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "保存后控制判断失败!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                if (DBUtility.ClsPub.isStrNull(ds2.Tables[0].Rows[0]["HBack"]) != "0")
                {
                    oCN.RollBack();
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "保存失败2!" + DBUtility.ClsPub.isStrNull(ds2.Tables[0].Rows[0]["HBackRemark"]);
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                //============================
                LogService.Write($"10.事务结束,用时" + sw.Elapsed);
                oCN.Commit();
                string sReturn = "";
                if (oSystemParameter.ShowBill(ref sReturn) == true)
                {
                    if (oSystemParameter.omodel.MES_StationOutBill_SaveAutoAddnew == "Y") //系统参数  页面保存自动变成新增状态
                    {
                        objJsonResult.Verify = "Y";
                    }
                    else
                    {
                        objJsonResult.Verify = "N";
                    }
                }
                sw.Stop();//结束计时
                LogService.Write($"11.参数查询结束,新增结束,用时" + sw.Elapsed);
                LogService.Write("END--出站单据保存结束,出站单号:" + HBillNo);
                objJsonResult.code = "1";
                objJsonResult.count = 1;
                objJsonResult.Message = "新增单据成功!";
                objJsonResult.data = ds.Tables[0];
                return objJsonResult;
            }
            catch (Exception e)
            {
                LogService.Write("出站单据保存发生异常,出站单号:" + sArray[0].ToString());
                oCN.RollBack();
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "Exception!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #region 批量新增单据-保存按钮
        [Route("Cj_StationOutBill/BatchAddBill")]
        [HttpPost]
        public object BatchAddBill([FromBody] JObject oMain)
        {
            var _value = oMain["oMain"].ToString();
            string msg1 = _value.ToString();
            string[] sArray = msg1.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
            try
            {
                //反序列化
                string msg2 = "[" + sArray[0].ToString() + "]"; //表头
                string user = sArray[1].ToString();//用户名
                string msg3 = sArray[2].ToString(); //表体
                Int64 OperationType = Convert.ToInt64(sArray[3]); //操作类型
                //判断是否有编辑权限
                if (!DBUtility.ClsPub.Security_Log("Cj_StationOutBill_Edit", 1, false, user))
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "无编辑权限!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                List<StationBill> list = Newtonsoft.Json.JsonConvert.DeserializeObject<List<StationBill>>(msg2);
                List<StationBill> listSub = Newtonsoft.Json.JsonConvert.DeserializeObject<List<StationBill>>(msg3);
                oCN.BeginTran();
                for (int i = 0;i < listSub.Count; i++)
                {
                    long HMainInterID = 0;
                    HMainInterID = list[0].HMainInterID;
                    string eventType = list[0].eventType;
                    string BillType = "3791";
                    string HBillSubType = "3791";
                    long HInterID = listSub[i].HInterID;//递入type得到的单据ID
                    string HBillNo = listSub[i].HBillNo;//递入type得到的单据号
                    int HBillStatus = 0;
                    string HMaker = user;//制单人
                    string HMouldNum = list[0].HMouldNum;//模穴号
                    int HYear = DateTime.Now.Year;
                    double HPeriod = DateTime.Now.Month;
                    string HRemark = list[0].HRemark;//备注
                    string HSourceName = listSub[i].HSourceName;//生产资源名称
                    double HPieceQty = list[0].HPieceQty;//进站PCS数
                    double HWasterQty = listSub[i].HWasterQty;//报废数量
                    double HPlanPieceQty = list[0].HPlanPieceQty;//进站PNL数
                    double HBadPNL = list[0].HBadPNL;//报废PNL数
                    long HICMOInterID = listSub[i].HICMOInterID;//任务单ID
                    string HICMOBillNo = listSub[i].HICMOBillNo;//任务单
                    int HProcPlanInterID = 0;
                    int HProcPlanEntryID = 0;
                    string HProcPlanBillNo = "";
                    long HProcExchInterID = listSub[i].lngBillKey;
                    long HProcExchEntryID = listSub[i].lngBillSubKey;
                    string HProcExchBillNo = listSub[i].HProcExchBillNo;//流转卡
                    long HMaterID = listSub[i].HMaterID;//产品ID
                    long HProcID = listSub[i].HProcID;//当前工序ID
                    double HICMOQty = listSub[i].HICMOQty;//任务单数量
                    double HPlanQty = listSub[i].HPlanQty;//移交PNL数
                    DateTime HStationOutTime = list[0].HStationOutTime;//汇报时间
                    long HSourceID = listSub[i].HSourceID;//生产资源ID
                    long HPayProcID = list[0].HPayProcID;//核算工序ID
                    long HGroupID = list[0].HGroupID;//班组ID
                    long HDeptID = 0;
                    long HEmpID = listSub[i].HEmpID;//操作员ID
                    string HBarCode = list[0].HBarCode;//条形码
                    string HAddr = "";
                    string HBarCodeMaker = "";
                    long HSourceID2 = list[0].HSourceID2;//生产资源2ID
                    long HSourceID3 = list[0].HSourceID3;//生产资源3ID
                    long HSourceID4 = list[0].HSourceID4;//生产资源4ID
                    long HSourceID5 = list[0].HSourceID5;//生产资源5ID
                    long HSupID = 0;
                    double HQty = listSub[i].HQty;//合格数量
                    double HPrice = 0;
                    double HMoney = 0;
                    double HBadCount = list[0].HBadCount;//不良数量
                    long HCenterID = listSub[0].HCenterID;//工作中心ID
                    string HProcNo = listSub[i].HProcNo;//流水号
                    string HOrderProcNO = list[0].HOrderProcNO;//订单跟踪号
                    string HSourceNameList = list[0].HSourceNameList;//设备清单
                    long HMainSourceInterID = listSub[0].HMainSourceInterID;//递入type得到的单据ID
                    long HMainSourceEntryID = listSub[0].HMainSourceEntryID;//递入type得到的单据子ID
                    string HMainSourceBillNo = listSub[0].HMainSourceBillNo;//递入type得到的单据号
                    string HMainSourceBillType = "3790";
                    bool HLastSubProc = listSub[0].HLastSubProc;//转下工序
                    long HEmpID2 = list[0].HEmpID2;//操作员2ID
                    long HEmpID3 = list[0].HEmpID3;//操作员3ID
                    long HEmpID4 = list[0].HEmpID4;//操作员4ID
                    long HEmpID5 = list[0].HEmpID5;//操作员5ID
                    double HDSQty = list[0].HDSQty;//折弯刀数
                    double HChongQty = list[0].HChongQty;//NCT冲次数
                    double HPriceRate = list[0].HPriceRate;//系数
                    double HWorkTimes = list[0].HWorkTimes;//工时
                    long HQCCheckID = list[0].HQCCheckID;//检验员ID
                    long HPRDOrgID = list[0].HPRDOrgID;//组织ID
                    var num = 0;
                    //若MAINDI重复则重新获取
                    if (OperationType == 1)//新增
                    {
                        num = 1;
                        if (!AllowbillNo(HBillNo))
                        {
                            oCN.RollBack();
                            objJsonResult.code = "0";
                            objJsonResult.count = 0;
                            objJsonResult.Message = "单据号重复!";
                            objJsonResult.data = null;
                            return objJsonResult;
                        }
                        oCN.RunProc("Insert Into Sc_StationOutBillMain " +
                        "(HBillType,HBillSubType,HInterID,HBillNo,HBillStatus,HDate,HMaker,HMakeDate,HMouldNum" +
                        ",HYear,HPeriod,HRemark,HSourceName,HPieceQty,HWasterQty,HPlanPieceQty,HBadPNL" +
                        ",HICMOInterID,HICMOBillNo,HProcPlanInterID,HProcPlanEntryID,HProcPlanBillNo,HProcExchInterID,HProcExchEntryID" +
                        ",HProcExchBillNo,HMaterID,HProcID,HICMOQty,HPlanQty,HStationOutTime,HSourceID,HPayProcID" +
                        ",HGroupID,HDeptID,HEmpID,HBarCode,HAddr,HBarCodeMaker,HBarCodeMakeDate,HSourceID2,HSourceID3,HSourceID4,HSourceID5" +
                        ",HSupID,HQty,HPrice,HMoney,HBadCount,HCenterID,HProcNo,HOrderProcNO,HSourceNameList" +
                        ",HMainSourceInterID,HMainSourceBillNo,HMainSourceBillType,HLastSubProc" +
                        ",HEmpID2,HEmpID3,HEmpID4,HEmpID5,HDSQty,HChongQty,HPriceRate,HWorkTimes,HQCCheckID,HMainInterID,HPRDOrgID,HMainSourceEntryID" +
                        ") " +
                        " values('" + BillType + "','" + HBillSubType + "'," + HInterID + ",'" + HBillNo + "'," + HBillStatus + ",getdate(),'" + HMaker + "',getdate(),'" + HMouldNum + "'" +
                        "," + HYear + "," + HPeriod + ",'" + HRemark + "','" + HSourceName + "'," + HPieceQty + "," + HWasterQty + "," + HPlanPieceQty + "," + HBadPNL +
                        "," + HICMOInterID + ",'" + HICMOBillNo + "'," + HProcPlanInterID + "," + HProcPlanEntryID + ",'" + HProcPlanBillNo + "'," + HProcExchInterID + "," + HProcExchEntryID +
                        ",'" + HProcExchBillNo + "'," + HMaterID + "," + HProcID + "," + HICMOQty + "," + HPlanQty + ",getdate()," + HSourceID + "," + HPayProcID +
                        "," + HGroupID + "," + HDeptID + "," + HEmpID + ",'" + HBarCode + "','" + HAddr + "','" + HBarCodeMaker + "',getdate()" + "," + HSourceID2 + "," + HSourceID3 + "," + HSourceID4 + "," + HSourceID5 +
                        "," + HSupID + "," + HQty + "," + HPrice + "," + HMoney + "," + HBadCount + "," + HCenterID + "," + HProcNo + ",'" + HOrderProcNO + "'" + ",'" + HSourceNameList + "'" +
                        "," + HMainSourceInterID + ",'" + HMainSourceBillNo + "','" + HMainSourceBillType + "'," + Convert.ToString(HLastSubProc ? 1 : 0) +
                        "," + HEmpID2 + "," + HEmpID3 + "," + HEmpID4 + "," + HEmpID5 + "," + HDSQty + "," + HChongQty + "," + HPriceRate + "," + HWorkTimes + "," + HQCCheckID + "," + HMainInterID + "," + HPRDOrgID + "," + HMainSourceEntryID +
                        ") ");
                    }
                    else
                    {
                        oCN.RollBack();
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "操作类型无效!";
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                    //主表
                    ds = oCN.RunProcReturn("exec h_p_MES_StationOutBill_QtyCtrl " + HInterID + "", "h_p_MES_StationOutBill_QtyCtrl");
                    if (ds == null)
                    {
                        oCN.RollBack();
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "判断数量失败!";
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                    if (ds.Tables[0].Rows.Count == 0)
                    {
                        oCN.RollBack();
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "判断数量失败!";
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                    if (ClsPub.isStrNull(ds.Tables[0].Rows[0]["HBack"]) == "2")
                    {
                        oCN.RollBack();
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "数量控制," + ClsPub.isStrNull(ds.Tables[0].Rows[0]["HBackRemark"]);
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                    oCN.RunProc("exec h_p_Mes_ProcessExchangeRelationQty_Out " + HInterID + "," + num + "");
                    oCN.RunProc("exec h_p_Mes_ProcessExchangeChangeStatus  " + HInterID + " ");
                    oCN.RunProc("exec h_p_Mes_StationOutBillBackBarCode  " + HInterID + " ");
                    //判断是否是 末道工序
                    ds1 = oCN.RunProcReturn(" select HLastProc,HFstProc from Sc_ProcessExchangeBillMain a  " +
                                        " inner join Sc_ProcessExchangeBillSub b on a.HInterID=b.HInterID  " +
                                        " Where a.HInterID=" + HProcExchInterID + " and b.HEntryID=" + HProcExchEntryID + " ", "Sc_ProcessExchangeBillMain");
                    //判断是否是新增
                    if (OperationType == 1)
                    {
                        //判断是否是末道工序
                        if (ClsPub.isStrNull(ds1.Tables[0].Rows[0]["HLastProc"]) == "是")
                        {
                            //获取系统参数
                            string Return = "";
                            if (oSystemParameter.ShowBill(ref Return))
                            {
                                //判断末道 生产汇报汇报 是否勾选
                                if (oSystemParameter.omodel.MES_StationOutBill_LastAutoICMOReport == "Y") //系统参数
                                {
                                    //同步生产汇报单
                                    objJsonResult = (json)SaveICMOReportBill(HInterID.ToString(), user, HBillNo, HPRDOrgID.ToString());
                                    if (objJsonResult.count == 0)
                                    {
                                        oCN.RollBack();
                                        objJsonResult.code = "0";
                                        objJsonResult.count = 0;
                                        objJsonResult.Message = objJsonResult.Message;
                                        objJsonResult.data = null;
                                        return objJsonResult;
                                    }
                                }
                                //判断末道 生产入库 是否勾选
                                else if (oSystemParameter.omodel.MES_StationOutBill_AutoStockIn == "Y") //系统参数
                                {
                                    //同步生产入库单
                                    objJsonResult = (json)SaveProcdutInBill(HBillNo);
                                    if (objJsonResult.count == 0)
                                    {
                                        oCN.RollBack();
                                        objJsonResult.code = "0";
                                        objJsonResult.count = 0;
                                        objJsonResult.Message = objJsonResult.Message;
                                        objJsonResult.data = null;
                                        return objJsonResult;
                                    }
                                }
                            }
                        }
                    }
                }
                oCN.Commit();
                string sReturn = "";
                if (oSystemParameter.ShowBill(ref sReturn) == true)
@@ -469,6 +871,7 @@
                return objJsonResult;
            }
        }
        #endregion
        #region 末道工序 生产汇报
        public object SaveICMOReportBill(string InterID, string user, string BillNo, string OrganizationID)
@@ -1100,12 +1503,12 @@
        //递入物料信息 返回未完全汇报的流转卡
        [Route("LEMS/Sc_StationOutBill_Mul_RYQ")]
        [HttpGet]
        public object Sc_StationOutBill_Mul_RYQ(String HMaterName, Int64 HOrgID)
        public object Sc_StationOutBill_Mul_RYQ(String HMaterName,string HProcNumber, Int64 HOrgID)
        {
            try
            {
                SQLHelper.ClsCN oCN = new SQLHelper.ClsCN();
                DataSet ds = oCN.RunProcReturn("exec h_p_CJGXPLHB_Query '" + HMaterName + "'," + HOrgID + "", "h_p_CJGXPLHB_Query");
                DataSet ds = oCN.RunProcReturn("exec h_p_CJGXPLHB_Query '" + HMaterName + "'," + HOrgID + ",'"+ HProcNumber + "'", "h_p_CJGXPLHB_Query");
               
                if (ds == null || ds.Tables[0].Rows.Count <= 0)
                {
@@ -1191,24 +1594,64 @@
        #region 返回工序出站汇报单列表
        [Route("Cj_StationOutBill/get_Display")]
        [HttpGet]
        public object get_Display(string sWhere,string user)
        public object get_Display(string sWhere,string user,string HBillSubType)
        {
            try
            {
                List<object> columnNameList = new List<object>();
                //判断是否有查询权限
                if (!DBUtility.ClsPub.Security_Log("Cj_StationOutBill_Query", 1, false, user))
                if (HBillSubType == "SUB")
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "无查询权限!";
                    objJsonResult.data = null;
                    return objJsonResult;
                    //判断是否有查询权限
                    if (!DBUtility.ClsPub.Security_Log("Cj_StationOutBill_Sub_Query", 1, false, user))
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "完工单无查询权限!";
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                }
                else {
                    //判断是否有查询权限
                    if (!DBUtility.ClsPub.Security_Log("Cj_StationOutBill_Query", 1, false, user))
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "出站单无查询权限!";
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                }
                //获取系统参数
                string Ret = "";
                if (oSystemParameter.ShowBill(ref Ret))
                {
                    //判断客户为龙山汽配
                    if (oSystemParameter.omodel.WMS_CampanyName == "龙山汽配")
                    {
                        //获取需要拼接的字符串
                        string sql_splice = DBUtility.ClsPub.SpliceSQL(user, "工序汇报单列表");
                        if (sql_splice == "没有查询到相关用户信息")
                        {
                            objJsonResult.code = "0";
                            objJsonResult.count = 0;
                            objJsonResult.Message = "没有查询到相关用户信息!";
                            objJsonResult.data = null;
                            return objJsonResult;
                        }
                        else
                        {
                            sWhere += sql_splice;
                        }
                    }
                }
                if (sWhere == null || sWhere.Equals(""))
                {
                    ds = oCN.RunProcReturn("select * from h_v_MES_StationOutBillList  order by hmainid desc", "h_v_MES_StationOutBillList");
                    ds = oCN.RunProcReturn("select * from h_v_MES_StationOutBillList where 1 = 1" + sWhere + "order by hmainid desc", "h_v_MES_StationOutBillList");
                }
                else
                {
@@ -1242,6 +1685,63 @@
                //objJsonResult.data = null;
                //return objJsonResult;
                //}
            }
            catch (Exception e)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "Exception!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
        #region 工序出站汇报单 子表查询
        [Route("Cj_StationOutBill/get_SubDisplay")]
        [HttpGet]
        public object get_SubDisplay(string sWhere, string TableName)
        {
            try
            {
                List<object> columnNameList = new List<object>();
                string sql = "";
                switch (TableName)
                {
                    case "TechParam":
                        sql = "select * from h_v_Sc_StationOutBillSubQuery_TechParam where 1 = 1 and HInterID=" + sWhere;
                        break;
                    case "Note":
                        sql = "select * from h_v_Sc_StationOutBillSubQuery_Note where 1 = 1 and HInterID=" + sWhere;
                        break;
                    case "SN":
                        sql = "select * from h_v_Sc_StationOutBillSubQuery_SN where 1 = 1 and HInterID=" + sWhere;
                        break;
                    case "Emp":
                        sql = "select * from h_v_Sc_StationOutBillSubQuery_Emp where 1 = 1 and HInterID=" + sWhere;
                        break;
                }
                ds = oCN.RunProcReturn(sql, TableName);
                //添加列名
                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));//获取到DataColumn列对象的列名
                }
                objJsonResult.code = "1";
                objJsonResult.count = 1;
                objJsonResult.Message = "Sucess!";
                objJsonResult.list = columnNameList;
                objJsonResult.data = ds.Tables[0];
                return objJsonResult;
            }
            catch (Exception e)
            {
@@ -1608,20 +2108,35 @@
        #region 根据id删除出站单
        [Route("Cj_StationOutBill/del_StationOutBill")]
        [HttpGet]
        public object del_StationOutBill(long HInterID, string HDeleteMan)
        public object del_StationOutBill(long HInterID, string HDeleteMan,string HBillSubType)
        {
            try
            {
                //编辑权限
                if (!DBUtility.ClsPub.Security_Log("Cj_StationOutBill_Drop", 1, false, HDeleteMan))
                string HComputerName = SystemInformation.ComputerName; //设备名称
                if (HBillSubType == "SUB")
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "无权限!";
                    objJsonResult.data = null;
                    return objJsonResult;
                    //编辑权限
                    if (!DBUtility.ClsPub.Security_Log("Cj_StationOutBill_Sub_Drop", 1, false, HDeleteMan))
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "完工单无权限!";
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                }
                else {
                    //编辑权限
                    if (!DBUtility.ClsPub.Security_Log("Cj_StationOutBill_Drop", 1, false, HDeleteMan))
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "出站单无权限!";
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                }
                DAL.ClsSc_StationOutBill oBill = new DAL.ClsSc_StationOutBill();
                if (oBill.ShowBill(HInterID, ref DBUtility.ClsPub.sExeReturnInfo))
                {
@@ -1681,10 +2196,52 @@
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                    //删除前判断有没有生成金蝶单据(生产汇报单,生产入库单)
                    ds = oCn.RunProcReturn($"exec h_p_Cj_StationOutBill_BeforeDelCtrl {HInterID}", "h_p_Cj_StationOutBill_BeforeDelCtrl");
                    if (ds == null || ds.Tables[0].Rows.Count <= 0)
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "删除出站汇报单发生异常,没有任何返回记录!";
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                    else
                    {
                        if (ds.Tables[0].Rows[0]["HBackCount"].ToString() == "1")
                        {
                            objJsonResult.code = "0";
                            objJsonResult.count = 0;
                            objJsonResult.Message = ds.Tables[0].Rows[0]["HRemarkBack"].ToString();
                            objJsonResult.data = null;
                            return objJsonResult;
                        }
                    }
                    //写入删除日志
                    string WorkList = "删除出站单:" + oBill.omodel.HBillNo;
                    if (!oBill.DeleteBill(oBill.omodel.HInterID, oBill.omodel.HProcExchInterID, oBill.omodel.HProcExchEntryID, ref DBUtility.ClsPub.sExeReturnInfo))
                    //删除前控制=========================================
                    string HBillNo = oBill.omodel.HBillNo;
                    string sql1 = "exec h_p_Sc_StationOutBill_BeforeDelCtrl " + HInterID + ",'" + HBillNo + "','" + HDeleteMan + "'";
                    ds = oCN.RunProcReturn(sql1, "h_p_Sc_StationOutBill_BeforeDelCtrl");
                    if (ds == null || ds.Tables.Count == 0 || ds.Tables[0].Rows.Count == 0)
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "删除失败!原因:删除前判断失败,请与网络管理人员联系";
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                    if (ds.Tables[0].Rows[0]["HBack"].ToString() != "0")
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "删除失败!原因:" + ds.Tables[0].Rows[0]["HRemark"].ToString(); ;
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                    //==================================================================================
                    if (!oBill.DeleteBill(oBill.omodel.HInterID, oBill.omodel.HProcExchInterID, oBill.omodel.HProcExchEntryID, HBillNo, "h_p_Sc_StationOutBill_AfterDelCtrl", HDeleteMan, ref DBUtility.ClsPub.sExeReturnInfo))
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
@@ -1694,12 +2251,153 @@
                    }
                    else
                    {
                        //写入删除日志
                        LogService.Write("用户:" + HDeleteMan + ",日期:" + DateTime.Now + ",删除工序出站单据:" + oBill.omodel.HBillNo);
                        oCN.RunProc("Insert into System_log (GeginDate, userid, WorkstationName, WorkList, SystemName, NetuserName, State) select GETDATE(),'" + HDeleteMan + "','" + HComputerName + "','" + "删除工序出站单据:" + oBill.omodel.HBillNo + "','LMES-工序出站模块','" + DBUtility.ClsPub.IPAddress + "','删除单据'", ref DBUtility.ClsPub.sExeReturnInfo);
                        objJsonResult.code = "1";
                        objJsonResult.count = 1;
                        objJsonResult.Message = "删除成功!";
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                }
                else
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "单据未找到!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
            }
            catch (Exception e)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "异常!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
        #region 根据id删除出站单 子件条码
        [Route("Cj_StationOutBill/del_StationOutBill_SN")]
        [HttpGet]
        public object del_StationOutBill_SN(long HInterID,string HBardcode, string HDeleteMan, string HBillSubType)
        {
            try
            {
                string HComputerName = SystemInformation.ComputerName; //设备名称
                if (HBillSubType == "SUB")
                {
                    //编辑权限
                    if (!DBUtility.ClsPub.Security_Log("Cj_StationOutBill_Sub_Drop", 1, false, HDeleteMan))
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "完工单无权限!";
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                }
                else
                {
                    //编辑权限
                    if (!DBUtility.ClsPub.Security_Log("Cj_StationOutBill_Drop", 1, false, HDeleteMan))
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "出站单无权限!";
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                }
                DAL.ClsSc_StationOutBill oBill = new DAL.ClsSc_StationOutBill();
                if (oBill.ShowBill(HInterID, ref DBUtility.ClsPub.sExeReturnInfo))
                {
                    string sReturn = "";
                    if (oSystemParameter.ShowBill(ref sReturn))
                    {
                        if (oSystemParameter.omodel.MES_StationOutBill_DeleteCtl == "Y")
                        {
                            if (oBill.omodel.HMaker != HDeleteMan && (HDeleteMan != "admin" && HDeleteMan != "Admin"))
                            {
                                objJsonResult.code = "0";
                                objJsonResult.count = 0;
                                objJsonResult.Message = "只能删除本人的单据!";
                                objJsonResult.data = null;
                                return objJsonResult;
                            }
                        }
                    }
                    SQLHelper.ClsCN oCn = new SQLHelper.ClsCN();
                    DataSet ds;
                    //判断是否存在 相同单据号 的领料单 判断生产订单是否已结案,要求计划手工反结案
                    ds = oCn.RunProcReturn("exec h_p_MES_StationOutBill_DelCtrl  '" + oBill.omodel.HBillNo + "'", "h_p_MES_StationOutBill_DelCtrl");
                    if (ds == null)
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "判断关联失败!";
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                    if (ds.Tables[0].Rows.Count > 0 && Pub_Class.ClsPub.isInt(ds.Tables[0].Rows[0][0]) == 2)
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = Pub_Class.ClsPub.isStrNull(ds.Tables[0].Rows[0][1]);
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                    if (oBill.omodel.HChecker != "")
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "单据已经审核,不能删除!";
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                    ds = oCn.RunProcReturn($"exec h_p_DelOutInBill {HInterID},'MES_StationOutBill_DeleteRelationCtl'", "h_p_DelOutInBill");
                    if (ds.Tables[0].Rows[0][0].ToString() == "0")
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "系统参数控制,已有下道工序,不能删除!";
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                    oCn.BeginTran();
                    ds = oCn.RunProcReturn($"select * from Sc_AssemblyBillMain  where HMainSourceInterID={oBill.omodel.HProcExchInterID} and HMainSourceEntryID={oBill.omodel.HProcExchEntryID} and HBarCode_P='{HBardcode}'", "Sc_AssemblyBillMain");
                    if (ds.Tables[0].Rows.Count > 0)
                    {
                        oCn.RunProc($"delete from Sc_AssemblyBillMain  where HMainSourceInterID={oBill.omodel.HProcExchInterID} and HMainSourceEntryID={oBill.omodel.HProcExchEntryID} and HBarCode_P='{HBardcode}'");
                        oCn.RunProc($"delete from Sc_AssemblyBillMain  where HInterID={ds.Tables[0].Rows[0]["HInterID"].ToString()} and HBarCode_P='{HBardcode}'");
                    }
                    oCn.RunProc("delete from Sc_StationOutBillSub_SN where HInterID=" + HInterID + " and HBarCode='" + HBardcode + "'");
                    oCn.RunProc("update  Sc_StationOutBillMain set HQty-=1 where HInterID=" + HInterID);
                    oCn.Commit();
                    objJsonResult.code = "1";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "删除成功!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                else
                {
@@ -1835,68 +2533,117 @@
        #region 审核
        [Route("Cj_StationOutBill/set_CheckBill")]
        [HttpGet]
        public object set_CheckBill(int HInterID, string CurUserName)
        public object set_CheckBill(string HInterID, string CurUserName,string HBillSubType)
        {
            try
            {
                string ModRightNameCheck = "Cj_StationOutBill_Check";
                ////审核权限
                if (!DBUtility.ClsPub.Security_Log(ModRightNameCheck, 1, false, CurUserName))
                if (HBillSubType == "SUB")
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "审核失败!无权限!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                if (HInterID == 0)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "单据ID为0,不能审核!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                DAL.ClsSc_StationOutBill oBill = new DAL.ClsSc_StationOutBill();
                //查看是否已审核,关闭,作废
                if (oBill.ShowBill(HInterID, ref DBUtility.ClsPub.sExeReturnInfo))
                {
                    if (oBill.omodel.HChecker.Trim() != "")
                    ////审核权限
                    if (!DBUtility.ClsPub.Security_Log("Cj_StationOutBill_Sub_Check", 1, false, CurUserName))
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "单据已审核!不能再次审核";
                        objJsonResult.Message = "完工单审核失败!无权限!";
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                }
                else
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "单据不存在!原因:" + DBUtility.ClsPub.sExeReturnInfo;
                    objJsonResult.data = null;
                    return objJsonResult;
                {   ////审核权限
                    if (!DBUtility.ClsPub.Security_Log("Cj_StationOutBill_Check", 1, false, CurUserName))
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "出站单审核失败!无权限!";
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                }
                //审核
                if (Cj_StationOutBillCheckBill(HInterID, CurUserName, oBill.omodel.HLastSubProc, ref DBUtility.ClsPub.sExeReturnInfo))
                var HInterIDs = HInterID.Split(',');
                string[] HBillNo = new string[HInterIDs.Length];
                DAL.ClsSc_StationOutBill oBill = new DAL.ClsSc_StationOutBill();
                for (int i = 0; i < HInterIDs.Length; i++)
                {
                    objJsonResult.code = "1";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "审核成功!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                else
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "审核失败!原因:" + DBUtility.ClsPub.sExeReturnInfo;
                    objJsonResult.data = null;
                    return objJsonResult;
                    if (HInterIDs[i] == "0")
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "第"+(i+1)+"行:单据ID为0,不能审核!";
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                    //查看是否已审核,关闭,作废
                    if (oBill.ShowBill(long.Parse(HInterIDs[i]), ref DBUtility.ClsPub.sExeReturnInfo))
                    {
                        if (oBill.omodel.HChecker.Trim() != "")
                        {
                            objJsonResult.code = "0";
                            objJsonResult.count = 0;
                            objJsonResult.Message = "第" + (i + 1) + "行:单据已审核!不能再次审核";
                            objJsonResult.data = null;
                            return objJsonResult;
                        }
                        HBillNo[i] = oBill.omodel.HBillNo;
                    }
                    else
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "第" + (i + 1) + "行:单据不存在!原因:" + DBUtility.ClsPub.sExeReturnInfo;
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                }
                int j = 0;
                for (int i = 0; i < HInterIDs.Length; i++)
                {
                    //审核前控制
                    string sql = "exec h_p_Sc_StationOutBill_BeforeCheckCtrl " + HInterIDs[i] + ",'" + HBillNo[i] + "','" + CurUserName + "'";
                    ds = oCN.RunProcReturn(sql, "h_p_Sc_StationOutBill_BeforeCheckCtrl");
                    if (ds == null || ds.Tables.Count == 0 || ds.Tables[0].Rows.Count == 0)
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 1;
                        objJsonResult.Message = "审核失败!原因:审核前判断失败,请与网络管理人员联系";
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                    if (ds.Tables[0].Rows[0]["HBack"].ToString() != "0")
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 1;
                        objJsonResult.Message = "审核失败!原因:" + ds.Tables[0].Rows[0]["HRemark"].ToString(); ;
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                    //审核
                    if (Cj_StationOutBillCheckBill(long.Parse(HInterIDs[i]), HBillNo[i], CurUserName, oBill.omodel.HLastSubProc, ref DBUtility.ClsPub.sExeReturnInfo))
                    {
                        j += 1;
                    }
                    else
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "成功:" + j + "行,第" + (i + 1) + "行:审核失败!原因:" + DBUtility.ClsPub.sExeReturnInfo;
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                }
                objJsonResult.code = "1";
                objJsonResult.count = 1;
                objJsonResult.Message = "全部执行成功!";
                objJsonResult.data = null;
                return objJsonResult;
            }
            catch (Exception e)
            {
@@ -1909,7 +2656,7 @@
        }
        //审核
        public bool Cj_StationOutBillCheckBill(Int64 lngBillKey, string CurUserName,bool HLastSubProc, ref string sReturn)
        public bool Cj_StationOutBillCheckBill(Int64 lngBillKey, string HBillNo, string CurUserName,bool HLastSubProc, ref string sReturn)
        {
            try
            {
@@ -1937,6 +2684,37 @@
                else if (Pub_Class.ClsPub.isStrNull(ds1.Tables[0].Rows[0]["HFstProc"]) == "是")
                {
                }
                DataSet dataSet = oCN.RunProcReturn(@"select a.HProcExchBillNo,a.HQty,b.HQty HProcExchQty  from Sc_StationOutBillMain a
inner join Sc_ProcessExchangeBillMain b on a.HProcExchInterID = b.HInterID
where a.HInterID = " + lngBillKey, "Sc_ProcessExchangeBillMain");
                if (dataSet.Tables[0].Rows.Count > 0)
                {
                    string HProcExchBillNo = dataSet.Tables[0].Rows[0]["HProcExchBillNo"].ToString();
                    double HQty = double.Parse(dataSet.Tables[0].Rows[0]["HQty"].ToString());
                    double HProcExchQty = double.Parse(dataSet.Tables[0].Rows[0]["HProcExchQty"].ToString());
                    LogService.Write("出站单据审核更改流转卡数量,流转卡:" + HProcExchBillNo + ",出站单号:" + HBillNo + ",原流转卡数量:" + HProcExchQty + ",新流转卡数量:" + HQty);
                }
                //审核后控制
                string sql = "exec h_p_Sc_StationOutBill_AfterCheckCtrl " + lngBillKey + ",'" + HBillNo + "','" + CurUserName + "'";
                ds = oCN.RunProcReturn(sql, "h_p_Sc_StationOutBill_AfterCheckCtrl");
                if (ds == null || ds.Tables.Count == 0 || ds.Tables[0].Rows.Count == 0)
                {
                    sReturn = "审核过程中出错,请与网络管理人员联系";
                    oCN.RollBack();
                    return false;
                }
                if (ds.Tables[0].Rows[0]["HBack"].ToString() != "0")
                {
                    sReturn = ds.Tables[0].Rows[0]["HRemark"].ToString();
                    oCN.RollBack();
                    return false;
                }
                sReturn = sReturn + " 审核功能!";
                oCN.Commit();
                return true;
@@ -1953,67 +2731,136 @@
        #region 反审核
        [Route("Cj_StationOutBill/set_AbandonCheck")]
        [HttpGet]
        public object set_AbandonCheck(int HInterID, string CurUserName)
        public object set_AbandonCheck(string HInterID, string CurUserName,string HBillSubType)
        {
            try
            {
                string ModRightNameCheck = "Cj_StationOutBill_Check";
                ////审核权限
                if (!DBUtility.ClsPub.Security_Log(ModRightNameCheck, 1, false, CurUserName))
                if (HBillSubType == "SUB")
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "反审核失败!无权限!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                if (HInterID == 0)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "单据ID为0,不能反审核!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                DAL.ClsSc_StationOutBill oBill = new DAL.ClsSc_StationOutBill();
                //查看是否已审核,关闭,作废
                if (oBill.ShowBill(HInterID, ref DBUtility.ClsPub.sExeReturnInfo))
                {
                    if (oBill.omodel.HChecker.Trim() == "")
                    ////审核权限
                    if (!DBUtility.ClsPub.Security_Log("Cj_StationOutBill_Sub_Check", 1, false, CurUserName))
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "单据未审核!不需要反审核!";
                        objJsonResult.Message = "完工单反审核失败!无权限!";
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                }
                else
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "单据不存在!原因:" + DBUtility.ClsPub.sExeReturnInfo;
                    objJsonResult.data = null;
                    return objJsonResult;
                    ////审核权限
                    if (!DBUtility.ClsPub.Security_Log("Cj_StationOutBill_Check", 1, false, CurUserName))
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "出站单反审核失败!无权限!";
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                }
                //反审核
                if (Cj_StationOutBillAbandonCheckBill(HInterID, CurUserName, oBill.omodel.HLastSubProc, ref DBUtility.ClsPub.sExeReturnInfo))
                var HInterIDs = HInterID.Split(',');
                string[] HBillNo = new string[HInterIDs.Length];
                DAL.ClsSc_StationOutBill oBill = new DAL.ClsSc_StationOutBill();
                //获取系统参数
                string Ret = "";
                oSystemParameter.ShowBill(ref Ret);
                    for (int i = 0; i < HInterIDs.Length; i++)
                {
                    objJsonResult.code = "1";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "反审核成功!";
                    objJsonResult.data = null;
                    return objJsonResult;
                    if (long.Parse(HInterIDs[i]) == 0)
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "第" + (i + 1) + "行:单据ID为0,不能反审核!";
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                    //查看是否已审核,关闭,作废
                    if (oBill.ShowBill(long.Parse(HInterIDs[i]), ref DBUtility.ClsPub.sExeReturnInfo))
                    {
                        if (oBill.omodel.HChecker.Trim() == "")
                        {
                            objJsonResult.code = "0";
                            objJsonResult.count = 0;
                            objJsonResult.Message = "第" + (i + 1) + "行:单据未审核!不需要反审核!";
                            objJsonResult.data = null;
                            return objJsonResult;
                        }
                        //审核人必须和反审核人保持一致  乔一
                        if (oSystemParameter.omodel.WMS_CampanyName == "乔一")
                        {
                            if (oBill.omodel.HChecker.Trim() != CurUserName)
                            {
                                objJsonResult.code = "0";
                                objJsonResult.count = 0;
                                objJsonResult.Message = "第" + (i + 1) + "行:审核人和反审核人不一致!";
                                objJsonResult.data = null;
                                return objJsonResult;
                            }
                        }
                        HBillNo[i] = oBill.omodel.HBillNo;
                    }
                    else
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "第" + (i + 1) + "行:单据不存在!原因:" + DBUtility.ClsPub.sExeReturnInfo;
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                }
                else
                int j = 0;
                for (int i = 0; i < HInterIDs.Length; i++)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "反审核失败!原因:" + DBUtility.ClsPub.sExeReturnInfo;
                    objJsonResult.data = null;
                    return objJsonResult;
                    //反审核前控制
                    string sql = "exec h_p_Sc_StationOutBill_BeforeUnCheckCtrl " + HInterIDs[i] + ",'" + HBillNo[i] + "','" + CurUserName + "'";
                    ds = oCN.RunProcReturn(sql, "h_p_Sc_StationOutBill_BeforeUnCheckCtrl");
                    if (ds == null || ds.Tables.Count == 0 || ds.Tables[0].Rows.Count == 0)
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 1;
                        objJsonResult.Message = "反审核失败!原因:反审核前判断失败,请与网络管理人员联系";
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                    if (ds.Tables[0].Rows[0]["HBack"].ToString() != "0")
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 1;
                        objJsonResult.Message = "反审核失败!原因:" + ds.Tables[0].Rows[0]["HRemark"].ToString(); ;
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                    //反审核
                    if (Cj_StationOutBillAbandonCheckBill(long.Parse(HInterIDs[i]),HBillNo[i], CurUserName, oBill.omodel.HLastSubProc, ref DBUtility.ClsPub.sExeReturnInfo))
                    {
                        j += 1;
                    }
                    else
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "成功:" + j + "行,第" + (i + 1) + "行:反审核失败!原因:" + DBUtility.ClsPub.sExeReturnInfo;
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                }
                objJsonResult.code = "1";
                objJsonResult.count = 1;
                objJsonResult.Message = "全部执行成功!";
                objJsonResult.data = null;
                return objJsonResult;
            }
            catch (Exception e)
            {
@@ -2026,7 +2873,7 @@
        }
        //反审核
        public bool Cj_StationOutBillAbandonCheckBill(Int64 lngBillKey, string CurUserName, bool HLastSubProc, ref string sReturn)
        public bool Cj_StationOutBillAbandonCheckBill(Int64 lngBillKey,string HBillNo, string CurUserName, bool HLastSubProc, ref string sReturn)
        {
            if (Cj_StationInBillisUse(lngBillKey, ref sReturn))
            {
@@ -2059,6 +2906,23 @@
                else if (Pub_Class.ClsPub.isStrNull(ds1.Tables[0].Rows[0]["HFstProc"]) == "是")
                {
                }
                //反审核后控制
                string sql = "exec h_p_Sc_StationOutBill_AfterUnCheckCtrl " + lngBillKey + ",'" + HBillNo + "','" + CurUserName + "'";
                ds = oCN.RunProcReturn(sql, "h_p_Sc_StationOutBill_AfterUnCheckCtrl");
                if (ds == null || ds.Tables.Count == 0 || ds.Tables[0].Rows.Count == 0)
                {
                    sReturn = "反审核过程中出错,请与网络管理人员联系";
                    oCN.RollBack();
                    return false;
                }
                if (ds.Tables[0].Rows[0]["HBack"].ToString() != "0")
                {
                    sReturn = ds.Tables[0].Rows[0]["HRemark"].ToString();
                    oCN.RollBack();
                    return false;
                }
                sReturn = sReturn + "反审核功能!";
                oCN.Commit();
                return true;
@@ -2070,6 +2934,130 @@
                return false; ;
            }
        }
        #region 工序出站关闭/反关闭功能
        [Route("Cj_StationOutBill/CloseCj_StationOutBill")]
        [HttpGet]
        public object CloseCj_StationOutBill(string HInterID, int Type, string user,string HBillSubType)
        {
            try
            {
                if (HBillSubType == "SUB")
                {
                    //判断是否有删除权限
                    if (!DBUtility.ClsPub.Security_Log("Cj_StationOutBill_Sub_Close", 1, false, user))
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "完工单无权限关闭!";
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                }
                else {
                    //判断是否有删除权限
                    if (!DBUtility.ClsPub.Security_Log("Cj_StationOutBill_Close", 1, false, user))
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "出站单无权限关闭!";
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                }
                if (string.IsNullOrWhiteSpace(HInterID))
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "HInterID为空!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                ClsPub.CurUserName = user;
                BillOld.MvarItemKey = "Sc_StationOutBillMain";
                oCN.BeginTran();//开始事务
                //Type 1 关闭  2  反关闭
                if (Type == 1)
                {
                    //判断单据是否已经关闭
                    DataSet ds;
                    string sql = "select * from " + BillOld.MvarItemKey + " where HinterID = " + HInterID;
                    ds = oCN.RunProcReturn(sql, BillOld.MvarItemKey);
                    if (ds.Tables[0] != null && ds.Tables[0].Rows.Count > 0)
                    {
                        if (ds.Tables[0].Rows[0]["HCloseMan"] != null && ds.Tables[0].Rows[0]["HCloseMan"].ToString() != "")
                        {
                            objJsonResult.code = "0";
                            objJsonResult.count = 0;
                            objJsonResult.Message = "单据已关闭!不需要再关闭!";
                            objJsonResult.data = null;
                            return objJsonResult;
                        }
                    }
                    //关闭单据
                    if (!BillOld.CloseBill(Int64.Parse(HInterID), ref ClsPub.sExeReturnInfo))
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 1;
                        objJsonResult.Message = "关闭失败!原因:" + ClsPub.sExeReturnInfo;
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                }
                else
                {
                    //判断单据是否已经反关闭
                    DataSet ds;
                    string sql = "select * from " + BillOld.MvarItemKey + " where HinterID = " + HInterID;
                    ds = oCN.RunProcReturn(sql, BillOld.MvarItemKey);
                    if (ds.Tables[0] != null && ds.Tables[0].Rows.Count > 0)
                    {
                        if (ds.Tables[0].Rows[0]["HCloseMan"] == null || ds.Tables[0].Rows[0]["HCloseMan"].ToString() == "")
                        {
                            objJsonResult.code = "0";
                            objJsonResult.count = 0;
                            objJsonResult.Message = "单据已反关闭!不需要再反关闭!";
                            objJsonResult.data = null;
                            return objJsonResult;
                        }
                    }
                    //反关闭单据
                    if (!BillOld.CancelClose(Int64.Parse(HInterID), ref ClsPub.sExeReturnInfo))
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 1;
                        objJsonResult.Message = "反关闭失败!原因:" + ClsPub.sExeReturnInfo;
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                }
                oCN.Commit();//提交事务
                objJsonResult.code = "0";
                objJsonResult.count = 1;
                objJsonResult.Message = "执行成功!";
                objJsonResult.data = null;
                return objJsonResult; ;
            }
            catch (Exception e)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "执行失败!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
        //是否被关联
        public bool Cj_StationInBillisUse(Int64 lngBillKey, ref string sReturn)
@@ -2277,5 +3265,410 @@
            }
        }
        #endregion
        #region  当前工单(扫码汇报) 条码查询
        [Route("Cj_StationOutBill_CurrentWork/SNHBardCodeList")]
        [HttpGet]
        public object SNHBardCodeList(string HBarCode, string HProcID, int HOrgID)
        {
            try
            {
                DataSet dataSet = null;
                var num = 0;
                ds = oCN.RunProcReturn(@"select HSourceInterID,HSourceBillNo from Gy_BarCodeBill WITH(NOLOCK) where HBarCode='" + HBarCode + "'", "Gy_BarCodeBill");
                if (ds.Tables[0].Rows.Count > 0)
                {
                    num = 1;
                    dataSet = ds;
                }
                ds = oCN.RunProcReturn(@"select HInterID,HBillNo from Sc_ProcessExchangeBillMain WITH(NOLOCK) where HBillNo='" + HBarCode + "'", "Sc_ProcessExchangeBillMain");
                if (ds.Tables[0].Rows.Count > 0)
                {
                    num = 2;
                    dataSet = ds;
                }
                if (num == 1)
                {
                    string HSourceInterID = dataSet.Tables[0].Rows[0]["HSourceInterID"].ToString();
                    string HSourceBillNo = dataSet.Tables[0].Rows[0]["HSourceBillNo"].ToString();
                    ds = oCN.RunProcReturn("select  * from h_v_Sc_ProcessExchangeBillList where hmainid=" + HSourceInterID + " and 单据号='" + HSourceBillNo + "' and HProcID=" + HProcID, "h_v_Sc_ProcessExchangeBillList");
                    if (ds.Tables[0].Rows.Count == 0) {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "条码:" + HBarCode + ",流转卡:" + HSourceBillNo + ",与当前流转卡,所对应的工序不存在!";
                        objJsonResult.data = ds.Tables[0];
                        return objJsonResult;
                    }
                    objJsonResult.code = "1";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "";
                    objJsonResult.data = ds.Tables[0];
                    return objJsonResult;
                }
                else if (num == 2)
                {
                    string HSourceInterID = dataSet.Tables[0].Rows[0]["HInterID"].ToString();
                    string HSourceBillNo = dataSet.Tables[0].Rows[0]["HBillNo"].ToString();
                    ds = oCN.RunProcReturn("select  * from h_v_Sc_ProcessExchangeBillList where hmainid=" + HSourceInterID + " and 单据号='" + HSourceBillNo + "' and HProcID=" + HProcID, "h_v_Sc_ProcessExchangeBillList");
                    if (ds.Tables[0].Rows.Count == 0)
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "条码:" + HBarCode + ",流转卡:" + HSourceBillNo + ",与当前流转卡,所对应的工序不存在!";
                        objJsonResult.data = ds.Tables[0];
                        return objJsonResult;
                    }
                    objJsonResult.code = "1";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "";
                    objJsonResult.data = ds.Tables[0];
                    return objJsonResult;
                }
                else
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "条码查无数据!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
            }
            catch (Exception e)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "没有返回任何记录!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
        #region  当前工单(扫码汇报) 出站单查询
        [Route("Cj_StationOutBill_CurrentWork/get_Out_Display")]
        [HttpGet]
        public object get_Out_Display(string sWhere, string user,string HBillSubType)
        {
            try
            {
                //判断是否有查询权限
                if (!DBUtility.ClsPub.Security_Log("Cj_StationOutBill_Query", 1, false, user))
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "出站单无查询权限!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                string sql1 = "select * from h_v_MES_StationOutBillList_SN where 1 = 1 ";
                string sql = sql1 + sWhere + "  order by 制单日期 desc";
                ds = oCN.RunProcReturn(sql, "h_v_MES_StationOutBillList_SN");
                objJsonResult.code = "1";
                objJsonResult.count = 1;
                objJsonResult.Message = "Sucess!";
                objJsonResult.data = ds.Tables[0];
                return objJsonResult;
            }
            catch (Exception e)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "Exception!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
        #region 当前工单(扫码汇报)  子表保存
        [Route("Cj_StationOutBill_CurrentWork/AddBillSub")]
        [HttpPost]
        public object AddBillSub([FromBody] JObject oMain)
        {
            var _value = oMain["oMain"].ToString();
            string msg1 = _value.ToString();
            string[] sArray = msg1.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
            try
            {
                //反序列化
                string msg2 = "[" + sArray[0].ToString() + "]";
                string user = sArray[1].ToString();//用户名
                string OperationType = sArray[2].ToString();//类型
                if (OperationType == "5")
                {
                    //判断是否有编辑权限
                    if (!DBUtility.ClsPub.Security_Log("Cj_StationOutBill_Sub_Edit", 1, false, user))
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "完工单无编辑权限!";
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                }
                else
                {
                    //判断是否有编辑权限
                    if (!DBUtility.ClsPub.Security_Log("Cj_StationOutBill_Edit", 1, false, user))
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "出站单无编辑权限!";
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                }
                List<StationBill> list = Newtonsoft.Json.JsonConvert.DeserializeObject<List<StationBill>>(msg2);
                long HInterID = list[0].HInterID;//递入type得到的单据ID
                string HBillNo = list[0].HBillNo;//递入type得到的单据号
                double HQty = list[0].HQty;//合格数量
                long HProcExchInterID = list[0].lngBillKey;
                long HProcExchEntryID = list[0].lngBillSubKey;
                string HProcExchBillNo = list[0].HProcExchBillNo;//流转卡
                string HBarCode = list[0].HBarCode;//条码
                string eventType = list[0].eventType;
                //若MAINDI重复则重新获取
                oCN.BeginTran();
                if ("Add".Equals(eventType))
                {
                    ds = oCN.RunProcReturn("select  * from Sc_StationOutBillSub_SN WITH(NOLOCK) where HInterID='" + HInterID + "' order by HEntryID desc", "Sc_StationOutBillSub_SN");
                    oCN.RunProc($@"insert into Sc_StationOutBillSub_SN(HInterID,HBillNo_bak,HEntryID,HBarCode,HBarCodeQty,HMakeTime,HRemark,HSourceInterID,HSourceEntryID,HSourceBillNo,HSourceBillType,HRelationQty,HRelationMoney)
values({HInterID}, '{HBillNo}', {(ds.Tables[0].Rows.Count == 0 ? 1 : int.Parse(ds.Tables[0].Rows[0]["HEntryID"].ToString()) + 1)}, '{HBarCode}', {HQty}, GETDATE(), '', " + HProcExchInterID + "," + HProcExchEntryID + ", '" + HProcExchBillNo + "', '', 0, 0)");
                }
                else
                {
                    oCN.RollBack();
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "操作类型无效!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                oCN.Commit();
                objJsonResult.code = "1";
                objJsonResult.count = 1;
                objJsonResult.Message = "新增单据成功!";
                objJsonResult.data = ds.Tables[0];
                return objJsonResult;
            }
            catch (Exception e)
            {
                oCN.RollBack();
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "Exception!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
        #region 当前工单(扫码汇报) 删除出站数据
        [Route("Cj_StationOutBill_CurrentWork/DelOutBill_SN")]
        [HttpGet]
        public object DelOutBill_SN(int HInterID, string HDeleteMan,string HBillSubType)
        {
            try
            {
                //判断是否有查询权限
                if (!DBUtility.ClsPub.Security_Log("Cj_StationOutBill_Drop", 1, false, HDeleteMan))
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "无删除权限!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                ds = oCN.RunProcReturn("select * from h_v_MES_StationOutBillList_SN WITH(NOLOCK) where hmainid = " + HInterID, "h_v_MES_StationOutBillList_SN");
                if (ds.Tables[0].Rows.Count == 0)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "查无数据!";
                    objJsonResult.data = null;
                }
                oCN.BeginTran();
                string sql = "";
                if (ds.Tables[0].Rows.Count == 1)
                {
                    sql = "delete from Sc_StationOutBillMain where HInterID = " + HInterID;
                    oCN.RunProc(sql);
                }
                sql = "delete from Sc_StationOutBillSub_SN where HInterID = " + HInterID ;
                oCN.RunProc(sql);
                oCN.Commit();
                objJsonResult.code = "1";
                objJsonResult.count = 1;
                objJsonResult.Message = "Sucess!";
                objJsonResult.data = null;
                return objJsonResult;
            }
            catch (Exception e)
            {
                oCN.RollBack();
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "Exception!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
        #region  当前工单(扫码汇报) 仪表盘查询
        [Route("Cj_StationOutBill_CurrentWork/get_PanelDisplay")]
        [HttpGet]
        public object get_PanelDisplay(string HBarCode, string user, int HOrgID)
        {
            try
            {
                ds = oCN.RunProcReturn(@"select HSourceInterID,HSourceBillNo from Gy_BarCodeBill WITH(NOLOCK) where HBarCode='" + HBarCode + "'", "Gy_BarCodeBill");
                objJsonResult.code = "1";
                objJsonResult.count = 1;
                objJsonResult.Message = "";
                objJsonResult.data = ds.Tables[0];
                return objJsonResult;
            }
            catch (Exception e)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "没有返回任何记录!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
        #region  当前工单(赋码汇报) 根据生产订单查询数据
        [Route("Cj_StationOutBill_CodingReport/get_ICMOProcessExchangeBillList")]
        [HttpGet]
        public object get_ICMOProcessExchangeBillList(string sWhere, string user, int HOrgID)
        {
            try
            {
                ds = oCN.RunProcReturn("select * from h_v_Sc_ICMOProcessExchangeBillList WITH(NOLOCK) where 1=1 " + sWhere, "h_v_Sc_ICMOProcessExchangeBillList");
                objJsonResult.code = "1";
                objJsonResult.count = 1;
                objJsonResult.Message = "";
                objJsonResult.data = ds.Tables[0];
                return objJsonResult;
            }
            catch (Exception e)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "没有返回任何记录!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
        #region  当前工单(赋码汇报) 查询当前用户今天生成条码的数据
        [Route("Cj_StationOutBill_CodingReport/get_BarCodeBillList")]
        [HttpGet]
        public object get_BarCodeBillList(string sWhere, string user, int HOrgID)
        {
            try
            {
                ds = oCN.RunProcReturn("select * from h_v_IF_BarCodeBillList WITH(NOLOCK) where 1=1 " + sWhere, "h_v_IF_BarCodeBillList");
                objJsonResult.code = "1";
                objJsonResult.count = 1;
                objJsonResult.Message = "";
                objJsonResult.data = ds.Tables[0];
                return objJsonResult;
            }
            catch (Exception e)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "没有返回任何记录!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
        #region 当前工单(扫码汇报) 删除出站数据
        [Route("Cj_StationOutBill_CodingReport/DelBarCodeBill_SN")]
        [HttpGet]
        public object DelBarCodeBill_SN(int HInterID, string HDeleteMan, string HBillSubType)
        {
            try
            {
                //判断是否有查询权限
                if (!DBUtility.ClsPub.Security_Log("Gy_BarCodeBillList_Edit", 1, false, HDeleteMan))
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "无删除权限!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                ds = oCN.RunProcReturn("select * from h_v_IF_BarCodeBillList WITH(NOLOCK) where hmainid = " + HInterID, "h_v_IF_BarCodeBillList");
                if (ds.Tables[0].Rows.Count == 0)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "查无数据!";
                    objJsonResult.data = null;
                }
                oCN.BeginTran();
                string sql = "";
                sql = "delete from Gy_BarCodeBill where HItemID = " + HInterID;
                oCN.RunProc(sql);
                oCN.Commit();
                objJsonResult.code = "1";
                objJsonResult.count = 1;
                objJsonResult.Message = "Sucess!";
                objJsonResult.data = null;
                return objJsonResult;
            }
            catch (Exception e)
            {
                oCN.RollBack();
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "Exception!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
    }
}