Create() public static method

public static Create ( AutoCatType type, string name ) : AutoCat
type AutoCatType
name string
return AutoCat
示例#1
0
        private void CreateNewAutoCat()
        {
            string       name = string.Empty;
            AutoCatType  t    = AutoCatType.None;
            bool         good = true;
            DialogResult result;

            do
            {
                using (DlgAutoCatCreate dialog = new DlgAutoCatCreate())
                {
                    result = dialog.ShowDialog();
                    if (result != DialogResult.OK)
                    {
                        continue;
                    }

                    good = true;
                    name = dialog.SelectedName;
                    t    = dialog.SelectedType;
                }

                if (string.IsNullOrEmpty(name))
                {
                    MessageBox.Show(GlobalStrings.DlgAutoCat_MustHaveName);
                    good = false;
                }
                else if (NameExists(name))
                {
                    MessageBox.Show(GlobalStrings.DlgAutoCat_NameInUse);
                    good = false;
                }
                else if (t == AutoCatType.None)
                {
                    MessageBox.Show(GlobalStrings.DlgAutoCat_SelectValidType);
                    good = false;
                }
            } while (result == DialogResult.OK && !good);

            AutoCat newAutoCat = null;

            if (result == DialogResult.OK)
            {
                newAutoCat = AutoCat.Create(t, name);
                if (newAutoCat != null)
                {
                    AutoCatList.Add(newAutoCat);
                }
            }

            AutoCatList.Sort();
            FillAutocatList();
            if (newAutoCat != null)
            {
                lstAutoCats.SelectedItem = newAutoCat;
            }
        }
示例#2
0
        private void CreateNewAutoCat()
        {
            string       name = string.Empty;
            AutoCatType  t    = AutoCatType.None;
            bool         good = true;
            DialogResult res;

            do
            {
                DlgAutoCatCreate dlg = new DlgAutoCatCreate();
                res = dlg.ShowDialog();
                if (res == System.Windows.Forms.DialogResult.OK)
                {
                    good = true;
                    name = dlg.SelectedName;
                    t    = dlg.SelectedType;
                    if (string.IsNullOrEmpty(name))
                    {
                        MessageBox.Show(GlobalStrings.DlgAutoCat_MustHaveName);
                        good = false;
                    }
                    else if (NameExists(name))
                    {
                        MessageBox.Show(GlobalStrings.DlgAutoCat_NameInUse);
                        good = false;
                    }
                    else if (t == AutoCatType.None)
                    {
                        MessageBox.Show(GlobalStrings.DlgAutoCat_SelectValidType);
                        good = false;
                    }
                }
            } while(res == DialogResult.OK && !good);
            if (res == DialogResult.OK)
            {
                AutoCat newAutoCat = AutoCat.Create(t, name);
                if (newAutoCat != null)
                {
                    AutoCatList.Add(newAutoCat);
                }
            }
            AutoCatList.Sort();
            FillAutocatList();
        }