Beispiel #1
0
        private void DeleteFridgeFromDatabase()
        {
            using (hotelDBEntities context = new hotelDBEntities())
            {
                int    id_fridge      = 0;
                Fridge selectedfridge = context.Fridges.FirstOrDefault(r => r.name == combo_fridgenames.Text);
                id_fridge = selectedfridge.id_fr;

                List <Room> roomlist = context.Rooms.ToList();
                foreach (Room room in roomlist)
                {
                    if (room.id_fr == id_fridge)
                    {
                        MessageBox.Show("Lednice je používána v pokoji : " + room.id_ro.ToString() + "\nPrvní lednici zaměň za jinčí !");
                        return;
                    }
                }

                Fridge fridge = context.Fridges.FirstOrDefault(r => r.name == combo_fridgenames.Text);
                context.Fridges.Remove(fridge);
                context.SaveChanges();
                MessageBox.Show("Lednice odstraněna z databáze !");

                FillCombobox_Fridgenames();
            }
        }
Beispiel #2
0
 private void AddProductsFromStorageToFridge()
 {
     using (hotelDBEntities context = new hotelDBEntities())
     {
         int id_storage = GetStorageIdByComboboxText(combo_storages);
         int id_product = GetProductIdByComboboxText(combo_products);
         int id_fridge  = GetFridgeIdByComboboxText(combo_fridges);
         int amount     = Int32.Parse(txt_howmuchproducts_tofridge.Text);
         if (IsEnoughAmountInStorage(id_storage, id_product, amount) == true)
         {
             if (DoesProductInFridgeExists(id_fridge, id_product) == true)
             {
                 DeleteStorageProductAmount(id_storage, id_product, amount); // Smazat počet produktů ze skladu ("přesunutí") OK
                 UpdateFridgeProducts(id_fridge, id_product, amount);        // Pokud záznam existuje, updatuju (+amount)
             }
             else
             {
                 DeleteStorageProductAmount(id_storage, id_product, amount); // Smazat počet produktů ze skladu ("přesunutí") OK
                 context.Product_Fridge.Add(new Product_Fridge {
                     id_pr = id_product, id_fr = id_fridge, amount = amount
                 });                                                                                                        // Pokud záznam neexistuje, vytvořím s daným počtem
             }
             context.SaveChanges();
             MessageBox.Show("Produkty přesunuty ze skladu do lednice !");
         }
         else
         {
             MessageBox.Show("Nedostatek produktů na přesunutí !");
         }
     }
 }
        private void Btn_pay_Click(object sender, RoutedEventArgs e)
        {
            using (hotelDBEntities context = new hotelDBEntities())
            {
                Reservation reservation = context.Reservations.FirstOrDefault(r => r.id_re == id_reservation);

                List <view_RoomReservations> roomreservationlist = context.view_RoomReservations.ToList();
                foreach (view_RoomReservations roomreservation in roomreservationlist)
                {
                    if (roomreservation.id_re == id_reservation)
                    {
                        // Price_total + ( count_days(from-to) * price_per_day )
                        decimal priceperday = roomreservation.price_per_day.Value;
                        reservation.price_total = reservation.price_total + (CalculateDaysBetweenTwoDates(reservation.date_from, reservation.date_to) * priceperday);
                        reservation.ispayed     = true;
                        context.SaveChanges();
                    }
                }
                // Uložím do JSON filu všechny zaplacené rezervace
                List <view_AllPayedReservations> payedreservationlist = context.view_AllPayedReservations.ToList();
                string jsonoutput = JsonConvert.SerializeObject(payedreservationlist, Formatting.Indented, new JsonSerializerSettings()
                {
                    ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore
                });
                Console.WriteLine(jsonoutput);
                System.IO.File.WriteAllText(@"D:\jsontestLISTjson.json", string.Empty);
                System.IO.File.WriteAllText(@"D:\jsontestLISTjson.json", jsonoutput);
                MessageBox.Show("Zaplaceno !");
            }
        }
        private void AddReservationToDatabase()
        {
            using (hotelDBEntities context = new hotelDBEntities())
            {
                DateTime    datefrom       = date_reservationfrom.SelectedDate.Value.Date;
                DateTime    dateto         = date_reservationto.SelectedDate.Value.Date;
                Reservation newreservation = context.Reservations.Add(new Reservation {
                    firstname = txt_firstname.Text, lastname = txt_lastname.Text, phone = txt_phone.Text, email = txt_email.Text, address = txt_adress.Text, date_from = datefrom, date_to = dateto
                });

                List <Room>     roomlist     = new List <Room>();     // Prázdný list roomů
                List <ComboBox> comboboxlist = new List <ComboBox>(); // Vyplním list comboboxů
                int             roomid       = Convert.ToInt32(combo_rooms1.Text);
                Room            selectedroom = context.Rooms.FirstOrDefault(r => r.id_ro == roomid);
                roomlist.Add(selectedroom);                                  // První room, který musí být ... nemůže být rezervace bez pokoje. Může být však jen jeden
                foreach (ComboBox combobox in stackpanel_morerooms.Children) // Pro každý další combobox v stackpanelu s dynamickým přidáváním projedu a přidám pokoj do roomlistu
                {
                    int  anotherroomid = Convert.ToInt32(combobox.Text);
                    Room anotherroom   = context.Rooms.FirstOrDefault(r => r.id_ro == anotherroomid);
                    roomlist.Add(anotherroom);
                }
                foreach (Room room in roomlist) // Přidám každý room v roomlistu do dané rezervace
                {
                    newreservation.Rooms.Add(room);
                }
                context.SaveChanges();
                MessageBox.Show("Rezervace přidána do databáze !");
                EmptyAllToolboxesInReservation();
            }
        }
