chenhaozhe
4 天以前 519315a21c6290455e4ea2b9a04d6bc51568a862
WebAPI/Controllers/²Ö´æ¹ÜÀí/ÌõÂëÉú³É/Sc_BarCodeController.cs
@@ -6,9 +6,11 @@
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web;
using System.Web.Http;
using WebAPI.Models;
@@ -131,6 +133,10 @@
                {
                    list.Add("唯一条码");
                    list.Add("批次条码");
                }
                else if (sCapName == "海诚")
                {
                    list.Add("品种条码");
                }
                else
                {
@@ -522,6 +528,8 @@
            return ordrlist;
        }
        public object HSourceOrderList1(DataTable dt, HSouceOrderList ordrlist, string HBarCodeType,string HSourceBillType)
        {
            oSystemParameter.ShowBill(ref DBUtility.ClsPub.sExeReturnInfo);
@@ -589,6 +597,16 @@
                            ordrlist.HGiveAwayFlag = 0;
                        }
                    }
                    if (HSourceBillType == "收料通知单" || HSourceBillType == "采购订单")
                    {
                        if (oSystemParameter.omodel.WMS_CampanyName == "海诚")   //系统参数  å®¢æˆ·å®šåˆ¶åŒ–名称     ç©ºç™½ä¸ºé€šç”¨
                        {
                            ordrlist.HSourceBillSEQ = dt.Rows[i]["HSEQ"].ToString();
                            ordrlist.HFactory = dt.Rows[i]["客户编号"].ToString();
                            ordrlist.HCoilNO = dt.Rows[i]["款号"].ToString();
                            ordrlist.HFurnaceNO = dt.Rows[i]["分组"].ToString();
                        }
                    }
                }
                if (HSourceBillType == "退货通知单")
                {
@@ -621,7 +639,7 @@
        //根据TABLE写入界面(出入库单据) 
        private object Sub_WriteInForm_InOut(DataTable dt, HSouceOrderList ordrlist, string HBarCodeType, string HSourceBillType)
        {
            oSystemParameter.ShowBill(ref DBUtility.ClsPub.sExeReturnInfo);
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                ordrlist.HQty = dt.Rows[i]["可生成条码数量"].ToString();
@@ -654,6 +672,20 @@
                ordrlist.HMTONo = dt.Rows[i]["计划跟踪号"].ToString();
                ordrlist.HDate = dt.Rows[i]["日期"].ToString(); 
                ordrlist.HShowDate = DateTime.Now.ToString();
                if(HSourceBillType=="采购入库单")
                {
                    if(oSystemParameter.omodel.WMS_CampanyName=="海诚")   //系统参数  å®¢æˆ·å®šåˆ¶åŒ–名称     ç©ºç™½ä¸ºé€šç”¨
                    {
                        ordrlist.HInnerBillNo = dt.Rows[i]["采购订单号"].ToString();
                        ordrlist.HSupID = dt.Rows[i]["HSupID"].ToString();
                        ordrlist.HSupNumber = dt.Rows[i]["供应商代码"].ToString();
                        ordrlist.HSupName = dt.Rows[i]["供应商"].ToString();
                        ordrlist.HFactory = dt.Rows[i]["客户编号"].ToString();
                        ordrlist.HCoilNO = dt.Rows[i]["款号"].ToString();
                        ordrlist.HFurnaceNO = dt.Rows[i]["分组"].ToString();
                    }
                }
            }
            return ordrlist;
        }
