using BLL; using BLL.Common; 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 定义项 /// /// 人员主键 /// public string SitePersonId { get { return (string)ViewState["SitePersonId"]; } set { ViewState["SitePersonId"] = value; } } /// /// 项目id /// public string ProjectId { get { return (string)ViewState["ProjectId"]; } set { ViewState["ProjectId"] = value; } } #endregion #region 加载页面 /// /// 加载页面 /// /// /// protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { Funs.DropDownPageSize(this.ddlPageSize); this.ProjectId = string.Empty; if (!string.IsNullOrEmpty(Request.Params["projectId"]) && Request.Params["projectId"] != this.ProjectId) { this.ProjectId = Request.Params["projectId"]; } else if (this.CurrUser != null) { this.ProjectId = this.CurrUser.LoginProjectId; } ////权限按钮方法 this.GetButtonPower(); this.btnMenuDelete.OnClientClick = Grid1.GetNoSelectionAlertReference("请至少选择一项!"); this.btnMenuDelete.ConfirmText = String.Format("你确定要删除选中的  行数据吗?", Grid1.GetSelectedCountReference()); this.ddlPageSize.SelectedValue = this.Grid1.PageSize.ToString(); BLL.WorkPostService.InitWorkPostDropDownList(this.drpPost, true); this.InitTreeMenu();//加载树 //if (this.CurrUser.PersonId == Const.hfnbdId || this.CurrUser.PersonId == Const.sysglyId) //{ // this.btnRefresh.Hidden = false; //} } } /// /// 加载树 /// private void InitTreeMenu() { this.tvProjectAndUnit.Nodes.Clear(); var project = BLL.ProjectService.GetProjectByProjectId(this.ProjectId); if (project != null) { var personLists = BLL.SitePerson_PersonService.GetSitePerson_PersonsLits(project.ProjectId, null, null, null); TreeNode rootNode = new TreeNode(); rootNode = new TreeNode { Text = project.ProjectName, NodeID = project.ProjectId }; if (personLists.Count() > 0) { int sumCount = personLists.Count(); int inCount = personLists.Where(x => x.States == Const.State_1).Count(); int outCount = personLists.Where(x => x.States == Const.State_2).Count(); int otherCount = sumCount - inCount - outCount; rootNode.ToolTip = "当前项目人员总数:" + sumCount + ";在场人员数:" + inCount + ";离场人员数:" + outCount + ";其他人员数:" + otherCount; } else { rootNode.ToolTip = "当前项目人员总数:0"; } rootNode.Expanded = true; this.tvProjectAndUnit.Nodes.Add(rootNode); GetUnitLists(rootNode.Nodes, this.ProjectId, personLists); } } /// /// 加载单位 /// /// /// private void GetUnitLists(TreeNodeCollection nodes, string parentId, List personLists) { List 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) { int sumCount = personUnitLists.Count(); int inCount = personUnitLists.Where(x => x.States == Const.State_1).Count(); int outCount = personUnitLists.Where(x => x.States == Const.State_2).Count(); int otherCount = sumCount - inCount - outCount; newNode.ToolTip = q.UnitName + "人员总数:" + sumCount + ";在场人员数:" + inCount + ";离场人员数:" + outCount + ";其他人员数:" + otherCount; } else { newNode.ToolTip = q.UnitName + "人员总数:0"; } } else { newNode.ToolTip = q.UnitName + "人员总数:0"; } newNode.EnableClickEvent = true; nodes.Add(newNode); } } } /// /// 绑定数据 /// private void BindGrid() { 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]; } string strSql = @"SELECT ProjectId,SitePersonId,PersonId,PersonName,IdentityCard,CardNo,PersonName ,WorkPostId,WorkPostName,UnitId,UnitName,TeamGroupId,TeamGroupName,InTime,RealNameAddTime,States, TrainCount,TrainCount1 FROM View_SitePerson_Person Where ProjectId=@ProjectId "; List listStr = new List { new SqlParameter("@ProjectId", this.ProjectId) }; if (!string.IsNullOrEmpty(unitId) && unitId != "0") { strSql += " AND UnitId =@UnitId "; listStr.Add(new SqlParameter("@UnitId", unitId)); } if (!string.IsNullOrEmpty(this.txtPersonName.Text.Trim())) { strSql += " AND PersonName LIKE @PersonName"; listStr.Add(new SqlParameter("@PersonName", "%" + this.txtPersonName.Text.Trim() + "%")); } if (!string.IsNullOrEmpty(this.txtIdentityCard.Text.Trim())) { strSql += " AND IdentityCard LIKE @IdentityCard"; listStr.Add(new SqlParameter("@IdentityCard", "%" + this.txtIdentityCard.Text.Trim() + "%")); } if (!string.IsNullOrEmpty(this.drpTreamGroup.SelectedValue) && this.drpTreamGroup.SelectedValue != BLL.Const._Null) { strSql += " AND TeamGroupId = @TeamGroupId"; listStr.Add(new SqlParameter("@TeamGroupId", this.drpTreamGroup.SelectedValue)); } if (this.drpPost.SelectedItemArray.Count() > 1 || (this.drpPost.SelectedValue != BLL.Const._Null && this.drpPost.SelectedItemArray.Count() == 1)) { strSql += " AND (1=2 "; int i = 0; foreach (var item in this.drpPost.SelectedValueArray) { if (!string.IsNullOrEmpty(item) && item != BLL.Const._Null) { strSql += " OR WorkPostId = @WorkPostId" + i.ToString(); listStr.Add(new SqlParameter("@WorkPostId" + i.ToString(), item)); } i++; } strSql += ")"; } if (this.ckTrain.Checked) { strSql += " AND (TrainCount =0 AND TrainCount1 =0)"; } if (this.ckIsUsed.Checked) { strSql += " AND States ='1'"; } if (this.ckJT.Checked) { strSql += " AND RealNameAddTime IS NULL"; } if (this.ckIdCardInfoNotOK.Checked) { strSql += " AND (IdcardType is null or IdentityCard is null or PhotoUrl is null or HeadImage IS NULL OR (LEN(IdentityCard) != 15 AND LEN(IdentityCard) != 18) or TeamGroupId is null or WorkPostId is null)"; } 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(); for (int i = 0; i < Grid1.Rows.Count; i++) { // string personId = Grid1.Rows[i].DataKeys[0].ToString(); var tCount = Grid1.Rows[i].Values[8].ToString(); var tCount1 = Grid1.Rows[i].Values[9].ToString(); if (tCount == "0" && tCount1 == "0") ////未参加过培训的人员 { Grid1.Rows[i].RowCssClass = "Red"; } var getPerson = Grid1.Rows[i].Values[6].ToString(); if (getPerson != null) { int j = this.Grid1.Columns.Count - 1; Grid1.Rows[i].CellCssClasses[j] = "LabelGreen"; } } } #endregion #region 点击TreeView /// /// 点击TreeView /// /// /// 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); BindGrid(); } } #endregion #region 页索引改变事件 /// /// 页索引改变事件 /// /// /// protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e) { Grid1.PageIndex = e.NewPageIndex; BindGrid(); } #endregion #region 排序 /// /// 排序 /// /// /// protected void Grid1_Sort(object sender, GridSortEventArgs e) { Grid1.SortDirection = e.SortDirection; Grid1.SortField = e.SortField; BindGrid(); } #endregion #region 分页选择下拉改变事件 /// /// 分页选择下拉改变事件 /// /// /// protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e) { Grid1.PageSize = Convert.ToInt32(ddlPageSize.SelectedValue); BindGrid(); } #endregion #region 增加按钮 /// /// 增加按钮 /// /// /// 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("~/Person/ProjectPersonEdit.aspx?ProjectId={0}&&UnitId={1}", projectId, unitId, "编辑 - "))); } } else { Alert.ShowInTop("请选择单位!", MessageBoxIcon.Warning); return; } } #endregion #region 编辑 /// /// 右键编辑事件 /// /// /// protected void btnMenuEdit_Click(object sender, EventArgs e) { this.EditData(); } /// /// 编辑 /// private void EditData() { if (Grid1.SelectedRowIndexArray.Length == 0) { Alert.ShowInTop("请至少选择一条记录!", MessageBoxIcon.Warning); return; } this.SitePersonId = Grid1.SelectedRowID; if (this.tvProjectAndUnit.SelectedNode != null) { 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("~/Person/ProjectPersonEdit.aspx?SitePersonId={0}&&ProjectId={1}&&UnitId={2}", this.SitePersonId, projectId, unitId, "编辑 - "))); } } else { PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("~/Person/ProjectPersonEdit.aspx?SitePersonId={0}", this.SitePersonId, "编辑 - "))); } } /// /// Grid双击事件 /// /// /// protected void Grid1_RowDoubleClick(object sender, GridRowClickEventArgs e) { this.EditData(); } #endregion #region 删除 /// /// 右键删除事件 /// /// /// protected void btnMenuDelete_Click(object sender, EventArgs e) { this.DeleteData(); } /// /// 删除方法 /// 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.SitePerson_PersonService.GetSitePersonById(rowID); if (getV != null) { BLL.LogService.AddSys_Log(this.CurrUser, getV.PersonName, getV.PersonId, BLL.Const.PersonListMenuId, BLL.Const.BtnDelete); BLL.SitePerson_PersonService.DeleteSitePersonById(rowID); } } BindGrid(); if (string.IsNullOrEmpty(message)) { ShowNotify("删除数据成功!", MessageBoxIcon.Success); } else { Alert.ShowInParent(message, MessageBoxIcon.Warning); } } } #endregion #region 关闭弹出窗口 /// /// 关闭弹出窗口 /// /// /// protected void Window1_Close(object sender, WindowCloseEventArgs e) { BindGrid(); } #endregion #region 判断按钮权限 /// /// 判断按钮权限 /// private void GetButtonPower() { if (Request.Params["value"] == "0") { return; } var buttonList = BLL.CommonService.GetAllButtonList(this.CurrUser.LoginProjectId, this.CurrUser.PersonId, 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; this.btnRefresh.Hidden = false; } if (buttonList.Contains(BLL.Const.BtnModify)) { this.btnMenuEdit.Hidden = false; this.btnPersonUnit.Hidden = false; } if (buttonList.Contains(BLL.Const.BtnDelete)) { this.btnMenuDelete.Hidden = false; this.btnPersonUnit.Hidden = false; } } } #endregion #region 导入 /// /// 导入按钮 /// /// /// 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, "导入 - "))); } /// /// 关闭导入弹出窗口 /// /// /// protected void Window2_Close(object sender, WindowCloseEventArgs 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.; BindGrid(); Response.Write(GetGridTableHtml(Grid1)); Response.End(); } #pragma warning disable CS0108 // “PersonList.GetGridTableHtml(Grid)”隐藏继承的成员“PageBase.GetGridTableHtml(Grid)”。如果是有意隐藏,请使用关键字 new。 /// /// 导出方法 /// /// /// private string GetGridTableHtml(Grid grid) #pragma warning restore CS0108 // “PersonList.GetGridTableHtml(Grid)”隐藏继承的成员“PageBase.GetGridTableHtml(Grid)”。如果是有意隐藏,请使用关键字 new。 { StringBuilder sb = new StringBuilder(); sb.Append(""); sb.Append(""); sb.Append(""); foreach (GridColumn column in grid.Columns) { sb.AppendFormat("", column.HeaderText); } sb.Append(""); foreach (GridRow row in grid.Rows) { sb.Append(""); 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("", html); sb.AppendFormat("", html); } sb.Append(""); } sb.Append("
{0}
{0}{0}
"); return sb.ToString(); } #endregion #region 批量出场 /// /// 批量出场按钮 /// /// /// protected void btnPersonOut_Click(object sender, EventArgs e) { PageContext.RegisterStartupScript(Window3.GetShowReference(String.Format("PersonOut.aspx?ProjectId={0}", this.CurrUser.LoginProjectId, "批量出场 - "))); } /// /// 批量单位转换 /// /// /// protected void btnPersonUnit_Click(object sender, EventArgs e) { if (BLL.CommonService.IsMainUnitOrAdmin(this.CurrUser.PersonId)) { PageContext.RegisterStartupScript(Window3.GetShowReference(String.Format("PersonUnitRefresh.aspx", "批量单位转换 - "))); } else { ShowNotify("非软件管理单位用户,不能调整人员单位!", MessageBoxIcon.Warning); } } /// /// 关闭导入弹出窗口 /// /// /// protected void Window3_Close(object sender, WindowCloseEventArgs e) { BindGrid(); } #endregion #region 查询 /// /// 查询 /// /// /// protected void TextBox_TextChanged(object sender, EventArgs e) { this.BindGrid(); } #endregion /// /// 批量生成二维码 /// /// /// protected void btnQR_Click(object sender, EventArgs e) { var getPersons = from x in Funs.DB.SitePerson_Person join y in Funs.DB.Person_Persons on x.IdentityCard equals y.IdentityCard where x.ProjectId == this.CurrUser.LoginProjectId && x.IdentityCard != null select y; 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); } /// /// 根据id返回单位工程名称 /// /// /// protected string ConvertWorkAreaName(object WorkAreaId) { string name = ""; if (WorkAreaId != null) { name = BLL.UnitWorkService.GetUnitWorkName(WorkAreaId.ToString()); name = Funs.GetSubStr(name, 6); } return name; } protected void drpPost_SelectedIndexChanged(object sender, EventArgs e) { this.drpPost.SelectedValueArray = Funs.RemoveDropDownListNull(this.drpPost.SelectedValueArray); this.BindGrid(); } /// /// 人员详细信息查看 /// /// /// protected void btnSee_Click(object sender, EventArgs e) { var getSitePerson = SitePerson_PersonService.GetSitePersonById(Grid1.SelectedRowID); if (getSitePerson != null) { PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("../../Person/ProjectPersonView.aspx?SitePersonId={0}", this.SitePersonId, "查看 - "))); } } protected void btnRefresh_Click(object sender, EventArgs e) { int count = GetDataService.SendCarNo(this.ProjectId); Alert.ShowInTop("刷新完成" + count.ToString() + "条。", MessageBoxIcon.Success); } protected void btnToYunMou_Click(object sender, EventArgs e) { if (Grid1.SelectedRowIndexArray.Length > 0) { foreach (int rowIndex in Grid1.SelectedRowIndexArray) { string rowID = Grid1.DataKeys[rowIndex][0].ToString(); var sitePerson = Funs.DB.SitePerson_Person.FirstOrDefault(x => x.SitePersonId == rowID); var person = Funs.DB.Person_Persons.FirstOrDefault(x => x.IdentityCard == sitePerson.IdentityCard); if (!string.IsNullOrEmpty(person.PhotoUrl)) { var token = YunMouHelper.getToken(); var project = Funs.DB.Base_Project.FirstOrDefault(x => x.ProjectId == CurrUser.LoginProjectId); var res1 = YunMouHelper.addPerson(person.IdentityCard, person.PersonName, string.IsNullOrEmpty(person.Telephone) ? "" : person.Telephone, person.PhotoUrl, token); var res2 = YunMouHelper.addPersonsToGroups(project.YunMouGroupId, new string[] { person.IdentityCard }, token); person.YunMouState = "已经同步"; Funs.DB.SubmitChanges(); } } this.BindGrid(); } else { ShowNotify("请选择用户", MessageBoxIcon.Warning); } } } }