public AppUserForm() { InitializeComponent(); this.Text = "用户管理"; //窗体关闭时dispose this.FormClosed += (s, e) => { if (bll != null) { bll.Dispose(); bll = null; } }; data = new Helpers.VirtualGridData <Models.AppUser> { Grid = this.vgMainGrid, LoadedCount = 0, PerLoadSize = 100 }; this.vgMainGrid.AutoSizeColumnsMode = VirtualGridAutoSizeColumnsMode.Fill;// this.vgMainGrid.EnableAlternatingRowColor = true; this.vgMainGrid.Selection.Multiselect = false; this.vgMainGrid.SelectionMode = VirtualGridSelectionMode.FullRowSelect; this.vgMainGrid.AllowAddNewRow = false; this.vgMainGrid.AllowEdit = false; this.vgMainGrid.FilterChanged += (s, e) => { Helpers.VirtualGridDataHelper.InitalLoad <Models.AppUser>(data); }; this.vgMainGrid.SortChanged += (s, e) => { Helpers.VirtualGridDataHelper.InitalLoad <Models.AppUser>(data); }; //表格删除时 this.vgMainGrid.UserDeletedRow += (s, e) => { DeleteEntry(); }; //双击编辑 this.vgMainGrid.CellDoubleClick += (s, e) => { var cell = this.vgMainGrid.CurrentCell; if (cell == null) { return; } if (cell.RowIndex < 0) { return; } var current = data.Data[cell.RowIndex]; AppUserAddEditForm form = new AppUserAddEditForm(); form.EditMode = Enums.EditFormMode.Edit; form.DataEntry = current; var dr = form.ShowDialog(this); if (dr == DialogResult.OK) { this.vgMainGrid.BeginUpdate(); data.Data[cell.RowIndex] = form.DataEntry; this.vgMainGrid.EndUpdate(); this.vgMainGrid.SelectCell(cell.RowIndex, cell.ColumnIndex); } }; //重置密码 this.btnResetPassword.Click += (s, e) => { var cell = this.vgMainGrid.CurrentCell; if (cell == null) { RadMessageBox.Show(this, "请选择一行!", "", MessageBoxButtons.OK, RadMessageIcon.Error); return; } if (cell.RowIndex < 0) { return; } var current = data.Data[cell.RowIndex]; var dr = RadMessageBox.Show(this, "密码将被重置为 888888,是否继续?", "", MessageBoxButtons.YesNo, RadMessageIcon.Question); if (dr == DialogResult.Yes) { int re = bll.Update <Models.AppUser>(current.Id, "Password", Helpers.EncryptDecryptHelper.GetStringMD5("888888")); if (re > 0) { RadMessageBox.Show(this, "密码已重置为 888888,请及时更改!", "", MessageBoxButtons.OK, RadMessageIcon.Info); } else { RadMessageBox.Show(this, "重置失败!", "", MessageBoxButtons.OK, RadMessageIcon.Error); } } }; //按钮编辑 this.btnEdit.Click += (s, e) => { var cell = this.vgMainGrid.CurrentCell; if (cell == null) { RadMessageBox.Show(this, "请选择一行!", "", MessageBoxButtons.OK, RadMessageIcon.Error); return; } if (cell.RowIndex < 0) { return; } var current = data.Data[cell.RowIndex]; AppUserAddEditForm form = new AppUserAddEditForm(); form.EditMode = Enums.EditFormMode.Edit; form.DataEntry = current; var dr = form.ShowDialog(this); //form.FormClosed += (ss, ee) => { Helpers.VirtualGridDataHelper.InitalLoad<Models.UserRole>(data, syncContext); }; if (dr == DialogResult.OK) { this.vgMainGrid.BeginUpdate(); data.Data[cell.RowIndex] = form.DataEntry; this.vgMainGrid.EndUpdate(); this.vgMainGrid.SelectCell(cell.RowIndex, cell.ColumnIndex); } }; this.btnReLoad.Click += (s, e) => { Helpers.VirtualGridDataHelper.InitalLoad <Models.AppUser>(data); }; this.btnAdd.Click += (s, e) => { AppUserAddEditForm form = new AppUserAddEditForm(); //form.StartPosition = FormStartPosition.WindowsDefaultLocation; form.EditMode = Enums.EditFormMode.Add; var dr = form.ShowDialog(this); if (dr == DialogResult.OK) { this.vgMainGrid.BeginUpdate(); this.data.Data.Insert(0, form.DataEntry); this.vgMainGrid.RowCount++; this.vgMainGrid.EndUpdate(); this.vgMainGrid.SelectCell(0, 0); } }; this.btnDelete.Click += (s, e) => { DeleteEntry(); }; Helpers.VirtualGridDataHelper.InitalLoad <Models.AppUser>(data); }
private void InitForm() { //窗体关闭时dispose this.FormClosed += (s, e) => { if (bll != null) { bll.Dispose(); bll = null; } }; data = new Helpers.VirtualGridData <Models.AppRole> { Grid = this.vgUserRoles, LoadedCount = 0, PerLoadSize = 100 }; this.Text = "角色管理"; this.vgUserRoles.AutoSizeColumnsMode = VirtualGridAutoSizeColumnsMode.Fill;// this.vgUserRoles.EnableAlternatingRowColor = true; this.vgUserRoles.Selection.Multiselect = false; this.vgUserRoles.SelectionMode = VirtualGridSelectionMode.FullRowSelect; this.vgUserRoles.AllowAddNewRow = false; //this.vgUserRoles.AllowDelete = false; this.vgUserRoles.AllowEdit = false; this.vgUserRoles.FilterChanged += (s, e) => { Helpers.VirtualGridDataHelper.InitalLoad <Models.AppRole>(data); }; this.vgUserRoles.SortChanged += (s, e) => { Helpers.VirtualGridDataHelper.InitalLoad <Models.AppRole>(data); }; //表格删除时 this.vgUserRoles.UserDeletedRow += (s, e) => { DeleteEntry(); }; //双击编辑 this.vgUserRoles.CellDoubleClick += (s, e) => { var cell = this.vgUserRoles.CurrentCell; if (cell == null) { return; } if (cell.RowIndex < 0) { return; } var current = data.Data[cell.RowIndex]; UserRolesAddEditForm form = new UserRolesAddEditForm(); form.EditMode = Enums.EditFormMode.Edit; form.UserRole = current; var dr = form.ShowDialog(this); if (dr == DialogResult.OK) { this.vgUserRoles.BeginUpdate(); data.Data[cell.RowIndex] = form.UserRole; this.vgUserRoles.EndUpdate(); this.vgUserRoles.SelectCell(cell.RowIndex, cell.ColumnIndex); } }; //按钮编辑 this.btnEdit.Click += (s, e) => { var cell = this.vgUserRoles.CurrentCell; if (cell == null) { RadMessageBox.Show(this, "请选择一行!", "", MessageBoxButtons.OK, RadMessageIcon.Error); return; } if (cell.RowIndex < 0) { return; } var current = data.Data[cell.RowIndex]; UserRolesAddEditForm form = new UserRolesAddEditForm(); form.EditMode = Enums.EditFormMode.Edit; form.UserRole = current; var dr = form.ShowDialog(this); //form.FormClosed += (ss, ee) => { Helpers.VirtualGridDataHelper.InitalLoad<Models.UserRole>(data, syncContext); }; if (dr == DialogResult.OK) { this.vgUserRoles.BeginUpdate(); data.Data[cell.RowIndex] = form.UserRole; this.vgUserRoles.EndUpdate(); this.vgUserRoles.SelectCell(cell.RowIndex, cell.ColumnIndex); } }; this.btnReLoad.Click += (s, e) => { Helpers.VirtualGridDataHelper.InitalLoad <Models.AppRole>(data); }; this.btnAdd.Click += (s, e) => { UserRolesAddEditForm form = new UserRolesAddEditForm(); //form.StartPosition = FormStartPosition.WindowsDefaultLocation; form.EditMode = Enums.EditFormMode.Add; var dr = form.ShowDialog(this); if (dr == DialogResult.OK) { this.vgUserRoles.BeginUpdate(); this.data.Data.Insert(0, form.UserRole); this.vgUserRoles.RowCount++; this.vgUserRoles.EndUpdate(); this.vgUserRoles.SelectCell(0, 0); } }; this.btnDelete.Click += (s, e) => { DeleteEntry(); }; Helpers.VirtualGridDataHelper.InitalLoad <Models.AppRole>(data); //设置Column宽度 命令列,使用ID列做为命令列 //this.vgUserRoles.TableElement.ColumnsViewState.SetItemSize(0, 30); //this.vgUserRoles.ColumnWidthChanging += (s, e) => { // //ID列为命令按钮,固定大小,不允许resize // int idIndex = Array.IndexOf(ModelHelper.GetColumnNames(typeof(UserRole)), "ID"); // if (e.ColumnIndex == idIndex) // { // e.Cancel = true; // } //}; //this.vgUserRoles.CreateCellElement += (s, e) => { // //ID列约定为命令按钮 // int idIndex = Array.IndexOf(ModelHelper.GetColumnNames(typeof(UserRole)), "ID"); // if (e.RowIndex >= 0 && e.ColumnIndex == idIndex) // { // var cmd = new Helpers.VirtualGridEditCommandCellElement(); // cmd.EditButtonClicked += (ss, ee) => { // var id = (int)cmd.Value; // var entity = data.Data.FirstOrDefault(x => x.ID == id); // if (entity!=null) // { // UserRolesAddEditForm form = new UserRolesAddEditForm(); // form.EditMode = Enums.EditFormMode.Edit; // form.UserRole = entity; // var dr = form.ShowDialog(this); // if (dr == DialogResult.OK) // { // Helpers.VirtualGridDataHelper.InitalLoad<Models.UserRole>(data, System.Threading.SynchronizationContext.Current); // } // } // }; // cmd.DeleteButtonClicked += (ss, ee) => { }; // e.CellElement = cmd; // } //}; //this.vgUserRoles.CellFormatting += (s, e) => { // //ID列约定为命令按钮 // int idIndex = Array.IndexOf(ModelHelper.GetColumnNames(typeof(UserRole)), "ID"); // if (e.CellElement.RowIndex == -3 && e.CellElement.ColumnIndex == idIndex) // { // e.CellElement.Visibility = Telerik.WinControls.ElementVisibility.Hidden; // } // if (e.CellElement.RowIndex == -1 && e.CellElement.ColumnIndex == idIndex) // { // e.CellElement.Visibility = Telerik.WinControls.ElementVisibility.Hidden; // } //}; }