@@ -801,12 +833,13 @@
                long HMaterID = DBUtility.ClsPub.isLong(ordrlist[i].HMaterID);              // ç‰©æ–™å†…码
                string HBatchNo = DBUtility.ClsPub.isStrNull(ordrlist[i].HBatchNo);         // æ‰¹å·
                long HAuxPropID = DBUtility.ClsPub.isLong(ordrlist[i].HAuxPropID);          // è¾…助属性ID
                string HMTONo = DBUtility.ClsPub.isStrNull(ordrlist[i].HMTONo);             //计划跟踪号
                double HSourceQty = DBUtility.ClsPub.isDoule(ordrlist[i].HMinQty);          // æºå•数量
                double HQty = DBUtility.ClsPub.isDoule(ordrlist[i].HQty);                   // æ•°é‡
                double HMinQty = DBUtility.ClsPub.isDoule(ordrlist[i].HMinQty);             // æœ€å°åŒ…装数
                if (HMaterID != 0)
                {
                    DataSet oDsCheck = oCN.RunProcReturn("exec h_p_Gy_BarCodeBill_AddCheck " + HSno.ToString() + ",'" + HBarCodeType + "','" + HSourceBillNo + "'," + HMaterID.ToString() + ",'" + HBatchNo + "'," + HAuxPropID.ToString() + "," + HSourceQty.ToString() + "," + HQty.ToString() + "," + HMinQty.ToString() + "," + HOrgID.ToString() + ",'" + SourceQtyCtl + "'", "h_p_Gy_BarCodeBill_AddCheck");
                    DataSet oDsCheck = oCN.RunProcReturn("exec h_p_Gy_BarCodeBill_AddCheck_New " + HSno.ToString() + ",'" + HBarCodeType + "','" + HSourceBillNo + "'," + HMaterID.ToString() + ",'" + HBatchNo + "'," + HAuxPropID.ToString() + ",'" + HMTONo + "'," + HSourceQty.ToString() + "," + HQty.ToString() + "," + HMinQty.ToString() + "," + HOrgID.ToString() + ",'" + SourceQtyCtl + "'", "h_p_Gy_BarCodeBill_AddCheck_New");
                    if (oDsCheck == null && oDsCheck.Tables[0].Rows.Count == 0)
                    {
                        objJsonResult.code = "0";
@@ -845,7 +878,7 @@
            int HBQty = 0;              //箱数
            double HQty = 0;            //数量
            string WeiShu = "";         //尾数
            int LSH = 0;                //流水号
            Int64 LSH = 0;              //流水号
            string LSH2 = "";           //流水号转换成字符
            string sDate = "";          //日期
            string sYear = "";          //å¹´
@@ -935,7 +968,7 @@
                            sTMNumber = HNumber + sYear + sPeriod + sDay;
                            Ds = oCN.RunProcReturn("exec h_p_WMS_GetMaxNo '" + sTMNumber + "'", "h_p_WMS_GetMaxNo");    //获取最大流水号
                            //oCn.RunProc("exec h_p_WMS_SetMaxNo '" + sTMNumber + "'");
                            LSH = ClsPub.isInt(Ds.Tables[0].Rows[0][0]);
                            LSH = ClsPub.isLong(Ds.Tables[0].Rows[0][0]);
                        }
                        else if (CampanyName == "飞龙")
                        {
@@ -952,7 +985,7 @@
                            sTMNumber = HWorksNumber + HNumber + sYear + sPeriod + sDay;
                            Ds = oCN.RunProcReturn("exec h_p_WMS_GetMaxNo '" + sTMNumber + "'", "h_p_WMS_GetMaxNo");    //获取最大流水号
                            //oCn.RunProc("exec h_p_WMS_SetMaxNo '" + sTMNumber + "'");
                            LSH = ClsPub.isInt(Ds.Tables[0].Rows[0][0]);
                            LSH = ClsPub.isLong(Ds.Tables[0].Rows[0][0]);
                        }
                        else if (CampanyName == "瑞与祺") {
                            var date = DateTime.Now.ToString("yyMMdd");//日期
@@ -977,7 +1010,7 @@
                                //sTMNumber = ordrlist[j].HMaterNumber + "-包装标识-" + date + "-" + ordrlist[j].HSupNumber + "-";
                                Ds = oCN.RunProcReturn("exec h_p_WMS_GetMaxNo '" + sTMNumber + "'", "h_p_WMS_GetMaxNo");    //获取最大流水号
                                LSH = ClsPub.isInt(Ds.Tables[0].Rows[0][0]);
                                LSH = ClsPub.isLong(Ds.Tables[0].Rows[0][0]);
                            }
                            else if (HSourceBillTypeName == "生产入库单")
                            {
@@ -1011,13 +1044,13 @@
                                //sTMNumber = ordrlist[j].HMaterNumber + "-包装标识-"+ date + "-组织代码-";
                                Ds = oCN.RunProcReturn("exec h_p_WMS_GetMaxNo '" + sTMNumber + "'", "h_p_WMS_GetMaxNo");    //获取最大流水号
                                LSH = ClsPub.isInt(Ds.Tables[0].Rows[0][0]);
                                LSH = ClsPub.isLong(Ds.Tables[0].Rows[0][0]);
                            }
                            else
                            {
                                sTMNumber = HOrgNumber + HNumber + sYear + sPeriod + sDay;
                                Ds = oCN.RunProcReturn("exec h_p_WMS_GetMaxNo '" + sTMNumber + "'", "h_p_WMS_GetMaxNo");    //获取最大流水号
                                LSH = ClsPub.isInt(Ds.Tables[0].Rows[0][0]);
                                LSH = ClsPub.isLong(Ds.Tables[0].Rows[0][0]);
                            }
                        }
                        else  //通用方法
@@ -1026,7 +1059,7 @@
                            sTMNumber = HOrgNumber + HNumber + sYear + sPeriod + sDay;
                            Ds = oCN.RunProcReturn("exec h_p_WMS_GetMaxNo '" + sTMNumber + "'", "h_p_WMS_GetMaxNo");    //获取最大流水号
                            //oCn.RunProc("exec h_p_WMS_SetMaxNo '" + sTMNumber + "'");
                            LSH = ClsPub.isInt(Ds.Tables[0].Rows[0][0]);
                            LSH = ClsPub.isLong(Ds.Tables[0].Rows[0][0]);
                        }
                    }
                    else if (HSelectBarCodeType == "品种条码")
@@ -1050,7 +1083,7 @@
                        sTMNumber = HMaterNumber + sYear + sPeriod + sDay;
                        Ds = oCN.RunProcReturn("exec h_p_WMS_GetMaxNo '" + sTMNumber + "'", "h_p_WMS_GetMaxNo");    //获取最大流水号
                                                                                                                    //oCn.RunProc("exec h_p_WMS_SetMaxNo '" + sTMNumber + "'");
                        LSH = ClsPub.isInt(Ds.Tables[0].Rows[0][0]);
                        LSH = ClsPub.isLong(Ds.Tables[0].Rows[0][0]);
                        LSHlen = 4;
                    }
                    else if (HSelectBarCodeType == "仪器成品条码规则") //另外处理了
@@ -1067,7 +1100,7 @@
                        sTMNumber = HMaterNumber + HBatchNo;
                        Ds = oCN.RunProcReturn("exec h_p_WMS_GetMaxNo '" + sTMNumber + "'", "h_p_WMS_GetMaxNo");    //获取最大流水号
                                                                                                                    //oCn.RunProc("exec h_p_WMS_SetMaxNo '" + sTMNumber + "'");
                        LSH = ClsPub.isInt(Ds.Tables[0].Rows[0][0]);
                        LSH = ClsPub.isLong(Ds.Tables[0].Rows[0][0]);
                        LSHlen = 6;
                    }
                    else if (HSelectBarCodeType == "内销机条码")
