コード例 #1
0
        private DbContext GetDbContext(IDataForm form)
        {
            var type    = form.GetDbContextType();
            var context = Activator.CreateInstance(type) as DbContext;

            return(context);
        }
コード例 #2
0
 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>();
 }
コード例 #3
0
ファイル: CardEdit.cs プロジェクト: 247321453/DataEditorX
 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);
 }
コード例 #4
0
ファイル: CardEdit.cs プロジェクト: yugiohone/DataEditorX
 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>();
 }
コード例 #5
0
 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);
 }
コード例 #6
0
 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);
     }
 }
コード例 #7
0
        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);
        }
コード例 #8
0
        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);
        }
コード例 #9
0
        //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);
            }
        }
コード例 #10
0
 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
             });
         }
     }
 }
コード例 #11
0
        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
                    });
                }
            }
        }
コード例 #12
0
        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();
        }
コード例 #13
0
        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);
        }
コード例 #14
0
 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]);
     }
 }
コード例 #15
0
ファイル: CardEdit.cs プロジェクト: IMJoyJ/DataEditorX
 public ModCommand(CardEdit cardedit)
 {
     this.dataform = cardedit.dataform;
 }
コード例 #16
0
ファイル: CardEdit.cs プロジェクト: 247321453/DataEditorX
 public ModCommand(CardEdit cardedit)
 {
     this.cardedit = cardedit;
     this.dataform = cardedit.dataform;
 }
コード例 #17
0
 public CopyCommand(CardEdit cardedit)
 {
     this.cardedit = cardedit;
     this.dataform = cardedit.dataform;
 }
コード例 #18
0
ファイル: CardEdit.cs プロジェクト: Lyris12/DataEditorX
 public AddCommand(CardEdit cardedit)
 {
     dataform = cardedit.dataform;
 }
コード例 #19
0
ファイル: Controller.cs プロジェクト: naimheshmati/Sanofi
        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;
        }
コード例 #20
0
 public SmtpSender(IDataForm <MainForm> data)
 {
     _data = data ?? throw new ArgumentException(nameof(data));
     InitSettingsAndFillDataMail();
 }