llj
2025-10-31 b8d7145eadce706aef50ef95be75cff9ef79b518
WebAPI/Controllers/CJGL/Cj_SingleStationController.cs
@@ -371,15 +371,21 @@
                {
                    if (oSystemParameter.omodel.WMS_CampanyName == "杭州斯莫尔")
                    {
                        //判断当前流转卡是否是开工
                        ds = oCN.RunProcReturn("select  * from Sc_ICMOBillStatus_Tmp where HSourceBillNo='" + HBarCode + "' and HICMOStatus<>'0'", "Sc_ICMOBillStatus_Tmp");
                        if (ds.Tables[0].Rows.Count == 0)
                        {
                            objJsonResult.code = "0";
                            objJsonResult.count = 0;
                            objJsonResult.Message = "[3791-2-018]卡号:" + HBarCode + ",流转卡未开工!";
                            objJsonResult.data = null;
                            return objJsonResult;
                            //判断当前流转卡是否墨西哥的
                            ds = oCN.RunProcReturn("select HPRDORGID from Sc_ProcessExchangeBillMain with(nolock) where HBillNo = '" + HBarCode + "' ", "Sc_ProcessExchangeBillMain");
                            if (ds.Tables[0].Rows[0]["HPRDORGID"].ToString() != "7667152")
                            {
                                objJsonResult.code = "0";
                                objJsonResult.count = 0;
                                objJsonResult.Message = "[3791-2-018]卡号:" + HBarCode + ",流转卡未开工!";
                                objJsonResult.data = null;
                                return objJsonResult;
                            }
                        }
                    }
                }
@@ -547,7 +553,7 @@
                sub = JsonConvert.DeserializeObject<List<Model.ClsSc_AssemblyBillSub>>(sSubStr);
                //条码上道工序是否过站
                ds = oCN.RunProcReturn("exec h_p_Sc_SNBarcodeProcCtrl_S '" + omodel.HBarCode_P + "'," + omodel.HProcID, "h_v_Gy_QualifiedRecordsList");
                ds = oCN.RunProcReturn("exec h_p_Sc_SNBarcodeProcCtrl_S '" + omodel.HBarCode_P + "'," + omodel.HProcID, "h_p_Sc_SNBarcodeProcCtrl_S");
                if (ClsPub.isInt(ds.Tables[0].Rows.Count) == 0)
                {
                    objJsonResult.code = "0";
@@ -605,26 +611,44 @@
                    {
                        Int64 HInterID1 = DBUtility.ClsPub.CreateBillID("3727", ref DBUtility.ClsPub.sExeReturnInfo);
                        string HBillNo1 = DBUtility.ClsPub.CreateBillCode("3727", ref DBUtility.ClsPub.sExeReturnInfo, true);
                        //保存生产组装单主表
                        string sql = $@"Insert Into Sc_AssemblyBillMain(HYear,HPeriod,HBillType,HBillSubType,HInterID,HDate
,HBillNo,HBillStatus,HMaker,HMakeDate,HMainSourceInterID,HMainSourceEntryID,HMainSourceBillNo
,HICMOInterID,HICMOBillNo,HBarCode_P,HMaterID,HUnitID,HAssemblyStatus,HProdOrgID)
values('{DateTime.Now.Year}','{DateTime.Now.Month}','3727','3727',{HInterID1},getdate()
,'{HBillNo1}','1','{user}',getdate(),{omodel.HProcExchInterID.ToString()},{omodel.HProcExchEntryID.ToString()},'{omodel.HProcExchBillNo.ToString()}'
,{omodel.HICMOInterID.ToString()},'{omodel.HICMOBillNo.ToString()}','{omodel.HBarCode_P.ToString()}',{omodel.HMaterID},0,'汇报',{omodel.HProdOrgID})";
                        string prefix = omodel.HBarCode_P.Substring(0, 10); // 从索引0开始,截取10个字符 判断每个项目的O星圈配件数量
                            //保存生产组装单主表
                         string sql = $@"Insert Into Sc_AssemblyBillMain(HYear,HPeriod,HBillType,HBillSubType,HInterID,HDate
                        ,HBillNo,HBillStatus,HMaker,HMakeDate,HMainSourceInterID,HMainSourceEntryID,HMainSourceBillNo
                        ,HICMOInterID,HICMOBillNo,HBarCode_P,HMaterID,HUnitID,HAssemblyStatus,HProdOrgID)
                        values('{DateTime.Now.Year}','{DateTime.Now.Month}','3727','3727',{HInterID1},getdate()
                        ,'{HBillNo1}','1','{user}',getdate(),{omodel.HProcExchInterID.ToString()},{omodel.HProcExchEntryID.ToString()},'{omodel.HProcExchBillNo.ToString()}'
                        ,{omodel.HICMOInterID.ToString()},'{omodel.HICMOBillNo.ToString()}','{omodel.HBarCode_P.ToString()}',{omodel.HMaterID},0,'汇报',{omodel.HProdOrgID})";
                        oCN.RunProc(sql);
                        for (int i = 0; i < sub.Count; i++)
                        {
                            //子表存储
                            string sq2 = $@"Insert Into Sc_AssemblyBillSub(HInterID,HBillNo_bak,HEntryID,HSourceInterID,HSourceEntryID,HSourceBillNo
,HSourceBillType,HMaterID,HSourceID,HEquipID,HUnitID,HQty
,HGroupID,HWorkerID,HScanDate,HBarCode,HBarCode_P,HSNNumber)
values({HInterID1},'{HBillNo1}',{(i + 1)},0,0,''
,'',{sub[i].HMaterID},0,0,0,1
,0,0,getdate(),'{sub[i].HBarCode}','{omodel.HBarCode_P}','') ";
                            oCN.RunProc(sq2);
                        if (prefix == "#0TE911124") {
                            for (int i = 0; i < sub.Count; i++)
                            {
                                //子表存储
                             string sq2 = $@"Insert Into Sc_AssemblyBillSub(HInterID,HBillNo_bak,HEntryID,HSourceInterID,HSourceEntryID,HSourceBillNo
                            ,HSourceBillType,HMaterID,HSourceID,HEquipID,HUnitID,HQty
                            ,HGroupID,HWorkerID,HScanDate,HBarCode,HBarCode_P,HSNNumber)
                            values({HInterID1},'{HBillNo1}',{(i + 1)},0,0,''
                            ,'',{sub[i].HMaterID},0,0,0,3
                            ,0,0,getdate(),'{sub[i].HBarCode}','{omodel.HBarCode_P}','') ";
                                oCN.RunProc(sq2);
                            }
                        }
                        else
                        {
                            for (int i = 0; i < sub.Count; i++)
                            {
                                //子表存储
                                string sq2 = $@"Insert Into Sc_AssemblyBillSub(HInterID,HBillNo_bak,HEntryID,HSourceInterID,HSourceEntryID,HSourceBillNo
                            ,HSourceBillType,HMaterID,HSourceID,HEquipID,HUnitID,HQty
                            ,HGroupID,HWorkerID,HScanDate,HBarCode,HBarCode_P,HSNNumber)
                            values({HInterID1},'{HBillNo1}',{(i + 1)},0,0,''
                            ,'',{sub[i].HMaterID},0,0,0,1
                            ,0,0,getdate(),'{sub[i].HBarCode}','{omodel.HBarCode_P}','') ";
                                oCN.RunProc(sq2);
                            }
                        }
                    }
                }
