2328 lines
		
	
	
		
			117 KiB
		
	
	
	
		
			C#
		
	
	
	
		
		
			
		
	
	
			2328 lines
		
	
	
		
			117 KiB
		
	
	
	
		
			C#
		
	
	
	
|  | using BLL; | |||
|  | using Newtonsoft.Json.Linq; | |||
|  | using System; | |||
|  | using System.Collections.Generic; | |||
|  | using System.Linq; | |||
|  | using System.Web.UI.WebControls; | |||
|  | 
 | |||
|  | namespace FineUIPro.Web.JDGL.WBSWeights | |||
|  | { | |||
|  |     public partial class WeightsAudit : PageBase | |||
|  |     { | |||
|  |         #region 定义项 | |||
|  |         private static List<string> noApproveInstallationIds = new List<string>(); | |||
|  |         private static List<string> noApproveCnProfessionIds = new List<string>(); | |||
|  |         private static List<string> noApproveUnitProjectIds = new List<string>(); | |||
|  |         private static List<string> noApproveWbsSetIds = new List<string>(); | |||
|  |         #endregion | |||
|  | 
 | |||
|  |         #region  页面加载 | |||
|  |         /// <summary> | |||
|  |         /// 页面加载 | |||
|  |         /// </summary> | |||
|  |         /// <param name="sender"></param> | |||
|  |         /// <param name="e"></param> | |||
|  |         protected void Page_Load(object sender, EventArgs e) | |||
|  |         { | |||
|  |             if (!IsPostBack) | |||
|  |             { | |||
|  |                 List<string> parentUnitWorkIds = new List<string>(); | |||
|  |                 List<string> wbsSetIds = new List<string>(); | |||
|  |                 noApproveInstallationIds.Clear(); | |||
|  |                 noApproveCnProfessionIds.Clear(); | |||
|  |                 noApproveUnitProjectIds.Clear(); | |||
|  |                 noApproveWbsSetIds.Clear(); | |||
|  | 
 | |||
|  |                 if (this.CurrUser.Account == BLL.Const.sysglyId) | |||
|  |                 { | |||
|  |                     this.btnUpdateInstallationWeights.Hidden = false; | |||
|  |                 } | |||
|  |                 GetButtonPower(); | |||
|  |                 InitTreeMenu(); | |||
|  |                 this.Grid1.Hidden = true; | |||
|  |                 this.Grid2.Hidden = true; | |||
|  |             } | |||
|  |             else | |||
|  |             { | |||
|  |                 if (GetRequestEventArgument() == "UPDATE_SUMMARY") | |||
|  |                 { | |||
|  |                     // 页面要求重新计算合计行的值 | |||
|  |                     OutputSummaryData(); | |||
|  |                 } | |||
|  |             } | |||
|  |         } | |||
|  |         #endregion | |||
|  | 
 | |||
|  |         #region 合计权重 | |||
|  |         /// <summary> | |||
|  |         /// 合计权重 | |||
|  |         /// </summary> | |||
|  |         private void OutputSummaryData() | |||
|  |         { | |||
|  |             Grid1.CommitChanges(); | |||
|  |             decimal lastWeights = 0, lastWeightsMoneys = 0; | |||
|  |             decimal totalWeights = 0, totalWeightsMoneys = 0; | |||
|  |             decimal firstWeightsMoneys = 0; | |||
|  |             decimal changedWeights = 0, changeWeightsMoneys = 0; | |||
|  |             decimal totalOtherWeights = 0, totalOtherWeightsMoneys = 0; | |||
|  |             int i = 0, j = 0; | |||
|  | 
 | |||
|  |             JObject firstValue = Grid1.GetMergedData()[0].Value<JObject>("values"); | |||
|  |             firstWeightsMoneys = firstValue.Value<decimal>("WeightsMoney"); | |||
|  | 
 | |||
|  |             foreach (JObject mergedRow in Grid1.GetMergedData()) | |||
|  |             { | |||
|  |                 if (j > 0) | |||
|  |                 { | |||
|  |                     JObject values = mergedRow.Value<JObject>("values"); | |||
|  | 
 | |||
|  |                     string id = values.Value<string>("Id"); | |||
|  |                     string type = values.Value<string>("Type"); | |||
|  | 
 | |||
|  |                     if (values["Weights"].ToString() != "" && values["WeightsMoney"].ToString() != "") | |||
|  |                     { | |||
|  | 
 | |||
|  |                         totalWeights += values.Value<decimal>("Weights"); | |||
|  |                         totalWeightsMoneys += values.Value<decimal>("WeightsMoney"); | |||
|  | 
 | |||
|  |                         if (values["WeightsChanged"].ToString() != "") | |||
|  |                         { | |||
|  |                             changedWeights = values.Value<decimal>("WeightsChanged"); | |||
|  |                         } | |||
|  |                         if (values["WeightsMoneyChange"].ToString() != "") | |||
|  |                         { | |||
|  |                             changeWeightsMoneys = values.Value<decimal>("WeightsMoneyChange"); | |||
|  |                         } | |||
|  |                         // 获得除变化的所有其它项的权重的和 | |||
|  |                         if (values.Value<decimal>("Weights") == changedWeights && values.Value<decimal>("WeightsMoney") == changeWeightsMoneys) | |||
|  |                         { | |||
|  |                             totalOtherWeights += values.Value<decimal>("Weights"); | |||
|  |                             totalOtherWeightsMoneys += values.Value<decimal>("WeightsMoney"); | |||
|  |                         } | |||
|  |                     } | |||
|  |                 } | |||
|  |                 j++; | |||
|  |             } | |||
|  | 
 | |||
|  |             foreach (JObject mergedRow in Grid1.GetMergedData()) | |||
|  |             { | |||
|  |                 if (i > 0) | |||
|  |                 { | |||
|  |                     decimal weights = 0, weightsMoneys = 0; | |||
|  |                     changeWeightsMoneys = 0; | |||
|  |                     changedWeights = 0; | |||
|  |                     JObject values = mergedRow.Value<JObject>("values"); | |||
|  |                     string id = values.Value<string>("Id"); | |||
|  |                     string type = values.Value<string>("Type"); | |||
|  | 
 | |||
|  |                     if (values["Weights"].ToString() != "") | |||
|  |                     { | |||
|  |                         weights = values.Value<decimal>("Weights"); | |||
|  |                     } | |||
|  |                     if (values["WeightsMoney"].ToString() != "") | |||
|  |                     { | |||
|  |                         weightsMoneys = values.Value<decimal>("WeightsMoney"); | |||
|  |                     } | |||
|  |                     if (values["WeightsMoneyChange"].ToString() != "") | |||
|  |                     { | |||
|  |                         changeWeightsMoneys = values.Value<decimal>("WeightsMoneyChange"); | |||
|  |                     } | |||
|  |                     if (values["WeightsChanged"].ToString() != "") | |||
|  |                     { | |||
|  |                         changedWeights = values.Value<decimal>("WeightsChanged"); | |||
|  |                     } | |||
|  | 
 | |||
|  |                     // 权重比率发生变化 | |||
|  |                     if (values["Weights"].ToString() != "") | |||
|  |                     { | |||
|  |                         if (changedWeights != values.Value<decimal>("Weights")) | |||
|  |                         { | |||
|  |                             if (totalWeights == 100) | |||
|  |                             { | |||
|  |                                 weightsMoneys = firstWeightsMoneys - totalOtherWeightsMoneys; | |||
|  |                             } | |||
|  |                             else | |||
|  |                             { | |||
|  |                                 weightsMoneys = decimal.Round((values.Value<decimal>("Weights") * firstWeightsMoneys / 100), 2); | |||
|  |                             } | |||
|  |                             lastWeights = values.Value<decimal>("Weights"); | |||
|  |                             lastWeightsMoneys = weightsMoneys; | |||
|  |                         } | |||
|  |                     } | |||
|  | 
 | |||
|  |                     // 权重发生变化 | |||
|  |                     if (values["WeightsMoney"].ToString() != "") | |||
|  |                     { | |||
|  |                         if (changeWeightsMoneys != values.Value<decimal>("WeightsMoney")) | |||
|  |                         { | |||
|  |                             if (totalWeightsMoneys == firstWeightsMoneys) | |||
|  |                             { | |||
|  |                                 weights = 100 - totalOtherWeights; | |||
|  |                             } | |||
|  |                             else | |||
|  |                             { | |||
|  |                                 weights = decimal.Round(((values.Value<decimal>("WeightsMoney") / firstWeightsMoneys) * 100), 2); | |||
|  |                             } | |||
|  |                             lastWeights = weights; | |||
|  |                             lastWeightsMoneys = values.Value<decimal>("WeightsMoney"); | |||
|  |                         } | |||
|  |                     } | |||
|  |                     // 当权重发生变化时,保存到数据库中 | |||
|  |                     if (changedWeights != weights || changedWeights != weightsMoneys) | |||
|  |                     { | |||
|  |                         if (type == "cnProfession") | |||
|  |                         { | |||
|  |                             Model.WBS_CnProfession wbs = BLL.CnProfessionService.GetCnProfessionByCnProfessionId(id); | |||
|  |                             if (wbs != null) | |||
|  |                             { | |||
|  |                                 wbs.Weights = weights; | |||
|  |                                 wbs.WeightsMoney = weightsMoneys; | |||
|  |                             } | |||
|  |                         } | |||
|  |                         if (type == "unitProject" || type == "childUnitProject") | |||
|  |                         { | |||
|  |                             Model.Wbs_UnitProject unit = BLL.UnitProjectService.GetUnitProjectByUnitProjectId(id); | |||
|  |                             if (unit != null) | |||
|  |                             { | |||
|  |                                 unit.Weights = weights; | |||
|  |                                 unit.WeightsMoney = weightsMoneys; | |||
|  |                             } | |||
|  |                         } | |||
|  |                         if (type == "wbsSet") | |||
|  |                         { | |||
|  |                             Model.Wbs_WbsSet wbs = BLL.WbsSetService.GetWbsSetByWbsSetId(id); | |||
|  |                             if (wbs != null) | |||
|  |                             { | |||
|  |                                 wbs.Weights = weights; | |||
|  |                                 wbs.WeightsMoney = weightsMoneys; | |||
|  |                             } | |||
|  |                         } | |||
|  |                         Funs.DB.SubmitChanges(); | |||
|  |                     } | |||
|  |                     this.Grid1.Rows[i].Values[7] = weights; | |||
|  |                     this.Grid1.Rows[i].Values[8] = weightsMoneys; | |||
|  |                 } | |||
|  |                 i++; | |||
|  |             } | |||
|  |             BindGrid(); | |||
|  |             if (this.Grid1.Rows.Count > 1) | |||
|  |             { | |||
|  |                 JObject summary = new JObject(); | |||
|  |                 summary.Add("ChildName", "合计:"); | |||
|  |                 summary.Add("Weights", totalOtherWeights + lastWeights); | |||
|  |                 summary.Add("WeightsMoney", totalOtherWeightsMoneys + lastWeightsMoneys); | |||
|  | 
 | |||
|  |                 Grid1.SummaryData = summary; | |||
|  |             } | |||
|  |             else | |||
|  |             { | |||
|  |                 Grid1.SummaryData = null; | |||
|  |             } | |||
|  |         } | |||
|  |         #endregion | |||
|  | 
 | |||
|  |         #region  修改关闭窗口 | |||
|  |         /// <summary> | |||
|  |         /// 关闭窗口 | |||
|  |         /// </summary> | |||
|  |         /// <param name="sender"></param> | |||
|  |         /// <param name="e"></param> | |||
|  |         protected void Window1_Close(object sender, WindowCloseEventArgs e) | |||
|  |         { | |||
|  |             ShowNotify("设置成功!", MessageBoxIcon.Success); | |||
|  |         } | |||
|  |         #endregion | |||
|  | 
 | |||
|  |         #region  加载树 | |||
|  |         /// <summary> | |||
|  |         /// 加载树 | |||
|  |         /// </summary> | |||
|  |         private void InitTreeMenu() | |||
|  |         { | |||
|  |             this.trWBS.Nodes.Clear(); | |||
|  |             this.trWBS.ShowBorder = false; | |||
|  |             this.trWBS.ShowHeader = false; | |||
|  |             this.trWBS.EnableIcons = true; | |||
|  |             this.trWBS.AutoScroll = true; | |||
|  |             this.trWBS.EnableSingleClickExpand = true; | |||
|  |             var installations = from x in Funs.DB.Project_Installation where x.ProjectId == this.CurrUser.LoginProjectId && x.SuperInstallationId == "0" orderby x.InstallationCode select x; | |||
|  |             foreach (var installation in installations) | |||
|  |             { | |||
|  |                 TreeNode rootNode = new TreeNode(); | |||
|  |                 if (noApproveInstallationIds.Contains(installation.InstallationId)) | |||
|  |                 { | |||
|  |                     rootNode.Text = "<font color='#FF0000'>" + installation.InstallationName + "</font>"; | |||
|  |                 } | |||
|  |                 else | |||
|  |                 { | |||
|  |                     rootNode.Text = installation.InstallationName; | |||
|  |                 } | |||
|  |                 rootNode.NodeID = installation.InstallationId; | |||
|  |                 rootNode.CommandName = "installation"; | |||
|  |                 rootNode.CommandArgument = installation.Weights == null ? null : installation.Weights.ToString(); | |||
|  |                 rootNode.ToolTip = installation.InstallationCode; | |||
|  |                 rootNode.EnableExpandEvent = true; | |||
|  |                 rootNode.EnableClickEvent = true; | |||
|  |                 this.trWBS.Nodes.Add(rootNode); | |||
|  |                 TreeNode emptyNode = new TreeNode(); | |||
|  |                 emptyNode.Text = ""; | |||
|  |                 emptyNode.NodeID = ""; | |||
|  |                 rootNode.Nodes.Add(emptyNode); | |||
|  |             } | |||
|  |         } | |||
|  |         #endregion | |||
|  | 
 | |||
|  |         #region  展开树 | |||
|  |         /// <summary> | |||
|  |         /// 展开树 | |||
|  |         /// </summary> | |||
|  |         /// <param name="sender"></param> | |||
|  |         /// <param name="e"></param> | |||
|  |         protected void trWBS_NodeExpand(object sender, TreeNodeEventArgs e) | |||
|  |         { | |||
|  |             e.Node.Nodes.Clear(); | |||
|  |             if (e.Node.CommandName == "installation")  //展开装置/单元节点 | |||
|  |             { | |||
|  |                 var installations = from x in Funs.DB.Project_Installation | |||
|  |                                     where x.SuperInstallationId == e.Node.NodeID | |||
|  |                                     orderby x.InstallationCode | |||
|  |                                     select x; | |||
|  |                 if (installations.Count() > 0) | |||
|  |                 { | |||
|  |                     foreach (var installation in installations) | |||
|  |                     { | |||
|  |                         TreeNode newNode = new TreeNode(); | |||
|  |                         if (noApproveInstallationIds.Contains(installation.InstallationId)) | |||
|  |                         { | |||
|  |                             newNode.Text = "<font color='#FF0000'>" + installation.InstallationName + "</font>"; | |||
|  |                         } | |||
|  |                         else | |||
|  |                         { | |||
|  |                             newNode.Text = installation.InstallationName; | |||
|  |                         } | |||
|  |                         newNode.NodeID = installation.InstallationId; | |||
|  |                         newNode.CommandName = "installation"; | |||
|  |                         newNode.CommandArgument = installation.Weights == null ? null : installation.Weights.ToString(); | |||
|  |                         newNode.ToolTip = installation.InstallationCode; | |||
|  |                         newNode.EnableExpandEvent = true; | |||
|  |                         newNode.EnableClickEvent = true; | |||
|  |                         e.Node.Nodes.Add(newNode); | |||
|  |                         TreeNode emptyNode = new TreeNode(); | |||
|  |                         emptyNode.Text = ""; | |||
|  |                         emptyNode.NodeID = ""; | |||
|  |                         newNode.Nodes.Add(emptyNode); | |||
|  |                     } | |||
|  |                 } | |||
|  |                 else | |||
|  |                 { | |||
|  |                     var cnProfessions = from x in Funs.DB.WBS_CnProfession where x.InstallationId == e.Node.NodeID orderby x.OldId select x; | |||
|  |                     if (cnProfessions.Count() > 0)   //普通装置主项 | |||
|  |                     { | |||
|  |                         foreach (var cnProfession in cnProfessions) | |||
|  |                         { | |||
|  |                             var unitProjects = from x in Funs.DB.Wbs_UnitProject where x.CnProfessionId == cnProfession.CnProfessionId && x.IsApprove == true select x; | |||
|  |                             if (unitProjects.Count() > 0) | |||
|  |                             { | |||
|  |                                 TreeNode newNode = new TreeNode(); | |||
|  |                                 if (noApproveCnProfessionIds.Contains(cnProfession.CnProfessionId)) | |||
|  |                                 { | |||
|  |                                     newNode.Text = "<font color='#FF0000'>" + cnProfession.CnProfessionName + "</font>"; | |||
|  |                                 } | |||
|  |                                 else | |||
|  |                                 { | |||
|  |                                     newNode.Text = cnProfession.CnProfessionName; | |||
|  |                                 } | |||
|  |                                 newNode.NodeID = cnProfession.CnProfessionId; | |||
|  |                                 newNode.CommandName = "cnProfession"; | |||
|  |                                 newNode.CommandArgument = cnProfession.Weights == null ? null : cnProfession.Weights.ToString(); | |||
|  |                                 newNode.ToolTip = cnProfession.CnProfessionCode; | |||
|  |                                 newNode.EnableExpandEvent = true; | |||
|  |                                 newNode.EnableClickEvent = true; | |||
|  |                                 e.Node.Nodes.Add(newNode); | |||
|  |                                 TreeNode emptyNode = new TreeNode(); | |||
|  |                                 emptyNode.Text = ""; | |||
|  |                                 emptyNode.NodeID = ""; | |||
|  |                                 newNode.Nodes.Add(emptyNode); | |||
|  |                             } | |||
|  |                         } | |||
|  |                     } | |||
|  |                     else       //总图 | |||
|  |                     { | |||
|  |                         var unitProjects = from x in Funs.DB.Wbs_UnitProject where x.InstallationId == e.Node.NodeID && x.SuperUnitProjectId == null orderby x.SortIndex, x.UnitProjectCode select x; | |||
|  |                         foreach (var unitProject in unitProjects) | |||
|  |                         { | |||
|  |                             var wbsSets = from x in Funs.DB.Wbs_WbsSet where x.UnitProjectId == unitProject.UnitProjectId && x.IsApprove == true select x; | |||
|  |                             if (wbsSets.Count() > 0) | |||
|  |                             { | |||
|  |                                 TreeNode newNode = new TreeNode(); | |||
|  |                                 if (noApproveUnitProjectIds.Contains(unitProject.UnitProjectId)) | |||
|  |                                 { | |||
|  |                                     newNode.Text = "<font color='#FF0000'>" + unitProject.UnitProjectName + "</font>"; | |||
|  |                                 } | |||
|  |                                 else | |||
|  |                                 { | |||
|  |                                     newNode.Text = unitProject.UnitProjectName; | |||
|  |                                 } | |||
|  |                                 newNode.NodeID = unitProject.UnitProjectId; | |||
|  |                                 newNode.CommandName = "unitProject"; | |||
|  |                                 newNode.CommandArgument = unitProject.Weights == null ? null : unitProject.Weights.ToString(); | |||
|  |                                 newNode.ToolTip = unitProject.UnitProjectCode; | |||
|  |                                 newNode.EnableExpandEvent = true; | |||
|  |                                 newNode.EnableClickEvent = true; | |||
|  |                                 e.Node.Nodes.Add(newNode); | |||
|  |                                 TreeNode emptyNode = new TreeNode(); | |||
|  |                                 emptyNode.Text = ""; | |||
|  |                                 emptyNode.NodeID = ""; | |||
|  |                                 newNode.Nodes.Add(emptyNode); | |||
|  |                             } | |||
|  |                         } | |||
|  |                     } | |||
|  |                 } | |||
|  |             } | |||
|  |             else if (e.Node.CommandName == "cnProfession")   //展开专业节点 | |||
|  |             { | |||
|  |                 var unitProjects = from x in Funs.DB.Wbs_UnitProject where x.CnProfessionId == e.Node.NodeID && x.SuperUnitProjectId == null && x.IsApprove == true orderby x.SortIndex, x.UnitProjectCode select x; | |||
|  |                 foreach (var unitProject in unitProjects) | |||
|  |                 { | |||
|  |                     TreeNode newNode = new TreeNode(); | |||
|  |                     if (noApproveUnitProjectIds.Contains(unitProject.UnitProjectId)) | |||
|  |                     { | |||
|  |                         newNode.Text = "<font color='#FF0000'>" + unitProject.UnitProjectName + "</font>"; | |||
|  |                     } | |||
|  |                     else | |||
|  |                     { | |||
|  |                         newNode.Text = unitProject.UnitProjectName; | |||
|  |                     } | |||
|  |                     newNode.NodeID = unitProject.UnitProjectId; | |||
|  |                     newNode.CommandName = "unitProject"; | |||
|  |                     newNode.CommandArgument = unitProject.Weights == null ? null : unitProject.Weights.ToString(); | |||
|  |                     newNode.ToolTip = unitProject.UnitProjectCode; | |||
|  |                     newNode.EnableExpandEvent = true; | |||
|  |                     newNode.EnableClickEvent = true; | |||
|  |                     e.Node.Nodes.Add(newNode); | |||
|  |                     TreeNode emptyNode = new TreeNode(); | |||
|  |                     emptyNode.Text = ""; | |||
|  |                     emptyNode.NodeID = ""; | |||
|  |                     newNode.Nodes.Add(emptyNode); | |||
|  |                 } | |||
|  |             } | |||
|  |             else if (e.Node.CommandName == "unitProject")   //展开单位工程节点 | |||
|  |             { | |||
|  |                 var childUnitProjects = from x in Funs.DB.Wbs_UnitProject where x.SuperUnitProjectId == e.Node.NodeID && x.IsApprove == true orderby x.SortIndex, x.UnitProjectCode select x; | |||
|  |                 if (childUnitProjects.Count() > 0)   //存在子单位工程 | |||
|  |                 { | |||
|  |                     foreach (var childUnitProject in childUnitProjects) | |||
|  |                     { | |||
|  |                         TreeNode newNode = new TreeNode(); | |||
|  |                         if (noApproveUnitProjectIds.Contains(childUnitProject.UnitProjectId)) | |||
|  |                         { | |||
|  |                             newNode.Text = "<font color='#FF0000'>" + childUnitProject.UnitProjectName + "</font>"; | |||
|  |                         } | |||
|  |                         else | |||
|  |                         { | |||
|  |                             newNode.Text = childUnitProject.UnitProjectName; | |||
|  |                         } | |||
|  |                         newNode.NodeID = childUnitProject.UnitProjectId; | |||
|  |                         newNode.CommandName = "childUnitProject"; | |||
|  |                         newNode.CommandArgument = childUnitProject.Weights == null ? null : childUnitProject.Weights.ToString(); | |||
|  |                         newNode.ToolTip = childUnitProject.UnitProjectCode; | |||
|  |                         newNode.EnableExpandEvent = true; | |||
|  |                         newNode.EnableClickEvent = true; | |||
|  |                         e.Node.Nodes.Add(newNode); | |||
|  |                         TreeNode emptyNode = new TreeNode(); | |||
|  |                         emptyNode.Text = ""; | |||
|  |                         emptyNode.NodeID = ""; | |||
|  |                         newNode.Nodes.Add(emptyNode); | |||
|  |                     } | |||
|  |                 } | |||
|  |                 else     //不存在子单位工程,加载分部工程 | |||
|  |                 { | |||
|  |                     var wbsSet1s = from x in Funs.DB.Wbs_WbsSet where x.Flag == 1 && x.UnitProjectId == e.Node.NodeID && x.IsApprove == true && x.NoShow == null orderby x.SortIndex, x.WbsSetCode select x; | |||
|  |                     if (wbsSet1s.Count() > 0) | |||
|  |                     { | |||
|  |                         foreach (var wbsSet1 in wbsSet1s) | |||
|  |                         { | |||
|  |                             TreeNode newNode = new TreeNode(); | |||
|  |                             if (noApproveWbsSetIds.Contains(wbsSet1.WbsSetId)) | |||
|  |                             { | |||
|  |                                 newNode.Text = "<font color='#FF0000'>" + wbsSet1.WbsSetName + "</font>"; | |||
|  |                             } | |||
|  |                             else | |||
|  |                             { | |||
|  |                                 newNode.Text = wbsSet1.WbsSetName; | |||
|  |                             } | |||
|  |                             newNode.NodeID = wbsSet1.WbsSetId; | |||
|  |                             newNode.CommandName = "wbsSet"; | |||
|  |                             newNode.CommandArgument = wbsSet1.Weights == null ? null : wbsSet1.Weights.ToString(); | |||
|  |                             newNode.ToolTip = wbsSet1.WbsSetCode; | |||
|  |                             newNode.EnableExpandEvent = true; | |||
|  |                             newNode.EnableClickEvent = true; | |||
|  |                             e.Node.Nodes.Add(newNode); | |||
|  |                             var childWbsSets2 = BLL.WbsSetService.GetApproveWbsSetsBySuperWbsSetId(newNode.NodeID); | |||
|  |                             if (childWbsSets2.Count() > 0) | |||
|  |                             { | |||
|  |                                 TreeNode emptyNode = new TreeNode(); | |||
|  |                                 emptyNode.Text = ""; | |||
|  |                                 emptyNode.NodeID = ""; | |||
|  |                                 newNode.Nodes.Add(emptyNode); | |||
|  |                             } | |||
|  |                         } | |||
|  |                     } | |||
|  |                     else    //单位工程下直接是分项内容,如质量行为 | |||
|  |                     { | |||
|  |                         var wbsSet3s = from x in Funs.DB.Wbs_WbsSet where x.Flag == 3 && x.UnitProjectId == e.Node.NodeID && x.IsApprove == true && x.NoShow == null orderby x.SortIndex, x.WbsSetCode select x; | |||
|  |                         if (wbsSet3s.Count() > 0) | |||
|  |                         { | |||
|  |                             foreach (var wbsSet3 in wbsSet3s) | |||
|  |                             { | |||
|  |                                 TreeNode newNode = new TreeNode(); | |||
|  |                                 if (noApproveWbsSetIds.Contains(wbsSet3.WbsSetId)) | |||
|  |                                 { | |||
|  |                                     newNode.Text = "<font color='#FF0000'>" + wbsSet3.WbsSetName + "</font>"; | |||
|  |                                 } | |||
|  |                                 else | |||
|  |                                 { | |||
|  |                                     newNode.Text = wbsSet3.WbsSetName; | |||
|  |                                 } | |||
|  |                                 newNode.NodeID = wbsSet3.WbsSetId; | |||
|  |                                 newNode.CommandName = "wbsSet"; | |||
|  |                                 newNode.CommandArgument = wbsSet3.Weights == null ? null : wbsSet3.Weights.ToString(); | |||
|  |                                 newNode.ToolTip = wbsSet3.WbsSetCode; | |||
|  |                                 newNode.EnableExpandEvent = true; | |||
|  |                                 newNode.EnableClickEvent = true; | |||
|  |                                 e.Node.Nodes.Add(newNode); | |||
|  |                                 var childWbsSets2 = BLL.WbsSetService.GetApproveWbsSetsBySuperWbsSetId(newNode.NodeID); | |||
|  |                                 if (childWbsSets2.Count() > 0) | |||
|  |                                 { | |||
|  |                                     TreeNode emptyNode = new TreeNode(); | |||
|  |                                     emptyNode.Text = ""; | |||
|  |                                     emptyNode.NodeID = ""; | |||
|  |                                     newNode.Nodes.Add(emptyNode); | |||
|  |                                 } | |||
|  |                             } | |||
|  |                         } | |||
|  |                     } | |||
|  |                 } | |||
|  |             } | |||
|  |             else if (e.Node.CommandName == "childUnitProject")   //展开子单位工程节点 | |||
|  |             { | |||
|  |                 var wbsSet1s = from x in Funs.DB.Wbs_WbsSet where x.Flag == 1 && x.UnitProjectId == e.Node.NodeID && x.IsApprove == true && x.NoShow == null orderby x.SortIndex, x.WbsSetCode select x; | |||
|  |                 foreach (var wbsSet1 in wbsSet1s) | |||
|  |                 { | |||
|  |                     TreeNode newNode = new TreeNode(); | |||
|  |                     if (noApproveWbsSetIds.Contains(wbsSet1.WbsSetId)) | |||
|  |                     { | |||
|  |                         newNode.Text = "<font color='#FF0000'>" + wbsSet1.WbsSetName + "</font>"; | |||
|  |                     } | |||
|  |                     else | |||
|  |                     { | |||
|  |                         newNode.Text = wbsSet1.WbsSetName; | |||
|  |                     } | |||
|  |                     newNode.NodeID = wbsSet1.WbsSetId; | |||
|  |                     newNode.CommandName = "wbsSet"; | |||
|  |                     newNode.CommandArgument = wbsSet1.Weights == null ? null : wbsSet1.Weights.ToString(); | |||
|  |                     newNode.ToolTip = wbsSet1.WbsSetCode; | |||
|  |                     newNode.EnableExpandEvent = true; | |||
|  |                     newNode.EnableClickEvent = true; | |||
|  |                     e.Node.Nodes.Add(newNode); | |||
|  |                     var childWbsSets2 = BLL.WbsSetService.GetApproveWbsSetsBySuperWbsSetId(newNode.NodeID); | |||
|  |                     if (childWbsSets2.Count() > 0) | |||
|  |                     { | |||
|  |                         TreeNode emptyNode = new TreeNode(); | |||
|  |                         emptyNode.Text = ""; | |||
|  |                         emptyNode.NodeID = ""; | |||
|  |                         newNode.Nodes.Add(emptyNode); | |||
|  |                     } | |||
|  |                 } | |||
|  |             } | |||
|  |             else if (e.Node.CommandName == "wbsSet")   //展开分部/子分部/分项/子分项工程节点 | |||
|  |             { | |||
|  |                 var childWbsSets = BLL.WbsSetService.GetApproveWbsSetsBySuperWbsSetId(e.Node.NodeID); | |||
|  |                 foreach (var wbsSet in childWbsSets) | |||
|  |                 { | |||
|  |                     TreeNode newNode = new TreeNode(); | |||
|  |                     if (noApproveWbsSetIds.Contains(wbsSet.WbsSetId)) | |||
|  |                     { | |||
|  |                         newNode.Text = "<font color='#FF0000'>" + wbsSet.WbsSetName + "</font>"; | |||
|  |                     } | |||
|  |                     else | |||
|  |                     { | |||
|  |                         newNode.Text = wbsSet.WbsSetName; | |||
|  |                     } | |||
|  |                     newNode.NodeID = wbsSet.WbsSetId; | |||
|  |                     newNode.CommandName = "wbsSet"; | |||
|  |                     newNode.CommandArgument = wbsSet.Weights == null ? null : wbsSet.Weights.ToString(); | |||
|  |                     newNode.ToolTip = wbsSet.WbsSetCode; | |||
|  |                     newNode.EnableExpandEvent = true; | |||
|  |                     newNode.EnableClickEvent = true; | |||
|  |                     e.Node.Nodes.Add(newNode); | |||
|  |                     var childWbsSets2 = BLL.WbsSetService.GetApproveWbsSetsBySuperWbsSetId(newNode.NodeID); | |||
|  |                     if (childWbsSets2.Count() > 0) | |||
|  |                     { | |||
|  |                         TreeNode emptyNode = new TreeNode(); | |||
|  |                         emptyNode.Text = ""; | |||
|  |                         emptyNode.NodeID = ""; | |||
|  |                         newNode.Nodes.Add(emptyNode); | |||
|  |                     } | |||
|  |                 } | |||
|  |             } | |||
|  |         } | |||
|  |         #endregion | |||
|  | 
 | |||
|  |         #region  Tree点击事件 | |||
|  |         /// <summary> | |||
|  |         /// Tree点击事件 | |||
|  |         /// </summary> | |||
|  |         /// <param name="sender"></param> | |||
|  |         /// <param name="e"></param> | |||
|  |         protected void trWBS_NodeCommand(object sender, TreeCommandEventArgs e) | |||
|  |         { | |||
|  |             this.Grid1.Hidden = true; | |||
|  |             this.Grid2.Hidden = true; | |||
|  |             this.btnSave.Hidden = false; | |||
|  |             this.Grid2.Columns[7].Hidden = true; | |||
|  |             this.btnUpdateInstallationWeights.Hidden = true; | |||
|  |             if (this.trWBS.SelectedNode.CommandName != "installation" && this.trWBS.SelectedNode.CommandName != "cnProfession" && this.trWBS.SelectedNode.CommandName != "unitProject")   //非装置、专业、单位工程节点可以设置 | |||
|  |             { | |||
|  |                 if (this.trWBS.SelectedNode.CommandName == "childUnitProject") | |||
|  |                 { | |||
|  |                     var wbsSet1s = from x in Funs.DB.Wbs_WbsSet where x.UnitProjectId == this.trWBS.SelectedNodeID && x.Flag == 1 select x; | |||
|  |                     bool isShow = true;   //子单位工程下只有一级子级时可以设置、分配权重 | |||
|  |                     foreach (var wbsSet1 in wbsSet1s) | |||
|  |                     { | |||
|  |                         var wbsSet2s = from x in Funs.DB.Wbs_WbsSet where x.SuperWbsSetId == wbsSet1.WbsSetId select x; | |||
|  |                         if (wbsSet2s.Count() > 0) | |||
|  |                         { | |||
|  |                             isShow = false; | |||
|  |                             break; | |||
|  |                         } | |||
|  |                     } | |||
|  |                     if (isShow) | |||
|  |                     { | |||
|  |                         this.Grid2.Hidden = false; | |||
|  |                         this.Grid1.Hidden = false; | |||
|  |                         BindGrid2(); | |||
|  |                         BindGrid(); | |||
|  |                         OutputSummaryData(); | |||
|  |                     } | |||
|  |                     else | |||
|  |                     { | |||
|  |                         Model.Wbs_UnitProject unitProject = BLL.UnitProjectService.GetUnitProjectByUnitProjectId(this.trWBS.SelectedNodeID); | |||
|  |                         if (unitProject.EngineerQuantity != null)   //设置过工程量 | |||
|  |                         { | |||
|  |                             this.Grid2.Hidden = false; | |||
|  |                             BindGrid2(); | |||
|  |                             this.Grid2.Columns[7].Hidden = false; | |||
|  |                         } | |||
|  |                     } | |||
|  |                 } | |||
|  |                 else if (this.trWBS.SelectedNode.CommandName == "wbsSet") | |||
|  |                 { | |||
|  |                     var wbsSet1s = from x in Funs.DB.Wbs_WbsSet where x.SuperWbsSetId == this.trWBS.SelectedNodeID select x; | |||
|  |                     bool isShow = true;   //分部分项下只有一级子级时可以设置、分配权重 | |||
|  |                     if (wbsSet1s.Count() > 0) | |||
|  |                     { | |||
|  |                         foreach (var wbsSet1 in wbsSet1s) | |||
|  |                         { | |||
|  |                             var wbsSet2s = from x in Funs.DB.Wbs_WbsSet where x.SuperWbsSetId == wbsSet1.WbsSetId && x.IsApprove == true select x; | |||
|  |                             if (wbsSet2s.Count() > 0) | |||
|  |                             { | |||
|  |                                 isShow = false; | |||
|  |                                 break; | |||
|  |                             } | |||
|  |                         } | |||
|  |                         if (isShow) | |||
|  |                         { | |||
|  |                             this.Grid2.Hidden = false; | |||
|  |                             this.Grid1.Hidden = false; | |||
|  |                             BindGrid2(); | |||
|  |                             BindGrid(); | |||
|  |                             OutputSummaryData(); | |||
|  |                         } | |||
|  |                         else | |||
|  |                         { | |||
|  |                             Model.Wbs_WbsSet wbsSet = BLL.WbsSetService.GetWbsSetByWbsSetId(this.trWBS.SelectedNodeID); | |||
|  |                             if (wbsSet.EngineerQuantity != null)   //设置过工程量 | |||
|  |                             { | |||
|  |                                 this.Grid2.Hidden = false; | |||
|  |                                 BindGrid2(); | |||
|  |                                 this.Grid2.Columns[7].Hidden = false; | |||
|  |                             } | |||
|  |                         } | |||
|  |                     } | |||
|  |                 } | |||
|  |             } | |||
|  |             else if (this.trWBS.SelectedNode.CommandName == "installation") | |||
|  |             { | |||
|  |                 string installationId = this.trWBS.SelectedNodeID; | |||
|  |                 Model.Project_Installation installation = BLL.Project_InstallationService.GetInstallationByInstallationId(installationId); | |||
|  |                 if (installation.SuperInstallationId == "0") | |||
|  |                 { | |||
|  |                     this.Grid1.Hidden = false; | |||
|  |                     this.btnUpdateInstallationWeights.Hidden = false; | |||
|  |                     this.btnSave.Hidden = true; | |||
|  |                 } | |||
|  |             } | |||
|  |         } | |||
|  |         #endregion | |||
|  | 
 | |||
|  |         #region 没有审核的项 | |||
|  |         /// <summary> | |||
|  |         /// 没有审核的项 | |||
|  |         /// </summary> | |||
|  |         private string noAuditText = string.Empty; | |||
|  | 
 | |||
|  |         /// <summary> | |||
|  |         /// 判断上级是不是还有没审核权重项 | |||
|  |         /// </summary> | |||
|  |         /// <param name="parentId"></param> | |||
|  |         private void IsParentNoAudit(TreeNode tn) | |||
|  |         { | |||
|  |             if (tn.ParentNode != null) | |||
|  |             { | |||
|  |                 if (tn.ParentNode.CommandName == "wbsSet") | |||
|  |                 { | |||
|  |                     Model.Wbs_WbsSet wbsSet = BLL.WbsSetService.GetWbsSetByWbsSetId(tn.ParentNode.NodeID); | |||
|  |                     if (wbsSet != null && (wbsSet.IsWeightsApprove == null || wbsSet.IsWeightsApprove == false)) | |||
|  |                     { | |||
|  |                         noAuditText = noAuditText + wbsSet.WbsSetName + ","; | |||
|  |                     } | |||
|  |                 } | |||
|  | 
 | |||
|  |                 if (tn.ParentNode.CommandName == "unitProject" || tn.ParentNode.CommandName == "childUnitProject") | |||
|  |                 { | |||
|  |                     Model.Wbs_UnitProject unitProject = BLL.UnitProjectService.GetUnitProjectByUnitProjectId(tn.ParentNode.NodeID); | |||
|  |                     if (unitProject != null && (unitProject.IsWeightsApprove == null || unitProject.IsWeightsApprove == false)) | |||
|  |                     { | |||
|  |                         noAuditText = noAuditText + unitProject.UnitProjectName + ","; | |||
|  |                     } | |||
|  |                 } | |||
|  | 
 | |||
|  |                 if (tn.ParentNode.CommandName == "cnProfession") | |||
|  |                 { | |||
|  |                     Model.WBS_CnProfession cnProfession = BLL.CnProfessionService.GetCnProfessionByCnProfessionId(tn.ParentNode.NodeID); | |||
|  |                     if (cnProfession != null && (cnProfession.IsWeightsApprove == null || cnProfession.IsWeightsApprove == false)) | |||
|  |                     { | |||
|  |                         noAuditText = noAuditText + cnProfession.CnProfessionName + ","; | |||
|  |                     } | |||
|  |                 } | |||
|  |                 IsParentNoAudit(tn.ParentNode); | |||
|  |             } | |||
|  |         } | |||
|  | 
 | |||
|  |         /// <summary> | |||
|  |         /// 选择节点没有审核项 | |||
|  |         /// </summary> | |||
|  |         /// <param name="tn"></param> | |||
|  |         private void IsSelectNodeNoAudit(TreeNode tn) | |||
|  |         { | |||
|  |             if (tn != null) | |||
|  |             { | |||
|  |                 if (tn.CommandName == "wbsSet") | |||
|  |                 { | |||
|  |                     Model.Wbs_WbsSet wbsSet = BLL.WbsSetService.GetWbsSetByWbsSetId(tn.NodeID); | |||
|  |                     if (wbsSet != null && (wbsSet.IsWeightsApprove == null || wbsSet.IsWeightsApprove == false)) | |||
|  |                     { | |||
|  |                         noAuditText = noAuditText + wbsSet.WbsSetName + ","; | |||
|  |                     } | |||
|  |                 } | |||
|  | 
 | |||
|  |                 if (tn.CommandName == "unitProject" || tn.CommandName == "childUnitProject") | |||
|  |                 { | |||
|  |                     Model.Wbs_UnitProject unitProject = BLL.UnitProjectService.GetUnitProjectByUnitProjectId(tn.NodeID); | |||
|  |                     if (unitProject != null && (unitProject.IsWeightsApprove == null || unitProject.IsWeightsApprove == false)) | |||
|  |                     { | |||
|  |                         noAuditText = noAuditText + unitProject.UnitProjectName + ","; | |||
|  |                     } | |||
|  |                 } | |||
|  | 
 | |||
|  |                 if (tn.CommandName == "cnProfession") | |||
|  |                 { | |||
|  |                     Model.WBS_CnProfession cnProfession = BLL.CnProfessionService.GetCnProfessionByCnProfessionId(tn.NodeID); | |||
|  |                     if (cnProfession != null && (cnProfession.IsWeightsApprove == null || cnProfession.IsWeightsApprove == false)) | |||
|  |                     { | |||
|  |                         noAuditText = noAuditText + cnProfession.CnProfessionName + ","; | |||
|  |                     } | |||
|  |                 } | |||
|  |             } | |||
|  |         } | |||
|  |         #endregion | |||
|  | 
 | |||
|  |         #region  保存方法 | |||
|  |         /// <summary> | |||
|  |         /// 保存方法 | |||
|  |         /// </summary> | |||
|  |         /// <param name="message"></param> | |||
|  |         private void SaveData() | |||
|  |         { | |||
|  |             decimal totalMoney = 0, percents = 0, moneys = 0; | |||
|  |             JObject firstValue = Grid1.GetMergedData()[0].Value<JObject>("values"); | |||
|  |             totalMoney = firstValue.Value<decimal>("WeightsMoney"); | |||
|  | 
 | |||
|  |             if (this.Grid1.Rows.Count > 1) | |||
|  |             { | |||
|  |                 int j = 0; bool isLessThanZero = false; | |||
|  |                 foreach (JObject mergedRow in Grid1.GetMergedData()) | |||
|  |                 { | |||
|  |                     if (j > 0) | |||
|  |                     { | |||
|  |                         JObject values = mergedRow.Value<JObject>("values"); | |||
|  |                         if (values["Weights"].ToString() != "") | |||
|  |                         { | |||
|  |                             percents += values.Value<decimal>("Weights"); | |||
|  |                             if (values.Value<decimal>("Weights") < 0) | |||
|  |                             { | |||
|  |                                 isLessThanZero = true; | |||
|  |                                 break; | |||
|  |                             } | |||
|  |                         } | |||
|  |                         if (values["WeightsMoney"].ToString() != "") | |||
|  |                         { | |||
|  |                             moneys += values.Value<decimal>("WeightsMoney"); | |||
|  |                             if (values.Value<decimal>("WeightsMoney") < 0) | |||
|  |                             { | |||
|  |                                 isLessThanZero = true; | |||
|  |                                 break; | |||
|  |                             } | |||
|  |                         } | |||
|  |                     } | |||
|  |                     j++; | |||
|  |                 } | |||
|  |                 if (isLessThanZero == true) | |||
|  |                 { | |||
|  |                     ShowNotify("权重或权重比率不能为负值!", MessageBoxIcon.Success); | |||
|  |                     return; | |||
|  |                 } | |||
|  |                 if (percents != 100) | |||
|  |                 { | |||
|  |                     Alert.ShowInTop("占比值不是100%!", MessageBoxIcon.Warning); | |||
|  |                     return; | |||
|  |                 } | |||
|  |             } | |||
|  |             Model.Project_Sys_Set sysSet = BLL.Project_SysSetService.GetSysSetBySetId("21", this.CurrUser.LoginProjectId); | |||
|  |             int i = 0; | |||
|  |             foreach (JObject mergedRow in Grid1.GetMergedData()) | |||
|  |             { | |||
|  |                 if (i > 0) | |||
|  |                 { | |||
|  |                     JObject values = mergedRow.Value<JObject>("values"); | |||
|  |                     string rowId = values["Id"].ToString(); | |||
|  |                     string type = values["Type"].ToString(); | |||
|  |                     if (type == "childUnitProject") | |||
|  |                     { | |||
|  |                         Model.Wbs_UnitProject unitProject = BLL.UnitProjectService.GetUnitProjectByUnitProjectId(rowId); | |||
|  |                         if (unitProject != null) | |||
|  |                         { | |||
|  |                             Model.Wbs_UnitProject unitProjectParent = BLL.UnitProjectService.GetUnitProjectByUnitProjectId(unitProject.SuperUnitProjectId); | |||
|  |                             unitProject.Weights = Funs.GetNewDecimalOrZero(values["Weights"].ToString()); | |||
|  |                             unitProject.WeightsMoney = unitProject.Weights * unitProjectParent.WeightsMoney / 100; | |||
|  |                             unitProject.IsWeightsApprove = true; | |||
|  |                             BLL.UnitProjectService.UpdateUnitProject(unitProject); | |||
|  |                         } | |||
|  |                     } | |||
|  |                     else if (type == "wbsSet") | |||
|  |                     { | |||
|  |                         Model.Wbs_WbsSet wbsSet = BLL.WbsSetService.GetWbsSetByWbsSetId(rowId); | |||
|  |                         if (wbsSet != null) | |||
|  |                         { | |||
|  |                             if (string.IsNullOrEmpty(wbsSet.SuperWbsSetId))   //父级为单位工程 | |||
|  |                             { | |||
|  |                                 Model.Wbs_UnitProject unitProject = BLL.UnitProjectService.GetUnitProjectByUnitProjectId(wbsSet.UnitProjectId); | |||
|  |                                 wbsSet.Weights = Funs.GetNewDecimalOrZero(values["Weights"].ToString()); | |||
|  |                                 wbsSet.WeightsMoney = wbsSet.Weights * unitProject.WeightsMoney / 100; | |||
|  |                                 wbsSet.IsWeightsApprove = true; | |||
|  |                                 BLL.WbsSetService.UpdateWbsSet(wbsSet); | |||
|  |                             } | |||
|  |                             else   //父级为分部分项工程 | |||
|  |                             { | |||
|  |                                 Model.Wbs_WbsSet wbsSetParent = BLL.WbsSetService.GetWbsSetByWbsSetId(wbsSet.SuperWbsSetId); | |||
|  |                                 wbsSet.Weights = Funs.GetNewDecimalOrZero(values["Weights"].ToString()); | |||
|  |                                 wbsSet.WeightsMoney = wbsSet.Weights * wbsSetParent.WeightsMoney / 100; | |||
|  |                                 wbsSet.IsWeightsApprove = true; | |||
|  |                                 BLL.WbsSetService.UpdateWbsSet(wbsSet); | |||
|  |                             } | |||
|  |                         } | |||
|  |                     } | |||
|  |                 } | |||
|  |                 i++; | |||
|  |             } | |||
|  |             //BLL.Sys_LogService.AddLog(BLL.Const.System_9, this.CurrUser.LoginProjectId, this.CurrUser.UserId, "审核权重"); | |||
|  |             Alert.ShowInTop("保存成功!", MessageBoxIcon.Success); | |||
|  |         } | |||
|  |         #endregion | |||
|  | 
 | |||
|  |         #region  根据比例(因权重发生变化造成数据不一致)更新子级权重 | |||
|  |         /// <summary> | |||
|  |         /// 根据比例更新子级权重 | |||
|  |         /// </summary> | |||
|  |         /// <param name="message"></param> | |||
|  |         private void UpdateWeights(string id, string type) | |||
|  |         { | |||
|  |             decimal rate = 0, weights = 0, totalWeights = 0, values = 0; | |||
|  |             int i = 0; | |||
|  |             if (type == "installation") | |||
|  |             { | |||
|  |                 var ins = BLL.Project_InstallationService.GetInstallationByInstallationId(id); | |||
|  |                 var cnProfession = from x in Funs.DB.WBS_CnProfession where x.InstallationId == id select x; | |||
|  |                 if (ins != null && ins.WeightsMoney != null) | |||
|  |                 { | |||
|  |                     weights = ins.WeightsMoney ?? 0; | |||
|  |                 } | |||
|  |                 if (cnProfession.Count() > 0) | |||
|  |                 { | |||
|  |                     rate = cnProfession.Sum(e => e.Weights ?? 0); | |||
|  |                     totalWeights = cnProfession.Sum(e => e.WeightsMoney ?? 0); | |||
|  |                 } | |||
|  | 
 | |||
|  |                 if (rate <= 100 && weights != totalWeights) | |||
|  |                 { | |||
|  |                     foreach (var q in cnProfession) | |||
|  |                     { | |||
|  |                         if (i == cnProfession.Count() - 1 && rate == 100) | |||
|  |                         { | |||
|  |                             q.WeightsMoney = weights - values; | |||
|  |                         } | |||
|  |                         else | |||
|  |                         { | |||
|  |                             q.WeightsMoney = decimal.Round(((q.Weights ?? 0) * weights / 100), 2); | |||
|  |                             values = values + q.WeightsMoney ?? 0; | |||
|  |                         } | |||
|  |                         Funs.DB.SubmitChanges(); | |||
|  | 
 | |||
|  |                         i++; | |||
|  |                     } | |||
|  |                 } | |||
|  |             } | |||
|  |             if (type == "cnProfession") | |||
|  |             { | |||
|  |                 var cn = BLL.CnProfessionService.GetCnProfessionByCnProfessionId(id); | |||
|  |                 var unit = from x in Funs.DB.Wbs_UnitProject where x.CnProfessionId == id select x; | |||
|  |                 if (cn != null && cn.WeightsMoney != null) | |||
|  |                 { | |||
|  |                     weights = cn.WeightsMoney ?? 0; | |||
|  |                 } | |||
|  |                 if (unit.Count() > 0) | |||
|  |                 { | |||
|  |                     rate = unit.Sum(e => e.Weights ?? 0); | |||
|  |                     totalWeights = unit.Sum(e => e.WeightsMoney ?? 0); | |||
|  |                 } | |||
|  | 
 | |||
|  |                 if (rate <= 100 && weights != totalWeights) | |||
|  |                 { | |||
|  |                     foreach (var q in unit) | |||
|  |                     { | |||
|  |                         if (i == unit.Count() - 1 && rate == 100) | |||
|  |                         { | |||
|  |                             q.WeightsMoney = weights - values; | |||
|  |                         } | |||
|  |                         else | |||
|  |                         { | |||
|  |                             q.WeightsMoney = decimal.Round(((q.Weights ?? 0) * weights / 100), 2); | |||
|  |                             values = values + q.WeightsMoney ?? 0; | |||
|  |                         } | |||
|  |                         Funs.DB.SubmitChanges(); | |||
|  | 
 | |||
|  |                         i++; | |||
|  |                     } | |||
|  |                 } | |||
|  |             } | |||
|  | 
 | |||
|  |             if (type == "unitProject") | |||
|  |             { | |||
|  |                 var unit = BLL.UnitProjectService.GetUnitProjectByUnitProjectId(id); | |||
|  |                 var childUnit = from x in Funs.DB.Wbs_UnitProject where x.SuperUnitProjectId == id select x; | |||
|  |                 var wbs = from x in Funs.DB.Wbs_WbsSet where x.UnitProjectId == id && (x.Flag == 1 || x.SuperWbsSetId == null) select x; | |||
|  |                 if (unit != null && unit.WeightsMoney != null) | |||
|  |                 { | |||
|  |                     weights = unit.WeightsMoney ?? 0; | |||
|  |                 } | |||
|  |                 if (childUnit.Count() > 0) | |||
|  |                 { | |||
|  |                     rate = childUnit.Sum(e => e.Weights ?? 0); | |||
|  |                     totalWeights = childUnit.Sum(e => e.WeightsMoney ?? 0); | |||
|  |                 } | |||
|  | 
 | |||
|  |                 if (wbs.Count() > 0) | |||
|  |                 { | |||
|  |                     rate = wbs.Sum(e => e.Weights ?? 0); | |||
|  |                     totalWeights = wbs.Sum(e => e.WeightsMoney ?? 0); | |||
|  |                 } | |||
|  | 
 | |||
|  |                 if (rate <= 100 && weights != totalWeights) | |||
|  |                 { | |||
|  |                     if (childUnit.Count() > 0) | |||
|  |                     { | |||
|  |                         foreach (var q in childUnit) | |||
|  |                         { | |||
|  |                             if (i == childUnit.Count() - 1 && rate == 100) | |||
|  |                             { | |||
|  |                                 q.WeightsMoney = weights - values; | |||
|  |                             } | |||
|  |                             else | |||
|  |                             { | |||
|  |                                 q.WeightsMoney = decimal.Round(((q.Weights ?? 0) * weights / 100), 2); | |||
|  |                                 values = values + q.WeightsMoney ?? 0; | |||
|  |                             } | |||
|  |                             Funs.DB.SubmitChanges(); | |||
|  | 
 | |||
|  |                             i++; | |||
|  |                         } | |||
|  |                     } | |||
|  |                     if (wbs.Count() > 0) | |||
|  |                     { | |||
|  |                         foreach (var q in wbs) | |||
|  |                         { | |||
|  |                             if (i == wbs.Count() - 1 && rate == 100) | |||
|  |                             { | |||
|  |                                 q.WeightsMoney = weights - values; | |||
|  |                             } | |||
|  |                             else | |||
|  |                             { | |||
|  |                                 q.WeightsMoney = decimal.Round(((q.Weights ?? 0) * weights / 100), 2); | |||
|  |                                 values = values + q.WeightsMoney ?? 0; | |||
|  |                             } | |||
|  |                             Funs.DB.SubmitChanges(); | |||
|  | 
 | |||
|  |                             i++; | |||
|  |                         } | |||
|  |                     } | |||
|  |                 } | |||
|  |             } | |||
|  | 
 | |||
|  |             if (type == "childUnitProject") | |||
|  |             { | |||
|  |                 var unit = BLL.UnitProjectService.GetUnitProjectByUnitProjectId(id); | |||
|  |                 var wbs = from x in Funs.DB.Wbs_WbsSet where x.UnitProjectId == id && (x.Flag == 1 || x.SuperWbsSetId == null) select x; | |||
|  |                 if (unit != null && unit.WeightsMoney != null) | |||
|  |                 { | |||
|  |                     weights = unit.WeightsMoney ?? 0; | |||
|  |                 } | |||
|  | 
 | |||
|  |                 if (wbs.Count() > 0) | |||
|  |                 { | |||
|  |                     rate = wbs.Sum(e => e.Weights ?? 0); | |||
|  |                     totalWeights = wbs.Sum(e => e.WeightsMoney ?? 0); | |||
|  |                 } | |||
|  | 
 | |||
|  |                 if (rate <= 100 && weights != totalWeights) | |||
|  |                 { | |||
|  |                     foreach (var q in wbs) | |||
|  |                     { | |||
|  |                         if (i == wbs.Count() - 1 && rate == 100) | |||
|  |                         { | |||
|  |                             q.WeightsMoney = weights - values; | |||
|  |                         } | |||
|  |                         else | |||
|  |                         { | |||
|  |                             q.WeightsMoney = decimal.Round(((q.Weights ?? 0) * weights / 100), 2); | |||
|  |                             values = values + q.WeightsMoney ?? 0; | |||
|  |                         } | |||
|  |                         Funs.DB.SubmitChanges(); | |||
|  | 
 | |||
|  |                         i++; | |||
|  |                     } | |||
|  |                 } | |||
|  |             } | |||
|  | 
 | |||
|  | 
 | |||
|  |             if (type == "wbsSet") | |||
|  |             { | |||
|  |                 var wbs = BLL.WbsSetService.GetWbsSetByWbsSetId(id); | |||
|  |                 var childWbs = from x in Funs.DB.Wbs_WbsSet where x.SuperWbsSetId == id select x; | |||
|  |                 if (wbs != null && wbs.WeightsMoney != null) | |||
|  |                 { | |||
|  |                     weights = wbs.WeightsMoney ?? 0; | |||
|  |                 } | |||
|  | 
 | |||
|  |                 if (childWbs.Count() > 0) | |||
|  |                 { | |||
|  |                     rate = childWbs.Sum(e => e.Weights ?? 0); | |||
|  |                     totalWeights = childWbs.Sum(e => e.WeightsMoney ?? 0); | |||
|  |                 } | |||
|  | 
 | |||
|  |                 if (rate <= 100 && weights != totalWeights) | |||
|  |                 { | |||
|  |                     foreach (var q in childWbs) | |||
|  |                     { | |||
|  |                         if (i == childWbs.Count() - 1 && rate == 100) | |||
|  |                         { | |||
|  |                             q.WeightsMoney = weights - values; | |||
|  |                         } | |||
|  |                         else | |||
|  |                         { | |||
|  |                             q.WeightsMoney = decimal.Round(((q.Weights ?? 0) * weights / 100), 2); | |||
|  |                             values = values + q.WeightsMoney ?? 0; | |||
|  |                         } | |||
|  |                         Funs.DB.SubmitChanges(); | |||
|  | 
 | |||
|  |                         i++; | |||
|  |                     } | |||
|  |                 } | |||
|  |             } | |||
|  | 
 | |||
|  |         } | |||
|  |         #endregion | |||
|  | 
 | |||
|  |         #region  提交、保存按钮 | |||
|  |         /// <summary> | |||
|  |         /// 提交 | |||
|  |         /// </summary> | |||
|  |         /// <param name="sender"></param> | |||
|  |         /// <param name="e"></param> | |||
|  |         protected void btnSave_Click(object sender, EventArgs e) | |||
|  |         { | |||
|  |             if (this.Grid1.Rows.Count > 0) | |||
|  |             { | |||
|  |                 Model.Wbs_UnitProject unitProject = BLL.UnitProjectService.GetUnitProjectByUnitProjectId(this.Grid1.Rows[0].DataKeys[0].ToString()); | |||
|  |                 Model.Wbs_WbsSet wbsSet = BLL.WbsSetService.GetWbsSetByWbsSetId(this.Grid1.Rows[0].DataKeys[0].ToString()); | |||
|  |                 if (unitProject != null) | |||
|  |                 { | |||
|  |                     if (unitProject.WeightsMoney == null || unitProject.WeightsMoney == 0) | |||
|  |                     { | |||
|  |                         Alert.ShowInTop("请先设置父级工作量!", MessageBoxIcon.Warning); | |||
|  |                         return; | |||
|  |                     } | |||
|  |                 } | |||
|  |                 if (wbsSet != null) | |||
|  |                 { | |||
|  |                     if (wbsSet.WeightsMoney == null || wbsSet.WeightsMoney == 0) | |||
|  |                     { | |||
|  |                         Alert.ShowInTop("请先设置父级工作量!", MessageBoxIcon.Warning); | |||
|  |                         return; | |||
|  |                     } | |||
|  |                 } | |||
|  |                 SaveData(); | |||
|  |             } | |||
|  |             else | |||
|  |             { | |||
|  |                 Alert.ShowInTop("请至少选择一条记录!", MessageBoxIcon.Warning); | |||
|  |                 return; | |||
|  |             } | |||
|  |         } | |||
|  | 
 | |||
|  |         /// <summary> | |||
|  |         /// 提交 | |||
|  |         /// </summary> | |||
|  |         /// <param name="sender"></param> | |||
|  |         /// <param name="e"></param> | |||
|  |         protected void btnSave2_Click(object sender, EventArgs e) | |||
|  |         { | |||
|  |             if (this.Grid2.Rows.Count > 0) | |||
|  |             { | |||
|  |                 if (this.trWBS.SelectedNode.CommandName == "childUnitProject") | |||
|  |                 { | |||
|  |                     Model.Wbs_UnitProject unitProject = BLL.UnitProjectService.GetUnitProjectByUnitProjectId(this.trWBS.SelectedNode.NodeID); | |||
|  |                     foreach (JObject mergedRow in Grid2.GetMergedData()) | |||
|  |                     { | |||
|  |                         decimal oldWeightsMoney = unitProject.WeightsMoney ?? 0; | |||
|  |                         JObject values = mergedRow.Value<JObject>("values"); | |||
|  |                         if (string.IsNullOrEmpty(values.Value<string>("EngineerQuantity")) || string.IsNullOrEmpty(values.Value<string>("BudgetUnitPrice")) || string.IsNullOrEmpty(values.Value<string>("CostUnivalent"))) | |||
|  |                         { | |||
|  |                             Alert.ShowInTop("工程量、预算单价、成本单价不能为空!", MessageBoxIcon.Warning); | |||
|  |                             return; | |||
|  |                         } | |||
|  |                         unitProject.EngineerQuantity = Convert.ToDecimal(values.Value<string>("EngineerQuantity")); | |||
|  |                         unitProject.Unit = values.Value<string>("Unit"); | |||
|  |                         unitProject.BudgetUnitPrice = Convert.ToDecimal(values.Value<string>("BudgetUnitPrice")); | |||
|  |                         unitProject.CostUnivalent = Convert.ToDecimal(values.Value<string>("CostUnivalent")); | |||
|  |                         unitProject.WeightsMoney = unitProject.EngineerQuantity * unitProject.BudgetUnitPrice; | |||
|  |                         unitProject.IsWeightsApprove = true; | |||
|  |                         BLL.UnitProjectService.UpdateUnitProject(unitProject); | |||
|  |                         decimal money = Convert.ToDecimal(unitProject.WeightsMoney) - oldWeightsMoney; | |||
|  |                         UpdateParentWeightsMoney1(unitProject, money); | |||
|  |                     } | |||
|  |                 } | |||
|  |                 else if (this.trWBS.SelectedNode.CommandName == "wbsSet") | |||
|  |                 { | |||
|  |                     Model.Wbs_WbsSet wbsSet = BLL.WbsSetService.GetWbsSetByWbsSetId(this.trWBS.SelectedNode.NodeID); | |||
|  |                     foreach (JObject mergedRow in Grid2.GetMergedData()) | |||
|  |                     { | |||
|  |                         decimal oldWeightsMoney = wbsSet.WeightsMoney ?? 0; | |||
|  |                         JObject values = mergedRow.Value<JObject>("values"); | |||
|  |                         if (string.IsNullOrEmpty(values.Value<string>("EngineerQuantity")) || string.IsNullOrEmpty(values.Value<string>("BudgetUnitPrice")) || string.IsNullOrEmpty(values.Value<string>("CostUnivalent"))) | |||
|  |                         { | |||
|  |                             Alert.ShowInTop("工程量、预算单价、成本单价不能为空!", MessageBoxIcon.Warning); | |||
|  |                             return; | |||
|  |                         } | |||
|  |                         wbsSet.EngineerQuantity = Convert.ToDecimal(values.Value<string>("EngineerQuantity")); | |||
|  |                         wbsSet.Unit = values.Value<string>("Unit"); | |||
|  |                         wbsSet.BudgetUnitPrice = Convert.ToDecimal(values.Value<string>("BudgetUnitPrice")); | |||
|  |                         wbsSet.CostUnivalent = Convert.ToDecimal(values.Value<string>("CostUnivalent")); | |||
|  |                         wbsSet.WeightsMoney = wbsSet.EngineerQuantity * wbsSet.BudgetUnitPrice; | |||
|  |                         wbsSet.IsWeightsApprove = true; | |||
|  |                         BLL.WbsSetService.UpdateWbsSet(wbsSet); | |||
|  |                         decimal money = Convert.ToDecimal(wbsSet.WeightsMoney) - oldWeightsMoney; | |||
|  |                         UpdateParentWeightsMoney2(wbsSet, money); | |||
|  |                     } | |||
|  |                 } | |||
|  |                 Alert.ShowInTop("保存成功!", MessageBoxIcon.Success); | |||
|  |             } | |||
|  |             else | |||
|  |             { | |||
|  |                 Alert.ShowInTop("请至少选择一条记录!", MessageBoxIcon.Warning); | |||
|  |                 return; | |||
|  |             } | |||
|  |         } | |||
|  | 
 | |||
|  |         /// <summary> | |||
|  |         /// 更新父级权重费用(当前级为子单位工程) | |||
|  |         /// </summary> | |||
|  |         /// <param name="childUnitProject"></param> | |||
|  |         private void UpdateParentWeightsMoney1(Model.Wbs_UnitProject childUnitProject, decimal money) | |||
|  |         { | |||
|  |             //更新单位工程 | |||
|  |             Model.Wbs_UnitProject unitProject = BLL.UnitProjectService.GetUnitProjectByUnitProjectId(childUnitProject.SuperUnitProjectId); | |||
|  |             if (unitProject.WeightsMoney == null) | |||
|  |             { | |||
|  |                 unitProject.WeightsMoney = money; | |||
|  |             } | |||
|  |             else | |||
|  |             { | |||
|  |                 unitProject.WeightsMoney += money; | |||
|  |             } | |||
|  |             BLL.UnitProjectService.UpdateUnitProject(unitProject); | |||
|  |             //更新专业 | |||
|  |             Model.WBS_CnProfession cnProfession = BLL.CnProfessionService.GetCnProfessionByCnProfessionId(childUnitProject.CnProfessionId); | |||
|  |             if (cnProfession.WeightsMoney == null) | |||
|  |             { | |||
|  |                 cnProfession.WeightsMoney = money; | |||
|  |             } | |||
|  |             else | |||
|  |             { | |||
|  |                 cnProfession.WeightsMoney += money; | |||
|  |             } | |||
|  |             BLL.CnProfessionService.UpdateCnProfession(cnProfession); | |||
|  |             //更新装置 | |||
|  |             //主项 | |||
|  |             Model.Project_Installation installation = BLL.Project_InstallationService.GetInstallationByInstallationId(childUnitProject.InstallationId); | |||
|  |             if (installation.WeightsMoney == null) | |||
|  |             { | |||
|  |                 installation.WeightsMoney = money; | |||
|  |             } | |||
|  |             else | |||
|  |             { | |||
|  |                 installation.WeightsMoney += money; | |||
|  |             } | |||
|  |             BLL.Project_InstallationService.UpdateInstallation(installation); | |||
|  |             //工序 | |||
|  |             Model.Project_Installation pInstallation = BLL.Project_InstallationService.GetInstallationByInstallationId(installation.SuperInstallationId); | |||
|  |             if (pInstallation.WeightsMoney == null) | |||
|  |             { | |||
|  |                 pInstallation.WeightsMoney = money; | |||
|  |             } | |||
|  |             else | |||
|  |             { | |||
|  |                 pInstallation.WeightsMoney += money; | |||
|  |             } | |||
|  |             BLL.Project_InstallationService.UpdateInstallation(pInstallation); | |||
|  |             //装置 | |||
|  |             Model.Project_Installation ppInstallation = BLL.Project_InstallationService.GetInstallationByInstallationId(pInstallation.SuperInstallationId); | |||
|  |             if (ppInstallation.WeightsMoney == null) | |||
|  |             { | |||
|  |                 ppInstallation.WeightsMoney = money; | |||
|  |             } | |||
|  |             else | |||
|  |             { | |||
|  |                 ppInstallation.WeightsMoney += money; | |||
|  |             } | |||
|  |             BLL.Project_InstallationService.UpdateInstallation(ppInstallation); | |||
|  |         } | |||
|  | 
 | |||
|  |         /// <summary> | |||
|  |         /// 更新父级权重费用(当前级为分部分项工程) | |||
|  |         /// </summary> | |||
|  |         /// <param name="childUnitProject"></param> | |||
|  |         private void UpdateParentWeightsMoney2(Model.Wbs_WbsSet wbsSet, decimal money) | |||
|  |         { | |||
|  |             //更新分部分项工程 | |||
|  |             Model.Wbs_WbsSet pWbsSet = BLL.WbsSetService.GetWbsSetByWbsSetId(wbsSet.SuperWbsSetId); | |||
|  |             if (pWbsSet != null) | |||
|  |             { | |||
|  |                 if (pWbsSet.WeightsMoney == null) | |||
|  |                 { | |||
|  |                     pWbsSet.WeightsMoney = money; | |||
|  |                 } | |||
|  |                 else | |||
|  |                 { | |||
|  |                     pWbsSet.WeightsMoney += money; | |||
|  |                 } | |||
|  |                 BLL.WbsSetService.UpdateWbsSet(pWbsSet); | |||
|  |                 Model.Wbs_WbsSet ppWbsSet = BLL.WbsSetService.GetWbsSetByWbsSetId(pWbsSet.SuperWbsSetId); | |||
|  |                 if (ppWbsSet != null) | |||
|  |                 { | |||
|  |                     if (ppWbsSet.WeightsMoney == null) | |||
|  |                     { | |||
|  |                         ppWbsSet.WeightsMoney = money; | |||
|  |                     } | |||
|  |                     else | |||
|  |                     { | |||
|  |                         ppWbsSet.WeightsMoney += money; | |||
|  |                     } | |||
|  |                     BLL.WbsSetService.UpdateWbsSet(ppWbsSet); | |||
|  |                     Model.Wbs_WbsSet pppWbsSet = BLL.WbsSetService.GetWbsSetByWbsSetId(ppWbsSet.SuperWbsSetId); | |||
|  |                     if (pppWbsSet != null) | |||
|  |                     { | |||
|  |                         if (pppWbsSet.WeightsMoney == null) | |||
|  |                         { | |||
|  |                             pppWbsSet.WeightsMoney = money; | |||
|  |                         } | |||
|  |                         else | |||
|  |                         { | |||
|  |                             pppWbsSet.WeightsMoney += money; | |||
|  |                         } | |||
|  |                         BLL.WbsSetService.UpdateWbsSet(pppWbsSet); | |||
|  |                     } | |||
|  |                 } | |||
|  |             } | |||
|  |             //更新单位工程 | |||
|  |             Model.Wbs_UnitProject unitProject = BLL.UnitProjectService.GetUnitProjectByUnitProjectId(wbsSet.UnitProjectId); | |||
|  |             if (unitProject.WeightsMoney == null) | |||
|  |             { | |||
|  |                 unitProject.WeightsMoney = money; | |||
|  |             } | |||
|  |             else | |||
|  |             { | |||
|  |                 unitProject.WeightsMoney += money; | |||
|  |             } | |||
|  |             BLL.UnitProjectService.UpdateUnitProject(unitProject); | |||
|  |             Model.Wbs_UnitProject pUnitProject = BLL.UnitProjectService.GetUnitProjectByUnitProjectId(unitProject.SuperUnitProjectId); | |||
|  |             if (pUnitProject != null) | |||
|  |             { | |||
|  |                 if (pUnitProject.WeightsMoney == null) | |||
|  |                 { | |||
|  |                     pUnitProject.WeightsMoney = money; | |||
|  |                 } | |||
|  |                 else | |||
|  |                 { | |||
|  |                     pUnitProject.WeightsMoney += money; | |||
|  |                 } | |||
|  |                 BLL.UnitProjectService.UpdateUnitProject(pUnitProject); | |||
|  |             } | |||
|  |             if (unitProject.CnProfessionId != null)   //非总图内容 | |||
|  |             { | |||
|  |                 //更新专业 | |||
|  |                 Model.WBS_CnProfession cnProfession = BLL.CnProfessionService.GetCnProfessionByCnProfessionId(unitProject.CnProfessionId); | |||
|  |                 if (cnProfession.WeightsMoney == null) | |||
|  |                 { | |||
|  |                     cnProfession.WeightsMoney = money; | |||
|  |                 } | |||
|  |                 else | |||
|  |                 { | |||
|  |                     cnProfession.WeightsMoney += money; | |||
|  |                 } | |||
|  |                 BLL.CnProfessionService.UpdateCnProfession(cnProfession); | |||
|  |                 //更新装置 | |||
|  |                 //主项 | |||
|  |                 Model.Project_Installation installation = BLL.Project_InstallationService.GetInstallationByInstallationId(unitProject.InstallationId); | |||
|  |                 if (installation.WeightsMoney == null) | |||
|  |                 { | |||
|  |                     installation.WeightsMoney = money; | |||
|  |                 } | |||
|  |                 else | |||
|  |                 { | |||
|  |                     installation.WeightsMoney += money; | |||
|  |                 } | |||
|  |                 BLL.Project_InstallationService.UpdateInstallation(installation); | |||
|  |                 //工序 | |||
|  |                 Model.Project_Installation pInstallation = BLL.Project_InstallationService.GetInstallationByInstallationId(installation.SuperInstallationId); | |||
|  |                 if (pInstallation.WeightsMoney == null) | |||
|  |                 { | |||
|  |                     pInstallation.WeightsMoney = money; | |||
|  |                 } | |||
|  |                 else | |||
|  |                 { | |||
|  |                     pInstallation.WeightsMoney += money; | |||
|  |                 } | |||
|  |                 BLL.Project_InstallationService.UpdateInstallation(pInstallation); | |||
|  |                 //装置 | |||
|  |                 Model.Project_Installation ppInstallation = BLL.Project_InstallationService.GetInstallationByInstallationId(pInstallation.SuperInstallationId); | |||
|  |                 if (ppInstallation.WeightsMoney == null) | |||
|  |                 { | |||
|  |                     ppInstallation.WeightsMoney = money; | |||
|  |                 } | |||
|  |                 else | |||
|  |                 { | |||
|  |                     ppInstallation.WeightsMoney += money; | |||
|  |                 } | |||
|  |                 BLL.Project_InstallationService.UpdateInstallation(ppInstallation); | |||
|  |             } | |||
|  |             else    //总图 | |||
|  |             { | |||
|  |                 Model.Project_Installation installation = BLL.Project_InstallationService.GetInstallationByInstallationId(unitProject.InstallationId); | |||
|  |                 if (installation.WeightsMoney == null) | |||
|  |                 { | |||
|  |                     installation.WeightsMoney = money; | |||
|  |                 } | |||
|  |                 else | |||
|  |                 { | |||
|  |                     installation.WeightsMoney += money; | |||
|  |                 } | |||
|  |                 BLL.Project_InstallationService.UpdateInstallation(installation); | |||
|  |             } | |||
|  |         } | |||
|  | 
 | |||
|  |         #region 取消审核 | |||
|  |         /// <summary> | |||
|  |         /// 判断子节点有没有审核权重项 | |||
|  |         /// </summary> | |||
|  |         /// <param name="parentId"></param> | |||
|  |         private bool IsChildAudit(GridRow row) | |||
|  |         { | |||
|  |             bool isAudit = false; | |||
|  |             if (row.Values[14].ToString() == "cnProfession") | |||
|  |             { | |||
|  |                 var unitProject = BLL.UnitProjectService.GetUnitProjectsBySuperUnitProjectId(row.RowID); | |||
|  |                 if (unitProject != null) | |||
|  |                 { | |||
|  |                     foreach (var unit in unitProject) | |||
|  |                     { | |||
|  |                         if (unit.IsWeightsApprove == true) | |||
|  |                         { | |||
|  |                             isAudit = true; | |||
|  |                             break; | |||
|  |                         } | |||
|  |                     } | |||
|  |                 } | |||
|  |             } | |||
|  |             if (row.Values[14].ToString() == "unitProject") | |||
|  |             { | |||
|  |                 var childUnit = BLL.UnitProjectService.GetUnitProjectsBySuperUnitProjectId(row.RowID); | |||
|  |                 if (childUnit != null) | |||
|  |                 { | |||
|  |                     foreach (var child in childUnit) | |||
|  |                     { | |||
|  |                         if (child.IsWeightsApprove == true) | |||
|  |                         { | |||
|  |                             isAudit = true; | |||
|  |                             break; | |||
|  |                         } | |||
|  |                     } | |||
|  |                 } | |||
|  | 
 | |||
|  |                 var wbsSet = from x in Funs.DB.Wbs_WbsSet where x.UnitProjectId == row.RowID select x; | |||
|  |                 if (wbsSet != null) | |||
|  |                 { | |||
|  |                     foreach (var wbs in wbsSet) | |||
|  |                     { | |||
|  |                         if (wbs.IsWeightsApprove == true) | |||
|  |                         { | |||
|  |                             isAudit = true; | |||
|  |                             break; | |||
|  |                         } | |||
|  |                     } | |||
|  |                 } | |||
|  |             } | |||
|  |             if (row.Values[14].ToString() == "childUnitProject") | |||
|  |             { | |||
|  |                 var wbsSet = from x in Funs.DB.Wbs_WbsSet where x.UnitProjectId == row.RowID select x; | |||
|  |                 if (wbsSet != null) | |||
|  |                 { | |||
|  |                     foreach (var wbs in wbsSet) | |||
|  |                     { | |||
|  |                         if (wbs.IsWeightsApprove == true) | |||
|  |                         { | |||
|  |                             isAudit = true; | |||
|  |                             break; | |||
|  |                         } | |||
|  |                     } | |||
|  |                 } | |||
|  |             } | |||
|  | 
 | |||
|  |             if (row.Values[14].ToString() == "wbsSet") | |||
|  |             { | |||
|  |                 var wbsSet = BLL.WbsSetService.GetWbsSetsBySuperWbsSetId(row.RowID); | |||
|  |                 if (wbsSet != null) | |||
|  |                 { | |||
|  |                     foreach (var wbs in wbsSet) | |||
|  |                     { | |||
|  |                         if (wbs.IsWeightsApprove == true) | |||
|  |                         { | |||
|  |                             isAudit = true; | |||
|  |                             break; | |||
|  |                         } | |||
|  |                     } | |||
|  |                 } | |||
|  |             } | |||
|  |             return isAudit; | |||
|  |         } | |||
|  | 
 | |||
|  |         /// <summary> | |||
|  |         /// 右键取消审核事件 | |||
|  |         /// </summary> | |||
|  |         /// <param name="sender"></param> | |||
|  |         /// <param name="e"></param> | |||
|  |         protected void btnClearAudit_Click(object sender, EventArgs e) | |||
|  |         { | |||
|  |             //if (BLL.CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, Const.JDGL_WeightsAuditMenuId, Const.BtnCancelAuditing)) | |||
|  |             //{ | |||
|  |                 if (IsChildAudit(Grid1.SelectedRow)) | |||
|  |                 { | |||
|  |                     Alert.ShowInTop("该项的子项权重已设置审核,不能取消审核!", MessageBoxIcon.Warning); | |||
|  |                     return; | |||
|  |                 } | |||
|  |                 else | |||
|  |                 { | |||
|  |                     if (Grid1.SelectedRow.Values[14].ToString() == "cnProfession") | |||
|  |                     { | |||
|  |                         var cn = BLL.CnProfessionService.GetCnProfessionByCnProfessionId(Grid1.SelectedRow.RowID); | |||
|  |                         if (cn != null) | |||
|  |                         { | |||
|  |                             cn.IsWeightsApprove = false; | |||
|  |                         } | |||
|  |                     } | |||
|  |                     if (Grid1.SelectedRow.Values[14].ToString() == "unitProject" || Grid1.SelectedRow.Values[14].ToString() == "childUnitProject") | |||
|  |                     { | |||
|  |                         var unitProject = BLL.UnitProjectService.GetUnitProjectByUnitProjectId(Grid1.SelectedRow.RowID); | |||
|  |                         if (unitProject != null) | |||
|  |                         { | |||
|  |                             unitProject.IsWeightsApprove = false; | |||
|  |                         } | |||
|  |                     } | |||
|  |                     if (Grid1.SelectedRow.Values[14].ToString() == "wbsSet") | |||
|  |                     { | |||
|  |                         var wbsSet = BLL.WbsSetService.GetWbsSetByWbsSetId(Grid1.SelectedRow.RowID); | |||
|  |                         if (wbsSet != null) | |||
|  |                         { | |||
|  |                             wbsSet.IsWeightsApprove = false; | |||
|  |                         } | |||
|  |                     } | |||
|  |                     Funs.DB.SubmitChanges(); | |||
|  |                     BindGrid(); | |||
|  |                     Alert.ShowInTop("已取消该项审核!", MessageBoxIcon.Warning); | |||
|  |                 } | |||
|  |             //} | |||
|  |             //else | |||
|  |             //{ | |||
|  |             //    Alert.ShowInTop("您没有消该项审权限,请于管理员联系!", MessageBoxIcon.Warning); | |||
|  |             //} | |||
|  |         } | |||
|  |         #endregion | |||
|  | 
 | |||
|  |         #endregion         | |||
|  | 
 | |||
|  |         #region  绑定数据 | |||
|  |         /// <summary> | |||
|  |         /// 绑定数据 | |||
|  |         /// </summary> | |||
|  |         /// <param name="sender"></param> | |||
|  |         /// <param name="e"></param> | |||
|  |         protected void Grid1_FilterChange(object sender, EventArgs e) | |||
|  |         { | |||
|  |             BindGrid(); | |||
|  |         } | |||
|  | 
 | |||
|  |         protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e) | |||
|  |         { | |||
|  |             Grid1.PageIndex = e.NewPageIndex; | |||
|  |             BindGrid(); | |||
|  |         } | |||
|  | 
 | |||
|  |         /// <summary> | |||
|  |         /// Grid1排序 | |||
|  |         /// </summary> | |||
|  |         /// <param name="sender"></param> | |||
|  |         /// <param name="e"></param> | |||
|  |         protected void Grid1_Sort(object sender, GridSortEventArgs e) | |||
|  |         { | |||
|  |             Grid1.SortDirection = e.SortDirection; | |||
|  |             Grid1.SortField = e.SortField; | |||
|  |             BindGrid(); | |||
|  |         } | |||
|  | 
 | |||
|  |         /// <summary> | |||
|  |         /// 分页下拉选择事件 | |||
|  |         /// </summary> | |||
|  |         /// <param name="sender"></param> | |||
|  |         /// <param name="e"></param> | |||
|  |         protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e) | |||
|  |         { | |||
|  |             Grid1.PageSize = Convert.ToInt32(ddlPageSize.SelectedValue); | |||
|  |             BindGrid(); | |||
|  |         } | |||
|  | 
 | |||
