Exemplo n.º 1
0
        private int getNextID()
        {
            RequestMedicineController rp    = new RequestMedicineController();
            List <Medicine>           lista = rp.GetAll();
            int number = 0;

            foreach (Medicine r in lista)
            {
                if (r.id > number)
                {
                    number = r.id;
                }
            }
            number += 1;
            return(number);
        }
Exemplo n.º 2
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            name        = Name.Text;
            quantity    = Quantity.Text;
            description = Description.Text;
            id          = getNextID();
            DoctorController  DoctorContr = new DoctorController();
            List <DoctorUser> listad      = new List <DoctorUser>();

            listad = DoctorContr.GetAll();


            Regex regex1 = new Regex(@"^([0-9]+)$");


            if (!regex1.IsMatch(quantity))
            {
                MessageBox.Show("Please, insert a number for quantity!", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }


            Lista stt = (Lista)Combo.Items.GetItemAt(Combo.SelectedIndex);

            String[] str = stt.Name.Split(' ');


            foreach (DoctorUser dok in listad)
            {
                if (str[0].Equals(dok.id.ToString()))
                {
                    doktor = dok;
                }
            }

            if (name == "" || quantity == "" || description == "")
            {
                MessageBox.Show("Please, fill all fields!", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            List <ModelRoom> rooms = new List <ModelRoom>();



            Room           s         = new Room();
            RoomController RoomContr = new RoomController();
            List <Room>    l         = new List <Room>();

            l = RoomContr.GetAll();
            Medicine med = new Medicine();

            RequestMedicineController MedContr  = new RequestMedicineController();
            MedicineController        MMedContr = new MedicineController();
            List <Medicine>           lista     = new List <Medicine>();

            lista = MedContr.GetAll();


            Boolean valid = MMedContr.isNameValid(name);



            if (!valid)
            {
                MessageBox.Show("Medicine with this name already exists", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }



            med = new Medicine(id, name, int.Parse(quantity), description, rooms, doktor, true);

            MedContr.New(med);



            GridMain.Children.Clear();
            UserControl usc = new ListOfMedicine();

            GridMain.Children.Add(usc);
        }