Exemplo n.º 1
0
        private void btnBook_Click(object sender, EventArgs e)
        {
            var getTotalCap = int.Parse(lblDelegates.Text) + int.Parse(lblCompetitors.Text);
            var bookedCap   = originalSingle + (originalDouble * 2);

            if (bookedCap < getTotalCap)
            {
                MessageBox.Show("Please ensure number of rooms booked are enough for all visitors!");
            }
            else
            {
                var boolCheck = true;
                foreach (DataGridViewRow item in dataGridView1.Rows)
                {
                    if (Convert.ToInt32(dataGridView1[2, item.Index].Value) < Convert.ToInt32(dataGridView1[3, item.Index].Value))
                    {
                        boolCheck = false;
                    }
                }
                if (boolCheck == false)
                {
                    MessageBox.Show("Hotel will not have enough rooms for desired amount!");
                }
                else
                {
                    using (var context = new Session3Entities())
                    {
                        var newBooking = new Hotel_Booking()
                        {
                            hotelIdFK = _hotelID,
                            numSingleRoomsRequired = originalSingle,
                            numDoubleRoomsRequired = originalDouble,
                            userIdFK = _user.userId
                        };
                        context.Hotel_Booking.Add(newBooking);
                        context.SaveChanges();
                        var getHotel = (from x in context.Hotels
                                        where x.hotelId == _hotelID
                                        select x).FirstOrDefault();
                        getHotel.numSingleRoomsBooked += originalSingle;
                        getHotel.numDoubleRoomsBooked += originalDouble;
                        context.SaveChanges();
                        MessageBox.Show("Hotel booking successful!");
                        Close();
                    }
                }
            }
        }
Exemplo n.º 2
0
 private void btnCreate_Click(object sender, EventArgs e)
 {
     if (cbCountry.SelectedItem == null || string.IsNullOrWhiteSpace(txtUserID.Text) || string.IsNullOrWhiteSpace(txtPassword.Text) || string.IsNullOrWhiteSpace(txtRePassword.Text))
     {
         MessageBox.Show("Please ensure all fields are filled!");
     }
     else if (txtPassword.Text != txtRePassword.Text)
     {
         MessageBox.Show("Passwords do not match!");
     }
     else if (txtUserID.TextLength < 8)
     {
         MessageBox.Show("Ensure there are at least 8 characters for User ID!");
     }
     else if (!Regex.IsMatch(txtUserID.Text, "^[a-zA-Z0-9]+$"))
     {
         MessageBox.Show("Ensure only letters and numeric characters in User ID!");
     }
     else
     {
         using (var context = new Session3Entities())
         {
             var findUser = (from x in context.Users
                             where x.userId == txtUserID.Text
                             select x).FirstOrDefault();
             if (findUser != null)
             {
                 MessageBox.Show("User ID used!");
             }
             else
             {
                 var newUser = new User()
                 {
                     countryName  = cbCountry.SelectedItem.ToString(),
                     userId       = txtUserID.Text,
                     userTypeIdFK = 2,
                     passwd       = txtPassword.Text
                 };
                 context.Users.Add(newUser);
                 context.SaveChanges();
                 MessageBox.Show("Successfully added user!");
                 Hide();
                 (new LoginForm()).ShowDialog();
                 Close();
             }
         }
     }
 }
Exemplo n.º 3
0
 private void btnConfirm_Click(object sender, EventArgs e)
 {
     if (!rb22.Checked && !rb23.Checked)
     {
         MessageBox.Show("Please select a date!");
     }
     else if (dataGridView1.CurrentCell == null)
     {
         MessageBox.Show("Please select a time!");
     }
     else if (dataGridView1.CurrentCell.Style.BackColor == Color.Black)
     {
         MessageBox.Show("Please select another timing that is not blacked out!");
     }
     else
     {
         var newArrival = new Arrival()
         {
             arrivalTime       = dataGridView1.CurrentCell.Value.ToString(),
             number19seat      = int.Parse(lbl19.Text),
             number42seat      = int.Parse(lbl42.Text),
             numberCars        = int.Parse(lblCar.Text),
             numberHead        = (int)nudHead.Value,
             numberDelegate    = (int)nudDelegates.Value,
             numberCompetitors = (int)nudCompetitors.Value,
             userIdFK          = _user.userId
         };
         if (rb22.Checked)
         {
             newArrival.arrivalDate = DateTime.Parse("22 July 2020");
         }
         else if (rb23.Checked)
         {
             newArrival.arrivalDate = DateTime.Parse("23 July 2020");
         }
         using (var context = new Session3Entities())
         {
             context.Arrivals.Add(newArrival);
             context.SaveChanges();
             MessageBox.Show("Successfully confirmed arrival!");
         }
         Hide();
         (new CountryMain(_user)).ShowDialog();
         Close();
     }
 }
