Ejemplo n.º 1
0
        private void buttonOK_Click(object sender, EventArgs e)
        {
            XMLProfileSettings profile = new XMLProfileSettings();

            SaveCurrentItem();
            profile.PutSetting("Profiles/ProfileCount", comboBoxProfiles.Items.Count);
            for (int i = 0; i < comboBoxProfiles.Items.Count; i++)
            {
                ProfileItem item = comboBoxProfiles.Items[i] as ProfileItem;
                profile.PutSetting("Profiles/" + "Profile" + i.ToString() + "/Name", item.Name);
                profile.PutSetting("Profiles/" + "Profile" + i.ToString() + "/DataFolder", item.DataFolder);
            }

            if (radioButtonAskMe.Checked)
            {
                profile.PutSetting("Profiles/LoadAction", "Ask");
            }
            else
            {
                profile.PutSetting("Profiles/LoadAction", "LoadSelected");
            }

            if (comboBoxLoadThisProfile.SelectedIndex >= 0)
            {
                profile.PutSetting("Profiles/ProfileToLoad", comboBoxLoadThisProfile.SelectedIndex);
            }

            DialogResult = System.Windows.Forms.DialogResult.OK;

            Close();
        }
Ejemplo n.º 2
0
        private void LoadSelectedProfile()
        {
            if (listBoxProfiles.SelectedIndex >= 0)
            {
                ProfileItem item = listBoxProfiles.SelectedItem as ProfileItem;
                DataFolder    = item.DataFolder;
                ProfileName   = item.Name;
                ProfileNumber = item.ProfileNumber;

                XMLProfileSettings profile = new XMLProfileSettings();
                profile.PutSetting(XMLProfileSettings.SettingType.Profiles, "Profile" + ProfileNumber.ToString() + "/DateLastLoaded", DateTime.Now);
                DialogResult = System.Windows.Forms.DialogResult.OK;
                Close();
            }
        }
