private void NewModelEvent(object sender, EventArgs e) { Model = Controller.NewModel(); DefaultControl?.Select(); AfterNew?.Invoke(true); }
public BaseBinder() : base() { Controllers = new Dictionary <string, IDBController>(); Mapper = new Dictionary <string, Control>(); Prop = new Func <string, PropertyInfo>(x => typeof(M).GetProperty(x)); isBoolean = new Func <string, bool>(x => Mapper[x].GetType() == typeof(CheckBox) && Prop(x).PropertyType == typeof(bool)); isDateTime = new Func <string, bool>(x => Prop(x).PropertyType == typeof(DateTime) || Prop(x).PropertyType == typeof(DateTime?)); isInt64 = new Func <string, bool>(x => Prop(x).PropertyType == typeof(Int64)); isInt32 = new Func <string, bool>(x => Prop(x).PropertyType == typeof(Int32) || Prop(x).PropertyType == typeof(int)); isDouble = new Func <string, bool>(x => Prop(x).PropertyType == typeof(double) || Prop(x).PropertyType == typeof(Double)); //Load += (s, e) => { // if (DesignMode || (Site != null && Site.DesignMode)) return; new PermissionsHelper <M>(this); foreach (var control in Mapper.Values.OrderBy(x => x.TabIndex)) { if (DefaultControl == null && control.TabStop) { DefaultControl = control; } control.KeyDown += delegate(object sender, KeyEventArgs ea) { if (ea.KeyCode == Keys.Enter) { ea.SuppressKeyPress = true; ea.Handled = true; SendKeys.Send("\t"); } }; } DefaultControl?.Focus(); if (SaveButton != null) { SaveButton.Enabled = SaveButtonEnabled; SaveButton.Click += (bs, be) => { try { Controller.Save(Model); Model = Controller.Find(Model, Controller.GetMetaData().UniqueKeyFields.ToArray()); AfterSave?.Invoke(); DefaultControl.Focus(); DefaultControl.Select(); }catch (Exception ex) { FormsHelper.Error(ex.Message); } }; } if (DeleteButton != null) { DeleteButton.Enabled = DeleteButtonEnabled; DeleteButton.Click += (bs, be) => { Controller.Delete(Model); NewButton?.PerformClick(); }; } if (NewButton != null) { NewButton.Enabled = NewButtonEnabled; NewButton.Click += (bs, be) => { Model = Controller.NewModel <M>(); }; } //}; }