yusijie
2025-01-09 c34e85eda515636993b37a752b52c0f43ae6e17b
WebAPI/Controllers/CJGL/Cj_StationOutBillController.cs
@@ -2,6 +2,7 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Pub_Class;
using SyntacticSugar.constant;
using System;
using System.Collections;
using System.Collections.Generic;
@@ -76,6 +77,7 @@
                long HMainInterID = 0;
                HMainInterID = list[0].HMainInterID;
                string eventType = list[0].eventType;
                string HDate = list[0].HDate;
                string BillType = "3791";
                string HBillSubType = "3791";
                long HInterID = list[0].HInterID;//递入type得到的单据ID
@@ -146,7 +148,11 @@
                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;//遗失数量
                double HBackWorkByMaterQty = list[0].HBackWorkByMaterQty;//遗失数量
                int HMouldID = list[0].HMouldID;//模具id
                double HMachineWorkTimes = list[0].HMachineWorkTimes;//设备工时
                LogService.Write($"1.字段赋值,用时" + sw.Elapsed );
                //单据完整性判断
@@ -220,8 +226,14 @@
                string Ret = "";
                if (oSystemParameter.ShowBill(ref Ret))
                {
                    //判断客户为乔一
                    if(oSystemParameter.omodel.WMS_CampanyName == "乔一")
                    {
                        HDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                    }
                    //判断客户不为龙山汽配
                    if (oSystemParameter.omodel.WMS_CampanyName != "龙山汽配"&& oSystemParameter.omodel.WMS_CampanyName != "瑞与祺") //系统参数
                    if (oSystemParameter.omodel.WMS_CampanyName != "龙山汽配" && oSystemParameter.omodel.WMS_CampanyName != "瑞与祺" && oSystemParameter.omodel.WMS_CampanyName != "添康科技") //系统参数
                    {
                        if (HSourceID == 0)
                        {
@@ -230,7 +242,7 @@
                            objJsonResult.Message = "生产资源没有选择!";
                            objJsonResult.data = null;
                            return objJsonResult;
                        }
                        }
                    }
                    //判断客户为龙山汽配
                    else if (oSystemParameter.omodel.WMS_CampanyName == "龙山汽配")
@@ -261,6 +273,41 @@
                            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 (oSystemParameter.omodel.MES_StationOutBill_MustBeginWorkCtl == "Y")
                    {
                        ds = oCN.RunProcReturn("select * from Sc_ICMOBillStatus_Tmp where HSourceID = '" + HSourceID + "' and HICMOBillNo = '" + HICMOBillNo + "' and HInterID = '" + HICMOInterID + "' and hicmostatus =1", "Sc_ICMOBillStatus_Tmp");
                        if (ds.Tables[0].Rows[0]["HICMOStatus"].ToString() != "1")
                        {
                            objJsonResult.code = "0";
                            objJsonResult.count = 0;
                            objJsonResult.Message = "当前工单不是开工状态不能汇报!";
                            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)
@@ -271,14 +318,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)
                //{
@@ -373,8 +413,9 @@
                    ",HMainSourceInterID,HMainSourceBillNo,HMainSourceBillType,HLastSubProc" +
                    ",HEmpID2,HEmpID3,HEmpID4,HEmpID5,HDSQty,HChongQty,HPriceRate,HWorkTimes,HQCCheckID,HMainInterID,HPRDOrgID" +
                    ",HmaterOutqty,HProcPriceRate,HTemporaryAreaID,HWasterQty_Work,HWasterQty_Mater,HBackWorkQty,HShiftsID" +
                    ",HToCheckQty,HLossQty,HBackWorkByMaterQty,HMouldID,HMachineWorkTimes " +
                    ") " +
                    " values('" + BillType + "','" + (OperationType == "5" ? "SUB" : HBillSubType)  + "'," + HInterID + ",'" + HBillNo + "'," + HBillStatus + ",getdate(),'" + HMaker + "',getdate(),'" + HMouldNum + "'" +
                    " values('" + BillType + "','" + (OperationType == "5" ? "SUB" : HBillSubType)  + "'," + HInterID + ",'" + HBillNo + "'," + HBillStatus + ",'"+ HDate + "','" + 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 +