@@ -1077,7 +1110,7 @@
                        sTMNumber = "1" + HModelName + HBarCodeDate + HBarCodeBatchNo + HYasuoji + "00";
                        Ds = oCN.RunProcReturn("exec h_p_WMS_GetMaxNo '" + sTMNumber + "'", "h_p_WMS_GetMaxNo");    //获取最大流水号
                                                                                                                    //oCn.RunProc("exec h_p_WMS_SetMaxNo '" + sTMNumber + "'");
                        LSH = ClsPub.isInt(Ds.Tables[0].Rows[0][0]);
                        LSH = ClsPub.isLong(Ds.Tables[0].Rows[0][0]);
                        LSHlen = 5;
                        if (sTMNumber.Length != 16)
                        {
@@ -1094,7 +1127,7 @@
                        sTMNumber = HMaterNumber.Replace(".", "") + HBarCodeDate + HBarCodeBatchNo;
                        Ds = oCN.RunProcReturn("exec h_p_WMS_GetMaxNo '" + sTMNumber + "'", "h_p_WMS_GetMaxNo");    //获取最大流水号
                                                                                                                    //oCn.RunProc("exec h_p_WMS_SetMaxNo '" + sTMNumber + "'");
                        LSH = ClsPub.isInt(Ds.Tables[0].Rows[0][0]);
                        LSH = ClsPub.isLong(Ds.Tables[0].Rows[0][0]);
                        LSHlen = 5;
                        if (sTMNumber.Length != 18)
                        {
@@ -1110,7 +1143,7 @@
                        sTMNumber = HICMOBillNo;
                        Ds = oCN.RunProcReturn("exec h_p_WMS_GetMaxNo '" + sTMNumber + "'", "h_p_WMS_GetMaxNo");    //获取最大流水号
                                                                                                                    //oCn.RunProc("exec h_p_WMS_SetMaxNo '" + sTMNumber + "'");
                        LSH = ClsPub.isInt(Ds.Tables[0].Rows[0][0]);
                        LSH = ClsPub.isLong(Ds.Tables[0].Rows[0][0]);
                        LSHlen = 5;
                    }
                    else if (HSelectBarCodeType == "托盘条码")
@@ -1119,7 +1152,7 @@
                        //条码前缀 = ç‰©æ–™å†…码 + å¹´ + æœˆ + æ—¥
                        sTMNumber = HNumber + sYear + sPeriod + sDay;
                        Ds = oCN.RunProcReturn("exec h_p_WMS_GetMaxNo '" + sTMNumber + "'", "h_p_WMS_GetMaxNo");    //获取最大流水号
                        LSH = ClsPub.isInt(Ds.Tables[0].Rows[0][0]);
                        LSH = ClsPub.isLong(Ds.Tables[0].Rows[0][0]);
                    }
                    else
                    {
@@ -1184,6 +1217,40 @@
                            return objJsonResult;
                        }
                        HBarCodeList barcode = new HBarCodeList();
                        if (CampanyName == "海诚") //系统参数  å®¢æˆ·å®šåˆ¶åŒ–名称
                        {
                            string sHMTONo = "";            //计划跟踪号
                            string sHSourceBillNo = "";     //源单单号
                            string sHSourceBillSEQ = "";    //源单行号
                            string sHSourceEntryID = "";    //源单子ID
                            string sSupNumber = "";         //供应商代码
                            string sHQty = "";              //数量
                            sHMTONo = DBUtility.ClsPub.isStrNull(ordrlist[j].HMTONo);
                            sHSourceBillNo = DBUtility.ClsPub.isStrNull(ordrlist[j].HBillNo);
                            sHSourceBillSEQ = DBUtility.ClsPub.isStrNull(ordrlist[j].HSourceBillSEQ);
                            sHSourceEntryID = DBUtility.ClsPub.isStrNull(ordrlist[j].HSubID);
                            sSupNumber = DBUtility.ClsPub.isStrNull(ordrlist[j].HSupNumber);
                            sHQty = DBUtility.ClsPub.isStrNull(HMinQty);
                            if (DBUtility.ClsPub.isStrNull(ordrlist[j].HBillType) == "1102") //源单:采购订单
                            {
                                //条码规则:采购订单单号@行号@物料代码@MTO@数量@供应商代码
                                TM = sHSourceBillNo + "@" + sHSourceBillSEQ + "@" + HMaterNumber + "@" + sHMTONo + "@" + sHQty + "@" + sSupNumber;
                            }
                            else if (DBUtility.ClsPub.isStrNull(ordrlist[j].HBillType) == "1103") //源单:收料通知单
                            {
                                //条码规则:收料通知单号@单据子内码@物料代码@MTO@数量@供应商代码
                                TM = sHSourceBillNo + "@" + sHSourceEntryID + "@" + HMaterNumber + "@" + sHMTONo + "@" + sHQty + "@" + sSupNumber;
                            }
                            else
                            {
                                //条码规则:物料内码@MTO@批次号@数量
                                TM = HNumber + "@" + sHMTONo.Replace(" ","") + "@" + HBatchNo.Replace(" ","") + "@" + sHQty;
                            }
                        }
                        barcode.HBarCode2 = TM;
                        barcode.HEntryID2 = ClsPub.isStrNull(j + 1);
                        barcode.HMaterID2 = ordrlist[j].HMaterID;
@@ -1501,7 +1568,7 @@
        }
        #endregion
        #region æ¡ç å­˜å…¥æ¡ç ä¸»æ¡£
        #region æ¡ç è½¬å­˜æ¡ç ä¸»æ¡£
        /// <summary>
        /// æ¡ç è½¬å­˜æ¡ç ä¸»æ¡£
        /// </summary>
