using BLL; using System; using System.Collections.Generic; using System.Data; using System.Data.SqlClient; using System.Linq; namespace FineUIPro.Web.JDGL.CostAnalysis { public partial class EarnedValueCurve : PageBase { #region 加载 /// /// 加载页面 /// /// /// protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { BLL.UnitService.InitUnitDropDownList(this.drpUnit, this.CurrUser.LoginProjectId, true); BindChart(); InitTreeMenu(); } } #endregion #region 加载 /// /// 加载树 /// private void InitTreeMenu() { this.trWBS.Nodes.Clear(); this.trWBS.ShowBorder = false; this.trWBS.ShowHeader = false; this.trWBS.EnableIcons = true; this.trWBS.AutoScroll = 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(); rootNode.Text = installation.InstallationName; rootNode.NodeID = installation.InstallationId; rootNode.CommandName = "installation"; rootNode.CommandArgument = installation.UnitId; rootNode.ToolTip = installation.InstallationCode; rootNode.EnableClickEvent = true; rootNode.EnableExpandEvent = true; this.trWBS.Nodes.Add(rootNode); var installation1s = from x in Funs.DB.Project_Installation where x.SuperInstallationId == installation.InstallationId orderby x.InstallationCode select x; if (installation1s.Count() > 0) { foreach (var installation1 in installation1s) { TreeNode newNode = new TreeNode(); newNode.Text = installation1.InstallationName; newNode.NodeID = installation1.InstallationId; newNode.CommandName = "installation"; newNode.CommandArgument = installation1.Weights == null ? null : installation1.Weights.ToString(); newNode.ToolTip = installation1.InstallationCode; newNode.EnableClickEvent = true; newNode.Expanded = true; rootNode.Nodes.Add(newNode); var installation2s = from x in Funs.DB.Project_Installation where x.SuperInstallationId == installation1.InstallationId orderby x.InstallationCode select x; foreach (var installation2 in installation2s) { TreeNode newNode2 = new TreeNode(); newNode2.Text = installation2.InstallationName; newNode2.NodeID = installation2.InstallationId; newNode2.CommandName = "installation"; newNode2.CommandArgument = installation2.Weights == null ? null : installation2.Weights.ToString(); newNode2.ToolTip = installation2.InstallationCode; newNode2.EnableClickEvent = true; newNode2.Expanded = true; newNode.Nodes.Add(newNode2); var cnProfessions = from x in Funs.DB.WBS_CnProfession where x.InstallationId == installation2.InstallationId 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) { TreeNode newNode3 = new TreeNode(); newNode3.Text = cnProfession.CnProfessionName; newNode3.NodeID = cnProfession.CnProfessionId; newNode3.CommandName = "cnProfession"; newNode3.CommandArgument = cnProfession.UnitId; newNode3.ToolTip = cnProfession.CnProfessionCode; newNode3.EnableExpandEvent = true; newNode3.EnableClickEvent = true; newNode2.Nodes.Add(newNode3); TreeNode emptyNode = new TreeNode(); emptyNode.Text = ""; emptyNode.NodeID = ""; newNode3.Nodes.Add(emptyNode); } } } } } else { TreeNode emptyNode = new TreeNode(); emptyNode.Text = ""; emptyNode.NodeID = ""; rootNode.Nodes.Add(emptyNode); } } } #endregion #region Tree展开事件 /// /// 树展开事件 /// /// /// protected void trWBS_NodeExpand(object sender, TreeNodeEventArgs e) { BindChart(); 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(); 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(); 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(); 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(); 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(); 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.SuperWbsSetId == null && 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(); 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.SuperWbsSetId == null && 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(); 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.SuperWbsSetId == null && 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(); 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(); 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 下拉选择事件 /// /// 单位下拉选择事件 /// /// /// protected void drpUnit_SelectedIndexChanged(object sender, EventArgs e) { List nodeIds = new List(); if (this.drpUnit.SelectedValue != BLL.Const._Null) { foreach (var item in this.trWBS.Nodes) { if (item.CommandArgument == this.drpUnit.SelectedValue) { nodeIds.Add(item.NodeID); } foreach (var item1 in item.Nodes) { foreach (var item2 in item1.Nodes) { foreach (var item3 in item2.Nodes) { if (item3.CommandArgument == this.drpUnit.SelectedValue) { nodeIds.Add(item3.NodeID); } } } } } } this.trWBS.SelectedNodeIDArray = nodeIds.ToArray(); BindChart(); } #endregion #region Tree点击事件 /// /// Tree点击事件 /// /// /// protected void trWBS_NodeCommand(object sender, TreeCommandEventArgs e) { BindChart(); } #endregion #region 数据绑定 /// /// 数据绑定 /// private void BindChart() { string[] nodeIds = this.trWBS.SelectedNodeIDArray; string toWbs = string.Empty; foreach (var nodeId in nodeIds) { toWbs += nodeId + ","; } string strSql = "select distinct (cast(YEAR(Months) as varchar(4))+'.'+cast(MONTH(Months) as varchar(2))) as 月份,t.Months, (select SUM(PlanValue) from dbo.WbsDetail where Months=t.Months and CHARINDEX(ToWbs,@ToWbs)>0) as 计划值," + "(select SUM(PlanValue) from dbo.WbsDetail where Months<=t.Months and CHARINDEX(ToWbs,@ToWbs)>0) as 累计计划值 ," + "(select SUM(CompleteValue) from dbo.WbsDetail where Months=t.Months and CHARINDEX(ToWbs,@ToWbs)>0) as 完成值," + "(select SUM(CompleteValue) from dbo.WbsDetail where Months<=t.Months and CHARINDEX(ToWbs,@ToWbs)>0) as 累计完成值," + "(select SUM(RealValue) from dbo.WbsDetail where Months=t.Months and CHARINDEX(ToWbs,@ToWbs)>0) as 实耗值," + "(select SUM(RealValue) from dbo.WbsDetail where Months<=t.Months and CHARINDEX(ToWbs,@ToWbs)>0) as 累计实耗值 " + "from dbo.WbsDetail as t where CHARINDEX(t.ToWbs,@ToWbs)>0 order by t.Months"; string date = DateTime.Now.Year + "-" + DateTime.Now.Month + "-01"; SqlParameter[] parameter = new SqlParameter[] { new SqlParameter("@ToWbs",toWbs), new SqlParameter("@Months",date), }; DataTable dt = SQLHelper.GetDataTableRunText(strSql, parameter); this.Grid1.DataSource = dt; this.Grid1.DataBind(); this.ChartEV.CreateMaryChart(dt, 920, 420, null); } #endregion #region 将DataTable行列转换 /// /// 将DataTable行列转换 /// /// 要转换的DataTable /// 要作为Column的哪列 /// private DataTable Col2Row(DataTable src, int columnHead) { DataTable result = new DataTable(); DataColumn myHead = src.Columns[columnHead]; result.Columns.Add(myHead.ColumnName); FineUIPro.RenderField bf; bf = new FineUIPro.RenderField(); bf.ColumnID = myHead.ColumnName; bf.DataField = myHead.ColumnName; bf.HeaderText = myHead.ColumnName; Grid1.Columns.Add(bf); for (int i = 0; i < src.Rows.Count; i++) { result.Columns.Add(src.Rows[i][myHead].ToString()); bf = new FineUIPro.RenderField(); bf.ColumnID = src.Rows[i][myHead].ToString(); bf.DataField = src.Rows[i][myHead].ToString(); bf.HeaderText = src.Rows[i][myHead].ToString(); Grid1.Columns.Add(bf); } Grid1.DataKeyNames = new string[] { "月份" }; foreach (DataColumn col in src.Columns) { if (col == myHead) continue; object[] newRow = new object[src.Rows.Count + 1]; newRow[0] = col.ColumnName; for (int i = 0; i < src.Rows.Count; i++) { newRow[i + 1] = src.Rows[i][col]; } result.Rows.Add(newRow); } return result; } private DataTable Col2Row(DataTable src, string columnHead) { for (int i = 0; i < src.Columns.Count; i++) { if (src.Columns[i].ColumnName.ToUpper() == columnHead.ToUpper()) return Col2Row(src, i); } return new DataTable(); } #endregion } }