@@ -749,7 +773,7 @@
                ds = oCN.RunProcReturn("select  * from Sc_StationOutBillSub_SN WITH(NOLOCK) where HInterID='" + omodel.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)}, '{omodel.HBarCode_P}', 1, GETDATE(), '', " + HProcExchInterID + ","+ HProcExchEntryID + ", '"+ HProcExchBillNo + "', '', 0, 0)");
                    values({HInterID}, '{HBillNo}', {(ds.Tables[0].Rows.Count == 0 ? 1 : int.Parse(ds.Tables[0].Rows[0]["HEntryID"].ToString()) + 1)}, '{omodel.HBarCode_P}', 1, GETDATE(), '', " + HProcExchInterID + ","+ HProcExchEntryID + ", '"+ HProcExchBillNo + "', '', 0, 0)");
                //把条码写入日志里面
                LogService.CustomWriteLog("条码:" + omodel.HBarCode_P + ",工序:"+ HProcID + ",出站时间:" + DateTime.Now, "TM" + DateTime.Now.ToString("yyyy-MM-dd"));
@@ -759,9 +783,9 @@
                ds = oCN.RunProcReturn($@"select (b.HQty -sum(isnull(ou.HQty,0))-sum(isnull(ou.HBadCount,0))) HQty from Sc_ProcessExchangeBillSub b WITH(NOLOCK)
left join Sc_StationOutBillMain ou WITH(NOLOCK) on b.HInterID=ou.HProcExchInterID and b.HEntryID=ou.HProcExchEntryID
where b.HInterID={HProcExchInterID} and b.HEntryID={HProcExchEntryID}
group by b.HInterID,b.HEntryID,b.HQty", "Sc_ProcessExchangeBill_Out");
                            left join Sc_StationOutBillMain ou WITH(NOLOCK) on b.HInterID=ou.HProcExchInterID and b.HEntryID=ou.HProcExchEntryID
                            where b.HInterID={HProcExchInterID} and b.HEntryID={HProcExchEntryID}
                            group by b.HInterID,b.HEntryID,b.HQty", "Sc_ProcessExchangeBill_Out");
                if (double.Parse(ds.Tables[0].Rows[0][0].ToString()) < 0) {
                    oCN.RollBack();
@@ -800,6 +824,7 @@
        {
            try
            {
                string str1 = "";
                ds = oCN.RunProcReturn(@"select * from h_v_Gy_BarCodeBill WITH(NOLOCK) where HBarCode='" + HBarCode + "'", "h_v_Gy_BarCodeBill");
                //判断条码是否存在条码档案
@@ -823,21 +848,21 @@
                    //判断长度是否为29位 无尘车间
                    if (HBarCode.Length == 29)
                    {
                        string str1 = HBarCode.Substring(18, 8);
                        str1 = HBarCode.Substring(18, 8);
                        DataSet dataSet = oCN.RunProcReturn(@"select  m.HNumber 物料代码,o.HNumber 组织代码 from Sc_ProcessExchangeBillMain a WITH(NOLOCK)
left join Gy_Material m WITH(NOLOCK) on a.HMaterID=m.HItemID
left join Xt_ORGANIZATIONS o WITH(NOLOCK) on a.HPRDORGID=o.HItemID
where HBillNo='" + HProcExchBillNo + "' and HProjectNum like'" + str1 + "%' and HPRDORGID=" + HOrgID, "Sc_ProcessExchangeBillMain");
                        left join Gy_Material m WITH(NOLOCK) on a.HMaterID=m.HItemID
                        left join Xt_ORGANIZATIONS o WITH(NOLOCK) on a.HPRDORGID=o.HItemID
                        where HBillNo='" + HProcExchBillNo + "' and HProjectNum like'" + str1 + "%' and HPRDORGID=" + HOrgID, "Sc_ProcessExchangeBillMain");
                        if (dataSet.Tables[0].Rows.Count == 0)
                        {
                            str1 = HBarCode.Substring(23, 3);
                            dataSet = oCN.RunProcReturn(@"select  m.HNumber 物料代码,o.HNumber 组织代码 from Sc_ProcessExchangeBillMain a WITH(NOLOCK)
left join Gy_Material m WITH(NOLOCK) on a.HMaterID=m.HItemID
left join Xt_ORGANIZATIONS o WITH(NOLOCK) on a.HPRDORGID=o.HItemID
where HBillNo='" + HProcExchBillNo + "' and HProjectNum like'" + str1 + "%' and HPRDORGID=" + HOrgID, "Sc_ProcessExchangeBillMain");
                            left join Gy_Material m WITH(NOLOCK) on a.HMaterID=m.HItemID
                            left join Xt_ORGANIZATIONS o WITH(NOLOCK) on a.HPRDORGID=o.HItemID
                            where HBillNo='" + HProcExchBillNo + "' and HProjectNum like'" + str1 + "%' and HPRDORGID=" + HOrgID, "Sc_ProcessExchangeBillMain");
                            if (dataSet.Tables[0].Rows.Count == 0)
                            {
@@ -861,30 +886,61 @@
                            return get_HBardBillSave(HProcExchBillNo, HBarCode);
                        }
                    }
                    //判断长度是否为50位  15车间
                    //判断长度是否为50位  15车间 和 O6项目
                    else if (HBarCode.Length == 50)
                    {
                        string str1 = HBarCode.Substring(42, 8);
                        DataSet dataSet = oCN.RunProcReturn(@"select  m.HNumber 物料代码,o.HNumber 组织代码 from Sc_ProcessExchangeBillMain a WITH(NOLOCK)
left join Gy_Material m WITH(NOLOCK) on a.HMaterID=m.HItemID
left join Xt_ORGANIZATIONS o WITH(NOLOCK) on a.HPRDORGID=o.HItemID
where HBillNo='" + HProcExchBillNo + "' and HProjectNum like'" + str1 + "%' and HPRDORGID=" + HOrgID, "Sc_ProcessExchangeBillMain");
                        if (dataSet.Tables[0].Rows.Count == 0)
                        string prefix = HBarCode.Substring(0, 10); // 从索引0开始,截取10个字符
                        if (prefix == "#0TE911124")
                        {
                            objJsonResult.code = "0";
                            objJsonResult.count = 0;
                            objJsonResult.Message = "[3791-2-016]条码与流转卡不存在对应关系!";
                            objJsonResult.data = null;
                            return objJsonResult;
                            str1 = HBarCode.Substring(41, 3);
                            LogService.Write($"条码前缀" + str1);
                            DataSet dataSet = oCN.RunProcReturn(@"select  m.HNumber 物料代码,o.HNumber 组织代码 from Sc_ProcessExchangeBillMain a WITH(NOLOCK)
                            left join Gy_Material m WITH(NOLOCK) on a.HMaterID=m.HItemID
                            left join Xt_ORGANIZATIONS o WITH(NOLOCK) on a.HPRDORGID=o.HItemID
                            where HBillNo='" + HProcExchBillNo + "' and HProjectNum like'" + str1 + "%' and HPRDORGID=" + HOrgID, "Sc_ProcessExchangeBillMain");
                            if (dataSet.Tables[0].Rows.Count == 0)
                            {
                                objJsonResult.code = "0";
                                objJsonResult.count = 0;
                                objJsonResult.Message = "[3791-2-016]条码与流转卡不存在对应关系!";
                                objJsonResult.data = null;
                                return objJsonResult;
                            }
                            else
                            {
                                ClsPub.CurUserName = user;
                                //条码生成
                                return get_HBardBillSave(HProcExchBillNo, HBarCode);
                            }
                        }
                        else
                        {
                            ClsPub.CurUserName = user;
                            //条码生成
                            return get_HBardBillSave(HProcExchBillNo, HBarCode);
                            str1 = HBarCode.Substring(42, 8);
                            LogService.Write($"条码前缀1.1" + str1);
                            DataSet dataSet = oCN.RunProcReturn(@"select  m.HNumber 物料代码,o.HNumber 组织代码 from Sc_ProcessExchangeBillMain a WITH(NOLOCK)
                            left join Gy_Material m WITH(NOLOCK) on a.HMaterID=m.HItemID
                            left join Xt_ORGANIZATIONS o WITH(NOLOCK) on a.HPRDORGID=o.HItemID
                            where HBillNo='" + HProcExchBillNo + "' and HProjectNum like'" + str1 + "%' and HPRDORGID=" + HOrgID, "Sc_ProcessExchangeBillMain");
                            if (dataSet.Tables[0].Rows.Count == 0)
                            {
                                objJsonResult.code = "0";
                                objJsonResult.count = 0;
                                objJsonResult.Message = "[3791-2-016]条码与流转卡不存在对应关系!";
                                objJsonResult.data = null;
                                return objJsonResult;
                            }
                            else
                            {
                                ClsPub.CurUserName = user;
                                //条码生成
                                return get_HBardBillSave(HProcExchBillNo, HBarCode);
                            }
                        }
                    }
                    else
                    {
@@ -895,25 +951,26 @@
                        return objJsonResult;
                    }
                }
                else {
                else
                {
                    //判断长度是否为29位 无尘车间
                    if (HBarCode.Length == 29)
                    {
                        string str1 = HBarCode.Substring(18, 8);
                        str1 = HBarCode.Substring(18, 8);
                        DataSet dataSet = oCN.RunProcReturn(@"select  m.HNumber 物料代码,o.HNumber 组织代码 from Sc_ProcessExchangeBillMain a WITH(NOLOCK)
left join Gy_Material m WITH(NOLOCK) on a.HMaterID=m.HItemID
left join Xt_ORGANIZATIONS o WITH(NOLOCK) on a.HPRDORGID=o.HItemID
where HBillNo='" + HProcExchBillNo + "' and HProjectNum like'" + str1 + "%' and HPRDORGID=" + HOrgID, "Sc_ProcessExchangeBillMain");
                        left join Gy_Material m WITH(NOLOCK) on a.HMaterID=m.HItemID
                        left join Xt_ORGANIZATIONS o WITH(NOLOCK) on a.HPRDORGID=o.HItemID
                        where HBillNo='" + HProcExchBillNo + "' and HProjectNum like'" + str1 + "%' and HPRDORGID=" + HOrgID, "Sc_ProcessExchangeBillMain");
                        if (dataSet.Tables[0].Rows.Count == 0)
                        {
                            str1 = HBarCode.Substring(23, 3);
                            dataSet = oCN.RunProcReturn(@"select  m.HNumber 物料代码,o.HNumber 组织代码 from Sc_ProcessExchangeBillMain a WITH(NOLOCK)
left join Gy_Material m WITH(NOLOCK) on a.HMaterID=m.HItemID
left join Xt_ORGANIZATIONS o WITH(NOLOCK) on a.HPRDORGID=o.HItemID
where HBillNo='" + HProcExchBillNo + "' and HProjectNum like'" + str1 + "%' and HPRDORGID=" + HOrgID, "Sc_ProcessExchangeBillMain");
                            left join Gy_Material m WITH(NOLOCK) on a.HMaterID=m.HItemID
                            left join Xt_ORGANIZATIONS o WITH(NOLOCK) on a.HPRDORGID=o.HItemID
                            where HBillNo='" + HProcExchBillNo + "' and HProjectNum like'" + str1 + "%' and HPRDORGID=" + HOrgID, "Sc_ProcessExchangeBillMain");
                            if (dataSet.Tables[0].Rows.Count == 0)
                            {
@@ -925,24 +982,47 @@
                            }
                        }
                    }
                    //判断长度是否为50位  15车间
                    //判断长度是否为50位  15车间  和 O6项目
                    else if (HBarCode.Length == 50)
                    {
                        string str1 = HBarCode.Substring(42, 8);
                        DataSet dataSet = oCN.RunProcReturn(@"select  m.HNumber 物料代码,o.HNumber 组织代码 from Sc_ProcessExchangeBillMain a WITH(NOLOCK)
left join Gy_Material m WITH(NOLOCK) on a.HMaterID=m.HItemID
left join Xt_ORGANIZATIONS o WITH(NOLOCK) on a.HPRDORGID=o.HItemID
where HBillNo='" + HProcExchBillNo + "' and HProjectNum like'" + str1 + "%' and HPRDORGID=" + HOrgID, "Sc_ProcessExchangeBillMain");
                        if (dataSet.Tables[0].Rows.Count == 0)
                        string prefix = HBarCode.Substring(0, 10); // 从索引0开始,截取10个字符
                        if (prefix == "#0TE911124")
                        {
                            objJsonResult.code = "0";
                            objJsonResult.count = 0;
                            objJsonResult.Message = "[3791-2-016]条码与流转卡不存在对应关系!";
                            objJsonResult.data = null;
                            return objJsonResult;
                            str1 = HBarCode.Substring(41, 3);
                            LogService.Write($"条码前缀" + str1);
                            DataSet dataSet = oCN.RunProcReturn(@"select  m.HNumber 物料代码,o.HNumber 组织代码 from Sc_ProcessExchangeBillMain a WITH(NOLOCK)
                            left join Gy_Material m WITH(NOLOCK) on a.HMaterID=m.HItemID
                            left join Xt_ORGANIZATIONS o WITH(NOLOCK) on a.HPRDORGID=o.HItemID
                            where HBillNo='" + HProcExchBillNo + "' and HProjectNum like'" + str1 + "%' and HPRDORGID=" + HOrgID, "Sc_ProcessExchangeBillMain");
                            if (dataSet.Tables[0].Rows.Count == 0)
                            {
                                objJsonResult.code = "0";
                                objJsonResult.count = 0;
                                objJsonResult.Message = "[3791-2-016]条码与流转卡不存在对应关系!";
                                objJsonResult.data = null;
                                return objJsonResult;
                            }
                        }
                        else
                        {
                            str1 = HBarCode.Substring(42, 8);
                            DataSet dataSet = oCN.RunProcReturn(@"select  m.HNumber 物料代码,o.HNumber 组织代码 from Sc_ProcessExchangeBillMain a WITH(NOLOCK)
                            left join Gy_Material m WITH(NOLOCK) on a.HMaterID=m.HItemID
                            left join Xt_ORGANIZATIONS o WITH(NOLOCK) on a.HPRDORGID=o.HItemID
                            where HBillNo='" + HProcExchBillNo + "' and HProjectNum like'" + str1 + "%' and HPRDORGID=" + HOrgID, "Sc_ProcessExchangeBillMain");
                            if (dataSet.Tables[0].Rows.Count == 0)
                            {
                                objJsonResult.code = "0";
                                objJsonResult.count = 0;
                                objJsonResult.Message = "[3791-2-016]条码与流转卡不存在对应关系!";
                                objJsonResult.data = null;
                                return objJsonResult;
                            }
                        }
                    }
                    if (ds.Tables[0].Rows[0]["HStatus"].ToString() != "")
@@ -977,10 +1057,10 @@
            {
                //查询流转卡数据
                DataSet dataSet = oCN.RunProcReturn(@"select  a.HPRDORGID, m.HModel 物料规格,m.HName 名物料称,a.HBillNo,a.HInterID,a.HMaterID,m.HNumber 物料代码,o.HNumber 组织代码,a.HUnitID,u.HNumber 单位代码 from Sc_ProcessExchangeBillMain a WITH(NOLOCK)
left join Gy_Material m WITH(NOLOCK) on a.HMaterID=m.HItemID
left join Xt_ORGANIZATIONS o WITH(NOLOCK) on a.HPRDORGID=o.HItemID
left join Gy_Unit u WITH(NOLOCK) on a.HUnitID=u.HItemID
where HBillNo='" + HProcExchBillNo + "'", "Sc_ProcessExchangeBillMain");
                left join Gy_Material m WITH(NOLOCK) on a.HMaterID=m.HItemID
                left join Xt_ORGANIZATIONS o WITH(NOLOCK) on a.HPRDORGID=o.HItemID
                left join Gy_Unit u WITH(NOLOCK) on a.HUnitID=u.HItemID
                where HBillNo='" + HProcExchBillNo + "'", "Sc_ProcessExchangeBillMain");
                string HMaterNumber = dataSet.Tables[0].Rows[0]["物料代码"].ToString();
                string HOrgNumber = dataSet.Tables[0].Rows[0]["组织代码"].ToString();
@@ -1707,7 +1787,7 @@
                        if (dataSet.Tables[0].Rows.Count > 0)
                        {
                            string HOutInterID = dataSet.Tables[0].Rows[0][0].ToString();
                            //斯莫尔的情况 分 工废料废 返工
                            //斯莫尔的情况 分 工废 料废 返工
                            //工废
                            if (subLsit[0].HBadTypeID == 3)
                            {
@@ -2321,5 +2401,408 @@
        }
        #endregion
        #region 工序单品过站 查询当前流转卡是否有已有出站单 获取id 单据号
        [Route("Cj_SingleStation/SingleItemTransit_CZD")]
        [HttpGet]
        public object SingleItemTransit_CZD(string sWhere)
        {
            try
            {
                List<object> columnNameList = new List<object>();
                ds = oCN.RunProcReturn(sWhere, "WindowPrint");
                //添加列名
                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 = "[0000-1-037]Sucess!";
                objJsonResult.data = ds.Tables[0];
                objJsonResult.list = columnNameList;
                return objJsonResult;
            }
            catch (Exception e)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "[0000-1-038]Exception!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
        #region 小卫单品过站接口
        #region  工序单品过站 批次码校验返回信息(只用于验证批次是否入库)
        [Route("Cj_SingleStation/checkHBarCode_Batch")]
        [HttpGet]
        public object checkHBarCode_Batch(string HBarCode,string user, int HOrgID)
        {
            try
            {
                ds = oCN.RunProcReturn(@"select * from h_v_Gy_BarCodeBill WITH(NOLOCK) where HBarCode='" + HBarCode + "'", "h_v_Gy_BarCodeBill");
                //判断条码是否存在条码档案
                if (ds.Tables[0].Rows.Count > 0)
                {
                    objJsonResult.code = "1";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "[0000-1-037]校验成功";
                    objJsonResult.data = ds.Tables[0];
                    return objJsonResult;
                }
                else
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "[0000-1-010]没有返回任何记录!当前批次码无入库信息请检查是否扫错";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
            }
            catch (Exception e)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "[0000-1-010]没有返回任何记录!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
        #region  工序单品过站 扫SN码出站保存(保存到出站汇报里(无关键件绑定))
        [Route("Cj_SingleStation/AddStationOutBillList")]
        [HttpPost]
        public object AddStationOutBillList([FromBody] JObject sMainSub)
        {
            try
            {
                var _value = sMainSub["sMainSub"].ToString();
                string msg = _value.ToString();
                string[] sArray = msg.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
                string sMainStr = sArray[0].ToString();//主表信息包含工序,班组,批次等信息
                string barCode_SN = sArray[1].ToString();//扫描的SN码镭雕码产品信息
                string user = sArray[2].ToString();
                //判断是否有查询权限
                if (!DBUtility.ClsPub.Security_Log("Cj_StationOutBill_Edit", 1, false, user))
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "[0000-2-038]无保存权限!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                oCN.BeginTran();
                string sExeReturnInfo = "";
                StationBill omodel = new StationBill();
                omodel = JsonConvert.DeserializeObject<StationBill>(sMainStr);
                //判断是否有对应流转卡信息并获取
                ds = oCN.RunProcReturn(@"exec h_p_Sc_ProcessExchangeBillList '" + barCode_SN + "'," + omodel.HProcID, "h_p_Sc_ProcessExchangeBillList");
                if (ds.Tables[0].Rows.Count > 0)
                {
                    //将流转卡信息写入
                    omodel.HProcExchBillNo = ds.Tables[0].Rows[0]["HProcExchBillNo"].ToString();
                    omodel.HProcExchInterID = DBUtility.ClsPub.isLong(ds.Tables[0].Rows[0]["HProcExchInterID"].ToString());
                    omodel.HProcExchEntryID = DBUtility.ClsPub.isLong(ds.Tables[0].Rows[0]["HProcExchEntryID"].ToString());
                    omodel.HMaterID = DBUtility.ClsPub.isLong(ds.Tables[0].Rows[0]["HMainMaterID"].ToString());
                    omodel.HCenterID = DBUtility.ClsPub.isLong(ds.Tables[0].Rows[0]["HCenterID"].ToString());
                    omodel.HICMOBillNo = ds.Tables[0].Rows[0]["HICMOBillNo"].ToString();
                    omodel.HICMOInterID = DBUtility.ClsPub.isLong(ds.Tables[0].Rows[0]["HICMOInterID"].ToString());
                    omodel.HICMOEntryID = DBUtility.ClsPub.isLong(ds.Tables[0].Rows[0]["HICMOEntryID"].ToString());
                    omodel.HICMOQty = DBUtility.ClsPub.isLong(ds.Tables[0].Rows[0]["HICMOQty"].ToString());
                    omodel.HProcNo = ds.Tables[0].Rows[0]["HProcNo"].ToString();
                }
                else
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "[3791-2-019]]当前SN码和工序无法找到对应流转卡请检查是否输入选择错误";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                //条码上道工序是否过站
                ds = oCN.RunProcReturn("exec h_p_Sc_SNBarcodeProcCtrl_S '" + barCode_SN + "'," + omodel.HProcID, "h_p_Sc_SNBarcodeProcCtrl_S");
                if (ClsPub.isInt(ds.Tables[0].Rows.Count) == 0)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "[0000-1-045]查无数据!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                else if (ds.Tables[0].Rows[0]["HBack"].ToString() == "2")
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "[0000-1-051]" + ds.Tables[0].Rows[0]["HBackRemark"].ToString() + "!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                //判断条码是否已经出站
                ds = oCN.RunProcReturn("select  * from h_v_Gy_QualifiedRecordsList WITH(NOLOCK) where 产品条码='" + barCode_SN + "' and HProcExchInterID=" + omodel.HProcExchInterID + " and HProcExchEntryID=" + omodel.HProcExchEntryID + " and HProcID=" + omodel.HProcID, "h_v_Gy_QualifiedRecordsList");
                if (ds.Tables[0].Rows.Count > 0)
                {
                    oCN.RollBack();
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "[0000-2-039]条码:" + barCode_SN + ",已存在!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                long HMainInterID = 0;
                string BillType = "3791";
                string HBillSubType = "3791";
                long HInterID = omodel.HInterID;//递入type得到的单据ID
                string HBillNo = omodel.HBillNo;//递入type得到的单据号
                int HBillStatus = 1;
                string HMaker = user;//制单人
                string HMouldNum = omodel.HMouldNum;//模穴号
                int HYear = DateTime.Now.Year;
                double HPeriod = DateTime.Now.Month;
                string HRemark = omodel.HRemark;//备注
                string HSourceName = omodel.HSourceName;//生产资源名称
                double HPieceQty = omodel.HPieceQty;//进站PCS数
                double HWasterQty = 0;//报废数量
                double HPlanPieceQty = 0;//进站PNL数
                double HBadPNL = 0;//报废PNL数
                long HICMOInterID = omodel.HICMOInterID;//任务单ID
                long HICMOEntryID = omodel.HICMOEntryID;//任务单ID
                string HICMOBillNo = omodel.HICMOBillNo;//任务单
                int HProcPlanInterID = 0;
                int HProcPlanEntryID = 0;
                string HProcPlanBillNo = "";
                long HProcExchInterID = omodel.HProcExchInterID;
                long HProcExchEntryID = omodel.HProcExchEntryID;
                string HProcExchBillNo = omodel.HProcExchBillNo;//流转卡
                long HMaterID = omodel.HMaterID;//产品ID
                long HProcID = omodel.HProcID;//当前工序ID
                double HICMOQty = omodel.HICMOQty;//任务单数量
                double HPlanQty = omodel.HICMOQty;//移交PNL数
                DateTime HStationOutTime = DateTime.Now;//汇报时间
                long HSourceID = omodel.HSourceID;//生产资源ID
                long HPayProcID = 0;//核算工序ID
                long HGroupID = omodel.HGroupID;//班组ID
                long HDeptID = omodel.HDeptID;
                long HEmpID = omodel.HEmpID;//操作员ID
                long HEmpID2 = omodel.HEmpID2;////操作员2ID
                string HBarCode = barCode_SN;//条形码
                string HAddr = "";
                string HBarCodeMaker = "";
                long HSourceID2 = 0;//生产资源2ID
                long HSourceID3 = 0;//生产资源3ID
                long HSourceID4 = 0;//生产资源4ID
                long HSourceID5 = 0;//生产资源5ID
                long HSupID = 0;
                double HQty = omodel.HQty;//合格数量
                double HPrice = 0;
                double HMoney = 0;
                double HBadCount = omodel.HBadCount;//不良数量
                long HCenterID = omodel.HCenterID;//工作中心ID
                string HProcNo = omodel.HProcNo;//流水号
                string HOrderProcNO = omodel.HOrderProcNO;//订单跟踪号
                string HSourceNameList = omodel.HSourceNameList;//设备清单
                long HMainSourceInterID = omodel.HProcExchInterID;//递入type得到的单据ID
                string HMainSourceBillNo = omodel.HProcExchBillNo;//递入type得到的单据号
                string HMainSourceBillType = "3772";
                bool HLastSubProc = omodel.HLastSubProc;//转下工序
                long HEmpID3 = 0;//操作员3ID
                long HEmpID4 = 0;//操作员4ID
                long HEmpID5 = 0;//操作员5ID
                double HDSQty = 0;//折弯刀数
                double HChongQty = 0;//NCT冲次数
                double HPriceRate = 0;//系数
                double HWorkTimes = 0;//工时
                long HQCCheckID = omodel.HEmpID;//检验员ID
                long HPRDOrgID = omodel.HPRDOrgID;//组织ID
                double HmaterOutqty = 0;//白坯发布
                double HProcPriceRate = 0;//工价系数
                int HTemporaryAreaID = 0;//暂放区
                int HShiftsID = 0;
                //获取当前班次
                //DataSet set = oCN.RunProcReturn("exec h_p_Gy_GetWorkShiftInfo " + HDeptID + "," + HCenterID, "h_p_Gy_GetWorkShiftInfo");
                //if (set.Tables[0].Rows.Count > 0)
                //{
                //    HShiftsID = int.Parse(set.Tables[0].Rows[0]["HInterID"].ToString());
                //}
                //判断当天当前的流转卡是否有出站单
                HInterID = DBUtility.ClsPub.CreateBillID("3791", ref sExeReturnInfo);//递入type得到的单据ID
                HBillNo = DBUtility.ClsPub.CreateBillCode_Prod("3791", ref sExeReturnInfo, true);//递入type得到的单据号
                //主表插入
                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" +
                    ",HmaterOutqty,HProcPriceRate,HTemporaryAreaID,HShiftsID" +
                ") " +
                " 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 +
                "," + HmaterOutqty + "," + HProcPriceRate + "," + HTemporaryAreaID + "," + HShiftsID + ") ");
                ds = oCN.RunProcReturn("select  * from Sc_StationOutBillSub_SN WITH(NOLOCK) where HInterID='" + omodel.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)}, '{barCode_SN}', 1, GETDATE(), '', " + HProcExchInterID + "," + HProcExchEntryID + ", '" + HProcExchBillNo + "', '', 0, 0)");
                //把条码写入日志里面
                LogService.CustomWriteLog("条码:" + barCode_SN + ",工序:" + HProcID + ",出站时间:" + DateTime.Now, "TM" + DateTime.Now.ToString("yyyy-MM-dd"));
                //反写工序出站单的合格数量
                //oCN.RunProc("update Sc_StationOutBillMain set HQty+=1  where HProcExchInterID='" + HProcExchInterID + "' and HProcExchEntryID=" + HProcExchEntryID + " and HInterID=" + HInterID);
                //=========================保存后控制
                DataSet ds2 = oCN.RunProcReturn("Exec h_p_Sc_SingleStationOutBill_AfterSaveCtrl " + HInterID.ToString() + ", '" + HBillNo + $@"',{(ds.Tables[0].Rows.Count == 0 ? 1 : int.Parse(ds.Tables[0].Rows[0]["HEntryID"].ToString()) + 1)},'{barCode_SN}','{user}' ", "h_p_Sc_SingleStationOutBill_AfterSaveCtrl");
                if (ds2 == null)
                {
                    oCN.RollBack();
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "[0000-2-016]保存后控制判断失败!";
                    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 = "[0000-1-051]保存失败2!" + DBUtility.ClsPub.isStrNull(ds2.Tables[0].Rows[0]["HBackRemark"]);
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                //============================
                //ds = oCN.RunProcReturn($@"select (b.HQty -sum(isnull(ou.HQty,0))-sum(isnull(ou.HBadCount,0))) HQty from Sc_ProcessExchangeBillSub b WITH(NOLOCK)
                //            left join Sc_StationOutBillMain ou WITH(NOLOCK) on b.HInterID=ou.HProcExchInterID and b.HEntryID=ou.HProcExchEntryID
                //            where b.HInterID={HProcExchInterID} and b.HEntryID={HProcExchEntryID}
                //            group by b.HInterID,b.HEntryID,b.HQty", "Sc_ProcessExchangeBill_Out");
                //if (double.Parse(ds.Tables[0].Rows[0][0].ToString()) < 0)
                //{
                //    oCN.RollBack();
                //    objJsonResult.code = "0";
                //    objJsonResult.count = 0;
                //    objJsonResult.Message = "[3791-2-028]出站数量超过流转卡数量!";
                //    objJsonResult.data = null;
                //    return objJsonResult;
                //}
                oCN.Commit();
                objJsonResult.code = "1";
                objJsonResult.count = 1;
                objJsonResult.Message = "[0000-1-050]保存成功!";
                objJsonResult.data = null;
                return objJsonResult;
            }
            catch (Exception e)
            {
                oCN.RollBack();
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "[0000-1-051]没有返回任何记录!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
        #region 返回历史出战汇报单信息(即历史过站清单)
        [Route("Cj_SingleStation/SingleStationOutBillList")]
        [HttpGet]
        public object get_Display(string sWhere, string user)
        {
            try
            {
                List<object> columnNameList = new List<object>();
                //判断是否有查询权限
                if (!DBUtility.ClsPub.Security_Log("Cj_StationOutBill_Query", 1, false, user))
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "[0000-1-068]出站单无查询权限!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                if (sWhere == null || sWhere.Equals(""))
                {
                    ds = oCN.RunProcReturn("select Top 1000 * from h_v_Sc_SingleStationOutBillList where 1 = 1" + sWhere + "order by hmainid desc", "h_v_Sc_SingleStationOutBillList");
                }
                else
                {
                    string sql1 = "select Top 1000 * from h_v_MES_StationOutBillList where 1 = 1 ";
                    string sql = sql1 + sWhere + "  order by hmainid desc";
                    ds = oCN.RunProcReturn(sql, "h_v_Sc_SingleStationOutBillList");
                }
                //添加列名
                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 = "[0000-1-037]Sucess!";
                objJsonResult.list = columnNameList;
                objJsonResult.data = ds.Tables[0];
                return objJsonResult;
            }
            catch (Exception e)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "[0000-1-038]Exception!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
        #endregion
    }
}