using System; using System.Collections.Generic; using System.Text; using System.Data; namespace DAL { public class ClsSc_ProcProdMoveBill:DBUtility.ClsXt_BaseBill { public Model.ClsSc_ProcProdMoveBillMain omodel = new Model.ClsSc_ProcProdMoveBillMain(); public List DetailColl = new List(); public ClsSc_ProcProdMoveBill() { base.MvarItemKeySub = "Sc_ProcProdMoveBillSub"; base.MvarItemKeySub2 = ""; base.MvarItemKeySub3 = ""; base.MvarItemKeySub4 = ""; base.MvarItemKey="Sc_ProcProdMoveBillMain"; base.MvarReportTitle="在制品转移单"; base.BillType="3771"; } #region 固定代码 ~ClsSc_ProcProdMoveBill() { DetailColl = null; } #endregion 自定义方法 //修改单据 public override bool ModifyBill(Int64 lngBillKey, ref string sReturn) { try { // oCn.BeginTran(); // DataSet Ds; Int64 HOutProcPlanInterID = 0; Int64 HOutProcPlanEntryID = 0; Int64 HInProcPlanInterID = 0; Int64 HInProcPlanEntryID = 0; double HQty = 0; Ds = oCn.RunProcReturn("select HOutProcPlanInterID,HOutProcPlanEntryID,HInProcPlanInterID,HInProcPlanEntryID,HQty from Sc_ProcProdMoveBillSub where hinterid=" + lngBillKey, "Sc_ProcProdMoveBillSub"); for (int i = 0; i < Ds.Tables[0].Rows.Count; i++) { HOutProcPlanInterID =DBUtility.ClsPub.isLong( Ds.Tables[0].Rows[i][0]); HOutProcPlanEntryID =DBUtility.ClsPub.isLong( Ds.Tables[0].Rows[i][1]); HInProcPlanInterID =DBUtility.ClsPub.isLong( Ds.Tables[0].Rows[i][2]); HInProcPlanEntryID = DBUtility.ClsPub.isLong( Ds.Tables[0].Rows[i][3]); HQty =DBUtility.ClsPub.isDoule( Ds.Tables[0].Rows[i][4]); oCn.RunProc("update Sc_ProcessPlanSub set HWorkingQty=HWorkingQty+" + HQty + " where hinterid=" + HOutProcPlanInterID + " and hentryid=" + HOutProcPlanEntryID); oCn.RunProc("update Sc_ProcessPlanSub set HWorkingQty=HWorkingQty-" + HQty + " where hinterid=" + HInProcPlanInterID + " and hentryid=" + HInProcPlanEntryID); } foreach (Model.ClsSc_ProcProdMoveBillSub oSub in DetailColl) { if (oSub.HOutProcPlanInterID != 0) { Ds = oCn.RunProcReturn("select HWorkingQty from Sc_ProcessPlanSub where hinterid=" + oSub.HOutProcPlanInterID + " and hentryid=" + oSub.HOutProcPlanEntryID, "Sc_ProcessPlanSub"); if (DBUtility.ClsPub.isDoule(Ds.Tables[0].Rows[0][0]) >= oSub.HQty) { oCn.RunProc("update Sc_ProcessPlanSub set HWorkingQty=HWorkingQty-" + oSub.HQty + " where hinterid=" + oSub.HOutProcPlanInterID + " and hentryid=" + oSub.HOutProcPlanEntryID); } else { sReturn = "转出工序中在制品数量小于转移数量,不允许保存!"; oCn.RollBack(); return false; } } if (oSub.HInProcPlanInterID != 0) { oCn.RunProc("update Sc_ProcessPlanSub set HWorkingQty=HWorkingQty+" + oSub.HQty + " where hinterid=" + oSub.HInProcPlanInterID + " and hentryid=" + oSub.HInProcPlanEntryID); } } //更新主表 oCn.RunProc("UpDate Sc_ProcProdMoveBillMain set " + " HYear=" + omodel.HYear.ToString() + ",HPeriod=" + omodel.HPeriod.ToString() + ",HDate='" + omodel.HDate.ToShortDateString() + "'" + ",HBillStatus=" + omodel.HBillStatus.ToString() + ",HCheckItemNowID=" + omodel.HCheckItemNowID.ToString() + ",HCheckItemNextID=" + omodel.HCheckItemNextID.ToString() + ",HCheckFlowID=" + omodel.HCheckFlowID.ToString() + ",HOutProcID=" + omodel.HOutProcID.ToString() + ",HInProcID=" + omodel.HInProcID.ToString() + ",HRemark='" + omodel.HRemark + "'" + ",HUpDater='" + omodel.HUpDater + "'" + ",HUpDateDate='" + omodel.HUpDateDate + "'" + " where HInterID=" + lngBillKey.ToString()); //删除关联 DeleteRelation(ref sReturn, lngBillKey); //删除子表 DeleteBillSub(lngBillKey); //插入子表 omodel.HInterID = lngBillKey; foreach (Model.ClsSc_ProcProdMoveBillSub oSub in DetailColl) { oCn.RunProc("Insert into Sc_ProcProdMoveBillSub " + " (HInterID,HEntryID,HOutProcPlanBillNo,HOutProcPlanInterID,HOutProcPlanEntryID" + ",HInProcPlanBillNo,HInProcPlanInterID,HInProcPlanEntryID,HMaterID,HUnitID" + ",HBatchNo,HOutCenterID,HInCenterID,HOutSourceID,HInSourceID" + ",HQty,HMoveType" + ",HOutEmpID,HInEmpID,HICMOInterID,HICMOBillNo" + ",HSeOrderBillNo,HSeOrderInterID,HSeOrderEntryID" + ",HCloseMan,HCloseType,HRemark,HSourceInterID,HSourceEntryID" + ",HSourceBillNo,HSourceBillType,HRelationQty,HRelationMoney" + ") values(" + omodel.HInterID.ToString() + "," + oSub.HEntryID.ToString() + ",'" + oSub.HOutProcPlanBillNo + "'," + oSub.HOutProcPlanInterID.ToString() + "," + oSub.HOutProcPlanEntryID.ToString() + ",'" + oSub.HInProcPlanBillNo + "'," + oSub.HInProcPlanInterID.ToString() + "," + oSub.HInProcPlanEntryID.ToString() + "," + oSub.HMaterID.ToString() + "," + oSub.HUnitID.ToString() + ",'" + oSub.HBatchNo + "'," + oSub.HOutCenterID.ToString() + "," + oSub.HInCenterID.ToString() + "," + oSub.HOutSourceID.ToString() + "," + oSub.HInSourceID.ToString() + "," + oSub.HQty.ToString() + ",'" + oSub.HMoveType + "'" + "," + oSub.HOutEmpID.ToString() + "," + oSub.HInEmpID.ToString() + "," + oSub.HICMOInterID.ToString() + ",'" + oSub.HICMOBillNo + "'" + ",'" + oSub.HSeOrderBillNo + "'," + oSub.HSeOrderInterID.ToString() + "," + oSub.HSeOrderEntryID.ToString() + ",'" + oSub.HCloseMan + "'," + Convert.ToString(oSub.HCloseType ? 1 : 0) + ",'" + oSub.HRemark + "'," + oSub.HSourceInterID.ToString() + "," + oSub.HSourceEntryID.ToString() + ",'" + oSub.HSourceBillNo + "','" + oSub.HSourceBillType + "'," + oSub.HRelationQty.ToString() + "," + oSub.HRelationMoney.ToString() + ") "); } sReturn = "修改单据成功!"; oCn.Commit(); return true; } catch (Exception e) { sReturn = e.Message; oCn.RollBack(); throw (e); } } //新增单据 public override bool AddBill(ref string sReturn) { try { //得到mainid omodel.HInterID = DBUtility.ClsPub.CreateBillID(BillType, ref DBUtility.ClsPub.sExeReturnInfo); //若MAINDI重复则重新获取 oCn.BeginTran(); // //foreach (Model.ClsSc_ProcProdMoveBillSub oSub in DetailColl) //{ // if (oSub.HOutProcPlanInterID != 0) // { // DataSet Ds; // Ds = oCn.RunProcReturn("select HWorkingQty from Sc_ProcessPlanSub where hinterid=" + oSub.HOutProcPlanInterID + " and hentryid=" + oSub.HOutProcPlanEntryID, "Sc_ProcessPlanSub"); // if (DBUtility.ClsPub.isDoule(Ds.Tables[0].Rows[0][0]) >= oSub.HQty) // { // oCn.RunProc("update Sc_ProcessPlanSub set HWorkingQty=HWorkingQty-" + oSub.HQty + " where hinterid=" + oSub.HOutProcPlanInterID + " and hentryid=" + oSub.HOutProcPlanEntryID); // } // else // { // sReturn = "转出工序中在制品数量小于转移数量,不允许保存!"; // oCn.RollBack(); // return false; // } // } // if (oSub.HInProcPlanInterID != 0) // { // oCn.RunProc("update Sc_ProcessPlanSub set HWorkingQty=HWorkingQty+" + oSub.HQty + " where hinterid=" + oSub.HInProcPlanInterID + " and hentryid=" + oSub.HInProcPlanEntryID); // } //} //主表 oCn.RunProc("Insert Into Sc_ProcProdMoveBillMain " + "(HYear,HPeriod,HBillType,HBillSubType,HInterID" + ",HDate,HBillNo,HBillStatus" + ",HCheckItemNowID,HCheckItemNextID,HCheckFlowID" + ",HOutProcID,HInProcID" + ",HRemark,HMaker,HMakeDate" + ") " + " values(" + omodel.HYear.ToString() + "," + omodel.HPeriod.ToString() + ",'" + this.BillType + "','" + omodel.HBillSubType + "'," + omodel.HInterID.ToString() + ",'" + omodel.HDate.ToShortDateString() + "','" + omodel.HBillNo + "'," + omodel.HBillStatus.ToString() + "," + omodel.HCheckItemNowID.ToString() + "," + omodel.HCheckItemNextID.ToString() +"," + omodel.HCheckFlowID.ToString() + "," + omodel.HOutProcID.ToString() + "," + omodel.HInProcID.ToString() + ",'" + omodel.HRemark + "','" + DBUtility.ClsPub.CurUserName + "','" + DBUtility.ClsPub.GetServerDate(-1) + "'" + ") "); //插入子表 foreach (Model.ClsSc_ProcProdMoveBillSub oSub in DetailColl) { oCn.RunProc("Insert into Sc_ProcProdMoveBillSub " + " (HInterID,HEntryID,HOutProcPlanBillNo,HOutProcPlanInterID,HOutProcPlanEntryID" + ",HInProcPlanBillNo,HInProcPlanInterID,HInProcPlanEntryID,HMaterID,HUnitID" + ",HBatchNo,HOutCenterID,HInCenterID,HOutSourceID,HInSourceID" + ",HQty,HMoveType" + ",HOutEmpID,HInEmpID,HICMOInterID,HICMOBillNo" + ",HSeOrderBillNo,HSeOrderInterID,HSeOrderEntryID" + ",HCloseMan,HCloseType,HRemark,HSourceInterID,HSourceEntryID" + ",HSourceBillNo,HSourceBillType,HRelationQty,HRelationMoney" + ") values(" + omodel.HInterID.ToString() + "," + oSub.HEntryID.ToString() + ",'" + oSub.HOutProcPlanBillNo + "'," + oSub.HOutProcPlanInterID.ToString() + "," + oSub.HOutProcPlanEntryID.ToString() + ",'" + oSub.HInProcPlanBillNo + "'," + oSub.HInProcPlanInterID.ToString() + "," + oSub.HInProcPlanEntryID.ToString() + "," + oSub.HMaterID.ToString() + "," + oSub.HUnitID.ToString() + ",'" + oSub.HBatchNo + "'," + oSub.HOutCenterID.ToString() + "," + oSub.HInCenterID.ToString() + "," + oSub.HOutSourceID.ToString() + "," + oSub.HInSourceID.ToString() + "," + oSub.HQty.ToString() + ",'" + oSub.HMoveType + "'" + "," + oSub.HOutEmpID.ToString() + "," + oSub.HInEmpID.ToString() + "," + oSub.HICMOInterID.ToString() + ",'" + oSub.HICMOBillNo + "'" + ",'" + oSub.HSeOrderBillNo + "'," + oSub.HSeOrderInterID.ToString() + "," + oSub.HSeOrderEntryID.ToString() + ",'" + oSub.HCloseMan + "'," + Convert.ToString(oSub.HCloseType ? 1 : 0) + ",'" + oSub.HRemark + "'," + oSub.HSourceInterID.ToString() + "," + oSub.HSourceEntryID.ToString() + ",'" + oSub.HSourceBillNo + "','" + oSub.HSourceBillType + "'," + oSub.HRelationQty.ToString() + "," + oSub.HRelationMoney.ToString() + ") "); } sReturn = "新增单据成功!"; oCn.Commit(); return true; } catch (Exception e) { sReturn = e.Message; oCn.RollBack(); throw (e); } } //显示单据 public override bool ShowBill(Int64 lngBillKey, ref string sReturn) { try { //查询主表 DataSet Ds ; Ds = oCn.RunProcReturn("Select * from Sc_ProcProdMoveBillMain Where HInterID=" + lngBillKey.ToString(), "Sc_ProcProdMoveBillMain"); if(Ds.Tables[0].Rows.Count==0) { sReturn = "单据未找到!"; return false; } //赋值 omodel.HYear = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["HYear"]); omodel.HPeriod = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["HPeriod"]); omodel.HBillType = DBUtility.ClsPub.isStrNull(Ds.Tables[0].Rows[0]["HBillType"]); omodel.HBillSubType = DBUtility.ClsPub.isStrNull(Ds.Tables[0].Rows[0]["HBillSubType"]); omodel.HInterID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["HInterID"]); omodel.HDate = DBUtility.ClsPub.isDate(Ds.Tables[0].Rows[0]["HDate"]); omodel.HBillNo = DBUtility.ClsPub.isStrNull(Ds.Tables[0].Rows[0]["HBillNo"]); omodel.HBillStatus = DBUtility.ClsPub.isInt(Ds.Tables[0].Rows[0]["HBillStatus"]); omodel.HCheckItemNowID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["HCheckItemNowID"]); omodel.HCheckItemNextID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["HCheckItemNextID"]); omodel.HCheckFlowID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["HCheckFlowID"]); // omodel.HRemark = DBUtility.ClsPub.isStrNull(Ds.Tables[0].Rows[0]["HRemark"]); omodel.HOutProcID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["HOutProcID"]); omodel.HInProcID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["HInProcID"]); // omodel.HBacker = DBUtility.ClsPub.isStrNull(Ds.Tables[0].Rows[0]["HBacker"]); omodel.HBackDate = DBUtility.ClsPub.isStrNull(Ds.Tables[0].Rows[0]["HBackDate"]); omodel.HChecker = DBUtility.ClsPub.isStrNull(Ds.Tables[0].Rows[0]["HChecker"]); omodel.HCheckDate = DBUtility.ClsPub.isStrNull(Ds.Tables[0].Rows[0]["HCheckDate"]); omodel.HMaker = DBUtility.ClsPub.isStrNull(Ds.Tables[0].Rows[0]["HMaker"]); omodel.HMakeDate = DBUtility.ClsPub.isStrNull(Ds.Tables[0].Rows[0]["HMakeDate"]); omodel.HUpDater = DBUtility.ClsPub.isStrNull(Ds.Tables[0].Rows[0]["HUpDater"]); omodel.HUpDateDate = DBUtility.ClsPub.isStrNull(Ds.Tables[0].Rows[0]["HUpDateDate"]); omodel.HCloseMan = DBUtility.ClsPub.isStrNull(Ds.Tables[0].Rows[0]["HCloseMan"]); omodel.HCloseDate = DBUtility.ClsPub.isStrNull(Ds.Tables[0].Rows[0]["HCloseDate"]); omodel.HCloseType = DBUtility.ClsPub.isBool(Ds.Tables[0].Rows[0]["HCloseType"]); omodel.HDeleteMan = DBUtility.ClsPub.isStrNull(Ds.Tables[0].Rows[0]["HDeleteMan"]); omodel.HDeleteDate = DBUtility.ClsPub.isStrNull(Ds.Tables[0].Rows[0]["HDeleteDate"]); //循环 DataSet DsSub ; DsSub = oCn.RunProcReturn("Select * from Sc_ProcProdMoveBillSub Where HInterID=" + lngBillKey.ToString() + " order by HEntryID ", "Sc_ProcProdMoveBillSub"); DetailColl.Clear();//清空 for (int i = 0; i < DsSub.Tables[0].Rows.Count; i++) { Model.ClsSc_ProcProdMoveBillSub oSub = new Model.ClsSc_ProcProdMoveBillSub(); oSub.HInterID = DBUtility.ClsPub.isLong(DsSub.Tables[0].Rows[i]["HInterID"]); oSub.HEntryID = DBUtility.ClsPub.isLong(DsSub.Tables[0].Rows[i]["HEntryID"]); // oSub.HOutProcPlanBillNo = DBUtility.ClsPub.isStrNull(DsSub.Tables[0].Rows[i]["HOutProcPlanBillNo"]); oSub.HOutProcPlanInterID = DBUtility.ClsPub.isLong(DsSub.Tables[0].Rows[i]["HOutProcPlanInterID"]); oSub.HOutProcPlanEntryID = DBUtility.ClsPub.isLong(DsSub.Tables[0].Rows[i]["HOutProcPlanEntryID"]); oSub.HInProcPlanBillNo = DBUtility.ClsPub.isStrNull(DsSub.Tables[0].Rows[i]["HInProcPlanBillNo"]); oSub.HInProcPlanInterID = DBUtility.ClsPub.isLong(DsSub.Tables[0].Rows[i]["HInProcPlanInterID"]); oSub.HInProcPlanEntryID = DBUtility.ClsPub.isLong(DsSub.Tables[0].Rows[i]["HInProcPlanEntryID"]); oSub.HMaterID = DBUtility.ClsPub.isLong(DsSub.Tables[0].Rows[i]["HMaterID"]); oSub.HUnitID = DBUtility.ClsPub.isLong(DsSub.Tables[0].Rows[i]["HUnitID"]); oSub.HBatchNo = DBUtility.ClsPub.isStrNull(DsSub.Tables[0].Rows[i]["HBatchNo"]); oSub.HOutCenterID = DBUtility.ClsPub.isLong(DsSub.Tables[0].Rows[i]["HOutCenterID"]); oSub.HInCenterID = DBUtility.ClsPub.isLong(DsSub.Tables[0].Rows[i]["HInCenterID"]); oSub.HOutSourceID = DBUtility.ClsPub.isLong(DsSub.Tables[0].Rows[i]["HOutSourceID"]); oSub.HInSourceID = DBUtility.ClsPub.isLong(DsSub.Tables[0].Rows[i]["HInSourceID"]); oSub.HOutEmpID = DBUtility.ClsPub.isLong(DsSub.Tables[0].Rows[i]["HOutEmpID"]); oSub.HInEmpID = DBUtility.ClsPub.isLong(DsSub.Tables[0].Rows[i]["HInEmpID"]); oSub.HQty = DBUtility.ClsPub.isDoule(DsSub.Tables[0].Rows[i]["HQty"]); oSub.HMoveType = DBUtility.ClsPub.isStrNull(DsSub.Tables[0].Rows[i]["HMoveType"]); oSub.HSeOrderInterID = DBUtility.ClsPub.isLong(DsSub.Tables[0].Rows[i]["HSeOrderInterID"]); oSub.HSeOrderEntryID = DBUtility.ClsPub.isLong(DsSub.Tables[0].Rows[i]["HSeOrderEntryID"]); oSub.HSeOrderBillNo = DBUtility.ClsPub.isStrNull(DsSub.Tables[0].Rows[i]["HSeOrderBillNo"]); oSub.HICMOBillNo = DBUtility.ClsPub.isStrNull(DsSub.Tables[0].Rows[i]["HICMOBillNo"]); oSub.HICMOInterID = DBUtility.ClsPub.isLong(DsSub.Tables[0].Rows[i]["HICMOInterID"]); // oSub.HCloseMan = DBUtility.ClsPub.isStrNull(DsSub.Tables[0].Rows[i]["HCloseMan"]); oSub.HEntryCloseDate = DBUtility.ClsPub.isDate(DsSub.Tables[0].Rows[i]["HEntryCloseDate"]); oSub.HCloseType = DBUtility.ClsPub.isBool(DsSub.Tables[0].Rows[i]["HCloseType"]); oSub.HRemark = DBUtility.ClsPub.isStrNull(DsSub.Tables[0].Rows[i]["HRemark"]); oSub.HSourceInterID = DBUtility.ClsPub.isLong(DsSub.Tables[0].Rows[i]["HSourceInterID"]); oSub.HSourceEntryID = DBUtility.ClsPub.isLong(DsSub.Tables[0].Rows[i]["HSourceEntryID"]); oSub.HSourceBillNo = DBUtility.ClsPub.isStrNull(DsSub.Tables[0].Rows[i]["HSourceBillNo"]); oSub.HSourceBillType = DBUtility.ClsPub.isStrNull(DsSub.Tables[0].Rows[i]["HSourceBillType"]); oSub.HRelationQty = DBUtility.ClsPub.isDoule(DsSub.Tables[0].Rows[i]["HRelationQty"]); oSub.HRelationMoney = DBUtility.ClsPub.isDoule(DsSub.Tables[0].Rows[i]["HRelationMoney"]); DetailColl.Add(oSub); } sReturn = "显示单据成功!"; return true; } catch (Exception e) { sReturn = e.Message; throw (e); } } /// /// 根据转出工序,得到接收工序 /// /// public bool GetNextProcessPlan(long HMainID,long HSubID, ref string sReturn) { DataSet DsSub; DsSub = oCn.RunProcReturn("Select top 1 * from h_v_Sc_ProcessPlanList where hmainid=" + HMainID.ToString() + " and hsubid>" + HSubID.ToString() + " order by hsubid ", "h_v_Sc_ProcessPlanList"); if (DsSub.Tables[0].Rows.Count == 0) { sReturn = "单据未找到!"; return false; } omodel.HInProcID = DBUtility.ClsPub.isLong(DsSub.Tables[0].Rows[0]["hprocid"]); DetailColl.Clear();//清空 for (int i = 0; i < DsSub.Tables[0].Rows.Count; i++) { Model.ClsSc_ProcProdMoveBillSub oSub = new Model.ClsSc_ProcProdMoveBillSub(); // oSub.HInProcPlanBillNo = DBUtility.ClsPub.isStrNull(DsSub.Tables[0].Rows[i]["工序计划单号"]); oSub.HInProcPlanInterID = DBUtility.ClsPub.isLong(DsSub.Tables[0].Rows[i]["hmainid"]); oSub.HInProcPlanEntryID = DBUtility.ClsPub.isLong(DsSub.Tables[0].Rows[i]["hsubid"]); oSub.HInCenterID = DBUtility.ClsPub.isLong(DsSub.Tables[0].Rows[i]["HCenterID"]); oSub.HInSourceID = DBUtility.ClsPub.isLong(DsSub.Tables[0].Rows[i]["HSourceID"]); // DetailColl.Add(oSub); } return true; } } }