1
lan
2024-05-30 8affd199e02bd37f0dcb16447d1fbcaa34bfa2f8
WebAPI/DLL/ClsSc_MESBeginWorkBill.cs
@@ -152,12 +152,22 @@
        {
            try
            {
                DataSet ds;
                //得到mainid
                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")
                {
                    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" +
                ",HYear,HPeriod,HRemark" +
@@ -165,7 +175,7 @@
                ",HProcExchBillNo,HMaterID,HProcID,HICMOQty,HPlanQty,HBeginWorkTime,HSourceID" +
                ",HSourceInterID_Main,HSourceEntryID_Main,HSourceBillNo_Main,HSourceBillType_Main" +
                ",HMainSourceInterID,HMainSourceEntryID,HMainSourceBillNo,HMainSourceBillType" +
                 ",HGroupID,HDeptID,HEmpID,HBarCode,HAddr,HBarCodeMaker,HBarCodeMakeDate" +
                 ",HGroupID,HDeptID,HEmpID,HBarCode,HAddr,HBarCodeMaker,HBarCodeMakeDate,HRunStatus,HSourceBeginQty" +
                ") " +
                " values('" + this.BillType + "','" + this.HBillSubType + "'," + omodel.HInterID.ToString() + ",'" + omodel.HBillNo + "'," + omodel.HBillStatus.ToString() + ",getdate(),'" + omodel.HMaker+ "',getdate()" +
                "," + omodel.HYear.ToString() + "," + omodel.HPeriod.ToString() + ",'" + omodel.HRemark + "'" +
@@ -173,11 +183,11 @@
                ",'" + omodel.HProcExchBillNo + "'," + omodel.HMaterID.ToString() + "," + omodel.HProcID.ToString() + "," + omodel.HICMOQty.ToString() + "," + omodel.HPlanQty.ToString() + ",getdate()," + omodel.HSourceID.ToString() +
                ",'" + omodel.HMainSourceInterID.ToString() + "'," + omodel.HMainSourceEntryID.ToString() + ",'" + omodel.HMainSourceBillNo.ToString() + "','" + omodel.HMainSourceBillType.ToString() + "'" +
                ",'" + omodel.HMainSourceInterID.ToString() + "'," + omodel.HMainSourceEntryID.ToString() + ",'" + omodel.HMainSourceBillNo.ToString() + "','" + omodel.HMainSourceBillType.ToString() + "'" +
                "," + omodel.HGroupID.ToString() + "," + omodel.HDeptID.ToString() + "," + omodel.HEmpID.ToString() + ",'" + omodel.HBarCode + "','" + omodel.HAddr + "','" + omodel.HBarCodeMaker + "',getdate()" +
                "," + omodel.HGroupID.ToString() + "," + omodel.HDeptID.ToString() + "," + omodel.HEmpID.ToString() + ",'" + omodel.HBarCode + "','" + omodel.HAddr + "','" + omodel.HBarCodeMaker + "',getdate(),'"+ omodel.HRunStatus + "','"+ omodel.HSourceBeginQty.ToString() + "'" +
              ") ");
                //再次验证 保存是否 合理
                DataSet ds=oCn.RunProcReturn("exec h_p_JIT_MESBeginWorkBill_SaveCtrl @HInterId=" + omodel.HInterID + "", "h_p_JIT_MESBeginWorkBill_SaveCtrl");
                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) 
                {
                    sReturn = "无验证数据!";
@@ -191,7 +201,37 @@
                    return false;
                }
                //保存后控制=========================================
                ds = oCn.RunProcReturn("exec h_p_Sc_MESBeginWorkBill_AfterSaveCtrl " + omodel.HInterID + "," + omodel.HICMOInterID + "," + omodel.HICMOEntryID + ",'" + omodel.HICMOBillNo + "'", "h_p_Sc_MESBeginWorkBill_AfterSaveCtrl");
                if (DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[0]["HBack"]) == "1")
                {
                    sReturn = DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[0]["HBackRemark"]);
                    oCn.RollBack();
                    return false;
                }
                //=========================================================
                //获取最近的上模单  把工单跟模具进行绑定
                ds = oCn.RunProcReturn(@"select  HICMOInterID,HICMOEntryID,HSourceInterID,HSourceEntryID,HSourceID from Sc_ICMOBillStatus_Tmp where HInterID=" + omodel.HMainSourceInterID.ToString(), "Sc_ICMOBillStatus_Tmp");
                if (ds.Tables[0].Rows.Count > 0)
                {
                    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());
                    }
                }
                sReturn = omodel.HInterID.ToString();
                oCn.Commit();
                return true;
@@ -399,7 +439,7 @@
        }
        //删除单据
        public override bool DeleteBill(Int64 lngBillKey, ref string sReturn)
        public  bool DeleteBill(Int64 lngBillKey, string HBillNo, string procName, string user, ref string sReturn)
        {
            try
            {
@@ -425,6 +465,24 @@
                //删除主表
                oCn.RunProc("Delete From " + MvarItemKey + "  where HInterID=" + lngBillKey.ToString());
                //删除后控制==================================================================================
                string sql2 = "exec " + procName + " " + lngBillKey + ",'" + HBillNo + "','" + user + "'";
                ds = oCn.RunProcReturn(sql2, procName);
                if (ds == null || ds.Tables.Count == 0 || ds.Tables[0].Rows.Count == 0)
                {
                    sReturn = "删除失败!原因:删除后判断失败,请与网络管理人员联系";
                    oCn.RollBack();
                    return false;
                }
                if (ds.Tables[0].Rows[0]["HBack"].ToString() != "0")
                {
                    sReturn = "删除失败!原因:" + ds.Tables[0].Rows[0]["HRemark"].ToString();
                    oCn.RollBack();
                    return false;
                }
                //==============================================================================================
                sReturn = "删除单据成功!";
                oCn.Commit();
                return true;