/// <summary> /// 保存数据具体实现 /// </summary> /// <returns>成功返回True</returns> protected bool SaveCore() { try { SaveEventArgs beforeargs = new SaveEventArgs(); beforeargs.IsNew = IsNew; beforeargs.BindEntity = CurrentEntity; OnBeforeSave(beforeargs); if (!beforeargs.IsSuccess) { return(false); } if (!ValidateControl(null)) { return(false); } if (CurrentEntity == null) { return(false); } if (IsNew) { Service.Create(CurrentEntity); CreateEntity(); } else { Service.Update(CurrentEntity); UpdateEntity(); } SaveEventArgs afterArgs = new SaveEventArgs(); afterArgs.IsNew = IsNew; afterArgs.BindEntity = CurrentEntity; OnAfterSave(afterArgs); if (afterArgs.IsSuccess) { SetButtonStatus(); } IsNew = false; IsEditValueChanged = false; return(true); } catch (VersionException ex) { //LogManager.Error(ex.Message, "AppUser", ex); var newEntity = (E)ex.NewEntity; BindMethod(newEntity); //Grid.UpdateEntity(newEntity); XtraMessageBoxHelper.ShowError(ex.Message); } catch (Exception ex) { XtraMessageBoxHelper.ShowError(ex.Message); //LogManager.Error(ex.Message, "AppUser", ex); } return(false); }
private void btnClear_Click(object sender, EventArgs e) { if (XtraMessageBoxHelper.ShowYesNoAndTips("确实要清空当前数据列表吗?删除后数据无法恢复") == System.Windows.Forms.DialogResult.Yes) { List.SelectAllMethod(); Delete(); } }
private void btnRestore_Click(object sender, EventArgs e) { if (XtraMessageBoxHelper.ShowYesNoAndTips("确实要还原选中的数据吗?") == System.Windows.Forms.DialogResult.Yes) { Restore(); Operate.LoadMethod(); } }
void List_BeforeDelete(object sender, ListDeleteEventArgs e) { if (XtraMessageBoxHelper.ShowYesNoAndTips("确实要彻底删除选中的数据吗?删除后数据无法恢复") == System.Windows.Forms.DialogResult.Yes) { Delete(); } e.IsSuccess = false; }
/// <summary> /// 验证控件 如果控件为空验证全部规则 /// </summary> /// <param name="control">控件</param> /// <returns>验证成功返回true</returns> public bool ValidateControl(BaseEdit control) { ValidateRule rule = GetFirstValidateRule(control); if (rule != null) { if (rule.Message.IsNotEmpty()) { XtraMessageBoxHelper.ShowWarning(rule.Message); } if (rule.IsFocusControl) { rule.Control.SelectAll(); rule.Control.Select(); } return(false); } return(true); }
/// <summary> /// 删除方法 /// </summary> public void DeleteMethod() { DeleteEventArgs beforeArgs = new DeleteEventArgs(); SetEditEventArgs(beforeArgs); OnBeforeDelete(beforeArgs); if (!beforeArgs.IsSuccess) { return; } if (CurrentEntity == null) { return; } XtraMessageBoxHelper.ShowYesNoAndWarning(DeleteConfirmMessage, d => { try { if (!Grid.IsAutoDeleteChild && Grid.FocusedNode.HasChildren) { XtraMessageBoxHelper.ShowWarning("此节点有下级 不允许删除"); return; } Service.Delete(CurrentEntity); Grid.Delete(Grid.GetSelected()); DeleteEventArgs afterArgs = new DeleteEventArgs(); SetEditEventArgs(afterArgs); OnAfterDelete(afterArgs); if (afterArgs.IsSuccess) { BindMethod(SelectedEntityCopy); SetButtonStatus(); } } catch (Exception ex) { XtraMessageBoxHelper.ShowError(ex.Message); } }); }
/// <summary> /// 保存数据具体实现 /// </summary> /// <returns>成功返回True</returns> protected bool SaveCore() { try { if (!ValidateControl(null)) { return(false); } SaveEventArgs beforeargs = new SaveEventArgs(); beforeargs.IsNew = IsNew; beforeargs.BindEntity = CurrentEntity; OnBeforeSave(beforeargs); if (!beforeargs.IsSuccess) { return(false); } if (CurrentEntity == null) { return(false); } if (IsNew) { int sortCode = 0; if (ParentNode == null && Grid.Nodes.Count > 0) { sortCode = Grid.Nodes.Count - 1; } else if (ParentNode != null) { var pNode = Grid.FindNodeByID(ParentNode.Id); if (pNode != null) { sortCode = pNode.Nodes.Count; } } CurrentEntity.SetPropertyValue(Metadata.SortCodeFieldName, sortCode); Service.Create(CurrentEntity); if (Grid.DataSource != null) { if (Grid.DataSource is IList) { Grid.Add(CurrentEntity); } else if (Grid.DataSource is DataTable) { var row = Factory.Default.MapToDataRow(Grid.TableSource, CurrentEntity); Grid.Add(row); } } } else { Service.Update(CurrentEntity); if (Grid.DataSource is IList) { Grid.Update(CurrentEntity); } else if (Grid.DataSource is DataTable) { var index = Grid.TableSource.Rows.IndexOf(Grid.GetSelected <DataRow>()); if (index > -1) { var row = Grid.TableSource.Rows[index]; Factory.Default.UpdateDataRow(row, CurrentEntity); } } } SaveEventArgs afterArgs = new SaveEventArgs(); afterArgs.IsNew = IsNew; afterArgs.BindEntity = CurrentEntity; OnAfterSave(afterArgs); if (afterArgs.IsSuccess) { SetButtonStatus(); } IsNew = false; IsEditValueChanged = false; return(true); } catch (VersionException ex) { //LogManager.Error(ex.Message, "AppUser", ex); var newEntity = (E)ex.NewEntity; BindMethod(newEntity); //Grid.UpdateEntity(newEntity); XtraMessageBoxHelper.ShowError(ex.Message); } catch (Exception ex) { XtraMessageBoxHelper.ShowError(ex.Message); //LogManager.Error(ex.Message, "AppUser", ex); } return(false); }