using System; using System.Collections.Generic; using System.Text; using System.Data; namespace DAL { public class ClsGy_CostAverageType_Ctl:DBUtility.ClsGy_Base_Ctl { SQLHelper.ClsCN oCn = new SQLHelper.ClsCN(); //原代码 用于 替换子项目 public string HOldNumber; public Model.ClsGy_CostAverageType_Model oModel = new Model.ClsGy_CostAverageType_Model(); public List DetailColl = new List(); //新增 public override bool AddNew(ref string sReturn) { try { oCn.BeginTran(); oCn.RunProc($@" INSERT INTO {MvarItemKey} (HNumber, HName, HShortNumber, HParentID, HLevel, HEndFlag, HStopflag, HRemark, HHelpCode, HUseFlag, HMakeTime, HMakeEmp, HUSEORGID, HCREATEORGID, HAverageRemark) VALUES ('{oModel.HNumber}', '{oModel.HName}', '{oModel.HShortNumber}', '{oModel.HParentID}', '{oModel.HLevel}', '{oModel.HEndFlag}', '{oModel.HStopflag}', '{oModel.HRemark}', '{oModel.HHelpCode}', '{oModel.HUseFlag}', getdate(), '{oModel.HMakeEmp}', '{oModel.HUSEORGID}', '{oModel.HCREATEORGID}', '{oModel.HAverageRemark}' ) ", ref sReturn); //修改上级为非末级代码 oCn.RunProc("Update " + MvarItemKey + " set HEndflag=0 where HItemID=" + oModel.HParentID, ref sReturn); DataSet dss= oCn.RunProcReturn("select MAX(HItemID) as HInterID from Gy_CostAverageType", "Gy_CostAverageType"); int HInterID = Convert.ToInt32(dss.Tables[0].Rows[0]["HInterID"]); oCn.RunProc("Delete From " + "Gy_CostAverageTypeSub" + " where HInterID=" + HInterID); //插入子表 if (DetailColl != null && DetailColl.Count > 0) { foreach (Model.ClsGy_CostAverageTypeSub_Model oSub in DetailColl) { if (oSub == null) continue; string subSql = "insert into Gy_CostAverageTypeSub" + "(HInterID,HEntryID,HSourceInterID,HSourceEntryID,HSourceBillNo,HSourceBillType" + ",HWeight,HMaterTypeID" + ")" + " values(" + HInterID + "," + (oSub.HEntryID != null ? oSub.HEntryID.ToString() : "0") + "," + (oSub.HSourceInterID != null && oSub.HSourceInterID != 0 ? oSub.HSourceInterID.ToString() : "0") + "," + (oSub.HSourceEntryID != null && oSub.HSourceEntryID != 0 ? oSub.HSourceEntryID.ToString() : "0") + ",'" + (oSub.HSourceBillNo ?? "") + "','" + (oSub.HSourceBillType ?? "") + "'," + (oSub.HWeight != null && oSub.HWeight != 0 ? oSub.HWeight.ToString() : "0") + "," + (oSub.HMaterTypeID != null && oSub.HMaterTypeID != 0 ? oSub.HMaterTypeID.ToString() : "0") + ")"; oCn.RunProc(subSql); } } oCn.Commit(); return true; } catch (Exception e) { oCn.RollBack(); throw (e); } } //修改 public override bool ModifyByID(Int64 sItemID, ref string sReturn) { try { oCn.BeginTran(); oCn.RunProc($@" UPDATE {MvarItemKey} SET HNumber='{oModel.HNumber}', HName='{oModel.HName}', HShortNumber='{oModel.HShortNumber}', HParentID='{oModel.HParentID}', HLevel='{oModel.HLevel}', HEndFlag='{oModel.HEndFlag}', HStopflag='{oModel.HStopflag}', HRemark='{oModel.HRemark}', HHelpCode='{oModel.HHelpCode}', HUseFlag='{oModel.HUseFlag}', HModifyEmp='{oModel.HModifyEmp}', HModifyTime=getdate(), HUSEORGID='{oModel.HUSEORGID}', HCREATEORGID='{oModel.HCREATEORGID}', HAverageRemark='{oModel.HAverageRemark}' WHERE HItemID='{oModel.HItemID}' ", ref sReturn); //修改子项目代码 // oCn.RunProc("exec h_p_Gy_UpdateNumber '" + MvarItemKey + "','" + oModel.HNumber + ".','" + this.HOldNumber + ".'", ref DBUtility.ClsPub.sExeReturnInfo); //将上级 为非末级 oCn.RunProc("Update " + MvarItemKey + " set HEndflag=0 where HItemID=" + oModel.HParentID, ref sReturn); // oCn.RunProc("Delete From " + "Gy_CostAverageTypeSub" + " where HInterID=" + oModel.HItemID); //插入子表 if (DetailColl != null && DetailColl.Count > 0) { foreach (Model.ClsGy_CostAverageTypeSub_Model oSub in DetailColl) { if (oSub == null) continue; string subSql = "insert into Gy_CostAverageTypeSub" + "(HInterID,HEntryID,HSourceInterID,HSourceEntryID,HSourceBillNo,HSourceBillType" + ",HWeight,HMaterTypeID" + ")" + " values(" + oModel.HItemID + "," + (oSub.HEntryID != null ? oSub.HEntryID.ToString() : "0") + "," + (oSub.HSourceInterID != null && oSub.HSourceInterID != 0 ? oSub.HSourceInterID.ToString() : "0") + "," + (oSub.HSourceEntryID != null && oSub.HSourceEntryID != 0 ? oSub.HSourceEntryID.ToString() : "0") + ",'" + (oSub.HSourceBillNo ?? "") + "','" + (oSub.HSourceBillType ?? "") + "'," + (oSub.HWeight != null && oSub.HWeight != 0 ? oSub.HWeight.ToString() : "0") + "," + (oSub.HMaterTypeID != null && oSub.HMaterTypeID != 0 ? oSub.HMaterTypeID.ToString() : "0") + ")"; oCn.RunProc(subSql); } } oCn.Commit(); return true; } catch (Exception e) { oCn.RollBack(); throw (e); } } //根据代码判断信息 public override bool HavParentCode(string sCode, Int64 sItemID) { DataSet DS; try { DS = oCn.RunProcReturn("Select * from " + MvarItemKey + " Where HStopflag=0 and HNumber='" + sCode + "' and HItemID<>" + sItemID, MvarItemKey, ref Pub_Class.ClsPub.sExeReturnInfo); if (DS.Tables[0].Rows.Count == 0) return false; else { oModel.HItemID = Convert.ToInt64(DS.Tables[0].Rows[0]["HItemID"]); return true; } } catch (Exception e) { throw (e); } } //构造函数 public ClsGy_CostAverageType_Ctl() { MvarItemKey = "Gy_CostAverageType"; MvarReportTitle = "成本分配类型设置"; oModel = new Model.ClsGy_CostAverageType_Model(); } } }