/// <summary> /// Init Linked table selector for multi values /// </summary> /// <param name="controlName">Control name</param> /// <param name="controlData">Control data</param> /// <param name="linkedTableAttribute">Attributes of property</param> public LinkedTableMultiSelectorControl(string controlName, PropertyAnalyze controlData, LinkedTableAttribute linkedTableAttribute) { this.controlData = controlData; LinkedTableType = linkedTableAttribute.LinkedTableType; CreateUI(controlName, controlData); }
/// <summary> /// Create linked table control /// </summary> /// <param name="controlName">Control name</param> /// <param name="controlData">Control data</param> /// <param name="controlType">Control type</param> /// <param name="linkedTableAttribute">Linked table attributes</param> /// <returns>Created control</returns> public static UIElement CreateLinkedTableControl(string controlName, PropertyAnalyze controlData, PropertyType controlType, LinkedTableAttribute linkedTableAttribute) { if (controlData is null) { throw new Base.Exceptions.ArgumentNullException(nameof(controlData)); } if (controlType != PropertyType.Int && controlType != PropertyType.Int32) { throw new Base.Exceptions.ArgumentOutOfRangeException(nameof(controlData), "Type of linked table presenter property must be integer."); } if (!(controlData.PropertyAttributes.FirstOrDefault(x => x.GetType() == typeof(UIParamsAttribute)) is UIParamsAttribute customization)) { throw new MissingRequiredAdditionalDataException("Linked table property require UIParams attribute for specificating design."); } var control = new LinkedTableMultiSelectorControl(controlName, controlData, linkedTableAttribute) { Name = controlName + Constants.DATA_CONTROL_IDENTIFIER, Margin = new Thickness(10) }; return(control); }
public void AnalyzerTest() { ModuleAnalyser analyzer = new ModuleAnalyser(); var analyzeResult = analyzer.AnalyseAndGet(typeof(TestClassNotBaseItem)); PropertyAnalyze prop1 = new PropertyAnalyze("StringProp", typeof(string), new List <object>() { new UIIgnoreAttribute(), new DbIgnoreAttribute(), new UIParamsAttribute() { UseLongTextInput = true } }); PropertyAnalyze prop2 = new PropertyAnalyze("IntProp", typeof(int), new List <object>()); Assert.IsTrue(analyzeResult.Values.ToList()[0].Equals(prop1)); Assert.IsTrue(analyzeResult.Values.ToList()[1].Equals(prop2)); }
/// <summary> /// Create editable controls /// </summary> /// <param name="controlAnalyze">Analyze of property</param> /// <param name="previousControl">Previous control</param> /// <param name="uiModule">UI module</param> /// <returns>New control</returns> public static UIElement CreateEditableControl(KeyValuePair <string, PropertyAnalyze> controlAnalyze, ref UIElement previousControl, UIModule uiModule) { string controlName = controlAnalyze.Key; PropertyAnalyze controlData = controlAnalyze.Value; PropertyType controlTypeName = controlData.PropertyType; UIElement control; UIParamsAttribute customization = controlData.PropertyAttributes.FirstOrDefault(x => x.GetType() == typeof(UIParamsAttribute)) as UIParamsAttribute; var linkedTableAttribute = controlData.PropertyAttributes.FirstOrDefault(x => x.GetType() == typeof(LinkedTableAttribute)) as LinkedTableAttribute; if (linkedTableAttribute != null) { switch (linkedTableAttribute.LinkedTableRelation) { case LinkedTableRelation.One: control = LinkedTableSingleSelectorControl.CreateLinkedTableControl(controlName, controlData, controlTypeName, linkedTableAttribute); break; case LinkedTableRelation.Many: control = LinkedTableMultiSelectorControl.CreateLinkedTableControl(controlName, controlData, controlTypeName, linkedTableAttribute); break; default: throw new NotSupportedPropertyTypeException("Not supported LinkedTableRelation."); } } else { switch (controlTypeName) { case PropertyType.String: case PropertyType.Int: case PropertyType.Int32: case PropertyType.Double: case PropertyType.Char: case PropertyType.Decimal: case PropertyType.Float: control = new TextBox() { Name = controlName + Constants.DATA_CONTROL_IDENTIFIER, Margin = new Thickness(10), TextWrapping = TextWrapping.Wrap, PlaceholderText = "Insert " + controlName }; if (controlTypeName == PropertyType.Char) { (control as TextBox).MaxLength = 1; } if (customization != null && customization.UseLongTextInput) { (control as TextBox).Height = 150; } break; case PropertyType.Boolean: control = new CheckBox() { Content = controlName, Margin = new Thickness(10), Name = controlName + Constants.DATA_CONTROL_IDENTIFIER }; break; case PropertyType.DateTime: if (customization == null) { throw new MissingRequiredAdditionalDataException("Property DateTime require UIParams attribute for specificating design."); } control = new Grid() { Margin = new Thickness(10) }; RowDefinition labelRow = new RowDefinition() { Height = new GridLength(1, GridUnitType.Auto) }; RowDefinition dateTimeRow = new RowDefinition() { Height = new GridLength(1, GridUnitType.Auto) }; (control as Grid).RowDefinitions.Add(labelRow); (control as Grid).RowDefinitions.Add(dateTimeRow); TextBlock label = new TextBlock() { Name = controlName + Constants.LABEL_CONTROL_IDENTIFIER, Text = customization == null?controlTypeName.ToString() : customization.LabelDescription, VerticalAlignment = VerticalAlignment.Center, Margin = new Thickness(0, 0, 0, 5) }; Grid.SetRow(label, 0); (control as Grid).Children.Add(label); //if (customization.ReadOnlyMode) //{ // TextBox data = new TextBox() // { // Text = "", // VerticalAlignment = VerticalAlignment.Center, // Margin = new Thickness(0, 0, 0, 5), // Name = controlName + DATA_CONTROL_IDENTIFIER // }; //} //else //{ // TextBlock data = new TextBlock() // { // Text = "", // VerticalAlignment = VerticalAlignment.Center, // Margin = new Thickness(0, 0, 0, 5), // Name = controlName + DATA_CONTROL_IDENTIFIER // }; //} UIElement dateTimeControl; switch (customization.DateTimeMode) { case DatePickerMode.Date: dateTimeControl = new CalendarDatePicker() { Date = DateTime.Today, HorizontalAlignment = HorizontalAlignment.Stretch, Margin = new Thickness(0, 5, 0, 0), PlaceholderText = "Select a date", Name = controlName + Constants.DATA_CONTROL_IDENTIFIER }; break; case DatePickerMode.Time: dateTimeControl = new TimePicker() { Time = DateTime.Now.TimeOfDay, HorizontalAlignment = HorizontalAlignment.Stretch, Margin = new Thickness(0, 5, 0, 0), Name = controlName + Constants.DATA_CONTROL_IDENTIFIER }; break; case DatePickerMode.DateAndTime: throw new Base.Exceptions.NotSupportedException("DateTime combination is not supported."); default: throw new Base.Exceptions.NotSupportedException("Not supported DatePickerMode."); } Grid.SetRow(dateTimeControl as FrameworkElement, 1); (control as Grid).Children.Add(dateTimeControl); break; case PropertyType.notImplementedYet: control = new Grid() { Background = new SolidColorBrush(Colors.Red), Margin = new Thickness(10), Height = 25 }; break; default: throw new NotSupportedPropertyTypeException("Not supported PropertyType."); } } RelativePanel.SetAlignLeftWithPanel(control, true); RelativePanel.SetAlignRightWithPanel(control, true); AddControlUnder(control, ref previousControl); return(control); }
/// <summary> /// Create readonly controls /// </summary> /// <param name="controlAnalyze">Analyze of property</param> /// <param name="previousControl">Previous control</param> /// <returns>New control</returns> internal static UIElement CreateDetailControl(KeyValuePair <string, PropertyAnalyze> controlAnalyze, ref UIElement previousControl) { string controlName = controlAnalyze.Key; PropertyAnalyze controlData = controlAnalyze.Value; PropertyType controlTypeName = controlData.PropertyType; UIElement control; UIParamsAttribute customization = controlData.PropertyAttributes.FirstOrDefault(x => x.GetType() == typeof(UIParamsAttribute)) as UIParamsAttribute; var linkedTableAttribute = controlData.PropertyAttributes.FirstOrDefault(x => x.GetType() == typeof(LinkedTableAttribute)) as LinkedTableAttribute; switch (controlTypeName) { case PropertyType.String: case PropertyType.Int: case PropertyType.Int32: case PropertyType.Double: case PropertyType.Char: case PropertyType.DateTime: case PropertyType.Boolean: if (customization == null && controlTypeName == PropertyType.DateTime) { throw new MissingRequiredAdditionalDataException("Property DateTime require UIParams attribute for specificating design."); } control = new Grid() { Margin = new Thickness(10), VerticalAlignment = VerticalAlignment.Stretch }; RowDefinition labelRow = new RowDefinition() { Height = new GridLength(1, GridUnitType.Auto) }; RowDefinition dateTimeRow = new RowDefinition() { Height = new GridLength(1, GridUnitType.Auto) }; (control as Grid).RowDefinitions.Add(labelRow); (control as Grid).RowDefinitions.Add(dateTimeRow); ColumnDefinition labelColumn = new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Auto) }; ColumnDefinition dataColumn = new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Auto) }; (control as Grid).ColumnDefinitions.Add(labelColumn); (control as Grid).ColumnDefinitions.Add(dataColumn); TextBlock label = new TextBlock() { VerticalAlignment = VerticalAlignment.Bottom, FontWeight = FontWeights.Bold, Margin = new Thickness(0, 0, 5, 0) }; if (customization.UseLabelDescription) { label.Text = customization.LabelDescription ?? ""; } else { label.Text = controlData.PropertyName; } Grid.SetRow(label, 0); (control as Grid).Children.Add(label); if (linkedTableAttribute != null && linkedTableAttribute.LinkedTableRelation == LinkedTableRelation.Many) { ListView linkedTableSelectedIds = new ListView() { Name = controlName + Constants.DATA_CONTROL_IDENTIFIER, VerticalAlignment = VerticalAlignment.Stretch, HorizontalAlignment = HorizontalAlignment.Stretch, Margin = new Thickness(0, 5, 0, 5), Height = 250, SelectionMode = ListViewSelectionMode.None }; Grid.SetRow(linkedTableSelectedIds, 1); Grid.SetColumnSpan(linkedTableSelectedIds, 2); (control as Grid).Children.Add(linkedTableSelectedIds); } else { TextBlock data = new TextBlock() { Text = "", VerticalAlignment = VerticalAlignment.Bottom, Margin = new Thickness(0, 5, 0, 0), Name = controlName + Constants.DATA_CONTROL_IDENTIFIER }; (control as Grid).Children.Add(data); if (customization.ShowDetailOnOneLine) { data.Margin = new Thickness(5, 5, 0, 0); Grid.SetColumn(data, 1); } else { Grid.SetRow(data, 1); } } break; case PropertyType.notImplementedYet: control = new Grid() { Background = new SolidColorBrush(Colors.Red), Margin = new Thickness(10), Height = 25 }; break; default: throw new NotSupportedPropertyTypeException("Not supported PropertyType."); } RelativePanel.SetAlignLeftWithPanel(control, true); RelativePanel.SetAlignRightWithPanel(control, true); AddControlUnder(control, ref previousControl); return(control); }
/// <summary> /// Create UI of selector /// </summary> /// <param name="controlName">Control name</param> /// <param name="controlData">Control data</param> private void CreateUI(string controlName, PropertyAnalyze controlData) { var customization = controlData.PropertyAttributes.FirstOrDefault(x => x.GetType() == typeof(UIParamsAttribute)) as UIParamsAttribute; RowDefinition labelRow = new RowDefinition() { Height = new GridLength(1, GridUnitType.Auto) }; RowDefinition linkedTableControlsRow = new RowDefinition() { Height = new GridLength(1, GridUnitType.Auto) }; RowDefinition linkedTablePresenterRow = new RowDefinition() { Height = new GridLength(250, GridUnitType.Pixel) }; RowDefinitions.Add(labelRow); RowDefinitions.Add(linkedTableControlsRow); RowDefinitions.Add(linkedTablePresenterRow); TextBlock label = new TextBlock() { Name = controlName + Constants.LABEL_CONTROL_IDENTIFIER, Text = customization.LabelDescription, VerticalAlignment = VerticalAlignment.Center, Margin = new Thickness(0, 0, 0, 5) }; SetRow(label, 0); Children.Add(label); ColumnDefinition linkedTablePresenterColumn = new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Auto) }; ColumnDefinition linkedTablePresenterInfoColumn = new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Auto) }; Grid linkedTableControlsRowGrid = new Grid(); linkedTableControlsRowGrid.ColumnDefinitions.Add(linkedTablePresenterColumn); linkedTableControlsRowGrid.ColumnDefinitions.Add(linkedTablePresenterInfoColumn); SetRow(linkedTableControlsRowGrid, 1); Children.Add(linkedTableControlsRowGrid); Button linkedTableRowAdder = new Button() { Content = "Add row", VerticalAlignment = VerticalAlignment.Center, Margin = new Thickness(0, 0, 5, 0) }; linkedTableRowAdder.Click += LinkedTableRowSelector_Click; Button linkedTableRowRemover = new Button() { Content = "Remove row", VerticalAlignment = VerticalAlignment.Center, Margin = new Thickness(5, 0, 0, 0) }; SetColumn(linkedTableRowRemover, 1); linkedTableRowRemover.Click += LinkedTableRowRemover_Click; //TextBlock linkedTableCountRowText = new TextBlock() //{ // Name = controlName + "Label", // //Text = "IDs count:", // VerticalAlignment = VerticalAlignment.Center, // Margin = new Thickness(5, 0, 0, 0) //}; //SetColumn(linkedTableCountRowText, 1); linkedTableControlsRowGrid.Children.Add(linkedTableRowAdder); linkedTableControlsRowGrid.Children.Add(linkedTableRowRemover); linkedTableSelectedIds = new ListBox() { VerticalAlignment = VerticalAlignment.Stretch, HorizontalAlignment = HorizontalAlignment.Stretch, Margin = new Thickness(0, 5, 0, 5) }; SetRow(linkedTableSelectedIds, 2); Children.Add(linkedTableSelectedIds); }
/// <summary> /// Init linked table selector /// </summary> /// <param name="controlData">Control data</param> public LinkedTableSelector(PropertyAnalyze controlData) { linkedTableAttribute = controlData.PropertyAttributes.FirstOrDefault(x => x.GetType() == typeof(LinkedTableAttribute)) as LinkedTableAttribute; }
/// <summary> /// Create UI of selector /// </summary> /// <param name="controlName">Control name</param> /// <param name="controlData">Control data</param> private void CreateUI(string controlName, PropertyAnalyze controlData) { var customization = controlData.PropertyAttributes.FirstOrDefault(x => x.GetType() == typeof(UIParamsAttribute)) as UIParamsAttribute; RowDefinition labelRow = new RowDefinition() { Height = new GridLength(1, GridUnitType.Auto) }; RowDefinition linkedTableControlsRow = new RowDefinition() { Height = new GridLength(1, GridUnitType.Auto) }; RowDefinitions.Add(labelRow); RowDefinitions.Add(linkedTableControlsRow); TextBlock headerLabel = new TextBlock() { Name = controlName + Constants.LABEL_CONTROL_IDENTIFIER, Text = customization.LabelDescription, VerticalAlignment = VerticalAlignment.Center, Margin = new Thickness(0, 0, 0, 5) }; SetRow(headerLabel, 0); Children.Add(headerLabel); ColumnDefinition linkedTableSelectorColumn = new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Auto) }; ColumnDefinition linkedTableCleanerColumn = new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Auto) }; ColumnDefinition linkedTableFreeColumn = new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Auto) }; RowDefinition linkedTableButtonsRow = new RowDefinition() { Height = new GridLength(1, GridUnitType.Auto) }; RowDefinition linkedTableInfoRow = new RowDefinition() { Height = new GridLength(1, GridUnitType.Auto) }; Grid linkedTableControlsRowGrid = new Grid(); linkedTableControlsRowGrid.ColumnDefinitions.Add(linkedTableSelectorColumn); linkedTableControlsRowGrid.ColumnDefinitions.Add(linkedTableCleanerColumn); linkedTableControlsRowGrid.ColumnDefinitions.Add(linkedTableFreeColumn); linkedTableControlsRowGrid.RowDefinitions.Add(linkedTableButtonsRow); linkedTableControlsRowGrid.RowDefinitions.Add(linkedTableInfoRow); SetRow(linkedTableControlsRowGrid, 1); Children.Add(linkedTableControlsRowGrid); Button linkedTableRowSelector = new Button { Content = "Choose row", VerticalAlignment = VerticalAlignment.Center, Margin = new Thickness(0, 0, 5, 5) }; linkedTableRowSelector.Click += LinkedTableRowSelector_Click; Button linkedTableRowCleaner = new Button { Content = "Clear link", VerticalAlignment = VerticalAlignment.Center, Margin = new Thickness(5, 0, 5, 5) }; SetColumn(linkedTableRowCleaner, 1); linkedTableRowCleaner.Click += LinkedTableRowCleaner_Click; TextBlock selectedIdTextLabel = new TextBlock() { Name = controlName + "InfoLabel", Text = "Selected ID: ", VerticalAlignment = VerticalAlignment.Center, Margin = new Thickness(5, 5, 0, 0) }; SetRow(selectedIdTextLabel, 1); selectedIdLabel = new TextBlock() { Name = controlName + "Label", VerticalAlignment = VerticalAlignment.Center, Margin = new Thickness(5, 5, 0, 0) }; SetColumn(selectedIdLabel, 1); SetRow(selectedIdLabel, 1); linkedTableControlsRowGrid.Children.Add(linkedTableRowSelector); linkedTableControlsRowGrid.Children.Add(linkedTableRowCleaner); linkedTableControlsRowGrid.Children.Add(selectedIdTextLabel); linkedTableControlsRowGrid.Children.Add(selectedIdLabel); }