private DbContext GetDbContext(IDataForm form) { var type = form.GetDbContextType(); var context = Activator.CreateInstance(type) as DbContext; return(context); }
public CardEdit(IDataForm dataform) { this.dataform = dataform; this.undoSQL = new List <string>(); this.undoModified = new List <FileModified>(); this.undoDeleted = new List <FileDeleted>(); this.undoCopied = new List <DBcopied>(); }
public CardEdit(IDataForm dataform) { this.dataform = dataform; this.addCard = new AddCommand(this); this.modCard = new ModCommand(this); this.delCard = new DelCommand(this); this.copyCard = new CopyCommand(this); }
public CardEdit(IDataForm dataform) { this.dataform = dataform; this.undoSQL = new List<string>(); this.undoModified = new List<FileModified>(); this.undoDeleted = new List<FileDeleted>(); this.undoCopied = new List<DBcopied>(); }
public bool IsPropertyValueNotUnique(IDataForm form, object item, string bindingProperty, Type entity) { using (var db = GetDbContext(form)) { var value = item.GetPropertyValue(bindingProperty); var result = db.FindSet(entity).Any($"{bindingProperty} = {value.ToSql()}"); return(result); } }
public IEnumerable <ValidationResult> ValidateCustomRules(IDataForm form, object item, int rowIndex, IEnumerable <DataField> fields, FormRuleTriggers trigger) { var result = new List <ValidationResult>(); foreach (var field in fields) { CustomRule(form, fields, item, rowIndex, field, result, trigger); } return(result); }
public IEnumerable <ValidationResult> ValidateModelProperty(IDataForm form, object item, int rowIndex, string bindingProperty, IEnumerable <DataField> fields) { var result = new List <ValidationResult>(); var field = fields.Single(f => f.BindingProperty == bindingProperty); PrimaryKeyRule(item, rowIndex, field, result); RequiredRule(item, rowIndex, field, result); UniqueRule(form, item, rowIndex, field, result); CustomRule(form, fields, item, rowIndex, field, result, FormRuleTriggers.Change); return(result); }
//public object GetModelData(IModelDefinitionForm form, int Id) //{ // throw new NotImplementedException(); //} public System.Collections.IList GetEntityData(IDataForm form, Type entity) { if (entity.IsEnum) { var result = Enum.GetValues(entity); return(result); } using (var db = GetDbContext(form)) { var result = db.FindSet(entity).ToDynamicList <object>(); return(result); } }
private void UniqueRule(IDataForm form, object item, int rowIndex, DataField field, List <ValidationResult> result) { if (field.Unique) { if (_dataEntryProvider.IsPropertyValueNotUnique(form, item, field.BindingProperty, item.GetType())) { result.Add(new ValidationResult { Message = "Not unique", BindingProperty = field.BindingProperty, ValidationResultType = ValidationResultTypes.Error, RowIndex = rowIndex }); } } }
private void CustomRule(IDataForm form, IEnumerable <DataField> fields, object item, int rowIndex, DataField field, List <ValidationResult> result, FormRuleTriggers trigger) { var rules = field.Rules.Where(r => r.Trigger == trigger || (trigger == FormRuleTriggers.ChangeSubmit && (r.Trigger == FormRuleTriggers.Change || r.Trigger == FormRuleTriggers.Submit)) || (trigger == FormRuleTriggers.Submit && (r.Trigger == FormRuleTriggers.Change || r.Trigger == FormRuleTriggers.Submit || r.Trigger == FormRuleTriggers.ChangeSubmit)) || (trigger == FormRuleTriggers.Change && (r.Trigger == FormRuleTriggers.Change || r.Trigger == FormRuleTriggers.Submit || r.Trigger == FormRuleTriggers.ChangeSubmit)) ); foreach (var rule in rules) { FormRuleResult vr; if (rule.Method != null) { vr = rule.Method(item); } else { Type argsType = typeof(RuleArgs <>).MakeGenericType(rule.EntityType); var args = Activator.CreateInstance(argsType, item) as RuleArgs; vr = rule.MethodArgs(args); var ruleFields = args.EntityBuilder.GetFieldDictionary(); //ToDo: update fields appearance here foreach (var f in fields) { var rf = ruleFields[f.BindingProperty]; f.Required = rf.Required; f.Hidden = rf.Hidden; f.ReadOnly = rf.ReadOnly; f.Label = rf.Label; } } if (vr != null && vr.IsFailed) { result.Add(new ValidationResult { Message = $"{vr.RuleName}: {vr.Message}", BindingProperty = field.BindingProperty, ValidationResultType = ValidationResultTypes.Error, RowIndex = rowIndex }); } } }
private void ShowForm(string title, IData data) { switch (data.GetType()) { case DataType.TrueFalse: _currentForm = new TrueFalseForm(title, (TrueFalse)data); break; case DataType.Cards: _currentForm = new CardForm(title, (Cards)data); break; default: return; } ((Form)_currentForm).Show(); }
public IEnumerable <ValidationResult> ValidateModel(IDataForm form, object item, int rowIndex, IEnumerable <DataField> fields, Dictionary <string, FieldState> states = null) { var result = new List <ValidationResult>(); foreach (var field in fields) { PrimaryKeyRule(item, rowIndex, field, result); RequiredRule(item, rowIndex, field, result); // Ignore this rule for Update by PrimaryKey if (states == null || !field.PrimaryKey || states[field.BindingProperty].IsNew) { UniqueRule(form, item, rowIndex, field, result); } CustomRule(form, fields, item, rowIndex, field, result, FormRuleTriggers.Submit); } return(result); }
public virtual void BindData(IDataForm dataForm) { this.TryEnter(); if (this.DataEngine == null) { throw new DataFormException("DataEngine cannot be null"); } if (this.ds != null) { this.BeginEdit(); foreach (DataControl control in this.daoDataForm.DataControls) { if (!(((control.MapColumn == null) && (control.MapTable == null)) && string.IsNullOrEmpty(control.ValueList))) { string memberName = (control.MapColumn != null) ? control.MapColumn.Name : string.Empty; dataForm.BindDataToControl(control.Name, (control.MapTable != null) ? this.ds.Tables[control.MapTable.Name] : null, memberName, control.ValueCollection); } } } else { LoggingService.WarnFormatted("异步线程没有获取到数据集", new object[0]); } }
public ModCommand(CardEdit cardedit) { this.dataform = cardedit.dataform; }
public ModCommand(CardEdit cardedit) { this.cardedit = cardedit; this.dataform = cardedit.dataform; }
public CopyCommand(CardEdit cardedit) { this.cardedit = cardedit; this.dataform = cardedit.dataform; }
public AddCommand(CardEdit cardedit) { dataform = cardedit.dataform; }
public DataFormController(IDataForm form) : base(form as IListForm) { EnableAutoRefresh = false; (this.form as IDataForm).Mode = DataFormMode.Read; (this.form as IDataForm).NewButton.Click += new RoutedEventHandler(New_Click); (this.form as IDataForm).EditButton.Click += new RoutedEventHandler(Edit_Click); this.form.EnableControls(false); DefaultState(); (this.form as IListForm).Grid.Visibility = System.Windows.Visibility.Collapsed; (this.form as IDataForm).NewButton.Visibility = Visibility.Collapsed; (this.form as IDataForm).EditButton.Visibility = Visibility.Collapsed; (this.form as IDataForm).DeleteButton.Visibility = Visibility.Collapsed; (this.form as IDataForm).SaveButton.Visibility = Visibility.Collapsed; }
public SmtpSender(IDataForm <MainForm> data) { _data = data ?? throw new ArgumentException(nameof(data)); InitSettingsAndFillDataMail(); }