public void Push() { var detailDt = this.DB.ExecuteDataTable(String.Format("SELECT * FROM S_EP_BudgetVersion_Detail WHERE S_EP_BudgetVersionID='{0}'", this.ModelDic.GetValue("ID"))); var detailList = FormulaHelper.DataTableToListDic(detailDt); foreach (var detail in detailList) { var modifyState = detail.GetValue("ModifyState"); if (modifyState == ModifyState.Added.ToString()) { //新增节点 var parentNodeDic = this.GetDataDicByID("S_EP_CBSNode", detail.GetValue("CBSParentID")); if (parentNodeDic == null) { throw new Formula.Exceptions.BusinessValidationException("没有找到CBS节点,无法同步新增"); } var parentNode = new S_EP_CBSNode(parentNodeDic); var cbsNode = new Dictionary <string, object>(); cbsNode.SetValue("ID", detail.GetValue("CBSID")); cbsNode.SetValue("Code", detail.GetValue("Code")); cbsNode.SetValue("Name", detail.GetValue("Name")); cbsNode.SetValue("BudgetValue", detail.GetValue("TotalValue")); cbsNode.SetValue("SortIndex", detail.GetValue("SortIndex")); parentNode.AddChild(cbsNode); } else if (modifyState == ModifyState.Removed.ToString()) { //删除节点 this.DB.ExecuteNonQuery(String.Format("DELETE FROM S_EP_CBSNode WHERE ID='{0}'", detail.GetValue("CBSID"))); } else { //更新节点 var nodeDic = new Dictionary <string, object>(); nodeDic.SetValue("ID", detail.GetValue("CBSID")); nodeDic.SetValue("Name", detail.GetValue("Name")); nodeDic.SetValue("BudgetValue", detail.GetValue("TotalValue")); nodeDic.SetValue("UnitPrice", detail.GetValue("UnitPrice")); nodeDic.SetValue("Quantity", detail.GetValue("Quantity")); nodeDic.UpdateDB(this.DB, "S_EP_CBSNode", nodeDic.GetValue("ID")); } } var budgetDic = this.BudgetUnit.ModelDic; if (String.IsNullOrEmpty(budgetDic.GetValue("CreateUser"))) { budgetDic.SetValue("CreateUser", this.ModelDic.GetValue("RegisterUserName")); budgetDic.SetValue("CreateUserID", this.ModelDic.GetValue("RegisterUser")); budgetDic.SetValue("CreateDate", DateTime.Now); } this.BudgetNode.SummaryBudgetValue(); budgetDic.SetValue("ModifyUser", this.ModelDic.GetValue("RegisterUserName")); budgetDic.SetValue("ModifyUserID", this.ModelDic.GetValue("RegisterUser")); budgetDic.SetValue("ModifyDate", DateTime.Now); budgetDic.SetValue("TotalBudgetValue", this.ModelDic.GetValue("BudgetValue")); budgetDic.UpdateDB(this.DB, "S_EP_BudgetUnit", budgetDic.GetValue("ID")); this._SumBudgetToTop(this.BudgetNode.ParentNode); this._UpdateChildren(this.BudgetNode.Children); }
public void Push() { var cbsDic = this.GetDataDicByID("S_EP_CBSNode", this.ModelDic.GetValue("CBSNode")); if (cbsDic == null) { throw new Formula.Exceptions.BusinessValidationException("没有找到对应的产值节点,无法补贴产值"); } cbsDic.SetValue("ProductionValue", this.ModelDic.GetValue("ProductionValue")); var cbsNode = new S_EP_CBSNode(cbsDic); var defineChildren = cbsNode.DefineNode.ChildrenNode.Where(c => c.ModelDic.GetValue("NodeType") != CBSNodeType.Communal.ToString() && c.ModelDic.GetValue("NodeType") != CBSNodeType.Reserved.ToString()).ToList(); if (defineChildren.Count > 0) { //判定结构定义中是否有子节点,如果有才能够对子节点进行操作 var detailRows = this.DB.ExecuteDataTable(String.Format("select * from S_EP_ProductionSubsidyApply_Detail where S_EP_ProductionSubsidyApplyID='{0}'" , this.ModelDic.GetValue("ID"))); foreach (DataRow detailRow in detailRows.Rows) { var detail = FormulaHelper.DataRowToDic(detailRow); #region 步更新产值CBS节点明细 var child = this.GetDataDicByID("S_EP_CBSNode", detail.GetValue("CBSID")); if (child == null) { continue; } else { child.SetValue("Name", detail.GetValue("Name")); if (!String.IsNullOrEmpty(detail.GetValue("Code"))) { child.SetValue("Code", detail.GetValue("Code")); } child.SetValue("RelateID", detail.GetValue("RelateID")); child.SetValue("ChargerDept", detail.GetValue("ChargerDept")); child.SetValue("ChargerDeptName", detail.GetValue("ChargerDeptName")); child.SetValue("ChargerUser", detail.GetValue("ChargerUser")); child.SetValue("ChargerUserName", detail.GetValue("ChargerUserName")); child.SetValue("ProductionValue", detail.GetValue("ProductionValueNew")); child.UpdateDB(this.DB, "S_EP_CBSNode", child.GetValue("ID")); this.DB.ExecuteNonQuery(String.Format("update S_EP_ProductionUnit set ProductionValue={0} where CBSNodeID='{1}'", String.IsNullOrEmpty(detail.GetValue("ProductionValueNew")) ? "0" : detail.GetValue("ProductionValueNew"), child.GetValue("ID"))); var childNode = new S_EP_CBSNode(child); childNode.SetUnit(); var changeValue = String.IsNullOrEmpty(detail.GetValue("AdjustValue")) ? 0m : Convert.ToDecimal(detail.GetValue("AdjustValue")); childNode.AutoSplitProductionValueToReversed(changeValue); } #endregion setChangeLoad(detail); } } if (cbsNode.DefineNode.ChildrenNode.Count(c => c.ModelDic.GetValue("NodeType") == CBSNodeType.Reserved.ToString()) > 0) { //当节点定义中有预留节点时,才能进行预留 #region 更新预留产值节点 var reserverNode = cbsNode.Children.FirstOrDefault(c => c.ModelDic.GetValue("NodeType") == CBSNodeType.Reserved.ToString()); if (reserverNode == null) { if (!String.IsNullOrEmpty(this.ModelDic.GetValue("ProductionReserveValue")) && Convert.ToDecimal(this.ModelDic.GetValue("ProductionReserveValue")) > 0) { var revDic = new Dictionary <string, object>(); revDic.SetValue("Name", "产值预留"); revDic.SetValue("Code", "Reserves"); revDic.SetValue("NodeType", CBSNodeType.Reserved.ToString()); var defineNode = cbsNode.Children.FirstOrDefault(c => c.GetValue("NodeType") == CBSNodeType.Reserved.ToString()); revDic.SetValue("DefineID", defineNode.GetValue("ID")); revDic.SetValue("ProductionValue", Convert.ToDecimal(this.ModelDic.GetValue("ProductionReserveValue"))); revDic.SetValue("RelateID", cbsDic.GetValue("ID") + CBSNodeType.Reserved.ToString()); reserverNode = new S_EP_CBSNode(revDic); cbsNode.AddChild(reserverNode); } } else { reserverNode.ModelDic.SetValue("ProductionValue", String.IsNullOrEmpty(this.ModelDic.GetValue("ProductionReserveValue")) ? 0m : Convert.ToDecimal(this.ModelDic.GetValue("ProductionReserveValue"))); reserverNode.ModelDic.UpdateDB(this.DB, "S_EP_CBSNode", reserverNode.ModelDic.GetValue("ID")); } #endregion //如果有预留节点,当前节点的计划产值等于所有子节点计划产值汇总 //因为所有的计划产值必须在分解的时候全部分解完毕,如果暂不分解完成的,必须存放在预留节点内 //没有预留节点说明不能预留 cbsNode.SumProductionValue(); } else { cbsDic.SetValue("ProductionValue", this.ModelDic.GetValue("ProductionValue")); cbsDic.UpdateDB(this.DB, "S_EP_CBSNode", cbsDic.GetValue("ID")); } cbsNode.SumProductionValueToTop(); setChangeLoad(cbsDic); foreach (var ancestor in cbsNode.Ancestors) { setChangeLoad(ancestor.ModelDic); } }
public void Push() { var cbsInfoDic = this.GetDataDicByID("S_EP_CBSInfo", this.ModelDic.GetValue("CBSInfoID")); if (cbsInfoDic == null) { throw new Formula.Exceptions.BusinessValidationException("没有找到核算项目,无法变更"); } var cbsInfo = new S_EP_CBSInfo(cbsInfoDic); var defineNodeDt = this.InfrasDB.ExecuteDataTable(String.Format(@"SELECT * FROM S_EP_DefineCBSNode WHERE DefineID='{0}' ", cbsInfoDic.GetValue("CBSDefineInfoID"))); defineNodeDt.PrimaryKey = new DataColumn[] { defineNodeDt.Columns["ID"] }; var detailDt = this.DB.ExecuteDataTable(@"SELECT * FROM S_EP_CBSInfoSchema_CBSNodeInfo WHERE S_EP_CBSInfoSchemaID='" + this.ModelDic.GetValue("ID") + "'"); var sqlCommand = new StringBuilder(); var addedList = new List <Dictionary <string, object> >(); foreach (DataRow row in detailDt.Rows) { if (row["ModifyState"] == null || row["ModifyState"] == DBNull.Value) { continue; } if (row["ModifyState"].ToString() == ModifyState.Added.ToString()) { var cbsNode = this.GetDataDicByID("S_EP_CBSNode", row["CBSNodeID"].ToString()); if (cbsNode != null) { Formula.LogWriter.Error("新增节点时候,CBS节点ID已存在,记录ID 为【" + row["ID"] + "】"); continue; } var defineNodeRow = defineNodeDt.Rows.Find(row["CBSDefineID"].ToString()); if (defineNodeRow == null) { Formula.LogWriter.Error("新增节点时候,没有找到CBS定义节点,记录ID 为【" + row["ID"] + "】"); continue; } var cbsNodeDic = FormulaHelper.DataRowToDic(row); cbsNodeDic.SetValue("ID", row["CBSNodeID"].ToString()); cbsNodeDic.SetValue("CBSInfoID", cbsInfoDic.GetValue("ID")); cbsNodeDic.SetValue("ParentID", row["CBSParentID"].ToString()); cbsNodeDic.SetValue("DefineID", row["CBSDefineID"].ToString()); cbsNodeDic.SetValue("FullID", row["CBSNodeFullID"].ToString()); cbsNodeDic.SetValue("NodeType", row["NodeType"].ToString()); cbsNodeDic.SetValue("CBSType", cbsInfoDic.GetValue("Type")); if (String.IsNullOrEmpty(cbsNodeDic.GetValue("Code"))) { cbsNodeDic.SetValue("Code", cbsInfoDic.GetValue("Code")); } cbsNodeDic.InsertDB(this.DB, "S_EP_CBSNode", cbsNodeDic.GetValue("ID")); addedList.Add(cbsNodeDic); cbsInfo.setUnit(cbsNodeDic, row, defineNodeRow); #region 自动增加静态节点 var staticDefineNodeList = defineNodeDt.AsEnumerable().Where(c => c["FullID"] != DBNull.Value && c["FullID"].ToString().StartsWith(defineNodeRow["FullID"].ToString()) && c["IsDynamic"].ToString() != "true"). OrderBy(c => c["FullID"].ToString()).ToList(); foreach (var staticDefineNodeRow in staticDefineNodeList) { var parentCBSNodeRows = addedList.Where(c => c["DefineID"] != DBNull.Value && c["DefineID"].ToString() == staticDefineNodeRow["ParentID"].ToString()).ToList(); foreach (var parentNodeRow in parentCBSNodeRows) { var staticNode = addedList.AsEnumerable().FirstOrDefault(c => c["ParentID"] != DBNull.Value && c["ParentID"].ToString() == parentNodeRow["ID"].ToString() && c["DefineID"] != DBNull.Value && c["DefineID"].ToString() == staticDefineNodeRow["ID"].ToString()); if (staticNode == null) { staticNode = new Dictionary <string, object>(); var staticDefineNodeDic = FormulaHelper.DataRowToDic(staticDefineNodeRow); var parentCBS = new S_EP_CBSNode(parentNodeRow); staticNode.SetValue("ID", FormulaHelper.CreateGuid()); staticNode.SetValue("DefineID", staticDefineNodeRow["ID"]); staticNode.SetValue("Name", staticDefineNodeRow["Name"]); staticNode.SetValue("Code", staticDefineNodeRow["Code"]); staticNode.SetValue("NodeType", staticDefineNodeRow["NodeType"]); if (staticNode.GetValue("NodeType") == CBSNodeType.Subject.ToString()) { staticNode.SetValue("SubjectID", staticDefineNodeRow["SubjectID"]); staticNode.SetValue("SubjectType", staticDefineNodeRow["SubjectType"]); staticNode.SetValue("Code", staticDefineNodeRow["SubjectCode"]); staticNode.SetValue("SubjectFullCode", staticDefineNodeRow["SubjectFullCode"]); } staticNode.SetValue("CBSType", cbsInfoDic.GetValue("Type")); staticNode.SetValue("ChargerUser", cbsInfoDic.GetValue("ChargerUser")); staticNode.SetValue("ChargerUserName", cbsInfoDic.GetValue("ChargerUserName")); staticNode.SetValue("ChargerDept", cbsInfoDic.GetValue("ChargerDept")); staticNode.SetValue("ChargerDeptName", cbsInfoDic.GetValue("ChargerDeptName")); staticNode.SetValue("ContractInfoID", cbsInfoDic.GetValue("ContractInfoID")); staticNode.SetValue("ProjectInfoID", cbsInfoDic.GetValue("ProjectInfoID")); staticNode.SetValue("EngineeringInfoID", cbsInfoDic.GetValue("EngineeringInfoID")); staticNode.SetValue("ClueInfoID", cbsInfoDic.GetValue("ClueInfoID")); parentCBS.AddChild(staticNode); addedList.Add(staticNode); } } } #endregion } else if (row["ModifyState"].ToString() == ModifyState.Modified.ToString()) { #region var cbsNode = this.GetDataDicByID("S_EP_CBSNode", row["CBSNodeID"].ToString()); if (cbsNode == null) { continue; } cbsNode.SetValue("Name", row["Name"]); cbsNode.SetValue("Code", row["Code"]); cbsNode.SetValue("ChargerUser", row["ChargerUser"]); cbsNode.SetValue("ChargerUserName", row["ChargerUserName"]); cbsNode.SetValue("ChargerDept", row["ChargerDept"]); cbsNode.SetValue("ChargerDeptName", row["ChargerDeptName"]); cbsNode.SetValue("ContractValue", row["ContractValue"]); cbsNode.SetValue("ContractTaxValue", row["ContractTaxValue"]); cbsNode.SetValue("ContractClearValue", row["ContractClearValue"]); cbsNode.SetValue("TaxRate", row["TaxRate"]); cbsNode.SetValue("DefineID", row["CBSDefineID"]); cbsNode.SetValue("NodeType", row["NodeType"]); sqlCommand.AppendLine(cbsNode.CreateUpdateSql(this.DB, "S_EP_CBSNode", cbsNode.GetValue("ID"))); #endregion var defineNodeRow = defineNodeDt.Rows.Find(row["CBSDefineID"].ToString()); if (defineNodeRow == null) { Formula.LogWriter.Error("新增节点时候,没有找到CBS定义节点,记录ID 为【" + row["ID"] + "】"); continue; } cbsInfo.setUnit(cbsNode, row, defineNodeRow); } else if (row["ModifyState"].ToString() == ModifyState.Removed.ToString()) { var cbsNode = this.GetDataDicByID("S_EP_CBSNode", row["CBSNodeID"].ToString()); if (cbsNode == null) { continue; } var node = new S_EP_CBSNode(cbsNode); node.Delete(); } } if (!String.IsNullOrEmpty(sqlCommand.ToString())) { this.DB.ExecuteNonQuery(sqlCommand.ToString()); } }