370 lines
		
	
	
		
			21 KiB
		
	
	
	
		
			C#
		
	
	
	
			
		
		
	
	
			370 lines
		
	
	
		
			21 KiB
		
	
	
	
		
			C#
		
	
	
	
| using BLL;
 | |
| using System;
 | |
| using System.Collections.Generic;
 | |
| using System.Linq;
 | |
| using System.Text;
 | |
| 
 | |
| namespace FineUIPro.Web.JDGL.WBS
 | |
| {
 | |
|     public partial class WBSOut : PageBase
 | |
|     {
 | |
|         #region 加载页面
 | |
|         /// <summary>
 | |
|         /// 加载页面
 | |
|         /// </summary>
 | |
|         /// <param name="sender"></param>
 | |
|         /// <param name="e"></param>
 | |
|         protected void Page_Load(object sender, EventArgs e)
 | |
|         {
 | |
|             if (!IsPostBack)
 | |
|             {
 | |
|                 BLL.ProjectService.InitAllProjectDropDownList(this.drpProject, true);
 | |
|                 this.drpProject.SelectedValue = this.CurrUser.LoginProjectId;
 | |
|                 this.BindGrid();
 | |
|             }
 | |
|         }
 | |
|         #endregion
 | |
| 
 | |
|         #region 项目下拉选择事件
 | |
|         /// <summary>
 | |
|         /// 项目下拉选择事件
 | |
|         /// </summary>
 | |
|         /// <param name="sender"></param>
 | |
|         /// <param name="e"></param>
 | |
|         protected void drpProject_SelectedIndexChanged(object sender, EventArgs e)
 | |
|         {
 | |
|             if (this.drpProject.SelectedValue != BLL.Const._Null)
 | |
|             {
 | |
|                 BindGrid();
 | |
|             }
 | |
|         }
 | |
|         #endregion
 | |
| 
 | |
|         #region 绑定数据
 | |
|         /// <summary>
 | |
|         /// 绑定数据
 | |
|         /// </summary>
 | |
|         private void BindGrid()
 | |
|         {
 | |
|             List<Model.WBSSetItem> items = new List<Model.WBSSetItem>();
 | |
|             var installations = from x in Funs.DB.Project_Installation
 | |
|                                 where x.ProjectId == this.drpProject.SelectedValue && x.SuperInstallationId == "0"
 | |
|                                 orderby x.InstallationCode
 | |
|                                 select x;
 | |
|             var cnProfessionsTotal = from x in Funs.DB.WBS_CnProfession where x.ProjectId == this.drpProject.SelectedValue select x;
 | |
|             var unitProjectsTotal = from x in Funs.DB.Wbs_UnitProject where x.ProjectId == this.drpProject.SelectedValue select x;
 | |
|             var wbsSetsTotal = from x in Funs.DB.Wbs_WbsSet where x.ProjectId == this.drpProject.SelectedValue && x.NoShow == null select x;
 | |
|             foreach (var installation in installations)
 | |
|             {
 | |
|                 Model.WBSSetItem item = new Model.WBSSetItem();
 | |
|                 item.Id = installation.InstallationId;
 | |
|                 item.Name = installation.InstallationName;
 | |
|                 items.Add(item);
 | |
|                 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)
 | |
|                     {
 | |
|                         Model.WBSSetItem item1 = new Model.WBSSetItem();
 | |
|                         item1.Id = installation1.InstallationId;
 | |
|                         item1.Name = installation1.InstallationName;
 | |
|                         items.Add(item1);
 | |
|                         var installation2s = from x in Funs.DB.Project_Installation
 | |
|                                              where x.SuperInstallationId == installation1.InstallationId
 | |
|                                              orderby x.InstallationCode
 | |
|                                              select x;
 | |
|                         foreach (var installation2 in installation2s)
 | |
|                         {
 | |
|                             Model.WBSSetItem item2 = new Model.WBSSetItem();
 | |
|                             item2.Id = installation2.InstallationId;
 | |
|                             item2.Name = installation2.InstallationName;
 | |
|                             items.Add(item2);
 | |
|                             var cnProfessions = from x in cnProfessionsTotal
 | |
|                                                 where x.InstallationId == installation2.InstallationId
 | |
|                                                 orderby x.OldId
 | |
|                                                 select x;
 | |
|                             foreach (var cnProfession in cnProfessions)
 | |
|                             {
 | |
|                                 Model.WBSSetItem item3 = new Model.WBSSetItem();
 | |
|                                 item3.Id = cnProfession.CnProfessionId;
 | |
|                                 item3.Name = cnProfession.CnProfessionName;
 | |
|                                 items.Add(item3);
 | |
|                                 var unitProjects = from x in unitProjectsTotal where x.CnProfessionId == cnProfession.CnProfessionId && x.SuperUnitProjectId == null && x.IsApprove == true orderby x.UnitProjectCode select x;
 | |
|                                 foreach (var unitProject in unitProjects)
 | |
|                                 {
 | |
|                                     Model.WBSSetItem item4 = new Model.WBSSetItem();
 | |
|                                     item4.Id = unitProject.UnitProjectId;
 | |
|                                     item4.Name = unitProject.UnitProjectName;
 | |
|                                     items.Add(item4);
 | |
|                                     var childUnitProjects = from x in unitProjectsTotal where x.SuperUnitProjectId == unitProject.UnitProjectId && x.SuperUnitProjectId == null && x.IsApprove == true orderby x.UnitProjectCode select x;
 | |
|                                     if (childUnitProjects.Count() > 0)  //存在子单位工程
 | |
|                                     {
 | |
|                                         foreach (var childUnitProject in childUnitProjects)
 | |
|                                         {
 | |
|                                             Model.WBSSetItem item5 = new Model.WBSSetItem();
 | |
|                                             item5.Id = childUnitProject.UnitProjectId;
 | |
|                                             item5.Name = childUnitProject.UnitProjectName;
 | |
|                                             items.Add(item5);
 | |
|                                             var wbsSet1s = from x in wbsSetsTotal where x.UnitProjectId == childUnitProject.UnitProjectId && x.SuperWbsSetId == null && x.IsApprove == true orderby x.WbsSetCode select x;
 | |
|                                             foreach (var wbsSet1 in wbsSet1s)
 | |
|                                             {
 | |
|                                                 Model.WBSSetItem item6 = new Model.WBSSetItem();
 | |
|                                                 item6.Id = wbsSet1.WbsSetId;
 | |
|                                                 item6.Name = wbsSet1.WbsSetName;
 | |
|                                                 items.Add(item6);
 | |
|                                                 var wbsSet2s = from x in wbsSetsTotal where x.SuperWbsSetId == wbsSet1.WbsSetId && x.IsApprove == true orderby x.WbsSetCode select x;
 | |
|                                                 foreach (var wbsSet2 in wbsSet2s)
 | |
|                                                 {
 | |
|                                                     Model.WBSSetItem item7 = new Model.WBSSetItem();
 | |
|                                                     item7.Id = wbsSet2.WbsSetId;
 | |
|                                                     item7.Name = wbsSet2.WbsSetName;
 | |
|                                                     items.Add(item7);
 | |
|                                                     var wbsSet3s = from x in wbsSetsTotal where x.SuperWbsSetId == wbsSet2.WbsSetId && x.IsApprove == true orderby x.WbsSetCode select x;
 | |
|                                                     foreach (var wbsSet3 in wbsSet3s)
 | |
|                                                     {
 | |
|                                                         Model.WBSSetItem item8 = new Model.WBSSetItem();
 | |
|                                                         item8.Id = wbsSet3.WbsSetId;
 | |
|                                                         item8.Name = wbsSet3.WbsSetName;
 | |
|                                                         items.Add(item8);
 | |
|                                                         var wbsSet4s = from x in wbsSetsTotal where x.SuperWbsSetId == wbsSet3.WbsSetId && x.IsApprove == true orderby x.WbsSetCode select x;
 | |
|                                                         foreach (var wbsSet4 in wbsSet4s)
 | |
|                                                         {
 | |
|                                                             Model.WBSSetItem item9 = new Model.WBSSetItem();
 | |
|                                                             item9.Id = wbsSet4.WbsSetId;
 | |
|                                                             item9.Name = wbsSet4.WbsSetName;
 | |
|                                                             items.Add(item9);
 | |
|                                                         }
 | |
|                                                     }
 | |
|                                                 }
 | |
|                                             }
 | |
|                                         }
 | |
|                                     }
 | |
|                                     else     //不存在子单位工程
 | |
|                                     {
 | |
|                                         var wbsSet1s = from x in wbsSetsTotal where x.UnitProjectId == unitProject.UnitProjectId && x.SuperWbsSetId == null && x.IsApprove == true orderby x.WbsSetCode select x;
 | |
|                                         foreach (var wbsSet1 in wbsSet1s)
 | |
|                                         {
 | |
|                                             Model.WBSSetItem item6 = new Model.WBSSetItem();
 | |
|                                             item6.Id = wbsSet1.WbsSetId;
 | |
|                                             item6.Name = wbsSet1.WbsSetName;
 | |
|                                             items.Add(item6);
 | |
|                                             var wbsSet2s = from x in wbsSetsTotal where x.SuperWbsSetId == wbsSet1.WbsSetId && x.IsApprove == true orderby x.WbsSetCode select x;
 | |
|                                             foreach (var wbsSet2 in wbsSet2s)
 | |
|                                             {
 | |
|                                                 Model.WBSSetItem item7 = new Model.WBSSetItem();
 | |
|                                                 item7.Id = wbsSet2.WbsSetId;
 | |
|                                                 item7.Name = wbsSet2.WbsSetName;
 | |
|                                                 items.Add(item7);
 | |
|                                                 var wbsSet3s = from x in wbsSetsTotal where x.SuperWbsSetId == wbsSet2.WbsSetId && x.IsApprove == true orderby x.WbsSetCode select x;
 | |
|                                                 foreach (var wbsSet3 in wbsSet3s)
 | |
|                                                 {
 | |
|                                                     Model.WBSSetItem item8 = new Model.WBSSetItem();
 | |
|                                                     item8.Id = wbsSet3.WbsSetId;
 | |
|                                                     item8.Name = wbsSet3.WbsSetName;
 | |
|                                                     items.Add(item8);
 | |
|                                                     var wbsSet4s = from x in wbsSetsTotal where x.SuperWbsSetId == wbsSet3.WbsSetId && x.IsApprove == true orderby x.WbsSetCode select x;
 | |
|                                                     foreach (var wbsSet4 in wbsSet4s)
 | |
|                                                     {
 | |
|                                                         Model.WBSSetItem item9 = new Model.WBSSetItem();
 | |
|                                                         item9.Id = wbsSet4.WbsSetId;
 | |
|                                                         item9.Name = wbsSet4.WbsSetName;
 | |
|                                                         items.Add(item9);
 | |
|                                                     }
 | |
|                                                 }
 | |
|                                             }
 | |
|                                         }
 | |
|                                     }
 | |
|                                 }
 | |
|                             }
 | |
|                         }
 | |
|                     }
 | |
|                 }
 | |
|                 else    //总图
 | |
|                 {
 | |
|                     var unitProjects = from x in unitProjectsTotal where x.InstallationId == installation.InstallationId && x.SuperUnitProjectId == null && x.IsApprove == true orderby x.UnitProjectCode select x;
 | |
|                     foreach (var unitProject in unitProjects)
 | |
|                     {
 | |
|                         Model.WBSSetItem item4 = new Model.WBSSetItem();
 | |
|                         item4.Id = unitProject.UnitProjectId;
 | |
|                         item4.Name = unitProject.UnitProjectName;
 | |
|                         items.Add(item4);
 | |
|                         var childUnitProjects = from x in unitProjectsTotal where x.SuperUnitProjectId == unitProject.UnitProjectId && x.SuperUnitProjectId == null && x.IsApprove == true orderby x.UnitProjectCode select x;
 | |
|                         if (childUnitProjects.Count() > 0)  //存在子单位工程
 | |
|                         {
 | |
|                             foreach (var childUnitProject in childUnitProjects)
 | |
|                             {
 | |
|                                 Model.WBSSetItem item5 = new Model.WBSSetItem();
 | |
|                                 item5.Id = childUnitProject.UnitProjectId;
 | |
|                                 item5.Name = childUnitProject.UnitProjectName;
 | |
|                                 items.Add(item5);
 | |
|                                 var wbsSet1s = from x in wbsSetsTotal where x.UnitProjectId == childUnitProject.UnitProjectId && x.SuperWbsSetId == null && x.IsApprove == true orderby x.WbsSetCode select x;
 | |
|                                 foreach (var wbsSet1 in wbsSet1s)
 | |
|                                 {
 | |
|                                     Model.WBSSetItem item6 = new Model.WBSSetItem();
 | |
|                                     item6.Id = wbsSet1.WbsSetId;
 | |
|                                     item6.Name = wbsSet1.WbsSetName;
 | |
|                                     items.Add(item6);
 | |
|                                     var wbsSet2s = from x in wbsSetsTotal where x.SuperWbsSetId == wbsSet1.WbsSetId && x.IsApprove == true orderby x.WbsSetCode select x;
 | |
|                                     foreach (var wbsSet2 in wbsSet2s)
 | |
|                                     {
 | |
|                                         Model.WBSSetItem item7 = new Model.WBSSetItem();
 | |
|                                         item7.Id = wbsSet2.WbsSetId;
 | |
|                                         item7.Name = wbsSet2.WbsSetName;
 | |
|                                         items.Add(item7);
 | |
|                                         var wbsSet3s = from x in wbsSetsTotal where x.SuperWbsSetId == wbsSet2.WbsSetId && x.IsApprove == true orderby x.WbsSetCode select x;
 | |
|                                         foreach (var wbsSet3 in wbsSet3s)
 | |
|                                         {
 | |
|                                             Model.WBSSetItem item8 = new Model.WBSSetItem();
 | |
|                                             item8.Id = wbsSet3.WbsSetId;
 | |
|                                             item8.Name = wbsSet3.WbsSetName;
 | |
|                                             items.Add(item8);
 | |
|                                             var wbsSet4s = from x in wbsSetsTotal where x.SuperWbsSetId == wbsSet3.WbsSetId && x.IsApprove == true orderby x.WbsSetCode select x;
 | |
|                                             foreach (var wbsSet4 in wbsSet4s)
 | |
|                                             {
 | |
|                                                 Model.WBSSetItem item9 = new Model.WBSSetItem();
 | |
|                                                 item9.Id = wbsSet4.WbsSetId;
 | |
|                                                 item9.Name = wbsSet4.WbsSetName;
 | |
|                                                 items.Add(item9);
 | |
|                                             }
 | |
|                                         }
 | |
|                                     }
 | |
|                                 }
 | |
|                             }
 | |
|                         }
 | |
|                         else     //不存在子单位工程
 | |
|                         {
 | |
|                             var wbsSet1s = from x in wbsSetsTotal where x.UnitProjectId == unitProject.UnitProjectId && x.SuperWbsSetId == null && x.IsApprove == true orderby x.WbsSetCode select x;
 | |
|                             foreach (var wbsSet1 in wbsSet1s)
 | |
|                             {
 | |
|                                 Model.WBSSetItem item6 = new Model.WBSSetItem();
 | |
|                                 item6.Id = wbsSet1.WbsSetId;
 | |
|                                 item6.Name = wbsSet1.WbsSetName;
 | |
|                                 items.Add(item6);
 | |
|                                 var wbsSet2s = from x in wbsSetsTotal where x.SuperWbsSetId == wbsSet1.WbsSetId && x.IsApprove == true orderby x.WbsSetCode select x;
 | |
|                                 foreach (var wbsSet2 in wbsSet2s)
 | |
|                                 {
 | |
|                                     Model.WBSSetItem item7 = new Model.WBSSetItem();
 | |
|                                     item7.Id = wbsSet2.WbsSetId;
 | |
|                                     item7.Name = wbsSet2.WbsSetName;
 | |
|                                     items.Add(item7);
 | |
|                                     var wbsSet3s = from x in wbsSetsTotal where x.SuperWbsSetId == wbsSet2.WbsSetId && x.IsApprove == true orderby x.WbsSetCode select x;
 | |
|                                     foreach (var wbsSet3 in wbsSet3s)
 | |
|                                     {
 | |
|                                         Model.WBSSetItem item8 = new Model.WBSSetItem();
 | |
|                                         item8.Id = wbsSet3.WbsSetId;
 | |
|                                         item8.Name = wbsSet3.WbsSetName;
 | |
|                                         items.Add(item8);
 | |
|                                         var wbsSet4s = from x in wbsSetsTotal where x.SuperWbsSetId == wbsSet3.WbsSetId && x.IsApprove == true orderby x.WbsSetCode select x;
 | |
|                                         foreach (var wbsSet4 in wbsSet4s)
 | |
|                                         {
 | |
|                                             Model.WBSSetItem item9 = new Model.WBSSetItem();
 | |
|                                             item9.Id = wbsSet4.WbsSetId;
 | |
|                                             item9.Name = wbsSet4.WbsSetName;
 | |
|                                             items.Add(item9);
 | |
|                                         }
 | |
|                                     }
 | |
|                                 }
 | |
|                             }
 | |
|                         }
 | |
|                     }
 | |
|                 }
 | |
|             }
 | |
|             Grid1.DataSource = items;
 | |
|             Grid1.DataBind();
 | |
|         }
 | |
