public void NextOfKinFormClosed() { //reset form and flasgs nextOfKinIsOpen = false; nextOfKinFrm = null; //update table and results //table name, field list, data grid SelectResultsAndUpdateGrid("next_of_kin", nextOfKinFieldList, next_of_kin_dg); }
private void insert_next_of_kin_btn_Click(object sender, EventArgs e) { CloseAndNullAllSubforms(); //create new mainform object to send to this fgomr //as refrence for student form MainForm newform = new MainForm(); newform = this; //send form refrence and set insert flag to true nextOfKinFrm = new NextOfKinForm(ref newform, true); //show form and set open flag nextOfKinFrm.Show(); nextOfKinIsOpen = true; }
public void DeleteOrUpdateSelectedRow(string tableName, string idFieldName, DataGridView datagridUpdate, bool isUpdate) { // check of rows in data grid bool isSelected = false; int rowId = 0; int numRows = 0; //number of rows in data grid numRows = datagridUpdate.Rows.Count; //loop though the rows for (int i = 0; i < numRows; i++) { //of row selected in data grid if (datagridUpdate.Rows[i].Selected) { rowId = i; isSelected = true; } } if (isSelected) { string idValue = datagridUpdate.Rows[rowId].Cells[0].Value.ToString(); //to debug comment / uncomment to show value of id selected //we will send this value to the query method //check if update or delete if (isUpdate) { CloseAndNullAllSubforms(); //create new main form object to send to this // as refrence to the student form MainForm newform = new MainForm(); newform = this; //send from refrence and set insert flag to false //send id from selected row switch (tableName) { case "student": { studentFrm = new StudentForm(ref newform, false, idValue); //show form and set open flag studentFrm.Show(); studentFrmIsOpen = true; } break; case "user_account": { userAccountFrm = new UserAccountForm(ref newform, false, idValue); //show form and set open flag userAccountFrm.Show(); userAccountFrmIsOpen = true; } break; case "staff": { staffFrm = new StaffForm(ref newform, false, idValue); //show form and set open faLSE staffFrm.Show(); staffFrmIsOpen = true; } break; case "next_of_kin": { nextOfKinFrm = new NextOfKinForm(ref newform, false, idValue); //show form and set open false nextOfKinFrm.Show(); nextOfKinIsOpen = true; } break; case "address": { addressFrm = new AddressForm(ref newform, false, idValue); //show form and set open false addressFrm.Show(); addressIsOpen = true; } break; case "department": { depFrm = new DepartmentForm(ref newform, false, idValue); //show form and set open false depFrm.Show(); depIsOpen = true; } break; case "job_role": { jobRoleFrm = new JobRoleForm(ref newform, false, idValue); //show form and set open false jobRoleFrm.Show(); jobRoleIsOpen = true; } break; case "learning_aim": { learningAimFrm = new LearningAimForm(ref newform, false, idValue); //show form and set open false learningAimFrm.Show(); learningAimIsOpen = true; } break; case "course": { courseFrm = new CourseForm(ref newform, false, idValue); //show form and set open false courseFrm.Show(); courseIsOpen = true; } break; case "enrolment": { enrolmentFrm = new EnrolmentForm(ref newform, false, idValue); //show form and set open false enrolmentFrm.Show(); enrolmentIsOpen = true; } break; } } else if (!isUpdate) { //calls delete row method on DB connection //and sends the id value to selected row mySqlSrc.DeleteRowWithId(tableName, idFieldName, idValue); } } else { // if no row selcted disply to user MessageBox.Show("No Row Selcted"); } }
// method to manage subforms private void CloseAndNullAllSubforms() { //check each form to see if open flag set //if so close the form and null object (unset flag) //STUDENT FORM if (studentFrmIsOpen) { studentFrm.Close(); studentFrm = null; studentFrmIsOpen = false; } //PRODUCT FORM if (userAccountFrmIsOpen) { userAccountFrm.Close(); userAccountFrm = null; userAccountFrmIsOpen = false; } //STAFF TABLE if (staffFrmIsOpen) { staffFrm.Close(); staffFrm = null; staffFrmIsOpen = false; } //NEXT OF KIN if (nextOfKinIsOpen) { nextOfKinFrm.Close(); nextOfKinFrm = null; nextOfKinIsOpen = false; } //ADDRESS TABLE if (addressIsOpen) { addressFrm.Close(); addressFrm = null; addressIsOpen = false; } //DEPARTMENT TABLE if (depIsOpen) { depFrm.Close(); depFrm = null; depIsOpen = false; } //JOB ROLE TABLE if (jobRoleIsOpen) { jobRoleFrm.Close(); jobRoleFrm = null; jobRoleIsOpen = false; } //LEARNING AIM TABLE if (learningAimIsOpen) { learningAimFrm.Close(); learningAimFrm = null; learningAimIsOpen = false; } //COURSE TABLE if (courseIsOpen) { courseFrm.Close(); courseFrm = null; courseIsOpen = false; } //ENROLEMT TANLE if (enrolmentIsOpen) { enrolmentFrm.Close(); enrolmentFrm = null; enrolmentIsOpen = false; } }