private void button_Click(object sender, RoutedEventArgs e)
        {
            NewReservation newReservationForm = new NewReservation();

            newReservationForm.Show();
            this.Close();
        }
예제 #2
0
        private void btnSubmit_Click(object sender, RoutedEventArgs e)
        {
            if (rdbExistingGuest.IsChecked == true)
            {
                string error = "";
                conn.Open();
                if (txtGuestID.Text != "")
                {
                    if (isUserExist(txtGuestID.Text) > 0)
                    {
                        if (cmbRoomType.SelectedItem == null || cmbRoomNumber.SelectedItem == null)
                        {
                            error += "\n Room needs to be selected!!";
                        }
                        if (dpiStartDate.Text == "" || dpiEndDate.Text == "")
                        {
                            error += "\n Dates must be selected!!";
                        }

                        if (error == "")
                        {
                            SqlCommand insertReservation = new SqlCommand("INSERT INTO tblReservations (GuestID,RoomID,EmployeeID,DateMade, ReservationStartDate,ReservationEndDate) VALUES (@guest,@room,@emp,CONVERT (date, SYSDATETIME()),@start,@end)", conn);
                            insertReservation.Parameters.Add(new SqlParameter("guest", txtGuestID.Text));
                            insertReservation.Parameters.Add(new SqlParameter("room", cmbRoomNumber.Text));
                            insertReservation.Parameters.Add(new SqlParameter("emp", txtEmployeeID.Text));
                            insertReservation.Parameters.Add(new SqlParameter("start", dpiStartDate.Text));
                            insertReservation.Parameters.Add(new SqlParameter("end", dpiEndDate.Text));
                            int r = insertReservation.ExecuteNonQuery();
                            if (r == 0)
                            {
                                MessageBox.Show("Cannot insert reservation!");
                            }
                            else
                            {
                                MessageBox.Show("Reservation Made Successfully!!");
                                NewReservation rs = new NewReservation();
                                rs.Show();
                                this.Close();
                            }
                        }
                        else
                        {
                            MessageBox.Show(error);
                        }
                        if (conn != null)
                        {
                            conn.Close();
                        }
                    }
                    else
                    {
                        MessageBox.Show("\nGuest with - " + txtGuestID.Text + " is not found\n");
                        txtGuestID.Focus();
                        txtGuestID.SelectAll();
                    }
                }
                else
                {
                    MessageBox.Show("Guest ID is required!");
                }



                conn.Close();
            }
            else if (rdbNewGuest.IsChecked == true)
            {
                string error = "";
                conn.Open();
                if (cmbRoomType.SelectedItem == null || cmbRoomNumber.SelectedItem == null)
                {
                    error += "\n Room needs to be selected!!";
                }
                if (dpiStartDate.Text == "" || dpiEndDate.Text == "")
                {
                    error += "\n Dates must be selected!!";
                }
                if (txtFirstName.Text == "" || txtLastName.Text == "")
                {
                    error += "\nFirst Name and Last Name both are required !!";
                }
                if (txtPhone.Text == "")
                {
                    error += "\nPhone Number is required !!";
                }
                if (txtPhone.Text.Length != 10)
                {
                    error += "\nPhone Number needs to be of 10 characters!!";
                }
                if (txtAddress.Text == "")
                {
                    error += "\nAddress is required !!";
                }
                if (txtPostalCode.Text == "")
                {
                    error += "\nPostal Code is required !!";
                }

                if (txtPostalCode.Text.Length != 6)
                {
                    error += "\nPostal Code needs to be of 6 characters without space !!";
                }

                if (error == "")
                {
                    SqlCommand insertGuest = new SqlCommand("INSERT INTO tblGuests (GuestID,FirstName,LastName,GuestAddress, PostalCode,Phone,EmailAddress) VALUES (@guest,@first,@last,@address,@postal,@phone,@email)", conn);

                    insertGuest.Parameters.Add(new SqlParameter("guest", txtGuestID.Text));
                    insertGuest.Parameters.Add(new SqlParameter("first", txtFirstName.Text));
                    insertGuest.Parameters.Add(new SqlParameter("last", txtLastName.Text));
                    insertGuest.Parameters.Add(new SqlParameter("address", txtAddress.Text));
                    insertGuest.Parameters.Add(new SqlParameter("postal", (txtPostalCode.Text).ToUpper()));
                    insertGuest.Parameters.Add(new SqlParameter("phone", txtPhone.Text));
                    insertGuest.Parameters.Add(new SqlParameter("email", txtEmail.Text));
                    int result = insertGuest.ExecuteNonQuery();
                    if (result == 0)
                    {
                        MessageBox.Show("Cannot insert Guest!");
                    }
                    else
                    {
                        SqlCommand insertReservation = new SqlCommand("INSERT INTO tblReservations (GuestID,RoomID,EmployeeID,DateMade, ReservationStartDate,ReservationEndDate) VALUES (@guest,@room,@emp,CONVERT (date, SYSDATETIME()),@start,@end)", conn);
                        insertReservation.Parameters.Add(new SqlParameter("guest", txtGuestID.Text));
                        insertReservation.Parameters.Add(new SqlParameter("room", cmbRoomNumber.Text));
                        insertReservation.Parameters.Add(new SqlParameter("emp", txtEmployeeID.Text));
                        insertReservation.Parameters.Add(new SqlParameter("start", dpiStartDate.Text));
                        insertReservation.Parameters.Add(new SqlParameter("end", dpiEndDate.Text));
                        int r = insertReservation.ExecuteNonQuery();
                        if (r == 0)
                        {
                            MessageBox.Show("Cannot insert reservation!");
                        }
                        else
                        {
                            MessageBox.Show("Reservation Made Successfully!!");
                            NewReservation rs = new NewReservation();
                            rs.Show();
                            this.Close();
                        }
                    }
                }
                else
                {
                    MessageBox.Show(error);
                }
                if (conn != null)
                {
                    conn.Close();
                }



                conn.Close();
            }
        }