private void frmShowPupils_Load(object sender, EventArgs e) { PupilDBAccess PDBAccess = new PupilDBAccess(db); BookingDBAccess BDBAccess = new BookingDBAccess(db); InstrumentDBAccess IDBAccess = new InstrumentDBAccess(db); selection = cBox.SelectedIndex; lbl1.Visible = false; lbl2.Visible = false; txtBoxID.Visible = false; txtBoxName.Visible = false; btn1.Visible = false; }
private void frmShowBooking_Load(object sender, EventArgs e) { BookingDBAccess BDBAccess = new BookingDBAccess(db); InstrumentDBAccess IDBAccess = new InstrumentDBAccess(db); PupilDBAccess PDBAccess = new PupilDBAccess(db); selection = cBox.SelectedIndex; lbl1.Visible = false; lbl2.Visible = false; btnSearch.Visible = false; txtBox1.Visible = false; txtBox2.Visible = false; }
public void addRowToPupil() { PupilDBAccess Pdba = new PupilDBAccess(db); int pupilNo = int.Parse(DataGrid.Rows[numRowsBeforeAdd].Cells[0].Value.ToString()); String pupilTitle = DataGrid.Rows[numRowsBeforeAdd].Cells[1].Value.ToString(); String pupilFirstName = DataGrid.Rows[numRowsBeforeAdd].Cells[2].Value.ToString(); String pupilLastName = DataGrid.Rows[numRowsBeforeAdd].Cells[3].Value.ToString(); String pupilDOB = DataGrid.Rows[numRowsBeforeAdd].Cells[4].Value.ToString(); String pupilAddress = DataGrid.Rows[numRowsBeforeAdd].Cells[5].Value.ToString(); String pupilPostCode = DataGrid.Rows[numRowsBeforeAdd].Cells[6].Value.ToString(); String pupilTelNo = DataGrid.Rows[numRowsBeforeAdd].Cells[7].Value.ToString(); String pupilEmail = DataGrid.Rows[numRowsBeforeAdd].Cells[8].Value.ToString(); Pdba.insertPupil(pupilNo, pupilTitle, pupilFirstName, pupilLastName, pupilDOB, pupilAddress, pupilPostCode, pupilTelNo, pupilEmail); MessageBox.Show("The row has been added to the database table Pupil.", "Success."); }
private void cBox1_SelectedIndexChanged(object sender, EventArgs e) { PupilDBAccess PDBAccess = new PupilDBAccess(db); BookingDBAccess BDBAccess = new BookingDBAccess(db); InstrumentDBAccess IDBAccess = new InstrumentDBAccess(db); switch (cBox.SelectedIndex) { case 0: CreateTableResults(BDBAccess.getAllBookings(), IDBAccess.getAllInstruments(), PDBAccess.getAllPupils()); break; case 1: lbl1.Visible = true; lbl2.Visible = true; btnSearch.Visible = true; txtBox1.Visible = true; txtBox2.Visible = true; break; } }
private void EditBtn_Click(object sender, EventArgs e) { int num = DataGrid.Rows.Count - 2; PupilDBAccess Pdba = new PupilDBAccess(db); int pupilNo = int.Parse(DataGrid.Rows[num].Cells[0].Value.ToString()); string pupilTitle = DataGrid.Rows[num].Cells[1].Value.ToString(); string pupilFirstName = DataGrid.Rows[num].Cells[2].Value.ToString(); string pupilLastName = DataGrid.Rows[num].Cells[3].Value.ToString(); string pupilDOB = DataGrid.Rows[num].Cells[4].Value.ToString(); string pupilAddress = DataGrid.Rows[num].Cells[5].Value.ToString(); string pupilPostCode = DataGrid.Rows[num].Cells[6].Value.ToString(); string pupilTelNo = DataGrid.Rows[num].Cells[7].Value.ToString(); string pupilEmail = DataGrid.Rows[num].Cells[8].Value.ToString(); Pdba.updatePupil(pupilNo, pupilTitle, pupilFirstName, pupilLastName, pupilDOB, pupilAddress, pupilPostCode, pupilTelNo, pupilEmail); MessageBox.Show("The row in the database has been updated.", "Success."); DataGrid.DataSource = null; }
private void DeleteBtn_Click(object sender, EventArgs e) { if (DataGrid.SelectedRows.Count == 0) { MessageBox.Show("No Row selected", "error"); } else if (DataGrid.SelectedRows.Count > 1) { MessageBox.Show("There are too many rows selected. Only select one please." + "Error"); } else if (DataGrid.SelectedRows.Count == 1) { int rowNum = DataGrid.SelectedRows[0].Index; //gets row selected by user PupilDBAccess PupilAccess = new PupilDBAccess(db); int pupilNo = int.Parse(DataGrid.Rows[rowNum].Cells[0].Value.ToString()); Pupil pup = new Pupil(); pup = PupilAccess.getPupilByPupilNo(pupilNo); PupilAccess.DeletePupilWithID(pup.pupilNo); } }
private void btn1_Click(object sender, EventArgs e) { PupilDBAccess PDBAccess = new PupilDBAccess(db); BookingDBAccess BDBAccess = new BookingDBAccess(db); InstrumentDBAccess IDBAccess = new InstrumentDBAccess(db); List <Pupil> pupils = new List <Pupil>(); Pupil Selected = new Pupil(); if (string.IsNullOrWhiteSpace(txtBoxID.Text)) { pupils = PDBAccess.getPupilByPupilName(txtBoxName.Text); } else { Selected = PDBAccess.getPupilByPupilNo(Convert.ToInt32(txtBoxID.Text)); pupils.Add(Selected); } CreateTableResults(pupils); }
private void button2_Click(object sender, EventArgs e) { PupilDBAccess Pdba = new PupilDBAccess(db); numRowsBeforeAdd = DataGrid.Rows.Count - 2; if (numRowsStart == numRowsBeforeAdd) { MessageBox.Show("You have not added any additional information to this table.", "Error."); } else if (numRowsBeforeAdd > numRowsStart + 1) { MessageBox.Show("You have tried to add too many rows. Only add one at a time.", "Error."); } else if (numRowsBeforeAdd == numRowsStart + 1) { addRowToPupil(); } }
private void button1_Click(object sender, EventArgs e) { try { // populates the labels with information about pupil if (DataGrid.SelectedRows.Count == 1) { BookingDBAccess BA = new BookingDBAccess(db); List <Booking> Booked = new List <Booking>(); Booked = BA.getAllBookings(); int rowNum = DataGrid.SelectedRows[0].Index; int id = int.Parse(DataGrid.Rows[rowNum].Cells[0].Value.ToString()); PupilDBAccess pupilAccess = new PupilDBAccess(db); Selected = pupilAccess.getPupilByPupilNo(id); lblPupilNo.Text = Selected.PupilNo.ToString(); lblTitle.Text = Selected.PupilTitle; lblFirstName.Text = Selected.PupilFirstName; lblLastName.Text = Selected.PupilLastName; lblDOB.Text = Selected.PupilDOB.ToString("d/MM/yyyy"); int now = int.Parse(DateTime.Now.ToString("yyyyMMdd")); string date = DateTime.Now.ToShortDateString(); int dob = int.Parse(Selected.PupilDOB.ToString("yyyyMMdd")); int age = (now - dob) / 10000; lblAge.Text = age.ToString(); //fix this to autoNumber lblBookingNo.Text = Convert.ToString(Booked[Booked.Count() - 1].bookingNo + 1); timer1.Start(); lblDate.Text = date; groupBox4.Enabled = false; groupBox5.Enabled = false; groupBox6.Enabled = false; groupBox1.Enabled = true; groupBox2.Enabled = true; groupBox3.Enabled = true; } } catch (NullReferenceException ex) { MessageBox.Show(ex.Message); } }
private void btn1_Click(object sender, EventArgs e) { //Searches pupil by either pupilNo or LastName PupilDBAccess pupilAccess = new PupilDBAccess(db); List <Pupil> pupils = new List <Pupil>(); if (string.IsNullOrWhiteSpace(PupilNotxt.Text)) { pupils = pupilAccess.getPupilByPupilName(Nametxt.Text); } else { Selected = pupilAccess.getPupilByPupilNo(Convert.ToInt32(PupilNotxt.Text)); pupils.Add(Selected); } // Creates table with pupil information table = new DataTable(); table.Columns.Add("PupilNo"); table.Columns.Add("First Name"); table.Columns.Add("Last Name"); addpupil(pupils); }
private void btn1_Click(object sender, EventArgs e) { //Searches pupil by either pupilNo or LastName PupilDBAccess pupilAccess = new PupilDBAccess(db); BookingDBAccess BookingAccess = new BookingDBAccess(db); List <Pupil> pupils = new List <Pupil>(); List <Booking> bookings = new List <Booking>(); List <Instrument> instruments = new List <Instrument>(); Booking Selected = new Booking(); if (string.IsNullOrWhiteSpace(txtBox1.Text)) { Selected = BookingAccess.getBookingByPupilID(Convert.ToInt32(txtBox2.Text)); bookings.Add(Selected); } else { Selected = BookingAccess.getBookingByID(Convert.ToInt32(txtBox1.Text)); bookings.Add(Selected); } CreateTableResults(bookings, instruments, pupils); }