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 AutoSplitProductionValueToReversed(decimal changeValue, bool igoreReserved = false, bool loopDeep = true) { var sql = String.Format(@"select * from S_EP_CBSNode with(nolock) where ParentID='{0}' and NodeType='{1}' ", this.GetValue("ID"), CBSNodeType.Reserved.ToString()); DataTable dt = new DataTable(); #region 判定是否直接将变更金额分解至子节点 var splitToChildren = false; if (igoreReserved) { splitToChildren = true; } else { dt = this.DB.ExecuteDataTable(sql); if (dt.Rows.Count == 0) { splitToChildren = true; } } #endregion if (splitToChildren) { //说明没有定义预留节点 sql = String.Format(@"select S_EP_CBSNode.*,isnull(ReservedValue,0) as ReservedValue, isnull(ProductionValue,0)- ISNULL(ReservedValue,0) SplitProductionValue, isnull(ProductionValue,0)- ISNULL(ReservedValue,0) -ISNULL(ProductionSettleValue,0) as RemainProductionValue from S_EP_CBSNode left join (select Sum(ProductionValue) as ReservedValue,ParentID from S_EP_CBSNode where NodeType='{1}' group by ParentID) ReservedInfo on ReservedInfo.ParentID=S_EP_CBSNode.ID where NodeType<>'{2}' and S_EP_CBSNode.ParentID= '{0}' and AccountNodeType like '%Production%' and NodeType<>'{1}' order by SortIndex", this.GetValue("ID"), CBSNodeType.Reserved.ToString(), CBSNodeType.Communal.ToString()); var children = this.DB.ExecuteDataTable(sql); var obj = children.Compute(" Sum(RemainProductionValue) ", ""); var sumRemain = 0m; if (obj != null && obj != DBNull.Value) { sumRemain = Convert.ToDecimal(obj); } if (sumRemain == 0) { return; } foreach (DataRow item in children.Rows) { var cbsDic = FormulaHelper.DataRowToDic(item); var remainValue = String.IsNullOrEmpty(cbsDic.GetValue("RemainProductionValue")) ? 0m : Convert.ToDecimal(cbsDic.GetValue("RemainProductionValue")); var addValue = changeValue * remainValue / sumRemain; var productionValue = String.IsNullOrEmpty(cbsDic.GetValue("ProductionValue")) ? 0m : Convert.ToDecimal(cbsDic.GetValue("ProductionValue")); var newValue = productionValue + addValue; cbsDic.SetValue("ProductionValue", newValue); cbsDic.UpdateDB(this.DB, "S_EP_CBSNode", cbsDic.GetValue("ID")); var cbsNode = new S_EP_CBSNode(cbsDic); if (loopDeep) { cbsNode.AutoSplitProductionValueToReversed(addValue, igoreReserved, loopDeep); } } } else { var reservedNodeDic = FormulaHelper.DataRowToDic(dt.Rows[0]); var productionValue = String.IsNullOrEmpty(reservedNodeDic.GetValue("ProductionValue")) ? 0 : Convert.ToDecimal(reservedNodeDic.GetValue("ProductionValue")); var sumValue = productionValue + changeValue; reservedNodeDic.SetValue("ProductionValue", sumValue); reservedNodeDic.UpdateDB(this.DB, "S_EP_CBSNode", reservedNodeDic.GetValue("ID")); } }