using BLL; using System; using System.Collections.Generic; using System.Data; using System.Data.SqlClient; using System.Linq; using System.Runtime.InteropServices.ComTypes; namespace FineUIPro.Web.ProjectData { public partial class MasterProjectData : PageBase { #region 加载 /// /// 加载页面 /// /// /// protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { Funs.DropDownPageSize(this.ddlPageSize); this.ddlPageSize.SelectedValue = Grid1.PageSize.ToString(); // 绑定表格 this.BindGrid(); } } #endregion #region 绑定数据 /// /// 绑定数据 /// private void BindGrid() { var db = Funs.DB; var masterProDatas = ProjectService.GetMasterProjectDataInfos(); var query = from x in masterProDatas join pro in db.Base_Project on x.Pro_id equals pro.MasterSysId into proGroup from pro in proGroup.DefaultIfEmpty() select new { Pid= x.Pro_id+(pro != null ? $"-{pro.ProjectId}":""), x.Pro_id, x.Pro_name, x.Pro_code, x.Start_date, x.Pro_status, ProjectName = pro != null ? pro.ProjectName : "", ProjectCode = pro != null ? pro.ProjectCode : "", StartDate = pro != null ? pro.StartDate : null, ProjectState = pro != null ? pro.ProjectState : "", relate = pro != null && pro.MasterSysId != null ? "已关联" : "" }; string proName = this.txtProjectName.Text.Trim(); string proCode = this.txtProjectCode.Text.Trim(); if (!string.IsNullOrEmpty(proName)) { query = query.Where(x => x.Pro_name.Contains(proName)); } if (!string.IsNullOrEmpty(proCode)) { query = query.Where(x => x.Pro_code.Contains(proCode)); } DataTable tb = Funs.LINQToDataTable(query); Grid1.RecordCount = tb.Rows.Count; Grid1.DataSource = this.GetPagedDataTable(Grid1, tb); Grid1.DataBind(); } /// /// 项目状态 /// /// /// protected string ConvertProjectState(object state) { string result = string.Empty; string stateStr = state.ToString(); if (state != null && !string.IsNullOrWhiteSpace(stateStr)) { result = stateStr == "2" ? "暂停中" : stateStr == "3" ? "已完工" : "施工中"; } return result; } #endregion #region Grid protected void TextBox_TextChanged(object sender, EventArgs e) { this.BindGrid(); } /// /// /// /// /// protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e) { BindGrid(); } /// /// /// /// /// protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e) { Grid1.PageSize = Convert.ToInt32(ddlPageSize.SelectedValue); BindGrid(); } protected void Grid1_Sort(object sender, FineUIPro.GridSortEventArgs e) { BindGrid(); } #endregion #region 导出按钮 /// 导出按钮 /// /// /// protected void btnOut_Click(object sender, EventArgs e) { Response.ClearContent(); string filename = Funs.GetNewFileName(); Response.AddHeader("content-disposition", "attachment; filename=" + System.Web.HttpUtility.UrlEncode("集团主数据在建项目使用情况" + filename, System.Text.Encoding.UTF8) + ".xls"); Response.ContentType = "application/excel"; Response.ContentEncoding = System.Text.Encoding.UTF8; this.Grid1.PageSize = this.Grid1.RecordCount; this.BindGrid(); Response.Write(GetGridMultiHeaderTableHtml(Grid1)); //Response.Write(GetGridTableHtml(Grid1)); Response.End(); } #endregion } }