@@ -382,8 +423,8 @@
                    "," + 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 + "," + HProcPriceRate + ","+ HTemporaryAreaID + "," + HWasterQty_Work + "," + HWasterQty_Mater + "," + HBackWorkQty +
                    "," + HShiftsID + ") ");
                    "," + HmaterOutqty + "," + HProcPriceRate + "," + HTemporaryAreaID + "," + HWasterQty_Work + "," + HWasterQty_Mater + "," + HBackWorkQty +
                    "," + HShiftsID + "," + HToCheckQty + "," + HLossQty + ","+ HBackWorkByMaterQty + "," + HMouldID + ",'" + HMachineWorkTimes + "') ");
                    LogService.Write($"4.新增结束,用时" + sw.Elapsed);
                    LogService.Write("用户:" + user + ",日期:" + DateTime.Now + ",新增工序出站单据:" + HBillNo);
@@ -409,9 +450,14 @@
                    ",HSourceID4=" + HSourceID4 +
                    ",HSourceID5=" + HSourceID5 +
                    ",HPayProcID=" + HPayProcID +
                    ",HGroupID=" + HGroupID +
                    ",HShiftsID=" + HShiftsID +
                    ",HWorkTimes=" + HWorkTimes +
                    ",HSaveBillFlag=0 " +
                    ",HBadCount=" + HBadCount +
                    ",HPieceQty=" + HPieceQty +
                    ",HToCheckQty=" + HToCheckQty +
                    ",HLossQty=" + HLossQty +
                    ",HQty=" + HQty +
                    ",HDSQty=" + HDSQty +
                    ",HChongQty=" + HChongQty +
@@ -423,7 +469,9 @@
                    ",HWasterQty_Work=" + HWasterQty_Work +
                    ",HWasterQty_Mater=" + HWasterQty_Mater +
                    ",HBackWorkQty=" + HBackWorkQty +
                    ",HShiftsID=" + HShiftsID +
                    ",HBackWorkByMaterQty=" + HBackWorkByMaterQty +
                    ",HMouldID=" + HMouldID +
                    ",HMachineWorkTimes=" + HMachineWorkTimes +
                    " where HInterID=" + HInterID);
                    LogService.Write("用户:" + user + ",日期:" + DateTime.Now + ",修改工序出站单据:" + HBillNo);
@@ -472,13 +520,13 @@
                    return objJsonResult;
                }
                LogService.Write($"6.判断结束,用时" + sw.Elapsed);
                oCN.RunProc("exec h_p_Mes_ProcessExchangeRelationQty_Out " + HInterID + ","+ num + "");
                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");