|  |         /// <summary> | |||
|  |         /// 加载Grid2 | |||
|  |         /// </summary> | |||
|  |         private void BindGrid2() | |||
|  |         { | |||
|  |             this.Grid2.Columns[4].Hidden = false; | |||
|  |             this.Grid2.Columns[5].Hidden = false; | |||
|  |             List<Model.WBSSetItem> items = new List<Model.WBSSetItem>(); | |||
|  |             Model.WBSSetItem item = new Model.WBSSetItem(); | |||
|  |             if (this.trWBS.SelectedNode != null) | |||
|  |             { | |||
|  |                 if (this.trWBS.SelectedNode.CommandName == "childUnitProject") | |||
|  |                 { | |||
|  |                     Model.Wbs_UnitProject unitProject = BLL.UnitProjectService.GetUnitProjectByUnitProjectId(this.trWBS.SelectedNode.NodeID); | |||
|  |                     if (unitProject != null) | |||
|  |                     { | |||
|  |                         item.Id = this.trWBS.SelectedNode.NodeID; | |||
|  |                         item.Code = unitProject.UnitProjectCode; | |||
|  |                         item.Name = unitProject.UnitProjectName; | |||
|  |                         item.Type = "unitProject"; | |||
|  |                         item.StartDate = unitProject.StartDate; | |||
|  |                         item.EndDate = unitProject.EndDate; | |||
|  |                         item.Weights = unitProject.Weights; | |||
|  |                         item.WeightsMoney = unitProject.WeightsMoney; | |||
|  |                         item.WeightsMoneyStr = decimal.Round(Convert.ToDecimal(item.WeightsMoney), 2).ToString(); | |||
|  |                         item.EngineerQuantity = unitProject.EngineerQuantity; | |||
|  |                         string unit = string.Empty; | |||
|  |                         decimal? budgetUnitPrice = 0, costUnivalent = 0; | |||
|  |                         Model.Wbs_UnitProject pUnitProject = BLL.UnitProjectService.GetUnitProjectByUnitProjectId(unitProject.SuperUnitProjectId); | |||
|  |                         if (pUnitProject != null) | |||
|  |                         { | |||
|  |                             if (!string.IsNullOrEmpty(pUnitProject.Unit)) | |||
|  |                             { | |||
|  |                                 unit = pUnitProject.Unit; | |||
|  |                             } | |||
|  |                             if (pUnitProject.BudgetUnitPrice != null) | |||
|  |                             { | |||
|  |                                 budgetUnitPrice = pUnitProject.BudgetUnitPrice; | |||
|  |                                 this.Grid2.Columns[4].Hidden = true; | |||
|  |                                 this.Grid2.Columns[5].Hidden = true; | |||
|  |                             } | |||
|  |                             if (pUnitProject.CostUnivalent != null) | |||
|  |                             { | |||
|  |                                 costUnivalent = pUnitProject.CostUnivalent; | |||
|  |                             } | |||
|  |                         } | |||
|  |                         item.Unit = unitProject.Unit == null ? unit : unitProject.Unit; | |||
|  |                         item.BudgetUnitPrice = unitProject.BudgetUnitPrice == null ? budgetUnitPrice : unitProject.BudgetUnitPrice; | |||
|  |                         item.CostUnivalent = unitProject.CostUnivalent == null ? costUnivalent : unitProject.CostUnivalent; | |||
|  |                         item.ChildEngineerQuantitys = BLL.UnitProjectService.GetChildEngineerQuantitys(this.trWBS.SelectedNode.NodeID); | |||
|  |                         items.Add(item); | |||
|  |                     } | |||
|  |                 } | |||
|  |                 else if (this.trWBS.SelectedNode.CommandName == "wbsSet") | |||
|  |                 { | |||
|  |                     Model.Wbs_WbsSet wbsSet = BLL.WbsSetService.GetWbsSetByWbsSetId(this.trWBS.SelectedNode.NodeID); | |||
|  |                     item.Id = this.trWBS.SelectedNode.NodeID; | |||
|  |                     item.Code = wbsSet.WbsSetCode; | |||
|  |                     item.Name = wbsSet.WbsSetName; | |||
|  |                     item.Type = "wbsSet"; | |||
|  |                     item.StartDate = wbsSet.StartDate; | |||
|  |                     item.EndDate = wbsSet.EndDate; | |||
|  |                     item.Weights = wbsSet.Weights; | |||
|  |                     item.WeightsMoney = wbsSet.WeightsMoney; | |||
|  |                     item.WeightsMoneyStr = decimal.Round(Convert.ToDecimal(item.WeightsMoney), 2).ToString(); | |||
|  |                     item.EngineerQuantity = wbsSet.EngineerQuantity; | |||
|  |                     string unit = string.Empty; | |||
|  |                     decimal? budgetUnitPrice = 0, costUnivalent = 0; | |||
|  |                     Model.Wbs_WbsSet pWbsSet = BLL.WbsSetService.GetWbsSetByWbsSetId(wbsSet.SuperWbsSetId); | |||
|  |                     if (pWbsSet != null) | |||
|  |                     { | |||
|  |                         if (pWbsSet.Unit != null) | |||
|  |                         { | |||
|  |                             unit = pWbsSet.Unit; | |||
|  |                         } | |||
|  |                         if (pWbsSet.BudgetUnitPrice != null) | |||
|  |                         { | |||
|  |                             budgetUnitPrice = pWbsSet.BudgetUnitPrice; | |||
|  |                             this.Grid2.Columns[4].Hidden = true; | |||
|  |                             this.Grid2.Columns[5].Hidden = true; | |||
|  |                         }  | |||
|  |                         if (pWbsSet.CostUnivalent != null) | |||
|  |                         { | |||
|  |                             costUnivalent = pWbsSet.CostUnivalent; | |||
|  |                         } | |||
|  |                     } | |||
|  |                     else | |||
|  |                     { | |||
|  |                         Model.Wbs_UnitProject pUnitProject = BLL.UnitProjectService.GetUnitProjectByUnitProjectId(wbsSet.UnitProjectId); | |||
|  |                         if (pUnitProject.Unit != null) | |||
|  |                         { | |||
|  |                             unit = pUnitProject.Unit; | |||
|  |                         } | |||
|  |                         if (pUnitProject.BudgetUnitPrice != null) | |||
|  |                         { | |||
|  |                             budgetUnitPrice = pUnitProject.BudgetUnitPrice; | |||
|  |                             this.Grid2.Columns[4].Hidden = true; | |||
|  |                             this.Grid2.Columns[5].Hidden = true; | |||
|  |                         } | |||
|  |                         if (pUnitProject.CostUnivalent != null) | |||
|  |                         { | |||
|  |                             costUnivalent = pUnitProject.CostUnivalent; | |||
|  |                         } | |||
|  |                     } | |||
|  |                     item.Unit = wbsSet.Unit == null ? unit : wbsSet.Unit; | |||
|  |                     item.BudgetUnitPrice = wbsSet.BudgetUnitPrice == null ? budgetUnitPrice : wbsSet.BudgetUnitPrice; | |||
|  |                     item.CostUnivalent = wbsSet.CostUnivalent == null ? costUnivalent : wbsSet.CostUnivalent; | |||
|  |                     item.ChildEngineerQuantitys = BLL.WbsSetService.GetChildEngineerQuantitys(this.trWBS.SelectedNode.NodeID); | |||
|  |                     items.Add(item); | |||
|  |                 } | |||
|  |                 this.Grid2.DataSource = items; | |||
|  |                 this.Grid2.DataBind(); | |||
|  |             } | |||
|  |         } | |||
|  | 
 | |||
