private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            if (nameTxtBox.Text != null && categoryTxtBox.Text != null)
            {
                try
                {
                    Medicine medicine = new Medicine();
                    medicine.Name = nameTxtBox.Text;
                    medicine.Price = int.Parse(priceTxtBox.Text);
                    medicine.Quantity = int.Parse(quantityTxtBox.Text);
                    medicine.Category = categoryTxtBox.Text;
                    medicine.ExpireDate = (System.DateTime)datePicker.SelectedDate;

                    MessageBox.Show(medicine.Name + "\n" +
                            medicine.Price + "\n" +
                            medicine.Quantity + "\n" +
                            medicine.Category + "\n" +
                            medicine.ExpireDate + "\n");
                    try
                    {
                        MainWindow.db.Medicines.Add(medicine);
                        MainWindow.db.SaveChanges();
                        dataGrid.ItemsSource = MainWindow.db.Medicines.ToList();
                    }
                    catch
                    {
                        MessageBox.Show("Errod adding medicine");
                    }
                }
                catch
                {
                    MessageBox.Show("All Fields are required");
                }
            } else MessageBox.Show("All Fields are required");
        }
Esempio n. 2
0
        /////////////////////////////////////////////////////////////// TIFA'S TASK
        private void RemoveBtnClicked(object sender, RoutedEventArgs e)
        {
            try
            {
                Medicine deletedata = new Medicine();
                Medicine data = MainWindow.db.Medicines.Single(c => c.Name == SearchBox.Text);
                MainWindow.db.Medicines.Remove(data); // DeleteOnSubmit()
                MainWindow.db.SaveChanges();
                MessageBox.Show(data.Name + "\n" + "Returned Successfully");
            }
            catch
            {
                MessageBox.Show(SearchBox.Text + "\n" + "not Found");
            }

            medicineData.ItemsSource = MainWindow.db.Medicines.ToList();

        }
Esempio n. 3
0
 /////////////////////////////////////////////////////////////// DOAA'S TASK
 private void GetMedicineButton_Click(object sender, RoutedEventArgs e)
 {
     if (SearchBox.Text != "")
     {
         string searchItem = SearchBox.Text;
         Medicine medicine = new Medicine();
         medicineData.Visibility = Visibility.Visible;
         var query = db.Medicines.Where(med => med.Name.Contains(searchItem)).ToList();
         medicineData.ItemsSource = query;
         if (medicineData.ItemsSource != null)
         {
             removeBtn.Visibility = Visibility.Visible;
         }
     }
     else
     {
         medicineData.ItemsSource = MainWindow.db.Medicines.ToList();
     }
 }