王 垚
2022-11-28 e4674196f18a1bec1d92ce63a50addbca001c9b4
WebAPI/Controllers/Éú²ú¹ÜÀí/Éú²úÈÎÎñµ¥/Sc_ICMOBillController.cs
@@ -224,6 +224,207 @@
        }
        #endregion
        #region ç”Ÿäº§ä»»åŠ¡å•(无列表) ä¿å­˜/编辑功能
        [Route("Sc_ICMOBill/ICMOBillEdit_NoTable")]
        [HttpPost]
        public object ICMOBillEdit_NoTable([FromBody] JObject sMainSub)
        {
            try
            {
                var _value = sMainSub["sMainSub"].ToString();
                string msg1 = _value.ToString();
                oCN.BeginTran();
                //保存主表
                objJsonResult = AddBillMain_NoTable(msg1);
                if (objJsonResult.code == "0")
                {
                    oCN.RollBack();
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = objJsonResult.Message;
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                oCN.Commit();
                objJsonResult.code = "1";
                objJsonResult.count = 1;
                objJsonResult.Message = "单据保存成功!";
                objJsonResult.data = null;
                return objJsonResult;
            }
            catch (Exception e)
            {
                oCN.RollBack();
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "保存失败!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        public json AddBillMain_NoTable(string msg1)
        {
            string[] sArray = msg1.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
            string msg2 = sArray[0].ToString(); //主表数据
            int OperationType = int.Parse(sArray[1].ToString()); // æ•°æ®ç±»åž‹ 1添加 3修改
            string user = sArray[2].ToString();
            try
            {
                if (!DBUtility.ClsPub.Security_Log("Sc_ICMOBill_Edit", 1, false, user))
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "无保存权限!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                var msg3 = msg2.ToString();
                msg2 = "[" + msg2.ToString() + "]";
                List<ClsSc_ICMOBillMain> mainList = Newtonsoft.Json.JsonConvert.DeserializeObject<List<ClsSc_ICMOBillMain>>(msg2);
                long HInterID = mainList[0].HInterID;//递入type得到的单据ID
                string HBillNo = mainList[0].HBillNo;//递入type得到的单据号
                long HPRDORGID = mainList[0].HPRDORGID;//组织
                DateTime HDate = mainList[0].HDate;//日期
                string HRemark = mainList[0].HRemark;//备注
                string HSeOrderBillNo = mainList[0].HSeOrderBillNo;//销售订单号
                long HSeOrderInterID = mainList[0].HSeOrderInterID;//销售订主id
                long HSeOrderEntryID = mainList[0].HSeOrderEntryID;//销售订子id
                long HEmpID = mainList[0].HEmpID;//业务员
                long HCusID = mainList[0].HCusID;//客户
                long HCenterID = mainList[0].HCenterID;//工作中心
                long HBomID = mainList[0].HBomID;//bom
                //double? HPlanQty = mainList[0].HPlanQty == null ? 0 : mainList[0].HPlanQty;//计划数量
                string HMaker = user;//制单人
                ds = oCN.RunProcReturn("select * from h_v_IF_ICMOBillList where hmainid=" + HInterID + " and å•据号='" + HBillNo + "'", "h_v_IF_ICMOBillList");
                if ((OperationType == 1 || OperationType == 2) && ds.Tables[0].Rows.Count == 0)//新增
                {
                    //主表
                    oCN.RunProc(@"Insert Into Sc_ICMOBillMain
                        (HBillType,HInterID,HBillNo,HDate,HPRDORGID
                        ,HYear,HPeriod,HRemark,HMaker,HMakeDate
                        ,HSeOrderBillNo,HSeOrderInterID,HSeOrderEntryID,HEmpID,HCusID
                        ,HCenterID,HPlanQty,HDeptID,HMaterID,HUnitID,HBomID,HPlanBeginDate,HPlanEndDate)
                        values('3710'," + HInterID + ",'" + HBillNo + "','" + HDate + "'," + HPRDORGID +
                    "," + DateTime.Now.Year + "," + DateTime.Now.Month + ",'" + HRemark + "','" + HMaker + "',getdate()" +
                    ",'" + HSeOrderBillNo + "'," + HSeOrderInterID + "," + HSeOrderEntryID + "," + HEmpID + "," + HCusID +
                    "," + HCenterID + ",0,0,0,0,"+ HBomID + ",'','') ");
                }
                else if (OperationType == 3 || ds.Tables[0].Rows.Count != 0)
                { //修改
                    oCN.RunProc("update Sc_ICMOBillMain  set " +
                                "HRemark='" + HRemark + "', HChecker='" + HMaker + "', HCheckDate=getdate()" +
                                ", HSeOrderBillNo='" + HSeOrderBillNo + "', HSeOrderInterID=" + HSeOrderInterID + ", HSeOrderEntryID=" + HSeOrderEntryID + ", HEmpID=" + HEmpID + ", HCusID=" + HCusID + "" +
                                ", HCenterID=" + HCenterID + ",HBomID="+ HBomID + " where HInterID=" + HInterID);
                    //删除子表
                    oCN.RunProc("delete from Sc_ICMOBillSub where HInterID='" + HInterID + "'");
                }
                //保存子表
                objJsonResult = AddBillSub_NoTable(msg3, HInterID, OperationType);
                if (objJsonResult.code == "0")
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = objJsonResult.Message;
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                objJsonResult.code = "1";
                objJsonResult.count = 1;
                objJsonResult.Message = null;
                objJsonResult.data = null;
                return objJsonResult;
            }
            catch (Exception e)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "Exception!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        public json AddBillSub_NoTable(string msg3, long HInterID, int OperationType)
        {
            ClsSc_ICMOBillSub oSub = Newtonsoft.Json.JsonConvert.DeserializeObject<ClsSc_ICMOBillSub>(msg3);
            if (oSub.HQty <= 0 || oSub.HQty == null)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "数量不能为0或者小于0";
                objJsonResult.data = null;
                return objJsonResult;
            }
            if (oSub.HMaterID == 0)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "物料不能为空";
                objJsonResult.data = null;
                return objJsonResult;
            }
            if (oSub.HDeptID == 0)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "生产车间不能为空";
                objJsonResult.data = null;
                return objJsonResult;
            }
            if (oSub.HUnitID == 0)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "计量单位不能为空";
                objJsonResult.data = null;
                return objJsonResult;
            }
            if (oSub.HBomID == 0)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "BOM不能为空";
                objJsonResult.data = null;
                return objJsonResult;
            }
            oCN.RunProc($@"Insert into Sc_ICMOBillSub
                (HInterID,HENTRYID,HQty
                ,HPlanBeginDate,HPlanEndDate
               ,HBeginDate,HEndDate
                ,HMaterID,HUnitID,HRemark,HSourceID,HDeptID,HSTATUS
                ,HBomID,HEntryCusID
            ,HSourceInterID,HSourceEntryID,HSourceBillNo,HSourceBillType,HRelationQty,HRelationMoney)
                 values({HInterID},1,{(oSub.HQty == null ? 0 : oSub.HQty)}
                ,'{(oSub.HPlanBeginDate == null ? DateTime.Now.ToString("yyyy-MM-dd") : oSub.HPlanBeginDate.ToString())}','{(oSub.HPlanEndDate == null ? DateTime.Now.AddDays(1).ToString("yyyy-MM-dd") : oSub.HPlanEndDate.ToString())}'
                ,'{(oSub.HBeginDate == null ? DateTime.Now.ToString("yyyy-MM-dd") : oSub.HBeginDate.ToString())}','{(oSub.HEndDate == null ? DateTime.Now.AddDays(1).ToString("yyyy-MM-dd") : oSub.HEndDate.ToString())}'
                ,{oSub.HMaterID},{oSub.HUnitID},'{oSub.HRemark}',{oSub.HSourceID},{oSub.HDeptID},{oSub.HSTATUS}
                 ,{oSub.HBomID}  ,{oSub.HCusID}
                       ,0,0,'','',0,0)");
            objJsonResult.code = "1";
            objJsonResult.count = 1;
            objJsonResult.Message = null;
            objJsonResult.data = null;
            return objJsonResult;
        }
        #endregion
        #region ç”Ÿäº§ä»»åŠ¡å•åˆ é™¤åŠŸèƒ½
        [Route("Sc_ICMOBill/DeltetSc_ICMOReportBill")]
        [HttpGet]