예제 #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (radioButton2.Checked)
            {                
                DialogResult res;
                if (listBox1 != null && listBox1.Items.Count > 0)
                    folderBrowserDialog1.SelectedPath=(string)listBox1.Items[listBox1.Items.Count - 1];
                else
                    folderBrowserDialog1.SelectedPath = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);

                 res= folderBrowserDialog1.ShowDialog();
                if (res == DialogResult.OK)
                {
                    if (!listBox1.Items.Contains(folderBrowserDialog1.SelectedPath))
                        listBox1.Items.Add(folderBrowserDialog1.SelectedPath);

                    SetDataDirOptions();
                }
            }
            else
            {
                if (radioButton1.Checked)
                {
                    DCDForm dcd;
                    dcd = new DCDForm();


                    if (dcd.ShowDialog() == DialogResult.OK)
                    {
                        listBox1.Items.Add(dcd.dcd);
                        manager.opt.dcdFiles.Add(dcd.dcd);

                        SetDataDirOptions();
                    }
                }
                else
                    if (radioButton3.Checked)
                    {
                        openFileDialog1.Filter = "All files (*)|*";
                        DialogResult res = openFileDialog1.ShowDialog();

                        if (res == DialogResult.OK)
                        {
                            try
                            {
                                StreamReader stR = new StreamReader(openFileDialog1.FileName);
                                string line = stR.ReadLine();
                                while (line != null)
                                {
                                    if (Directory.Exists(line))
                                        listBox1.Items.Add(line);

                                    line = stR.ReadLine();
                                }
                                stR.Close();
                                SetDataDirOptions();
                            }
                            catch (Exception ex)
                            {
                                MessageBox.Show("File cannot be read. Error:" + ex.Message);
                            }
                        }
                    }
                    else
                        if (radioButton4.Checked)
                        {
                            DialogResult res;
                            if (listBox1.Items.Count > 0)
                        {
                                foreach (var item in listBox1.Items)
                                {
                                    if (!((string)item).Contains("profiles"))
                                    {
                                        res=MessageBox.Show("There are incompatible items on the list.\nAll items will be removed.\nDo you want to proceed?", 
                                            "Important question",
                                            MessageBoxButtons.YesNo);
                                        if (res == DialogResult.Yes)
                                        {
                                            listBox1.Items.Clear();                                            
                                            break;
                                        }
                                        else
                                            return;
                                    }
                                }
                            }
                            res = openFileDialog1.ShowDialog();
                            if (res == DialogResult.OK)
                            {
                                listBox1.Items.Add(openFileDialog1.FileName + " profiles");
                                radioButton1.Enabled = false;
                                radioButton2.Enabled = false;
                                radioButton3.Enabled = false;
                                SetDataDirOptions();
                            }
                        }
            }
        }
예제 #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (listBox1 != null && listBox1.Items.Count > 0)
            {
                folderBrowserDialog1.SelectedPath = (string)listBox1.Items[listBox1.Items.Count - 1];
                openFileDialog1.InitialDirectory  = Path.GetDirectoryName((string)listBox1.Items[listBox1.Items.Count - 1]);
            }
            else
            {
                folderBrowserDialog1.SelectedPath = openFileDialog1.InitialDirectory = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) +
                                                                                       Path.DirectorySeparatorChar + "data";
            }

            if (radioButton2.Checked)
            {
                DialogResult res;


                res = folderBrowserDialog1.ShowDialog();
                if (res == DialogResult.OK)
                {
                    //if(folderBrowserDialog1.SelectedPath)
                    if (!listBox1.Items.Contains(folderBrowserDialog1.SelectedPath))
                    {
                        listBox1.Items.Add(folderBrowserDialog1.SelectedPath);
                    }

                    SetDataDirOptions();
                }
            }
            else
            {
                if (radioButton1.Checked)
                {
                    DCDForm dcd;
                    dcd = new DCDForm();


                    if (dcd.ShowDialog() == DialogResult.OK)
                    {
                        listBox1.Items.Add(dcd.dcd);
                        manager.opt.dcdFiles.Add(dcd.dcd);

                        SetDataDirOptions();
                    }
                }
                else
                if (radioButton3.Checked)
                {
                    openFileDialog1.Filter = "All files (*)|*";
                    DialogResult res = openFileDialog1.ShowDialog();

                    if (res == DialogResult.OK)
                    {
                        try
                        {
                            StreamReader stR  = new StreamReader(openFileDialog1.FileName);
                            string       line = stR.ReadLine();
                            while (line != null)
                            {
                                if (Directory.Exists(line))
                                {
                                    listBox1.Items.Add(line);
                                }

                                line = stR.ReadLine();
                            }
                            stR.Close();
                            SetDataDirOptions();
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show("File cannot be read. Error:" + ex.Message);
                        }
                    }
                }
                else
                if (radioButton4.Checked)
                {
                    DialogResult res;
                    if (listBox1.Items.Count > 0)
                    {
                        foreach (var item in listBox1.Items)
                        {
                            if (!((string)item).Contains("profiles"))
                            {
                                res = MessageBox.Show("There are incompatible items on the list.\nAll items will be removed.\nDo you want to proceed?",
                                                      "Important question",
                                                      MessageBoxButtons.YesNo);
                                if (res == DialogResult.Yes)
                                {
                                    listBox1.Items.Clear();
                                    break;
                                }
                                else
                                {
                                    return;
                                }
                            }
                        }
                    }
                    res = openFileDialog1.ShowDialog();
                    if (res == DialogResult.OK)
                    {
                        listBox1.Items.Add(openFileDialog1.FileName + " profiles");
                        radioButton1.Enabled = false;
                        radioButton2.Enabled = false;
                        radioButton3.Enabled = false;
                        SetDataDirOptions();
                    }
                }
            }
        }