//Fill data public AssignModule fillDataProf(string id) { try { //sql query string sql = "SELECT * FROM AssignModule WHERE MId ='" + id + "'AND pId='" + ProfessorHome.profid + "'"; SqlCommand cmd = new SqlCommand(sql, con); // sql command con.Open(); // open connection SqlDataReader reader = cmd.ExecuteReader(); //read table if (reader.Read()) //loop until data found { amod = new AssignModule(); amod.setmid(reader[0].ToString()); amod.setprogramme(reader[1].ToString()); amod.setfaculty(reader[2].ToString()); amod.setmodfee(reader[3].ToString()); amod.setduration(reader[4].ToString()); amod.setstarddate(reader[5].ToString()); amod.setenddate(reader[6].ToString()); } else { MessageBox.Show("The Module has not yet been assigned"); //errror message } } finally { con.Close(); //close connection } return(amod); //return object }
private void metrobuttonAssignMod_Click(object sender, EventArgs e) { if (metroComboBoxMod.Text == "" && metroTextBoxFac.Text == "" && metroTextBoxDur.Text == "" && metroTextBoxMFee.Text == "" && metroTextBoxModule.Text == "" && metroTextBoxStDate.Text == "" && metroTextBoxEDate.Text == "") { MetroMessageBox.Show(this, "Fields cannot be left empty"); } else { CommonDBTransaction c = new CommonDBTransaction(); string sql = "SELECT * FROM AssignModule WHERE mid ='" + metroComboBoxMod.Text + "'"; DataTable d = c.searchData(sql); if (d.Rows.Count > 0) { MetroMessageBox.Show(this, "This Data already exist"); } else { if (metroGridProf.Rows.Count < 2) { MetroMessageBox.Show(this, "Insuffcient Students for the module requirement!"); } else if (metroGridProf.Rows.Count > 9) { MetroMessageBox.Show(this, "The number of students for this module has been equiped with!"); } else { AssignModule am = new AssignModule(); am.setmid(metroComboBoxMod.Text); am.setprogramme(metroTextBoxModule.Text); am.setfaculty(metroTextBoxFac.Text); am.setmodfee(metroTextBoxMFee.Text); am.setduration(metroTextBoxDur.Text); am.setstarddate(metroTextBoxStDate.Text); am.setenddate(metroTextBoxEDate.Text); StringBuilder sb = new StringBuilder(); string seperator = ""; for (int i = 0; i < metroGridStd.Rows.Count; i++) { sb.AppendFormat("{0}{1}", seperator, metroGridStd.Rows[i].Cells[0].Value.ToString()); seperator = ","; } string lid = sb.ToString(); am.setlid(lid); StringBuilder sb1 = new StringBuilder(); string seperator1 = ""; for (int i = 0; i < metroGridProf.Rows.Count; i++) { sb1.AppendFormat("{0}{1}", seperator1, metroGridProf.Rows[i].Cells[0].Value.ToString()); seperator1 = ","; } string sid = sb1.ToString(); am.setsid(sid); AssignModuleTransaction amt = new AssignModuleTransaction(); amt.addModule(am); } } } }
//add a module public void addModule(AssignModule obj) { try { //sql query string sql = "INSERT INTO AssignModule(MId,Programme,Faculty,ModuleFee,Duration,StartDate,EndDate,pId,sId)VALUES('" + obj.getmid() + "','" + obj.getprogramme() + "','" + obj.getfaculty() + "','" + obj.getmodfee() + "','" + obj.getduration() + "','" + obj.getstartdate() + "','" + obj.getenddate() + "','" + obj.getlid() + "','" + obj.getmid() + "')"; SqlCommand cmd = new SqlCommand(sql, con); // sql command con.Open(); //open connection cmd.ExecuteNonQuery(); //execute query } finally { con.Close(); // close connection } }
private void metroButton2_Click(object sender, EventArgs e) { AssignModule am = new AssignModule(); AssignModuleTransaction amt = new AssignModuleTransaction(); try { am = amt.fillDataProf(metroComboBoxRMods.Text); metroComboBoxRMods.Text = am.getmid(); metroTextBoxFacM.Text = am.getfaculty(); metroTextBoxP.Text = am.getprogramme(); metroTextBoxModFees.Text = am.getmodfee(); metroTextBoxStd.Text = am.getstartdate(); metroTextBoxEnd.Text = am.getenddate(); } catch { MetroMessageBox.Show(this, "Course not yet assinged"); } }
private void metroComboBox3_SelectedIndexChanged(object sender, EventArgs e) { //load values to input fields AssignModule am = new AssignModule(); AssignModuleTransaction amt = new AssignModuleTransaction(); try { am = amt.fillData(metroComboBoxMods.Text); metroComboBoxMods.Text = am.getmid(); metroTextBoxMFac.Text = am.getfaculty(); metroTextBoxProgram.Text = am.getprogramme(); metroTextBoxMFees.Text = am.getmodfee(); metroTextBoxstDate.Text = am.getstartdate(); metroTextBoxedDate.Text = am.getenddate(); } catch { MetroMessageBox.Show(this, "Course not yet assinged"); } }