@@ -1515,7 +1582,7 @@
            {
                var _value = msg["msg"].ToString();
                string msg1 = _value.ToString();
                string[] sArray = msg1.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
                string[] sArray = msg1.Split(new string[] { ";" }, StringSplitOptions.None);
                string msg2 = sArray[0].ToString();
                string HOrgType = sArray[1].ToString();
                string HSourceBillTypeName = sArray[2].ToString();
@@ -1523,6 +1590,9 @@
                string CampanyName = sArray[4].ToString() == "xxx" ? "" : sArray[4].ToString();
                string UserName = sArray[5].ToString();
                string barCodeNo = sArray[6].ToString();
                string HFactory = sArray[7].ToString();
                string HCoilNO = sArray[8].ToString();
                string HFurnaceNO = sArray[9].ToString();
                ClsPub.CurUserName = UserName;
                //获取内码
@@ -1551,12 +1621,12 @@
                }
                else
                {
                    string HBarCodeType = ClsPub.isStrNull(HSelectBarCodeType);
                    // æ¡ç è½¬å­˜
                    msg2 = msg2.Replace("\\", "");
                    msg2 = msg2.Replace("\n", "");  //\n
                    List<HSouceOrderList> ordrlist = Newtonsoft.Json.JsonConvert.DeserializeObject<List<HSouceOrderList>>(msg2);
                    LogService.Write(ordrlist[0]);
                    // LogService.Write(ordrlist[0]);
                    long HSourceInterID = string.IsNullOrEmpty(ordrlist[0].HMainID) == true ? 0 : ClsPub.isLong(ordrlist[0].HMainID);
                    long HSourceEntryID = string.IsNullOrEmpty(ordrlist[0].HSubID) == true ? 0 : ClsPub.isLong(ordrlist[0].HSubID);
@@ -1573,16 +1643,24 @@
                        ",@HMTONO = N'" + ordrlist[0].HMTONo + "'" +
                        ",@HBarCodeDate = N'" + ordrlist[0].HDate + "'" +
                        ",@HEmpID = " + ordrlist[0].HEmpID  +
                        ",@HGroupID = " + ordrlist[0].HGroupID +
                        ",@HSourceInterID = " + HSourceInterID + 
                        ",@HSourceEntryID = " + HSourceEntryID
                        ",@HSourceEntryID = " + HSourceEntryID +
                        ",@HBarCodeType = N'" + HBarCodeType + "'" +
                        ",@HSourceBillNo = N'" + ordrlist[0].HSourceBillNo + "'" +
                        ",@HMaker = N'" + ordrlist[0].HMaker + "'" +
                        ",@HFactory = N'" + HFactory + "'" +
                        ",@HCoilNO = N'" + HCoilNO + "'" +
                        ",@HFurnaceNO = N'" + HFurnaceNO + "'" +
                        ",@HInnerBillNo = N'" + ordrlist[0].HInnerBillNo + "'" +
                        ",@HSourceBillType = N'" + ordrlist[0].HBillType + "'" +
                        ",@HStockOrg = N'" + HOrgType + "'" +
                        ",@HInterID = N'" + ordrlist[0].HInterID + "'"
                        , "h_p_SC_BarCode_Transfer");
                    if((bool)ds1.Tables[0].Rows[0]["returntype"] == true)
                    {
                        objJsonResult.code = "1";
                        objJsonResult.count = 1;
                        objJsonResult.Message = "[0000-1-037]获取资源绑定数据成功!";
                        objJsonResult.Message = ds1.Tables[0].Rows[0]["mesg"].ToString();
                    }
                    else
                    {
@@ -1599,6 +1677,221 @@
                return objJsonResult;
            }
            return objJsonResult;
        }
        #endregion
        #region æ¡ç è½¬å­˜æ¡ç ä¸»æ¡£(批量)
        /// <summary>
        /// æ¡ç è½¬å­˜æ¡ç ä¸»æ¡£(批量)
        /// </summary>
        /// <param name="msg"></param>
        /// <returns></returns>
        [Route("Sc_BarCode/SaveBarCode_NoGenerate_Batch")]
        [HttpPost]
        public object SaveBarCode_NoGenerate_Batch([FromBody] JObject msg)
        {
            try
            {
                var _value = msg["msg"].ToString();
                string msg1 = _value.ToString();
                string[] sArray = msg1.Split(new string[] { ";" }, StringSplitOptions.None);
                string msg2 = sArray[0].ToString();
                string HOrgType = sArray[1].ToString();
                string HSourceBillTypeName = sArray[2].ToString();
                string HSelectBarCodeType = sArray[3].ToString();
                string CampanyName = sArray[4].ToString() == "xxx" ? "" : sArray[4].ToString();
                string UserName = sArray[5].ToString();
                string barCodeNoStrs = sArray[6].ToString(); // è¿™é‡Œçš„æ¡ç æ˜¯ä¸Žæäº¤çš„单据序列对应的条码数组
                string HFactory = sArray[7].ToString();
                string HCoilNO = sArray[8].ToString();
                string HFurnaceNO = sArray[9].ToString();
                ClsPub.CurUserName = UserName;
                //获取内码
                HInterID = DBUtility.ClsPub.CreateBillID_Prod(ModName, ref DBUtility.ClsPub.sExeReturnInfo);
                DAL.ClsGy_ORGANIZATIONS_View oClsGy_ORGANIZATIONS_View = new DAL.ClsGy_ORGANIZATIONS_View();
                HOrgNumber = "";
                if (oClsGy_ORGANIZATIONS_View.GetInfoByName(HOrgType))
                {
                    HOrgID = oClsGy_ORGANIZATIONS_View.omodel.HItemID;
                    HOrgNumber = DBUtility.ClsPub.isStrNull(oClsGy_ORGANIZATIONS_View.omodel.HNumber);
                }
                if (HOrgID == -1)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "[0000-2-055]选择组织有错误!";
                    return objJsonResult;
                }
                if (!Sub_AllowSave(msg2, HSelectBarCodeType))//单据完整性判断
                {
                    return objJsonResult;
                }
                if (HSelectBarCodeType == "仪器成品条码规则")
                {
                    //客户定制
                }
                else
                {
                    string HBarCodeType = ClsPub.isStrNull(HSelectBarCodeType);
                    // æ¡ç è½¬å­˜
                    msg2 = msg2.Replace("\\", "");
                    msg2 = msg2.Replace("\n", "");  //\n
                    List<HSouceOrderList> ordrlist = Newtonsoft.Json.JsonConvert.DeserializeObject<List<HSouceOrderList>>(msg2);
                    List<string> barcodeList = Newtonsoft.Json.JsonConvert.DeserializeObject<List<string>>(barCodeNoStrs);
                    // TODO é€šè¿‡InterID å’Œ EntryID ä»Žæ¡ç æ¡£æ¡ˆä¸­æŸ¥è¯¢æ˜¯å¦æœ‰å·²ç”Ÿæˆçš„单据 é‡æ–°å†™ä¸€ä¸ªå­˜å‚¨è¿‡ç¨‹ï¼Œå½“已存在对应的条码单据时,返回条码主档中的条码档案
                    DataSet dsCache = oCN.RunProcReturn($@"select * from h_v_IF_BarCodeBillList a
                                                    Inner Join Gy_BarCodeBill b on a.HItemID = b.HItemID
                                                    where b.HSourceINterID = { ordrlist[0].HMainID } and b.HSourceEntryID = {ordrlist[0].HSubID}"
                                                        , "h_v_IF_BarCodeBillList");
                    if(dsCache.Tables[0].Rows.Count > 0)
                    {
                        objJsonResult.code = "2";
                        objJsonResult.count = 1;
                        objJsonResult.data = dsCache.Tables[0];
                        objJsonResult.Message = "条码已存在!";
                        return objJsonResult;
                    }
                    DataSet ds1 = new DataSet();
                    for(int i=0; i<ordrlist.Count; i++)
                    {
                        long HSourceInterID = string.IsNullOrEmpty(ordrlist[i].HMainID) == true ? 0 : ClsPub.isLong(ordrlist[0].HMainID);
                        long HSourceEntryID = string.IsNullOrEmpty(ordrlist[i].HSubID) == true ? 0 : ClsPub.isLong(ordrlist[0].HSubID);
                        ds1 = oCN.RunProcReturn("exec h_p_SC_BarCode_Transfer " +
                        "@HBarCodeNo = N'" + barcodeList[i] + "'" +
                        ",@HSubID = " + ordrlist[i].HSubID +
                        ",@HMaterID = " + ordrlist[i].HMaterID +
                        ",@HGiveAwayFlag = " + ordrlist[i].HGiveAwayFlag +
                        ",@HQty = " + ordrlist[i].HQty +
                        ",@HUnitID = " + ordrlist[i].HUnitID +
                        ",@HMinQty = " + ordrlist[i].HMinQty +
                        ",@HSupID = " + ordrlist[i].HSupID +
                        ",@HBatchNo = N'" + ordrlist[i].HBatchNo + "'" +
                        ",@HMTONO = N'" + ordrlist[i].HMTONo + "'" +
                        ",@HBarCodeDate = N'" + ordrlist[i].HDate + "'" +
                        ",@HEmpID = " + ordrlist[i].HEmpID +
                        ",@HSourceInterID = " + HSourceInterID +
                        ",@HSourceEntryID = " + HSourceEntryID +
                        ",@HBarCodeType = N'" + HBarCodeType + "'" +
                        ",@HSourceBillNo = N'" + ordrlist[i].HSourceBillNo + "'" +
                        ",@HMaker = N'" + ordrlist[i].HMaker + "'" +
                        ",@HFactory = N'" + HFactory + "'" +
                        ",@HCoilNO = N'" + HCoilNO + "'" +
                        ",@HFurnaceNO = N'" + HFurnaceNO + "'" +
                        ",@HInnerBillNo = N'" + ordrlist[i].HInnerBillNo + "'" +
                        ",@HSourceBillType = N'" + ordrlist[i].HBillType + "'" +
                        ",@HStockOrg = N'" + HOrgType + "'" +
                        ",@HInterID = " + ordrlist[i].HInterID
                        , "h_p_SC_BarCode_Transfer");
                        if ((bool)ds1.Tables[0].Rows[0]["returntype"] == false)
                        {
                            throw new Exception(ds1.Tables[0].Rows[0]["mesg"].ToString());
                        }
                    }
                    objJsonResult.code = "1";
                    objJsonResult.count = 1;
                    objJsonResult.Message = ds1.Tables[0].Rows[0]["mesg"].ToString();
                }
            }
            catch (Exception e)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "[3899-2-006]条码生成失败!" + e.Message;
                return objJsonResult;
            }
            return objJsonResult;
        }
        #endregion
        #region [获取标签打印指令 CPCL指令]
        [Route("Sc_BarCode/Get_BarCodePrintCode_CPCL")]
        [HttpGet]
        public object Get_BarCodePrintCode_CPCL(string HOrginationName, int HBillInterID, int HBillEntryID, string HViewName, string HBillSubType, int HInterID)
        {
            try
            {
                ds = oCN.RunProcReturn("exec h_p_getHBarCodePrintCode_CPCL N'" + HOrginationName + "'" +
                    "," + HBillInterID + "," + HBillEntryID + ",N'" + HViewName + "',N'" + HBillSubType + "'," + HInterID, "h_p_getHBarCodePrintCode_CPCL");
                if((int)ds.Tables[0].Rows[0]["resultType"] == 1)
                {
                    string resultMesg = ds.Tables[0].Rows[0]["payload"].ToString().Replace("\\r\\n", "\r\n");
                    objJsonResult.code = "1";
                    objJsonResult.count = 1;
                    objJsonResult.Message = resultMesg;
                    return objJsonResult;
                }
                else
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "打印指令获取失败!" + ds.Tables[0].Rows[0]["payload"];
                    return objJsonResult;
                }
            }
            catch(Exception e)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "打印指令获取失败!" + e.Message;
                return objJsonResult;
            }
        }
        #endregion
        #region [APP èŽ·å–æ‰“å°æ¨¡æ¿]
        public class PrintTemplate
        {
            public int Id { get; }
            public string OrgShort { get; }
            public string HBillSubtype { get; }
            public string Format { get; }
            public string Description { get; }
            public string[] Placeholder { get; }
        }
        [Route("Sc_BarCode/Get_BarCodeGenTemplate")]
        [HttpGet]
        public object Get_BarCodeGenTemplate(string HOrginationName, string HBillSubType)
        {
            try
            {
                string filePath = HttpContext.Current.Server.MapPath("~/Template");
                string fileFullPath = Path.Combine(filePath, "barCodeTemplateStorage.json");
                if (!File.Exists(fileFullPath))
                {
                    throw new Exception($"模板文件不存在:{fileFullPath}");
                }
                string jsonContent = File.ReadAllText(fileFullPath);
                var templates = JsonConvert.DeserializeObject<PrintTemplate[]>(jsonContent);
                var targetTemplate = templates.FirstOrDefault<PrintTemplate>(t => HOrginationName.Contains(t.OrgShort) && string.Equals(t.HBillSubtype, HBillSubType));
                if (targetTemplate != null)
                {
                    objJsonResult.code = "1";
                    objJsonResult.count = 1;
                    objJsonResult.data = JsonConvert.SerializeObject(targetTemplate);
                    return objJsonResult;
                }
                else
                {
                    throw new Exception($"没有找到对应的模板");
                }
            }
            catch (Exception e)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "打印模板获取失败!" + e.Message;
                return objJsonResult;
            }
        }
        #endregion