Exemplo n.º 4
0
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            var getTotalCap = (int)nudCompetitors.Value + (int)nudDelegates.Value;
            var bookedCap   = originalSingle + (originalDouble * 2);

            if (bookedCap < getTotalCap)
            {
                MessageBox.Show("Please ensure number of rooms booked are enough for all visitors!");
            }
            else
            {
                var boolCheck = true;
                foreach (DataGridViewRow item in dataGridView1.Rows)
                {
                    if (dataGridView1[4, item.Index].Value.ToString() != "")
                    {
                        if (Convert.ToInt32(dataGridView1[2, item.Index].Value) < Convert.ToInt32(dataGridView1[4, item.Index].Value))
                        {
                            boolCheck = false;
                        }
                    }
                    else
                    {
                        if (Convert.ToInt32(dataGridView1[2, item.Index].Value) < Convert.ToInt32(dataGridView1[3, item.Index].Value))
                        {
                            boolCheck = false;
                        }
                    }
                }
                if (boolCheck == false)
                {
                    MessageBox.Show("Hotel will not have enough rooms for desired amount!");
                }
                else
                {
                    using (var context = new Session3Entities())
                    {
                        var findArrival = (from x in context.Arrivals
                                           where x.userIdFK == _user.userId
                                           select x).FirstOrDefault();
                        findArrival.numberHead        = (int)nudHead.Value;
                        findArrival.numberCompetitors = (int)nudCompetitors.Value;
                        findArrival.numberDelegate    = (int)nudDelegates.Value;
                        context.SaveChanges();
                        var findBooking = (from x in context.Hotel_Booking
                                           where x.userIdFK == _user.userId
                                           select x).FirstOrDefault();
                        findBooking.numSingleRoomsRequired = originalSingle;
                        findBooking.numDoubleRoomsRequired = originalDouble;
                        context.SaveChanges();
                        var findHotel = (from x in context.Hotels
                                         where x.hotelId == findBooking.hotelIdFK
                                         select x).FirstOrDefault();
                        foreach (DataGridViewRow item in dataGridView1.Rows)
                        {
                            if (dataGridView1[0, item.Index].Value.ToString() == "Single")
                            {
                                if (dataGridView1[4, item.Index].Value.ToString() != "")
                                {
                                    if (findHotel.numSingleRoomsBooked == Convert.ToInt32(dataGridView1[4, item.Index].Value))
                                    {
                                        findHotel.numSingleRoomsBooked = Convert.ToInt32(dataGridView1[4, item.Index].Value);
                                    }
                                    else
                                    {
                                        findHotel.numSingleRoomsBooked = findHotel.numSingleRoomsBooked - Convert.ToInt32(dataGridView1[3, item.Index].Value) + Convert.ToInt32(dataGridView1[4, item.Index].Value);
                                    }
                                }
                            }
                            else
                            {
                                if (dataGridView1[4, item.Index].Value.ToString() != "")
                                {
                                    if (findHotel.numDoubleRoomsBooked == Convert.ToInt32(dataGridView1[4, item.Index].Value))
                                    {
                                        findHotel.numDoubleRoomsBooked = Convert.ToInt32(dataGridView1[4, item.Index].Value);
                                    }
                                    else
                                    {
                                        findHotel.numDoubleRoomsBooked = findHotel.numDoubleRoomsBooked - Convert.ToInt32(dataGridView1[3, item.Index].Value) + Convert.ToInt32(dataGridView1[4, item.Index].Value);
                                    }
                                }
                            }
                        }
                        context.SaveChanges();
                        MessageBox.Show("Update Info and Booking successful!");
                        Hide();
                        (new CountryMain(_user)).ShowDialog();
                        Close();
                    }
                }
            }
        }