using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Web; namespace WebAPI.DLL { public class ClsWW_PPBomBill : DBUtility.ClsXt_BaseBill { public Models.ClsWW_PPBomBillMain omodel = new Models.ClsWW_PPBomBillMain(); public List DetailColl = new List(); public ClsWW_PPBomBill() { base.MvarItemKeySub = "WW_PPBomBillSub"; base.MvarItemKeySub2 = ""; base.MvarItemKeySub3 = ""; base.MvarItemKeySub4 = ""; base.MvarItemKey = "WW_PPBomBillMain"; base.MvarReportTitle = "委外用料单"; base.BillType = "1604"; base.HBillSubType = "1604"; } #region 固定代码 ~ClsWW_PPBomBill() { DetailColl = null; } #endregion 自定义方法 //新增单据 public override bool AddBill(ref string sReturn) { try { //得到mainid omodel.HInterID = DBUtility.ClsPub.CreateBillID(BillType, ref DBUtility.ClsPub.sExeReturnInfo); //若MAINDI重复则重新获取 oCn.BeginTran(); string sql = "Insert Into WW_PPBomBillMain " + "(HBillType,HBillSubType,HInterID,HBillNo,HDate" + ",HRemark,HMaker,HMakeDate" + /*"HYear, HPeriod,"*/ ",HDeptID,HMaterID,HUnitID,HQty,HType" + ") " + " values('" + this.BillType + "','" + this.HBillSubType + "'," + omodel.HInterID.ToString() + ",'" + omodel.HBillNo + "','" + omodel.HDate + "'" + ", '" + omodel.HRemark.ToString() + "','" + omodel.HMaker + "',getdate()" + /*omodel.HYear.ToString() + "," + omodel.HPeriod.ToString() + ",'" +*/ ","+ omodel.HDeptID.ToString() +","+ omodel.HMaterID.ToString() + ","+ omodel.HUnitID.ToString() +","+ omodel.HQty.ToString()+",'"+ omodel.HQty+ "') "; //主表 oCn.RunProc(sql); //插入子表 foreach (Models.ClsWW_PPBomBillSub oSub in DetailColl) { oCn.RunProc("Insert into WW_PPBomBillSub " + " (HInterID,HEntryID,HCloseMan,HEntryCloseDate,HCloseType,HRemark" + ",HSourceInterID,HSourceEntryID,HSourceBillNo,HSourceBillType,HRelationQty,HRelationMoney" + ",HMaterID,HMaterNumber,HUnitID,HUnitNumber,HQtyMust,HQty" + ",HWHID,HQtyScrap,HSendDate,HSPID" + ") values(" + omodel.HInterID.ToString() + "," + oSub.HEntryID.ToString() + ",'" + oSub.HCloseMan + "','" + oSub.HEntryCloseDate.ToShortDateString() + "'," + 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.HMaterID.ToString() + ",'" + oSub.HMaterNumber+ "'," + oSub.HUnitID.ToString() + ",'" + oSub.HUnitNumber + "'," + oSub.HQtyMust.ToString() + "," + oSub.HQty.ToString() + "," + oSub.HWHID.ToString() + "," + oSub.HQtyScrap.ToString() + ",'" + oSub.HSendDate + "'," + oSub.HSPID.ToString() + ") "); } sReturn = "新增单据成功!"; oCn.Commit(); return true; } catch (Exception e) { sReturn = e.Message; oCn.RollBack(); throw (e); } } //修改单据 public override bool ModifyBill(Int64 lngBillKey, ref string sReturn) { try { // oCn.BeginTran(); //更新主表 oCn.RunProc("UpDate WW_PPBomBillMain set " + " HBillNo='" + omodel.HBillNo + "'" + //固定赋值=============== ",HDate='" + omodel.HDate + "'" + ",HYear='" + omodel.HYear.ToString() + "'" + ",HPeriod='" + omodel.HPeriod.ToString() + "'" + ",HRemark='" + omodel.HRemark + "'" + ",HUpDater='" + omodel.HMaker + "'" + ",HUpDateDate=getdate()" + //======================================== ",HDeptID=" + omodel.HDeptID.ToString() + ",HMaterID=" + omodel.HMaterID.ToString() + ",HUnitID=" + omodel.HUnitID.ToString() + ",HQty=" + omodel.HQty.ToString() + ",HType=" + omodel.HType.ToString() + " where HInterID=" + lngBillKey.ToString()); //删除关联 DeleteRelation(ref sReturn, lngBillKey); //删除子表 DeleteBillSub(lngBillKey); //插入子表 foreach (Models.ClsWW_PPBomBillSub oSub in DetailColl) { oCn.RunProc("Insert into WW_PPBomBillSub " + " (HInterID,HEntryID,HCloseMan,HEntryCloseDate,HCloseType,HRemark" + ",HSourceInterID,HSourceEntryID,HSourceBillNo,HSourceBillType,HRelationQty,HRelationMoney" + ",HMaterID,HMaterNumber,HUnitID,HUnitNumber,HQtyMust,HQty" + ",HWHID,HQtyScrap,HSendDate,HSPID" + ") values(" + omodel.HInterID.ToString() + "," + oSub.HEntryID.ToString() + ",'" + oSub.HCloseMan + "','" + oSub.HEntryCloseDate.ToShortDateString() + "'," + 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.HMaterID.ToString() + ",'" + oSub.HMaterNumber + "'," + oSub.HUnitID.ToString() + ",'" + oSub.HUnitNumber + "'," + oSub.HQtyMust.ToString() + "," + oSub.HQty.ToString() + "," + oSub.HWHID.ToString() + "," + oSub.HQtyScrap.ToString() + ",'" + oSub.HSendDate + "'," + oSub.HSPID.ToString() + ") "); } sReturn = "修改单据成功!"; oCn.Commit(); return true; } catch (Exception e) { sReturn = e.Message; oCn.RollBack(); throw (e); } } } }