|  |  | 
 |  |  |     { | 
 |  |  |         public Models.ClsSb_EquipRepairWorkBillMain omodel = new Models.ClsSb_EquipRepairWorkBillMain(); | 
 |  |  |         public List<Models.ClsSb_EquipRepairWorkBillSub> DetailColl = new List<Models.ClsSb_EquipRepairWorkBillSub>(); | 
 |  |  |         public List<Model.ClsSb_EquipRepairWorkBillSub_Mater> DetailColl_Mater = new List<Model.ClsSb_EquipRepairWorkBillSub_Mater>(); | 
 |  |  |  | 
 |  |  |         public ClsSb_EquipRepairWorkBill() | 
 |  |  |         { | 
 |  |  | 
 |  |  |         { | 
 |  |  |             try | 
 |  |  |             { | 
 |  |  |                 //保存前控制========================================= | 
 |  |  |                 string HBillNote = ""; | 
 |  |  |                 DataSet ds = oCn.RunProcReturn("Exec h_p_Sb_EquipRepairWorkBill_BeforeSaveCtrl " + omodel.HInterID.ToString() + ", '" + omodel.HBillNo + "','" + HBillNote + "',1 ", "h_p_Sb_EquipRepairWorkBill_BeforeSaveCtrl"); | 
 |  |  |                 if (ds == null) | 
 |  |  |                 { | 
 |  |  |                     sReturn = "保存前判断失败!"; | 
 |  |  |                     return false; | 
 |  |  |                 } | 
 |  |  |                 if (DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[0]["HBack"]) != "0") | 
 |  |  |                 { | 
 |  |  |                     sReturn = "保存失败!" + DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[0]["HBackRemark"]); | 
 |  |  |                     return false; | 
 |  |  |                 } | 
 |  |  |                 //========================================================= | 
 |  |  |  | 
 |  |  |                 // | 
 |  |  |                 oCn.BeginTran(); | 
 |  |  |                 //更新主表 | 
 |  |  | 
 |  |  |                 DeleteRelation(ref sReturn, lngBillKey); | 
 |  |  |                 //删除子表 | 
 |  |  |                 DeleteBillSub(lngBillKey); | 
 |  |  |                 //删除配件数据 | 
 |  |  |                 oCn.RunProc("delete from Sb_EquipRepairWorkBillSub_Mater where HInterID="+ lngBillKey); | 
 |  |  |                 //插入子表 | 
 |  |  |                 omodel.HInterID = lngBillKey; | 
 |  |  |                 foreach (Models.ClsSb_EquipRepairWorkBillSub oSub in DetailColl) | 
 |  |  | 
 |  |  |                        ",HSourceInterID,HSourceEntryID,HSourceBillNo,HSourceBillType,HRelationQty,HRelationMoney" + | 
 |  |  |                        ",HRepairID,HManagerID,HRepairExplanation,HEmpID" + | 
 |  |  |                        ") values(" | 
 |  |  |                        + omodel.HInterID.ToString() + "," + oSub.HEntryID.ToString() + ",'" + oSub.HCloseMan + "','" + oSub.HEntryCloseDate.ToShortDateString() + "'," + Convert.ToString(oSub.HCloseType ? 1 : 0) + ",'" + oSub.HRemark + "'" + | 
 |  |  |                        + omodel.HInterID.ToString() + "," + oSub.HEntryID.ToString() + ",'" + oSub.HCloseMan + "','" + oSub.HEntryCloseDate + "'," + Convert.ToString(oSub.HCloseType ? 1 : 0) + ",'" + oSub.HRemark + "'" + | 
 |  |  |                        "," + oSub.HSourceInterID.ToString() + "," + oSub.HSourceEntryID.ToString() + ",'" + oSub.HSourceBillNo + "','" + oSub.HSourceBillType + "'," + oSub.HRelationQty.ToString() + "," + oSub.HRelationMoney.ToString() + | 
 |  |  |                       "," + oSub.HRepairID.ToString() + ",'"+ oSub.HManagerID.ToString() + "','" + oSub.HRepairExplanation + "'," + oSub.HEmpID.ToString() +  | 
 |  |  |                        ") "); | 
 |  |  |                 } | 
 |  |  |  | 
 |  |  |                 foreach (Model.ClsSb_EquipRepairWorkBillSub_Mater oSub in DetailColl_Mater) | 
 |  |  |                 { | 
 |  |  |                     oCn.RunProc("Insert into Sb_EquipRepairWorkBillSub_Mater " + | 
 |  |  |                       " (HInterID,HEntryID," + | 
 |  |  |                       "HCloseMan,HEntryCloseDate,HCloseType,HRemark," + | 
 |  |  |                       "HSourceInterID,HSourceEntryID,HSourceBillNo,HSourceBillType,HRelationQty,HRelationMoney," + | 
 |  |  |                       "HQty,HMaterID,HUnitID,HQtyMust," + | 
 |  |  |                       "HManagerID ) values(" + | 
 |  |  |                       omodel.HInterID.ToString() + "," + oSub.HEntryID.ToString() + | 
 |  |  |                       ",'" + oSub.HCloseMan + "','" + oSub.HEntryCloseDate + "'," + Convert.ToString(oSub.HCloseType ? 1 : 0) + ",'" + oSub.HRemark + "'" + | 
 |  |  |                       "," + oSub.HSourceInterID.ToString() + "," + oSub.HSourceEntryID.ToString() + ",'" + oSub.HSourceBillNo + "','" + oSub.HSourceBillType + "'," + oSub.HRelationQty.ToString() + "," + oSub.HRelationMoney.ToString() + | 
 |  |  |                       "," + oSub.HQty.ToString() + "," + oSub.HMaterID.ToString() + "," + oSub.HUnitID.ToString() + "," + oSub.HQtyMust.ToString() + | 
 |  |  |                       "," + oSub.HManagerID.ToString() + ") "); | 
 |  |  |                 } | 
 |  |  |  | 
 |  |  |                 // | 
 |  |  |                 //foreach (Model.ClsSb_EquipRepairWorkBillSub oSub in DetailColl) | 
 |  |  |                 //{ | 
 |  |  | 
 |  |  |                 //        return false; | 
 |  |  |                 //    } | 
 |  |  |                 //} | 
 |  |  |  | 
 |  |  |  | 
 |  |  |                 //=========================保存后控制   | 
 |  |  |                 DataSet ds2 = oCn.RunProcReturn("Exec h_p_Sb_EquipRepairWorkBill_AfterSaveCtrl " + omodel.HInterID.ToString() + ", '" + omodel.HBillNo + "',1 ", "h_p_Sb_EquipRepairWorkBill_AfterSaveCtrl"); | 
 |  |  |                 if (ds2 == null) | 
 |  |  |                 { | 
 |  |  |                     sReturn = "保存后控制判断失败!"; | 
 |  |  |                     oCn.RollBack(); | 
 |  |  |                     return false; | 
 |  |  |                 } | 
 |  |  |                 if (DBUtility.ClsPub.isStrNull(ds2.Tables[0].Rows[0]["HBack"]) != "0") | 
 |  |  |                 { | 
 |  |  |                     sReturn = "保存失败2!" + DBUtility.ClsPub.isStrNull(ds2.Tables[0].Rows[0]["HBackRemark"]); | 
 |  |  |                     oCn.RollBack(); | 
 |  |  |                     return false; | 
 |  |  |                 } | 
 |  |  |                 //============================ | 
 |  |  |  | 
 |  |  |  | 
 |  |  |                 sReturn = "修改单据成功!"; | 
 |  |  |                 oCn.Commit(); | 
 |  |  |                 return true; | 
 |  |  | 
 |  |  |             { | 
 |  |  |                 //得到mainid | 
 |  |  |                 omodel.HInterID = DBUtility.ClsPub.CreateBillID(BillType, ref DBUtility.ClsPub.sExeReturnInfo); | 
 |  |  |  | 
 |  |  |                 //保存前控制========================================= | 
 |  |  |                 string HBillNote = ""; | 
 |  |  |                 DataSet ds = oCn.RunProcReturn("Exec h_p_Sb_EquipRepairWorkBill_BeforeSaveCtrl " + omodel.HInterID.ToString() + ", '" + omodel.HBillNo + "','" + HBillNote + "',1 ", "h_p_Sb_EquipRepairWorkBill_BeforeSaveCtrl"); | 
 |  |  |                 if (ds == null) | 
 |  |  |                 { | 
 |  |  |                     sReturn = "保存前判断失败!"; | 
 |  |  |                     return false; | 
 |  |  |                 } | 
 |  |  |                 if (DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[0]["HBack"]) != "0") | 
 |  |  |                 { | 
 |  |  |                     sReturn = "保存失败!" + DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[0]["HBackRemark"]); | 
 |  |  |                     return false; | 
 |  |  |                 } | 
 |  |  |                 //========================================================= | 
 |  |  |  | 
 |  |  |  | 
 |  |  |                 //若MAINDI重复则重新获取 | 
 |  |  |                 oCn.BeginTran(); | 
 |  |  |                 | 
 |  |  | 
 |  |  |                 " values('" + this.BillType + "','"  + this.HBillSubType + "'," +omodel.HInterID.ToString() + ",'" + omodel.HBillNo + "','" + omodel.HDate + "'" + | 
 |  |  |                 ", " + omodel.HYear.ToString() + "," + omodel.HPeriod.ToString() + ",'" + omodel.HRemark + "','" + omodel.HMaker + "',getdate()" + | 
 |  |  |                 ", " + omodel.HEquipID.ToString() + "," + omodel.HRepairID.ToString() + "," + omodel.HPlanTimes.ToString() + "," + omodel.HEmpID.ToString() + "," + omodel.HManagerID.ToString() + "," + omodel.HTimes.ToString() + | 
 |  |  |                 ", " + omodel.HDeptID.ToString() + ",'" + omodel.HExplanation + "','" + omodel.HInnerBillNo + "','" + omodel.HRepairBeginDate.ToShortDateString() + "','" + omodel.HRepairEndDate.ToShortDateString() + "','" + omodel.HRepairContent + "','" + omodel.HCycleUnit + "','" + | 
 |  |  |                 ", " + omodel.HDeptID.ToString() + ",'" + omodel.HExplanation + "','" + omodel.HInnerBillNo + "','" + omodel.HRepairBeginDate + "','" + omodel.HRepairEndDate + "','" + omodel.HRepairContent + "','" + omodel.HCycleUnit + "','" + | 
 |  |  |                  omodel.HMainSourceBillType+"',"+ omodel.HMainSourceInterID.ToString()+","+ omodel.HMainSourceEntryID.ToString() + | 
 |  |  |                 ") "); | 
 |  |  |                 //插入子表 | 
 |  |  | 
 |  |  |                        ",HSourceInterID,HSourceEntryID,HSourceBillNo,HSourceBillType,HRelationQty,HRelationMoney" + | 
 |  |  |                        ",HRepairID,HManagerID,HRepairExplanation,HEmpID" + | 
 |  |  |                        ") values(" | 
 |  |  |                        + omodel.HInterID.ToString() + "," + oSub.HEntryID.ToString() + ",'" + oSub.HCloseMan + "','" + oSub.HEntryCloseDate.ToShortDateString() + "'," + Convert.ToString(oSub.HCloseType ? 1 : 0) + ",'" + oSub.HRemark + "'" + | 
 |  |  |                        + omodel.HInterID.ToString() + "," + oSub.HEntryID.ToString() + ",'" + oSub.HCloseMan + "','" + oSub.HEntryCloseDate + "'," + Convert.ToString(oSub.HCloseType ? 1 : 0) + ",'" + oSub.HRemark + "'" + | 
 |  |  |                        "," + oSub.HSourceInterID.ToString() + "," + oSub.HSourceEntryID.ToString() + ",'" + oSub.HSourceBillNo + "','" + oSub.HSourceBillType + "'," + oSub.HRelationQty.ToString() + "," + oSub.HRelationMoney.ToString() + | 
 |  |  |                       "," + oSub.HRepairID.ToString() + ",'" + oSub.HManagerID.ToString() + "','" + oSub.HRepairExplanation + "'," + oSub.HEmpID.ToString() + | 
 |  |  |                        ")"); | 
 |  |  | 
 |  |  |                        ",HSourceInterID,HSourceEntryID,HSourceBillNo,HSourceBillType,HRelationQty,HRelationMoney" + | 
 |  |  |                        ",HRepairID,HManagerID,HRepairExplanation,HEmpID" + | 
 |  |  |                        ") values(" | 
 |  |  |                        + omodel.HInterID.ToString() + "," + oSub.HEntryID.ToString() + ",'" + oSub.HCloseMan + "','" + oSub.HEntryCloseDate.ToShortDateString() + "'," + Convert.ToString(oSub.HCloseType ? 1 : 0) + ",'" + oSub.HRemark + "'" + | 
 |  |  |                        + omodel.HInterID.ToString() + "," + oSub.HEntryID.ToString() + ",'" + oSub.HCloseMan + "','" + oSub.HEntryCloseDate + "'," + Convert.ToString(oSub.HCloseType ? 1 : 0) + ",'" + oSub.HRemark + "'" + | 
 |  |  |                        "," + oSub.HSourceInterID.ToString() + "," + oSub.HSourceEntryID.ToString() + ",'" + oSub.HSourceBillNo + "','" + oSub.HSourceBillType + "'," + oSub.HRelationQty.ToString() + "," + oSub.HRelationMoney.ToString() + | 
 |  |  |                       "," + oSub.HRepairID.ToString() + ",'"+ oSub.HManagerID.ToString() + "','" + oSub.HRepairExplanation + "'," + oSub.HEmpID.ToString() + | 
 |  |  |                        ") "); | 
 |  |  |                 } | 
 |  |  |  | 
 |  |  |                 foreach (Model.ClsSb_EquipRepairWorkBillSub_Mater oSub in DetailColl_Mater) | 
 |  |  |                 { | 
 |  |  |                     oCn.RunProc("Insert into Sb_EquipRepairWorkBillSub_Mater " + | 
 |  |  |                       " (HInterID,HEntryID," + | 
 |  |  |                       "HCloseMan,HEntryCloseDate,HCloseType,HRemark," + | 
 |  |  |                       "HSourceInterID,HSourceEntryID,HSourceBillNo,HSourceBillType,HRelationQty,HRelationMoney," + | 
 |  |  |                       "HQty,HMaterID,HUnitID,HQtyMust," + | 
 |  |  |                       "HManagerID ) values(" + | 
 |  |  |                       omodel.HInterID.ToString() + "," + oSub.HEntryID.ToString() + | 
 |  |  |                       ",'" + oSub.HCloseMan + "','" + oSub.HEntryCloseDate + "'," + Convert.ToString(oSub.HCloseType ? 1 : 0) + ",'" + oSub.HRemark + "'" + | 
 |  |  |                       "," + oSub.HSourceInterID.ToString() + "," + oSub.HSourceEntryID.ToString() + ",'" + oSub.HSourceBillNo + "','" + oSub.HSourceBillType + "'," + oSub.HRelationQty.ToString() + "," + oSub.HRelationMoney.ToString() + | 
 |  |  |                       "," + oSub.HQty.ToString() + "," + oSub.HMaterID.ToString() + "," + oSub.HUnitID.ToString() + "," + oSub.HQtyMust.ToString() + | 
 |  |  |                       "," + oSub.HManagerID.ToString() + ") "); | 
 |  |  |                 } | 
 |  |  |                 // | 
 |  |  |                 //foreach (Model.ClsSb_EquipRepairWorkBillSub oSub in DetailColl) | 
 |  |  | 
 |  |  |                 //    } | 
 |  |  |                 //} | 
 |  |  |                 // | 
 |  |  |  | 
 |  |  |                 //=========================保存后控制   | 
 |  |  |                 DataSet ds2 = oCn.RunProcReturn("Exec h_p_Sb_EquipRepairWorkBill_AfterSaveCtrl " + omodel.HInterID.ToString() + ", '" + omodel.HBillNo + "',1 ", "h_p_Sb_EquipRepairWorkBill_AfterSaveCtrl"); | 
 |  |  |                 if (ds2 == null) | 
 |  |  |                 { | 
 |  |  |                     sReturn = "保存后控制判断失败!"; | 
 |  |  |                     oCn.RollBack(); | 
 |  |  |                     return false; | 
 |  |  |                 } | 
 |  |  |                 if (DBUtility.ClsPub.isStrNull(ds2.Tables[0].Rows[0]["HBack"]) != "0") | 
 |  |  |                 { | 
 |  |  |                     sReturn = "保存失败2!" + DBUtility.ClsPub.isStrNull(ds2.Tables[0].Rows[0]["HBackRemark"]); | 
 |  |  |                     oCn.RollBack(); | 
 |  |  |                     return false; | 
 |  |  |                 } | 
 |  |  |                 //============================ | 
 |  |  |  | 
 |  |  |                 sReturn = "新增单据成功!"; | 
 |  |  |                 oCn.Commit(); | 
 |  |  |                 return true; |