llj
7 天以前 2bf6de5d4748d28f7f3a098af25503d6a0c619d1
WebAPI/Controllers/²Ö´æ¹ÜÀí/ÌõÂëÉú³É/Sc_BarCodeController.cs
@@ -25,6 +25,7 @@
        public WebServer webserver = new WebServer();
        SQLHelper.ClsCN oCN = new SQLHelper.ClsCN();
        private WebS.WebService1 oWebs = new WebS.WebService1();
        public WebS.ClsKf_ICStockBill_WMS WebSoBar = new WebS.ClsKf_ICStockBill_WMS();
        //获取系统参数
        Pub_Class.ClsXt_SystemParameter oSystemParameter = new Pub_Class.ClsXt_SystemParameter();
        public Int64 HInterID = 0;      //内码
@@ -2752,30 +2753,42 @@
        #region [条码生成接口_小卫镭雕码]
        [Route("Sc_BarCode/SaveSNByICMO_XW")]
        [HttpGet]
        public object SaveSNByICMO_XW(String HBillNo,string HSN, int HBeginNo, int HEndNo, int HCount)
        public object SaveSNByICMO_XW(String HBillNo,string HSN, int HBeginNo, int HEndNo, int HCount,string HMachineCode)
        {
            try
            {
                //ds = oCN.RunProcReturn("exec h_p_WMS_GetSNByICMO_XW '" + HCount + "', "+ HSeq, "h_p_WMS_GetSNByICMO_XW");
                if(oWebs.GetWebAPIToLocal_ICMO(HBillNo, "3710", "admin", ref DBUtility.ClsPub.sErrInfo)==false)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "[0000-2-020]单据同步失败请联系管理员,"+ DBUtility.ClsPub.sErrInfo;
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                else
                {
                    ds = oCN.RunProcReturn("exec h_p_WMS_SaveSNByICMO_XW '" + @HBillNo + "', " + HSN +","+HBeginNo+","+HEndNo+","+HCount+",'"+HMachineCode+"'", "h_p_WMS_SaveSNByICMO_XW");
                //if (ds == null)
                //{
                //    objJsonResult.code = "0";
                //    objJsonResult.count = 0;
                //    objJsonResult.Message = "[0000-2-020]没有返回任何结果,条码保存失败!";
                //    objJsonResult.data = null;
                //    return objJsonResult;
                //}
                //if (DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[0]["HBack"]) != "0")
                //{
                //    objJsonResult.code = "0";
                //    objJsonResult.count = 0;
                //    objJsonResult.Message = ds.Tables[0].Rows[0]["HRemark"].ToString();
                //    objJsonResult.data = null;
                //    return objJsonResult;
                //}
                    if (ds == null)
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "[0000-2-020]没有返回任何结果,条码保存失败!";
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                    if (DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[0]["HBack"]) != "0")
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "[0000-2-020]条码绑定失败!"+ ds.Tables[0].Rows[0]["HRemark"].ToString();
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                }
                objJsonResult.code = "1";
                objJsonResult.count = 1;
                objJsonResult.Message = "[0000-1-037]条码生成成功!";
@@ -2794,6 +2807,351 @@
        }
        #endregion        
        #region [条码生成接口_小卫托条码]
        [Route("Sc_BarCode/Sub_SaveBill_xiaowei")]
        [HttpPost]
        public object Sub_SaveBill_xiaowei([FromBody] JObject msg)
        {
            try
            {
                var _value = msg["msg"].ToString();
                string msg1 = _value.ToString();
                string[] sArray = msg1.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
                string msg2 = sArray[0].ToString();
                string HOrgType = sArray[1].ToString();//组织名称
                string HSourceBillTypeName = "生产订单";//源单类型
                string HSelectBarCodeType = "托盘条码";
                string CampanyName = "小卫";
                string UserName = sArray[2].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
                {
                    //生成条码
                    SaveBarCode_xiaowei(msg2, HSelectBarCodeType, CampanyName, HSourceBillTypeName);
                }
            }
            catch (Exception e)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "[3899-2-006]条码生成失败!" + e.Message;
                return objJsonResult;
            }
            return objJsonResult;
        }
        #endregion
        #region[条码生成方法_xiaowei]
        private object SaveBarCode_xiaowei(string msg2, string HSelectBarCodeType, string CampanyName, string HSourceBillTypeName)
        {
            DateTime sDate = DateTime.Now;                      //日期
            string HSourceBillType_Temp = "";                   //源单类型
            int n = 0;                                          //同批生成的条码索引
            //获取明细信息
            msg2 = msg2.Replace("\\", "");
            msg2 = msg2.Replace("\n", "");  //\n
            HSouceOrderList ordrlist = Newtonsoft.Json.JsonConvert.DeserializeObject<HSouceOrderList>(msg2);
           // List<HSouceOrderList> ordrlist = Newtonsoft.Json.JsonConvert.DeserializeObject<List<HSouceOrderList>>(msg2);
            List<HBarCodeList> ListRows = new List<HBarCodeList>();
            DataSet Ds;
            for (int i = 0; i < 1; i++)
            {
                HSourceBillType_Temp = ordrlist.HBillType;
                if (ClsPub.isLong(ordrlist.HMaterID) != 0)
                {
                    if (HSelectBarCodeType == "托盘条码")
                    {
                        //拆分每条物料记录为多条条码记录
                        double HSumQty = ClsPub.isDoule(ordrlist.HQty);                      //产品数量
                        double HQty = ClsPub.isDoule(ordrlist.HQty);                         //数量
                        double HMinQty = ClsPub.isDoule(ordrlist.HMinQty);                   //最小包装数
                        int HBQty = ClsPub.isInt(ordrlist.HBQty);                            //箱数
                        string WeiShu = "";                                                     //尾数
                        for (int j = 0; j < HBQty; j++)
                        {
                            string HBarCode_Temp = "";                                                  //条码
                            string sTMNumber = "";                                                      //条码前缀
                            string LSH = "";                                                            //最大流水号
                            int HLen = 6;                                                            //流水号长度
                            //条码拼接所需字段
                            string HMaterialName = DBUtility.ClsPub.isStrNull(ordrlist.HMaterName);
                            string HSupNumber = DBUtility.ClsPub.isStrNull(ordrlist.HSupNumber).Replace(".", "");             //供应商代码(去掉分隔符)
                            int lastDigit = int.Parse(DateTime.Today.Year.ToString().Last().ToString());
                            char productionMonth = DateTime.Today.Month <= 9
                            ? (char)(DateTime.Today.Month + '0')
                            : (char)('A' + DateTime.Today.Month - 10);
                            if (HMaterialName.Trim() == "")
                            {
                                objJsonResult.code = "0";
                                objJsonResult.count = 0;
                                objJsonResult.Message = "物料不能为空,不能生成条码!";
                                return objJsonResult;
                            }
                            //todo
                            //条码前缀 = p+商品SKU+生产年份+生产月份+6位流水号+生产工厂代码
                            sTMNumber = "P" + HMaterialName + lastDigit+ productionMonth;
                            //根据条码前缀获取最大流水号
                            Ds = oCN.RunProcReturn("exec h_p_WMS_GetMaxNo '" + sTMNumber + "'", "h_p_WMS_GetMaxNo");
                            LSH = String.Format("{0:D" + HLen + "}", ClsPub.isInt(Ds.Tables[0].Rows[0][0]) + 1);
                            //拼接条码
                            HBarCode_Temp = sTMNumber + LSH+"XXX";
                            if (HSumQty - HMinQty > 0)
                            {
                                WeiShu = "";
                                HSumQty = HSumQty - HMinQty;
                            }
                            else
                            {
                                if (HSumQty == HMinQty)
                                {
                                    WeiShu = "";
                                }
                                else
                                {
                                    WeiShu = "尾数";
                                }
                                HMinQty = HSumQty;
                            }
                            HBarCodeList barcode = new HBarCodeList();
                            barcode.HBarCode2 = HBarCode_Temp;
                            barcode.HBarCodeType2 = "托盘条码";
                            barcode.HBarCodeSubType2 = "托条码";
                            barcode.HEntryID2 = ClsPub.isStrNull(i + 1);
                            barcode.HMaterID2 = ordrlist.HMaterID;
                            barcode.HMaterNumber2 = ordrlist.HMaterNumber;
                            barcode.HMaterName2 = ordrlist.HMaterName;
                            barcode.HMaterModel2 = ordrlist.HMaterModel;
                            barcode.HPinfan2 = ordrlist.HPinfan;
                            barcode.HPinfanBarCode2 = ordrlist.HPinfanBarCode;
                            barcode.HAuxPropID2 = ordrlist.HAuxPropID;
                            barcode.HAuxPropNumber2 = ordrlist.HAuxPropNumber;
                            barcode.HAuxPropName2 = ordrlist.HAuxPropName;
                            barcode.HUnitID2 = ordrlist.HUnitID;
                            barcode.HUnitNumber2 = ordrlist.HUnitNumber;
                            barcode.HUnitName2 = ordrlist.HUnitName;
                            barcode.HQty2 = ClsPub.isStrNull(HMinQty);
                            barcode.HBatchNo2 = ordrlist.HBatchNo;
                            barcode.HSourceInterID2 = ordrlist.HMainID;
                            barcode.HSourceEntryID2 = ordrlist.HSubID;
                            barcode.HSourceBillNo2 = ordrlist.HBillNo;
                            barcode.HSourceBillType2 = ordrlist.HBillType;
                            barcode.HPrint = "0";
                            barcode.HWei = WeiShu;
                            barcode.HBarcodeNo = ClsPub.isStrNull(n + 1);
                            barcode.HBarcodeQtys = ordrlist.HBQty;
                            barcode.HSupID2 = ordrlist.HSupID;
                            barcode.HSupNumber2 = ordrlist.HSupNumber;
                            barcode.HSupName2 = ordrlist.HSupName;
                            barcode.HDeptID2 = ordrlist.HDeptID;
                            barcode.HDeptNumber2 = ordrlist.HDeptNumber;
                            barcode.HDeptName2 = ordrlist.HDeptName;
                            barcode.HRemark2 = ordrlist.HRemark;
                            barcode.HDate2 = ordrlist.HDate;
                            barcode.HShowDate2 = ordrlist.HShowDate;
                            barcode.HWhID2 = ordrlist.HWhID;
                            barcode.HWhNumber2 = ordrlist.HWhNumber;
                            barcode.HWhName2 = ordrlist.HWhName;
                            barcode.HSPID2 = ordrlist.HSPID;
                            barcode.HSPNumber2 = ordrlist.HSPNumber;
                            barcode.HSPName2 = ordrlist.HSPName;
                            barcode.HMTONo2 = ordrlist.HMTONo;
                            barcode.HCusID2 = ordrlist.HCusID;
                            barcode.HCusNumber2 = ordrlist.HCusNumber;
                            barcode.HCusName2 = ordrlist.HCusName;
                            barcode.HCusType2 = ordrlist.HCusType;
                            barcode.HSourceID2 = ordrlist.HSourceID;
                            barcode.HSourceNumber2 = ordrlist.HSourceNumber;
                            barcode.HSourceName2 = ordrlist.HSourceName;
                            barcode.HEndDate2 = ordrlist.HEndDate;
                            barcode.HSeOrderBillNo2 = ordrlist.HSeOrderBillNo;
                            barcode.HInnerBillNo2 = ordrlist.HInnerBillNo;
                            barcode.HMaker2 = ordrlist.HMaker;
                            barcode.HGiveAwayFlag2 = ordrlist.HGiveAwayFlag;
                            barcode.HCoilNO = ordrlist.HCoilNO;
                            barcode.HFurnaceNO = ordrlist.HFurnaceNO;
                            barcode.HFactory = ordrlist.HFactory;
                            barcode.HAuxQty = ordrlist.HAuxQty;
                            barcode.HheatNO = ordrlist.HheatNO;
                            barcode.HGroupID2 = ordrlist.HGroupID;
                            barcode.HEmpID2 = ordrlist.HEmpID;
                            barcode.HCusModel2 = ordrlist.HCusModel;
                            barcode.HCusMaterName2 = ordrlist.HCusMaterName;
                            barcode.HCheckEmpName2 = ordrlist.HCheckEmpName;
                            barcode.HZZRQ = ordrlist.HZZRQ;
                            ListRows.Add(barcode);
                            n += 1;                                                             //更新同批生成的条码数
                            oCN.RunProc("exec h_p_WMS_SetMaxNo '" + sTMNumber + "'");           //更新最大流水号
                        }
                    }
                    else
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "错误的条码类型,不能生成条码!";
                        return objJsonResult;
                    }
                }
            }
            try
            {
                oCN.BeginTran();
                for (int i = 0; i < ListRows.Count; i++)
                {
                    if (ClsPub.isLong(ListRows[i].HMaterID2) != 0)
                    {
                        string HBarCode = ClsPub.isStrNull(ListRows[i].HBarCode2);
                        string HBarCodeType = ClsPub.isStrNull(ListRows[i].HBarCodeType2);
                        string HBarCodeSubType = ClsPub.isStrNull(ListRows[i].HBarCodeSubType2);
                        Int64 HMaterID = ClsPub.isLong(ListRows[i].HMaterID2);
                        Int64 HEntryID = ClsPub.isLong(ListRows[i].HEntryID2);
                        Int64 HAuxPropID = ClsPub.isLong(ListRows[i].HAuxPropID2);
                        Int64 HUnitID = ClsPub.isLong(ListRows[i].HUnitID2);
                        double HQty2 = ClsPub.isDoule(ListRows[i].HQty2);
                        string HWei = ClsPub.isStrNull(ListRows[i].HWei);
                        string HBatchNo2 = ClsPub.isStrNull(ListRows[i].HBatchNo2);
                        Int64 HSourceInterID = ClsPub.isLong(ListRows[i].HSourceInterID2);
                        Int64 HSourceEntryID = ClsPub.isLong(ListRows[i].HSourceEntryID2);
                        string HSourceBillNo = ClsPub.isStrNull(ListRows[i].HSourceBillNo2);
                        string HSourceBillType = ClsPub.isStrNull(ListRows[i].HSourceBillType2);
                        Int64 HBarcodeQtys = ClsPub.isLong(ListRows[i].HBarcodeQtys);
                        Int64 HBarcodeNo = ClsPub.isLong(ListRows[i].HBarcodeNo);
                        Int64 HSupID = ClsPub.isLong(ListRows[i].HSupID2);
                        Int64 HDeptID = ClsPub.isLong(ListRows[i].HDeptID2);
                        Int64 HWhID = ClsPub.isLong(ListRows[i].HWhID2);
                        Int64 HSPID = ClsPub.isLong(ListRows[i].HSPID2);
                        string HRemark = ClsPub.isStrNull(ListRows[i].HRemark2);
                        string HMaterName = ClsPub.isStrNull(ListRows[i].HMaterName2);
                        string HMaterModel = ClsPub.isStrNull(ListRows[i].HMaterModel2);
                        string HPinfan = ClsPub.isStrNull(ListRows[i].HPinfan2);
                        string HMTONo = ClsPub.isStrNull(ListRows[i].HMTONo2);
                        Int64 HCusID = ClsPub.isLong(ListRows[i].HCusID2);
                        string HCusType = ClsPub.isStrNull(ListRows[i].HCusType2);
                        DateTime HEndDate = ClsPub.isDate(ListRows[i].HEndDate2);
                        string HWorkLineName = ClsPub.isStrNull(ListRows[i].HSourceName2);
                        string HSeOrderBillNo = ClsPub.isStrNull(ListRows[i].HSeOrderBillNo2);
                        string HInnerBillNo = ClsPub.isStrNull(ListRows[i].HInnerBillNo2);
                        bool HGiveAwayFlag = ClsPub.isBool(ListRows[i].HGiveAwayFlag2);
                        int HPrintQty = ClsPub.isInt(ListRows[i].HPrint);
                        string HCoilNO2 = ClsPub.isStrNull(ListRows[i].HCoilNO);
                        string HFurnaceNO2 = ClsPub.isStrNull(ListRows[i].HFurnaceNO);
                        string HFactory2 = ClsPub.isStrNull(ListRows[i].HFactory);
                        Int64 HAuxQty2 = ClsPub.isLong(ListRows[i].HAuxQty);
                        string HheatNO2 = ClsPub.isStrNull(ListRows[i].HheatNO);
                        DateTime HProduceDate = ClsPub.isDate(ListRows[i].HProduceDate);
                        DateTime HExpiryDate = ClsPub.isDate(ListRows[i].HExpiryDate);
                        int HGroupID2 = ClsPub.isInt(ListRows[i].HGroupID2);
                        Int64 HEmpID2 = ClsPub.isLong(ListRows[i].HEmpID2);
                        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 " +
                                    ",HBarcodeQtys,HBarcodeNo,HDeptID,HWhID,HSPID,HRemark " +
                                    ",HCusID,HCusType,HEndDate,HWorkLineName,HBarCodeDate " +
                                    ",HSTOCKORGID,HOWNERID,HSeOrderBillNo,HInterID,HEntryID " +
                                    ",HGiveAwayFlag " +
                                    ",HMaterName,HMaterModel,HPinfan,HAuxPropID,HMTONo,HInnerBillNo" +
                                    ",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()
                                    + ", " + HSourceInterID.ToString() + "," + HSourceEntryID.ToString() + ",'" + HSourceBillNo + "','" + HSourceBillType + "','" + HWei + "'"
                                    + ", " + HBarcodeQtys.ToString() + "," + HBarcodeNo.ToString() + "," + HDeptID.ToString() + "," + HWhID.ToString() + "," + HSPID.ToString() + ",'" + HRemark + "'"
                                    + ", " + HCusID.ToString() + ",'" + HCusType + "','" + HEndDate.ToShortDateString() + "','" + HWorkLineName + "','" + sDate + "'"
                                    + ", " + 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 + "','" + 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
                //获取生成的条码信息
                string sql = string.Format(@"select * from h_v_IF_BarCodeBillList Where HinterID=" + HInterID.ToString() + " order by HItemID");
                ds = new SQLHelper.ClsCN().RunProcReturn(sql, "h_v_IF_ICMOBillList_Table");
                if (ds.Tables[0].Rows.Count > 0)
                {
                    objJsonResult.code = "1";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "[0000-1-037]获取资源绑定数据成功!";
                    objJsonResult.data = JsonConvert.DeserializeObject<DataTable>(JsonConvert.SerializeObject(ds.Tables[0], new IsoDateTimeConverter { DateTimeFormat = "yyyy-MM-dd HH:mm:ss" }));  //序列化DataSet中的时间格式,然后再反序列化回来
                    objJsonResult.list = listobj;
                    return objJsonResult;
                }
                else
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "[0000-2-020]没有返回任何结果,条码不存在!";
                    objJsonResult.data = null;
                    objJsonResult.list = listobj;
                    return objJsonResult;
                }
            }
            catch (Exception e)
            {
                oCN.RollBack();
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "[3899-2-006]条码生成失败!" + e.Message;
                return objJsonResult;
            }
        }
        #endregion
        #endregion
    }
}