duhe
2025-04-15 d03c33eeebd11111ee6c116b35ccf8cd7372de8d
WebAPI/Controllers/SCGL/Sc_PPBomBillController.cs
@@ -91,6 +91,50 @@
            }
        }
        [Route("Sc_PPBomBill/Editlist")]
        [HttpGet]
        public object Editlist(string sWhere)
        {
            try
            {
                List<object> a = new List<object>();
                //判断是否有查询权限
                if (sWhere == null || sWhere.Equals(""))
                {
                    ds = oCN.RunProcReturn("select * from h_v_IF_PPBomBillList order by hmainid desc ", "h_v_IF_PPBomBillList");
                }
                else
                {
                    string sql1 = "select * from h_v_IF_PPBomBillList where 1 = 1 ";
                    string sql = sql1 + sWhere + " order by hmainid desc ";
                    ds = oCN.RunProcReturn(sql, "h_v_IF_PPBomBillList");
                }
                foreach (DataColumn col in ds.Tables[0].Columns)//遍历ds中第一个表(Tables[0])的所有列(Columns)每次循环中,col变量会持有当前列的引用
                {
                    Type dataType = col.DataType; //获取当前数据类型传入 自定义变量datadataType
                    string ColmString = "{\"ColmCols\":\"" + col.ColumnName + "\",\"ColmType\":\"" + dataType.Name + "\"}"; //字符串拼接         // 将列名和数据类型信息拼接成一个JSON格式的字符串
                    a.Add(JsonConvert.DeserializeObject(ColmString));//获取到DataColumn列对象的列名
                }
                objJsonResult.code = "1";
                objJsonResult.count = 1;
                objJsonResult.Message = "Sucess!";
                objJsonResult.data = ds.Tables[0];
                objJsonResult.list = a;
                return objJsonResult;
            }
            catch (Exception e)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "Exception!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #region 生产用料清单列表分页列表
        [Route("Sc_PPBomBill/page")]
@@ -304,6 +348,216 @@
        }
        #endregion
        #region 生产用料单 保存/编辑功能 新方法
        [Route("Sc_PPBomBill/sc_PPBomBillAdd")]
        [HttpPost]
        public object sc_PPBomBillAdd([FromBody] JObject sMainSub)
        {
            var _value = sMainSub["sMainSub"].ToString();
            string msg1 = _value.ToString();
            string[] sArray = msg1.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
            try
            {
                string msg2 = sArray[0].ToString(); //主表数据
                string msg3 = sArray[1].ToString(); //子表数据
                int OperationType = int.Parse(sArray[2].ToString()); // 数据类型 1添加 3修改
                string user = sArray[3].ToString();
                //判断是否有编辑权限
                if (!DBUtility.ClsPub.Security_Log("QC_TestSampleCheckBill_Edit", 1, false, user))
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "无编辑权限!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                ClsSc_PPBomBillMain list = Newtonsoft.Json.JsonConvert.DeserializeObject<ClsSc_PPBomBillMain>(msg2);
                string BillType = "3720";
                string HBillSubType = "3720";
                long HInterID = list.HInterID;//递入type得到的单据ID
                string HBillNo = list.HBillNo;//递入type得到的单据号
                int HBillStatus = 1;
                string HMaker = user;//制单人
                int HYear = DateTime.Now.Year;
                double HPeriod = DateTime.Now.Month;
                long HICMOInterID = list.HICMOInterID;//任务单ID
                long HICMOEntryID = list.HICMOEntryID;//任务单ID
                string HICMOBillNo = list.HICMOBillNo;//任务单ID
                long HMaterID = list.HMaterID;//产品ID
                long HUnitID = list.HUnitID;//计量单位
                long HPRDORGID = list.HPRDORGID;//组织ID
                long HICMOEntrySEQ = list.HICMOEntrySEQ;
                DateTime HDate = list.HDate;
                double HQty = list.HQty;
                long HDeptID = list.HDeptID;
                string HRemark = list.HRemark;
                string HChecker = "";
                string HCheckDate = "";
                string HSeOrderBillNo = "";
                long HSeOrderInterID = 0;
                long HSeOrderEntryID = 0;
                long HENTRUSTORGID = 0;
                long HPARENTOWNERID = 0;
                long HPARENTOWNERTYPEID = 0;
                long HERPInterID = 0;
                long HSeOrderEntrySEQ = 0;
                string HERPBillType = "";
                string HREQSRC = "";
                oCN.BeginTran();
                if (OperationType== 1)
                {
                    ds = oCN.RunProcReturn("select * from Sc_PPBomBillMain where HBillNo='" + HBillNo + "'", "Sc_PPBomBillMain");
                    if (ds.Tables[0].Rows.Count == 1)
                    {
                        oCN.RollBack();
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "单据号重复!";
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                    //主表
                    oCN.RunProc(@"Insert Into Sc_PPBomBillMain
                        (HInterID,HYear,HPeriod,HBillType,HBillSubType,HDate,HBillNo,HBillStatus,HICMOInterID
                        ,HICMOEntryID,HMaterID,HUnitID,HQty,HDeptID,HMaker,HMakeDate,HChecker,HCheckDate
                        ,HSeOrderBillNo,HSeOrderInterID,HSeOrderEntryID,HPRDORGID,HENTRUSTORGID,HPARENTOWNERID
                        ,HPARENTOWNERTYPEID,HERPInterID,HERPBillType,HSeOrderEntrySEQ,HICMOEntrySEQ,HREQSRC,HRemark)
                        values(" + HInterID + "," + DateTime.Now.Year + "," + DateTime.Now.Month + ",'" + BillType + "','" +
                    HBillSubType + "','" + HDate + "','" + HBillNo + "','" + HBillStatus + "'," + HICMOInterID +
                    "," + HICMOEntryID + ",'" + HMaterID + "'," + HUnitID + "," + HQty + "," + HDeptID +
                    ",'" + HMaker + "',getdate(),'" + HChecker + "','" + HCheckDate + "','" + HSeOrderBillNo + "'," + HSeOrderInterID + "," + HSeOrderEntryID + "," + HPRDORGID + "," + HENTRUSTORGID + "," + HPARENTOWNERID + "," +
                    HPARENTOWNERTYPEID + "," + HERPInterID + ",'" + HERPBillType + "'," + HSeOrderEntrySEQ + "," + HICMOEntrySEQ + ",'" + HREQSRC + "','"+ HRemark + "')");
                }
                else  if (OperationType == 3 )
                { //修改
                    oCN.RunProc("update Sc_PPBomBillMain  set " +
                                "HRemark='" + HRemark + "', HChecker='" + HMaker + "', HCheckDate=getdate()" +
                                ",HDeptID=" + HDeptID + ",HICMOInterID=" + HICMOInterID + ",HICMOEntryID=" + HICMOEntryID + ",HMaterID=" + HMaterID + ",HUnitID=" + HUnitID + ",HICMOEntrySEQ=" + HICMOEntrySEQ + " ,HQty=" + HQty + " where HInterID=" + HInterID);
                    //删除子表
                    oCN.RunProc("delete from Sc_PPBomBillSub where HInterID='" + HInterID + "'");
                }
                else
                {
                    oCN.RollBack();
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "操作类型无效!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                List<ClsSc_PPBomBillSub> DetailColl = Newtonsoft.Json.JsonConvert.DeserializeObject<List<ClsSc_PPBomBillSub>>(msg3);
                int i = 0;
                foreach (ClsSc_PPBomBillSub oSub in DetailColl)
                {
                    i++;
                    string HMaterNumber = oSub.HMaterNumber;
                    string HUnitNumber = oSub.HUnitNumber;
                    long HQtyMust = 0;
                    long HSourceInterID = oSub.HSourceInterID;
                    long HSourceEntryID = oSub.HSourceEntryID;
                    long HCHILDSUPPLYORGID = oSub.HCHILDSUPPLYORGID;
                    long HSUPPLYORGID = oSub.HSUPPLYORGID;
                    long HENTRUSTPICKORGID = oSub.HENTRUSTPICKORGID;
                    long HSRCTRANSORGID = oSub.HSRCTRANSORGID;
                    long HGROUPBYOWNERID = oSub.HGROUPBYOWNERID;
                    long HOWNERID = oSub.HOWNERID;
                    long HAuxPropID = oSub.HAuxPropID;
                    long HERPEntryID = oSub.HERPEntryID;
                    long HProcessID = oSub.HProcessID;
                    long HICMOENTRYSEQ = oSub.HICMOENTRYSEQ;
                    long HOPERID = oSub.HOPERID;
                    long HSEQ = i;
                    long HSTOCKSTATUSID = oSub.HSTOCKSTATUSID;
                    long HOPTQUEUE = oSub.HOPTQUEUE;
                    long HLOT = oSub.HLOT;
                    long HRESERVETYPE = oSub.HRESERVETYPE;
                    string HOWNERTYPEID = oSub.HOWNERTYPEID;
                    double HRelationQty = oSub.HRelationQty;
                    double HMoveStockQty = oSub.HMoveStockQty;
                    double HQtyScrap = oSub.HQtyScrap;
                    double HBackRelationQty = oSub.HBackRelationQty;
                    double HNumerator = oSub.HNumerator;
                    double HDenominator = oSub.HDenominator;
                    double HSelPickedQty = oSub.HSelPickedQty;
                    double HSELPRCDRETURNQTY = oSub.HSELPRCDRETURNQTY;
                    string HSourceBillNo = oSub.HSourceBillNo;
                    string HSourceBillType = oSub.HSourceBillType;
                    string HBatchNO = oSub.HBatchNO;
                    string HMTONo = oSub.HMTONo;
                    string HPROJECTNO = oSub.HPROJECTNO;
                    if (oSub.HQty <= 0 || oSub.HQty == null)
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "第" + i + "行,数量不能为0或者小于0";
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                    if (oSub.HMaterID == 0)
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "第" + i + "行,物料不能为空";
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                    if (oSub.HUnitID == 0)
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "第" + i + "行,计量单位不能为空";
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                    Int64 NewHEntryID = i;
                    oCN.RunProc($@"Insert into Sc_PPBomBillSub
                (HInterID,HEntryID,HMaterID,HMaterNumber,HUnitID,HUnitNumber,HSPID,HQty,HQtyMust,HWHID,HRemark
               ,HSourceInterID,HSourceEntryID,HSourceBillNo,HSourceBillType,HICMOInterID,HICMOEntryID,HICMOBillNo
               ,HCHILDSUPPLYORGID,HSUPPLYORGID,HENTRUSTPICKORGID,HSRCTRANSORGID,HGROUPBYOWNERID,HOWNERID,HOWNERTYPEID
               ,HRelationQty,HMoveStockQty,HAuxPropID,HBatchNO,HMTONo,HQtyScrap,HERPInterID,HERPEntryID
               ,HBackRelationQty,HNumerator,HDenominator,HBASEUNITID,HProcessID,HICMOENTRYSEQ,HPROJECTNO
                ,HOPERID,HSEQ,HSTOCKSTATUSID,HLOT,HOPTQUEUE,HRESERVETYPE,HSelPickedQty,HSELPRCDRETURNQTY)
                 values({HInterID},{NewHEntryID},{oSub.HMaterID},'{HMaterNumber}',{oSub.HUnitID},'{HUnitNumber}',{oSub.HSPID},{(oSub.HQty == null ? 0 : oSub.HQty)}
                ,{HQtyMust},{oSub.HWHID},'{oSub.HRemark}',{HSourceInterID},{HSourceEntryID},'{HSourceBillNo}','{HSourceBillType}',{HICMOInterID},{HICMOEntryID},'{HICMOBillNo}',{HCHILDSUPPLYORGID},{HSUPPLYORGID},{HENTRUSTPICKORGID},{HSRCTRANSORGID},{HGROUPBYOWNERID},{HOWNERID},'{HOWNERTYPEID}',{HRelationQty},{HMoveStockQty},{HAuxPropID},'{HBatchNO}','{HMTONo}',{HQtyScrap},{HERPInterID},
                  {HERPEntryID},{HBackRelationQty},{HNumerator},{HDenominator},{oSub.HBASEUNITID},{HProcessID},{HICMOENTRYSEQ},'{HPROJECTNO}',{HOPERID},{HSEQ},{HSTOCKSTATUSID},{HLOT},{HOPTQUEUE},{HRESERVETYPE},{HSelPickedQty},{HSELPRCDRETURNQTY})");
                }
                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 = "Exception!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
        #region 生产用料单 保存/编辑功能
        [Route("Sc_PPBomBill/PPBomBillEdit")]
        [HttpPost]