Example #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            HandleItems h    = new HandleItems(checkedListBox1);
            Item1       item = new Item1(textBox1.Text, dateTimePicker1.Value.Date);

            if (textBox1.Text != "")
            {
                int x = 0;
                foreach (Item1 value in list1)
                {
                    if (item.Name_ == value.Name_)
                    {
                        MessageBox.Show("There is already an item with the same name", "Error");
                        x = 1;
                    }
                }
                if (x == 0)
                {
                    if (openFileDialog1.ShowDialog() == DialogResult.OK)
                    {
                        var fileName = string.Empty;
                        var savePath = string.Empty;
                        fileName = openFileDialog1.SafeFileName;
                        savePath = (folder_path + @"\" + textBox1.Text + ".pdf");
                        var file = openFileDialog1.FileName;
                        System.IO.File.Copy(file, savePath);
                        MessageBox.Show("File selected: " + fileName, "File has been added", MessageBoxButtons.OK);

                        h.AddItem(item, list1);
                        textBox1.Clear();
                    }
                    else
                    {
                        MessageBox.Show("No file selected!", "Warning!", MessageBoxButtons.OK);
                    }
                }
            }
            else
            {
                MessageBox.Show("Name can't be empty", "Error");
            }
        }