@@ -1797,6 +2090,7 @@
                            barcode.HCusModel2 = ordrlist[i].HCusModel;
                            barcode.HCusMaterName2 = ordrlist[i].HCusMaterName;
                            barcode.HCheckEmpName2 = ordrlist[i].HCheckEmpName;
                            barcode.HZZRQ = ordrlist[i].HZZRQ;
                            ListRows.Add(barcode);
                            n += 1;                                                             //更新同批生成的条码数
@@ -1901,6 +2195,7 @@
                            barcode.HCusModel2 = ordrlist[i].HCusModel;
                            barcode.HCusMaterName2 = ordrlist[i].HCusMaterName;
                            barcode.HCheckEmpName2 = ordrlist[i].HCheckEmpName;
                            barcode.HZZRQ = ordrlist[i].HZZRQ;
                            ListRows.Add(barcode);
                            n += 1;                                                             //更新同批生成的条码数
@@ -2005,6 +2300,7 @@
                            barcode.HCusModel2 = ordrlist[i].HCusModel;
                            barcode.HCusMaterName2 = ordrlist[i].HCusMaterName;
                            barcode.HCheckEmpName2 = ordrlist[i].HCheckEmpName;
                            barcode.HZZRQ = ordrlist[i].HZZRQ;
                            ListRows.Add(barcode);
                            n += 1;                                                             //更新同批生成的条码数