|         #endregion
 | |
| 
 | |
|         #region 分页排序
 | |
|         /// <summary>
 | |
|         /// 
 | |
|         /// </summary>
 | |
|         /// <param name="sender"></param>
 | |
|         /// <param name="e"></param>
 | |
|         protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e)
 | |
|         {
 | |
|             Grid1.PageIndex = e.NewPageIndex;
 | |
|             BindGrid();
 | |
|         }
 | |
| 
 | |
|         /// <summary>
 | |
|         /// 
 | |
|         /// </summary>
 | |
|         /// <param name="sender"></param>
 | |
|         /// <param name="e"></param>
 | |
|         protected void Grid1_FilterChange(object sender, EventArgs e)
 | |
|         {
 | |
|             BindGrid();
 | |
|         }
 | |
| 
 | |
|         /// <summary>
 | |
|         /// 排序
 | |
|         /// </summary>
 | |
|         /// <param name="sender"></param>
 | |
|         /// <param name="e"></param>
 | |
|         protected void Grid1_Sort(object sender, FineUIPro.GridSortEventArgs e)
 | |
|         {
 | |
|             Grid1.SortDirection = e.SortDirection;
 | |
|             Grid1.SortField = e.SortField;
 | |
|             BindGrid();
 | |
|         }
 | |