Ejemplo n.º 3
0
        private void buttonOK_Click(object sender, EventArgs e)
        {
            XMLProfileSettings profile         = new XMLProfileSettings();
            List <string>      checkName       = new List <string>();
            List <string>      checkDataFolder = new List <string>();
            List <string>      duplicateItems  = new List <string>();
            List <string>      checkDataPath   = new List <string>();
            bool duplicateName       = false;
            bool duplicateDataFolder = false;
            bool invalidDataPath     = false;

            //Check for null values, duplicate profile name or datapath and non rooted datapath
            foreach (ProfileItem item in comboBoxProfiles.Items)
            {
                if (item.Name == null || item.DataFolder == null)
                {
                    //messageBox Arguments are (Text, Title, No Button Visible, Cancel Button Visible)
                    MessageBoxForm.msgIcon = SystemIcons.Warning;                     //this is used if you want to add a system icon to the message form.
                    var messageBox = new MessageBoxForm("One or more of your profile entries has a blank name or data folder. You must correct this before continuing.",
                                                        @"Warning - Blank Entries", false, false);
                    messageBox.ShowDialog();
                }

                if (checkName.Contains(item.Name))
                {
                    duplicateName = true;
                    duplicateItems.Add(item.Name + ":\t " + item.DataFolder);
                }
                checkName.Add(item.Name);

                if (checkDataFolder.Contains(item.DataFolder))
                {
                    duplicateDataFolder = true;
                    duplicateItems.Add(item.Name + ":\t " + item.DataFolder);
                }

                checkDataFolder.Add(item.DataFolder);

                if (!Path.IsPathRooted(item.DataFolder) || !item.DataFolder.Contains(@"\"))
                {
                    invalidDataPath = true;
                    checkDataPath.Add(item.Name + ":\t " + item.DataFolder);
                }
            }

            if (duplicateName || duplicateDataFolder)
            {
                //Not pretty here, but works well on the dialog
                //messageBox Arguments are (Text, Title, No Button Visible, Cancel Button Visible)
                MessageBoxForm.msgIcon = SystemIcons.Warning;                 //this is used if you want to add a system icon to the message form.
                var messageBox = new MessageBoxForm("A duplicate profile name, or data path exists." + Environment.NewLine + Environment.NewLine +
                                                    @"The duplicate items found were:" + Environment.NewLine + Environment.NewLine + string.Join(Environment.NewLine, duplicateItems) + Environment.NewLine + Environment.NewLine +
                                                    @"Click OK to accept and contine, or Cancel to go back and edit.",
                                                    @"Warning - Duplicate Entries", false, true);
                messageBox.ShowDialog();

                if (messageBox.DialogResult != DialogResult.OK)
                {
                    DialogResult = DialogResult.None;
                    return;
                }
            }

            if (invalidDataPath)
            {
                //messageBox Arguments are (Text, Title, No Button Visible, Cancel Button Visible)
                MessageBoxForm.msgIcon = SystemIcons.Warning;                 //this is used if you want to add a system icon to the message form.
                var messageBox = new MessageBoxForm("An invalid profile data folder exists." + Environment.NewLine + Environment.NewLine +
                                                    @"The items with invalid paths were:" + Environment.NewLine + Environment.NewLine + string.Join(Environment.NewLine, checkDataPath) + Environment.NewLine + Environment.NewLine +
                                                    @"Click OK to accept and contine, or Cancel to go back and edit.",
                                                    @"Warning - Invalid Data Path", false, true);
                messageBox.ShowDialog();

                if (messageBox.DialogResult != DialogResult.OK)
                {
                    DialogResult = DialogResult.None;
                    return;
                }
            }

            SaveCurrentItem();
            profile.PutSetting(XMLProfileSettings.SettingType.Profiles, "ProfileCount", comboBoxProfiles.Items.Count);
            for (int i = 0; i < comboBoxProfiles.Items.Count; i++)
            {
                ProfileItem item = comboBoxProfiles.Items[i] as ProfileItem;
                profile.PutSetting(XMLProfileSettings.SettingType.Profiles, "Profile" + i + "/Name", item.Name);
                profile.PutSetting(XMLProfileSettings.SettingType.Profiles, "Profile" + i + "/DataFolder", item.DataFolder);
                if (!Directory.Exists(item.DataFolder))
                {
                    //messageBox Arguments are (Text, Title, No Button Visible, Cancel Button Visible)
                    MessageBoxForm.msgIcon = SystemIcons.Exclamation;                     //this is used if you want to add a system icon to the message form.
                    var messageBox = new MessageBoxForm("The data directory '" + item.DataFolder + "' for profile '" + item.Name + "' does not exist.  Would you like to create it?",
                                                        Application.ProductName, true, false);
                    messageBox.ShowDialog();
                    if (messageBox.DialogResult == DialogResult.OK)
                    {
                        try
                        {
                            Directory.CreateDirectory(item.DataFolder);
                        }
                        catch (Exception)
                        {
                            //messageBox Arguments are (Text, Title, No Button Visible, Cancel Button Visible)
                            MessageBoxForm.msgIcon = SystemIcons.Error;                             //this is used if you want to add a system icon to the message form.
                            messageBox             = new MessageBoxForm("Could not create new profile directory: " + item.DataFolder + Environment.NewLine + Environment.NewLine +
                                                                        "Click OK to ignore and continue, or Cancel to go back and edit.",
                                                                        "Error", false, true);
                            messageBox.ShowDialog();
                            if (messageBox.DialogResult == DialogResult.Cancel)
                            {
                                DialogResult = DialogResult.None;
                                return;
                            }
                        }
                    }
                }
            }

            profile.PutSetting(XMLProfileSettings.SettingType.Profiles, "LoadAction",
                               radioButtonAskMe.Checked ? "Ask" : "LoadSelected");

            if (comboBoxLoadThisProfile.SelectedIndex >= 0)
            {
                profile.PutSetting(XMLProfileSettings.SettingType.Profiles, "ProfileToLoad", comboBoxLoadThisProfile.SelectedIndex);
            }

            DialogResult = DialogResult.OK;
            Close();
        }
Ejemplo n.º 4
0
        private void buttonOK_Click(object sender, EventArgs e)
        {
            XMLProfileSettings profile         = new XMLProfileSettings();
            List <string>      checkName       = new List <string>();
            List <string>      checkDataFolder = new List <string>();
            bool duplicateName       = false;
            bool duplicateDataFolder = false;

            SaveCurrentItem();
            profile.PutSetting("Profiles/ProfileCount", comboBoxProfiles.Items.Count);
            for (int i = 0; i < comboBoxProfiles.Items.Count; i++)
            {
                ProfileItem item = comboBoxProfiles.Items[i] as ProfileItem;
                profile.PutSetting("Profiles/" + "Profile" + i.ToString() + "/Name", item.Name);
                profile.PutSetting("Profiles/" + "Profile" + i.ToString() + "/DataFolder", item.DataFolder);
                //We're getting out of here and expect a restart by user, if the specified DataFolder doesn't exist, we should create it.

                if (item.DataFolder != string.Empty)
                {
                    if (!System.IO.Directory.Exists(item.DataFolder))
                    {
                        System.IO.Directory.CreateDirectory(item.DataFolder);
                    }
                }
                if (checkName.Contains(item.Name))
                {
                    duplicateName = true;
                }
                checkName.Add(item.Name);
                if (checkDataFolder.Contains(item.DataFolder))
                {
                    duplicateDataFolder = true;
                }
                checkDataFolder.Add(item.DataFolder);
            }

            if (radioButtonAskMe.Checked)
            {
                profile.PutSetting("Profiles/LoadAction", "Ask");
            }
            else
            {
                profile.PutSetting("Profiles/LoadAction", "LoadSelected");
            }

            if (comboBoxLoadThisProfile.SelectedIndex >= 0)
            {
                profile.PutSetting("Profiles/ProfileToLoad", comboBoxLoadThisProfile.SelectedIndex);
            }

            //If a duplicate entry is found, we will prompt the user to contine on, or cancel and edit. This could be done with one bool, but in the event that we want to
            //be more specific about things in the future, Ill leave it the way it is for now.
            if (duplicateName || duplicateDataFolder)
            {
                if (MessageBox.Show("Duplicate profile entries were found. A duplicate profile name, or data path exists. Click OK to accept and contine, or Cancel to go back and edit.", "Warning", MessageBoxButtons.OKCancel) == DialogResult.OK)
                {
                    DialogResult = System.Windows.Forms.DialogResult.OK;
                    Close();
                }
                else
                {
                    //Too late to cancel without changes, lets not give false hope.
                    buttonCancel.Enabled = false;
                    DialogResult         = System.Windows.Forms.DialogResult.None;
                }
            }
            else
            {
                DialogResult = System.Windows.Forms.DialogResult.OK;
                Close();
            }
        }
Ejemplo n.º 5
0
        private void buttonOK_Click(object sender, EventArgs e)
        {
            XMLProfileSettings profile         = new XMLProfileSettings();
            List <string>      checkName       = new List <string>();
            List <string>      checkDataFolder = new List <string>();
            List <string>      duplicateItems  = new List <string>();
            List <string>      checkDataPath   = new List <string>();
            bool duplicateName       = false;
            bool duplicateDataFolder = false;
            bool invalidDataPath     = false;

            //Check for null values, duplicate profile name or datapath and non rooted datapath
            foreach (ProfileItem item in comboBoxProfiles.Items)
            {
                if (item.Name == null || item.DataFolder == null)
                {
                    MessageBox.Show(
                        @"One or more of your profile entries has a blank name or data folder. You must correct this before continuing.",
                        @"Warning - Blank Entries", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }

                if (checkName.Contains(item.Name))
                {
                    duplicateName = true;
                    duplicateItems.Add(item.Name + ":\t " + item.DataFolder);
                }
                checkName.Add(item.Name);

                if (checkDataFolder.Contains(item.DataFolder))
                {
                    duplicateDataFolder = true;
                    duplicateItems.Add(item.Name + ":\t " + item.DataFolder);
                }

                checkDataFolder.Add(item.DataFolder);

                if (!Path.IsPathRooted(item.DataFolder) || !item.DataFolder.Contains(@"\"))
                {
                    invalidDataPath = true;
                    checkDataPath.Add(item.Name + ":\t " + item.DataFolder);
                }
            }

            if (duplicateName || duplicateDataFolder)
            {
                //Not pretty here, but works well on the dialog
                var result =
                    MessageBox.Show(
                        @"A duplicate profile name, or data path exists." + Environment.NewLine + Environment.NewLine +
                        @"The duplicate items found were:" + Environment.NewLine + Environment.NewLine + string.Join(Environment.NewLine, duplicateItems) + Environment.NewLine + Environment.NewLine +
                        @"Click OK to accept and contine, or Cancel to go back and edit.",
                        @"Warning - Duplicate Entries", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);

                if (result != DialogResult.OK)
                {
                    DialogResult = DialogResult.None;
                    return;
                }
            }

            if (invalidDataPath)
            {
                var result =
                    MessageBox.Show(
                        @"An invalid profile data folder exists." + Environment.NewLine + Environment.NewLine +
                        @"The items with invalid paths were:" + Environment.NewLine + Environment.NewLine + string.Join(Environment.NewLine, checkDataPath) + Environment.NewLine + Environment.NewLine +
                        @"Click OK to accept and contine, or Cancel to go back and edit.",
                        @"Warning - Invalid Data Path", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);

                if (result != DialogResult.OK)
                {
                    DialogResult = DialogResult.None;
                    return;
                }
            }

            SaveCurrentItem();
            profile.PutSetting(XMLProfileSettings.SettingType.Profiles, "ProfileCount", comboBoxProfiles.Items.Count);
            for (int i = 0; i < comboBoxProfiles.Items.Count; i++)
            {
                ProfileItem item = comboBoxProfiles.Items[i] as ProfileItem;
                profile.PutSetting(XMLProfileSettings.SettingType.Profiles, "Profile" + i + "/Name", item.Name);
                profile.PutSetting(XMLProfileSettings.SettingType.Profiles, "Profile" + i + "/DataFolder", item.DataFolder);
                //We're getting out of here and expect a restart by user, if the specified DataFolder doesn't exist, we should create it.

                if (item.DataFolder != string.Empty)
                {
                    if (!Directory.Exists(item.DataFolder))
                    {
                        Directory.CreateDirectory(item.DataFolder);
                    }
                }
            }

            profile.PutSetting(XMLProfileSettings.SettingType.Profiles, "LoadAction",
                               radioButtonAskMe.Checked ? "Ask" : "LoadSelected");

            if (comboBoxLoadThisProfile.SelectedIndex >= 0)
            {
                profile.PutSetting(XMLProfileSettings.SettingType.Profiles, "ProfileToLoad", comboBoxLoadThisProfile.SelectedIndex);
            }

            DialogResult = DialogResult.OK;
            Close();
        }