Beispiel #5
0
 private void DeleteProductFromDatabase()
 {
     using (hotelDBEntities context = new hotelDBEntities())
     {
         Product product = context.Products.FirstOrDefault(r => r.name == combo_productnames.Text);
         context.Products.Remove(product);
         context.SaveChanges();
         MessageBox.Show("Produkt odstraněn z databáze !");
     }
     FillCombobox_Productnames();
 }
Beispiel #6
0
 public void DeleteFridgeProducts(int id_fridge, int id_product, int amount)
 {
     using (hotelDBEntities context = new hotelDBEntities())
     {
         Product_Fridge fridge_product = context.Product_Fridge.FirstOrDefault(r => (r.id_fr == id_fridge) && (r.id_pr == id_product));
         int?           currentamount  = fridge_product.amount;
         currentamount         = currentamount - amount;
         fridge_product.amount = currentamount;
         context.SaveChanges();
     }
 }
Beispiel #7
0
 private void DeleteStorageFromDatabase()
 {
     using (hotelDBEntities context = new hotelDBEntities())
     {
         Storage storage = context.Storages.FirstOrDefault(r => r.name == combo_storagenames.Text);
         context.Storages.Remove(storage);
         context.SaveChanges();
         MessageBox.Show("Sklad odstraněn z databáze !");
     }
     FillCombobox_Storagenames();
 }
Beispiel #8
0
 private void DeleteStorageProductAmount(int id_storage, int id_product, int amount)
 {
     using (hotelDBEntities context = new hotelDBEntities())
     {
         Storage_Product storage_product = context.Storage_Product.FirstOrDefault(r => (r.id_st == id_storage) && (r.id_pr == id_product));
         int?            currentamount   = storage_product.amount;
         currentamount          = currentamount - amount;
         storage_product.amount = currentamount;
         context.SaveChanges();
     }
 }
Beispiel #9
0
 private void DeleteAttributeFromDatabase()
 {
     using (hotelDBEntities context = new hotelDBEntities())
     {
         Attribute attribute = context.Attributes.FirstOrDefault(r => r.name == combo_attributenames.Text);
         context.Attributes.Remove(attribute);
         context.SaveChanges();
         MessageBox.Show("Vlastnost odstraněna z databáze !");
     }
     FillCombobox_Attributenames();
 }
