CNCEC_SUBQHSE_WUHUAN/SGGL/FineUIPro.Web/HSSE/SitePerson/PersonList.aspx.cs

733 lines
27 KiB
C#
Raw Normal View History

2021-04-30 10:28:37 +08:00
using BLL;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using AspNet = System.Web.UI.WebControls;
namespace FineUIPro.Web.HSSE.SitePerson
{
public partial class PersonList : 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.ProjectId)
{
this.ProjectId = Request.Params["projectId"];
}
////权限按钮方法
this.GetButtonPower();
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();
BLL.WorkPostService.InitWorkPostDropDownList(this.drpPost, true);
this.InitTreeMenu();//加载树
}
}
/// <summary>
/// 加载树
/// </summary>
private void InitTreeMenu()
{
this.tvProjectAndUnit.Nodes.Clear();
var project = BLL.ProjectService.GetProjectByProjectId(this.ProjectId);
if (project != null)
{
var personLists = BLL.PersonService.GetPersonList(project.ProjectId);
TreeNode rootNode = new TreeNode();
rootNode = new TreeNode
{
Text = project.ProjectName,
NodeID = project.ProjectId
};
if (personLists.Count() > 0)
{
2022-03-25 14:57:05 +08:00
var personIn = personLists.Where(x => x.ProjectId == project.ProjectId && x.IsUsed == true
2021-04-30 10:28:37 +08:00
&& x.InTime <= DateTime.Now && (!x.OutTime.HasValue || x.OutTime > DateTime.Now)).ToList();
rootNode.ToolTip = "当前项目人员总数:" + personLists.Count() + ";在场人员数:" + personIn.Count() + ";离场人员数:" + (personLists.Count() - personIn.Count());
}
else
{
rootNode.ToolTip = "当前项目人员总数0";
}
rootNode.Expanded = true;
2021-07-06 15:16:17 +08:00
rootNode.EnableClickEvent = true;
2021-04-30 10:28:37 +08:00
this.tvProjectAndUnit.Nodes.Add(rootNode);
2022-03-25 14:57:05 +08:00
GetUnitLists(rootNode.Nodes, project.ProjectId, personLists);
2021-04-30 10:28:37 +08:00
}
}
/// <summary>
/// 加载单位
/// </summary>
/// <param name="nodes"></param>
/// <param name="parentId"></param>
private void GetUnitLists(TreeNodeCollection nodes, string parentId, List<Model.SitePerson_Person> personLists)
{
List<Model.Base_Unit> unitLists = BLL.UnitService.GetUnitByProjectIdList(parentId);
if (unitLists.Count() > 0)
{
if (BLL.ProjectUnitService.GetProjectUnitTypeByProjectIdUnitId(parentId, this.CurrUser.UnitId))
{
unitLists = unitLists.Where(x => x.UnitId == this.CurrUser.UnitId).ToList();
}
//添加其他单位/无单位人员
Model.Base_Unit otherUnit = new Model.Base_Unit
{
UnitId = "0",
UnitName = "其他"
};
unitLists.Add(otherUnit);
TreeNode newNode = null;
foreach (var q in unitLists)
{
newNode = new TreeNode
{
Text = q.UnitName,
NodeID = q.UnitId + "|" + parentId,
ToolTip = q.UnitName
};
if (personLists.Count() > 0)
{
var personUnitLists = personLists.Where(x => x.UnitId == q.UnitId);
if (q.UnitId == "0")
{
personUnitLists = personLists.Where(x => x.UnitId == null);
}
if (personUnitLists.Count() > 0)
{
var personIn = personUnitLists.Where(x => x.InTime <= System.DateTime.Now && x.IsUsed == true
&& (!x.OutTime.HasValue || x.OutTime >= System.DateTime.Now));
newNode.ToolTip = q.UnitName + "人员总数:" + personUnitLists.Count() + ";在场人员数:" + personIn.Count() + ";离场人员数:" + (personUnitLists.Count() - personIn.Count());
}
else
{
newNode.ToolTip = q.UnitName + "人员总数0";
}
}
else
{
newNode.ToolTip = q.UnitName + "人员总数0";
}
newNode.EnableClickEvent = true;
nodes.Add(newNode);
}
}
}
/// <summary>
/// 绑定数据
/// </summary>
private void BindGrid()
{
using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString))
2021-08-26 11:26:04 +08:00
{
2021-07-06 15:16:17 +08:00
string unitId = string.Empty;
2021-04-30 10:28:37 +08:00
if (this.tvProjectAndUnit != null && !string.IsNullOrEmpty(this.tvProjectAndUnit.SelectedNodeID))
{
2021-07-06 15:16:17 +08:00
var str = this.tvProjectAndUnit.SelectedNodeID.Split('|');
2021-04-30 10:28:37 +08:00
if (str.Count() > 1)
{
unitId = str[0];
}
2021-07-06 15:16:17 +08:00
}
2021-04-30 10:28:37 +08:00
2021-08-16 17:41:00 +08:00
var getData = PersonService.getListData(this.ProjectId, unitId, this.txtPersonName.Text.Trim(), this.txtIdentityCard.Text.Trim(),
2021-08-17 11:01:22 +08:00
this.drpTreamGroup.SelectedValue, Funs.GetStringByArray(this.drpPost.SelectedValueArray), this.ckTrain.Checked, this.rblPost.SelectedValue, this.ckJT.Checked,
2025-05-24 14:48:16 +08:00
this.ckIdCardInfoNotOK.Checked, this.chManager.Checked, Grid1);
2021-08-16 17:41:00 +08:00
Grid1.RecordCount = PersonService.count;
Grid1.DataSource = getData;
2021-07-06 15:16:17 +08:00
Grid1.DataBind();
2024-08-07 15:00:10 +08:00
var project = BLL.ProjectService.GetProjectByProjectId(this.CurrUser.LoginProjectId);
2021-08-26 11:26:04 +08:00
for (int i = 0; i < Grid1.Rows.Count; i++)
{
string idCard = Grid1.Rows[i].Values[3].ToString();
2024-08-07 15:00:10 +08:00
if (project.IsForeign == null || project.IsForeign == false)
2021-08-26 11:26:04 +08:00
{
2024-08-07 15:00:10 +08:00
if (!IDCardValid.CheckIDCard(idCard))
{
Grid1.Rows[i].RowCssClass = "Red";
}
2021-08-26 11:26:04 +08:00
}
}
2021-04-30 10:28:37 +08:00
}
}
#endregion
#region TreeView
/// <summary>
/// 点击TreeView
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void tvProjectAndUnit_NodeCommand(object sender, TreeCommandEventArgs e)
{
this.drpTreamGroup.Items.Clear();
if (this.tvProjectAndUnit.SelectedNodeID.Contains("|"))
{
string id = this.tvProjectAndUnit.SelectedNodeID;
string unitId = string.Empty;
string projectId = string.Empty;
var str = id.Split('|');
if (str.Count() > 1)
{
unitId = str[0];
projectId = str[1];
}
BLL.TeamGroupService.InitTeamGroupProjectUnitDropDownList(this.drpTreamGroup, projectId, unitId, true);
2021-07-06 15:16:17 +08:00
BindGrid();
}
else
{
2021-04-30 10:28:37 +08:00
BindGrid();
}
}
#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)
{
if (this.tvProjectAndUnit.SelectedNodeID.Contains("|"))
{
string id = this.tvProjectAndUnit.SelectedNodeID;
string[] str = id.Split('|');
if (str.Count() > 1)
{
string unitId = id.Split('|')[0];
string projectId = id.Split('|')[1];
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("PersonListEdit.aspx?ProjectId={0}&&UnitId={1}", projectId, unitId, "编辑 - ")));
}
}
else
{
Alert.ShowInTop("请选择单位!", MessageBoxIcon.Warning);
return;
}
}
#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;
}
this.PersonId = Grid1.SelectedRowID;
2021-07-06 15:16:17 +08:00
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("PersonListEdit.aspx?PersonId={0}", this.PersonId, "编辑 - ")));
2021-04-30 10:28:37 +08:00
}
/// <summary>
/// Grid双击事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Grid1_RowDoubleClick(object sender, GridRowClickEventArgs e)
{
this.EditData();
}
#endregion
2021-04-30 10:28:37 +08:00
#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)
{
string message = string.Empty;
foreach (int rowIndex in Grid1.SelectedRowIndexArray)
{
string rowID = Grid1.DataKeys[rowIndex][0].ToString();
var getV = BLL.PersonService.GetPersonById(rowID);
if (getV != null)
{
string rowMessage = this.judgementDelete(rowID, getV.PersonName);
if (string.IsNullOrEmpty(rowMessage))
{
BLL.LogService.AddSys_Log(this.CurrUser, getV.PersonName, getV.PersonId, BLL.Const.PersonListMenuId, BLL.Const.BtnDelete);
BLL.PersonService.DeletePerson(rowID);
}
else
{
message += rowMessage;
}
}
}
BindGrid();
if (string.IsNullOrEmpty(message))
{
ShowNotify("删除数据成功!", MessageBoxIcon.Success);
}
else
{
Alert.ShowInParent(message, MessageBoxIcon.Warning);
}
}
}
/// <summary>
/// 判断是否可删除
/// </summary>
/// <param name="rowID"></param>
/// <param name="isShow"></param>
/// <returns></returns>
private string judgementDelete(string rowID, string name)
{
string content = string.Empty;
///违规人员
var getViolation = from x in Funs.DB.Check_ViolationPerson where x.PersonId == rowID select x;
foreach (var item in getViolation)
{
content += "违规人员【" + item.ViolationPersonCode + "】";
}
///培训记录
var getTrainRecord = from x in Funs.DB.EduTrain_TrainRecordDetail
join y in Funs.DB.EduTrain_TrainRecord on x.TrainingId equals y.TrainingId
where x.PersonId == rowID select y;
foreach (var item in getTrainRecord)
{
content += "培训记录【" + item.TrainingCode + "】";
}
///考试计划 - 考试记录
var getTestRecode = from x in Funs.DB.Training_TestRecord
join y in Funs.DB.Training_TestPlan on x.TestPlanId equals y.TestPlanId
where x.TestManId == rowID
select y;
foreach (var item in getTestRecode)
{
content += "考试计划【" + item. PlanCode+ "】";
}
///人员绩效
var getPerfomances = from x in Funs.DB.Perfomance_PersonPerfomance
where x.PersonId == rowID
select x;
foreach (var item in getPerfomances)
{
content += "人员绩效【" + item.PersonPerfomanceCode + "】";
2021-08-30 21:49:56 +08:00
}
2021-04-30 10:28:37 +08:00
2021-08-30 21:49:56 +08:00
var getPerson = Funs.DB.SitePerson_Person.FirstOrDefault(x => x.PersonId == rowID && x.RealNameAddTime.HasValue);
if (getPerson != null)
{
content += "人员【" + getPerson.PersonName + "】已上传集团。";
}
2021-04-30 10:28:37 +08:00
if (!string.IsNullOrEmpty(content))
{
content += "中已使用该人员【" + name + "】!";
}
return content;
}
#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.CurrUser.LoginProjectId, this.CurrUser.UserId, BLL.Const.PersonListMenuId);
if (buttonList.Count() > 0)
{
if (buttonList.Contains(BLL.Const.BtnAdd))
{
this.btnNew.Hidden = false;
this.btnImport.Hidden = false;
this.btnPersonOut.Hidden = false;
}
if (buttonList.Contains(BLL.Const.BtnModify))
{
this.btnMenuEdit.Hidden = false;
this.btnPersonUnit.Hidden = false;
btnMenuBlack.Hidden = false;
2021-04-30 10:28:37 +08:00
}
if (buttonList.Contains(BLL.Const.BtnDelete))
{
this.btnMenuDelete.Hidden = false;
this.btnPersonUnit.Hidden = false;
}
}
}
#endregion
#region
/// <summary>
/// 导入按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnImport_Click(object sender, EventArgs e)
{
//if (this.tvProjectAndUnit.SelectedNodeID.Contains("|"))
//{
// string id = this.tvProjectAndUnit.SelectedNodeID;
// string unitId = string.Empty;
// string projectId = string.Empty;
// unitId = id.Split('|')[0];
// projectId = id.Split('|')[1];
//}
//else
//{
// Alert.ShowInTop("请选择单位!", MessageBoxIcon.Warning);
// return;
//}
PageContext.RegisterStartupScript(Window2.GetShowReference(String.Format("PersonIn.aspx?ProjectId={0}", this.CurrUser.LoginProjectId, "导入 - ")));
}
/// <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;
2021-07-09 16:47:06 +08:00
this.Grid1.PageSize = this.Grid1.RecordCount;
2021-04-30 10:28:37 +08:00
BindGrid();
Response.Write(GetGridTableHtml(Grid1));
Response.End();
}
#pragma warning disable CS0108 // “PersonList.GetGridTableHtml(Grid)”隐藏继承的成员“PageBase.GetGridTableHtml(Grid)”。如果是有意隐藏,请使用关键字 new。
/// <summary>
/// 导出方法
/// </summary>
/// <param name="grid"></param>
/// <returns></returns>
private string GetGridTableHtml(Grid grid)
#pragma warning restore CS0108 // “PersonList.GetGridTableHtml(Grid)”隐藏继承的成员“PageBase.GetGridTableHtml(Grid)”。如果是有意隐藏,请使用关键字 new。
{
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("labNumber") as AspNet.Label).Text;
}
if (column.ColumnID == "tfI")
{
html = (row.FindControl("lbI") as AspNet.Label).Text;
}
//sb.AppendFormat("<td>{0}</td>", html);
sb.AppendFormat("<td style='vnd.ms-excel.numberformat:@;width:140px;'>{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 btnPersonOut_Click(object sender, EventArgs e)
{
PageContext.RegisterStartupScript(Window3.GetShowReference(String.Format("PersonOut.aspx?ProjectId={0}", this.CurrUser.LoginProjectId, "批量出场 - ")));
}
/// <summary>
/// 批量单位转换
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnPersonUnit_Click(object sender, EventArgs e)
{
if (BLL.CommonService.IsMainUnitOrAdmin(this.CurrUser.UserId))
{
PageContext.RegisterStartupScript(Window3.GetShowReference(String.Format("PersonUnitRefresh.aspx", "批量单位转换 - ")));
}
else
{
ShowNotify("非软件管理单位用户,不能调整人员单位!", MessageBoxIcon.Warning);
}
}
/// <summary>
/// 关闭导入弹出窗口
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Window3_Close(object sender, WindowCloseEventArgs e)
{
BindGrid();
}
#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="sender"></param>
/// <param name="e"></param>
protected void btnQR_Click(object sender, EventArgs e)
{
var getPersons = from x in Funs.DB.SitePerson_Person
where x.ProjectId == this.CurrUser.LoginProjectId && x.IdentityCard != null && x.QRCodeAttachUrl == null
select x;
int num = 0;
if (getPersons.Count() > 0)
{
foreach (var item in getPersons)
{
string url = CreateQRCodeService.CreateCode_Simple("person$" + item.IdentityCard);
if (!string.IsNullOrEmpty(url))
{
item.QRCodeAttachUrl = url;
Funs.DB.SubmitChanges();
num++;
}
}
}
ShowNotify("操作完成,新生成二维码"+ num.ToString()+"条", MessageBoxIcon.Success);
}
2021-07-08 20:34:29 +08:00
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnPhoto_Click(object sender, EventArgs e)
{
var getPersons = from x in Funs.DB.SitePerson_Person
where x.ProjectId == this.ProjectId && x.HeadImage == null && x.PhotoUrl != null
select x;
2021-07-09 16:47:06 +08:00
int num = 0;
2021-07-08 20:34:29 +08:00
foreach (var item in getPersons)
{
item.HeadImage = AttachFileService.SetImageToByteArray(Funs.RootPath + item.PhotoUrl);
Funs.DB.SubmitChanges();
2021-07-09 16:47:06 +08:00
num++;
2021-07-08 20:34:29 +08:00
}
2021-07-09 16:47:06 +08:00
ShowNotify("操作完成,新转二进制照片" + num.ToString() + "条", MessageBoxIcon.Success);
2021-07-08 20:34:29 +08:00
}
2021-08-16 17:41:00 +08:00
protected void drpPost_SelectedIndexChanged(object sender, EventArgs e)
{
this.drpPost.SelectedValueArray = Funs.RemoveDropDownListNull(this.drpPost.SelectedValueArray);
}
protected void btnPersonStates_Click(object sender, EventArgs e)
{
var getPersons = from x in Funs.DB.SitePerson_Person
where x.ProjectId == this.CurrUser.LoginProjectId && x.ExchangeTime.HasValue
select x;
int pcount = getPersons.Count();
if (pcount > 0)
{
foreach (var item in getPersons)
{
item.ExchangeTime = null;
item.ExchangeTime2 = null;
Funs.DB.SubmitChanges();
}
}
Alert.ShowInTop("操作完成,重置人员" + pcount.ToString() + "条", MessageBoxIcon.Success);
}
#region
protected void btnMenuBlack_Click(object sender, EventArgs e)
{
if (Grid1.SelectedRowIndexArray.Length == 0)
{
Alert.ShowInTop("请至少选择一条记录!", MessageBoxIcon.Warning);
return;
}
this.PersonId = Grid1.SelectedRowID;
var result = Funs.DB.SitePerson_Person.FirstOrDefault(x => x.PersonId == PersonId);
if (result != null)
{
result.IsBlacklist = true;
Funs.DB.SubmitChanges();
BindGrid();
}
}
#endregion
2021-04-30 10:28:37 +08:00
}
}