public void LoadData() { if (_mode == "Edit" || _mode == "AddClone") { if (_mode == "Edit") this.Text = "Editing Course..."; else { this.Text = "Adding Course Clone..."; btnDelete.Enabled = false; } Scheduler.BusinessLayer.Course objCourse=new Scheduler.BusinessLayer.Course(); objCourse.CourseId = _courseid; objCourse.LoadData(); IsRecurringSeries = objCourse.IsRecurring(); bool[] boolArray = objCourse.CheckTestEvents(); HasTestInitialEvent = boolArray[0]; HasTestMidtermEvent = boolArray[1]; HasTestFinalEvent = boolArray[2]; foreach(DataRow dr in objCourse.CourseDataTable.Rows) { //Get the Client/Department/Program if(dr["Client"]!=System.DBNull.Value) cmbClient.Text = dr["Client"].ToString(); intClientID = Common.GetCompanyID( "Select ContactID From Contact " + "Where (CompanyName=@CompanyName OR NickName=@CompanyName) ", cmbClient.Text ); if(intClientID!=0) { llblClient.Tag = intClientID; Common.PopulateDropdown( cmbDept, "Select CASE " + "WHEN C.NickName IS NULL THEN C.CompanyName " + "WHEN C.NickName = '' THEN C.CompanyName " + "ELSE C.NickName " + "END AS CompanyName From " + "Department D, Contact C Where D.ContactID=C.ContactID " + "and D.ClientID=" + intClientID + " Order By CompanyName"); } if(dr["Department"]!=System.DBNull.Value) cmbDept.Text = dr["Department"].ToString(); string query = "Select CASE " + "WHEN C.NickName IS NULL THEN C.CompanyName " + "WHEN C.NickName = '' THEN C.CompanyName " + "ELSE C.NickName " + "END AS CompanyName From " + "Department D, Contact C Where D.ContactID=C.ContactID and " + "D.DepartmentStatus=1 and D.ClientID=" + intClientID + " Order By CompanyName"; IDataReader reader = DAC.SelectStatement(query); while (reader.Read()) { if (reader["CompanyName"] != DBNull.Value && reader["CompanyName"].ToString() != cmbDept.Text) { cmbDept.Items.Remove(reader["CompanyName"].ToString()); ; } } intDepartmentID = Common.GetCompanyID( "Select D.DepartmentID, C.ContactID From Department D, Contact C " + "Where D.ContactID=C.ContactID and (C.CompanyName=@CompanyName OR C.NickName=@CompanyName) and D.ClientID = '" + intClientID + "' ", cmbDept.Text ); if (intDepartmentID != 0) { llbDepartment.Tag = intDepartmentID; Common.PopulateDropdown( cmbProgram, "Select CASE " + "WHEN NickName IS NULL THEN [Name] " + "WHEN NickName = '' THEN [Name] " + "ELSE NickName " + "END AS [Name] From " + "Program Where DepartmentID=" + intDepartmentID + " Order By [Name]"); } if (dr["Program"] != System.DBNull.Value) { llblProgram.Tag = dr["ProgramId"].ToString(); cmbProgram.SelectedIndex = cmbProgram.Items.IndexOf(dr["Program"].ToString()); } query = "Select CASE " + "WHEN NickName IS NULL THEN [Name] " + "WHEN NickName = '' THEN [Name] " + "ELSE NickName " + "END AS [Name] From " + "Program Where ProgramStatus=1 and DepartmentID=" + intDepartmentID + " Order By [Name]"; reader = DAC.SelectStatement(query); while (reader.Read()) { if (reader["Name"] != DBNull.Value && reader["Name"].ToString() != cmbProgram.Text) { cmbProgram.Items.Remove(reader["Name"].ToString()); ; } } txtCourseName.Text = dr["Name"].ToString(); if (_mode == "AddClone") txtCourseName.Text = "Copy of " + txtCourseName.Text; txtNamePhonetic.Text = dr["NamePhonetic"].ToString(); txtNameRomaji.Text = dr["NameRomaji"].ToString(); txtNickName.Text = dr["NickName"].ToString(); txtDescription.Text = dr["Description"].ToString(); txtRemarks.Text = dr["SpecialRemarks"].ToString(); txtCurriculam.Text = dr["Curriculam"].ToString(); cmbCourseType.Text = dr["CourseType"].ToString(); txtNumberStudents.Text = dr["NumberStudents"].ToString(); txtHomeWorkMinutes.Text = dr["HomeWorkMinutes"].ToString(); textBoxBreakDuration.Text = dr["BreakDuration"].ToString(); if (dr["CourseStatus"].ToString() == "Active") cmbStatus.SelectedIndex = 0; else { cmbStatus.SelectedIndex = 1; //chkEventModified.Checked = true; } if (_mode == "Edit") { txtInitialEvent.Text = dr["TestInitialEventId"].ToString(); txtMidtermEvent.Text = dr["TestMidTermEventId"].ToString(); txtFinalEvent.Text = dr["TestFinalEventId"].ToString(); txtEvent.Text = dr["EventID"].ToString(); eventid[0] = Convert.ToInt32(dr["TestInitialEventId"].ToString()); eventid[1] = Convert.ToInt32(dr["TestMidTermEventId"].ToString()); eventid[2] = Convert.ToInt32(dr["TestFinalEventId"].ToString()); eventid[3] = Convert.ToInt32(dr["EventID"].ToString()); //Making sure all events on record exist if (eventid[0] > 0) { if (!objCourse.IsEventExists(eventid[0])) eventid[0] = 0; } if (eventid[1] > 0) { if (!objCourse.IsEventExists(eventid[1])) eventid[1] = 0; } if (eventid[2] > 0) { if (!objCourse.IsEventExists(eventid[2])) eventid[2] = 0; } if (eventid[3] > 0) { if (!objCourse.IsEventExists(eventid[3])) eventid[3] = 0; } txtInitialForm.Text = dr["TestInitialForm"].ToString(); txtMidtermForm.Text = dr["TestMidTermForm"].ToString(); txtFinalForm.Text = dr["TestFinalForm"].ToString(); } else { txtInitialEvent.Text = String.Empty; txtMidtermEvent.Text = String.Empty; txtFinalEvent.Text = String.Empty; txtEvent.Text = String.Empty; eventid[0] = 0; eventid[1] = 0; eventid[2] = 0; eventid[3] = 0; txtInitialForm.Text = String.Empty; txtMidtermForm.Text = String.Empty; txtFinalForm.Text = String.Empty; } break; } if (_mode == "Edit") { //Load Events if any string strHint = ""; llblInitialEvt.Text = objCourse.getEventText(txtInitialEvent.Text, "Initial", ref strHint); if (strHint == "None") txtInitialEvent.Text = "0"; strHint = ""; llblMidEvt.Text = objCourse.getEventText(txtMidtermEvent.Text, "Midterm", ref strHint); if (strHint == "None") txtMidtermEvent.Text = "0"; strHint = ""; llblFinalEvt.Text = objCourse.getEventText(txtFinalEvent.Text, "Final", ref strHint); if (strHint == "None") txtFinalEvent.Text = "0"; strHint = ""; llblEvent.Text = objCourse.getEventText(txtEvent.Text, "Event", ref strHint); if (strHint != "") llblEvent.Text = strHint; if (strHint == "None") txtEvent.Text = "0"; strHint = ""; if (eventid[intIndex] > 0) LoadEvent(eventid[intIndex], calendareventid[intIndex]); } else { llblInitialEvt.Text = String.Empty; txtInitialEvent.Text = "0"; llblMidEvt.Text = String.Empty; txtMidtermEvent.Text = "0"; llblFinalEvt.Text = String.Empty; txtFinalEvent.Text = "0"; llblEvent.Text = String.Empty; txtEvent.Text = "0"; } if (_mode == "Edit") { string query = "Select CASE " + "WHEN NickName IS NULL THEN CompanyName " + "WHEN NickName = '' THEN CompanyName " + "ELSE NickName " + "END AS CompanyName From " + "Contact Where ContactType=2 and " + "ContactStatus=1 Order By CompanyName"; IDataReader reader = DAC.SelectStatement(query); while (reader.Read()) { if (reader["CompanyName"] != DBNull.Value && reader["CompanyName"].ToString() != cmbClient.Text) cmbClient.Items.Remove(reader["CompanyName"].ToString()); } query = "Select " + "CASE " + "WHEN NickName IS NULL THEN LastName + ', ' + FirstName " + "WHEN NickName = '' THEN LastName + ', ' + FirstName " + "ELSE NickName " + "END as TeacherName From " + "Contact Where ContactType=1 and " + "ContactStatus=1 Order By LastName, FirstName "; reader = DAC.SelectStatement(query); while (reader.Read()) { if (reader["TeacherName"] != DBNull.Value && reader["TeacherName"].ToString() != cmbTeacher2_I.Text && reader["TeacherName"].ToString() != cmbTeacher1_I.Text) { cmbTeacher1_I.Items.Remove(reader["TeacherName"].ToString()); cmbTeacher2_I.Items.Remove(reader["TeacherName"].ToString()); } } } } else { this.Text = "Adding Class..."; string query = "Select CASE " + "WHEN NickName IS NULL THEN CompanyName " + "WHEN NickName = '' THEN CompanyName " + "ELSE NickName " + "END as CompanyName From " + "Contact Where ContactType=2 and " + "ContactStatus=1 Order By CompanyName"; IDataReader reader = DAC.SelectStatement(query); while (reader.Read()) { if (reader["CompanyName"] != DBNull.Value ) cmbClient.Items.Remove(reader["CompanyName"].ToString()); } query = "Select " + "CASE " + "WHEN NickName IS NULL THEN LastName + ', ' + FirstName " + "WHEN NickName = '' THEN LastName + ', ' + FirstName " + "ELSE NickName " + "END as TeacherName From " + "Contact Where ContactType=1 and " + "ContactStatus=1 Order By LastName, FirstName "; reader = DAC.SelectStatement(query); while (reader.Read()) { if (reader["TeacherName"] != DBNull.Value) { cmbTeacher1_I.Items.Remove(reader["TeacherName"].ToString()); cmbTeacher2_I.Items.Remove(reader["TeacherName"].ToString()); } } cmbClient.Text = String.Empty; cmbDept.Text = String.Empty; cmbProgram.Text = String.Empty; txtCourseName.Text = String.Empty; txtNamePhonetic.Text = String.Empty; txtNameRomaji.Text = String.Empty; txtNickName.Text = String.Empty; txtDescription.Text = String.Empty; txtRemarks.Text = String.Empty; txtCurriculam.Text = String.Empty; cmbCourseType.Text = String.Empty; txtNumberStudents.Text = String.Empty; txtHomeWorkMinutes.Text = String.Empty; textBoxBreakDuration.Text = String.Empty; txtInitialEvent.Text = String.Empty; txtMidtermEvent.Text = String.Empty; txtFinalEvent.Text = String.Empty; txtEvent.Text = String.Empty; eventid[0] = 0; eventid[1] = 0; eventid[2] = 0; eventid[3] = 0; txtInitialForm.Text = String.Empty; txtMidtermForm.Text = String.Empty; txtFinalForm.Text = String.Empty; cmbStatus.SelectedIndex = 0; SetEventModificationControls(false); //load Events if any llblInitialEvt.Text = String.Empty; txtInitialEvent.Text = "0"; llblMidEvt.Text = String.Empty; txtMidtermEvent.Text = "0"; llblFinalEvt.Text = String.Empty; txtFinalEvent.Text = "0"; llblEvent.Text = String.Empty; llblEvent.Text = String.Empty; } }
private void btnDelete_Click(object sender, System.EventArgs e) { if (BusinessLayer.Message.MsgDelete()) { Scheduler.BusinessLayer.Course objCourse = new Scheduler.BusinessLayer.Course(); objCourse.CourseId = _courseid; if (!objCourse.DeleteData()) { BusinessLayer.Message.MsgWarning("Class cannot be deleted"); return; } else { deleted = true; btnDelete.Enabled = false; this.Text = "Adding Class..."; _mode = "Add"; _courseid = 0; foreach (Control c in tbpCourse.Controls) { if (c.GetType().ToString() == "System.Windows.Forms.TextBox") { if (c.Tag == null) c.Text = ""; else if (c.Tag.ToString() == "N") c.Text = "0"; } if (c.GetType().ToString() == "System.Windows.Forms.LinkLabel") { c.Text = "None"; } if (c.GetType().ToString() == "System.Windows.Forms.ComboBox") { c.Text = ""; } } foreach (Control c in tbpCurriculam.Controls) { if (c.GetType().ToString() == "System.Windows.Forms.TextBox") { if (c.Tag == null) c.Text = ""; else if (c.Tag.ToString() == "N") c.Text = "0"; } if (c.GetType().ToString() == "System.Windows.Forms.ComboBox") { c.Text = ""; } } foreach (Control c in tbpDescription.Controls) { if (c.GetType().ToString() == "System.Windows.Forms.TextBox") { if (c.Tag == null) c.Text = ""; else if (c.Tag.ToString() == "N") c.Text = "0"; } if (c.GetType().ToString() == "System.Windows.Forms.ComboBox") { c.Text = ""; } } foreach (Control c in tbpSpecialRemarks.Controls) { if (c.GetType().ToString() == "System.Windows.Forms.TextBox") { if (c.Tag == null) c.Text = ""; else if (c.Tag.ToString() == "N") c.Text = "0"; } if (c.GetType().ToString() == "System.Windows.Forms.ComboBox") { c.Text = ""; } } this.DialogResult = DialogResult.OK; Close(); } } }
private void btnSave_Click(object sender, System.EventArgs e) { btnEventSave_Click(sender, e); //fake call to save event. it is here to remove a save button. actually the code below is unclear to me sorry #region Course Validation if (txtCourseName.Text == "") { tbcCourse.SelectedIndex = 0; Scheduler.BusinessLayer.Message.MsgInformation("Enter Class Name"); txtCourseName.Focus(); return; } if (cmbProgram.Text == "") { tbcCourse.SelectedIndex = 0; Scheduler.BusinessLayer.Message.MsgInformation("Enter Program"); cmbProgram.Focus(); return; } if (cmbCourseType.Text == "") { tbcCourse.SelectedIndex = 0; Scheduler.BusinessLayer.Message.MsgInformation("Enter Job Type"); cmbCourseType.Focus(); return; } bool boolSuccess; #endregion Scheduler.BusinessLayer.Course objCourse = null; #region Setting Course Object objCourse = new Scheduler.BusinessLayer.Course(); objCourse.CourseId = 0; objCourse.name = txtCourseName.Text; objCourse.NamePhonetic = txtNamePhonetic.Text; objCourse.NameRomaji = txtNameRomaji.Text; objCourse.NickName = txtNickName.Text; objCourse.ProgramID = intProgramID; objCourse.CourseType = cmbCourseType.Text; int noOfStudents = 0; if (txtNumberStudents.Text != "") Int32.TryParse(txtNumberStudents.Text, out noOfStudents); int homeworkMinutes = 0; if (txtHomeWorkMinutes.Text != "") Int32.TryParse(txtHomeWorkMinutes.Text, out homeworkMinutes); int breakDuration = 0; if (textBoxBreakDuration.Text != "") Int32.TryParse(textBoxBreakDuration.Text, out breakDuration); objCourse.NumberStudents = noOfStudents; objCourse.HomeWorkMinutes = homeworkMinutes; objCourse.BreakDuration = breakDuration; objCourse.Description = txtDescription.Text; objCourse.SpecialRemarks = txtRemarks.Text; objCourse.Curriculam = txtCurriculam.Text; objCourse.TestInitialEventID = eventid[0];//Convert.ToInt32(txtInitialEvent.Text); objCourse.TestMidEventID = eventid[1];//Convert.ToInt32(txtMidtermEvent.Text); objCourse.TestFinalEventID = eventid[2];//Convert.ToInt32(txtFinalEvent.Text); objCourse.EventID = eventid[3];//Convert.ToInt32(txtEvent.Text); objCourse.TestInitialForm = txtInitialForm.Text; objCourse.TestMidtermForm = txtMidtermForm.Text; objCourse.TestFinalForm = txtFinalForm.Text; objCourse.CourseStatus = cmbStatus.SelectedIndex; objCourse.CourseId = _courseid; //if (objCourse.Exists()) //{ // Scheduler.BusinessLayer.Message.MsgInformation("Duplicate Class Name not allowed"); // txtCourseName.Focus(); // return; //} if (txtNickName.Text != "") { if (objCourse.NickNameExists()) { Scheduler.BusinessLayer.Message.MsgInformation("Duplicate Abbreviated Name not allowed"); txtNickName.Focus(); return; } } if ((_mode == "Add") || (_mode == "AddClone") || (_mode == "")) { boolSuccess = objCourse.InsertData(); } else { objCourse.CourseId = _courseid; boolSuccess = objCourse.UpdateData(); } #endregion #region Handling the event saving if (IsEventChanged) { DialogResult dlg = MessageBox.Show(this, "You have made changes to the events.\n\nWould you like to save the changes?", "Scheduler", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (dlg == DialogResult.Yes) { SaveAllEvents(GetCurrentEventID((TabPage)pnlEvent.Parent)); } } if (objEvent != null) { //Update the events _courseid = objCourse.CourseId; if (_courseid != 0) { int _id = 0; //Test Initial Event if (eventid[0] != 0) { _id = eventid[0]; if (_id < 0) _id = 0; objEvent.UpdateClassEvent("TestInitialEventID", _id, _courseid); _id = 0; } //Test Midterm Event if (eventid[1] != 0) { _id = eventid[1]; if (_id < 0) _id = 0; objEvent.UpdateClassEvent("TestMidtermEventID", _id, _courseid); _id = 0; } //Test Final Event if (eventid[2] != 0) { _id = eventid[2]; if (_id < 0) _id = 0; objEvent.UpdateClassEvent("TestFinalEventID", _id, _courseid); _id = 0; } //Class Event if (eventid[3] != 0) { _id = eventid[3]; if (_id < 0) _id = 0; objEvent.UpdateClassEvent("EventID", _id, _courseid); _id = 0; } } } #endregion if (!boolSuccess) { if (_mode == "Add") Scheduler.BusinessLayer.Message.ShowException("Inserting Class record.", objCourse.Message); else if (_mode == "AddClone") Scheduler.BusinessLayer.Message.ShowException("Cloning Class record.", objCourse.Message); else Scheduler.BusinessLayer.Message.ShowException("Updating Class record.", objCourse.Message); return; } this.DialogResult = DialogResult.OK; Close(); }