@@ -2075,6 +2371,7 @@
                        string HCusModel2 = ClsPub.isStrNull(ListRows[i].HCusModel2);
                        string HCusMaterName2 = ClsPub.isStrNull(ListRows[i].HCusMaterName2);
                        string HCheckEmpName2 = ClsPub.isStrNull(ListRows[i].HCheckEmpName2);
                        string HZZRQ = ClsPub.isStrNull(ListRows[i].HZZRQ);
                        oCN.RunProc("insert into Gy_BarCodeBill (HBarCode,HBarCodeType,HBarCodeSubType,HMaterID,HUnitID,HQty" +
                                    ",HBatchNo,HSupID,HGroupID,HMaker,HMakeDate,HPrintQty,HinitQty" +
                                    ",HSourceInterID,HSourceEntryID,HSourceBillNo,HSourceBillType,HEndQty " +
@@ -2083,7 +2380,7 @@
                                    ",HSTOCKORGID,HOWNERID,HSeOrderBillNo,HInterID,HEntryID " +
                                    ",HGiveAwayFlag " +
                                    ",HMaterName,HMaterModel,HPinfan,HAuxPropID,HMTONo,HInnerBillNo" +
                                    ",HCoilNO,HFurnaceNO,HFactory,HAuxQty,HheatNO,HProduceDate,HExpiryDate,HEmpID,HCusModel,HCusMaterName,HCheckEmpName " +
                                    ",HCoilNO,HFurnaceNO,HFactory,HAuxQty,HheatNO,HProduceDate,HExpiryDate,HEmpID,HCusModel,HCusMaterName,HCheckEmpName,HZZRQ " +
                                    ") values ("
                                    + "'" + HBarCode + "','" + HBarCodeType + "','" + HBarCodeSubType + "'," + HMaterID.ToString() + "," + HUnitID.ToString() + "," + HQty2.ToString()
                                    + ",'" + HBatchNo2 + "'," + HSupID.ToString() + "," + HGroupID2.ToString() + ",'" + ClsPub.CurUserName + "',getdate()," + HPrintQty.ToString() + "," + HQty2.ToString()
@@ -2093,13 +2390,16 @@
                                    + ", " + HOrgID.ToString() + "," + HOrgID.ToString() + ",'" + HSeOrderBillNo + "'," + HInterID.ToString() + "," + HEntryID.ToString() + ""
                                    + ", " + DBUtility.ClsPub.BoolToString(HGiveAwayFlag)
                                    + ",'" + HMaterName + "','" + HMaterModel + "','" + HPinfan + "'," + HAuxPropID.ToString() + ",'" + HMTONo + "','" + HInnerBillNo + "'"
                                    + ",'" + HCoilNO2 + "','" + HFurnaceNO2 + "','" + HFactory2 + "'," + HAuxQty2 + ",'" + HheatNO2 + "','" + HProduceDate + "','" + HExpiryDate + "'," + HEmpID2.ToString() + ",'" + HCusModel2 + "','" + HCusMaterName2 + "','" + HCheckEmpName2 + "'" + ")");
                                    + ",'" + HCoilNO2 + "','" + HFurnaceNO2 + "','" + HFactory2 + "'," + HAuxQty2 + ",'" + HheatNO2 + "','" + HProduceDate + "','" + HExpiryDate + "'," + HEmpID2.ToString() + ",'" + HCusModel2 + "','" + HCusMaterName2 + "','" + HCheckEmpName2 + "','" + HZZRQ + "'" + ")");
                    }
                }
                //增加 æ¡ç è¶…过未生成功能控制
                //
                //自动装箱
                string sql_autoForBoxBill = "exec h_v_Gy_BarCode_AutoProductBarCodeBox " + HInterID.ToString();
                oCN.RunProc(sql_autoForBoxBill);
                oCN.Commit();
                List<Object> listobj = ListRows.ConvertAll(s => (object)s);//List实体类转换为object
