xinjiang/SGGL/FineUIPro.Web/Person/PersonPlan.aspx.cs

567 lines
20 KiB
C#
Raw Normal View History

2024-11-19 09:45:27 +08:00
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
/// <summary>
/// 加载页面
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
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
/// <summary>
/// 绑定数据
/// </summary>
private void BindGrid()
{
string strSql = @"SELECT * FROM View_Person_PersonPlan WHERE Years=@years";
List<SqlParameter> listStr = new List<SqlParameter>();
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;
}
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
/// <summary>
/// 分页
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e)
{
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>
/// 排序
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Grid1_Sort(object sender, FineUIPro.GridSortEventArgs e)
{
BindGrid();
}
#endregion
#region
/// <summary>
/// 查询
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnSearch_Click(object sender, EventArgs e)
{
BindGrid();
}
#endregion
#region
/// <summary>
/// 关闭弹出窗口
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Window1_Close(object sender, WindowCloseEventArgs e)
{
BindGrid();
}
#endregion
#region
/// <summary>
/// 导入按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnImport_Click(object sender, EventArgs e)
{
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("PersonPlanIn.aspx", "导入 - ")));
}
#endregion
#region
/// <summary>
/// 导出事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
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("<meta http-equiv=\"Content-Type\" content=\"application/vnd.ms-excel;charset=utf-8\"/>");
sb.Append("<table cellspacing=\"0\" rules=\"all\" border=\"1\" style=\"border-collapse:collapse;\">");
foreach (List<object[]> rows in mht.MultiTable)
{
sb.Append("<tr>");
foreach (object[] cell in rows)
{
int rowspan = Convert.ToInt32(cell[0]);
int colspan = Convert.ToInt32(cell[1]);
GridColumn column = cell[2] as GridColumn;
sb.AppendFormat("<th{0}{1}{2}>{3}</th>",
rowspan != 1 ? " rowspan=\"" + rowspan + "\"" : "",
colspan != 1 ? " colspan=\"" + colspan + "\"" : "",
colspan != 1 ? " style=\"text-align:center;\"" : "",
column.HeaderText);
}
sb.Append("</tr>");
}
foreach (GridRow row in grid.Rows)
{
sb.Append("<tr>");
foreach (GridColumn column in mht.Columns)
{
string html = row.Values[column.ColumnIndex].ToString();
if (column.ColumnID == "tfNumber")
{
html = (row.FindControl("labNumber") as AspNet.Label).Text;
}
// 处理CheckBox
if (html.Contains("f-grid-static-checkbox"))
{
if (!html.Contains("f-checked"))
{
html = "×";
}
else
{
html = "√";
}
}
sb.AppendFormat("<td>{0}</td>", html);
}
sb.Append("</tr>");
}
sb.Append("</table>");
return sb.ToString();
}
#region
/// <summary>
/// 处理多表头的类
/// </summary>
public class MultiHeaderTable
{
// 包含 rowspancolspan 的多表头,方便生成 HTML 的 table 标签
public List<List<object[]>> MultiTable = new List<List<object[]>>();
// 最终渲染的列数组
public List<GridColumn> Columns = new List<GridColumn>();
public void ResolveMultiHeaderTable(GridColumnCollection columns)
{
List<object[]> row = new List<object[]>();
foreach (GridColumn column in columns)
{
object[] cell = new object[4];
cell[0] = 1; // rowspan
cell[1] = 1; // colspan
cell[2] = column;
cell[3] = null;
row.Add(cell);
}
ResolveMultiTable(row, 0);
ResolveColumns(row);
}
private void ResolveColumns(List<object[]> row)
{
foreach (object[] cell in row)
{
GroupField groupField = cell[2] as GroupField;
if (groupField != null && groupField.Columns.Count > 0)
{
List<object[]> subrow = new List<object[]>();
foreach (GridColumn column in groupField.Columns)
{
subrow.Add(new object[]
{
1,
1,
column,
groupField
});
}
ResolveColumns(subrow);
}
else
{
Columns.Add(cell[2] as GridColumn);
}
}
}
private void ResolveMultiTable(List<object[]> row, int level)
{
List<object[]> nextrow = new List<object[]>();
foreach (object[] cell in row)
{
GroupField groupField = cell[2] as GroupField;
if (groupField != null && groupField.Columns.Count > 0)
{
// 如果当前列包含子列,则更改当前列的 colspan以及增加父列向上递归的colspan
cell[1] = Convert.ToInt32(groupField.Columns.Count);
PlusColspan(level - 1, cell[3] as GridColumn, groupField.Columns.Count - 1);
foreach (GridColumn column in groupField.Columns)
{
nextrow.Add(new object[]
{
1,
1,
column,
groupField
});
}
}
}
MultiTable.Add(row);
// 如果当前下一行,则增加上一行(向上递归)中没有子列的列的 rowspan
if (nextrow.Count > 0)
{
PlusRowspan(level);
ResolveMultiTable(nextrow, level + 1);
}
}
private void PlusRowspan(int level)
{
if (level < 0)
{
return;
}
foreach (object[] cells in MultiTable[level])
{
GroupField groupField = cells[2] as GroupField;
if (groupField != null && groupField.Columns.Count > 0)
{
// ...
}
else
{
cells[0] = Convert.ToInt32(cells[0]) + 1;
}
}
PlusRowspan(level - 1);
}
private void PlusColspan(int level, GridColumn parent, int plusCount)
{
if (level < 0)
{
return;
}
foreach (object[] cells in MultiTable[level])
{
GridColumn column = cells[2] as GridColumn;
if (column == parent)
{
cells[1] = Convert.ToInt32(cells[1]) + plusCount;
PlusColspan(level - 1, cells[3] as GridColumn, plusCount);
}
}
}
}
#endregion
#endregion
#region
/// <summary>
/// 获取按钮权限
/// </summary>
/// <param name="button"></param>
/// <returns></returns>
private void GetButtonPower()
{
var buttonList = BLL.CommonService.GetAllButtonList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, BLL.Const.PersonPlanMenuId);
if (buttonList.Count() > 0)
{
if (buttonList.Contains(BLL.Const.BtnModify))
{
this.btnMenuEdit.Hidden = false;
this.Grid1.EnableRowDoubleClickEvent = true;
}
else
{
this.Grid1.EnableRowDoubleClickEvent = false;
}
if (buttonList.Contains(BLL.Const.BtnDelete))
{
this.btnMenuDelete.Hidden = false;
}
if (buttonList.Contains(BLL.Const.BtnIn))
{
this.btnImport.Hidden = false;
}
}
}
#endregion
#region
/// <summary>
/// 编辑数据方法
/// </summary>
private void EditData()
{
if (Grid1.SelectedRowIndexArray.Length == 0)
{
Alert.ShowInTop("请至少选择一条记录!", MessageBoxIcon.Warning);
return;
}
string id = Grid1.SelectedRowID;
var personPlan = BLL.Person_PersonPlanService.GetPersonPlanById(id);
if (personPlan != null)
{
PageContext.RegisterStartupScript(Window2.GetShowReference(String.Format("PersonPlanEdit.aspx?PersonPlanId={0}", id, "编辑 - ")));
}
}
/// <summary>
/// Grid行双击事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Grid1_RowDoubleClick(object sender, GridRowClickEventArgs e)
{
this.EditData();
}
/// <summary>
///右键编辑
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnMenuEdit_Click(object sender, EventArgs e)
{
this.EditData();
}
#endregion
#region
/// <summary>
/// 右键删除
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnMenuDelete_Click(object sender, EventArgs e)
{
if (Grid1.SelectedRowIndexArray.Length > 0)
{
foreach (int rowIndex in Grid1.SelectedRowIndexArray)
{
string rowID = Grid1.DataKeys[rowIndex][0].ToString();
if (!string.IsNullOrEmpty(rowID))
{
var personPlan = BLL.Person_PersonPlanService.GetPersonPlanById(rowID);
if (personPlan != null)
{
BLL.Person_PersonPlanService.DeletePersonPlanById(rowID);
}
}
}
BindGrid();
ShowNotify("删除数据成功!", MessageBoxIcon.Success);
}
}
#endregion
}
}