using BLL; using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Web.UI.WebControls; namespace FineUIPro.Web.BaseInfo { public partial class WorkPostCleanupMerge : PageBase { protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { this.btnClose.OnClientClick = ActiveWindow.GetHideReference(); ////权限按钮方法 this.GetButtonPower(); BindGrid(); BindGrid2(); } } #region 加载合并后的岗位 /// /// 加载合并后的岗位 /// private void BindGrid() { var pType = (from x in Funs.DB.Sys_Const where x.GroupId == ConstValue.Group_PostType select x); var list = (from x in Funs.DB.Base_WorkPost join y in pType on x.PostType equals y.ConstValue into yGroup from y in yGroup.DefaultIfEmpty() orderby x.WorkPostName descending select new { x.WorkPostId, x.WorkPostName, x.WorkPostCode, x.IsHsse, x.IsCQMS, x.PostType, IsHsseStr = x.IsHsse == true ? "是" : "否", IsCQMSStr = x.IsCQMS == true ? "是" : "否", PostTypeName = y.ConstText, x.Remark }).ToList(); string codeName = ttbWorkPostNameCodeSearch.Text.Trim(); if (!string.IsNullOrWhiteSpace(codeName)) { list = list.Where(x => (!string.IsNullOrWhiteSpace(x.WorkPostName) && x.WorkPostName.Contains(codeName)) || (!string.IsNullOrWhiteSpace(x.WorkPostCode) && x.WorkPostCode.Contains(codeName))).ToList(); } // 1.设置总项数(特别注意:数据库分页一定要设置总记录数RecordCount) Grid1.RecordCount = list.Count(); // 2.获取当前分页数据 DataTable table = Funs.LINQToDataTable(list); // 3.绑定到Grid //Grid1.DataSource = table; Grid1.DataSource = this.GetPagedDataTable(Grid1, table); Grid1.DataBind(); } /// /// /// /// /// protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e) { BindGrid(); } protected void Grid1_Sort(object sender, GridSortEventArgs e) { BindGrid(); } protected void ttbWorkPostNameCodeSearch_Trigger1Click(object sender, EventArgs e) { ttbWorkPostNameCodeSearch.Text = string.Empty; ttbWorkPostNameCodeSearch.ShowTrigger1 = false; BindGrid(); } protected void ttbWorkPostNameCodeSearch_Trigger2Click(object sender, EventArgs e) { ttbWorkPostNameCodeSearch.ShowTrigger1 = true; BindGrid(); } /// /// /// /// /// protected void TextBox_TextChanged(object sender, EventArgs e) { BindGrid(); } #endregion #region 加载需要合并的岗位 /// /// 加载需要合并的岗位 /// private void BindGrid2() { var pType = (from x in Funs.DB.Sys_Const where x.GroupId == ConstValue.Group_PostType select x); var list = (from x in Funs.DB.Base_WorkPost join y in pType on x.PostType equals y.ConstValue into yGroup from y in yGroup.DefaultIfEmpty() orderby x.WorkPostName descending select new { x.WorkPostId, x.WorkPostName, x.WorkPostCode, x.IsHsse, x.IsCQMS, x.PostType, IsHsseStr = x.IsHsse == true ? "是" : "否", IsCQMSStr = x.IsCQMS == true ? "是" : "否", PostTypeName = y.ConstText, x.Remark }).ToList(); string workPostId = this.drpWorkPostBox.Value; if (!string.IsNullOrWhiteSpace(workPostId)) { list = list.Where(x => x.WorkPostId != workPostId).ToList(); } string codeName = ttbMergeWorkPostNameCodeSearch.Text.Trim(); if (!string.IsNullOrWhiteSpace(codeName)) { list = list.Where(x => (!string.IsNullOrWhiteSpace(x.WorkPostName) && x.WorkPostName.Contains(codeName)) || (!string.IsNullOrWhiteSpace(x.WorkPostCode) && x.WorkPostCode.Contains(codeName))).ToList(); } // 1.设置总项数(特别注意:数据库分页一定要设置总记录数RecordCount) Grid2.RecordCount = list.Count(); // 2.获取当前分页数据 DataTable table = Funs.LINQToDataTable(list); // 3.绑定到Grid //Grid2.DataSource = table; Grid2.DataSource = this.GetPagedDataTable(Grid2, table); Grid2.DataBind(); } /// /// /// /// /// protected void Grid2_PageIndexChange(object sender, GridPageEventArgs e) { BindGrid2(); } protected void Grid2_Sort(object sender, GridSortEventArgs e) { BindGrid2(); } protected void ttbMergeWorkPostNameCodeSearch_Trigger1Click(object sender, EventArgs e) { ttbMergeWorkPostNameCodeSearch.Text = string.Empty; ttbMergeWorkPostNameCodeSearch.ShowTrigger1 = false; BindGrid2(); } protected void ttbMergeWorkPostNameCodeSearch_Trigger2Click(object sender, EventArgs e) { ttbMergeWorkPostNameCodeSearch.ShowTrigger1 = true; BindGrid2(); } /// /// /// /// /// protected void MergeTextBox_TextChanged(object sender, EventArgs e) { BindGrid2(); } #endregion /// /// 保存按钮 /// /// /// protected void btnSave_Click(object sender, EventArgs e) { string workPostId = string.Empty; string workPostMergeId = string.Empty; string workPostName = string.Empty; string workPostMergeName = string.Empty; if (!string.IsNullOrWhiteSpace(this.drpWorkPostBox.Text)) { workPostId = this.drpWorkPostBox.Value.Trim(); workPostName = this.drpWorkPostBox.Text; } else { Alert.ShowInParent("请选择合并后岗位!", MessageBoxIcon.Warning); return; } if (!string.IsNullOrWhiteSpace(this.drpMergeWorkPostBox.Text)) { workPostMergeId = this.drpMergeWorkPostBox.Value.Trim(); workPostMergeName = this.drpMergeWorkPostBox.Text; if (workPostMergeId == workPostId) { Alert.ShowInParent("两个岗位为同一个岗位,无需合并!", MessageBoxIcon.Warning); return; } } else { Alert.ShowInParent("请选择需要合并的岗位!", MessageBoxIcon.Warning); return; } List workPostMergeIds = workPostMergeId.Split(',').ToList(); workPostMergeIds = workPostMergeIds.Where(x => x != workPostId).ToList(); string msg = string.Empty; bool merge = DataCleanupMergeHelper.DataCleanupMerge("Base_WorkPost", "PostId", workPostMergeIds, workPostId, ref msg); if (merge) { string txtRemark = this.txtRemark.Text.Trim(); //其他数据表岗位数据合并后,删除岗位表冗余岗位 foreach (var mergeId in workPostMergeIds) { string wId = mergeId.Trim(); var workPost = BLL.WorkPostService.GetWorkPostById(wId); if (workPost != null) { WorkPostService.DeleteWorkPostById(wId); string op = $"岗位合并清理后,{Const.BtnDelete};备注:{txtRemark}"; LogService.AddSys_Log(this.CurrUser, workPost.WorkPostCode, workPost.WorkPostId, Const.WorkPostMenuId, op); } } } PageContext.RegisterStartupScript(ActiveWindow.GetHideRefreshReference()); } #region 获取按钮权限 /// /// 获取按钮权限 /// /// /// private void GetButtonPower() { if (this.CurrUser.UserId == Const.sysglyId || this.CurrUser.UserId == Const.hfnbdId || this.CurrUser.UserId == Const.fuweiId || this.CurrUser.UserId == Const.shenyinhangId) {//系统管理员、合肥诺必达、付伟、申银行 this.btnSave.Hidden = false; } } #endregion } }