Exemple #1
0
        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            DataConfigSetting          setting = value as DataConfigSetting;
            IWindowsFormsEditorService edSvc   = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));

            if (setting.Type == DataConfigSetting.TYPE.FILENAME ||
                setting.Type == DataConfigSetting.TYPE.FILENAME1)
            {
                OpenFileDialog dlg      = new OpenFileDialog();
                string[]       rgstrExt = setting.Extra.Split(',');

                string strFilter = "Data Files(";
                foreach (string strExt in rgstrExt)
                {
                    strFilter += "*." + strExt;
                    strFilter += ", ";
                }

                strFilter  = strFilter.TrimEnd(',', ' ');
                strFilter += ")|";

                foreach (string strExt in rgstrExt)
                {
                    strFilter += "*." + strExt;
                    strFilter += ";";
                }

                strFilter  = strFilter.TrimEnd(';');
                strFilter += "||";

                dlg.Filter     = strFilter;
                dlg.Title      = "Select the " + setting.Name;
                dlg.DefaultExt = setting.Extra;
                dlg.FileName   = (string)setting.Value;

                if (setting.Type == DataConfigSetting.TYPE.FILENAME1)
                {
                    dlg.CheckFileExists = false;
                }

                if (dlg.ShowDialog() == DialogResult.OK)
                {
                    setting.Value = dlg.FileName;
                }
                else
                {
                    setting.Value = "";
                }
            }
            else if (setting.Type == DataConfigSetting.TYPE.DIRECTORY)
            {
                FormSelectFolder dlg = new FormSelectFolder(setting.Value.ToString());

                if (dlg.ShowDialog() == DialogResult.OK)
                {
                    setting.Value = dlg.SelectedFolder;
                }
            }
            else if (setting.Type == DataConfigSetting.TYPE.LIST)
            {
                if (edSvc != null)
                {
                    ListBox list = new ListBox();

                    list.SelectedIndexChanged += new EventHandler(list_SelectedIndexChanged);

                    OptionItem item = setting.Value as OptionItem;

                    foreach (OptionItem option in item.Options)
                    {
                        list.Items.Add(option.Name);
                    }

                    list.Tag = edSvc;
                    edSvc.DropDownControl(list);

                    if (list.SelectedItem != null)
                    {
                        OptionItem selectedItem = item.Options.Find(list.SelectedItem.ToString());
                        selectedItem.Options = item.Options;

                        setting.Value = selectedItem;
                    }
                }
            }
            else if (setting.Type == DataConfigSetting.TYPE.DATETIME)
            {
                if (edSvc != null)
                {
                    DateTime dt = DateTime.Parse(setting.Value.ToString());

                    FormDateTime dlg = new FormDateTime(dt);
                    if (dlg.ShowDialog() == DialogResult.OK)
                    {
                        setting.Value = dlg.SelectedDateTime.ToString();
                    }
                }
            }
            else if (setting.Type == DataConfigSetting.TYPE.CUSTOM)
            {
                if (setting.VerifyInterface != null)
                {
                    setting.VerifyInterface.GetCustomSetting(setting.Name, setting.Extra, (DataConfigSetting[])context.Instance);
                }
            }
            else
            {
                if (edSvc != null)
                {
                    TextBox edt = new TextBox();

                    edt.Text = setting.Value.ToString();
                    edt.Tag  = edSvc;

                    edSvc.DropDownControl(edt);

                    if (setting.Type == DataConfigSetting.TYPE.INTEGER)
                    {
                        int nVal;

                        if (!int.TryParse(edt.Text, out nVal))
                        {
                            throw new Exception("The value specified for '" + setting.Name + "' is invalid.  Please enter a valid INTEGER number.");
                        }
                    }
                    else if (setting.Type == DataConfigSetting.TYPE.REAL)
                    {
                        double dfVal;

                        if (!double.TryParse(edt.Text, out dfVal))
                        {
                            throw new Exception("The value specified for '" + setting.Name + "' is invalid.  Please enter a valid REAL number.");
                        }
                    }

                    setting.Value = edt.Text;
                }
            }

            if (setting.VerifyInterface != null)
            {
                setting.VerifyInterface.VerifyConfiguration((DataConfigSetting[])context.Instance);
            }

            return(value);
        }
Exemple #2
0
        public OptionItem Clone()
        {
            OptionItem item = new OptionItem(m_strName, m_nIdx, Options);

            return(item);
        }