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 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); }