Esempio n. 1
0
        public SettingEditForm(Setting setting, WorkingDirectoryObject directory)
        {
            InitializeComponent();

            this.setting = setting;
            this.directory = directory;

            comboBox1.DataSource = Enum.GetNames(typeof(ValueDataType)).OrderBy(s => s).ToArray();
            comboBox1.SelectedItem = "String";

            if (setting != null)
            {
                SetEditorWithValue(setting);

                textKey.Text = setting.Key;
                textInfo.Text = setting.Info;
                textObjectId.EditValue = setting.ObjectId;
            }
            else
            {
                SetEditor(ValueDataType.String); 
            }

            comboBox1.SelectedIndexChanged += ComboBox1_SelectedIndexChanged;
        }
Esempio n. 2
0
        private async Task<bool> ValidateInputAsync()
        {
            if (string.IsNullOrWhiteSpace(textKey.Text))
            {
                textKey.ErrorText = "Enter a Name";
                return false;
            }
            else
            {
                if (textObjectId.EditValue == null)
                {
                    textObjectId.ErrorText = "Invalid ObjectId";
                    return false;
                }

                if (setting == null && await directory.Exists(int.Parse(textObjectId.Text), textKey.Text))
                {
                    textKey.ErrorText = "A Setting Key with this name already in exist";
                    return false;
                }

                if (setting == null)
                {
                    setting = new Setting();
                }

                if (!Editor.ValidateValue())
                {
                    return false;
                }

                setting.Value = Editor.Value;
                setting.ValueType = Editor.ValueType;
                setting.Info = textInfo.Text;
                setting.ObjectId = int.Parse(textObjectId.Text);
                setting.Key = textKey.Text.Trim();

                return true;
            }
        } 
Esempio n. 3
0
        private void SetEditorWithValue(Setting setting)
        {
            SetEditor(setting.ValueType);

            try
            {
                if (Editor.ValidateValue(setting.Value))
                {
                    Editor.Value = setting.Value;
                }
                else
                {
                    throw new ArgumentException("Value");
                }
            }
            catch (Exception)
            {
                MessageBox.Show(string.Format("Could not initialize the editor for type '{0}' with the provided value.", setting.ValueType.ToString()));
                SetEditor(ValueDataType.Custom);
                Editor.Value = setting.Value;
            }
        }