|         #endregion
 | |
| 
 | |
|         #region 导出按钮
 | |
|         /// 导出按钮
 | |
|         /// </summary>
 | |
|         /// <param name="sender"></param>
 | |
|         /// <param name="e"></param>
 | |
|         protected void btnOut_Click(object sender, EventArgs e)
 | |
|         {
 | |
|             Response.ClearContent();
 | |
|             string filename = Funs.GetNewFileName();
 | |
|             Response.AddHeader("content-disposition", "attachment; filename=" + System.Web.HttpUtility.UrlEncode("WBS信息" + filename, System.Text.Encoding.UTF8) + ".xls");
 | |
|             Response.ContentType = "application/excel";
 | |
|             Response.ContentEncoding = System.Text.Encoding.UTF8;
 | |
|             this.Grid1.PageSize = 100000;
 | |
|             this.BindGrid();
 | |
|             Response.Write(GetGridTableHtml(Grid1));
 | |
|             Response.End();
 | |
|         }
 | |
| 
 | |
|         /// <summary>
 | |
|         /// 导出方法
 | |
|         /// </summary>
 | |
|         /// <param name="grid"></param>
 | |
|         /// <returns></returns>
 | |
|         private string GetGridTableHtml(Grid grid)
 | |
|         {
 | |
|             StringBuilder sb = new StringBuilder();
 | |
|             sb.Append("<meta http-equiv=\"content-type\" content=\"application/excel; charset=UTF-8\"/>");
 | |
|             sb.Append("<table cellspacing=\"0\" rules=\"all\" border=\"1\" style=\"border-collapse:collapse;\">");
 | |
|             sb.Append("<tr>");
 | |
|             foreach (GridColumn column in grid.Columns)
 | |
|             {
 | |
|                 if (column.HeaderText != "序号")
 | |
|                 {
 | |
|                     sb.AppendFormat("<td>{0}</td>", column.HeaderText);
 | |
|                 }
 | |
|             }
 | |
|             sb.Append("</tr>");
 | |
|             foreach (GridRow row in grid.Rows)
 | |
|             {
 | |
|                 sb.Append("<tr>");
 | |
|                 foreach (GridColumn column in grid.Columns)
 | |
|                 {
 | |
|                     string html = row.Values[column.ColumnIndex].ToString();
 | |
|                     if (column.ColumnID != "tfNumber")
 | |
|                     {
 | |
|                         sb.AppendFormat("<td>{0}</td>", html);
 | |
|                     }
 | |
|                 }
 | |
|                 sb.Append("</tr>");
 | |
|             }
 | |
|             sb.Append("</table>");
 | |
|             return sb.ToString();
 | |
|         }
 | |
|         #endregion
 | |
|     }
 | |
| } |