wyb
2021-05-07 6bb8899afd83cab8cbe03c77a68cdc82e7d495cd
WebAPI/Controllers/Sc_ProcessMangementController.cs
@@ -1602,5 +1602,153 @@
        }
        /// <summary>
        /// 保存委外汇报单信息
        /// </summary>
        /// <param name="msg"></param>
        /// <returns></returns>
        [Route("SaveWW_EntrustProcessReportBill")]
        [HttpPost]
        public object SaveWW_EntrustProcessReportBill([FromBody] JObject msg)
        {
            var _value = msg["msg"].ToString();
            string msg1 = _value.ToString();
            string[] sArray = msg1.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
            string msg2 = sArray[0].ToString();
            string msg3 = sArray[1].ToString();
            string UserName = "";
            ListModels oListModels = new ListModels();
            try
            {
                WebAPI.DLL.ClsWW_EntrustProcessReportBill Sendwork = new WebAPI.DLL.ClsWW_EntrustProcessReportBill();
                List<WebAPI.Models.ClsWW_EntrustProcessReportBillMain> lsmain = new List<WebAPI.Models.ClsWW_EntrustProcessReportBillMain>();
                msg2 = msg2.Replace("\\", "");
                msg2 = msg2.Replace("\n", "");
                lsmain = oListModels.getObjectByJson_WW_EntrustProcessReportBillMain(msg2);
                foreach (WebAPI.Models.ClsWW_EntrustProcessReportBillMain oItem in lsmain)
                {
                    UserName = oItem.HMaker;
                    oItem.HMakeDate = DBUtility.ClsPub.isStrNull(DateTime.Now.ToString("yyyy-MM-dd"));
                    oItem.HYear = DBUtility.ClsPub.isLong(DateTime.Now.Year);
                    oItem.HDate = DateTime.Now;
                    oItem.HMainSourceInterID = oItem.HInterID;
                    oItem.HInterID = 0;
                    Sendwork.omodel = oItem;
                }
                //表体数据
                //按 },{来拆分数组 //去掉【和】
                msg3 = msg3.Substring(1, msg3.Length - 2);
                msg3 = msg3.Replace("\\", "");
                msg3 = msg3.Replace("\n", "");  //\n
                List<WebAPI.Models.WW_EntrustProcSendWorkViewModel> ls = new List<WebAPI.Models.WW_EntrustProcSendWorkViewModel>();
                ls = oListModels.getObjectByJson_WW_EntrustProcSendWork(msg3);
                int i = 0;
                List<Models.ClsWW_EntrustProcessReportBillSub> lss = new List<Models.ClsWW_EntrustProcessReportBillSub>();
                foreach (WebAPI.Models.WW_EntrustProcSendWorkViewModel oItemSub in ls)
                {
                    i++;
                    Models.ClsWW_EntrustProcessReportBillSub sendworksub = new Models.ClsWW_EntrustProcessReportBillSub();
                    sendworksub.HProcID = 0;//--工序ID
                    sendworksub.HSourceInterID = (long)oItemSub.hmainid;//源单id
                    sendworksub.HSourceEntryID = (long)oItemSub.hsubid; //--源单子ID
                    sendworksub.HSourceBillNo = oItemSub.单据号; //--源单单号
                    sendworksub.HSourceBillType = oItemSub.HBillType; //--源单类型
                    sendworksub.HQty = (decimal)oItemSub.数量; //--数量
                    sendworksub.HICMOBillNo = "";  //--任务单号
                    sendworksub.HSeOrderBillNo = ""; //--销售订单号
                    sendworksub.HSeOrderEntryID = 0; //--销售子ID
                    sendworksub.HSeOrderInterID = 0; //--销售订单主ID
                    sendworksub.HTimes = 0; //--计划工时
                    if (oItemSub.数量 <= 0)
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "保存失败!第" + i.ToString() + "行数量不大于0无法保存!";
                        objJsonResult.data = 1;
                        return objJsonResult;
                    }
                    if (Convert.ToInt32(sendworksub.HQty) > Convert.ToInt32(oItemSub.数量))
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "保存失败!第" + i.ToString() + "行委外汇报数量不能大于委外派工单数量!";
                        objJsonResult.data = 1;
                        return objJsonResult;
                    }
                    sendworksub.HEntryID = i;
                    sendworksub.HEntryCloseDate = DBUtility.ClsPub.isDate(DateTime.Now);
                    sendworksub.HRemark = "";
                    sendworksub.HCloseMan = "";
                    sendworksub.HCloseType = false;
                    lss.Add(sendworksub);//先把数据存放到派工单子表集合里
                }
                if (lss.Count > 0)
                {
                    //然后再循环保存到派工单子表的集合里
                    foreach (Models.ClsWW_EntrustProcessReportBillSub Itemsendwork in lss)
                    {
                        Sendwork.DetailColl.Add(Itemsendwork);
                    }
                }
                else
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "保存失败!lss集合小于0";
                    objJsonResult.data = 1;
                    return objJsonResult;
                }
                //保存
                //保存完毕后处理
                bool bResult;
                if (Sendwork.omodel.HInterID == 0)
                {
                    // bResult = oBill.AddBill(ref DBUtility.ClsPub.sExeReturnInfo);
                    bResult = Sendwork.AddBill(ref DBUtility.ClsPub.sExeReturnInfo);
                }
                else
                {
                    bResult = Sendwork.ModifyBill(Sendwork.omodel.HInterID, ref DBUtility.ClsPub.sExeReturnInfo);
                }
                if (bResult)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "保存成功!";
                    //WebAPIController.Add_Log("送货单下推", UserName, "生成送货单");
                    objJsonResult.data = 1;
                    return objJsonResult;
                }
                else
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "保存失败!" + DBUtility.ClsPub.sExeReturnInfo;
                    objJsonResult.data = 1;
                    return objJsonResult;
                }
            }
            catch (Exception e)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "保存失败!" + e.ToString();
                objJsonResult.data = 1;
                return objJsonResult;
            }
        }
    }
}