@@ -564,6 +612,10 @@
                string sReturn = "";
                if (oSystemParameter.ShowBill(ref sReturn) == true)
                {
                    if (oSystemParameter.omodel.MES_StationOutBill_AutoCheck == "Y") //系统参数  自动审核
                    {
                        object objResult = set_CheckBill(HInterID.ToString(), user, HBillSubType);
                    }
                    if (oSystemParameter.omodel.MES_StationOutBill_SaveAutoAddnew == "Y") //系统参数  页面保存自动变成新增状态
                    {
                        objJsonResult.Verify = "Y";
@@ -576,6 +628,27 @@
                sw.Stop();//结束计时
                LogService.Write($"11.参数查询结束,新增结束,用时" + sw.Elapsed);
                LogService.Write("END--出站单据保存结束,出站单号:" + HBillNo);
                //测试语句===========================================================================================================
                string msg_str = "";
                string sql_str = "select a.HQty HQty_Main,b.HQty HQty_Sub " +
                            "from Sc_ProcessExchangeBillMain as a " +
                            "inner join Sc_ProcessExchangeBillSub as b on a.HInterID = b.HInterID " +
                            "where a.HInterID = " + HProcExchInterID;
                DataSet ds_str = oCN.RunProcReturn(sql_str, "Sc_ProcessExchangeBillMain");
                if (ds_str.Tables[0].Rows.Count > 0)
                {
                    msg_str = "HQty_Main:" + ds_str.Tables[0].Rows[0]["HQty_Main"].ToString() + ";HQty_Sub:";
                    for (int j = 0; j < ds_str.Tables[0].Rows.Count; j++)
                    {
                        msg_str += ds_str.Tables[0].Rows[j]["HQty_Sub"].ToString() + ",";
                    }
                }
                oCN.RunProc("Insert into System_log (GeginDate, userid, WorkstationName, WorkList, SystemName, NetuserName, State) select GETDATE(),'" + user + "','" + HComputerName + "','" + "修改工序出站单据:" + HBillNo + "[工序流转卡号:" + HProcExchBillNo + "]" + msg_str + "','LMES-工序出站模块','" + DBUtility.ClsPub.IPAddress + "','新增或修改单据'", ref DBUtility.ClsPub.sExeReturnInfo);
                //==============================================================================================================
                objJsonResult.code = "1";
                objJsonResult.count = 1;
                objJsonResult.Message = "新增单据成功!";
@@ -1677,6 +1750,102 @@
        }
        #endregion
        #region 返回工序出站汇报单列表-分页
        [Route("Cj_StationOutBill/get_Display_byPage")]
        [HttpGet]
        public object get_Display_byPage(string sWhere, string user, string Organization, int page, int size, string HBillSubType)
        {
            try
            {
                List<object> columnNameList = new List<object>();
                if (HBillSubType == "SUB")
                {
                    //判断是否有查询权限
                    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;
                        }
                    }
                }
                //sWhere = sWhere.Replace("'", "''");
                if (sWhere == null || sWhere.Equals(""))
                {
                    ds = oCN.RunProcReturn("exec h_p_MES_StationOutBillList " + page + "," + size + ",'" + Organization + "'," + "''", "h_p_MES_StationOutBillList");
                }
                else
                {
                    ds = oCN.RunProcReturn("exec h_p_MES_StationOutBillList " + page + "," + size + ",'" + Organization + "','" + sWhere + "'", "h_p_MES_StationOutBillList");
                }
                //添加列名
                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 = int.Parse(ds.Tables[1].Rows[0]["count"].ToString());
                objJsonResult.Message = "Sucess!";
                objJsonResult.list = columnNameList;
                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/get_SubDisplay")]
        [HttpGet]
@@ -1702,7 +1871,10 @@
                    case "Emp":
                        sql = "select * from h_v_Sc_StationOutBillSubQuery_Emp where 1 = 1 and HInterID=" + sWhere;
                        break;
                    case "Sup":
                        sql = "select * from h_v_Sc_StationOutBillSubQuery_Sup where 1 = 1 and HInterID=" + sWhere;
                        break;
                }
                ds = oCN.RunProcReturn(sql, TableName);
@@ -1781,7 +1953,7 @@
            string HRemark = HttpContext.Current.Request.Params["HRemark"];  //备注
            string HUserName = HttpContext.Current.Request.Params["HUserName"];  //创建人
            HttpPostedFile files = HttpContext.Current.Request.Files["file"];
            string path = HttpContext.Current.Server.MapPath("~/../Files/" + HBillNo);
            string path = HttpContext.Current.Server.MapPath("~/../Files/Cj_StationOutBill/" + HBillNo);
            //string path = @"D:\\Files\\"+ HBillNo;
            dynamic dyResult = UpLoadFile(files, path, HBillNo, HRemark, HUserName);
            if (dyResult != null && dyResult.result == 1)