Beispiel #10
0
 private void DeleteRoomFromDatabase()
 {
     using (hotelDBEntities context = new hotelDBEntities())
     {
         int  id_room = Int32.Parse(combo_roomnames.Text);
         Room room    = context.Rooms.FirstOrDefault(r => r.id_ro == id_room);
         context.Rooms.Remove(room);
         context.SaveChanges();
         MessageBox.Show("Pokoj odstraněn z databáze !");
     }
     FillCombobox_Roomnames();
 }
Beispiel #11
0
 private void AddStorageToDatabase(string name)
 {
     using (hotelDBEntities context = new hotelDBEntities())
     {
         context.Storages.Add(new Storage {
             name = txt_storagename.Text
         });
         context.SaveChanges();
         MessageBox.Show("Sklad přidán do databáze !");
         txt_storagename.Text = String.Empty;
         FillCombobox_Storagenames();
     }
 }
Beispiel #12
0
 private void AddFridgeToDatabase(string name)
 {
     using (hotelDBEntities context = new hotelDBEntities())
     {
         context.Fridges.Add(new Fridge {
             name = txt_fridgename.Text
         });
         context.SaveChanges();
         MessageBox.Show("Lednice přidána do databáze !");
         txt_fridgename.Text = String.Empty;
         FillCombobox_Fridgenames();
     }
 }
Beispiel #13
0
 private void DeleteAttributeFromRoom()
 {
     using (hotelDBEntities context = new hotelDBEntities())
     {
         int       roomid            = Convert.ToInt32(combo_6deleteroomid.Text);
         Room      selectedroom      = context.Rooms.FirstOrDefault(r => r.id_ro == roomid);
         Attribute selectedattribute = context.Attributes.FirstOrDefault(r => r.name == combo_6deleteroomattributes.Text);
         selectedroom.Attributes.Remove(selectedattribute);
         context.SaveChanges();
         MessageBox.Show("Vlastnost odebrána pokoji !");
         FillCombobox_Roomattributes();
     }
 }
Beispiel #14
0
 private void AddAttributeToDatabase(string attribute)
 {
     using (hotelDBEntities context = new hotelDBEntities())
     {
         context.Attributes.Add(new Attribute {
             name = attribute
         });
         context.SaveChanges();
         MessageBox.Show("Vlastnost přidána do databáze !");
         txt_attributename.Text = String.Empty;
         FillCombobox_Attributenames();
     }
 }
Beispiel #15
0
 private void UpdateStorageProducts(int id_product, int id_storage, int amount)
 {
     using (hotelDBEntities context = new hotelDBEntities())
     {
         Storage_Product product_storage = context.Storage_Product.FirstOrDefault(r => (r.id_pr == id_product) && (r.id_st == id_storage));
         int?            currentamount   = product_storage.amount;
         MessageBox.Show("BYLO : " + currentamount.ToString());
         currentamount = currentamount + amount;
         MessageBox.Show("PO PRIDANI : " + currentamount.ToString());
         product_storage.amount = currentamount;
         context.SaveChanges();
         MessageBox.Show("OK PRIDANO");
     }
 }
