using System; using System.Collections.Generic; using System.Data; using System.Text; using System.Threading; using CMSC.Class; using CMSC.Class.CsSubs; using CMSC.OA.Dal.Sys.Base; using CMSC.OA.Dal.Sys.Sys; using CMSC.OA.Model.Sys.Sys; using CMSC.OA.Web.Com.Class; namespace CMSC.OA.Web.Com.Select { public partial class SelectUser_List : CsPageSingle { private int PageNo = 1; private int PageSize = 100; private string SysCode = ""; private string SearchMode = ""; private string SysCode2 = ""; private string PageFrame = ""; private string BackObject = ""; private string BackEvent = ""; private string BackRow = ""; private string JobCode = ""; private string UserCode = ""; private string UserName = ""; private string TrueName = ""; private string Contact = ""; private string UserFlag = ""; private string IsSysUser = ""; private D_Sys_User dal = new D_Sys_User(); private D_Sys_Org dal2 = new D_Sys_Org(); protected void Page_Load(object sender, EventArgs e) { try { this.PagePermit = "FreeView"; this.LoginUser = Com_Sys.GetLoginUser(PageCookie); this.PageLoadData(); this.AddScriptFile("table.js"); this.CreatePage(); } catch (ThreadAbortException) { } catch (Exception ex) { LoadTip.TipText = ex.Message; LoadTip.CloseLayer("SelectUser"); Response.Write(LoadTip.SetScriptHtml()); Response.End(); } } #region 页面加载 private void PageLoadData() { #region PageLoadData if (Request["pageframe"] == null || Request["pageframe"].ToString().Trim() == "") throw new Exception("获取Request参数数据为Null或空值"); if (Request["obj"] == null || Request["obj"].ToString().Trim() == "") throw new Exception("获取Request参数数据为Null或空值"); if (Request["fn"] == null || Request["fn"].ToString().Trim() == "") throw new Exception("获取Request参数数据为Null或空值"); if (Request["searchmode"] != null && Request["searchmode"].ToString().Trim() != "") SearchMode = Request["searchmode"].ToString().Trim(); if (Request["syscode2"] != null && Request["syscode2"].ToString().Trim() != "") SysCode2 = Request["syscode2"].ToString().Trim(); if (Request["syscode"] != null && Request["syscode"].ToString().Trim() != "") SysCode = Request["syscode"].ToString().Trim(); if (Request["jobcode"] != null && Request["jobcode"].ToString().Trim() != "") JobCode = Request["jobcode"].ToString().Trim(); if (Request["usercode"] != null && Request["usercode"].ToString().Trim() != "") UserCode = Request["usercode"].ToString().Trim(); if (Request["username"] != null && Request["username"].ToString().Trim() != "") UserName = Request["username"].ToString().Trim(); if (Request["truename"] != null && Request["truename"].ToString().Trim() != "") TrueName = Request["truename"].ToString().Trim(); if (Request["contact"] != null && Request["contact"].ToString().Trim() != "") Contact = Request["contact"].ToString().Trim(); if (Request["userflag"] != null && Request["userflag"].ToString().Trim() != "") UserFlag = Request["userflag"].ToString().Trim(); if (Request["issysuser"] != null && Request["issysuser"].ToString().Trim() != "") IsSysUser = Request["issysuser"].ToString().Trim(); PageFrame = Request["pageframe"].ToString().Trim(); BackObject = Request["obj"].ToString().Trim(); BackEvent = Request["fn"].ToString().Trim(); BackRow = Request["row"].ToString().Trim(); #endregion } protected override StringBuilder SetEndHtml() { #region SetEndHtml StringBuilder html = new StringBuilder(); ContextMenu cm = new ContextMenu(); cm.AddMenu("mlink", "刷新列表", "refuseUserList();"); html.Append(cm.BoxHtml()); HiddenForm sf = new HiddenForm(0, "SearchForm", "get"); sf.AddFormItem("pageframe", PageFrame); sf.AddFormItem("obj", BackObject); sf.AddFormItem("fn", BackEvent); sf.AddFormItem("row", BackRow); sf.AddFormItem("syscode", SysCode); sf.AddFormItem("page", ""); html.Append(sf.BoxHtml()); HiddenForm hf = new HiddenForm(0, "PostBackForm", "post"); hf.Action = "SelectUser_List.aspx"; hf.Target = "HiddenFrame"; hf.AddFormItem("pageframe", PageFrame); hf.AddFormItem("obj", BackObject); hf.AddFormItem("fn", BackEvent); hf.AddFormItem("row", BackRow); hf.AddFormItem("syscode", SysCode); hf.AddFormItem("userids", ""); hf.AddFormItem("delflag", ""); html.Append(hf.BoxHtml()); return html; #endregion } protected override StringBuilder EndScript() { #region EndScript StringBuilder js = new StringBuilder(); js.Append(@"var CMSCTableView = new CMSC.TableView();"); js.Append(@"function selectUser(userstrs) {"); js.Append(@"if(CMSCTableView.CheckRowSelect()) {"); js.Append(@"var datakey = CMSC.$$(""SelectDataKey"").value;"); js.Append(@"var win = rootElement.CMSC.$$(""" + PageFrame + @""").contentWindow;"); js.Append(@"win." + BackEvent + @"('" + BackObject + @"',userstrs,'" + BackRow + @"');"); js.Append(@"rootElement.CMSC.FrameLayerClose(""SelectUser"");"); js.Append(@"}"); js.Append(@"}"); js.Append(@"function addUser() {"); js.Append(@"var layer = rootElement.CMSC.$$(""LayerForm"");"); js.Append(@"layer.LayerId.value = ""AddUser"";"); js.Append(@"layer.Permit.value = ""Sys_Base_User_Add"";"); js.Append(@"layer.LayerTitle.value = ""添加一名新员工"";"); js.Append(@"layer.CanMax.value = false;"); js.Append(@"layer.LayerUrl.value = ""/Sys/Base/User_Add.aspx?select=1&syscode=" + SysCode + @""";"); js.Append(@"layer.Padding.value = 20;"); js.Append(@"layer.LayerWidth.value = 640;"); js.Append(@"layer.LayerHeight.value = 430;"); js.Append(@""); js.Append(@"layer.submit();"); js.Append(@"}"); js.Append(@"function editUser() {"); js.Append(@"if(CMSCTableView.CheckRowSelect()) {"); js.Append(@"var datakey = CMSC.$$(""SelectDataKey"").value;"); js.Append(@"var layer = rootElement.CMSC.$$(""LayerForm"");"); js.Append(@"layer.LayerId.value = ""EditUser"";"); js.Append(@"layer.Permit.value = ""Sys_Base_User_Edit"";"); js.Append(@"layer.LayerTitle.value = ""修改员工信息"";"); js.Append(@"layer.CanMax.value = false;"); js.Append(@"layer.LayerUrl.value = ""/Sys/Base/User_Edit.aspx?select=1&userid=""+datakey;"); js.Append(@"layer.Padding.value = 20;"); js.Append(@"layer.LayerWidth.value = 640;"); js.Append(@"layer.LayerHeight.value = 430;"); js.Append(@""); js.Append(@"layer.submit();"); js.Append(@"}"); js.Append(@"}"); js.Append(@"function delUser() {"); js.Append(@"if(CMSCTableView.CheckRowSelect()) {"); js.Append(@"if(confirm(""确认将选中的员工帐号禁用吗?"")){"); js.Append(@"var subform = CMSC.$$(""PostBackForm"");"); js.Append(@"var datakey = CMSC.$$(""SelectDataKeys"").value;"); js.Append(@"if (datakey=='') datakey = CMSC.$$(""SelectDataKey"").value;"); js.Append(@"subform.subflag.value = 1;"); js.Append(@"subform.userids.value = datakey;"); js.Append(@"subform.submit();"); js.Append(@"}"); js.Append(@"}"); js.Append(@"}"); js.Append(@"function toPage(page){"); js.Append(@"var subform = CMSC.$$(""SearchForm"");"); js.Append(@"subform.subflag.value = 0;"); js.Append(@"subform.page.value = page;"); js.Append(@"subform.submit();"); js.Append(@"}"); js.Append(Com_Sys.TreeClickScript()); js.Append(@"function refuseUserList(){"); js.Append(@"this.location.href = ""SelectUser_List.aspx?pageframe=" + PageFrame + @"&obj=" + BackObject + @"&fn=" + BackEvent + @"&row=" + BackRow + @"&syscode=" + SysCode + @""";"); js.Append(@"}"); return js; #endregion } #endregion #region 显示表格 protected override StringBuilder SetHtml() { #region SetHtml StringBuilder html = new StringBuilder(); TableView tv = new TableView(); List<M_Sys_Field> celllist = new D_Sys_Sys().GetSysFieldModelList(LoginUser.UserId, "ComSelectUser"); if (celllist == null || celllist.Count <= 0) throw new Exception("无法获取数据显示结构信息。"); foreach (M_Sys_Field cell in celllist) tv.AddHeaderColumn(cell.FieldName.Trim(), cell.IsLock, cell.Width); string filtersql = ""; if (SearchMode.Trim() == "") { filtersql += "a.SysCode='" + SysCode.Replace("'", "") + "' "; } else { if (SysCode2.Trim() != "" || JobCode.Trim() != "" || UserCode.Trim() != "" || UserName.Trim() != "" || TrueName.Trim() != "" || Contact.Trim() != "" || UserFlag.Trim() != "" || IsSysUser.Trim() != "") { filtersql += "(1=1 "; if (SysCode2.Trim() != "") filtersql += "and a.SysCode like '" + SysCode2.Replace("'", "") + "%' "; if (JobCode.Trim() != "") filtersql += "and a.JobCode='" + JobCode.Replace("'", "") + "' "; if (UserCode.Trim() != "") filtersql += "and a.UserCode='" + UserCode.Replace("'", "") + "' "; if (UserName.Trim() != "") filtersql += "and a.UserName like '%" + UserName.Replace("'", "") + "%' "; if (TrueName.Trim() != "") filtersql += "and a.TrueName like '%" + TrueName.Replace("'", "") + "%' "; if (Contact.Trim() != "") filtersql += "and a.Contact='" + Contact.Replace("'", "") + "' "; if (UserFlag.Trim() != "") filtersql += "and a.UserFlag=" + Convert.ToInt16(UserFlag); if (IsSysUser.Trim() != "") filtersql += "and a.IsSysUser=" + Convert.ToInt16(IsSysUser); filtersql += ")"; } } tv.SelectRows = false; tv.ShowIndex = true; tv.IndexColumnWidth = 50; tv.RowKeys = "UserId"; tv.PageNo = PageNo; tv.PageSize = PageSize; tv.FilterSql = filtersql; tv.OrderSql = "order by pdb.SysCode,pdb.SortCode asc"; tv.RowCount = dal.GetTableViewRowCount(tv); int rowindex = 1; DataSet ds = dal.GetTableViewPageDataSet(tv); foreach (DataRow dr in ds.Tables[0].Rows) { tv.AddRowBegin(rowindex, dr); foreach (M_Sys_Field cell in celllist) LoadTableViewRow(tv, cell, dr); tv.AddRowEnd(); rowindex++; } return tv.BoxHtml(); #endregion } private void LoadTableViewRow(TableView tv, M_Sys_Field cell, DataRow dr) { #region LoadTableViewRow string lockstr = (cell.IsLock == 0 ? "" : " lockcell"); switch (cell.FieldValue.Trim()) { case "UserCode": tv.AddRowColumn(dr["UserCode"].ToString().Trim(), "left" + lockstr); break; case "UserName": string uname = " "; if (dr["UserName"].ToString().Trim() != "") uname = dr["UserName"].ToString().Trim(); tv.AddRowColumn(uname, "left" + lockstr); break; case "TrueName": tv.AddRowColumn(dr["TrueName"].ToString().Trim(), "left" + lockstr); break; case "Select": string aLink = @"<a href=""javascript:selectUser('" + dr["UserId"].ToString().Trim() + @"|" + dr["TrueName"].ToString().Trim() + @"|" + dr["SysCode"].ToString().Trim() + @"|" + dr["OrgName"].ToString().Trim() + @"|" + dr["Contact"].ToString().Trim() + @"');"">选择</a>"; tv.AddRowColumn(aLink, "center" + lockstr); break; } #endregion } #endregion #region 回调函数 protected override string PostCheckInput(int subflag) { #region PostCheckInput if (!CsClass.CheckParame(new string[] { Request.Form["syscode"], Request.Form["userids"] })) { return "在接收的数据中检测到异常的空值!"; } else { return ""; } #endregion } protected override SaveResult PostSave(int subflag) { #region PostSave try { if (subflag == 1) { string UserIdList = Request.Form["userids"].ToString().Trim(); int ExecuteRows = dal.ModifyUserByUserIdList(UserIdList, 1, this.GetSysCodeByPagePermit("Sys_Base_User_Del")); if (ExecuteRows >= 1 ? true : false) { SaveTip.IsOk = true; SaveTip.TipText = "已成功禁用了【" + ExecuteRows + "】名员工!"; SaveTip.RefuseFrame("SelectUserFrame", "ListFrame"); return SaveTip; } else { SaveTip.IsOk = false; SaveTip.TipText = "禁用员工异常失败!"; return SaveTip; } } return null; } catch (Exception ex) { SaveTip.IsOk = false; SaveTip.TipText = ex.Message; return SaveTip; } #endregion } #endregion } }