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 ddlPageSize_SelectedIndexChanged(object sender, EventArgs e) { FineUIGridCommon.SyncSelectedRowIndexArrayToHiddenField(hides, hidename, Grid1); Grid1.PageSize = Convert.ToInt32(ddlPageSize.SelectedValue); Grid1.PageIndex = 0; BindData(); }
protected void btnDeleteSelected_Click(object sender, EventArgs e) { //删除权限 if (!VerifyPurview(",SR-DELUSER,")) { Alert.ShowInParent(CHECK_POWER_FAIL_ACTION_MESSAGE); return; } if (roleId > 0) { DeleteTip(new UserRoleBLL().BatchDelete(roleId, FineUIGridCommon.GetSelectedDataKeyToIndex(gridUser, 0))); } }
protected void btnSaveClose_Click(object sender, EventArgs e) { if (!VerifyPurview(",SR-ADDUSER,")) { Alert.ShowInParent(CHECK_POWER_FAIL_ACTION_MESSAGE); return; } if (roleId > 0) { SyncSelectedRowIndexArrayToHiddenField(); List <string> ids = FineUIGridCommon.GetSelectedIDsFromHiddenField(hfSelectedIDS); if (ids != null && ids.Count > 0) { int result = 0; using (DataTable dt = new DataTable()) { dt.Columns.Add("roleid", typeof(int)); dt.Columns.Add("userid", typeof(int)); foreach (string userid in ids) { DataRow dr = dt.NewRow(); dr[0] = roleId; dr[1] = userid; dt.Rows.Add(dr); } result = new UserRoleBLL().BatchSave(dt); } if (result > 0) { PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference()); } else { Alert.ShowInParent("添加角色用户失败!"); } } else { PageContext.RegisterStartupScript(ActiveWindow.GetHideReference()); } } else { // 参数错误,首先弹出Alert对话框然后关闭弹出窗口 Alert.Show("参数错误!", String.Empty, ActiveWindow.GetHideReference()); } }
// 行事件 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()); } } }
private void SyncSelectedRowIndexArrayToHiddenField() { // 重新绑定表格数据之前,将当前表格页选中行的数据同步到隐藏字段中 FineUIGridCommon.SyncSelectedRowIndexArrayToHiddenField(hfSelectedIDS, Grid1); }
// 确认事件 protected void btnSubmit_Click(object sender, EventArgs e) { FineUIGridCommon.SyncSelectedRowIndexArrayToHiddenField(hides, hidename, Grid1); LoadGridChoose(); }
protected void Grid1_PageIndexChange(object sender, FineUI.GridPageEventArgs e) { FineUIGridCommon.SyncSelectedRowIndexArrayToHiddenField(hides, hidename, Grid1); Grid1.PageIndex = e.NewPageIndex; BindData(); }
private void LoadData() { FineUIGridCommon.ResolveDeleteButtonForGrid(btnDeleteSelected, gridUser, "确定要从当前角色中移除选中的{0}项记录吗?"); BindUser(); }