Esempio n. 1
0
        private void btnResetFilter_Click(object sender, RoutedEventArgs e)
        {
            var roomsRep = new SqlRoomRepository(connection);

            rooms = roomsRep.GetAllRooms();

            dgRooms.ItemsSource = rooms;

            chbFreeRoomOnly.IsChecked = false;
            chbEconom.IsChecked       = false;
            chbStandard.IsChecked     = false;
            chbSuit.IsChecked         = false;
            chbFamily.IsChecked       = false;
            cbPlaces.SelectedIndex    = 0;
            tbLowPrice.Text           = "";
            tbUpPrice.Text            = "";
        }
Esempio n. 2
0
        private void btnEvictGuest_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                int id = 0;

                try
                {
                    id = ((Guest)dgGuests.SelectedItem).Id;
                }
                catch
                {
                    throw new Exception("Select guest please.");
                }

                if (MessageBox.Show("Do you really want to evict this guest?", "Info", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
                {
                    var guestsRep = new SqlGuestRepository(connection);
                    var roomsRep  = new SqlRoomRepository(connection);

                    guestsRep.EvictGuest(id);

                    guests = guestsRep.GetAllGuests();
                    rooms  = roomsRep.GetAllRooms();

                    dgGuests.ItemsSource = guests;
                    dgRooms.ItemsSource  = rooms;

                    tbInfoAboutGuest2.Text = "";

                    btnCheckOut.IsEnabled   = false;
                    btnPrintBill.IsEnabled  = false;
                    btnEvictGuest.IsEnabled = false;

                    tbChangeDateGuestName.Text = "";
                    dpChangeCheckOutDate.ClearValue(DatePicker.SelectedDateProperty);

                    MessageBox.Show("Guest was successfully evicted.", "Info", MessageBoxButton.OK, MessageBoxImage.Asterisk);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
        }
Esempio n. 3
0
        private void btnDeleteRoom_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                int id = 0;

                try
                {
                    id = ((Room)dgRooms.SelectedItem).Id;
                }
                catch
                {
                    throw new Exception("Select room please.");
                }

                if (!((Room)dgRooms.SelectedItem).IsFree)
                {
                    throw new Exception("Room isn't free currently. You can't delete it.");
                }

                if (MessageBox.Show("Do you really want to delete this room?", "Info", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
                {
                    var roomsRep = new SqlRoomRepository(connection);

                    roomsRep.DeleteRoom((int)id);

                    rooms = roomsRep.GetAllRooms();

                    dgRooms.ItemsSource = rooms;

                    tbUpdatedRoomId.Text = "";
                    tbSettleRoomId.Text  = "";

                    MessageBox.Show("Room was successfully deleted.", "Info", MessageBoxButton.OK, MessageBoxImage.Asterisk);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
        }
Esempio n. 4
0
        public MainWindow()
        {
            InitializeComponent();

            var roomsRep  = new SqlRoomRepository(connection);
            var guestsRep = new SqlGuestRepository(connection);

            rooms  = roomsRep.GetAllRooms();
            guests = guestsRep.GetAllGuests();

            dgRooms.ItemsSource  = rooms;
            dgGuests.ItemsSource = guests;

            var sb = new StringBuilder();

            sb.AppendLine("№");
            sb.AppendLine("Category");
            sb.AppendLine("Places");
            sb.AppendLine("Prices");
            sb.AppendLine("TV");
            sb.AppendLine("Conditioner");
            sb.AppendLine("Internet");
            sb.AppendLine("Jacuzzi");

            tbInfoAboutRoom1.Text = sb.ToString();

            sb = new StringBuilder();

            sb.AppendLine("Name");
            sb.AppendLine("Passport");
            sb.AppendLine("Room");
            sb.AppendLine("Price");
            sb.AppendLine("Check in date");
            sb.AppendLine("Check out date");

            tbInfoAboutGuest.Text = sb.ToString();

            dpCheckOutDate.SelectedDate = DateTime.Now.AddDays(1);
        }
Esempio n. 5
0
        private void btnSettleGuest_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (tbSettleRoomId.Text == "")
                {
                    throw new Exception("Select room please.");
                }

                var id       = 0;
                var name     = "";
                var passport = "";
                var checkIn  = DateTime.Now;
                var checkOut = DateTime.Now;

                try
                {
                    id = int.Parse(tbSettleRoomId.Text);

                    name = tbSettleGuestName.Text;

                    passport = tbSettleGuestPassport.Text;

                    checkOut = (DateTime)dpCheckOutDate.SelectedDate;
                }
                catch
                {
                    throw new Exception("Some problem occured. Check input please.");
                }

                if (name == "" || passport == "")
                {
                    throw new Exception("'Name' and 'passport' fields can't be empty.");
                }

                if (checkIn >= checkOut)
                {
                    throw new Exception("Check in date must be greater than check out.");
                }

                var guestsRep = new SqlGuestRepository(connection);
                var roomsRep  = new SqlRoomRepository(connection);

                if (!((Room)dgRooms.SelectedItem).IsFree)
                {
                    throw new Exception("Room isn't free currently. You can't settle guest here.");
                }

                guestsRep.SettleGuestInTheRoom(id, name, passport, checkIn, checkOut);

                rooms  = roomsRep.GetAllRooms();
                guests = guestsRep.GetAllGuests();

                dgRooms.ItemsSource  = rooms;
                dgGuests.ItemsSource = guests;

                expSettleGuest.IsExpanded = false;

                MessageBox.Show("Guest was successfully settled.", "Info", MessageBoxButton.OK, MessageBoxImage.Asterisk);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
        }
Esempio n. 6
0
        private void btnChangeRoom_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (tbUpdatedRoomId.Text == "")
                {
                    throw new Exception("Select room please.");
                }

                var id       = 0;
                var category = "";
                var places   = 0;
                var price    = 0.0;

                try
                {
                    id = int.Parse(tbUpdatedRoomId.Text);

                    category = cbUpdatedRoomCategory.SelectedValue.ToString();

                    places = int.Parse(cbUpdatedRoomPlaces.SelectedValue.ToString());

                    price = double.Parse(tbUpdatedRoomPrice.Text);
                }
                catch
                {
                    throw new Exception("Some problem occured. Check input please.");
                }

                if (price <= 0)
                {
                    throw new Exception("Price must be a positive number.");
                }

                int categoryID = 0;

                switch (category)
                {
                case "Econom":
                    categoryID = 1;
                    break;

                case "Standard":
                    categoryID = 2;
                    break;

                case "Suit":
                    categoryID = 3;
                    break;

                case "Family":
                    categoryID = 4;
                    break;
                }

                var roomsRep = new SqlRoomRepository(connection);
                var allRooms = roomsRep.GetAllRooms();

                if (!allRooms.Where(room => room.Id == id).First().IsFree)
                {
                    throw new Exception("Room isn't free currently. You can't change it.");
                }

                if (MessageBox.Show("Do you really want to change this room?", "Info", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
                {
                    roomsRep.ChangeRoom(id, categoryID, places, (int)price);

                    rooms = roomsRep.GetAllRooms();

                    dgRooms.ItemsSource = rooms;

                    expAddRoom.IsExpanded = false;

                    WriteInfoAboutRoom(id);

                    expChangeRoom.IsExpanded = false;

                    MessageBox.Show("Room was successfully changed.", "Info", MessageBoxButton.OK, MessageBoxImage.Asterisk);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
        }
Esempio n. 7
0
        private void btnAddRoom_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                var id       = 0;
                var category = "";
                var places   = 0;
                var price    = 0.0;

                try
                {
                    id = int.Parse(tbNewRoomId.Text);

                    category = cbNewRoomCategory.SelectedValue.ToString();

                    places = int.Parse(cbNewRoomPlaces.SelectedValue.ToString());

                    price = double.Parse(tbNewRoomPrice.Text);
                }
                catch
                {
                    throw new Exception("Some problem occured. Check input please.");
                }

                if (id <= 0 || price <= 0)
                {
                    throw new Exception("ID and price must be positive numbers.");
                }

                var roomsRep = new SqlRoomRepository(connection);
                var allRooms = roomsRep.GetAllRooms();

                if (allRooms.Select(room => room.Id).Contains(id))
                {
                    throw new Exception("Room №" + id + " already exists.");
                }

                int categoryID = 0;

                switch (category)
                {
                case "Econom":
                    categoryID = 1;
                    break;

                case "Standard":
                    categoryID = 2;
                    break;

                case "Suit":
                    categoryID = 3;
                    break;

                case "Family":
                    categoryID = 4;
                    break;
                }

                roomsRep.AddRoom(id, categoryID, places, (int)price);

                rooms = roomsRep.GetAllRooms();

                dgRooms.ItemsSource = rooms;

                tbNewRoomId.Text = "";
                cbNewRoomCategory.SelectedIndex = 0;
                cbNewRoomPlaces.SelectedIndex   = 0;
                tbNewRoomPrice.Text             = "";
                expAddRoom.IsExpanded           = false;

                MessageBox.Show("New room was successfully added.", "Info", MessageBoxButton.OK, MessageBoxImage.Asterisk);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
        }