Beispiel #1
0
        private void addMedicine_Click(object sender, EventArgs e)
        {
            Medicine medicine = new Medicine(medicineName.Text, medicineCountry.Text, Convert.ToDecimal(medicinePrice.Text), medicineExpire.Value);

            admin.AddMedicine(medicine);

            Stream         myStream;
            OpenFileDialog selectPicture = new OpenFileDialog()
            {
                InitialDirectory = "C:\\", Filter = "Image Files (*.bmp;*.jpg;*.jpeg,*.png)|*.BMP;*.JPG;*.JPEG;*.PNG"
            };

            if (selectPicture.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    if ((myStream = selectPicture.OpenFile()) != null)
                    {
                        using (myStream)
                        {
                            medicine.AddPicture(imageToByteArray(new Bitmap(myStream)));
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message);
                }
            }

            medicineCountry.Text = medicineName.Text = medicinePrice.Text = "";

            medicines.Add(medicine);
            allMedicine_Click(0, EventArgs.Empty);
        }