|  |         /// <summary> | |||
|  |         /// 加载Grid | |||
|  |         /// </summary> | |||
|  |         private void BindGrid() | |||
|  |         { | |||
|  |             List<Model.WBSSetItem> items = new List<Model.WBSSetItem>(); | |||
|  |             if (this.trWBS.SelectedNode != null) | |||
|  |             { | |||
|  |                 if (this.trWBS.SelectedNode.CommandName == "installation") | |||
|  |                 { | |||
|  |                     this.Grid1.Columns[0].HeaderText = "装置"; | |||
|  |                     this.Grid1.Columns[1].HeaderText = "专业"; | |||
|  |                     Model.Project_Installation installation = BLL.Project_InstallationService.GetInstallationByInstallationId(this.trWBS.SelectedNodeID); | |||
|  |                     Model.WBSSetItem parentItem = new Model.WBSSetItem(); | |||
|  |                     if (installation != null) | |||
|  |                     { | |||
|  |                         Model.Base_Project project = BLL.ProjectService.GetProjectByProjectId(this.CurrUser.LoginProjectId); | |||
|  |                         parentItem.Id = this.trWBS.SelectedNode.NodeID; | |||
|  |                         parentItem.Code = installation.InstallationCode; | |||
|  |                         parentItem.Name = installation.InstallationName; | |||
|  |                         parentItem.Type = "installation"; | |||
|  |                         parentItem.StartDate = installation.StartDate; | |||
|  |                         parentItem.EndDate = installation.EndDate; | |||
|  |                         parentItem.Weights = installation.Weights; | |||
|  |                         if (project.ConstructionMoney != null) | |||
|  |                         { | |||
|  |                             parentItem.WeightsMoney = Convert.ToDecimal(project.ConstructionMoney * installation.Weights / 100); | |||
|  |                             parentItem.WeightsMoneyStr = decimal.Round(Convert.ToDecimal(parentItem.WeightsMoney), 2).ToString(); | |||
|  |                         } | |||
|  |                         items.Add(parentItem); | |||
|  |                     } | |||
|  |                     var cnProfessions = from x in Funs.DB.WBS_CnProfession where x.InstallationId == this.trWBS.SelectedNodeID orderby x.OldId select x; | |||
|  |                     foreach (var cnProfession in cnProfessions) | |||
|  |                     { | |||
|  |                         var unitProjects = from x in Funs.DB.Wbs_UnitProject where x.CnProfessionId == cnProfession.CnProfessionId && x.IsApprove == true select x; | |||
|  |                         if (unitProjects.Count() > 0) | |||
|  |                         { | |||
|  |                             Model.WBSSetItem item = new Model.WBSSetItem(); | |||
|  |                             item.Id = cnProfession.CnProfessionId; | |||
|  |                             item.ChildCode = cnProfession.CnProfessionCode; | |||
|  |                             item.ChildName = cnProfession.CnProfessionName; | |||
|  |                             item.Type = "cnProfession"; | |||
|  |                             item.StartDate = cnProfession.StartDate; | |||
|  |                             item.EndDate = cnProfession.EndDate; | |||
|  |                             item.Weights = cnProfession.Weights; | |||
|  |                             item.WeightsMoney = cnProfession.WeightsMoney; | |||
|  |                             item.WeightsMoneys = parentItem.WeightsMoney; | |||
|  |                             if (item.WeightsMoney != null) | |||
|  |                             { | |||
|  |                                 item.WeightsMoneyStr = decimal.Round(Convert.ToDecimal(item.WeightsMoney), 2).ToString(); | |||
|  |                             } | |||
|  |                             items.Add(item); | |||
|  |                         } | |||
|  |                     } | |||
|  |                 } | |||
|  |                 else if (this.trWBS.SelectedNode.CommandName == "cnProfession") | |||
|  |                 { | |||
|  |                     this.Grid1.Columns[0].HeaderText = "专业"; | |||
|  |                     this.Grid1.Columns[1].HeaderText = "单位工程"; | |||
|  |                     Model.WBS_CnProfession cnProfession = BLL.CnProfessionService.GetCnProfessionByCnProfessionId(this.trWBS.SelectedNode.NodeID); | |||
|  |                     Model.WBSSetItem parentItem = new Model.WBSSetItem(); | |||
|  |                     if (cnProfession != null) | |||
|  |                     { | |||
|  |                         parentItem.Id = this.trWBS.SelectedNode.NodeID; | |||
|  |                         parentItem.Code = cnProfession.CnProfessionCode; | |||
|  |                         parentItem.Name = cnProfession.CnProfessionName; | |||
|  |                         parentItem.Type = "cnProfession"; | |||
|  |                         parentItem.StartDate = cnProfession.StartDate; | |||
|  |                         parentItem.EndDate = cnProfession.EndDate; | |||
|  |                         parentItem.Weights = cnProfession.Weights; | |||
|  |                         parentItem.WeightsMoney = cnProfession.WeightsMoney; | |||
|  |                         parentItem.WeightsMoneyStr = decimal.Round(Convert.ToDecimal(parentItem.WeightsMoney), 2).ToString(); | |||
|  |                         items.Add(parentItem); | |||
|  |                     } | |||
|  |                     var unitProjects = from x in Funs.DB.Wbs_UnitProject where x.CnProfessionId == this.trWBS.SelectedNodeID && x.SuperUnitProjectId == null && x.IsApprove == true orderby x.SortIndex, x.UnitProjectCode select x; | |||
|  |                     foreach (var unitProject in unitProjects) | |||
|  |                     { | |||
|  |                         Model.WBSSetItem item = new Model.WBSSetItem(); | |||
|  |                         item.Id = unitProject.UnitProjectId; | |||
|  |                         item.ChildCode = unitProject.UnitProjectCode; | |||
|  |                         item.ChildName = unitProject.UnitProjectName; | |||
|  |                         item.Type = "unitProject"; | |||
|  |                         item.StartDate = unitProject.StartDate; | |||
|  |                         item.EndDate = unitProject.EndDate; | |||
|  |                         item.Weights = unitProject.Weights; | |||
|  |                         item.WeightsMoney = unitProject.WeightsMoney; | |||
|  |                         item.WeightsMoneys = parentItem.WeightsMoney; | |||
|  |                         if (item.WeightsMoney != null) | |||
|  |                         { | |||
|  |                             item.WeightsMoneyStr = decimal.Round(Convert.ToDecimal(item.WeightsMoney), 2).ToString(); | |||
|  |                         } | |||
|  |                         items.Add(item); | |||
|  |                     } | |||
|  |                 } | |||
|  |                 else if (this.trWBS.SelectedNode.CommandName == "unitProject") | |||
|  |                 { | |||
|  |                     this.Grid1.Columns[0].HeaderText = "单位工程"; | |||
|  |                     Model.Wbs_UnitProject unitProject = BLL.UnitProjectService.GetUnitProjectByUnitProjectId(this.trWBS.SelectedNode.NodeID); | |||
|  |                     Model.WBSSetItem parentItem = new Model.WBSSetItem(); | |||
|  |                     if (unitProject != null) | |||
|  |                     { | |||
|  |                         parentItem.Id = this.trWBS.SelectedNode.NodeID; | |||
|  |                         parentItem.Code = unitProject.UnitProjectCode; | |||
|  |                         parentItem.Name = unitProject.UnitProjectName; | |||
|  |                         parentItem.Type = "unitProject"; | |||
|  |                         parentItem.StartDate = unitProject.StartDate; | |||
|  |                         parentItem.EndDate = unitProject.EndDate; | |||
|  |                         parentItem.Weights = unitProject.Weights; | |||
|  |                         parentItem.WeightsMoney = unitProject.WeightsMoney; | |||
|  |                         parentItem.WeightsMoneyStr = decimal.Round(Convert.ToDecimal(parentItem.WeightsMoney), 2).ToString(); | |||
|  |                         items.Add(parentItem); | |||
|  |                     } | |||
|  |                     var childUnitProjects = from x in Funs.DB.Wbs_UnitProject where x.SuperUnitProjectId == this.trWBS.SelectedNode.NodeID && x.IsApprove == true orderby x.SortIndex, x.UnitProjectCode select x; | |||
|  |                     if (childUnitProjects.Count() > 0)   //存在子单位工程 | |||
|  |                     { | |||
|  |                         this.Grid1.Columns[1].HeaderText = "子单位工程"; | |||
|  |                         foreach (var childUnitProject in childUnitProjects) | |||
|  |                         { | |||
|  |                             Model.WBSSetItem item = new Model.WBSSetItem(); | |||
|  |                             item.Id = childUnitProject.UnitProjectId; | |||
|  |                             item.ChildCode = childUnitProject.UnitProjectCode; | |||
|  |                             item.ChildName = childUnitProject.UnitProjectName; | |||
|  |                             item.Type = "childUnitProject"; | |||
|  |                             item.StartDate = childUnitProject.StartDate; | |||
|  |                             item.EndDate = childUnitProject.EndDate; | |||
|  |                             item.Weights = childUnitProject.Weights; | |||
|  |                             item.WeightsMoney = childUnitProject.WeightsMoney; | |||
|  |                             item.WeightsMoneys = parentItem.WeightsMoney; | |||
|  |                             if (item.WeightsMoney != null) | |||
|  |                             { | |||
|  |                                 item.WeightsMoneyStr = decimal.Round(Convert.ToDecimal(item.WeightsMoney), 2).ToString(); | |||
|  |                             } | |||
|  |                             items.Add(item); | |||
|  |                         } | |||
|  |                     } | |||
|  |                     else | |||
|  |                     { | |||
|  |                         this.Grid1.Columns[1].HeaderText = "分部工程"; | |||
|  |                         var wbsSet1s = from x in Funs.DB.Wbs_WbsSet where x.Flag == 1 && x.UnitProjectId == this.trWBS.SelectedNode.NodeID && x.IsApprove == true orderby x.SortIndex, x.WbsSetCode select x; | |||
|  |                         if (wbsSet1s.Count() > 0) | |||
|  |                         { | |||
|  |                             foreach (var wbsSet1 in wbsSet1s) | |||
|  |                             { | |||
|  |                                 Model.WBSSetItem item = new Model.WBSSetItem(); | |||
|  |                                 item.Id = wbsSet1.WbsSetId; | |||
|  |                                 item.ChildCode = wbsSet1.WbsSetCode; | |||
|  |                                 item.ChildName = wbsSet1.WbsSetName; | |||
|  |                                 item.Type = "wbsSet"; | |||
|  |                                 item.StartDate = wbsSet1.StartDate; | |||
|  |                                 item.EndDate = wbsSet1.EndDate; | |||
|  |                                 item.Weights = wbsSet1.Weights; | |||
|  |                                 item.WeightsMoney = wbsSet1.WeightsMoney; | |||
|  |                                 item.WeightsMoneys = parentItem.WeightsMoney; | |||
|  |                                 if (item.WeightsMoney != null) | |||
|  |                                 { | |||
|  |                                     item.WeightsMoneyStr = decimal.Round(Convert.ToDecimal(item.WeightsMoney), 2).ToString(); | |||
|  |                                 } | |||
|  |                                 items.Add(item); | |||
|  |                             } | |||
|  |                         } | |||
|  |                         else    //单位工程下直接是分项内容,如质量行为 | |||
|  |                         { | |||
|  |                             var wbsSet3s = from x in Funs.DB.Wbs_WbsSet where x.Flag == 3 && x.UnitProjectId == this.trWBS.SelectedNode.NodeID && x.IsApprove == true orderby x.SortIndex, x.WbsSetCode select x; | |||
|  |                             if (wbsSet3s.Count() > 0) | |||
|  |                             { | |||
|  |                                 foreach (var wbsSet3 in wbsSet3s) | |||
|  |                                 { | |||
|  |                                     Model.WBSSetItem item = new Model.WBSSetItem(); | |||
|  |                                     item.Id = wbsSet3.WbsSetId; | |||
|  |                                     item.ChildCode = wbsSet3.WbsSetCode; | |||
|  |                                     item.ChildName = wbsSet3.WbsSetName; | |||
|  |                                     item.Type = "wbsSet"; | |||
|  |                                     item.StartDate = wbsSet3.StartDate; | |||
|  |                                     item.EndDate = wbsSet3.EndDate; | |||
|  |                                     item.Weights = wbsSet3.Weights; | |||
|  |                                     item.WeightsMoney = wbsSet3.WeightsMoney; | |||
|  |                                     item.WeightsMoneys = parentItem.WeightsMoney; | |||
|  |                                     if (item.WeightsMoney != null) | |||
|  |                                     { | |||
|  |                                         item.WeightsMoneyStr = decimal.Round(Convert.ToDecimal(item.WeightsMoney), 2).ToString(); | |||
|  |                                     } | |||
|  |                                     items.Add(item); | |||
|  |                                 } | |||
|  |                             } | |||
|  |                         } | |||
|  |                     } | |||
|  |                 } | |||
|  |                 else if (this.trWBS.SelectedNode.CommandName == "childUnitProject") | |||
|  |                 { | |||
|  |                     this.Grid1.Columns[0].HeaderText = "子单位工程"; | |||
|  |                     this.Grid1.Columns[1].HeaderText = "分部工程"; | |||
|  |                     Model.Wbs_UnitProject unitProject = BLL.UnitProjectService.GetUnitProjectByUnitProjectId(this.trWBS.SelectedNode.NodeID); | |||
|  |                     Model.WBSSetItem parentItem = new Model.WBSSetItem(); | |||
|  |                     if (unitProject != null) | |||
|  |                     { | |||
|  |                         parentItem.Id = this.trWBS.SelectedNode.NodeID; | |||
|  |                         parentItem.Code = unitProject.UnitProjectCode; | |||
|  |                         parentItem.Name = unitProject.UnitProjectName; | |||
|  |                         parentItem.Type = "unitProject"; | |||
|  |                         parentItem.StartDate = unitProject.StartDate; | |||
|  |                         parentItem.EndDate = unitProject.EndDate; | |||
|  |                         parentItem.Weights = unitProject.Weights; | |||
|  |                         parentItem.WeightsMoney = unitProject.WeightsMoney; | |||
|  |                         parentItem.WeightsMoneyStr = decimal.Round(Convert.ToDecimal(parentItem.WeightsMoney), 2).ToString(); | |||
|  |                         items.Add(parentItem); | |||
|  |                     } | |||
|  |                     var wbsSet1s = from x in Funs.DB.Wbs_WbsSet where x.Flag == 1 && x.UnitProjectId == this.trWBS.SelectedNode.NodeID && x.IsApprove == true orderby x.SortIndex, x.WbsSetCode select x; | |||
|  |                     foreach (var wbsSet1 in wbsSet1s) | |||
|  |                     { | |||
|  |                         Model.WBSSetItem item = new Model.WBSSetItem(); | |||
|  |                         item.Id = wbsSet1.WbsSetId; | |||
|  |                         item.ChildCode = wbsSet1.WbsSetCode; | |||
|  |                         item.ChildName = wbsSet1.WbsSetName; | |||
|  |                         item.Type = "wbsSet"; | |||
|  |                         item.StartDate = wbsSet1.StartDate; | |||
|  |                         item.EndDate = wbsSet1.EndDate; | |||
|  |                         item.Weights = wbsSet1.Weights; | |||
|  |                         item.WeightsMoney = wbsSet1.WeightsMoney; | |||
|  |                         item.WeightsMoneys = parentItem.WeightsMoney; | |||
|  |                         if (item.WeightsMoney != null) | |||
|  |                         { | |||
|  |                             item.WeightsMoneyStr = decimal.Round(Convert.ToDecimal(item.WeightsMoney), 2).ToString(); | |||
|  |                         } | |||
|  |                         items.Add(item); | |||
|  |                     } | |||
|  |                 } | |||
|  |                 else if (this.trWBS.SelectedNode.CommandName == "wbsSet") | |||
|  |                 { | |||
|  |                     Model.Wbs_WbsSet wbsSet = BLL.WbsSetService.GetWbsSetByWbsSetId(this.trWBS.SelectedNode.NodeID); | |||
|  |                     string column0 = string.Empty; | |||
|  |                     if (wbsSet.Flag == 1) | |||
|  |                     { | |||
|  |                         column0 = "分部工程"; | |||
|  |                     } | |||
|  |                     else if (wbsSet.Flag == 2) | |||
|  |                     { | |||
|  |                         column0 = "子分部工程"; | |||
|  |                     } | |||
|  |                     else if (wbsSet.Flag == 3) | |||
|  |                     { | |||
|  |                         column0 = "分项工程"; | |||
|  |                     } | |||
|  |                     else if (wbsSet.Flag == 4) | |||
|  |                     { | |||
|  |                         column0 = "子分项工程"; | |||
|  |                     } | |||
|  |                     this.Grid1.Columns[0].HeaderText = column0; | |||
|  |                     Model.WBSSetItem parentItem = new Model.WBSSetItem(); | |||
|  |                     if (wbsSet != null) | |||
|  |                     { | |||
|  |                         parentItem.Id = this.trWBS.SelectedNode.NodeID; | |||
|  |                         parentItem.Code = wbsSet.WbsSetCode; | |||
|  |                         parentItem.Name = wbsSet.WbsSetName; | |||
|  |                         parentItem.Type = "wbsSet"; | |||
|  |                         parentItem.StartDate = wbsSet.StartDate; | |||
|  |                         parentItem.EndDate = wbsSet.EndDate; | |||
|  |                         parentItem.Weights = wbsSet.Weights; | |||
|  |                         parentItem.WeightsMoney = wbsSet.WeightsMoney; | |||
|  |                         if (parentItem.Weights != null && parentItem.WeightsMoney == null) | |||
|  |                         { | |||
|  |                             parentItem.WeightsMoney = wbsSet.WeightsMoney * parentItem.Weights / 100; | |||
|  |                         } | |||
|  |                         parentItem.WeightsMoneyStr = decimal.Round(Convert.ToDecimal(parentItem.WeightsMoney), 2).ToString(); | |||
|  |                         items.Add(parentItem); | |||
|  |                     } | |||
|  |                     var childWbsSets = BLL.WbsSetService.GetApproveWbsSetsBySuperWbsSetId(this.trWBS.SelectedNode.NodeID); | |||
|  |                     string column1 = string.Empty; | |||
|  |                     if (childWbsSets.Count() > 0) | |||
|  |                     { | |||
|  |                         if (childWbsSets[0].Flag == 2) | |||
|  |                         { | |||
|  |                             column1 = "子分部工程"; | |||
|  |                         } | |||
|  |                         else if (childWbsSets[0].Flag == 3) | |||
|  |                         { | |||
|  |                             column1 = "分项工程"; | |||
|  |                         } | |||
|  |                         else if (childWbsSets[0].Flag == 4) | |||
|  |                         { | |||
|  |                             column1 = "子分项工程"; | |||
|  |                         } | |||
|  |                         this.Grid1.Columns[1].HeaderText = column1; | |||
|  |                     } | |||
|  |                     else | |||
|  |                     { | |||
|  |                         this.Grid1.Columns[1].HeaderText = string.Empty; | |||
|  |                     } | |||
|  |                     foreach (var childWbsSet in childWbsSets) | |||
|  |                     { | |||
|  |                         Model.WBSSetItem item = new Model.WBSSetItem(); | |||
|  |                         item.Id = childWbsSet.WbsSetId; | |||
|  |                         item.ChildCode = childWbsSet.WbsSetCode; | |||
|  |                         item.ChildName = childWbsSet.WbsSetName; | |||
|  |                         item.Type = "wbsSet"; | |||
|  |                         item.StartDate = childWbsSet.StartDate; | |||
|  |                         item.EndDate = childWbsSet.EndDate; | |||
|  |                         item.Weights = childWbsSet.Weights; | |||
|  |                         item.WeightsMoney = childWbsSet.WeightsMoney; | |||
|  |                         item.WeightsMoneys = parentItem.WeightsMoney; | |||
|  |                         if (item.WeightsMoney != null) | |||
|  |                         { | |||
|  |                             item.WeightsMoneyStr = decimal.Round(Convert.ToDecimal(item.WeightsMoney), 2).ToString(); | |||
|  |                         } | |||
|  |                         items.Add(item); | |||
|  |                     } | |||
|  |                 } | |||
|  |                 this.Grid1.DataSource = items; | |||
|  |                 this.Grid1.DataBind(); | |||
|  |                 if (this.Grid1.Rows.Count > 0) | |||
|  |                 { | |||
|  |                     Grid1.Rows[0].CellCssClasses[7] = "f-grid-cell-uneditable"; | |||
|  |                     Grid1.Rows[0].CellCssClasses[8] = "f-grid-cell-uneditable"; | |||
|  |                 } | |||
|  |             } | |||
|  |         } | |||
|  |         #endregion | |||
|  | 
 | |||
