/// <summary> /// Gets the text field vm. /// </summary> /// <param name="prop">The property.</param> /// <param name="model">The model.</param> /// <param name="textAttr">The text attribute.</param> /// <param name="promptAttr">The prompt attribute.</param> /// <param name="display">The display.</param> /// <param name="fieldEditorAttr">The field editor attribute.</param> /// <returns></returns> private TextFieldViewModel GetTextFieldVM(PropertyInfo prop, IEditableRoot model, TextFieldAttribute textAttr, PromptAttribute promptAttr, DisplayAttribute display, FieldEditorAttribute fieldEditorAttr) { var vm = TextFieldViewModelFactory.CreateExport().Value; vm.NumberOfRows = textAttr.NumberOfRows; vm.Mask = textAttr.Mask; vm.MaskType = textAttr.MaskType; vm.MaxLength = textAttr.NumberOfCharacters; SetupField(prop, promptAttr, display, vm, model); vm.FieldType = GetFieldEditor(prop, fieldEditorAttr); return vm; }
/// <summary> /// Setups the field. /// </summary> /// <param name="prop">The property.</param> /// <param name="promptAttr">The prompt attribute.</param> /// <param name="display">The display.</param> /// <param name="fieldViewModel">The field view model.</param> /// <param name="model">The model.</param> /// <param name="defaultValue">The default value.</param> private static void SetupField(PropertyInfo prop, PromptAttribute promptAttr, DisplayAttribute display, IFieldViewModel fieldViewModel, IEditableRoot model, object defaultValue = null) { fieldViewModel.Property = prop; fieldViewModel.Init(model, prop.GetValue(model, null) ?? defaultValue, null); fieldViewModel.Label = display == null ? prop.Name : display.GetName(); fieldViewModel.IsCalculated = prop.GetCustomAttributes(typeof(CalculatedAttribute), false).Length > 0; //fieldViewModel.WidthPercentage = 1.0; // (commonSettingsAttr == null || commonSettingsAttr.HideFromDetails) ? 0.4 : commonSettingsAttr.Width / 100; fieldViewModel.IsVisible = true; fieldViewModel.Prompt = promptAttr == null ? string.Format(CultureInfo.InvariantCulture, LanguageService.Translate("Tooltip_EnterPrompt"), fieldViewModel.Label) : promptAttr.PromptString; //fieldViewModel.ShowDocumentation = docAttr != null; //fieldViewModel.Documentation = docAttr == null ? null : ClrUnicodeConverter.ToText(docAttr.DocumentationBody); }
/// <summary> /// Gets the date time field vm. /// </summary> /// <param name="prop">The property.</param> /// <param name="model">The model.</param> /// <param name="dateAttr">The date attribute.</param> /// <param name="promptAttr">The prompt attribute.</param> /// <param name="display">The display.</param> /// <param name="fieldEditorAttr">The field editor attribute.</param> /// <returns></returns> private DateTimeFieldViewModel GetDateTimeFieldVM(PropertyInfo prop, IEditableRoot model, DateTimeFormatAttribute dateAttr, PromptAttribute promptAttr, DisplayAttribute display, FieldEditorAttribute fieldEditorAttr) { var vm = DateTimeFieldViewModelFactory.CreateExport().Value; vm.InputMode = dateAttr.Value; SetupField(prop, promptAttr, display, vm, model); vm.FieldType = GetFieldEditor(prop, fieldEditorAttr); return vm; }
/// <summary>Gets the schedule date field vm.</summary> /// <param name="prop">The property.</param> /// <param name="model">The model.</param> /// <param name="promptAttr">The prompt attribute.</param> /// <param name="display">The display.</param> /// <param name="fieldEditorAttr">The field editor attribute.</param> /// <returns></returns> private ScheduleDateFieldViewModel GetScheduleDateFieldVM(PropertyInfo prop, IEditableRoot model, PromptAttribute promptAttr, DisplayAttribute display, FieldEditorAttribute fieldEditorAttr) { var vm = ScheduleDateFieldViewModelFactory.CreateExport().Value; SetupField(prop, promptAttr, display, vm, model); vm.FieldType = GetFieldEditor(prop, fieldEditorAttr); return vm; }
/// <summary> /// Gets the numeric field view model vm. /// </summary> /// <param name="prop">The property.</param> /// <param name="model">The model.</param> /// <param name="promptAttr">The prompt attribute.</param> /// <param name="display">The display.</param> /// <param name="fieldEditorAttr">The field editor attribute.</param> /// <param name="numericAttr">The numeric attribute.</param> /// <returns></returns> private NumericFieldViewModel GetNumericFieldViewModelVM(PropertyInfo prop, IEditableRoot model, PromptAttribute promptAttr, DisplayAttribute display, FieldEditorAttribute fieldEditorAttr, NumericAttribute numericAttr) { var vm = NumericFieldViewModelFactory.CreateExport().Value; SetupField(prop, promptAttr, display, vm, model, 0); vm.FieldType = GetFieldEditor(prop, fieldEditorAttr); vm.NumericType = numericAttr.NumericType; vm.NumberOfDigits = numericAttr.NumberOfDigits; return vm; }
/// <summary> /// Gets the checkbox field vm. /// </summary> /// <param name="prop">The property.</param> /// <param name="model">The model.</param> /// <param name="promptAttr">The prompt attribute.</param> /// <param name="display">The display.</param> /// <param name="fieldEditorAttr">The field editor attribute.</param> /// <returns></returns> private FieldViewModel GetCheckboxFieldVM(PropertyInfo prop, IEditableRoot model, PromptAttribute promptAttr, DisplayAttribute display, FieldEditorAttribute fieldEditorAttr) { var vm = FieldViewModelFactory.CreateExport().Value; SetupField(prop, promptAttr, display, vm, model); vm.FieldType = GetFieldEditor(prop, fieldEditorAttr); foreach (var nameValueAttribute in prop.GetCustomAttributes(typeof(NameValueAttribute), true).Cast<NameValueAttribute>()) vm.AddProperty(GetAttributeName(nameValueAttribute), nameValueAttribute.Value.GetType(), true); foreach (var nameValueAttribute in prop.GetCustomAttributes(typeof(NameValueAttribute), true).Cast<NameValueAttribute>()) vm.SetPropertyValue(GetAttributeName(nameValueAttribute), nameValueAttribute.Value); return vm; }
/// <summary> /// Gets the cr field vm. /// </summary> /// <param name="prop">The property.</param> /// <param name="model">The model.</param> /// <param name="crossRefAttr">The cross reference attribute.</param> /// <param name="promptAttr">The prompt attribute.</param> /// <param name="display">The display.</param> /// <param name="fieldEditorAttr">The field editor attribute.</param> /// <returns></returns> private ICrossRefFieldViewModelBase GetCRFieldVM(PropertyInfo prop, IEditableRoot model, CrossRefFieldAttribute crossRefAttr, PromptAttribute promptAttr, DisplayAttribute display, FieldEditorAttribute fieldEditorAttr) { ICrossRefFieldViewModelBase crossReffieldViewModel; dynamic defaultValue = null; if (crossRefAttr.AllowMultiple) { crossReffieldViewModel = MultiCrossRefFieldViewModelFactory.CreateExport().Value; var crType = TheDynamicTypeManager.GetCrossReferenceListType(model.ProcessName, prop.Name); defaultValue = Activator.CreateInstance(crType); } else { var vm = SingleCrossRefFieldViewModelFactory.CreateExport().Value; vm.AllowAddNew = false; // crossRefAttr.AllowAddNew; vm.AllowViewDetail = false; // crossRefAttr.AllowViewDetail; vm.AllowClear = crossRefAttr.AllowClear; crossReffieldViewModel = vm; } crossReffieldViewModel.List = null; crossReffieldViewModel.ReferenceName = crossRefAttr.ReferenceTableName; crossReffieldViewModel.DisplayField = crossRefAttr.RefFieldName; crossReffieldViewModel.DisplayPath = crossRefAttr.DisplayFieldList; crossReffieldViewModel.FieldType = crossRefAttr.AllowMultiple ? "MultiCrossRef" : "SingleCrossRef"; crossReffieldViewModel.ItemProcess = crossRefAttr.ReferenceTableName; SetupField(prop, promptAttr, display, crossReffieldViewModel, model, defaultValue); crossReffieldViewModel.ItemType = crossReffieldViewModel.List != null ? crossReffieldViewModel.List.GetType().BaseType.GetGenericArguments()[1] : TheDynamicTypeManager.GetCrossReferenceItemType(model.ProcessName, prop.Name); return crossReffieldViewModel; }
private static void SetupField(PropertyInfo prop, CommonSettingsAttribute commonSettingsAttr, DocumentationAttribute docAttr, PromptAttribute promptAttr, object display, IFieldViewModel fieldViewModel, IEditableRoot model, IDetailsViewModel detailsViewModel) { fieldViewModel.Property = prop; fieldViewModel.Init(model, prop.GetValue(model, null), detailsViewModel); fieldViewModel.Label = display == null ? prop.Name : ((DisplayAttribute)display).GetName(); fieldViewModel.WidthPercentage = (commonSettingsAttr == null || commonSettingsAttr.HideFromDetails) ? 0.4 : commonSettingsAttr.Width / 100; fieldViewModel.Section = (commonSettingsAttr == null || commonSettingsAttr.HideFromDetails) ? string.Empty : commonSettingsAttr.Section; fieldViewModel.Position = (commonSettingsAttr == null || commonSettingsAttr.HideFromDetails) ? 0 : commonSettingsAttr.Position; fieldViewModel.RowSpan = (commonSettingsAttr == null) ? 1 : commonSettingsAttr.RowSpan; fieldViewModel.Section = commonSettingsAttr == null ? string.Empty : commonSettingsAttr.Section; fieldViewModel.ShowDocumentation = docAttr != null; fieldViewModel.Documentation = docAttr == null ? null : ClrUnicodeConverter.ToText(docAttr.DocumentationBody); fieldViewModel.Prompt = promptAttr == null ? string.Format(CultureInfo.InvariantCulture, LanguageService.Translate("Tooltip_EnterPrompt"), fieldViewModel.Label) : promptAttr.PromptString; fieldViewModel.IsCalculated = prop.GetCustomAttributes(typeof(CalculatedAttribute), false).Length > 0; fieldViewModel.ParentDetailsVM = detailsViewModel; }
private IFieldViewModel SetupDateTimeFieldViewModel(PropertyInfo prop, IEditableRoot model, IDetailsViewModel detailsViewModel, DateTimeFormatAttribute dateAttr, FieldEditorAttribute fieldEditorAttr, CommonSettingsAttribute commonSettingsAttr, DocumentationAttribute docAttr, PromptAttribute promptAttr, object display) { var vm = DateTimeFieldViewModelFactory.CreateExport().Value; vm.InputMode = dateAttr.Value; vm.FieldType = GetFieldEditor(prop, fieldEditorAttr); SetupField(prop, commonSettingsAttr, docAttr, promptAttr, display, vm, model, detailsViewModel); return vm; }