zrg
2024-10-09 243e86af1a7c74c8bfda3bb41f29a11fef13c065
WebAPI/DLL/ClsSc_MESBeginWorkBill.cs
@@ -9,12 +9,13 @@
    {
        public Models.ClsSc_MESBeginWorkBillMain omodel = new Models.ClsSc_MESBeginWorkBillMain();
        public List<Models.ClsSc_MESBeginWorkBillSub> DetailColl = new List<Models.ClsSc_MESBeginWorkBillSub>();
        public List<Models.ClsSc_MESBeginWorkBillSub_RelationBill> DetailCol2 = new List<Models.ClsSc_MESBeginWorkBillSub_RelationBill>();
        //public List<Model.ClsSc_MESBeginWorkBillSub_Item> DetailColl1 = new List<Model.ClsSc_MESBeginWorkBillSub_Item>();
        public ClsSc_MESBeginWorkBill()
        {
            base.MvarItemKeySub = "Sc_MESBeginWorkBillSub";
            base.MvarItemKeySub2 = "";
            base.MvarItemKeySub2 = "Sc_MESBeginWorkBillSub_RelationBill";
            base.MvarItemKeySub3 = "";
            base.MvarItemKeySub4 = "";
            base.MvarItemKey="Sc_MESBeginWorkBillMain";
@@ -30,15 +31,75 @@
        {
            DetailColl = null;
        }
        #endregion   自定义方法
        //保存前控制
        public bool BeforeSave(Int64 HInterID, Int64 HICMOInterID, Int64 HICMOEntryID, string HICMOBillNo, Int64 OperationType, ref string sReturn)
        {
            try
            {
                DataSet Ds = oCn.RunProcReturn("Exec h_p_Sc_MESBeginWorkBill_BeforeSaveCtrl " + HInterID.ToString() + "," + HICMOInterID.ToString() + "," + HICMOEntryID.ToString() + ",'" + HICMOBillNo + "'," + OperationType.ToString(), "h_p_Sc_MESBeginWorkBill_BeforeSaveCtrl");
                if (Ds == null || Ds.Tables[0].Rows.Count == 0)
                {
                    sReturn = "保存前判断失败!";
                    return false;
                }
                else
                {
                    if (DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["HBack"]) == 1)
                    {
                        sReturn = DBUtility.ClsPub.isStrNull(Ds.Tables[0].Rows[0]["HRemark"]);
                        return false;
                    }
                }
                return true;
            }
            catch (Exception e)
            {
                throw (e);
            }
        }
        //保存后控制
        public bool AfterSave(Int64 HInterID, Int64 HICMOInterID, Int64 HICMOEntryID, string HICMOBillNo, Int64 OperationType, ref string sReturn)
        {
            try
            {
                DataSet Ds = oCn.RunProcReturn("Exec h_p_Sc_MESBeginWorkBill_AfterSaveCtrl " + HInterID.ToString() + "," + HICMOInterID.ToString() + "," + HICMOEntryID.ToString() + ",'" + HICMOBillNo + "'," + OperationType.ToString(), "h_p_Sc_MESBeginWorkBill_AfterSaveCtrl");
                if (Ds == null || Ds.Tables[0].Rows.Count == 0)
                {
                    sReturn = "保存后判断失败!";
                    return false;
                }
                else
                {
                    if (DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["HBack"]) == 1)
                    {
                        sReturn = DBUtility.ClsPub.isStrNull(Ds.Tables[0].Rows[0]["HRemark"]);
                        return false;
                    }
                }
                return true;
            }
            catch (Exception e)
            {
                throw (e);
            }
        }
        //修改单据
        public override bool ModifyBill(Int64 lngBillKey, ref string sReturn)
        {
            try
            {
                //
                oCn.BeginTran();
                //保存前控制
                if (!BeforeSave(lngBillKey, omodel.HICMOInterID, omodel.HICMOEntryID, omodel.HICMOBillNo, 2, ref sReturn))
                {
                    oCn.RollBack();
                    return false;
                }
                //更新主表
                oCn.RunProc("UpDate Sc_MESBeginWorkBillMain set  " +
                " HBillNo='" + omodel.HBillNo + "'" +  //固定赋值===============
@@ -92,8 +153,41 @@
                DeleteRelation(ref sReturn, lngBillKey);
                //删除子表
                DeleteBillSub(lngBillKey);
                DeleteBillSub2(lngBillKey);
                //插入子表
                omodel.HInterID = lngBillKey;
                //插入子表_副产计划
                foreach (Models.ClsSc_MESBeginWorkBillSub_RelationBill oSub in DetailCol2)
                {
                    string subSql = "insert into Sc_MESBeginWorkBillSub_RelationBill " +
                        "(HInterID, HEntryID,HBillNo_bak, HSourceInterID, HSourceEntryID, HSourceBillNo, HSourceBillType, HRemark, " +
                        "HRelationBillInterID, HRelationBillEntryID, HRelationBillNo, HRelationBillType, HICMOInterID, HICMOEntryID, HICMOBillNo, " +
                        "HProcExchInterID, HProcExchEntryID, HProcExchBillNo, HMaterID, HProcID) " +
                        "values(" +
                        "'" + omodel.HInterID.ToString() + "'," +
                        "'" + oSub.HEntryID.ToString() + "'," +
                        "'" + omodel.HBillNo + "'," +
                        "'" + oSub.HSourceInterID + "'," +
                        "'" + oSub.HSourceEntryID + "'," +
                        "'" + oSub.HSourceBillNo + "'," +
                        "'" + oSub.HSourceBillType + "'," +
                        "'" + oSub.HRemark + "'," +
                        "'" + oSub.HRelationBillInterID + "'," +
                        "'" + oSub.HRelationBillEntryID + "'," +
                        "'" + oSub.HRelationBillNo + "'," +
                        "'" + oSub.HRelationBillType + "'," +
                        "'" + oSub.HICMOInterID + "'," +
                        "'" + oSub.HICMOEntryID + "'," +
                        "'" + oSub.HICMOBillNo + "'," +
                        "'" + oSub.HProcExchInterID + "'," +
                        "'" + oSub.HProcExchEntryID + "'," +
                        "'" + oSub.HProcExchBillNo + "'," +
                        "'" + oSub.HMaterID + "'," +
                        "'" + oSub.HProcID + "')";
                    oCn.RunProc(subSql);
                }
                foreach (Models.ClsSc_MESBeginWorkBillSub oSub in DetailColl)
                {
                    //oCn.RunProc("Insert into Sc_MESBeginWorkBillSub " +
@@ -136,7 +230,14 @@
                //        return false;
                //    }
                //}
                sReturn = "修改单据成功!";
                //保存后控制
                if (!AfterSave(lngBillKey, omodel.HICMOInterID, omodel.HICMOEntryID, omodel.HICMOBillNo, 2, ref sReturn))
                {
                    oCn.RollBack();
                    return false;
                }
                sReturn = "单据号:" + omodel.HBillNo + " 修改成功!";
                oCn.Commit();
                return true;
            }
@@ -157,16 +258,12 @@
                omodel.HInterID = DBUtility.ClsPub.CreateBillID(BillType, ref DBUtility.ClsPub.sExeReturnInfo);
                //若MAINDI重复则重新获取
                oCn.BeginTran();
                //保存前控制=========================================
                ds = oCn.RunProcReturn("exec h_p_Sc_MESBeginWorkBill_BeforeSaveCtrl " + omodel.HInterID + "," + omodel.HICMOInterID + "," + omodel.HICMOEntryID + ",'" + omodel.HICMOBillNo + "'", "h_p_Sc_MESBeginWorkBill_BeforeSaveCtrl");
                if (DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[0]["HBack"]) == "1")
                //保存前控制
                if (!BeforeSave(omodel.HInterID, omodel.HICMOInterID, omodel.HICMOEntryID, omodel.HICMOBillNo, 1, ref sReturn))
                {
                    sReturn = DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[0]["HBackRemark"]);
                    oCn.RollBack();
                    return false;
                }
                //=========================================================
                //主表
                oCn.RunProc("Insert Into Sc_MESBeginWorkBillMain " +
                "(HBillType,HBillSubType,HInterID,HBillNo,HBillStatus,HDate,HMaker,HMakeDate" +
@@ -186,6 +283,38 @@
                "," + omodel.HGroupID.ToString() + "," + omodel.HDeptID.ToString() + "," + omodel.HEmpID.ToString() + ",'" + omodel.HBarCode + "','" + omodel.HAddr + "','" + omodel.HBarCodeMaker + "',getdate(),'"+ omodel.HRunStatus + "','"+ omodel.HSourceBeginQty.ToString() + "'" +
              ") ");
                //插入子表
                foreach (Models.ClsSc_MESBeginWorkBillSub_RelationBill oSub in DetailCol2)
                {
                    string subSql = "insert into Sc_MESBeginWorkBillSub_RelationBill " +
                        "(HInterID, HEntryID,HBillNo_bak, HSourceInterID, HSourceEntryID, HSourceBillNo, HSourceBillType, HRemark, " +
                        "HRelationBillInterID, HRelationBillEntryID, HRelationBillNo, HRelationBillType, HICMOInterID, HICMOEntryID, HICMOBillNo, " +
                        "HProcExchInterID, HProcExchEntryID, HProcExchBillNo, HMaterID, HProcID) " +
                        "values(" +
                        "'" + omodel.HInterID.ToString() + "'," +
                        "'" + oSub.HEntryID.ToString() + "'," +
                        "'" + omodel.HBillNo + "'," +
                        "'" + oSub.HSourceInterID + "'," +
                        "'" + oSub.HSourceEntryID + "'," +
                        "'" + oSub.HSourceBillNo + "'," +
                        "'" + oSub.HSourceBillType + "'," +
                        "'" + oSub.HRemark + "'," +
                        "'" + oSub.HRelationBillInterID + "'," +
                        "'" + oSub.HRelationBillEntryID + "'," +
                        "'" + oSub.HRelationBillNo + "'," +
                        "'" + oSub.HRelationBillType + "'," +
                        "'" + oSub.HICMOInterID + "'," +
                        "'" + oSub.HICMOEntryID + "'," +
                        "'" + oSub.HICMOBillNo + "'," +
                        "'" + oSub.HProcExchInterID + "'," +
                        "'" + oSub.HProcExchEntryID + "'," +
                        "'" + oSub.HProcExchBillNo + "'," +
                        "'" + oSub.HMaterID + "'," +
                        "'" + oSub.HProcID + "')";
                    oCn.RunProc(subSql);
                }
                //再次验证 保存是否 合理
                ds = oCn.RunProcReturn("exec h_p_JIT_MESBeginWorkBill_SaveCtrl @HInterId=" + omodel.HInterID + "", "h_p_JIT_MESBeginWorkBill_SaveCtrl");
                if (ds == null || ds.Tables[0].Rows.Count <= 0) 
@@ -201,16 +330,40 @@
                    return false;
                }
                //保存后控制=========================================
                ds = oCn.RunProcReturn("exec h_p_Sc_MESBeginWorkBill_AfterSaveCtrl " + omodel.HInterID + "," + omodel.HICMOInterID + "," + omodel.HICMOEntryID + ",'" + omodel.HICMOBillNo + "'", "h_p_Sc_MESBeginWorkBill_AfterSaveCtrl");
                //获取最近的上模单  把工单跟模具进行绑定
                ds = oCn.RunProcReturn(@"select  HICMOInterID,HICMOEntryID,HSourceInterID,HSourceEntryID,HSourceID from Sc_ICMOBillStatus_Tmp where HInterID=" + omodel.HMainSourceInterID.ToString(), "Sc_ICMOBillStatus_Tmp");
                if (DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[0]["HBack"]) == "1")
                if (ds.Tables[0].Rows.Count > 0)
                {
                    sReturn = DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[0]["HBackRemark"]);
                    string HICMOInterID = ds.Tables[0].Rows[0]["HICMOInterID"].ToString();
                    string HICMOEntryID = ds.Tables[0].Rows[0]["HICMOEntryID"].ToString();
                    string HSourceInterID = ds.Tables[0].Rows[0]["HSourceInterID"].ToString();
                    string HSourceEntryID = ds.Tables[0].Rows[0]["HSourceEntryID"].ToString();
                    string HSourceID = ds.Tables[0].Rows[0]["HSourceID"].ToString();
                    ds = oCn.RunProcReturn(@"select  HMouldID from Sc_MouldUpperBillMain a
                        inner join Sc_MouldUpperBillSub b on a.HInterID = b.HInterID where HICMOInterID=" + HICMOInterID + " and HICMOEntryID=" + HICMOEntryID + " and HProcExchInterID=" + HSourceInterID + " and  HProcExchEntryID=" + HSourceEntryID + " and HSourceID=" + HSourceID + " order by HMakeDate desc", "Sc_MouldUpperBillMain");
                    if (ds.Tables[0].Rows.Count > 0)
                    {
                        oCn.RunProc("update Sc_ICMOBillStatus_Tmp set HMouldID= " + ds.Tables[0].Rows[0]["HMouldID"].ToString() + " where HInterID=" + omodel.HMainSourceInterID.ToString());
                    }
                    else
                    {
                        ds = oCn.RunProcReturn(@"select  HMouldID from Sc_MouldUpperBillMain a
                        inner join Sc_MouldUpperBillSub b on a.HInterID = b.HInterID where  HSourceID=" + HSourceID + " order by HMakeDate desc", "Sc_MouldUpperBillMain");
                        if (ds.Tables[0].Rows.Count > 0)
                        {
                            oCn.RunProc("update Sc_ICMOBillStatus_Tmp set HMouldID= " + ds.Tables[0].Rows[0]["HMouldID"].ToString() + " where HInterID=" + omodel.HMainSourceInterID.ToString());
                        }
                    }
                }
                //保存后控制
                if (!AfterSave(omodel.HInterID, omodel.HICMOInterID, omodel.HICMOEntryID, omodel.HICMOBillNo, 1, ref sReturn))
                {
                    oCn.RollBack();
                    return false;
                }
                //=========================================================
                sReturn = omodel.HInterID.ToString();
                oCn.Commit();
@@ -419,7 +572,7 @@
        }
        //删除单据
        public override bool DeleteBill(Int64 lngBillKey, string HBillNo, string procName, string user, ref string sReturn)
        public  bool DeleteBill(Int64 lngBillKey, string HBillNo, string procName, string user, ref string sReturn)
        {
            try
            {