|  |  | 
 |  |  |         public Models.ClsSc_MESBeginWorkBillMain omodel = new Models.ClsSc_MESBeginWorkBillMain(); | 
 |  |  |         public List<Models.ClsSc_MESBeginWorkBillSub> DetailColl = new List<Models.ClsSc_MESBeginWorkBillSub>(); | 
 |  |  |         //public List<Model.ClsSc_MESBeginWorkBillSub_Item> DetailColl1 = new List<Model.ClsSc_MESBeginWorkBillSub_Item>(); | 
 |  |  |         //获取系统参数 | 
 |  |  |         Pub_Class.ClsXt_SystemParameter oSystemParameter = new Pub_Class.ClsXt_SystemParameter(); | 
 |  |  |  | 
 |  |  |         public ClsSc_MESBeginWorkBill() | 
 |  |  |         { | 
 |  |  |             base.MvarItemKeySub = "Sc_MESBeginWorkBillSub"; | 
 |  |  | 
 |  |  |                 //得到mainid | 
 |  |  |                 omodel.HInterID = DBUtility.ClsPub.CreateBillID(BillType, ref DBUtility.ClsPub.sExeReturnInfo); | 
 |  |  |                 //若MAINDI重复则重新获取 | 
 |  |  |                 oCn.BeginTran(); | 
 |  |  |                 //主表 | 
 |  |  |                 | 
 |  |  |                 oCn.RunProc("Insert Into Sc_MESBeginWorkBillMain " + | 
 |  |  |                 "(HBillType,HBillSubType,HInterID,HBillNo,HBillStatus,HDate,HMaker,HMakeDate" + | 
 |  |  |                 ",HYear,HPeriod,HRemark" + | 
 |  |  | 
 |  |  |                 ",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 + "'" + | 
 |  |  | 
 |  |  |                 ",'" + 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() + "'" + | 
 |  |  |               ") "); | 
 |  |  |  | 
 |  |  |                 //根据开工单内码 设置 生产状态表 开工状态(先把 本资源全部工单 设置为非开工状态,再设置本单对应得源单 为开工状态) | 
 |  |  |                 oCn.RunProcReturn("exec h_p_JIT_MESBeginWorkBill_BeginWork @HInterId=" + omodel.HInterID + ",@flag='开工'", "h_p_JIT_MESBeginWorkBill_BeginWork"); | 
 |  |  |                 sReturn = "新增单据成功!"; | 
 |  |  |                 //系统参数  自动审核  | 
 |  |  |                 string AutoCheck = oSystemParameter.GetSingleSystemParameter("Sc_MESBeginWorkBill_AutoCheck",ref sReturn); | 
 |  |  |                 if (AutoCheck=="Y")  | 
 |  |  |                 //再次验证 保存是否 合理 | 
 |  |  |                 DataSet 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)  | 
 |  |  |                 { | 
 |  |  |                     //审核单据 | 
 |  |  |                     oCn.RunProc(" Update " + MvarItemKey + " set HBillStatus='2', HChecker='" + omodel.HMaker + "',HCheckDate=getdate() Where HInterID=" + omodel.HInterID.ToString()); | 
 |  |  |                     sReturn = "无验证数据!"; | 
 |  |  |                     return false; | 
 |  |  |                 } | 
 |  |  |                 if (DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[0]["HBack"]) == "2")  | 
 |  |  |                 { | 
 |  |  |                     sReturn = DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[0]["HBackRemark"]); | 
 |  |  |                     return false; | 
 |  |  |                 } | 
 |  |  |  | 
 |  |  |                 oCn.Commit(); | 
 |  |  |  | 
 |  |  |                 sReturn = omodel.HInterID.ToString(); | 
 |  |  |                 return true; | 
 |  |  |             } | 
 |  |  |             catch (Exception e) | 
 |  |  |             { | 
 |  |  |                 sReturn = e.Message; | 
 |  |  |                 oCn.RollBack(); | 
 |  |  |                 throw (e); | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         //删除单据 | 
 |  |  |         public override bool DeleteBill(Int64 lngBillKey, ref string sReturn)  | 
 |  |  |         { | 
 |  |  |             try | 
 |  |  |             { | 
 |  |  |                 oCn.BeginTran(); | 
 |  |  |                 //判断是否允许删除 | 
 |  |  |                 DataSet ds = oCn.RunProcReturn("exec h_p_JIT_MESBeginWorkBill_DelCtrl @HInterId=" + lngBillKey + "", "h_p_JIT_MESBeginWorkBill_SaveCtrl"); | 
 |  |  |                 if (ds == null || ds.Tables[0].Rows.Count <= 0) | 
 |  |  |                 { | 
 |  |  |                     sReturn = "无验证数据!"; | 
 |  |  |                     return false; | 
 |  |  |                 } | 
 |  |  |                 if (DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[0]["HBack"]) == "2") | 
 |  |  |                 { | 
 |  |  |                     sReturn = DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[0]["HBackRemark"]); | 
 |  |  |                     return false; | 
 |  |  |                 } | 
 |  |  |  | 
 |  |  |                 //删除关联关系 | 
 |  |  |                 oCn.RunProc("exec h_p_JIT_MESBeginWorkBill_DelRelation @HInterId=" + lngBillKey + ""); | 
 |  |  |  | 
 |  |  |                 //删除明细表 | 
 |  |  |                 oCn.RunProc("Delete From " + MvarItemKeySub + "  where HInterID=" + lngBillKey.ToString()); | 
 |  |  |                 //删除主表 | 
 |  |  |                 oCn.RunProc("Delete From " + MvarItemKey + "  where HInterID=" + lngBillKey.ToString()); | 
 |  |  |  | 
 |  |  |                 sReturn = "删除单据成功!"; | 
 |  |  |                 oCn.Commit(); | 
 |  |  |                 return true; | 
 |  |  |             } | 
 |  |  |             catch (Exception e) | 
 |  |  |             { | 
 |  |  |                 sReturn = e.Message; | 
 |  |  |                 oCn.RollBack(); | 
 |  |  |                 throw (e); | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         //审核 | 
 |  |  |         public bool CheckBill(Int64 lngBillKey, ref string sReturn) | 
 |  |  |         { | 
 |  |  | 
 |  |  |             { | 
 |  |  |                 string HChecker = DBUtility.ClsPub.CurUserName; | 
 |  |  |                 string HCheckDate = DBUtility.ClsPub.GetServerDate(-1); | 
 |  |  |                 oCn.BeginTran(); | 
 |  |  |                 oCn.RunProc(" Update " + MvarItemKey + " set HBillStatus='2',HChecker='" + HChecker + "',HCheckDate='" + HCheckDate + "' Where HInterID=" + lngBillKey.ToString()); | 
 |  |  |                 //根据开工单内码 设置 生产状态表 开工状态(先把 本资源全部工单 设置为非开工状态,再设置本单对应得源单 为开工状态) | 
 |  |  |                 oCn.RunProc("exec h_p_JIT_MESBeginWorkBill_BeginWork @HInterId=" + lngBillKey + ",@flag='开工'"); | 
 |  |  |                 oCn.Commit(); | 
 |  |  |                 //生成调拨单 | 
 |  |  |                 //得到调拨单 mainid 单据号 | 
 |  |  |                 //long NewInterID = DBUtility.ClsPub.CreateBillID("1207", ref DBUtility.ClsPub.sExeReturnInfo); |