/* * Математический аппарат */ #region public override void SetProperties(AbstractDictionary dictionary) public override void SetProperties(AbstractDictionary dictionary) { if (dictionary is SmsEventType) { SetProperties((SmsEventType)dictionary); } }
/* * Методы */ #region public override void SetProperties(AbstractDictionary dictionary) public override void SetProperties(AbstractDictionary dictionary) { if (dictionary is EventClass) { SetProperties((EventClass)dictionary); } }
/* * Глобальные коллекции */ #region public void Save(BaseSmartCoreObject saveObject) public void Save(BaseEntityObject saveObject) { if (saveObject == null) { return; } saveObject.CorrectorId = _casEnvironment.IdentityUser.ItemId; var type = AuditOperation.Created; if (saveObject.ItemId > 0) { type = AuditOperation.Changed; } CasEnvironment.Keeper.Save(saveObject); _auditRepository.WriteAsync(saveObject, type, _casEnvironment.IdentityUser); if (saveObject is AbstractDictionary) { IDictionaryCollection col = CasEnvironment.GetDictionary(saveObject.GetType()); if (col == null) { return; } AbstractDictionary dict = (AbstractDictionary)col.GetItemById(saveObject.ItemId); if (dict == null || saveObject.ItemId != dict.ItemId) { col.Add(saveObject); } else { dict.SetProperties((AbstractDictionary)saveObject); } } if (saveObject is Store) { Store o = CasEnvironment.Stores.GetItemById(saveObject.ItemId); if (o == null || saveObject.ItemId != o.ItemId) { CasEnvironment.Stores.Add((Store)saveObject); } } if (saveObject is BaseComponent) { BaseComponent o = _componentCore.GetBaseComponentById(saveObject.ItemId); if (o == null || saveObject.ItemId != o.ItemId) { CasEnvironment.BaseComponents.Add((BaseComponent)saveObject); } } }
/// <summary> /// Новый метод для сохранения объектов /// </summary> /// <param name="saveObject">Сохраняемый объект</param> /// <param name="saveChild">Сохранять дочерние объекты</param> /// <param name="saveForced">Сохранять свойтсва, помеченные как "принудительные"</param> public void SaveAll(BaseEntityObject saveObject, bool saveChild = false, bool saveForced = false) { if (saveObject == null) { return; } CasEnvironment.Keeper.SaveAll(saveObject, saveChild, saveForced); if (saveObject is AbstractDictionary) { IDictionaryCollection col = CasEnvironment.GetDictionary(saveObject.GetType()); if (col == null) { return; } AbstractDictionary dict = (AbstractDictionary)col.GetItemById(saveObject.ItemId); if (dict == null || saveObject.ItemId != dict.ItemId) { col.Add(saveObject); } else { dict.SetProperties((AbstractDictionary)saveObject); } } if (saveObject is Store) { Store o = CasEnvironment.Stores.GetItemById(saveObject.ItemId); if (o == null || saveObject.ItemId != o.ItemId) { CasEnvironment.Stores.Add((Store)saveObject); } } if (saveObject is BaseComponent) { BaseComponent o = _componentCore.GetBaseComponentById(saveObject.ItemId); if (o == null || saveObject.ItemId != o.ItemId) { CasEnvironment.BaseComponents.Add((BaseComponent)saveObject); } } }
private Control GetControl(BaseEntityObject obj, PropertyInfo propertyInfo, int controlWidth, bool controlEnabled) { #region ЭУ для прикрепленного файла if (propertyInfo.PropertyType.Name == nameof(AttachedFile) || propertyInfo.PropertyType.IsSubclassOf(typeof(AttachedFile))) { object val = propertyInfo.GetValue(obj, null); return(new AttachedFileControl { AttachedFile = (AttachedFile)val, Enabled = controlEnabled, Filter = "PDF file (*.pdf)|*.pdf", Icon = Properties.Resources.PDFIconSmall, MaximumSize = new Size(350, 100), Size = new Size(350, 75), Tag = propertyInfo }); } #endregion #region ЭУ для StaticDictionary if (propertyInfo.PropertyType.IsSubclassOf(typeof(StaticDictionary))) { object val = propertyInfo.GetValue(obj, null); if (propertyInfo.PropertyType.GetCustomAttributes(typeof(TableAttribute), false).Length > 0) { DictionaryComboBox dc = new DictionaryComboBox { Enabled = controlEnabled, Name = propertyInfo.Name, SelectedItem = (StaticDictionary)val, Tag = propertyInfo, Type = propertyInfo.PropertyType, }; //для возможности вызова новой вкладки Program.MainDispatcher.ProcessControl(dc); // return(dc); } ComboBox nc = new ComboBox { Enabled = controlEnabled, Tag = propertyInfo, Width = controlWidth, }; //поиск своиства Items у типа StaticDictionary Type t = propertyInfo.PropertyType; PropertyInfo p = t.GetProperty("Items"); ConstructorInfo ci = t.GetConstructor(new Type[0]); StaticDictionary instance = (StaticDictionary)ci.Invoke(null); IEnumerable staticList = (IEnumerable)p.GetValue(instance, null); foreach (StaticDictionary o in staticList) { nc.Items.Add(o); } nc.SelectedItem = val; return(nc); } #endregion #region ЭУ для AbstractDictionary if (propertyInfo.PropertyType.IsSubclassOf(typeof(AbstractDictionary))) { AbstractDictionary val = (AbstractDictionary)propertyInfo.GetValue(obj, null); DictionaryComboBox dc = new DictionaryComboBox { Enabled = controlEnabled, SelectedItem = val, Tag = propertyInfo, Type = propertyInfo.PropertyType, }; //для возможности вызова новой вкладки Program.MainDispatcher.ProcessControl(dc); // return(dc); } #endregion #region ЭУ для BaseEntityObject if (propertyInfo.PropertyType.IsSubclassOf(typeof(BaseEntityObject))) { object val = propertyInfo.GetValue(obj, null); TextBox tb = new TextBox { AutoSize = true, Enabled = controlEnabled, Tag = propertyInfo, Text = val != null?val.ToString() : "", Width = controlWidth, }; return(tb); } #endregion #region ЭУ для Enum if (propertyInfo.PropertyType.IsEnum) { object val = propertyInfo.GetValue(obj, null); if (propertyInfo.PropertyType.GetCustomAttributes(typeof(FlagsAttribute), false).Length > 0) { CommonFlagsControl cfc = new CommonFlagsControl { Enabled = controlEnabled, SourceEnum = propertyInfo.PropertyType, Tag = propertyInfo }; return(cfc); } ComboBox nc = new ComboBox { Enabled = controlEnabled, Tag = propertyInfo }; foreach (object o in Enum.GetValues(propertyInfo.PropertyType)) { nc.Items.Add(o); } nc.SelectedItem = val; return(nc); } #endregion //#region ЭУ для базовых типов //string typeName = propertyInfo.PropertyType.Name.ToLower(); //switch (typeName) //{ // case "string": // { // string val = (string)propertyInfo.GetValue(obj, null); // Control control; // if (richTextBox) // { // RichTextBox richText = new RichTextBox // { // AutoSize = true, // Enabled = controlEnabled, // MinimumSize = new Size(20, 17), // Multiline = controlLines > 1, // Tag = propertyInfo, // Width = controlWidth, // }; // try // { // richText.Rtf = val; // } // catch (Exception) // { // richText.Text = val; // } // if (controlLines > 1) // { // richText.ScrollBars = RichTextBoxScrollBars.Both; // richText.Height = richText.Font.Height * controlLines + 7; // } // control = richText; // } // else // { // TextBox textBox = new TextBox // { // AutoSize = true, // Enabled = controlEnabled, // MinimumSize = new Size(20, 17), // Multiline = controlLines > 1, // Tag = propertyInfo, // Text = val, // Width = controlWidth, // }; // if (controlLines > 1) // { // textBox.ScrollBars = ScrollBars.Vertical; // textBox.Height = textBox.Font.Height * controlLines + 7; // } // control = textBox; // } // return control; // } // case "int32": // { // Int32 val = (Int32)propertyInfo.GetValue(obj, null); // MinMaxValueAttribute mmValue = // (MinMaxValueAttribute)propertyInfo.GetCustomAttributes(typeof(MinMaxValueAttribute), false).FirstOrDefault(); // NumericUpDown nud = new NumericUpDown(); // if (mmValue != null) // { // nud.Maximum = (decimal)mmValue.Max; // nud.Minimum = (decimal)mmValue.Min; // if (val < (Int32)mmValue.Min) val = (Int32)mmValue.Min; // if (val > (Int32)mmValue.Max) val = (Int32)mmValue.Max; // } // nud.Enabled = controlEnabled; // nud.Value = val; // nud.DecimalPlaces = 0; // nud.MinimumSize = new Size(20, 17); // nud.Tag = propertyInfo; // return nud; // } // case "int16": // { // object val = propertyInfo.GetValue(obj, null); // MinMaxValueAttribute mmValue = // (MinMaxValueAttribute)propertyInfo.GetCustomAttributes(typeof(MinMaxValueAttribute), false).FirstOrDefault(); // NumericUpDown nud = new NumericUpDown(); // if (mmValue != null) // { // nud.Maximum = (decimal)mmValue.Max; // nud.Minimum = (decimal)mmValue.Min; // } // nud.Enabled = controlEnabled; // nud.Value = (Int16)val; // nud.DecimalPlaces = 0; // nud.MinimumSize = new Size(20, 17); // nud.Tag = propertyInfo; // return nud; // } // case "datetime": // { // DateTime val = (DateTime)propertyInfo.GetValue(obj, null); // return new DateTimePicker // { // Enabled = controlEnabled, // MinDate = new DateTime(1950,1,1), // MinimumSize = new Size(20, 17), // //AutoSize = true, // Tag = propertyInfo, // Value = val > DateTimePicker.MinimumDateTime ? new DateTime(val.Ticks) : DateTimePicker.MinimumDateTime // }; // } // case "bool": // case "boolean": // { // object val = propertyInfo.GetValue(obj, null); // return new CheckBox // { // Checked = (bool)val, // Enabled = controlEnabled, // MinimumSize = new Size(20, 17), // //AutoSize = true, // Tag = propertyInfo // }; // } // case "double": // { // object val = propertyInfo.GetValue(obj, null); // MinMaxValueAttribute mmValue = // (MinMaxValueAttribute)propertyInfo.GetCustomAttributes(typeof(MinMaxValueAttribute), false).FirstOrDefault(); // NumericUpDown nud = new NumericUpDown(); // if (mmValue != null) // { // nud.Maximum = (decimal)mmValue.Max; // nud.Minimum = (decimal)mmValue.Min; // } // nud.Enabled = controlEnabled; // nud.Value = (decimal) (double) val; // nud.DecimalPlaces = 2; // nud.MinimumSize = new Size(20, 17); // nud.Tag = propertyInfo; // return nud; // } // case "directivethreshold": // { // object val = propertyInfo.GetValue(obj, null); // return new DirectiveThresholdControl { Enabled = controlEnabled, Threshold = (DirectiveThreshold)val, Tag = propertyInfo }; // } // case "detaildirectivethreshold": // { // object val = propertyInfo.GetValue(obj, null); // return new DetailDirectiveThresholdControl { Enabled = controlEnabled, Threshold = (DetailDirectiveThreshold)val, Tag = propertyInfo }; // } // case "lifelength": // { // object val = propertyInfo.GetValue(obj, null); // return new LifelengthViewer // { // Enabled = controlEnabled, // Lifelength = (Lifelength) val, // MinimumSize = new Size(20, 17), // Tag = propertyInfo // }; // } // case "timespan": // { // TimeSpan val = (TimeSpan)propertyInfo.GetValue(obj, null); // return new DateTimePicker // { // CustomFormat = "HH:mm", // Enabled = controlEnabled, // Format = DateTimePickerFormat.Custom, // MinDate = new DateTime(1950, 1, 1), // MinimumSize = new Size(20, 17), // //AutoSize = true, // ShowUpDown = true, // Tag = propertyInfo, // Value = DateTime.Today.Add(val) // }; // } // default: // return null; //} //#endregion return(null); }