@@ -2136,6 +2436,204 @@
            }
        }
        #endregion
        #region [app æ¡ç æ‹†ç èŽ·å–å­æ¡ç ]
        [Route("Sc_BarCode/SplitBarCode_Sub")]
        [HttpGet]
        public object SplitBarCode_Sub(string HBarCodeNo)
        {
            try
            {
                SQLHelper.ClsCN oCn = new SQLHelper.ClsCN();
                //查询条码信息
                if (HBarCodeNo != null)
                {
                    string prefix = HBarCodeNo.Trim() + "-";
                    ds = oCn.RunProcReturn("SELECT * FROM h_v_Gy_SplitBarCode WITH(NOLOCK) WHERE HBarCode LIKE '" + prefix + "' + '%' AND HBarCode NOT LIKE  '" + prefix + "'  + '%-%' AND ISNUMERIC(RIGHT(HBarCode, LEN(HBarCode) - LEN( '" + prefix + "' ))) = 1  AND TRY_CAST(RIGHT(HBarCode, LEN(HBarCode) - LEN( '" + prefix + "' )) AS INT) IS NOT NULL ", "Gy_BarCodeBill");
                    if (ds != null || ds.Tables[0].Rows.Count >= 0)
                    {
                        // æ‰¾å‡ºæœ€å¤§åŽç¼€æ•°å­—,用于生成下一个编号
                        int maxSuffix = 0;
                        foreach (DataRow row in ds.Tables[0].Rows)
                        {
                            string barCode = row["HBarCode"].ToString();
                            string suffixPart = barCode.Substring(prefix.Length); // å– - åŽçš„部分
                            if (int.TryParse(suffixPart, out int num))
                            {
                                if (num > maxSuffix) maxSuffix = num;
                            }
                        }
                        // ç”Ÿæˆä¸‹ä¸€ä¸ªå­ç ç¼–号
                        string nextBarCode = $"{HBarCodeNo}-{maxSuffix + 1}";
                        objJsonResult.code = "1";
                        objJsonResult.count = 1;
                        objJsonResult.Message = "Sucess!";
                        objJsonResult.data = new
                        {
                            SubBarCodes = ds.Tables[0],        // æ¡ç åŸºç¡€ä¿¡æ¯
                            NextBarCode = nextBarCode          // ä¸‹ä¸€ä¸ªç”Ÿæˆçš„æ¡ç 
                        };
                        return objJsonResult;
                    }
                    else
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        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 = "Exception!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
        #region [app条码拆码生成]
        [Route("Sc_BarCode/SplitBarCode_Save")]
        [HttpPost]
        public object SplitBarCode_Save([FromBody] JObject msg)
        {
            try
            {
                ListModels oListModels = new ListModels();
                DAL.ClsGy_BarCodeBill_ChaiMa BillNew = new DAL.ClsGy_BarCodeBill_ChaiMa();
                var _value = msg["msg"].ToString();
                string msg1 = _value.ToString();
                string[] sArray = msg1.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
                string barcode = sArray[0].ToString(); //条码编号
                Double splitnum = Convert.ToDouble(sArray[1]); //拆码数量
                string data = sArray[2].ToString(); //表体数据
                string user = sArray[3].ToString(); //用户名
                data = data.Replace("\\", "");
                data = data.Replace("\n", "");  //\n
                List<Model.ClsGy_BarCodeEdit_Model> lsmain = new List<Model.ClsGy_BarCodeEdit_Model>();
                lsmain = oListModels.getObjectByJson_Gy_SplitBarCode(data);
                oCN.BeginTran();
                ds = oCN.RunProcReturn("select top 1 * from Gy_BarCodeBill where HBarCode='" + barcode + "'", "Gy_BarCodeBill");
                if (ds != null || ds.Tables[0].Rows.Count > 0)
                {
                    string sql = "insert into Gy_BarCodeBill (HInterID, HEntryID, HBarCode, HBarCodeType, HBarCodeSubType, HMaterID, HUnitID, HQty, HBatchNo, HSupID, HGroupID, HMaker, HMakeDate, " +
                  "HPrintQty, HSourceInterID, HSourceEntryID, HSourceBillNo, HSourceBillType, HinitQty, HEndQty, HBarcodeQtys, HBarcodeNo, HDeptID, HWhID, HSPID, HRemark, " +
                  "HCusID, HCusType, HEndDate, HWorkLineName, HBarCodeDate, HSTOCKORGID, HOWNERID, HSeOrderBillNo, HGiveAwayFlag, HMaterName, HMaterModel, " +
                  "HPinfan, HAuxPropID, HMTONo, HInnerBillNo, HCoilNO, HFurnaceNO, HFactory, HAuxQty, HheatNO, HProduceDate, HExpiryDate, HEmpID, HCusModel, HCusMaterName, HCheckEmpName, HZZRQ" +
                  ") values (" +
                  "'" + ds.Tables[0].Rows[0]["HInterID"].ToString() + "', " +
                  "'" + (int.Parse(ds.Tables[0].Rows[0]["HEntryID"].ToString()) + 1).ToString() + "', " +
                  "'" + lsmain[0].HBarCode.ToString() + "', " +
                  "'" + ds.Tables[0].Rows[0]["HBarCodeType"].ToString() + "', " +
                  "'" + ds.Tables[0].Rows[0]["HBarCodeSubType"].ToString() + "', " +
                  "'" + ds.Tables[0].Rows[0]["HMaterID"].ToString() + "', " +
                  "'" + ds.Tables[0].Rows[0]["HUnitID"].ToString() + "', " +
                  "'" + splitnum + "', " +
                  "'" + ds.Tables[0].Rows[0]["HBatchNo"].ToString() + "', " +
                  "'" + ds.Tables[0].Rows[0]["HSupID"].ToString() + "', " +
                  "'" + ds.Tables[0].Rows[0]["HGroupID"].ToString() + "', " +
                  "'" + user + "', getdate(), " +
                  "'" + ds.Tables[0].Rows[0]["HPrintQty"].ToString() + "', " +
                  "'" + ds.Tables[0].Rows[0]["HSourceInterID"].ToString() + "', " +
                  "'" + ds.Tables[0].Rows[0]["HSourceEntryID"].ToString() + "', " +
                  "'" + ds.Tables[0].Rows[0]["HSourceBillNo"].ToString() + "', " +
                  "'" + ds.Tables[0].Rows[0]["HSourceBillType"].ToString() + "', " +
                  "'" + splitnum + "', " +
                  "'" + ds.Tables[0].Rows[0]["HEndQty"].ToString() + "', " +
                  "'" + ds.Tables[0].Rows[0]["HBarcodeQtys"].ToString() + "', " +
                  "'" + ds.Tables[0].Rows[0]["HBarcodeNo"].ToString() + "', " +
                  "'" + ds.Tables[0].Rows[0]["HDeptID"].ToString() + "', " +
                  "'" + ds.Tables[0].Rows[0]["HWhID"].ToString() + "', " +
                  "'" + ds.Tables[0].Rows[0]["HSPID"].ToString() + "', " +
                  "'" + ds.Tables[0].Rows[0]["HRemark"].ToString() + "', " +
                  "'" + ds.Tables[0].Rows[0]["HCusID"].ToString() + "', " +
                  "'" + ds.Tables[0].Rows[0]["HCusType"].ToString() + "', " +
                  "'" + ds.Tables[0].Rows[0]["HEndDate"].ToString() + "', " +
                  "'" + ds.Tables[0].Rows[0]["HWorkLineName"].ToString() + "', " +
                  "'" + ds.Tables[0].Rows[0]["HBarCodeDate"].ToString() + "', " +
                  "'" + ds.Tables[0].Rows[0]["HSTOCKORGID"].ToString() + "', " +
                  "'" + ds.Tables[0].Rows[0]["HOWNERID"].ToString() + "', " +
                  "'" + ds.Tables[0].Rows[0]["HSeOrderBillNo"].ToString() + "', " +
                  "'" + ds.Tables[0].Rows[0]["HGiveAwayFlag"].ToString() + "', " +
                  "'" + ds.Tables[0].Rows[0]["HMaterName"].ToString() + "', " +
                  "'" + ds.Tables[0].Rows[0]["HMaterModel"].ToString() + "', " +
                  "'" + ds.Tables[0].Rows[0]["HPinfan"].ToString() + "', " +
                  "'" + ds.Tables[0].Rows[0]["HAuxPropID"].ToString() + "', " +
                  "'" + ds.Tables[0].Rows[0]["HMTONo"].ToString() + "', " +
                  "'" + ds.Tables[0].Rows[0]["HInnerBillNo"].ToString() + "', " +
                  "'" + ds.Tables[0].Rows[0]["HCoilNO"].ToString() + "', " +
                  "'" + ds.Tables[0].Rows[0]["HFurnaceNO"].ToString() + "', " +
                  "'" + ds.Tables[0].Rows[0]["HFactory"].ToString() + "', " +
                  "'" + ds.Tables[0].Rows[0]["HAuxQty"].ToString() + "', " +
                  "'" + ds.Tables[0].Rows[0]["HheatNO"].ToString() + "', " +
                  "'" + ds.Tables[0].Rows[0]["HProduceDate"].ToString() + "', " +
                  "'" + ds.Tables[0].Rows[0]["HExpiryDate"].ToString() + "', " +
                  "'" + ds.Tables[0].Rows[0]["HEmpID"].ToString() + "', " +
                  "'" + ds.Tables[0].Rows[0]["HCusModel"].ToString() + "', " +
                  "'" + ds.Tables[0].Rows[0]["HCusMaterName"].ToString() + "', " +
                  "'" + ds.Tables[0].Rows[0]["HCheckEmpName"].ToString() + "', " +
                  "'" + ds.Tables[0].Rows[0]["HZZRQ"].ToString() + "'" +
                  ")";
                    //插入拆分条码
                    oCN.RunProc(sql);
                    //更新老条码的HQty数量
                    oCN.RunProc("update  Gy_BarCodeBill set HQty= HQty-'"+splitnum+"' where HItemID="+ ds.Tables[0].Rows[0]["HItemID"].ToString());
                    oCN.Commit();
                    objJsonResult.code = "1";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "保存成功!";
                    objJsonResult.data = 1;
                    return objJsonResult;
                }
                else
                {
                    oCN.RollBack();
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "保存失败!未查询到条码信息";
                    objJsonResult.data = 1;
                    return objJsonResult;
                }
            }
            catch (Exception e)
            {
                oCN.RollBack();
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "保存失败!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
        #endregion
    }
}