using System; using System.Collections.Generic; using System.Text; using System.Data; namespace DAL { public class ClsGy_MaterialPackingRelation : DBUtility.ClsXt_BaseBill { public Model.ClsGy_MaterialPackingRelationMain omodel = new Model.ClsGy_MaterialPackingRelationMain(); public List DetailColl = new List(); public ClsGy_MaterialPackingRelation() { base.MvarItemKeySub = "Gy_MaterialPackingRelationSub"; base.MvarItemKeySub2 = ""; base.MvarItemKeySub3 = ""; base.MvarItemKeySub4 = ""; base.MvarItemKey= "Gy_MaterialPackingRelationMain"; base.MvarReportTitle="产品包装关联信息"; base.BillType="3339"; base.HBillSubType = "3339"; } #region 固定代码 #region 无参构造函数 ~ClsGy_MaterialPackingRelation() { DetailColl = null; } #endregion #endregion #region 关联数量 //删除关联 public override void DeleteRelation(ref string sReturn, Int64 lngBillKey) { } //新增关联 public override void AddNewRelation(ref string sReturn, Int64 lngBillKey) { } #endregion #region 修改单据 public override bool ModifyBill(Int64 lngBillKey, ref string sReturn) { try { oCn.BeginTran(); //更新主表 string mainSql = "update Gy_MaterialPackingRelationMain set " + "HBillNo = '" + omodel.HBillNo + "'" + ",HDate = '" + omodel.HDate + "'" + ",HUpDater = '" + omodel.HUpDater + "'" + ",HUpDateDate = '" + DBUtility.ClsPub.isStrNull(DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss")) + "'" + ",HCusID = " + omodel.HCusID + "" + ",HProjectName = '" + omodel.HProjectName + "'" + ",HMaterID = " + omodel.HMaterID + "" + ",HRemark = '" + omodel.HRemark + "'" + ",HOrgID = " + omodel.HOrgID + "" + " where HInterID = " + omodel.HInterID; oCn.RunProc(mainSql); //删除子表 DeleteBillSub(lngBillKey); //插入子表 omodel.HInterID = lngBillKey; //插入子表 foreach (Model.ClsGy_MaterialPackingRelationSub oSub in DetailColl) { string subSql = "insert into Gy_MaterialPackingRelationSub" + "(HInterID,HEntryID,HMouldID,HSNP,HTransPackFlag,HSendPackFlag" + ",HDefaultTransPackFlag,HDefaultSendPackFlag,HUseFlag,HRemark) " + " values(" + "" + omodel.HInterID + "" + "," + oSub.HEntryID + "" + "," + oSub.HMouldID + "" + "," + oSub.HSNP + "" + "," + oSub.HTransPackFlag + "" + "," + oSub.HSendPackFlag + "" + "," + oSub.HDefaultTransPackFlag + "" + "," + oSub.HDefaultSendPackFlag + "" + "," + oSub.HUseFlag + "" + ",'" + oSub.HRemark + "'" + ")"; oCn.RunProc(subSql); } sReturn = "修改单据成功!"; oCn.Commit(); return true; } catch (Exception e) { sReturn = e.Message; oCn.RollBack(); throw (e); } } #endregion #region 新增单据 public override bool AddBill(ref string sReturn) { try { DataSet ds; oCn.BeginTran(); //检查主表内码是否重复,若重复则重新生成并继续检查,直到不再重复 while (true) { ds = oCn.RunProcReturn("select * from Gy_MaterialPackingRelationMain where HInterID = " + omodel.HInterID, "Gy_MaterialPackingRelationMain"); if(ds!=null && ds.Tables[0].Rows.Count > 0) { omodel.HInterID = DBUtility.ClsPub.CreateBillID(BillType, ref DBUtility.ClsPub.sExeReturnInfo); } else { break; } } //插入主表 string mainSql = "insert into Gy_MaterialPackingRelationMain" + "(HInterID,HBillNo,HDate,HYear,HPeriod,HBillType" + ",HMaker,HMakeDate,HCusID,HProjectName,HMaterID,HRemark,HOrgID) " + "values(" + "" + omodel.HInterID + "" + ",'" + omodel.HBillNo + "'" + ",'" + omodel.HDate + "'" + "," + DBUtility.ClsPub.isLong(DateTime.Now.Year) + "" + "," + DBUtility.ClsPub.isLong(DateTime.Now.Month) + "" + ",'" + BillType + "'" + ",'" + omodel.HMaker + "'" + ",'" + DBUtility.ClsPub.isStrNull(DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss")) + "'" + "," + omodel.HCusID + "" + ",'" + omodel.HProjectName + "'" + "," + omodel.HMaterID + "" + ",'" + omodel.HRemark + "'" + "," + omodel.HOrgID + "" + ")"; oCn.RunProc(mainSql); //插入子表 foreach (Model.ClsGy_MaterialPackingRelationSub oSub in DetailColl) { string subSql = "insert into Gy_MaterialPackingRelationSub" + "(HInterID,HEntryID,HMouldID,HSNP,HTransPackFlag,HSendPackFlag" + ",HDefaultTransPackFlag,HDefaultSendPackFlag,HUseFlag,HRemark) " + " values(" + "" + omodel.HInterID + "" + "," + oSub.HEntryID + "" + "," + oSub.HMouldID + "" + "," + oSub.HSNP + "" + "," + oSub.HTransPackFlag + "" + "," + oSub.HSendPackFlag + "" + "," + oSub.HDefaultTransPackFlag + "" + "," + oSub.HDefaultSendPackFlag + "" + "," + oSub.HUseFlag + "" + ",'" + oSub.HRemark + "'" + ")"; oCn.RunProc(subSql); } sReturn = "新增单据成功!"; oCn.Commit(); return true; } catch (Exception e) { sReturn = e.Message; oCn.RollBack(); throw (e); } } #endregion #region 显示单据 public override bool ShowBill(Int64 lngBillKey, ref string sReturn) { try { //查询主表 DataSet Ds ; Ds = oCn.RunProcReturn("select * from Gy_MaterialPackingRelationMain Where HInterID = " + lngBillKey.ToString(), "Gy_MaterialPackingRelationMain"); 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.HInterID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["HInterID"]); omodel.HBillStatus = DBUtility.ClsPub.isInt(Ds.Tables[0].Rows[0]["HBillStatus"]); omodel.HDate = DBUtility.ClsPub.isStrNull(Ds.Tables[0].Rows[0]["HDate"]); omodel.HBillNo = Ds.Tables[0].Rows[0]["HBillNo"].ToString().Trim(); omodel.HRemark = Ds.Tables[0].Rows[0]["HRemark"].ToString().Trim(); omodel.HCheckDate = Ds.Tables[0].Rows[0]["HCheckDate"].ToString().Trim(); omodel.HChecker = Ds.Tables[0].Rows[0]["HChecker"].ToString().Trim(); omodel.HMaker = Ds.Tables[0].Rows[0]["HMaker"].ToString().Trim(); omodel.HMakeDate = Ds.Tables[0].Rows[0]["HMakeDate"].ToString().Trim(); omodel.HUpDateDate = Ds.Tables[0].Rows[0]["HUpDateDate"].ToString().Trim(); omodel.HUpDater = Ds.Tables[0].Rows[0]["HUpDater"].ToString().Trim(); omodel.HCloseDate = Ds.Tables[0].Rows[0]["HCloseDate"].ToString().Trim(); omodel.HCloseMan= Ds.Tables[0].Rows[0]["HCloseMan"].ToString().Trim(); omodel.HDeleteDate = Ds.Tables[0].Rows[0]["HDeleteDate"].ToString().Trim(); omodel.HDeleteMan = Ds.Tables[0].Rows[0]["HDeleteMan"].ToString().Trim(); //======================================================== omodel.HCusID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["HCusID"]); omodel.HProjectName = DBUtility.ClsPub.isStrNull(Ds.Tables[0].Rows[0]["HProjectName"]); omodel.HMaterID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["HMaterID"]); omodel.HOrgID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["HOrgID"]); //循环 DataSet DsSub ; DsSub = oCn.RunProcReturn("select * from Gy_MaterialPackingRelationSub where HInterID = " + lngBillKey.ToString() + "order by HEntryID", "Gy_MaterialPackingRelationSub"); DetailColl.Clear();//清空 for (int i = 0; i < DsSub.Tables[0].Rows.Count; i++) { Model.ClsGy_MaterialPackingRelationSub oSub = new Model.ClsGy_MaterialPackingRelationSub(); // 固定赋值=============================================== oSub.HInterID = DBUtility.ClsPub.isLong(DsSub.Tables[0].Rows[i]["HInterID"]); oSub.HEntryID = DBUtility.ClsPub.isLong(DsSub.Tables[0].Rows[i]["HEntryID"]); oSub.HRemark = DsSub.Tables[0].Rows[i]["HRemark"].ToString().Trim(); //=================================================== oSub.HMouldID = DBUtility.ClsPub.isLong(DsSub.Tables[0].Rows[i]["HMouldID"]); oSub.HSNP = DBUtility.ClsPub.isLong(DsSub.Tables[0].Rows[i]["HSNP"]); oSub.HTransPackFlag = DBUtility.ClsPub.isInt(DsSub.Tables[0].Rows[i]["HTransPackFlag"]); oSub.HSendPackFlag = DBUtility.ClsPub.isInt(DsSub.Tables[0].Rows[i]["HSendPackFlag"]); oSub.HDefaultTransPackFlag = DBUtility.ClsPub.isInt(DsSub.Tables[0].Rows[i]["HDefaultTransPackFlag"]); oSub.HDefaultSendPackFlag = DBUtility.ClsPub.isInt(DsSub.Tables[0].Rows[i]["HDefaultSendPackFlag"]); oSub.HUseFlag = DBUtility.ClsPub.isInt(DsSub.Tables[0].Rows[i]["HUseFlag"]); DetailColl.Add(oSub); } sReturn = "显示单据成功!"; return true; } catch (Exception e) { sReturn = e.Message; throw (e); } } #endregion } }