@@ -1837,7 +2009,7 @@
                {
                    File.Delete(fileurl);      //删除指定文件
                    files.SaveAs(fileurl);
                    string StrPath = "/files/"+ HBillNo+"/"+ filename;
                    string StrPath = "/files/Cj_StationOutBill/" + HBillNo+"/"+ filename;
                    if (File.Exists(fileurl)) 
                    {
                        //这里可以执行一些其它的操作,比如更新数据库
@@ -1860,7 +2032,7 @@
                {
                    Directory.CreateDirectory(fileSavePath); //添加文件夹
                    files.SaveAs(fileurl);
                    string StrPath = "/files/" + HBillNo + "/" + filename;
                    string StrPath = "/files/Cj_StationOutBill/" + HBillNo + "/" + filename;
                    if (File.Exists(fileurl))
                    {
                        //这里可以执行一些其它的操作,比如更新数据库
@@ -1901,7 +2073,7 @@
            string HRemark = HttpContext.Current.Request.Params["HRemark"];  //备注
            string HUserName = HttpContext.Current.Request.Params["HUserName"];  //创建人
            HttpPostedFile files = HttpContext.Current.Request.Files["file"];
            string path = HttpContext.Current.Server.MapPath("~/../Files/" + HBillNo);
            string path = HttpContext.Current.Server.MapPath("~/../Files/Cj_StationOutBill/" + HBillNo);
            //string path = @"D:\\Files\\"+ HBillNo;
            dynamic dyResult = UpLoadFile1(files, path, HBillNo, HRemark, HUserName);
            if (dyResult != null && dyResult.result == 1)
@@ -1957,7 +2129,7 @@
                {
                    File.Delete(fileurl);      //删除指定文件
                    files.SaveAs(fileurl);
                    string StrPath = "/files/" + HBillNo + "/" + filename;
                    string StrPath = "/files/Cj_StationOutBill/" + HBillNo + "/" + filename;
                    if (File.Exists(fileurl))
                    {
                        //这里可以执行一些其它的操作,比如更新数据库
@@ -1980,7 +2152,7 @@
                {
                    Directory.CreateDirectory(fileSavePath); //添加文件夹
                    files.SaveAs(fileurl);
                    string StrPath = "/files/" + HBillNo + "/" + filename;
                    string StrPath = "/files/Cj_StationOutBill/" + HBillNo + "/" + filename;
                    if (File.Exists(fileurl))
                    {
                        //这里可以执行一些其它的操作,比如更新数据库
@@ -2030,7 +2202,7 @@
        [HttpGet]
        public object Filelist(string HBillNo)
        {
            var url = fileip + "/files/" + HBillNo+"/";
            var url = fileip + "/files/Cj_StationOutBill/" + HBillNo+"/";
            //@"C:\\files\\"
            try
            {
@@ -2065,7 +2237,7 @@
            {
                oCN.RunProc("delete from MES_AccessoriesList where HItemID =" + HItemID);
                string fileurl = Path.Combine(HttpContext.Current.Server.MapPath("~/../Files/" + HSourceBillNo), HFileName);
                string fileurl = Path.Combine(HttpContext.Current.Server.MapPath("~/../Files/Cj_StationOutBill/" + HSourceBillNo), HFileName);
                File.Delete(fileurl);      //删除指定文件
                objJsonResult.code = "1";
                objJsonResult.count = 1;
@@ -2665,6 +2837,19 @@
                {
                }
                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");
@@ -2680,6 +2865,7 @@
                    oCN.RollBack();
                    return false;
                }
                sReturn = sReturn + " 审核功能!";
                oCN.Commit();
@@ -3636,5 +3822,370 @@
            }
        }
        #endregion
        #region  当前工单(扫码汇报) 找出当前工单使用模具
        [Route("Cj_StationOutBill_CurrentWork/getHModelList")]
        [HttpGet]
        public object getHModelList(string HInterID, string HEntryID,string HBillNo)
        {
            try
            {
                ds = oCN.RunProcReturn("exec h_p_StationOutBill_Model  '" + HInterID + "','"+ HEntryID + "' ,'" + HBillNo + "'", "h_p_StationOutBill_Model");
                if (ds.Tables[0].Rows.Count != 0 && ds != null)
                {
                    objJsonResult.code = "1";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "";
                    objJsonResult.data = ds.Tables[0];
                    return objJsonResult;
                }
                else
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "";
                    return objJsonResult;
                }
            }
            catch (Exception e)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "没有返回任何记录!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
        #region 保存生成白标
        public class WhiteLabelGeneration {
         public  string ProjectNo { get; set; }
         public  string OrderingCode { get; set; }
         public  string DrawVersionNumber { get; set; }
         public  string CustomerOrderNumber { get; set; }
         public  string WaybillNumber { get; set; }
         public  string HRemark { get; set; }
         public  string HBarCode_Pack { get; set; }
         public  string HBillType { get; set; }
        }
        [Route("Cj_StationOutBill_Detail/MES_WhiteLabelGeneration")]
        [HttpPost]
        public object MES_WhiteLabelGeneration([FromBody] JObject oMain)
        {
            try
            {
                oCN.BeginTran();
                var _value = oMain["oMain"].ToString();
                string msg1 = _value.ToString();
                string[] sArray = msg1.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
                string msg2 = sArray[0].ToString(); //主表数据
                WhiteLabelGeneration Main = Newtonsoft.Json.JsonConvert.DeserializeObject<WhiteLabelGeneration>(msg2);
                string HBillType = Main.HBillType;
                string ProjectNo = Main.ProjectNo;
                string OrderingCode = Main.OrderingCode;
                string DrawVersionNumber = Main.DrawVersionNumber;
                string CustomerOrderNumber = Main.CustomerOrderNumber;
                string WaybillNumber = Main.WaybillNumber;
                string HRemark = Main.HRemark;
                string HBarCode_Pack = Main.HBarCode_Pack;
                ds = oCN.RunProcReturn($"exec h_p_MES_HBarCode_White_SMR_15 '{HBillType}','{ProjectNo}','{OrderingCode}','{DrawVersionNumber}','{CustomerOrderNumber}','{WaybillNumber}','{HRemark}','{HBarCode_Pack}'", "h_p_MES_HBarCode_White_SMR_15");
                string HBarCode_White = ds.Tables[0].Rows[0]["HBarCode_White"].ToString();
                if (HBarCode_White == "")
                {
                    oCN.RollBack();
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "生成白标失败,单据标识:" + HBarCode_Pack + "!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                oCN.RunProc("update Sc_PackUnionBillMain set HBarCode_White='" + HBarCode_White + "' where HBarCode_Pack='" + HBarCode_Pack + "'");
                oCN.Commit();
                objJsonResult.code = "1";
                objJsonResult.count = 1;
                objJsonResult.Message = "Sucess!";
                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/PushDownBackInfo")]
        [HttpGet]
        public object PushDownBackInfo(string linterid, string user)
        {
            try
            {
                List<object> columnNameList = new List<object>();
                ds = oCN.RunProcReturn("select * from h_v_Sc_StationOutBill_PushDownBackInfo where hmainid in (" + linterid + ")", "h_v_Sc_StationOutBill_PushDownBackInfo");
                if (ds.Tables[0].Rows.Count > 0 && ds != null)
                {
                    //添加列名
                    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;
                }
                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 = "Exception!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
        #region 编辑页面根据id获取工序出站汇报单信息
        [Route("Cj_StationOutBill/SetBillTime")]
        [HttpGet]
        public object SetBillTime(int HInterID,DateTime dateTime,string user)
        {
            try
            {
                //判断是否有编辑权限
                if (!DBUtility.ClsPub.Security_Log("Cj_StationOutBill_Edit", 1, false, user))
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "出站单无编辑权限!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                string sql = "select * from Sc_StationOutBillMain  with(nolock) where HInterID=" + HInterID;
                ds = oCN.RunProcReturn(sql, "Sc_StationOutBillMain");
                if (ds == null || ds.Tables[0].Rows.Count == 0)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "修改失败没找到相关出站汇报单";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                //修改前时间修改后时间判断有无工资计算
                string HGroupID = ds.Tables[0].Rows[0]["HGroupID"].ToString();
                string HOldDate = ds.Tables[0].Rows[0]["HDate"].ToString();
                string sql1 = "select * from Pay_SingleBalBillMain where HGroupID =" +HGroupID + " and HDate ='" + HOldDate + "'";
                string sql2 = "select * from Pay_GroupBalBillMain where HGroupID =" + HGroupID + " and HDate ='" + HOldDate + "'";
                string sql3 = "select * from Pay_SingleBalBillMain where HGroupID =" + HGroupID + " and HDate ='" + dateTime + "'";
                string sql4 = "select * from Pay_GroupBalBillMain where HGroupID =" + HGroupID + " and HDate ='" + dateTime + "'";
                ds = oCN.RunProcReturn(sql1, "Sc_StationOutBillMain");
                if (ds.Tables[0].Rows.Count > 0)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "修改失败该时间班组已计算工资:" + HOldDate;
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                ds = oCN.RunProcReturn(sql2, "Sc_StationOutBillMain");
                if (ds.Tables[0].Rows.Count > 0)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "修改失败该时间班组已计算工资:" + HOldDate;
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                ds = oCN.RunProcReturn(sql3, "Sc_StationOutBillMain");
                if (ds.Tables[0].Rows.Count > 0)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "修改失败该时间班组已计算工资:" + dateTime;
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                ds = oCN.RunProcReturn(sql4, "Sc_StationOutBillMain");
                if (ds.Tables[0].Rows.Count > 0)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "修改失败该时间班组已计算工资:" + dateTime;
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                //修改时间
                sql = "update Sc_StationOutBillMain set HDate = '" + dateTime + "' where HInterID = " + HInterID;
                oCN.RunProcReturn(sql, "Sc_StationOutBillMain");
                objJsonResult.code = "1";
                objJsonResult.count = 1;
                objJsonResult.Message = "Sucess!";
                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 出站单列表-下推PPM数据录入保存,删除
        [Route("Cj_StationOutBill/PPMSupAddBill")]
        [HttpPost]
        public object PPMSupAddBill([FromBody] JObject sSubStr)
        {
            var _value = sSubStr["sSubStr"].ToString();
            string msg1 = _value.ToString();
            string[] sArray = msg1.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
            try
            {
                //反序列化
                string msg2 = sArray[0].ToString(); //表体
                string refSav = sArray[1].ToString();//操作类型
                string user = sArray[2].ToString(); //用户
                msg2 = msg2.Substring(1, msg2.Length - 2);
                msg2 = msg2.Replace("\\", "");
                msg2 = msg2.Replace("\n", "");
                msg2 = "[" + msg2 + "]";
                //判断是否有编辑权限
                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<Sc_StationOutBillSub_Sup> list = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Sc_StationOutBillSub_Sup>>(msg2);
                oCN.BeginTran();
                for (int i = 0; i < list.Count; i++)
                {
                    int HInterID = list[i].HInterID;
                    int HEntryID = i+1;
                    int HSupID = list[i].HSupID;
                    double HWasterQty_Mater = list[i].HWasterQty_Mater;
                    double HBackWorkQty = list[i].HBackWorkQty;
                    oCN.RunProc("Insert Into Sc_StationOutBillSub_Sup " +
                     "(HInterID, HEntryID, HSupID, HWasterQty_Mater, HBackWorkQty) " +
                     "values ('" + HInterID + "', '" + HEntryID + "', '" + HSupID + "', '" + HWasterQty_Mater + "', '" + HBackWorkQty + "')");
                }
                oCN.Commit();
                objJsonResult.code = "1";
                objJsonResult.count = 1;
                objJsonResult.Message = "新增单据成功!";
                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;
            }
        }
        [Route("Cj_StationOutBill/PPMSupDelete")]
        [HttpGet]
        public object PPMSupDelete(int HInterID,string user)
        {
            try
            {
                //判断是否有查询权限
                if (!DBUtility.ClsPub.Security_Log("Cj_StationOutBill_Drop", 1, false, user))
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "无删除权限!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                ds = oCN.RunProcReturn("select * from Sc_StationOutBillSub_Sup WITH(NOLOCK) where HInterID = " + HInterID, "Sc_StationOutBillSub_Sup");
                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 Sc_StationOutBillSub_Sup 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
    }
}