using BLL; using FineUIPro.Web.DataShow; using FineUIPro.Web.ProjectData; using FineUIPro.Web.ZHGL.RealName; using Model; 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.Customization.CNCCG.HSSE.QualityAudit { public partial class SafePersonQuality : PageBase { #region 项目主键 /// /// 项目主键 /// public string ProjectId { get { return (string)ViewState["ProjectId"]; } set { ViewState["ProjectId"] = value; } } public string MenuId= Const.CompanySafePersonMenuId; #endregion #region 加载 /// /// 加载页面 /// /// /// protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { ////权限按钮方法 this.GetButtonPower(); this.ProjectId = this.CurrUser.LoginProjectId; if (!string.IsNullOrEmpty(Request.Params["projectId"]) && Request.Params["projectId"] != this.CurrUser.LoginProjectId) { this.ProjectId = Request.Params["projectId"]; } this.InitDropDownList(); this.ucTree.UnitId = this.CurrUser.UnitId; this.ucTree.ProjectId = this.ProjectId; Funs.DropDownPageSize(this.ddlPageSize); // 绑定表格 this.BindGrid(); if (!string.IsNullOrEmpty(this.ProjectId) && CommonService.GetThisUnitId() != Const.CncecFccId) { MenuId = Const.SafePersonQualityMenuId; this.panelLeftRegion.Hidden = true; // this.Grid1.Columns[0].Hidden = true; ////权限按钮方法 this.GetButtonPower(); } } } protected void changeTree(object sender, EventArgs e) { this.ProjectId = this.ucTree.ProjectId; this.InitDropDownList(); this.BindGrid(); } private void InitDropDownList() { BLL.UnitService.InitUnitDropDownList(this.drpUnitId, this.ProjectId, true); if (BLL.ProjectUnitService.GetProjectUnitTypeByProjectIdUnitId(this.ProjectId, this.CurrUser.UnitId)) { this.drpUnitId.SelectedValue = this.CurrUser.UnitId; this.drpUnitId.Enabled = false; } } /// /// 绑定数据 /// private void BindGrid() { var db = Funs.DB; var query = ( from person in db.SitePerson_Person join post in db.Base_WorkPost on person.WorkPostId equals post.WorkPostId into posts from post in posts.DefaultIfEmpty() join unit in db.Base_Unit on person.UnitId equals unit.UnitId into units from unit in units.DefaultIfEmpty() join postTitle in db.Base_PostTitle on person.PostTitleId equals postTitle.PostTitleId into postTitles from postTitle in postTitles.DefaultIfEmpty() join personQuality in db.QualityAudit_PersonQuality on person.PersonId equals personQuality.PersonId into personQualitys from personQuality in personQualitys.DefaultIfEmpty() join edu in db.RealName_BasicData on person.EduLevel equals edu.DictCode into edus from edu in edus.DefaultIfEmpty() join project in db.Base_Project on person.ProjectId equals project.ProjectId into projects from project in projects.DefaultIfEmpty() //join teamGroup in db.ProjectData_TeamGroup on person.TeamGroupId equals teamGroup.TeamGroupId into // teamGroups //from teamGroup in teamGroups.DefaultIfEmpty() where post.IsHsse == true && (drpUnitId.SelectedValue == Const._Null || person.UnitId == drpUnitId.SelectedValue) && (string.IsNullOrEmpty(txtCardNo.Text) || person.CardNo.Contains(txtCardNo.Text.Trim())) && (string.IsNullOrEmpty(txtPersonName.Text) || person.PersonName.Contains(txtPersonName.Text.Trim())) && (string.IsNullOrEmpty(txtWorkPostName.Text) || post.WorkPostName.Contains(txtWorkPostName.Text.Trim())) && person.IsUsed == (drpIsUsedName.SelectedValue == "是" ? true : false) && project.ProjectState== BLL.Const.ProjectState_1 && (project .IsDelete==null || project.IsDelete==false) select new { person.ProjectId, person.UnitId, person.PersonId, person.PersonName, person.Birthday, Sex = person.Sex == "1" ? "男" : person.Sex == "2" ? "女" : "", edu.DictName, unit.UnitName, post.WorkPostName, person.Major, person.SafeWorkingYears, person.WorkingYears, person.InTime, person.IsUsed, IsUsedName = person.IsUsed == true ? "是" : "否", person.OutTime, postTitle.PostTitleName, personQuality.PersonQualityId, personQuality.CertificateNo, ProjectUnitId=project.UnitId, project.ShortName // teamGroup.TeamGroupName, } ).Distinct(); if (!string.IsNullOrEmpty(ProjectId) && ProjectId != Const._Null) { query = query.Where(e => e.ProjectId == ProjectId); } else { if (this.ucTree.UnitId!=CommonService.GetThisUnitId()) { query = query.Where(e => e.ProjectUnitId == this.ucTree.UnitId).OrderBy(e => e.ShortName).ThenBy(e => e.UnitId); } //query = query.Where(e => Equals(e.ProjectId, null) && e.UnitId== this.ucTree.UnitId); } // 添加计数的序号 var groupedQuery = query.ToList().GroupBy(p => p.PersonId).SelectMany((group, index) => group.Select((person, personIndex) => new { Index = index + 1, person.PersonId, person.PersonName, person.Birthday, person.Sex, person.DictName, person.UnitName, person.WorkPostName, person.Major, person.SafeWorkingYears, person.WorkingYears, person.InTime, person.IsUsed, person.IsUsedName, person.OutTime, person.PostTitleName, person.PersonQualityId, person.CertificateNo, person.ShortName // person.TeamGroupName })).ToList(); this.Grid1.RecordCount = groupedQuery.Count; this.lbAllPersonNum.Text = "合计:共" + groupedQuery .Select(g => g.Index) .DefaultIfEmpty(0) // 当集合为空时提供默认值0 .Max() +"人"; var table = groupedQuery.OrderBy(p => p.Index).Skip(this.Grid1.PageIndex * this.Grid1.PageSize).Take(this.Grid1.PageSize).ToList(); this.Grid1.DataSource = table; this.Grid1.DataBind(); } /// /// 改变索引事件 /// /// /// protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e) { this.BindGrid(); } /// /// 分页下拉选择事件 /// /// /// protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e) { this.Grid1.PageSize = Convert.ToInt32(this.ddlPageSize.SelectedValue); this.BindGrid(); } /// /// 排序 /// /// /// protected void Grid1_Sort(object sender, FineUIPro.GridSortEventArgs e) { this.BindGrid(); } #endregion #region 查询 /// /// 查询 /// /// /// protected void TextBox_TextChanged(object sender, EventArgs e) { this.BindGrid(); } #endregion #region 编辑 /// /// 双击事件 /// /// /// protected void Grid1_RowDoubleClick(object sender, GridRowClickEventArgs e) { this.EditData(); } /// /// 右键编辑事件 /// /// /// protected void btnMenuEdit_Click(object sender, EventArgs e) { this.EditData(); } /// /// 编辑数据方法 /// private void EditData() { if (Grid1.SelectedRowIndexArray.Length == 0) { Alert.ShowInTop("请至少选择一条记录!", MessageBoxIcon.Warning); return; } string id = Grid1.SelectedRow.DataKeys[0].ToString(); var person = BLL.PersonService.GetPersonById(id); if (person != null) { if (!string.IsNullOrEmpty(ProjectId)) { PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("PersonListEdit.aspx?ProjectId={0}&&Type={1}&&PersonId={2}&&UnitId={3}", this.ProjectId, "0", id, ucTree.UnitId, "编辑 - "))); } else { PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("PersonListEdit.aspx?ProjectId={0}&&Type={1}&&PersonId={2}&&UnitId={3}&&CompanyEdit={4}", this.ProjectId, "0", id, ucTree.UnitId,1, "编辑 - "))); } } } #endregion #region 获取按钮权限 /// /// 获取按钮权限 /// /// /// private void GetButtonPower() { var buttonList = BLL.CommonService.GetAllButtonList(this.ProjectId, this.CurrUser.UserId, MenuId); if (buttonList.Count() > 0) { if (buttonList.Contains(BLL.Const.BtnModify)) { this.btnMenuEdit.Hidden = false; } if (buttonList.Contains(BLL.Const.BtnAdd)) { this.btnNew.Hidden = false; } if (buttonList.Contains(BLL.Const.BtnDelete)) { this.btnMenuDelete.Hidden = false; } } } #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 = 500; BindGrid(); Response.Write(GetGridTableHtml(Grid1)); Response.End(); } /// /// 导出方法 /// /// /// private string GetGridTableHtml(Grid grid) { StringBuilder sb = new StringBuilder(); sb.Append(""); sb.Append(""); sb.Append(""); foreach (GridColumn column in grid.Columns) { if (column.ColumnID != "attWindow") { 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("lblNumber") as AspNet.Label).Text; } if (column.ColumnID != "attWindow") { sb.AppendFormat("", html); } } sb.Append(""); } sb.Append("
{0}
{0}
"); return sb.ToString(); } #endregion protected void btnNew_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(ProjectId)) { PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("PersonListEdit.aspx?ProjectId={0}&&UnitId={1}&&Type={2}&&CompanyEdit={3}", ProjectId, ucTree.UnitId, "0",1, "编辑 - "))); } else { PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("PersonListEdit.aspx?ProjectId={0}&&UnitId={1}&&Type={2}", ProjectId, ucTree.UnitId, "0", "编辑 - "))); } } #region 删除 /// /// 右键删除事件 /// /// /// protected void btnMenuDelete_Click(object sender, EventArgs e) { this.DeleteData(); } /// /// 删除方法 /// 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, MenuId, BLL.Const.BtnDelete); BLL.PersonService.DeletePerson(rowID); } } } BindGrid(); if (i > 0) { ShowNotify("删除数据成功!(表格数据已重新绑定)", MessageBoxIcon.Success); } } } /// /// 判断是否可删除 /// /// /// /// private bool judgementDelete(string rowID, bool isShow) { string content = string.Empty; //var q = from x in Funs.DB.QualityAudit_PersonQuality where x.PersonId == rowID select x; //if (q.Count() > 0) //{ // content += "人员资质中已存在该人员,无法删除!"; //} if (string.IsNullOrEmpty(content)) { return true; } else { if (isShow) { Alert.ShowInTop(content); } return false; } } #endregion } }