private void BindGrid() { if (roleId > 0) { try { StringBuilder condition = new StringBuilder("WHERE U_DISABLED=0"); //去除用户为系统管理员 condition.AppendFormat(" AND (SELECT COUNT(*) AS num FROM [S_ROLE_USER] b WHERE b.U_ID=a.U_ID AND R_ID={0})=0", roleId); string name = StringHelper.ClearSqlStringExSpace(ttbSearchUser.Text.Trim()); if (name.Length > 0) { condition.AppendFormat(" AND (U_NAME like'%{0}%' OR U_REALNAME like'%{0}%')", name); } int recordCount = 0; using (DataTable dt = SqlPagerHelper.GetTableByCondition(DefaultConnection.ConnectionStringByDefaultDB, "U_ID,U_NAME,U_REALNAME,U_EMAIL,U_MOBILE", "[S_USER] a", condition.ToString(), "ORDER BY U_ID ASC", Grid1.PageIndex + 1, Grid1.PageSize, out recordCount)) { Grid1.RecordCount = recordCount; Grid1.DataSource = dt; Grid1.DataBind(); } } catch (Exception ex) { logger.Error("S.R.AddUser.BindGrid():Exception", ex); Alert.ShowInParent("系统错误。"); } // 重新绑定表格数据之后,更新选中行 FineUIGridCommon.UpdateSelectedRowIndexArray(hfSelectedIDS, Grid1); } else { // 参数错误,首先弹出Alert对话框然后关闭弹出窗口 Alert.Show("参数错误!", String.Empty, ActiveWindow.GetHideReference()); } }
//页面数据加载 private void BindData() { try { StringBuilder condition = new StringBuilder(); if (string.IsNullOrEmpty(this.ttbSearchUser.Text)) { condition.Append(""); } else { condition.Append(" where CName like'%" + this.ttbSearchUser.Text + "%' "); } int recordCount = 0; using (DataTable dt = SqlPagerHelper.GetTableByCondition(DefaultConnection.ConnectionStringByDefaultDB, "*", "[view_person]", condition.ToString(), "ORDER BY CName asc", Grid1.PageIndex + 1, Grid1.PageSize, out recordCount)) { Grid1.RecordCount = recordCount; Grid1.DataSource = dt; Grid1.DataBind(); FineUIGridCommon.UpdateSelectedRowIndexArray(hides, Grid1); } } catch (Exception ex) { logger.Error("X.MessageList.BindData():Exception", ex); Alert.ShowInParent("系统错误。"); } }
// 行事件 protected void GridChoose_RowCommand(object sender, GridCommandEventArgs e) { if (e.CommandName == "Delete") { string keyid = GridChoose.Rows[e.RowIndex].Values[0].ToString(); var id = hides.Text.Replace("[", "").Replace("]", "").Replace("\"", "").Split(',').ToList(); var name = hidename.Text.Replace("[", "").Replace("]", "").Replace("\"", "").Split(',').ToList(); for (int i = 0; i < id.Count; i++) { if (id[i].ToString() == keyid) { id.RemoveAt(i); name.RemoveAt(i); } } if (hides.Text.Length > 10)//有选择人的数据 { if (id.Count > 0) { string newhides = "["; string newhidename = "["; for (int i = 0; i < id.Count; i++) { newhides += "\"" + id[i].ToString() + "\","; newhidename += "\"" + name[i].ToString() + "\","; } newhides = newhides.Substring(0, newhides.Length - 1); newhidename = newhidename.Substring(0, newhidename.Length - 1); newhides += "]"; newhidename += "]"; hides.Text = newhides; hidename.Text = newhidename; } else { hides.Text = ""; hidename.Text = ""; } } FineUIGridCommon.UpdateSelectedRowIndexArray(hides, Grid1); FineUIGridCommon.SyncSelectedRowIndexArrayToHiddenField(hides, hidename, Grid1); BindData(); LoadGridChoose(); } }
//编辑状态加载数据 private void LoadInfo() { string type = RequestHelper.GetRequestString("id", ""); txttype = type; this.Panel7.Title = "新增"; if (!string.IsNullOrEmpty(type)) { this.Panel7.Title = "修改"; DataTable dt = operate.GetRecommendByTypeName(type); if (dt != null && dt.Rows.Count > 0) { this.txtTypeName.Readonly = true; this.txtTypeName.Text = HttpUtility.HtmlDecode(dt.Rows[0]["TypeName"].ToString()); this.chkFlag.Checked = Convert.ToBoolean(dt.Rows[0]["Flag"]); var id = HttpUtility.HtmlDecode(dt.Rows[0]["PersonID"].ToString()).Split(','); var name = HttpUtility.HtmlDecode(dt.Rows[0]["PersonName"].ToString()).Split(','); string newhides = "["; string newhidename = "["; for (int i = 0; i < id.Length; i++) { newhides += "\"" + id[i].ToString() + "\","; newhidename += "\"" + name[i].ToString() + "\","; } newhides = newhides.Substring(0, newhides.Length - 1); newhidename = newhidename.Substring(0, newhidename.Length - 1); newhides += "]"; newhidename += "]"; hides.Text = newhides; hidename.Text = newhidename; FineUIGridCommon.UpdateSelectedRowIndexArray(hides, Grid1); FineUIGridCommon.SyncSelectedRowIndexArrayToHiddenField(hides, hidename, Grid1); //BindData(); LoadGridChoose(); } else { Alert.ShowInParent("读取数据失败!", String.Empty, ActiveWindow.GetHideReference()); } } }