Ejemplo n.º 1
0
        public void LoadDataControl()
        {
            switch (Machine.Instance.Setting.MachineSelect)
            {
            case MachineSelection.RTV:
                this.dataControl = new RTVDataControl();
                break;

            case MachineSelection.AFN:
                this.dataControl = new AmphnolDataControl();
                break;

            default:
                this.dataControl = new DefaultDataControl();
                break;
            }
        }
Ejemplo n.º 2
0
        private UserControl BuildControl(FormControlSettings formControlSettings)
        {
            UserControl userControl = null;

            switch (formControlSettings.ObjectType)
            {
            case ObjectTypes.String:
                var stringField = new StringField();

                stringField.BuildDisplay(formControlSettings);

                if (formControlSettings.Required)
                {
                    OnValidate += stringField.Validate;
                }

                stringField.OnControlModified        += s => OnPropertyModified?.Invoke(formControlSettings.FieldFullName, s);
                stringField.OnControlFinishedEditing += s => OnPropertyFinishedEditing?.Invoke(formControlSettings.FieldFullName, s);

                OnAddFieldInsertItems += (Name, Items) =>
                {
                    if (Name == formControlSettings.FieldFullName)
                    {
                        stringField.AddDropdownItems(Items, formControlSettings.Value);
                    }
                };

                //OnSpecialDropdownDisplaying?.Invoke(formControlSettings.FieldFullName);

                userControl = stringField;
                break;

            case ObjectTypes.Password:
                var passwordField = new PasswordField();

                passwordField.BuildDisplay(formControlSettings);

                if (formControlSettings.Required)
                {
                    OnValidate += passwordField.Validate;
                }

                passwordField.OnControlModified        += s => OnPropertyModified?.Invoke(formControlSettings.FieldFullName, s);
                passwordField.OnControlFinishedEditing += s => OnPropertyFinishedEditing?.Invoke(formControlSettings.FieldFullName, s);

                userControl = passwordField;
                break;

            case ObjectTypes.Double:
                var doubleField = new DoubleField();

                doubleField.BuildDisplay(formControlSettings);

                if (formControlSettings.Required)
                {
                    OnValidate += doubleField.Validate;
                }

                doubleField.OnControlModified        += s => OnPropertyModified?.Invoke(formControlSettings.FieldFullName, s);
                doubleField.OnControlFinishedEditing += s => OnPropertyFinishedEditing?.Invoke(formControlSettings.FieldFullName, s);

                userControl = doubleField;
                break;

            case ObjectTypes.Int32:
                var intField = new IntField();

                intField.BuildDisplay(formControlSettings);

                if (formControlSettings.Required)
                {
                    OnValidate += intField.Validate;
                }

                intField.OnControlModified        += s => OnPropertyModified?.Invoke(formControlSettings.FieldFullName, s);
                intField.OnControlFinishedEditing += s => OnPropertyFinishedEditing?.Invoke(formControlSettings.FieldFullName, s);

                userControl = intField;
                break;

            case ObjectTypes.Single:
                var floatField = new FloatField();

                floatField.BuildDisplay(formControlSettings);

                if (formControlSettings.Required)
                {
                    OnValidate += floatField.Validate;
                }

                floatField.OnControlModified        += s => OnPropertyModified?.Invoke(formControlSettings.FieldFullName, s);
                floatField.OnControlFinishedEditing += s => OnPropertyFinishedEditing?.Invoke(formControlSettings.FieldFullName, s);

                userControl = floatField;
                break;

            case ObjectTypes.Boolean:
                var booleanField = new BooleanField();

                booleanField.BuildDisplay(formControlSettings);

                if (formControlSettings.Required)
                {
                    OnValidate += booleanField.Validate;
                }

                booleanField.OnControlModified        += s => OnPropertyModified?.Invoke(formControlSettings.FieldFullName, s);
                booleanField.OnControlFinishedEditing += s => OnPropertyFinishedEditing?.Invoke(formControlSettings.FieldFullName, s);

                userControl = booleanField;
                break;

            case ObjectTypes.SpecialDropdown:
                var specialDropdown = new SpecialDropdownField();

                specialDropdown.BuildDisplay(formControlSettings);

                if (formControlSettings.Required)
                {
                    OnValidate += specialDropdown.Validate;
                }

                OnAddSpecialDropdownItems += (Name, Items) =>
                {
                    if (Name == formControlSettings.FieldFullName)
                    {
                        specialDropdown.AddDropdownItems(Items, formControlSettings.Value);
                    }
                };

                OnSpecialDropdownDisplaying?.Invoke(formControlSettings.FieldFullName, (Name, Items) =>
                {
                    if (Name == formControlSettings.FieldFullName)
                    {
                        specialDropdown.AddDropdownItems(Items, formControlSettings.Value);
                    }
                });

                specialDropdown.OnControlModified        += s => OnPropertyModified?.Invoke(formControlSettings.FieldFullName, s);
                specialDropdown.OnControlFinishedEditing += s => OnPropertyFinishedEditing?.Invoke(formControlSettings.FieldFullName, s);

                userControl = specialDropdown;
                break;

            case ObjectTypes.FolderBrowser:
                var folderStringField = new FolderBrowserField();

                folderStringField.BuildDisplay(formControlSettings);

                if (formControlSettings.Required)
                {
                    OnValidate += folderStringField.Validate;
                }

                folderStringField.OnControlModified        += s => OnPropertyModified?.Invoke(formControlSettings.FieldFullName, s);
                folderStringField.OnControlFinishedEditing += s => OnPropertyFinishedEditing?.Invoke(formControlSettings.FieldFullName, s);

                userControl = folderStringField;
                break;

            case ObjectTypes.TimePicker:
                var timePickerField = new TimePickerField();

                timePickerField.BuildDisplay(formControlSettings);

                timePickerField.OnControlModified        += s => OnPropertyModified?.Invoke(formControlSettings.FieldFullName, s);
                timePickerField.OnControlFinishedEditing += s => OnPropertyFinishedEditing?.Invoke(formControlSettings.FieldFullName, s);

                userControl = timePickerField;
                break;

            case ObjectTypes.Custom:
                if (formControlSettings.FormField.CustomControl != null && formControlSettings.FormField.CustomControl.GetInterface(typeof(ICustomControl).FullName) != null)
                {
                    var customControlClass = (ICustomControl)Activator.CreateInstance(formControlSettings.FormField.CustomControl);
                    if (!(customControlClass is UserControl))
                    {
                        break;
                    }

                    var customControlBase = new CustomControlBase();

                    customControlBase.BuildDisplay(formControlSettings, customControlClass);

                    customControlBase.OnControlModified        += s => OnPropertyModified?.Invoke(formControlSettings.FieldFullName, s);
                    customControlBase.OnControlFinishedEditing += s => OnPropertyFinishedEditing?.Invoke(formControlSettings.FieldFullName, s);

                    userControl = customControlBase;
                }
                break;
            }

            return(userControl);
        }