コード例 #1
0
        private void btnCreate_Click(object sender, EventArgs e)
        {
            Regex regex = new Regex("^[a-zA-Z0-9]*$");

            if (cbCountry.SelectedItem == null || string.IsNullOrWhiteSpace(txtUserID.Text) || string.IsNullOrWhiteSpace(txtPassword.Text) || string.IsNullOrWhiteSpace(txtRePassword.Text))
            {
                MessageBox.Show("Please check your fields and try again!",
                                "Empty Field(s)", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else if (txtPassword.Text != txtRePassword.Text)
            {
                MessageBox.Show("Passwords do not match!",
                                "Password Mismatch", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else if (txtUserID.TextLength < 8)
            {
                MessageBox.Show("User ID needs to be at least 8 characters long!",
                                "User ID too short", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else if (!regex.IsMatch(txtUserID.Text))
            {
                MessageBox.Show("User ID cannot have special characters!",
                                "User ID Invalid", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                using (var context = new Session3Entities())
                {
                    var getUser = (from x in context.Users
                                   where x.userId == txtUserID.Text
                                   select x).FirstOrDefault();
                    if (getUser != null)
                    {
                        MessageBox.Show("User ID used!",
                                        "Existing User ID", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    else
                    {
                        var newUser = new User()
                        {
                            countryName  = cbCountry.SelectedItem.ToString(),
                            userId       = txtUserID.Text,
                            passwd       = txtRePassword.Text,
                            userTypeIdFK = 2
                        };
                        context.Users.Add(newUser);
                        context.SaveChanges();
                        MessageBox.Show("Account created successfully!",
                                        "Create Account", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        Hide();
                        (new LoginForm()).ShowDialog();
                        Close();
                    }
                }
            }
        }
コード例 #2
0
 private void btnConfirm_Click(object sender, EventArgs e)
 {
     if (dataGridView1.CurrentCell.Style.BackColor == Color.Black)
     {
         MessageBox.Show("Unable to confirm blacked-out timings!", "Invalid Timing",
                         MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
     else if (rb22July.Checked == false && rb23July.Checked == false)
     {
         MessageBox.Show("Please select a date!", "Invalid Date",
                         MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
     else
     {
         var newArrival = new Arrival()
         {
             arrivalDate       = DateTime.Parse(rb22July.Text),
             arrivalTime       = dataGridView1.CurrentCell.Value.ToString(),
             numberHead        = Convert.ToInt32(nudHead.Value),
             numberDelegate    = Convert.ToInt32(nudDelegates.Value),
             numberCompetitors = Convert.ToInt32(nudCompetitors.Value),
             userIdFK          = _user.userId,
             numberCars        = Int32.Parse(lblCar.Text),
             number19seat      = Int32.Parse(lbl19Bus.Text),
             number42seat      = Int32.Parse(lbl42Bus.Text)
         };
         using (var context = new Session3Entities())
         {
             context.Arrivals.Add(newArrival);
             context.SaveChanges();
         }
         MessageBox.Show("Arrival confirmed!", "Confirm Arrival Details",
                         MessageBoxButtons.OK, MessageBoxIcon.Information);
         Hide();
         (new CountryMain(_user)).ShowDialog();
         Close();
     }
 }
コード例 #3
0
        private void btnBook_Click(object sender, EventArgs e)
        {
            var totalParticipants  = Int32.Parse(lblDelegates.Text) + Int32.Parse(lblCompetitors.Text);
            var getTotalCapOfRooms = 0;
            var boolCheck          = true;

            for (int i = 0; i <= dataGridView1.RowCount - 1; i++)
            {
                if (i == 0)
                {
                    getTotalCapOfRooms += Convert.ToInt32(dataGridView1.Rows[i].Cells[3].Value);
                }
                else if (i == 1)
                {
                    getTotalCapOfRooms += Convert.ToInt32(dataGridView1.Rows[i].Cells[3].Value) * 2;
                }
            }
            foreach (DataGridViewRow item in dataGridView1.Rows)
            {
                if (Convert.ToInt32(dataGridView1.Rows[item.Index].Cells[2].Value) - Convert.ToInt32(dataGridView1.Rows[item.Index].Cells[3].Value) < 0)
                {
                    boolCheck = false;
                }
            }
            if (getTotalCapOfRooms < totalParticipants)
            {
                MessageBox.Show("There are not enough rooms booked to accomedate all participants!",
                                "Insufficient rooms booked", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else if (boolCheck == false)
            {
                MessageBox.Show("There are not enough rooms for the hotel to accomedate all participants!",
                                "Insufficient rooms booked", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                var numberOfSingleBooked = Convert.ToInt32(dataGridView1.Rows[0].Cells[3].Value);
                var numberOfDoubleBooked = Convert.ToInt32(dataGridView1.Rows[1].Cells[3].Value);
                using (var context = new Session3Entities())
                {
                    var getHotel = (from x in context.Hotels
                                    where x.hotelName == HotelName
                                    select x).FirstOrDefault();
                    var newBooking = new Hotel_Booking()
                    {
                        hotelIdFK = getHotel.hotelId,
                        userIdFK  = _user.userId,
                        numSingleRoomsRequired = numberOfSingleBooked,
                        numDoubleRoomsRequired = numberOfDoubleBooked
                    };
                    context.Hotel_Booking.Add(newBooking);
                    context.SaveChanges();
                    getHotel.numSingleRoomsBooked += numberOfSingleBooked;
                    getHotel.numDoubleRoomsBooked += numberOfDoubleBooked;
                    context.SaveChanges();
                    MessageBox.Show("Hotel booked successfully!", "Hotel Booking",
                                    MessageBoxButtons.OK, MessageBoxIcon.Information);
                    Close();
                }
            }
        }
コード例 #4
0
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            var totalParticipants  = Convert.ToInt32(nudCompetitors.Value) + Convert.ToInt32(nudDelegates.Value);
            var getTotalCapOfRooms = 0;
            var boolCheck          = true;

            for (int i = 0; i <= dataGridView1.RowCount - 1; i++)
            {
                if (i == 0)
                {
                    if (dataGridView1.Rows[i].Cells[4].Value.ToString() == "")
                    {
                        getTotalCapOfRooms += Convert.ToInt32(dataGridView1.Rows[i].Cells[3].Value);
                    }
                    else
                    {
                        getTotalCapOfRooms += Convert.ToInt32(dataGridView1.Rows[i].Cells[4].Value);
                    }
                }
                else if (i == 1)
                {
                    if (dataGridView1.Rows[i].Cells[4].Value.ToString() == "")
                    {
                        getTotalCapOfRooms += Convert.ToInt32(dataGridView1.Rows[i].Cells[3].Value) * 2;
                    }
                    else
                    {
                        getTotalCapOfRooms += Convert.ToInt32(dataGridView1.Rows[i].Cells[4].Value) * 2;
                    }
                }
            }
            foreach (DataGridViewRow item in dataGridView1.Rows)
            {
                if (dataGridView1.Rows[item.Index].Cells[4].Value.ToString() != "")
                {
                    if (Convert.ToInt32(dataGridView1.Rows[item.Index].Cells[2].Value) - Convert.ToInt32(dataGridView1.Rows[item.Index].Cells[4].Value) < 0)
                    {
                        boolCheck = false;
                    }
                }
                else
                {
                    if (Convert.ToInt32(dataGridView1.Rows[item.Index].Cells[2].Value) - Convert.ToInt32(dataGridView1.Rows[item.Index].Cells[3].Value) < 0)
                    {
                        boolCheck = false;
                    }
                }
            }
            if (getTotalCapOfRooms < totalParticipants)
            {
                MessageBox.Show("There are not enough rooms booked to accomedate all participants!",
                                "Insufficient rooms booked", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else if (boolCheck == false)
            {
                MessageBox.Show("There are not enough rooms for the hotel to accomedate all participants!",
                                "Insufficient rooms booked", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                using (var context = new Session3Entities())
                {
                    var getArrivalDetails = (from x in context.Arrivals
                                             where x.userIdFK == _user.userId
                                             select x).FirstOrDefault();
                    var getBookings = (from x in context.Hotel_Booking
                                       where x.userIdFK == _user.userId
                                       select x).FirstOrDefault();
                    var hotelDetails = (from x in context.Hotels
                                        where x.hotelId == getBookings.hotelIdFK
                                        select x).FirstOrDefault();
                    getArrivalDetails.numberHead        = Convert.ToInt32(nudHead.Value);
                    getArrivalDetails.numberDelegate    = Convert.ToInt32(nudDelegates.Value);
                    getArrivalDetails.numberCompetitors = Convert.ToInt32(nudCompetitors.Value);
                    context.SaveChanges();
                    foreach (DataGridViewRow item in dataGridView1.Rows)
                    {
                        if (dataGridView1.Rows[item.Index].Cells[4].Value.ToString() == "")
                        {
                            continue;
                        }
                        else
                        {
                            if (dataGridView1.Rows[item.Index].Cells[0].Value.ToString() == "Single")
                            {
                                getBookings.numSingleRoomsRequired = Convert.ToInt32(dataGridView1.Rows[item.Index].Cells[4].Value);
                                if (hotelDetails.numSingleRoomsBooked - Convert.ToInt32(dataGridView1.Rows[item.Index].Cells[3].Value) == 0)
                                {
                                    hotelDetails.numSingleRoomsBooked = Convert.ToInt32(dataGridView1.Rows[item.Index].Cells[4].Value);
                                }
                                else
                                {
                                    hotelDetails.numSingleRoomsBooked = hotelDetails.numSingleRoomsBooked - Convert.ToInt32(dataGridView1.Rows[item.Index].Cells[3].Value) + Convert.ToInt32(dataGridView1.Rows[item.Index].Cells[4].Value);
                                }
                            }
                            else
                            {
                                getBookings.numDoubleRoomsRequired = Convert.ToInt32(dataGridView1.Rows[item.Index].Cells[4].Value);
                                if (hotelDetails.numDoubleRoomsBooked - Convert.ToInt32(dataGridView1.Rows[item.Index].Cells[3].Value) == 0)
                                {
                                    hotelDetails.numDoubleRoomsBooked = Convert.ToInt32(dataGridView1.Rows[item.Index].Cells[4].Value);
                                }
                                else
                                {
                                    hotelDetails.numDoubleRoomsBooked = hotelDetails.numDoubleRoomsBooked - Convert.ToInt32(dataGridView1.Rows[item.Index].Cells[3].Value) + Convert.ToInt32(dataGridView1.Rows[item.Index].Cells[4].Value);
                                }
                            }
                        }
                    }
                    context.SaveChanges();
                    MessageBox.Show("Updated info and booking successful!", "Update Info / Booking",
                                    MessageBoxButtons.OK, MessageBoxIcon.Information);
                    Hide();
                    (new CountryMain(_user)).ShowDialog();
                    Close();
                }
            }
        }