|  |         #region 判断按钮权限 | |||
|  |         /// <summary> | |||
|  |         /// 判断按钮权限 | |||
|  |         /// </summary> | |||
|  |         private void GetButtonPower() | |||
|  |         { | |||
|  |             if (Request.Params["value"] == "0") | |||
|  |             { | |||
|  |                 return; | |||
|  |             } | |||
|  |             var buttonList = BLL.CommonService.GetAllButtonList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, BLL.Const.WeightsAuditMenuId); | |||
|  |             if (buttonList.Count() > 0) | |||
|  |             { | |||
|  |                 if (buttonList.Contains(BLL.Const.BtnSave)) | |||
|  |                 { | |||
|  |                     this.btnSave.Hidden = false; | |||
|  |                     this.btnSave2.Hidden = false; | |||
|  |                 } | |||
|  |                 if (buttonList.Contains(BLL.Const.BtnCancelAuditing)) | |||
|  |                 { | |||
|  |                     this.btnClearAudit.Hidden = false; | |||
|  |                 } | |||
|  |             } | |||
|  |         } | |||
|  |         #endregion | |||
|  | 
 | |||
|  |         #region  计算装置权重 | |||
|  |         /// <summary> | |||
|  |         /// 计算装置权重 | |||
|  |         /// </summary> | |||
|  |         /// <param name="sender"></param> | |||
|  |         /// <param name="e"></param> | |||
|  |         protected void btnUpdateInstallationWeights_Click(object sender, EventArgs e) | |||
|  |         { | |||
|  |             if (this.trWBS.SelectedNode != null) | |||
|  |             { | |||
|  |                 if (this.trWBS.SelectedNode.CommandName == "installation") | |||
|  |                 { | |||
|  |                     string installationId = this.trWBS.SelectedNodeID; | |||
|  |                     Model.Project_Installation installation = BLL.Project_InstallationService.GetInstallationByInstallationId(installationId); | |||
|  |                     if (installation.SuperInstallationId == "0") | |||
|  |                     { | |||
|  |                         var installations = (from x in Funs.DB.Project_Installation where x.ProjectId == this.CurrUser.LoginProjectId && x.SuperInstallationId == "0" select x).ToList(); | |||
|  |                         decimal installationTotalMoney = installations.Sum(x => x.WeightsMoney ?? 0); | |||
|  |                         decimal totalInstallationWeights = 0; | |||
|  |                         for (int i = 0; i < installations.Count(); i++) | |||
|  |                         { | |||
|  |                             if (installations[i].WeightsMoney != null && installationTotalMoney > 0) | |||
|  |                             { | |||
|  |                                 if (i != installations.Count() - 1) | |||
|  |                                 { | |||
|  |                                     decimal installationWeights = decimal.Round(Convert.ToDecimal(installations[i].WeightsMoney) / installationTotalMoney * 100, 2); | |||
|  |                                     installations[i].Weights = installationWeights; | |||
|  |                                     totalInstallationWeights += installationWeights; | |||
|  |                                     BLL.Project_InstallationService.UpdateInstallation(installations[i]); | |||
|  |                                 } | |||
|  |                                 else   //最后一项的权重为100减去前面项的权重 | |||
|  |                                 { | |||
|  |                                     installations[i].Weights = 100 - totalInstallationWeights; | |||
|  |                                     BLL.Project_InstallationService.UpdateInstallation(installations[i]); | |||
|  |                                 } | |||
|  |                             } | |||
|  |                         } | |||
|  |                         //工序 | |||
|  |                         var installation1s = (from x in Funs.DB.Project_Installation where x.ProjectId == this.CurrUser.LoginProjectId && x.SuperInstallationId == installationId select x).ToList(); | |||
|  |                         if (installation1s.Count > 0)    //非总图装置 | |||
|  |                         { | |||
|  |                             decimal installation1TotalMoney = installation.WeightsMoney ?? 0; | |||
|  |                             decimal totalInstallation1Weights = 0; | |||
|  |                             for (int i = 0; i < installation1s.Count(); i++) | |||
|  |                             { | |||
|  |                                 if (installation1s[i].WeightsMoney != null && installation1TotalMoney > 0) | |||
|  |                                 { | |||
|  |                                     if (i != installation1s.Count() - 1) | |||
|  |                                     { | |||
|  |                                         decimal installation1Weights = decimal.Round(Convert.ToDecimal(installation1s[i].WeightsMoney) / installation1TotalMoney * 100, 2); | |||
|  |                                         installation1s[i].Weights = installation1Weights; | |||
|  |                                         totalInstallation1Weights += installation1Weights; | |||
|  |                                         BLL.Project_InstallationService.UpdateInstallation(installation1s[i]); | |||
|  |                                     } | |||
|  |                                     else   //最后一项的权重为100减去前面项的权重 | |||
|  |                                     { | |||
|  |                                         installation1s[i].Weights = 100 - totalInstallation1Weights; | |||
|  |                                         BLL.Project_InstallationService.UpdateInstallation(installation1s[i]); | |||
|  |                                     } | |||
|  |                                     //主项 | |||
|  |                                     var installation2s = (from x in Funs.DB.Project_Installation where x.ProjectId == this.CurrUser.LoginProjectId && x.SuperInstallationId == installation1s[i].InstallationId select x).ToList(); | |||
|  |                                     decimal installation2TotalMoney = installation1s[i].WeightsMoney ?? 0; | |||
|  |                                     decimal totalInstallation2Weights = 0; | |||
|  |                                     for (int j = 0; j < installation2s.Count(); j++) | |||
|  |                                     { | |||
|  |                                         if (installation2s[j].WeightsMoney != null && installation2TotalMoney > 0) | |||
|  |                                         { | |||
|  |                                             if (j != installation2s.Count() - 1) | |||
|  |                                             { | |||
|  |                                                 decimal weights = decimal.Round(Convert.ToDecimal(installation2s[j].WeightsMoney) / installation2TotalMoney * 100, 2); | |||
|  |                                                 installation2s[j].Weights = weights; | |||
|  |                                                 totalInstallation2Weights += weights; | |||
|  |                                                 BLL.Project_InstallationService.UpdateInstallation(installation2s[j]); | |||
|  |                                             } | |||
|  |                                             else   //最后一项的权重为100减去前面项的权重 | |||
|  |                                             { | |||
|  |                                                 installation2s[j].Weights = 100 - totalInstallation2Weights; | |||
|  |                                                 BLL.Project_InstallationService.UpdateInstallation(installation2s[j]); | |||
|  |                                             } | |||
|  |                                             //专业 | |||
|  |                                             var cnProfessions = (from x in Funs.DB.WBS_CnProfession where x.ProjectId == this.CurrUser.LoginProjectId && x.InstallationId == installation2s[j].InstallationId select x).ToList(); | |||
|  |                                             decimal cnProfessionTotalMoney = installation2s[j].WeightsMoney ?? 0; | |||
|  |                                             decimal totalCnProfessionWeights = 0; | |||
|  |                                             for (int a = 0; a < cnProfessions.Count(); a++) | |||
|  |                                             { | |||
|  |                                                 if (cnProfessions[a].WeightsMoney != null && cnProfessionTotalMoney > 0) | |||
|  |                                                 { | |||
|  |                                                     if (a != cnProfessions.Count() - 1) | |||
|  |                                                     { | |||
|  |                                                         decimal weights = decimal.Round(Convert.ToDecimal(cnProfessions[a].WeightsMoney) / cnProfessionTotalMoney * 100, 2); | |||
|  |                                                         cnProfessions[a].Weights = weights; | |||
|  |                                                         totalCnProfessionWeights += weights; | |||
|  |                                                         BLL.CnProfessionService.UpdateCnProfession(cnProfessions[a]); | |||
|  |                                                     } | |||
|  |                                                     else   //最后一项的权重为100减去前面项的权重 | |||
|  |                                                     { | |||
|  |                                                         cnProfessions[a].Weights = 100 - totalCnProfessionWeights; | |||
|  |                                                         BLL.CnProfessionService.UpdateCnProfession(cnProfessions[a]); | |||
|  |                                                     } | |||
|  |                                                     //单位工程 | |||
|  |                                                     var unitProjects = (from x in Funs.DB.Wbs_UnitProject where x.ProjectId == this.CurrUser.LoginProjectId && x.SuperUnitProjectId == null && x.CnProfessionId == cnProfessions[a].CnProfessionId select x).ToList(); | |||
|  |                                                     decimal unitProjectTotalMoney = cnProfessions[a].WeightsMoney ?? 0; | |||
|  |                                                     decimal totalUnitProjectWeights = 0; | |||
|  |                                                     for (int b = 0; b < unitProjects.Count(); b++) | |||
|  |                                                     { | |||
|  |                                                         if (unitProjects[b].WeightsMoney != null && unitProjectTotalMoney > 0) | |||
|  |                                                         { | |||
|  |                                                             if (b != unitProjects.Count() - 1) | |||
|  |                                                             { | |||
|  |                                                                 decimal weights = decimal.Round(Convert.ToDecimal(unitProjects[b].WeightsMoney) / unitProjectTotalMoney * 100, 2); | |||
|  |                                                                 unitProjects[b].Weights = weights; | |||
|  |                                                                 totalUnitProjectWeights += weights; | |||
|  |                                                                 BLL.UnitProjectService.UpdateUnitProject(unitProjects[b]); | |||
|  |                                                             } | |||
|  |                                                             else   //最后一项的权重为100减去前面项的权重 | |||
|  |                                                             { | |||
|  |                                                                 unitProjects[b].Weights = 100 - totalUnitProjectWeights; | |||
|  |                                                                 BLL.UnitProjectService.UpdateUnitProject(unitProjects[b]); | |||
|  |                                                             } | |||
|  |                                                             var childUnitProjects = (from x in Funs.DB.Wbs_UnitProject where x.SuperUnitProjectId == unitProjects[b].UnitProjectId select x).ToList(); | |||
|  |                                                             if (childUnitProjects.Count > 0)   //存在子单位工程 | |||
|  |                                                             { | |||
|  |                                                                 decimal childUnitProjectTotalMoney = unitProjects[b].WeightsMoney ?? 0; | |||
|  |                                                                 decimal totalChildUnitProjectWeights = 0; | |||
|  |                                                                 for (int c = 0; c < childUnitProjects.Count(); c++) | |||
|  |                                                                 { | |||
|  |                                                                     if (childUnitProjects[c].WeightsMoney != null && childUnitProjectTotalMoney > 0) | |||
|  |                                                                     { | |||
|  |                                                                         if (c != childUnitProjects.Count() - 1) | |||
|  |                                                                         { | |||
|  |                                                                             decimal weights = decimal.Round(Convert.ToDecimal(childUnitProjects[c].WeightsMoney) / childUnitProjectTotalMoney * 100, 2); | |||
|  |                                                                             childUnitProjects[c].Weights = weights; | |||
|  |                                                                             totalChildUnitProjectWeights += weights; | |||
|  |                                                                             BLL.UnitProjectService.UpdateUnitProject(childUnitProjects[c]); | |||
|  |                                                                         } | |||
|  |                                                                         else   //最后一项的权重为100减去前面项的权重 | |||
|  |                                                                         { | |||
|  |                                                                             childUnitProjects[c].Weights = 100 - totalChildUnitProjectWeights; | |||
|  |                                                                             BLL.UnitProjectService.UpdateUnitProject(childUnitProjects[c]); | |||
|  |                                                                         } | |||
|  |                                                                         SetWbsSetWeights(childUnitProjects[c]); | |||
|  |                                                                     } | |||
|  |                                                                 } | |||
|  |                                                             } | |||
|  |                                                             else   //不存在子单位工程 | |||
|  |                                                             { | |||
|  |                                                                 SetWbsSetWeights(unitProjects[b]); | |||
|  |                                                             } | |||
|  |                                                         } | |||
|  |                                                     } | |||
|  |                                                 } | |||
|  |                                             } | |||
|  |                                         } | |||
|  |                                     } | |||
|  |                                 } | |||
|  |                             } | |||
|  |                         } | |||
|  |                         else   //总图 | |||
|  |                         { | |||
|  |                             var unitProjects = (from x in Funs.DB.Wbs_UnitProject where x.InstallationId == installationId && x.SuperUnitProjectId == null orderby x.SortIndex, x.UnitProjectCode select x).ToList(); | |||
|  |                             decimal unitProjectTotalMoney = installation.WeightsMoney ?? 0; | |||
|  |                             decimal totalUnitProjectWeights = 0; | |||
|  |                             for (int b = 0; b < unitProjects.Count(); b++) | |||
|  |                             { | |||
|  |                                 if (unitProjects[b].WeightsMoney != null && unitProjectTotalMoney > 0) | |||
|  |                                 { | |||
|  |                                     if (b != unitProjects.Count() - 1) | |||
|  |                                     { | |||
|  |                                         decimal weights = decimal.Round(Convert.ToDecimal(unitProjects[b].WeightsMoney) / unitProjectTotalMoney * 100, 2); | |||
|  |                                         unitProjects[b].Weights = weights; | |||
|  |                                         totalUnitProjectWeights += weights; | |||
|  |                                         BLL.UnitProjectService.UpdateUnitProject(unitProjects[b]); | |||
|  |                                     } | |||
|  |                                     else   //最后一项的权重为100减去前面项的权重 | |||
|  |                                     { | |||
|  |                                         unitProjects[b].Weights = 100 - totalUnitProjectWeights; | |||
|  |                                         BLL.UnitProjectService.UpdateUnitProject(unitProjects[b]); | |||
|  |                                     } | |||
|  |                                     SetWbsSetWeights(unitProjects[b]); | |||
|  |                                 } | |||
|  |                             } | |||
|  |                         } | |||
|  |                         Alert.ShowInTop("计算成功!", MessageBoxIcon.Success); | |||
|  |                     } | |||
|  |                     else | |||
|  |                     { | |||
|  |                         Alert.ShowInTop("请选择一个装置!", MessageBoxIcon.Warning); | |||
|  |                         return; | |||
|  |                     } | |||
|  |                 } | |||
|  |                 else | |||
|  |                 { | |||
|  |                     Alert.ShowInTop("请选择一个装置!", MessageBoxIcon.Warning); | |||
|  |                     return; | |||
|  |                 } | |||
|  |             } | |||
|  |             else | |||
|  |             { | |||
|  |                 Alert.ShowInTop("请选择装置!", MessageBoxIcon.Warning); | |||
|  |                 return; | |||
|  |             } | |||
|  |         } | |||
|  | 
 | |||
