//When a cell in the data grid view is clicked on, this method finds the forenames and surnames of all the members who are booked for that class //and returns the as a list. Then, when a cell is clicked on, the MemberForename and MemberSurname appear in a Message Box. private void dataGridViewBooking_CellClick(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex == -1) { return; } if (dataGridViewBooking.CurrentCell.ColumnIndex.Equals(0)) { if (dataGridViewBooking.CurrentCell != null && dataGridViewBooking.CurrentCell.Value != null) { int cell = Convert.ToInt32(dataGridViewBooking.CurrentCell.Value); List <string> mSurnames = Bookings.getMemberSurname(Convert.ToString(cell)); if (mSurnames.Count > 0) { StringBuilder sb = new StringBuilder(); foreach (string surname in mSurnames) { sb.AppendLine(Convert.ToString(mSurnames)); } ; List <string> mForenames = Bookings.getMemberForename(Convert.ToString(cell)); { if (mForenames.Count > 0) { StringBuilder sb1 = new StringBuilder(); foreach (string fornames in mForenames) { sb.AppendLine(Convert.ToString(mForenames)); } string membername = mForenames[0] + " " + mSurnames[0]; MessageBox.Show(membername); } } } } } }
private void Search() { //If txtBookingID is not empty. if (txtBookingID.Text != "") { //This method will check if the BookingID is valid. using (SqlConnection connection = new SqlConnection(_connectionString)) { using (SqlCommand sqlCommand = new SqlCommand("SELECT COUNT(*) FROM Booking WHERE (BookingID = @BookingID)", connection)) { connection.Open(); sqlCommand.Parameters.AddWithValue("@BookingID", txtBookingID.Text); int booking = (int)sqlCommand.ExecuteScalar(); bool bookingExist = false; if (booking > 0) { bookingExist = true; //If bookingExist is true. if (bookingExist) { //Call the getBookingDate method from the Bookings Class and pass across the data. List <DateTime> bDates = Bookings.getBookingDate(txtBookingID.Text); { //If the amount of bookingsDates is greater than 0... if (bDates.Count > 0) { //Create an instance of the stringbuilder class. StringBuilder string_Builder = new StringBuilder(); foreach (DateTime date in bDates) { string_Builder.AppendLine(Convert.ToString(date)); //Display and convert the BookingDate in lblDisplayBookingDate. lblDisplayBookingDate.Text = Convert.ToString(date.ToString("yyyy-MM-dd")); } } } //Call the getMemberID method from the Bookings Class and pass across the data. List <int> ids = Bookings.getMemberID(txtBookingID.Text); { //If the amount of IDs is greater than 0... if (ids.Count > 0) { //Create an instance of the stringbuilder class. StringBuilder _sb = new StringBuilder(); foreach (int id in ids) { _sb.AppendLine(Convert.ToString(id)); //Display the ID in lblMemberID. txtMemberID.Text = Convert.ToString(id); } } } //Call the getMemberForename method from the Bookings Class and pass across the data. List <string> fnames = Bookings.getMemberForename(txtMemberID.Text); { //If the amount of names is greater than 0... if (fnames.Count > 0) { //Create an instance of the stringbuilder class. StringBuilder stringBuilder = new StringBuilder(); foreach (string fname in fnames) { stringBuilder.AppendLine(fname); //Display the name in lblDisplayName. lblDisplayName.Text = fname; //Save the name into the variable _fname. _fname = lblDisplayName.Text; } } } //Call the getBookingSurname method from the Bookings Class and pass across the data. List <string> snames = Bookings.getMemberSurname(txtMemberID.Text); { //If the amount of names is greater than 0... if (snames.Count > 0) { //Create an instance of the stringbuilder class. StringBuilder string_Builder = new StringBuilder(); foreach (string sname in snames) { string_Builder.AppendLine(sname); //Display the forname and surname in lblDisplayName. lblDisplayName.Text = _fname + " " + sname; } } } //Call the getMemberPostCode method from the Bookings Class and pass across the data. List <string> postCodes = Bookings.getMemberPostCode(txtMemberID.Text); { //If the amount of postcodes is greater than 0... if (postCodes.Count > 0) { //Create an instance of the stringbuilder class. StringBuilder string_Builder = new StringBuilder(); foreach (string pc in postCodes) { string_Builder.AppendLine(pc); //Display the postcode in lblDisplayPostCode. lblDisplayPostCode.Text = pc; } } } //Call the getClassID method from the Bookings Class and pass across the data. List <string> classIDs = Bookings.getClassID(txtBookingID.Text); { //If the amount of IDs is greater than 0... if (classIDs.Count > 0) { //Create an instance of the stringbuilder class. StringBuilder s_b = new StringBuilder(); foreach (string id in classIDs) { s_b.AppendLine(id); //Display the ClassID in lblClassID. cbClassID.Text = id; } } } //Call the getClassName method from the Bookings Class and pass across the data. List <string> classNames = Bookings.getClassName(cbClassID.Text); { //If the amount of names is greater than 0... if (classNames.Count > 0) { //Create an instance of the stringbuilder class. StringBuilder string_b = new StringBuilder(); foreach (string name in classNames) { string_b.AppendLine(name); //Display the name in lblDisplayClassName. lblDisplayClassName.Text = name; } } } //Call the getClassDay method from the Bookings Class and pass across the data. List <string> classDays = Bookings.getClassDay(cbClassID.Text); { //If the amount of days is greater than 0... if (classDays.Count > 0) { //Create an instance of the stringbuilder class. StringBuilder string_build = new StringBuilder(); foreach (string day in classDays) { string_build.AppendLine(day); //Display the day in lblDisplayDay. lblDisplayDay.Text = day; } } } //Call the getClassTime method from the Bookings Class and pass across the data. List <string> classTimes = Bookings.getClassTime(cbClassID.Text); { //If the amount of times is greater than 0... if (classTimes.Count > 0) { //Create an instance of the stringbuilder class. StringBuilder s_builder = new StringBuilder(); foreach (string time in classTimes) { s_builder.AppendLine(time); //Display the time in lblDisplayTime. lblDisplayTime.Text = time; } } } //Call the getClassDate method from the Bookings Class and pass across the data. List <DateTime> classDates = Bookings.getClassDate(txtBookingID.Text); { //If the amount of dates is greater than 0... if (classDates.Count > 0) { //Create an instance of the stringbuilder class. StringBuilder string_builder = new StringBuilder(); foreach (DateTime c_date in classDates) { string_builder.AppendLine(Convert.ToString(c_date)); //Display the ClassDate in dateTimePickerClass. dateTimePickerClass.Value = c_date; } } } } //Otherwise display the message below. else { MessageBox.Show("This booking does not exist."); } } //Otherwise display the message below. else { MessageBox.Show("This booking does not exist."); } } } } //Otherwise display the message below. else { MessageBox.Show("Please enter a BookingID."); } }
private void SearchMember() { //Call the getMemberForename method from the Bookings Class and pass across the data. List <string> fnames = Bookings.getMemberForename(txtMemberID.Text); { //If the amount of names is greater than 0... if (fnames.Count > 0) { //Create an instance of the stringbuilder class. StringBuilder stringb = new StringBuilder(); foreach (string fname in fnames) { stringb.AppendLine(fname); //Display the name in lblDisplayForename. lblDisplayForename.Text = fname; } } } //Call the getBookingSurname method from the Bookings Class and pass across the data. List <string> snames = Bookings.getMemberSurname(txtMemberID.Text); { //If the amount of names is greater than 0... if (snames.Count > 0) { //Create an instance of the stringbuilder class. StringBuilder string_b = new StringBuilder(); foreach (string sname in snames) { string_b.AppendLine(sname); //Display the forname and surname in lblDisplaySurname. lblDisplaySurname.Text = sname; } } } //Call the getMemberStreet method from the Bookings Class and pass across the data. List <string> streets = Bookings.getMemberStreet(txtMemberID.Text); { //If the amount of streets is greater than 0... if (streets.Count > 0) { //Create an instance of the stringbuilder class. StringBuilder s_b = new StringBuilder(); foreach (string street in streets) { s_b.AppendLine(street); //Display the postcode in lblDisplayStreet. lblDisplayStreet.Text = street; } } } //Call the getMemberTown method from the Bookings Class and pass across the data. List <string> towns = Bookings.getMemberTown(txtMemberID.Text); { //If the amount of towns is greater than 0... if (towns.Count > 0) { //Create an instance of the stringbuilder class. StringBuilder stringbuild = new StringBuilder(); foreach (string town in towns) { stringbuild.AppendLine(town); //Display the postcode in lblDisplayTown. lblDisplayTown.Text = town; } } } //Call the getMemberCounty method from the Bookings Class and pass across the data. List <string> counties = Bookings.getMemberCounty(txtMemberID.Text); { //If the amount of counties is greater than 0... if (counties.Count > 0) { //Create an instance of the stringbuilder class. StringBuilder sbuild = new StringBuilder(); foreach (string county in counties) { sbuild.AppendLine(county); //Display the postcode in lblDisplayCounty. lblDisplayCounty.Text = county; } } } //Call the getMemberPostCode method from the Bookings Class and pass across the data. List <string> pcs = Bookings.getMemberPostCode(txtMemberID.Text); { //If the amount of postcodes is greater than 0... if (pcs.Count > 0) { //Create an instance of the stringbuilder class. StringBuilder stbuilder = new StringBuilder(); foreach (string pc in pcs) { stbuilder.AppendLine(pc); //Display the postcode in lblDisplayPostCode. lblDisplayPostCode.Text = pc; } } } }