using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Text;
using System.IO;
using AspNet = System.Web.UI.WebControls;
using System.Data.SqlClient;
using BLL;
using System.Linq;
namespace FineUIPro.Web.Person
{
public partial class PersonPlan : PageBase
{
#region 加载
///
/// 加载页面
///
///
///
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Funs.DropDownPageSize(this.ddlPageSize);
////权限按钮方法
this.GetButtonPower();
if (this.CurrUser != null && this.CurrUser.PageSize.HasValue)
{
Grid1.PageSize = this.CurrUser.PageSize.Value;
}
this.ddlPageSize.SelectedValue = Grid1.PageSize.ToString();
BLL.ProjectService.InitAllProjectDropDownList(this.drpProjectId, true);
BLL.DepartService.InitDepartDropDownList(this.drpDepartId, true);
this.drpPersonType.DataTextField = "Text";
this.drpPersonType.DataValueField = "Value";
this.drpPersonType.DataSource = BLL.DropListService.drpPersonTypeList();
this.drpPersonType.DataBind();
Funs.FineUIPleaseSelect(this.drpPersonType);
this.drpMonth.DataTextField = "Text";
this.drpMonth.DataValueField = "Value";
this.drpMonth.DataSource = BLL.DropListService.drpMonthList();
this.drpMonth.DataBind();
Funs.FineUIPleaseSelect(this.drpMonth);
// 绑定表格
this.BindGrid();
this.Grid1.Columns[6].HeaderText = DateTime.Now.Year.ToString();
}
}
#endregion
#region 数据绑定
///
/// 绑定数据
///
private void BindGrid()
{
if (!this.ckDistinct.Checked)
{
string strSql = @"SELECT * FROM View_Person_PersonPlan WHERE Years=@years";
List listStr = new List();
listStr.Add(new SqlParameter("@years", DateTime.Now.Year));
if (this.drpProjectId.SelectedValue != BLL.Const._Null)
{
strSql += " AND ProjectId=@projectId";
listStr.Add(new SqlParameter("@projectId", this.drpProjectId.SelectedValue));
}
if (this.drpDepartId.SelectedValue != BLL.Const._Null)
{
strSql += " AND DepartId=@DepartId";
listStr.Add(new SqlParameter("@DepartId", this.drpDepartId.SelectedValue));
}
if (!string.IsNullOrEmpty(this.txtMajor.Text.Trim()))
{
strSql += " AND Major LIKE @Major";
listStr.Add(new SqlParameter("@Major", "%" + this.txtMajor.Text.Trim() + "%"));
}
if (this.drpPersonType.SelectedValue != BLL.Const._Null)
{
strSql += " AND PersonType=@PersonType";
listStr.Add(new SqlParameter("@PersonType", this.drpPersonType.SelectedValue));
}
if (!string.IsNullOrEmpty(this.txtUserName.Text.Trim()))
{
strSql += " AND UserName LIKE @UserName";
listStr.Add(new SqlParameter("@UserName", "%" + this.txtUserName.Text.Trim() + "%"));
}
if (this.drpMonth.SelectedValue != BLL.Const._Null)
{
this.Grid1.FindColumn("Month1").Hidden = true;
this.Grid1.FindColumn("Month2").Hidden = true;
this.Grid1.FindColumn("Month3").Hidden = true;
this.Grid1.FindColumn("Month4").Hidden = true;
this.Grid1.FindColumn("Month5").Hidden = true;
this.Grid1.FindColumn("Month6").Hidden = true;
this.Grid1.FindColumn("Month7").Hidden = true;
this.Grid1.FindColumn("Month8").Hidden = true;
this.Grid1.FindColumn("Month9").Hidden = true;
this.Grid1.FindColumn("Month10").Hidden = true;
this.Grid1.FindColumn("Month11").Hidden = true;
this.Grid1.FindColumn("Month12").Hidden = true;
if (this.drpMonth.SelectedValue == "1")
{
this.Grid1.FindColumn("Month1").Hidden = false;
}
else if (this.drpMonth.SelectedValue == "2")
{
this.Grid1.FindColumn("Month2").Hidden = false;
}
else if (this.drpMonth.SelectedValue == "3")
{
this.Grid1.FindColumn("Month3").Hidden = false;
}
else if (this.drpMonth.SelectedValue == "4")
{
this.Grid1.FindColumn("Month4").Hidden = false;
}
else if (this.drpMonth.SelectedValue == "5")
{
this.Grid1.FindColumn("Month5").Hidden = false;
}
else if (this.drpMonth.SelectedValue == "6")
{
this.Grid1.FindColumn("Month6").Hidden = false;
}
else if (this.drpMonth.SelectedValue == "7")
{
this.Grid1.FindColumn("Month7").Hidden = false;
}
else if (this.drpMonth.SelectedValue == "8")
{
this.Grid1.FindColumn("Month8").Hidden = false;
}
else if (this.drpMonth.SelectedValue == "9")
{
this.Grid1.FindColumn("Month9").Hidden = false;
}
else if (this.drpMonth.SelectedValue == "10")
{
this.Grid1.FindColumn("Month10").Hidden = false;
}
else if (this.drpMonth.SelectedValue == "11")
{
this.Grid1.FindColumn("Month11").Hidden = false;
}
else if (this.drpMonth.SelectedValue == "12")
{
this.Grid1.FindColumn("Month12").Hidden = false;
}
}
else
{
this.Grid1.FindColumn("Month1").Hidden = false;
this.Grid1.FindColumn("Month2").Hidden = false;
this.Grid1.FindColumn("Month3").Hidden = false;
this.Grid1.FindColumn("Month4").Hidden = false;
this.Grid1.FindColumn("Month5").Hidden = false;
this.Grid1.FindColumn("Month6").Hidden = false;
this.Grid1.FindColumn("Month7").Hidden = false;
this.Grid1.FindColumn("Month8").Hidden = false;
this.Grid1.FindColumn("Month9").Hidden = false;
this.Grid1.FindColumn("Month10").Hidden = false;
this.Grid1.FindColumn("Month11").Hidden = false;
this.Grid1.FindColumn("Month12").Hidden = false;
}
this.Grid1.FindColumn("ProjectName").Hidden = false;
this.Grid1.FindColumn("Remark").Hidden = false;
SqlParameter[] parameter = listStr.ToArray();
DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
Grid1.RecordCount = tb.Rows.Count;
var table = this.GetPagedDataTable(Grid1, tb);
Grid1.DataSource = table;
Grid1.DataBind();
}
else //去重复筛选
{
string strSql = @"SELECT distinct DepartName+UserName as PersonPlanId, DepartName,UserName,Major,PersonTypeName,'' as ProjectName,Remark FROM View_Person_PersonPlan WHERE Years=@years";
List listStr = new List();
listStr.Add(new SqlParameter("@years", DateTime.Now.Year));
if (this.drpProjectId.SelectedValue != BLL.Const._Null)
{
strSql += " AND ProjectId=@projectId";
listStr.Add(new SqlParameter("@projectId", this.drpProjectId.SelectedValue));
}
if (this.drpDepartId.SelectedValue != BLL.Const._Null)
{
strSql += " AND DepartId=@DepartId";
listStr.Add(new SqlParameter("@DepartId", this.drpDepartId.SelectedValue));
}
if (!string.IsNullOrEmpty(this.txtMajor.Text.Trim()))
{
strSql += " AND Major LIKE @Major";
listStr.Add(new SqlParameter("@Major", "%" + this.txtMajor.Text.Trim() + "%"));
}
if (this.drpPersonType.SelectedValue != BLL.Const._Null)
{
strSql += " AND PersonType=@PersonType";
listStr.Add(new SqlParameter("@PersonType", this.drpPersonType.SelectedValue));
}
if (!string.IsNullOrEmpty(this.txtUserName.Text.Trim()))
{
strSql += " AND UserName LIKE @UserName";
listStr.Add(new SqlParameter("@UserName", "%" + this.txtUserName.Text.Trim() + "%"));
}
if (this.drpMonth.SelectedValue != BLL.Const._Null)
{
if (this.drpMonth.SelectedValue == "1")
{
strSql += " AND Month1=1";
}
else if (this.drpMonth.SelectedValue == "2")
{
strSql += " AND Month2=1";
}
else if (this.drpMonth.SelectedValue == "3")
{
strSql += " AND Month3=1";
}
else if (this.drpMonth.SelectedValue == "4")
{
strSql += " AND Month4=1";
}
else if (this.drpMonth.SelectedValue == "5")
{
strSql += " AND Month5=1";
}
else if (this.drpMonth.SelectedValue == "6")
{
strSql += " AND Month6=1";
}
else if (this.drpMonth.SelectedValue == "7")
{
strSql += " AND Month7=1";
}
else if (this.drpMonth.SelectedValue == "8")
{
strSql += " AND Month8=1";
}
else if (this.drpMonth.SelectedValue == "9")
{
strSql += " AND Month9=1";
}
else if (this.drpMonth.SelectedValue == "10")
{
strSql += " AND Month10=1";
}
else if (this.drpMonth.SelectedValue == "11")
{
strSql += " AND Month11=1";
}
else if (this.drpMonth.SelectedValue == "12")
{
strSql += " AND Month12=1";
}
}
this.Grid1.FindColumn("ProjectName").Hidden = true;
this.Grid1.FindColumn("Month1").Hidden = true;
this.Grid1.FindColumn("Month2").Hidden = true;
this.Grid1.FindColumn("Month3").Hidden = true;
this.Grid1.FindColumn("Month4").Hidden = true;
this.Grid1.FindColumn("Month5").Hidden = true;
this.Grid1.FindColumn("Month6").Hidden = true;
this.Grid1.FindColumn("Month7").Hidden = true;
this.Grid1.FindColumn("Month8").Hidden = true;
this.Grid1.FindColumn("Month9").Hidden = true;
this.Grid1.FindColumn("Month10").Hidden = true;
this.Grid1.FindColumn("Month11").Hidden = true;
this.Grid1.FindColumn("Month12").Hidden = true;
this.Grid1.FindColumn("Remark").Hidden = true;
SqlParameter[] parameter = listStr.ToArray();
DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
Grid1.RecordCount = tb.Rows.Count;
var table = this.GetPagedDataTable(Grid1, tb);
Grid1.DataSource = table;
Grid1.DataBind();
}
}
#endregion
#region 分页
///
/// 分页
///
///
///
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 btnSearch_Click(object sender, EventArgs e)
{
BindGrid();
}
#endregion
#region 关闭弹出窗口
///
/// 关闭弹出窗口
///
///
///
protected void Window1_Close(object sender, WindowCloseEventArgs e)
{
BindGrid();
}
#endregion
#region 导入
///
/// 导入按钮
///
///
///
protected void btnImport_Click(object sender, EventArgs e)
{
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("PersonPlanIn.aspx", "导入 - ")));
}
#endregion
#region 导出按钮
///
/// 导出事件
///
///
///
protected void btnMenuOut_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 = Grid1.RecordCount;
BindGrid();
Response.Write(GetGridTableHtmlNew(Grid1));
Response.End();
}
private string GetGridTableHtmlNew(Grid grid)
{
StringBuilder sb = new StringBuilder();
MultiHeaderTable mht = new MultiHeaderTable();
mht.ResolveMultiHeaderTable(Grid1.Columns);
sb.Append("");
sb.Append("
");
foreach (List
");
return sb.ToString();
}
#region 多表头处理
///
/// 处理多表头的类
///
public class MultiHeaderTable
{
// 包含 rowspan,colspan 的多表头,方便生成 HTML 的 table 标签
public List> MultiTable = new List>();
// 最终渲染的列数组
public List Columns = new List();
public void ResolveMultiHeaderTable(GridColumnCollection columns)
{
List