SGGL_JT/SUBQHSE/FineUIPro.Web/CQMS/Comprehensive/CqmsPerson.aspx.cs

529 lines
17 KiB
C#

using BLL;
using System;
using System.Linq;
using System.Text;
using AspNet = System.Web.UI.WebControls;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
namespace FineUIPro.Web.CQMS.Comprehensive
{
public partial class CqmsPerson : PageBase
{
#region
/// <summary>
/// 人员主键
/// </summary>
public string PersonId
{
get { return (string)ViewState["PersonId"]; }
set { ViewState["PersonId"] = value; }
}
/// <summary>
/// 项目id
/// </summary>
public string ProjectId
{
get { return (string)ViewState["ProjectId"]; }
set { ViewState["ProjectId"] = value; }
}
#endregion
#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.ProjectId = this.CurrUser.LoginProjectId;
if (!string.IsNullOrEmpty(Request.Params["projectId"]) &&
Request.Params["projectId"] != this.CurrUser.LoginProjectId)
{
this.ProjectId = Request.Params["projectId"];
}
this.ucTree.UnitId = this.CurrUser.UnitId;
this.ucTree.ProjectId = this.ProjectId;
if (!string.IsNullOrEmpty(this.CurrUser.LoginProjectId))
{
this.panelLeftRegion.Hidden = true;
////权限按钮方法
this.GetButtonPower();
}
BLL.UnitService.InitUnitDropDownList(this.drpUnitId, this.ProjectId, true);
this.btnMenuDelete.OnClientClick = Grid1.GetNoSelectionAlertReference("请至少选择一项!");
this.btnMenuDelete.ConfirmText = String.Format("你确定要删除选中的&nbsp;<b><script>{0}</script></b>&nbsp;行数据吗?",
Grid1.GetSelectedCountReference());
this.ddlPageSize.SelectedValue = this.Grid1.PageSize.ToString();
var postList = Funs.DB.Base_WorkPost.Where(x => x.IsCQMSCheck == true).OrderBy(x => x.WorkPostCode).ToList();
drpPost.DataValueField = "WorkPostId";
drpPost.DataTextField = "WorkPostName";
drpPost.DataSource = postList;
drpPost.DataBind();
Funs.FineUIPleaseSelect(drpPost);
this.BindGrid();
}
}
/// <summary>
/// 公司级树加载
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void changeTree(object sender, EventArgs e)
{
this.ProjectId = this.ucTree.ProjectId;
this.BindGrid();
this.GetButtonPower();
if (string.IsNullOrEmpty(this.CurrUser.LoginProjectId))
{
btnNew.Hidden = true;
btnImport.Hidden = true;
btnMenuEdit.Hidden = true;
btnMenuDelete.Hidden = true;
}
}
/// <summary>
/// 绑定数据
/// </summary>
private void BindGrid()
{
if (string.IsNullOrEmpty(this.ProjectId))
{
return;
}
string strSql = "select * from View_SitePerson_Person as Person" +
" LEFT JOIN Base_WorkPost AS Post ON Post.WorkPostId = Person.WorkPostId" +
" Where Post.IsCQMSCheck = '1' and Person.ProjectId=@ProjectId ";
List<SqlParameter> listStr = new List<SqlParameter>
{
new SqlParameter("@ProjectId", this.ProjectId)
};
if (!string.IsNullOrEmpty(this.drpUnitId.SelectedValue) && this.drpUnitId.SelectedValue != BLL.Const._Null)
{
strSql += " AND Person.UnitId = @UnitId";
listStr.Add(new SqlParameter("@UnitId", this.drpUnitId.SelectedValue));
}
if (drpIsUsedName.SelectedValue == "是")
{
strSql += " AND Person.IsUsed = @IsUsed";
listStr.Add(new SqlParameter("@IsUsed", "1"));
}
else
{
strSql += " AND Person.IsUsed = @IsUsed";
listStr.Add(new SqlParameter("@IsUsed", "0"));
}
if (!string.IsNullOrEmpty(this.txtPersonName.Text.Trim()))
{
strSql += " AND Person.PersonName LIKE @PersonName";
listStr.Add(new SqlParameter("@PersonName", "%" + this.txtPersonName.Text.Trim() + "%"));
}
if (!string.IsNullOrEmpty(this.txtIdentityCard.Text.Trim()))
{
strSql += " AND Person.IdentityCard LIKE @IdentityCard";
listStr.Add(new SqlParameter("@IdentityCard", "%" + this.txtIdentityCard.Text.Trim() + "%"));
}
if (this.drpPost.SelectedValue != BLL.Const._Null)
{
strSql += " AND Person.WorkPostId = @WorkPostId";
listStr.Add(new SqlParameter("@WorkPostId", this.drpPost.SelectedValue));
}
strSql += " ORDER BY Person.InTime desc";
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)
{
Grid1.PageIndex = e.NewPageIndex;
BindGrid();
}
#endregion
#region
/// <summary>
/// 排序
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Grid1_Sort(object sender, GridSortEventArgs e)
{
Grid1.SortDirection = e.SortDirection;
Grid1.SortField = e.SortField;
BindGrid();
}
#endregion
#region
/// <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();
}
#endregion
#region
/// <summary>
/// 增加按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnNew_Click(object sender, EventArgs e)
{
PageContext.RegisterStartupScript(Window1.GetShowReference(
String.Format("CqmsPersonEdit.aspx?ProjectId={0}", this.ProjectId, "编辑 - ")));
}
#endregion
#region
/// <summary>
/// 右键编辑事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnMenuEdit_Click(object sender, EventArgs e)
{
this.EditData();
}
/// <summary>
/// 编辑
/// </summary>
private void EditData()
{
if (Grid1.SelectedRowIndexArray.Length == 0)
{
Alert.ShowInTop("请至少选择一条记录!", MessageBoxIcon.Warning);
return;
}
string id = Grid1.SelectedRowID;
this.PersonId = id;
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format(
"CqmsPersonEdit.aspx?PersonId={0}&&ProjectId={1}", this.PersonId, this.ProjectId,
"编辑 - ")));
}
/// <summary>
/// Grid双击事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Grid1_RowDoubleClick(object sender, GridRowClickEventArgs e)
{
this.EditData();
}
#endregion
#region
/// <summary>
/// 右键删除事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnMenuDelete_Click(object sender, EventArgs e)
{
this.DeleteData();
}
/// <summary>
/// 删除方法
/// </summary>
private void DeleteData()
{
if (Grid1.SelectedRowIndexArray.Length > 0)
{
bool isShow = false;
if (Grid1.SelectedRowIndexArray.Length == 1)
{
isShow = true;
}
int i = 0;
foreach (int rowIndex in Grid1.SelectedRowIndexArray)
{
string rowID = Grid1.DataKeys[rowIndex][0].ToString();
if (this.judgementDelete(rowID, isShow))
{
i++;
var getV = BLL.PersonService.GetPersonById(rowID);
if (getV != null)
{
BLL.LogService.AddSys_Log(this.CurrUser, getV.PersonName, getV.PersonId,
BLL.Const.PersonListMenuId, BLL.Const.BtnDelete);
BLL.PersonService.DeletePerson(rowID);
}
}
}
BindGrid();
if (i > 0)
{
ShowNotify("删除数据成功!(表格数据已重新绑定)", MessageBoxIcon.Success);
}
}
}
/// <summary>
/// 判断是否可删除
/// </summary>
/// <param name="rowID"></param>
/// <param name="isShow"></param>
/// <returns></returns>
private bool judgementDelete(string rowID, bool isShow)
{
string content = string.Empty;
if (string.IsNullOrEmpty(content))
{
return true;
}
else
{
if (isShow)
{
Alert.ShowInTop(content);
}
return false;
}
}
#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>
private void GetButtonPower()
{
if (Request.Params["value"] == "0")
{
return;
}
var buttonList =
BLL.CommonService.GetAllButtonList(this.ProjectId, this.CurrUser.UserId, BLL.Const.PersonListMenuId);
if (buttonList.Count() > 0)
{
if (buttonList.Contains(BLL.Const.BtnAdd))
{
this.btnNew.Hidden = false;
this.btnImport.Hidden = false;
}
if (buttonList.Contains(BLL.Const.BtnModify))
{
this.btnMenuEdit.Hidden = false;
}
if (buttonList.Contains(BLL.Const.BtnDelete))
{
this.btnMenuDelete.Hidden = false;
}
}
}
#endregion
#region
/// <summary>
/// 导入按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnImport_Click(object sender, EventArgs e)
{
PageContext.RegisterStartupScript(
Window2.GetShowReference(String.Format("../../HSSE/SitePerson/PersonIn.aspx?ProjectId={0}", this.ProjectId, "导入 - ")));
}
/// <summary>
/// 关闭导入弹出窗口
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Window2_Close(object sender, WindowCloseEventArgs e)
{
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("质量人员报验信息" + filename, System.Text.Encoding.UTF8) + ".xls");
Response.ContentType = "application/excel";
Response.ContentEncoding = System.Text.Encoding.UTF8;
this.Grid1.PageSize = 500;
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)
{
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")
{
html = (row.FindControl("lblNumber") as AspNet.Label).Text;
}
if (column.ColumnID == "tfAge")
{
html = (row.FindControl("lblAge") as AspNet.Label).Text;
}
if (column.ColumnID == "tfI")
{
html = (row.FindControl("lbI") as AspNet.Label).Text;
}
// 对长数字添加前缀空格或格式,防止 Excel 精度丢失
if (column.ColumnID == "tfI" && html.Length > 15)
{
sb.AppendFormat("<td style=\"mso-number-format:'\\@';\">{0}</td>", html);
}
else
{
sb.AppendFormat("<td>{0}</td>", html);
}
}
sb.Append("</tr>");
}
sb.Append("</table>");
return sb.ToString();
}
#endregion
#region
/// <summary>
/// 查询
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void TextBox_TextChanged(object sender, EventArgs e)
{
this.BindGrid();
}
#endregion
/// <summary>
/// 年龄
/// </summary>
/// <param name="compileMan"></param>
/// <returns></returns>
protected string ConvertAge(object rirthday)
{
string age = string.Empty;
if (rirthday != null)
{
DateTime? bDate = Funs.GetNewDateTime(rirthday.ToString());
if (bDate.HasValue)
{
age = CommonService.CalculateAgeCorrect(bDate.Value).ToString();
}
}
return age;
}
}
}