private void button3_Click(object sender, EventArgs e) { var splitter = SplitByString(trvCourses.SelectedNode.Text, " - "); try { var update = Database.Query("Courses", "idCourses = '" + splitter[0] + "'"); update.Tables[0].Rows[0]["Name"] = txtName.Text; update.Tables[0].Rows[0]["IDcourses"] = txtID.Text; update.Tables[0].Rows[0]["Type"] = clsFunctions.retrieveAbrev(lstTypes.Text); update.Tables[0].Rows[0]["hasElectives"] = txtElectives.Text; update.Tables[0].Rows[0]["maxElectives"] = txtElectivesMax.Text; update.Tables[0].Rows[0]["active"] = chkActive.Checked ? (object)"1" : DBNull.Value; Database.Update(update, "courses", "idCourses = '" + splitter[0] + "'"); trvCourses.SelectedNode.Text = txtID.Text + " - " + txtName.Text; } catch { if (clsFunctions.retrieveAbrev(lstTypes.Text) == "PROJ" && nqfTextBox.Text.Length == 0) { MessageBox.Show("Please specify a NQF Level"); return; } string tempName; var update = Database.Query("components", "idCourseComponents = '" + splitter[0] + "'"); update.Tables[0].Rows[0]["IsElective"] = chkElective.Checked ? (object)"1" : DBNull.Value; update.Tables[0].Rows[0]["showOnAssesment"] = chkAssesment.Checked ? (object)"yes" : DBNull.Value; tempName = update.Tables[0].Rows[0]["Name"].ToString(); update.Tables[0].Rows[0]["Name"] = txtName.Text; update.Tables[0].Rows[0]["idCourseComponents"] = txtID.Text; update.Tables[0].Rows[0]["totalMark"] = txtMarks.Text; update.Tables[0].Rows[0]["ComponentAbrev"] = clsFunctions.retrieveAbrev(lstTypes.Text); update.Tables[0].Rows[0]["nqfLevel"] = Convert.ToInt16(nqfTextBox.Text); try { update.Tables[0].Rows[0]["nqfLevel"] = nqfTextBox.Text.Length > 0 ? Convert.ToInt16(nqfTextBox.Text) : 0; } catch (FormatException) { MessageBox.Show("Please enter a number for nqfLevel"); return; } try { update.Tables[0].Rows[0]["credits"] = creditsTextBox.Text.Length > 0 ? Convert.ToInt16(creditsTextBox.Text) : 0; } catch (FormatException) { MessageBox.Show("Please enter a number for credits"); return; } Database.Update(update, "components", "idCourseComponents = '" + splitter[0] + "'"); if (clsFunctions.retrieveAbrev(lstTypes.Text) == "SC" || clsFunctions.retrieveAbrev(lstTypes.Text) == "PROJ") { bool allColleges = DevExpress.XtraEditors.XtraMessageBox.Show("Would you like to apply this change to other components with the same name?", "Alert", MessageBoxButtons.YesNo) == DialogResult.Yes; if (allColleges) { var list = Database.Query("SELECT * FROM components WHERE Name = '" + tempName + "' AND idCourseComponents <> '" + txtID.Text + "'"); var theListArray = new ArrayList(); foreach (DataRow theRow in list.Tables[0].Rows) { theListArray.Add(theRow["idCourseComponents"]); } var listSelect = new frmSelectMulti("Select Courses to Update", "Select Course", theListArray); listSelect.ShowDialog(); if (listSelect.Selection == null) return; string theInString = ""; foreach (string theString in listSelect.Selection) { theInString += "'" + theString + "',"; } theInString = theInString.Remove(theInString.Length - 1); var list2 = Database.Query("SELECT * FROM components WHERE idCourseComponents in(" + theInString + ")"); foreach (DataRow theRow in list2.Tables[0].Rows) { Database.Command("UPDATE components SET IsElective = " + (chkElective.Checked ? "1" : "Null") + ", showOnAssesment = " + (chkAssesment.Checked ? "'yes'" : "Null") + ", Name = '" + txtName.Text + "', totalMark = '" + txtMarks.Text + "', ComponentAbrev = '" + clsFunctions.retrieveAbrev(lstTypes.Text) + "', nqfLevel = '" + nqfTextBox.Text + "', credits = '" + creditsTextBox.Text + "' WHERE idCourseComponents = '" + theRow["idCourseComponents"] + "'"); } } } else { bool allColleges = DevExpress.XtraEditors.XtraMessageBox.Show("Would you like to apply this change to other components that belong to short courses/projects with the same name?", "Alert", MessageBoxButtons.YesNo) == DialogResult.Yes; if (allColleges) { var parent = Database.Row("SELECT * FROM components WHERE idCourseComponents = '" + bubbleParent(txtID.Text) + "'"); var list = Database.Query("SELECT * FROM components WHERE Name = '" + parent["Name"] + "' AND idCourseComponents <> '" + parent["idCourseComponents"] + "'"); var theListArray = new ArrayList(); foreach (DataRow theRow in list.Tables[0].Rows) { theListArray.Add(txtID.Text.Replace(parent["idCourseComponents"].ToString(),theRow["idCourseComponents"].ToString())); } var listSelect = new frmSelectMulti("Select Courses to Update", "Select Course", theListArray); listSelect.ShowDialog(); if (listSelect.Selection == null) return; string theInString = ""; foreach (string theString in listSelect.Selection) { theInString += "'" + theString + "',"; } theInString = theInString.Remove(theInString.Length - 1); var list2 = Database.Query("SELECT * FROM components WHERE idCourseComponents in(" + theInString + ")"); foreach (DataRow theRow in list2.Tables[0].Rows) { Database.Command("UPDATE components SET IsElective = " + (chkElective.Checked ? "1" : "Null") + ", showOnAssesment = " + (chkAssesment.Checked ? "'yes'" : "Null") + ", Name = '" + txtName.Text + "', totalMark = '" + txtMarks.Text + "', ComponentAbrev = '" + clsFunctions.retrieveAbrev(lstTypes.Text) + "', nqfLevel = '" + nqfTextBox.Text + "', credits = '" + creditsTextBox.Text + "' WHERE idCourseComponents = '" + theRow["idCourseComponents"] + "'"); } } } trvCourses.SelectedNode.Text = txtID.Text + " - " + txtName.Text; } }
private void courseEnrollmentToolStripMenuItem_Click(object sender, EventArgs e) { //ArrayList list = new ArrayList(); //DataSet courses = Database.Query("courses", "Not Type = 'CC'"); //foreach (DataRow theRow in courses.Tables["courses"].Rows) //{ // list.Add(theRow["idCourses"] + " - " + theRow["Name"]); //} var frmSelect = new frmCourseSelect("Select Course", "Course to Enroll In"); frmSelect.ShowDialog(); if (frmSelect.Selection == "***") return; string[] arrSplit = new string[5]; string[] splitter = { " - " }; arrSplit = SplitByString(frmSelect.Selection, " - "); DataSet temp = Database.Query("enrollments", "idEnrollments = 0"); string[] columns = new string[4]; string[] values = new string[4]; for (int i2 = 1; i2 <= 4; i2++) { DataColumn theColumn = temp.Tables[0].Columns[i2]; columns[i2 - 1] = theColumn.ColumnName; } values[0] = Database.Retrieve("learner_details", "division = '" + GlobalProperties.loggedOnUserDivison + "' AND learnerNumber = '" + GlobalProperties.strLearnerNumber + "'", "LearnerKey"); var dateSelect = new frmSubmitDate("Please select registration date", "Please select registration date"); dateSelect.ShowDialog(); if (dateSelect.status == false) return; values[1] = dateSelect.Selection.ToString("yyyyMMdd"); values[2] = "1"; values[3] = DateTime.Now.ToString("yyyyMMdd"); Database.Insert("enrollments", columns, values); DataSet tempe = Database.Query("enrollments", "LearnerKey = '" + clsFunctions.GetLearnerKey(GlobalProperties.varLearner_id) + "' AND regDate = '" + dateSelect.Selection.ToString("yyyyMMdd") + "' ORDER BY idEnrollments DESC"); DataSet haselectives = Database.Query("courses", "idCourses = '" + arrSplit[0] + "'"); if (haselectives.Tables[0].Rows.Count > 0) { if (Convert.ToString(haselectives.Tables[0].Rows[0]["hasElectives"]) != "0") { //Retrieve Elective Component Links DataSet electives = Database.Query("coursecomponents", "idCourses = '" + arrSplit[0] + "'"); //foreach elective ArrayList theList = new ArrayList(); foreach (DataRow theRow in electives.Tables[0].Rows) { DataSet row = Database.Query("components", "idCourseComponents = '" + theRow["idComponents"] + "'"); DataRow thetheRow = row.Tables[0].Rows[0]; if (Convert.ToString(thetheRow["isElective"]) == "1") theList.Add(Convert.ToString(thetheRow["idCourseComponents"]) + " - " + Convert.ToString(thetheRow["Name"])); } frmSelectMulti frmMultiSelect = null; try { frmMultiSelect = new frmSelectMulti("Select Electives", "Please Select Electives:", Convert.ToInt16( haselectives.Tables[0].Rows[0][ "hasElectives"]), Convert.ToInt16( haselectives.Tables[0].Rows[0][ "maxElectives"]), theList); } catch { MessageBox.Show( "An error has occured with this action. This is most likely due to no elective information for the course."); return; } if (frmMultiSelect != null) { frmMultiSelect.ShowDialog(); if (frmMultiSelect.Selection == null) return; foreach (object item in frmMultiSelect.Selection) { string[] arrSplit2 = new string[5]; arrSplit2 = SplitByString((string)item, " - "); string[] columns2 = { "idEnrollments", "idCourseComponents" }; string[] values2 = new string[2]; values2[0] = Convert.ToString(tempe.Tables[0].Rows[0]["idEnrollments"]); values2[1] = arrSplit2[0]; Database.Insert("enrollmentcomponents", columns2, values2); } if (frmMultiSelect.Selection.Count == 0) return; } } } string[] arrSplit3 = new string[5]; arrSplit3 = SplitByString(frmSelect.Selection, " - "); string[] coursescolumns = { "idcourses", "Name", "Status", "xPeriod", "Type" }; string[] coursesvalues = new string[5]; coursesvalues[0] = "ENR" + Convert.ToString(tempe.Tables[0].Rows[0]["idEnrollments"]); coursesvalues[1] = "Custom Course Selection"; coursesvalues[2] = "1"; coursesvalues[3] = "0"; coursesvalues[4] = "CC"; Database.Insert("courses", coursescolumns, coursesvalues); //check if this course has electives clsFunctions.WriteLog("Created new enrollment for learner (" + GlobalProperties.strLearnerNumber + ") : Course " + arrSplit[0] + ": Enrollment (" + Convert.ToString(tempe.Tables[0].Rows[0]["idEnrollments"]) + ")"); columns = new string[2]; columns[0] = "idEnrollments"; columns[1] = "idCourses"; values = new string[2]; values[0] = Convert.ToString(tempe.Tables[0].Rows[0]["idEnrollments"]); values[1] = arrSplit3[0]; Database.Insert("enrollmentscourses", columns, values); frmSelect.Dispose(); values[0] = Convert.ToString(tempe.Tables[0].Rows[0]["idEnrollments"]); values[1] = "ENR" + Convert.ToString(tempe.Tables[0].Rows[0]["idEnrollments"]); string subject = (cboEnrollments.Items.Count >= 1 ? "Additional Enrollment :" : "NewEnrollment :"); Database.Insert("enrollmentscourses", columns, values); string message = GlobalProperties.LoggedOnUserDivision + " Learner " + GlobalProperties.strLearnerNumber + " has enrolled for " + arrSplit[1] + ".\nEnrolled By:" + GlobalProperties.loggedOnUser; clsFunctions.SendEmail("*****@*****.**", subject + GlobalProperties.LoggedOnUserDivision, message); DataSet payment = Database.Query("paymentinfo", "idenrollments = '0'"); columns = new string[12]; values = new string[12]; for (int i = 0; i < payment.Tables[0].Columns.Count; i++) { DataColumn theColumn = payment.Tables[0].Columns[i]; columns[i] = theColumn.ColumnName; } values[0] = ""; values[1] = ""; values[2] = ""; values[3] = ""; values[4] = ""; values[5] = ""; values[6] = ""; values[7] = ""; values[8] = "No"; values[9] = "No"; values[10] = ""; values[11] = Convert.ToString(tempe.Tables[0].Rows[0]["idEnrollments"]); Database.Insert("paymentinfo", columns, values); frmSelect.Dispose(); load_enrollmentstab(); cboEnrollments.SelectedIndex = cboEnrollments.Items.Count - 1; string[] arrEnrollmentID = new string[5]; arrEnrollmentID = SplitByString(cboEnrollments.Text, "-"); load_enrollments(arrEnrollmentID[1]); panel1.Visible = true; txtTotalContractPrice.Focus(); }