Beispiel #16
0
 private void AddProductToDatabase(string name, decimal price)
 {
     using (hotelDBEntities context = new hotelDBEntities())
     {
         context.Products.Add(new Product {
             name = name, price = price
         });
         context.SaveChanges();
         MessageBox.Show("Produkt přidán do databáze !");
         txt_productname.Text  = String.Empty;
         txt_productprice.Text = String.Empty;
         FillCombobox_Productnames();
     }
 }
        private void Btn_addProduct1_Click(object sender, RoutedEventArgs e)
        {
            int    id_room           = 0;
            string s                 = label_room1.Content.ToString();
            var    separetedroomname = s.Split(' '); // Cislo0pokoje1:2CISLO3

            id_room = Convert.ToInt32(separetedroomname[3]);

            int id_fridge  = 0;
            int id_product = 0;
            int amount     = 0;

            using (hotelDBEntities context = new hotelDBEntities())
            {
                Room room = context.Rooms.FirstOrDefault(r => r.id_ro == id_room);
                id_fridge = room.Fridge.id_fr;

                Product product = context.Products.FirstOrDefault(r => r.name == combo_roomproducts1.SelectedItem.ToString());
                id_product = product.id_pr;
            }

            amount = Int32.Parse(txt_productamount1.Text);

            if (storageFunction.IsEnoughAmountInFridge(id_fridge, id_product, amount) == true)
            {
                string name          = combo_choosereservation.SelectedItem.ToString();
                var    nameseparated = name.Split(' ');
                string firstname     = nameseparated[0];
                string lastname      = nameseparated[1];

                using (hotelDBEntities context = new hotelDBEntities())
                {
                    Reservation reservation = context.Reservations.FirstOrDefault(r => r.id_re == id_reservation);
                    reservation.price_total = reservation.price_total + CalculateProductAmountPrices(id_product, amount);
                    context.SaveChanges();
                }

                storageFunction.DeleteFridgeProducts(id_fridge, id_product, amount);

                FillCombobox_reservations();

                MessageBox.Show("Úspěšně odepsáno z lednice a přidáno do zaplacení!");
            }
            else
            {
                MessageBox.Show("V lednici nebylo tolik produktů !");
                return;
            }
        }
Beispiel #18
0
        private void AddRoomToDatabase(int beds, decimal price, string fridgename)
        {
            using (hotelDBEntities context = new hotelDBEntities())
            {
                Fridge fridge = context.Fridges.FirstOrDefault(r => r.name == fridgename);

                context.Rooms.Add(new Room {
                    beds = beds, price_per_day = price, id_fr = fridge.id_fr
                });
                context.SaveChanges();
                MessageBox.Show("Pokoj přidán do databáze !");
                txt_roombeds.Text        = String.Empty;
                txt_roompriceperday.Text = String.Empty;
                FillCombobox_Roomnames();
            }
        }
Beispiel #19
0
 private void AddProductsToStorage()
 {
     using (hotelDBEntities context = new hotelDBEntities())
     {
         int id_product = GetProductIdByComboboxText(combo_productnames_tostorage);
         int id_storage = GetStorageIdByComboboxText(combo_storagenames_tostorage);
         if (DoesProductInStorageExists(id_product, id_storage) == true)
         {
             UpdateStorageProducts(id_product, id_storage, Int32.Parse(txt_howmuchproducts_tostorage.Text));
         }
         else
         {
             context.Storage_Product.Add(new Storage_Product {
                 id_pr = id_product, id_st = id_storage, amount = Int32.Parse(txt_howmuchproducts_tostorage.Text)
             });
             context.SaveChanges();
         }
         MessageBox.Show("Produkty přidány do skladu !");
     }
 }
Beispiel #20
0
        private void Btn_changeFridge_Click(object sender, RoutedEventArgs e)
        {
            if ((combo_4changefridge_chooseroom.SelectedItem != null) && (combo_4changefridge_chooseroom.SelectedItem != null))
            {
                int id_room = 0;
                using (hotelDBEntities context = new hotelDBEntities())
                {
                    id_room = Convert.ToInt32(combo_4changefridge_chooseroom.SelectedItem);
                    Room   room   = context.Rooms.FirstOrDefault(r => r.id_ro == id_room);
                    Fridge fridge = context.Fridges.FirstOrDefault(r => r.name == combo_4changefridge_choosefridge.SelectedItem.ToString());

                    room.Fridge = fridge;
                    MessageBox.Show("Lednice změněna !");
                    context.SaveChanges();

                    FillCombobox_Roomnames();
                    FillCombobox_Fridgenames();
                }
            }
            else
            {
                MessageBox.Show("Vyber pokoj a lednici pro změnu !");
            }
        }