using BLL; using System; using System.Collections.Generic; using System.Data; using System.Data.SqlClient; namespace FineUIPro.Web.Customization.CNCEC4.HSSE.Report { public partial class PersonnelAllocationInfo : PageBase { #region 项目主键 /// /// 项目主键 /// 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 = 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.ProjectId)) { this.panelLeftRegion.Hidden = true; ////权限按钮方法 //this.GetButtonPower(); } this.ddlPageSize.SelectedValue = Grid1.PageSize.ToString(); // 绑定表格 this.BindGrid(); this.txtMonth.Text = string.Format("{0:yyyy-MM}", DateTime.Now); } } /// /// 公司级树加载 /// /// /// protected void changeTree(object sender, EventArgs e) { this.ProjectId = this.ucTree.ProjectId; if (string.IsNullOrEmpty(this.CurrUser.LoginProjectId)) { btnNew.Hidden = true; } //this.GetButtonPower(); this.BindGrid(); } #region 绑定数据 /// /// 绑定数据 /// private void BindGrid() { if (string.IsNullOrEmpty(this.ProjectId)) { return; } string strSql = @"SELECT report.ReportId, report.Months, report.UnitId, unit.UnitName, report.ProjectId, project.ProjectName, report.Duties, report.PersonName, report.Telephone, report.EmergentTel, report.IdentityCard, report.Sex, report.Education, report.Major, report.YearsOfService, report.Qualification, report.PersonStates, report.Remark, report.CompileDate" + @" FROM dbo.Report_PersonnelAllocationInfo as report" + @" LEFT JOIN dbo.Base_Project as project on project.projectId = report.ProjectId" + @" LEFT JOIN dbo.Base_Unit as unit on unit.UnitId = report.UnitId" + @" WHERE report.ProjectId= @ProjectId "; List listStr = new List(); listStr.Add(new SqlParameter("@ProjectId", this.ProjectId)); 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(); } /// /// 改变索引事件 /// /// /// protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e) { BindGrid(); } /// /// 分页下拉选择事件 /// /// /// protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e) { Grid1.PageSize = Convert.ToInt32(ddlPageSize.SelectedValue); BindGrid(); } /// /// 排序 /// /// /// protected void Grid1_Sort(object sender, FineUIPro.GridSortEventArgs e) { BindGrid(); } /// /// 关闭弹出窗口 /// /// /// protected void Window1_Close(object sender, EventArgs e) { BindGrid(); } #endregion #endregion #region 增加按钮事件 /// /// 增加按钮事件 /// /// /// protected void btnNew_Click(object sender, EventArgs e) { if (GetButtonPower(Const.BtnAdd)) { var report = BLL.PersonnelAllocationInfoService.GetReportByMonth(this.ProjectId, this.txtMonth.Text.Trim()); if (report != null) { Alert.ShowInTop("本月月报已存在!", MessageBoxIcon.Warning); return; } else { PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("PersonnelAllocationInfoEdit.aspx?monts={0}", string.Format("{0:yyyy-MM}", this.txtMonth.Text.Trim()), "新增 - "))); } } else { Alert.ShowInTop("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning); return; } } #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; } if (GetButtonPower(Const.BtnModify)) { PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("PersonnelAllocationInfoEdit.aspx?reportId={0}", Grid1.SelectedRowID, "编辑 - "))); } else { Alert.ShowInTop("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning); return; } } #endregion #region 删除 /// /// 右键删除事件 /// /// /// protected void btnMenuDelete_Click(object sender, EventArgs e) { if (GetButtonPower(Const.BtnDelete)) { if (Grid1.SelectedRowIndexArray.Length > 0) { string strShowNotify = string.Empty; foreach (int rowIndex in Grid1.SelectedRowIndexArray) { string rowID = Grid1.DataKeys[rowIndex][0].ToString(); var getReport = BLL.PersonnelAllocationInfoService.GetReportById(rowID); if (getReport != null) { string cont = judgementDelete(rowID); if (string.IsNullOrEmpty(cont)) { BLL.PersonnelAllocationInfoService.DeleteReportById(rowID); } else { strShowNotify += "专职安全管理人员配备信息" + ":" + getReport.PersonName + cont; } } } BindGrid(); if (!string.IsNullOrEmpty(strShowNotify)) { Alert.ShowInTop(strShowNotify, MessageBoxIcon.Warning); } else { ShowNotify("删除成功!", MessageBoxIcon.Success); } } } else { Alert.ShowInTop("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning); return; } } #region 判断是否可删除 /// /// 判断是否可以删除 /// /// private string judgementDelete(string id) { string content = string.Empty; //if (Funs.DB.Pipeline_WeldJoint.FirstOrDefault(x => x.PipeAssembly1Id == id) != null) //{ // content += "已在【焊口信息】中使用,不能删除!"; //} return content; } #endregion #endregion #region 获取按钮权限 /// /// 获取按钮权限 /// /// /// private bool GetButtonPower(string button) { return BLL.CommonService.GetAllButtonPowerList(this.ProjectId, this.CurrUser.UserId, BLL.Const.PersonnelAllocationInfoMenuId, button); } #endregion } }