public AppUserAddEditForm() { InitializeComponent(); this.AcceptButton = this.btnOk; this.CancelButton = this.btnCancel; this.FormClosed += (s, e) => { //释放 资源 if (bll != null) { bll.Dispose(); bll = null; } }; //设置dataentity this.deMain.FitToParentWidth = true; this.deMain.ShowValidationPanel = true; this.deMain.EditorInitializing += (s, e) => { e.Editor.Name = e.Property.Name; if (e.Property.Name == "UserName" && EditMode == Enums.EditFormMode.Edit) { e.Editor.Enabled = false; } else if (e.Property.Name == "Email") { RadMaskedEditBox editor = new RadMaskedEditBox(); editor.MaskType = MaskType.EMail; editor.MaskedEditBoxElement.StretchVertically = true; e.Editor = editor; } //else if (e.Property.Name == "Tel") //{ // RadMaskedEditBox editor = new RadMaskedEditBox(); // editor.MaskType = MaskType.Regex; // editor.MaskedEditBoxElement.StretchVertically = true; // //editor.Mask = "9"; // e.Editor = editor; //} }; this.deMain.ItemValidating += (s, e) => { Models.AppUser user = this.deMain.CurrentObject as Models.AppUser; switch (e.Label.Text) { case "用户名": if (string.IsNullOrWhiteSpace(user.UserName)) { string errorMessage = "用户名不能为空!"; e.ErrorProvider.SetError(s as Control, errorMessage); e.Cancel = true; AddErrorLabel(this.deMain, e.Label.Text, errorMessage); } else { e.ErrorProvider.Clear(); this.deMain.ValidationPanel.PanelContainer.Controls.RemoveByKey(e.Label.Text); } break; default: break; } }; this.Shown += (s, e) => { //设置窗体title switch (EditMode) { case Enums.EditFormMode.Add: this.Text = "新增"; DataEntry = new Models.AppUser() { Password = Helpers.EncryptDecryptHelper.GetStringMD5("888888") }; //新增用户默认密码 break; case Enums.EditFormMode.Edit: this.Text = "编辑"; break; case Enums.EditFormMode.Delete: this.Text = "删除"; break; default: this.Text = "新增/编辑"; break; } if (DataEntry != null) { this.deMain.DataSource = this.DataEntry; } }; this.btnCancel.Click += (s, e) => { //this.UserRole.CancelEdit(); this.DialogResult = DialogResult.Cancel; }; this.btnOk.Click += (s, e) => { var t = ValidationHelper.hasValidationErrors(this.deMain.Controls); if (t) { return; } this.btnOk.Enabled = false; Task.Factory.StartNew <AppUser>(() => { Models.AppUser re = null; if (EditMode == Enums.EditFormMode.Add) { re = bll.Insert <Models.AppUser>(this.DataEntry); } else if (EditMode == Enums.EditFormMode.Edit) { re = bll.Update <Models.AppUser>(this.DataEntry); } return(re); }).ContinueWith(tt => { if (!tt.IsFaulted) { syncContext.Post((state) => { Models.AppUser sta = (Models.AppUser)state; if (sta != null) { this.DataEntry = sta; this.DialogResult = DialogResult.OK; //this.SubmitSucess = true; } else { RadMessageBox.Show(this, "保存失败!", "", MessageBoxButtons.OK, RadMessageIcon.Error); } }, tt.Result); } syncContext.Post((state) => { this.btnOk.Enabled = true; }, tt.Result); }); }; }
//private bool isUpdate = false; //private ObservableCollection<BasLayer> layerData = new ObservableCollection<BasLayer>(); public BaseParaSettingForm() { InitializeComponent(); this.Text = "基础参数设置"; this.AutoValidate = AutoValidate.EnableAllowFocusChange;//控件验证时 validating e.cancel = true 时可以 切换焦点 InitMaterialCostGridView(); InitMaterialGridView(); InitLayerDataEntry(); InitLayerGridView(); LoadLayerData(); this.pvSetting.SelectedPageChanged += (s, e) => { switch (this.pvSetting.SelectedPage.Name) { case "pvpMaterialSetting": //物料设置 //InitMaterialGridView(); LoadMaterialData(); break; case "pvpLayerSetting": //层数设置 //InitLayerDataEntry(); //InitLayerGridView(); LoadLayerData(); break; default: break; } }; this.btnMaterialReload.Click += (s, e) => { LoadMaterialData(); }; this.btnMaterialDelete.Click += (s, e) => { if (RadMessageBox.Show(this, "确认删除所选行?", "", MessageBoxButtons.YesNo, RadMessageIcon.Question) == DialogResult.No) { return; } var rows = this.gvMaterial.SelectedRows; if (rows.Count <= 0) { RadMessageBox.Show(this, "请选择想删除的行!", "", MessageBoxButtons.OK, RadMessageIcon.Error); return; } delIds.Clear(); foreach (var row in rows) { var tmp = row.DataBoundItem as QuoMaterial; if (tmp != null && tmp.Id > 0) { delIds.Add(tmp.Id); } } if (delIds.Count > 0) { Task.Factory.StartNew(() => { bll.Delete <QuoMaterial>(delIds); }).ContinueWith(t => { if (t.IsFaulted) { LoadMaterialData(); } syncContext.Post((state) => { this.gvMaterial.BeginUpdate(); foreach (var i in rows) { this.gvMaterial.Rows.Remove(i); } this.gvMaterial.EndUpdate(); }, ""); }); } }; //取消按钮事件 this.btnLayerCancel.Click += (s, e) => { if (EditMode == Enums.EditFormMode.Add) { this.deLayer.DataSource = new QuoLayer(); } else if (EditMode == Enums.EditFormMode.Edit) { this.deLayer.DataSource = OriLayer; var cur = this.gvLayer.CurrentRow.DataBoundItem as QuoLayer; ObjectHelper.CopyAllField(OriLayer, cur); //this.deLayer.DataSource = OriginalLayer ; } }; //加载按钮事件 this.btnReLoad.Click += (s, e) => { LoadLayerData(); }; //新增按钮事件 this.btnLayerAdd.Click += (s, e) => { EditMode = Enums.EditFormMode.Add; this.deLayer.DataSource = new QuoLayer(); }; //删除按钮事件 this.btnLayerDelete.Click += (s, e) => { if (RadMessageBox.Show(this, "确认删除?", "", MessageBoxButtons.YesNo, RadMessageIcon.Question) == DialogResult.Yes) { this.btnLayerDelete.Enabled = false; Task.Factory.StartNew <QuoLayer>(() => { var cur = this.gvLayer.CurrentRow.DataBoundItem as QuoLayer; if (bll.Delete <QuoLayer>(cur.Id) > 0) { return(cur); } else { return(null); } }).ContinueWith(t => { if (!t.IsFaulted && t.Result != null) { syncContext.Post((state) => { this.gvLayer.BeginUpdate(); var layerData = this.gvLayer.DataSource as ObservableCollection <QuoLayer>; layerData.Remove(t.Result); this.gvLayer.EndUpdate(); }, ""); } syncContext.Post((state) => { this.btnLayerDelete.Enabled = true; }, ""); }); } }; //保存按钮事件 this.btnLayerSave.Click += (s, e) => { var t = ValidationHelper.hasValidationErrors(this.deLayer.Controls); if (t) { return; } this.btnLayerSave.Enabled = false; Task.Factory.StartNew <QuoLayer>(() => { QuoLayer re = null; if (EditMode == Enums.EditFormMode.Add) { re = bll.Insert <QuoLayer>(this.deLayer.CurrentObject as QuoLayer); } else if (EditMode == Enums.EditFormMode.Edit) { re = bll.Update(this.deLayer.CurrentObject as QuoLayer); OriLayer = re; } return(re); }).ContinueWith(tt => { if (!tt.IsFaulted) { syncContext.Post((state) => { if (tt.Result != null) { this.gvLayer.BeginUpdate(); if (EditMode == Enums.EditFormMode.Add) { var layerData = this.gvLayer.DataSource as ObservableCollection <QuoLayer>; layerData.Insert(0, tt.Result); } else if (EditMode == Enums.EditFormMode.Edit) { var layerData = this.gvLayer.DataSource as ObservableCollection <QuoLayer>; var cur = this.gvLayer.CurrentRow.DataBoundItem as QuoLayer; //cur = tt.Result; layerData[layerData.IndexOf(cur)] = tt.Result; } this.gvLayer.EndUpdate(); if (EditMode == Enums.EditFormMode.Add) { this.gvLayer.Rows[0].IsCurrent = true; } } }, ""); } syncContext.Post((state) => { this.btnLayerSave.Enabled = true; }, ""); }); }; }
public UserRolesAddEditForm() { InitializeComponent(); this.AcceptButton = this.btnSubmit; this.CancelButton = this.btnCanel; this.FormClosed += (s, e) => { //释放 资源 if (bll != null) { bll.Dispose(); bll = null; } }; //设置dataentity this.deUserRole.FitToParentWidth = true; this.deUserRole.ShowValidationPanel = true; this.deUserRole.EditorInitializing += (s, e) => { e.Editor.Name = e.Property.Name; }; this.deUserRole.ItemValidating += (s, e) => { Models.AppRole role = this.deUserRole.CurrentObject as Models.AppRole; switch (e.Label.Text) { case "角色名称": if (string.IsNullOrWhiteSpace(role.RoleName)) { string errorMessage = "角色名称不能为空!"; e.ErrorProvider.SetError(s as Control, errorMessage); e.Cancel = true; AddErrorLabel(this.deUserRole, e.Label.Text, errorMessage); } else { e.ErrorProvider.Clear(); this.deUserRole.ValidationPanel.PanelContainer.Controls.RemoveByKey(e.Label.Text); } break; default: break; } }; this.Shown += (s, e) => { //设置窗体title switch (EditMode) { case Enums.EditFormMode.Add: this.Text = "新增"; UserRole = new Models.AppRole(); break; case Enums.EditFormMode.Edit: this.Text = "编辑"; break; case Enums.EditFormMode.Delete: this.Text = "删除"; break; default: this.Text = "新增/编辑"; break; } if (UserRole != null) { this.deUserRole.DataSource = this.UserRole; this.UserRole.BeginEdit(); } }; this.btnCanel.Click += (s, e) => { //this.UserRole.CancelEdit(); this.DialogResult = DialogResult.Cancel; }; this.btnSubmit.Click += (s, e) => { var t = ValidationHelper.hasValidationErrors(this.deUserRole.Controls); if (t) { return; } this.btnSubmit.Enabled = false; Task.Factory.StartNew(() => { Models.AppRole re = null; if (EditMode == Enums.EditFormMode.Add) { re = bll.Insert <Models.AppRole>(this.UserRole); } else if (EditMode == Enums.EditFormMode.Edit) { re = bll.Update <Models.AppRole>(this.UserRole); } syncContext.Post((state) => { this.btnSubmit.Enabled = true; Models.AppRole sta = (Models.AppRole)state; if (sta != null) { this.UserRole = sta; this.DialogResult = DialogResult.OK; //this.SubmitSucess = true; } else { RadMessageBox.Show(this, "保存失败!", "", MessageBoxButtons.OK, RadMessageIcon.Error); } }, re); }); }; }
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); }