|  |         /// <summary> | |||
|  |         /// 计算分部分项权重 | |||
|  |         /// </summary> | |||
|  |         /// <param name="unitProject"></param> | |||
|  |         private void SetWbsSetWeights(Model.Wbs_UnitProject unitProject) | |||
|  |         { | |||
|  |             var wbsSet1s = (from x in Funs.DB.Wbs_WbsSet where x.Flag == 1 && x.UnitProjectId == unitProject.UnitProjectId && x.IsApprove == true && x.NoShow == null orderby x.SortIndex, x.WbsSetCode select x).ToList(); | |||
|  |             decimal wbsSet1TotalMoney = unitProject.WeightsMoney ?? 0; | |||
|  |             decimal totalWbsSet1Weights = 0; | |||
|  |             for (int a = 0; a < wbsSet1s.Count(); a++) | |||
|  |             { | |||
|  |                 if (wbsSet1s[a].WeightsMoney != null && wbsSet1TotalMoney > 0) | |||
|  |                 { | |||
|  |                     if (a != wbsSet1s.Count() - 1) | |||
|  |                     { | |||
|  |                         decimal weights = decimal.Round(Convert.ToDecimal(wbsSet1s[a].WeightsMoney) / wbsSet1TotalMoney * 100, 2); | |||
|  |                         wbsSet1s[a].Weights = weights; | |||
|  |                         totalWbsSet1Weights += weights; | |||
|  |                         BLL.WbsSetService.UpdateWbsSet(wbsSet1s[a]); | |||
|  |                     } | |||
|  |                     else   //最后一项的权重为100减去前面项的权重 | |||
|  |                     { | |||
|  |                         wbsSet1s[a].Weights = 100 - totalWbsSet1Weights; | |||
|  |                         BLL.WbsSetService.UpdateWbsSet(wbsSet1s[a]); | |||
|  |                     } | |||
|  |                     var wbsSet2s = (from x in Funs.DB.Wbs_WbsSet where x.SuperWbsSetId == wbsSet1s[a].WbsSetId && x.IsApprove == true && x.NoShow == null orderby x.SortIndex, x.WbsSetCode select x).ToList(); | |||
|  |                     decimal wbsSet2TotalMoney = wbsSet1s[a].WeightsMoney ?? 0; | |||
|  |                     decimal totalWbsSet2Weights = 0; | |||
|  |                     for (int b = 0; b < wbsSet2s.Count(); b++) | |||
|  |                     { | |||
|  |                         if (wbsSet2s[b].WeightsMoney != null && wbsSet2TotalMoney > 0) | |||
|  |                         { | |||
|  |                             if (b != wbsSet2s.Count() - 1) | |||
|  |                             { | |||
|  |                                 decimal weights = decimal.Round(Convert.ToDecimal(wbsSet2s[b].WeightsMoney) / wbsSet2TotalMoney * 100, 2); | |||
|  |                                 wbsSet2s[b].Weights = weights; | |||
|  |                                 totalWbsSet2Weights += weights; | |||
|  |                                 BLL.WbsSetService.UpdateWbsSet(wbsSet2s[b]); | |||
|  |                             } | |||
|  |                             else   //最后一项的权重为100减去前面项的权重 | |||
|  |                             { | |||
|  |                                 wbsSet2s[b].Weights = 100 - totalWbsSet2Weights; | |||
|  |                                 BLL.WbsSetService.UpdateWbsSet(wbsSet2s[b]); | |||
|  |                             } | |||
|  |                             var wbsSet3s = (from x in Funs.DB.Wbs_WbsSet where x.SuperWbsSetId == wbsSet2s[b].WbsSetId && x.IsApprove == true && x.NoShow == null orderby x.SortIndex, x.WbsSetCode select x).ToList(); | |||
|  |                             decimal wbsSet3TotalMoney = wbsSet2s[b].WeightsMoney ?? 0; | |||
|  |                             decimal totalWbsSet3Weights = 0; | |||
|  |                             for (int c = 0; c < wbsSet3s.Count(); c++) | |||
|  |                             { | |||
|  |                                 if (wbsSet3s[c].WeightsMoney != null && wbsSet3TotalMoney > 0) | |||
|  |                                 { | |||
|  |                                     if (c != wbsSet3s.Count() - 1) | |||
|  |                                     { | |||
|  |                                         decimal weights = decimal.Round(Convert.ToDecimal(wbsSet3s[c].WeightsMoney) / wbsSet3TotalMoney * 100, 2); | |||
|  |                                         wbsSet3s[c].Weights = weights; | |||
|  |                                         totalWbsSet3Weights += weights; | |||
|  |                                         BLL.WbsSetService.UpdateWbsSet(wbsSet3s[c]); | |||
|  |                                     } | |||
|  |                                     else   //最后一项的权重为100减去前面项的权重 | |||
|  |                                     { | |||
|  |                                         wbsSet3s[c].Weights = 100 - totalWbsSet3Weights; | |||
|  |                                         BLL.WbsSetService.UpdateWbsSet(wbsSet3s[c]); | |||
|  |                                     } | |||
|  |                                     var wbsSet4s = (from x in Funs.DB.Wbs_WbsSet where x.SuperWbsSetId == wbsSet3s[c].WbsSetId && x.IsApprove == true && x.NoShow == null orderby x.SortIndex, x.WbsSetCode select x).ToList(); | |||
|  |                                     decimal wbsSet4TotalMoney = wbsSet3s[c].WeightsMoney ?? 0; | |||
|  |                                     decimal totalWbsSet4Weights = 0; | |||
|  |                                     for (int d = 0; d < wbsSet4s.Count(); d++) | |||
|  |                                     { | |||
|  |                                         if (wbsSet4s[d].WeightsMoney != null && wbsSet4TotalMoney > 0) | |||
|  |                                         { | |||
|  |                                             if (d != wbsSet4s.Count() - 1) | |||
|  |                                             { | |||
|  |                                                 decimal weights = decimal.Round(Convert.ToDecimal(wbsSet4s[d].WeightsMoney) / wbsSet4TotalMoney * 100, 2); | |||
|  |                                                 wbsSet4s[d].Weights = weights; | |||
|  |                                                 totalWbsSet4Weights += weights; | |||
|  |                                                 BLL.WbsSetService.UpdateWbsSet(wbsSet4s[d]); | |||
|  |                                             } | |||
|  |                                             else   //最后一项的权重为100减去前面项的权重 | |||
|  |                                             { | |||
|  |                                                 wbsSet4s[d].Weights = 100 - totalWbsSet4Weights; | |||
|  |                                                 BLL.WbsSetService.UpdateWbsSet(wbsSet4s[d]); | |||
|  |                                             } | |||
|  |                                         } | |||
|  |                                     } | |||
|  |                                 } | |||
|  |                             } | |||
|  |                         } | |||
|  |                     } | |||
|  |                 } | |||
|  |             } | |||
|  |         } | |||
|  | 
 | |||
