protected void gridUsers_RowUpdating(object sender, DevExpress.Web.Data.ASPxDataUpdatingEventArgs e) { try { SessionManager.IsEditFormCreated = false; int keyToUpdate = int.Parse(e.Keys[0].ToString()); //update user User cc = this.CollectNewDataFromForm(keyToUpdate, e.OldValues, e.NewValues, false); BuUser.UpdateUser(cc, e.OldValues["UserName"].ToString()); //update rights List <int> selectedRights = GetRightsFromList(); foreach (KeyValuePair <int, int> pair in SessionManager.CheckBoxListHelper) { BuUser.UpdateRightsRelation(keyToUpdate, pair.Value, selectedRights.Contains(pair.Key)); } e.Cancel = true; gridUsers.CancelEdit(); this.BindData(); } catch (Exception ex) { Logger.Log(string.Format("exception {0}", ex.ToString()), LogLevel.Error); } }
protected void gridUsers_RowInserting(object sender, DevExpress.Web.Data.ASPxDataInsertingEventArgs e) { try { SessionManager.IsEditFormCreated = false; //insert user User cc = this.CollectNewDataFromForm(0, null, e.NewValues, true); int insertedId = BuUser.InsertUser(cc); //update rights List <int> selectedRights = GetRightsFromList(); foreach (KeyValuePair <int, int> pair in SessionManager.CheckBoxListHelper) { BuUser.UpdateRightsRelation(insertedId, pair.Value, selectedRights.Contains(pair.Key)); } e.Cancel = true; gridUsers.CancelEdit(); this.BindData(); } catch (Exception ex) { Logger.Log(string.Format("exception {0}", ex.ToString()), LogLevel.Error); } }
protected void gridUsers_RowDeleting(object sender, DevExpress.Web.Data.ASPxDataDeletingEventArgs e) { try { BuUser.DeleteUserById(int.Parse(e.Keys[0].ToString())); e.Cancel = true; gridUsers.CancelEdit(); this.BindData(); } catch (Exception ex) { Logger.Log(string.Format("exception {0}", ex.ToString()), LogLevel.Error); } }
/// <summary> /// Handler for general callback event (filtering, bulk deleting) /// </summary> /// <param name="source"></param> /// <param name="e"></param> protected void clbPanelUsers_Callback(object source, DevExpress.Web.ASPxClasses.CallbackEventArgsBase e) { try { if (string.IsNullOrEmpty(e.Parameter)) { List <object> keyValues = gridUsers.GetSelectedFieldValues("UserId"); foreach (object key in keyValues) { BuUser.DeleteUserById(int.Parse(key.ToString())); } } this.BindData(); } catch (Exception ex) { Logger.Log(string.Format("exception {0}", ex.ToString()), LogLevel.Error); } }
protected void gridUsers_HtmlEditFormCreated(object sender, ASPxGridViewEditFormEventArgs e) { // this.LocalizeEditForm(e.EditForm); ASPxTextBox username = (ASPxTextBox)gridUsers.FindEditFormTemplateControl("txtEfUsername"); if (username != null) { username.Focus(); } if ((!SessionManager.IsEditFormCreated) || (EditFormHasErrors)) { CanonDataContext db = Cdb.Instance; //init user rights checkbox list CheckBoxList cbl = (CheckBoxList)gridUsers.FindEditFormTemplateControl("chblUserRights"); if (cbl != null) { int counter = 0; cbl.Items.Clear(); SessionManager.CheckBoxListHelper = new Dictionary <int, int>(5); Dictionary <UserRightsEnum, string> list = BuUser.GetAllRightsList(); foreach (KeyValuePair <UserRightsEnum, string> pair in list) { int pairKey = (int)pair.Key; cbl.Items.Add(new ListItem(pair.Value, pairKey.ToString())); SessionManager.CheckBoxListHelper.Add(counter, pairKey); counter++; } } //initialize listbox and checkboxlist if anything exists if ((!gridUsers.IsNewRowEditing) && (!EditFormHasErrors)) { //combo/list initialization if needed object value = gridUsers.GetRowValues(gridUsers.EditingRowVisibleIndex, new String[] { "UserId" }); int idToEdit = int.Parse(value.ToString()); //checkbox list init if (cbl != null) { Dictionary <UserRightsEnum, string> list = BuUser.GetRightsList(idToEdit); foreach (ListItem li in cbl.Items) { foreach (KeyValuePair <UserRightsEnum, string> pair in list) { if (li.Value == ((int)pair.Key).ToString()) { li.Selected = true; } } } } } if (EditFormHasErrors) { //rights if (cbl != null) { string[] values = SelectedRights.Split(';'); foreach (string val in values) { string[] item = val.Split('='); if (item.Length != 2) { continue; } foreach (ListItem li in cbl.Items) { if ((li.Value == item[0]) && (item[1] == "1")) { li.Selected = true; } } } } } Control popupCtrl = gridUsers.FindEditFormTemplateControl("popupChangePassword"); if (popupCtrl != null) { Control changeCtrl = popupCtrl.FindControl("changePasswordCtrl"); if (changeCtrl != null && changeCtrl is AdminChangePassword) { object row = gridUsers.GetRow(gridUsers.EditingRowVisibleIndex); if (row != null && row is User) { int userID = (row as User).UserId; (changeCtrl as AdminChangePassword).SetUserId(userID); } } } SessionManager.IsEditFormCreated = true; } }