|  |         private void UpdateWbsSetWeights(Model.Wbs_WbsSet wbsSet) | |||
|  |         { | |||
|  |             decimal surplusWbsSetWeightsMoney = Funs.GetNewDecimalOrZero(wbsSet.WeightsMoney.ToString());  //剩余专业费 | |||
|  |             int wbsIndex = 0; | |||
|  |             var childWbsSets = from x in Funs.DB.Wbs_WbsSet where x.SuperWbsSetId == wbsSet.WbsSetId && x.IsApprove == true && x.Weights != null && x.Weights > 0 orderby x.Weights, x.SortIndex, x.WbsSetCode select x; | |||
|  |             if (childWbsSets.Count() > 0) | |||
|  |             { | |||
|  |                 var noWeightChildWbsSets = from x in Funs.DB.Wbs_WbsSet where x.SuperWbsSetId == wbsSet.WbsSetId && x.IsApprove == true && (x.Weights == null || x.Weights == 0) orderby x.Weights, x.SortIndex, x.WbsSetCode select x; | |||
|  |                 foreach (var noWeightChildWbsSet in noWeightChildWbsSets) | |||
|  |                 { | |||
|  |                     noWeightChildWbsSet.WeightsMoney = 0; | |||
|  |                     BLL.WbsSetService.UpdateWbsSet(noWeightChildWbsSet); | |||
|  |                 } | |||
|  |                 foreach (var childWbsSet in childWbsSets) | |||
|  |                 { | |||
|  |                     if (wbsIndex < childWbsSets.Count() - 1) | |||
|  |                     { | |||
|  |                         childWbsSet.WeightsMoney = decimal.Round(Convert.ToDecimal(wbsSet.WeightsMoney * childWbsSet.Weights / 100), 2); | |||
|  |                     } | |||
|  |                     else | |||
|  |                     { | |||
|  |                         childWbsSet.WeightsMoney = surplusWbsSetWeightsMoney; | |||
|  |                     } | |||
|  |                     BLL.WbsSetService.UpdateWbsSet(childWbsSet); | |||
|  |                     surplusWbsSetWeightsMoney = surplusWbsSetWeightsMoney - Funs.GetNewDecimalOrZero(childWbsSet.WeightsMoney.ToString()); | |||
|  |                     UpdateWbsSetWeights(childWbsSet); | |||
|  |                     wbsIndex++; | |||
|  |                 } | |||
|  |             } | |||
|  |         } | |||
|  |         #endregion | |||
|  |     } | |||
|  | } |