protected void txtCustomStudentId_TextChanged(object sender, EventArgs e) { StudentBO studentBO = new StudentBO(); StudentMajorBO studentmajorBO = new StudentMajorBO(); int studentId = 0; if (txtCustomStudentId.Text.Trim() != "") { try { studentId = int.Parse(txtCustomStudentId.Text.Trim()); string studentName = studentBO.GetStudentNameForId(studentId); if (studentName != "") { List <StudentMajorVO> stmajorList = studentmajorBO.GetStudentMajorList(studentId); string major = ""; foreach (StudentMajorVO studentMajorVO in stmajorList) { major += "&" + studentMajorVO.MajorID; } if (major.StartsWith("&")) { major = major.Substring(1); } txtStudentMajor.Text = major; ddMajor.Enabled = false; txtStudentId.Text = studentId.ToString(); } txtName.Text = studentName; if (studentName == "") { ScriptManager.RegisterClientScriptBlock(this.Page, this.Page.GetType(), "alert", "alert(' Please enter a valid student id');", true); // Response.Write("<script>alert(' Please enter a valid student id ');</script>"); return; } else { FillTemplateNameDropDown(); } } catch (ParseException) { ScriptManager.RegisterClientScriptBlock(this.Page, this.Page.GetType(), "alert", "alert(' Please enter a valid student id ');", true); //Response.Write("<script>alert(' Please enter a valid student id ');</script>"); } catch (Exception ex) { Response.Write("<script>alert(' Error in getting student details ');</script>"); ExceptionUtility.LogException(ex, "Error Page"); } } else { txtStudentId.Text = ""; txtName.Text = ""; } }
protected void btnAddStudent_Click(object sender, EventArgs e) { try { DBConnection.conn.Open(); SqlCommand cmd = new SqlCommand("SELECT COUNT(*) FROM dbo.Student WHERE StudentID =" + Convert.ToInt32(txtStudentID.Text.Trim()), DBConnection.conn); Int32 count = (Int32)cmd.ExecuteScalar(); DBConnection.conn.Close(); if (count > 0) { Response.Write("<script>alert('StudentID already exists.');</script>"); } else if (!txtEmail.Text.Trim().EndsWith("@ess.ais.ac.nz")) { Response.Write("<script>alert('Please enter valid email (e.g. [email protected])');</script>"); } DBConnection.conn.Open(); SqlCommand cmd1 = new SqlCommand("SELECT COUNT(*) FROM dbo.IlmpUser WHERE EmailId ='" + txtEmail.Text.Trim() + "'", DBConnection.conn); Int32 count1 = (Int32)cmd1.ExecuteScalar(); DBConnection.conn.Close(); if (count1 > 0) { Response.Write("<script>alert('Email already exists, please check email Student');</script>"); } else { bool valid = ValidateControls(); if (valid) { int studentID = 0; try { studentID = Int32.Parse(txtStudentID.Text); } catch (ParseException) { Response.Write("<script>alert('Please enter valid studentid');</script>"); } string firstName = txtFirstName.Text; string lastName = txtLastName.Text; string status = "Studying"; string emailID = txtEmail.Text; DateTime createdDTM = DateTime.Now; DateTime updatedDTM = DateTime.Now; StudentVO studentVO = new StudentVO(studentID, firstName, lastName, status, createdDTM, updatedDTM); UserVO userVO = new UserVO(); userVO.StudentID = studentID; userVO.StaffID = 0; userVO.EmailID = emailID; userVO.Role = ApplicationConstants.StudentRole; if (lbMajor.Items.Count == 0) { Response.Write("<script>alert('Please choose major');</script>"); } else if (studentBO.AddStudent(studentVO)) { for (int i = 0; i < lbMajor.Items.Count; i++) { ListItem lmajor = lbMajor.Items[i]; StudentMajorVO studentMajorVO = new StudentMajorVO(studentID, ddlProgramme.SelectedItem.Value, lmajor.Value, "Yes"); StudentMajorBO studentMajorBO = new StudentMajorBO(); if (studentMajorBO.AddStudent(studentMajorVO)) { Response.Write("<script>alert('Student added successfully');</script>"); } else { Response.Write("<script>alert('Error in adding student major');</script>"); } } UserBO userBO = new UserBO(); userBO.AddUser(userVO); } else { Response.Write("<script>alert('Error in adding student');</script>"); } } else { Response.Write("<script>alert('Please enter all student details');</script>"); } } } catch (CustomException ex) { Response.Write("<script>alert('" + ex.Message + "');</script>"); } catch (Exception ex) { Response.Write("<script>alert('Error in adding student');</script>"); ExceptionUtility.LogException(ex, "Error Page"); } Clear(); }
private void SetInitialRowInGrids() { ILMPVO ilmpVO = new ILMPVO(); ilmpVO = ilmpBO.GetILMPCoursesWorkshopForId(ilmpId); populateILMPDetails(ilmpVO); StudentMajorBO studentMajorBO = new StudentMajorBO(); studentMajorVO = studentMajorBO.GetStudentMajor(ilmpVO.StudentId); // ILMPTemplateVO ilmpTemplateVO = ilmpTemplateBO.GetTemplateForId(ilmpVO.TemplateId); if (ilmpVO.IlmpCourses.Count > 0) { DataTable dt = new DataTable(); DataRow dr = null; //Define the Columns dt.Columns.Add(new DataColumn("Column1", typeof(string))); dt.Columns.Add(new DataColumn("Column2", typeof(string))); dt.Columns.Add(new DataColumn("Column3", typeof(string))); dt.Columns.Add(new DataColumn("Column4", typeof(string))); dt.Columns.Add(new DataColumn("Column5", typeof(string))); dt.Columns.Add(new DataColumn("Column6", typeof(string))); dt.Columns.Add(new DataColumn("Column7", typeof(string))); dt.Columns.Add(new DataColumn("Column8", typeof(string))); dt.Columns.Add(new DataColumn("Column9", typeof(string))); //Add a Dummy Data on Initial Load dr = dt.NewRow(); dt.Rows.Add(dr); //Store the DataTable in ViewState ViewState["CurrentTable"] = dt; //Bind the DataTable to the Grid gvIlmpCourse.DataSource = dt; gvIlmpCourse.DataBind(); gvIlmpCourse.Rows[0].Cells[0].Width = 40; // AddNewRowToGrid(); DataTable dt1 = new DataTable(); DataRow dr1 = null; dt1.Columns.Add(new DataColumn("Column1", typeof(string))); //Add a Dummy Data on Initial Load dr1 = dt1.NewRow(); dt1.Rows.Add(dr1); //Store the DataTable in ViewState ViewState["CurrentTableWorkshop"] = dt1; //Bind the DataTable to the Grid gvWorkshop.DataSource = dt1; gvWorkshop.DataBind(); foreach (ILMPCourseVO ilmpCourseVO in ilmpVO.IlmpCourses) { AddNewRowToCourseGrid(ilmpCourseVO); } List <WorkshopVO> workshops = ilmpBO.GetILMPWorkshopForId(ilmpId); foreach (WorkshopVO workshopVO in workshops) { AddNewRowToWorkshopGrid(workshopVO.WorkshopId); } /* foreach (TemplateCourseVO templateCourseVO in ilmpTemplateVO.TemplateCourses) * { * if (templateCourseVO.WorkshopId == 0 && templateCourseVO.CourseCode != "") * { * AddNewRowToCourseGrid(templateCourseVO); * } * else * { * AddNewRowToWorkshopGrid(templateCourseVO.WorkshopId); * } * }*/ if ((gvIlmpCourse.Rows[gvIlmpCourse.Rows.Count - 1].Cells[0].FindControl("lblCourseCode") as Label).Text == "") { gvIlmpCourse.Rows[gvIlmpCourse.Rows.Count - 1].Visible = false; } if ((gvWorkshop.Rows[gvWorkshop.Rows.Count - 1].Cells[0].FindControl("lblWorkshop") as Label).Text == "") { gvWorkshop.Rows[gvWorkshop.Rows.Count - 1].Visible = false; } } List <ILMPCourseGridVO> ilmpCourses = ilmpBO.GetILMPCoursesForId(ilmpId); for (int i = 0; i < gvIlmpCourse.Rows.Count - 1; i++) { ((DropDownList)gvIlmpCourse.Rows[i].Cells[2].FindControl("ddSemester")).Text = ilmpCourses[i].Semester.ToString(); ((DropDownList)gvIlmpCourse.Rows[i].Cells[3].FindControl("ddYear")).Text = ilmpCourses[i].Year.ToString(); ((DropDownList)gvIlmpCourse.Rows[i].Cells[1].FindControl("ddCourseType")).Text = ilmpCourses[i].CourseType.ToString(); ((DropDownList)gvIlmpCourse.Rows[i].Cells[1].FindControl("ddResult")).Text = ilmpCourses[i].Result.ToString(); } }
protected void btnUpdateStudent_Click(object sender, EventArgs e) { try { int studentID = Convert.ToInt32(txtStudentID.Text.Trim()); string firstName = txtFirstName.Text.Trim(); string lastName = txtLastName.Text.Trim(); string programmeId = ddlStudentProgramme.SelectedValue.Trim(); string emailID = txtEmailID.Text.Trim(); string status = ddlStatus.Text.Trim(); DateTime updatedDTM = DateTime.Now; string active = ""; if (ddlStatus.Text != "Studying") { active = "No"; } else { active = "Yes"; } if (!txtEmailID.Text.Trim().EndsWith("@ess.ais.ac.nz")) { Response.Write("<script>alert('Please enter valid email ess.ais.ac.nz');</script>"); } StudentVO studentVO = new StudentVO(studentID, firstName, lastName, status, updatedDTM); UserVO userVO = new UserVO(studentID, emailID, active); if (active == "No" || status == "Withdrawn" || status == "Graduated" || status == "Postponed") { ILMPBO ilmpBO = new ILMPBO(); bool ilmpUpdationStatus = ilmpBO.UpdateILMPStatusForStudent(studentID, "No"); } if (txtFirstName.Text == "" || txtLastName.Text == "" || txtEmailID.Text == "" || lbMajor.Items.Count == 0) { Response.Write("<script>alert('Please check First Name, Last Name, Email and Major is filled');</script>"); } else if (studentBO.UpdateStudent(studentVO) && userBO.UpdateUser(userVO)) { DBConnection.conn.Open(); string query = "DELETE FROM StudentMajor WHERE StudentID=" + studentID; SqlCommand cmd2 = new SqlCommand(query, DBConnection.conn); cmd2.ExecuteNonQuery(); DBConnection.conn.Close(); for (int i = 0; i < lbMajor.Items.Count; i++) { ListItem lmajor = lbMajor.Items[i]; StudentMajorVO studentMajorVO = new StudentMajorVO(studentID, programmeId, lmajor.Value, active); StudentMajorBO studentMajorBO = new StudentMajorBO(); if (studentMajorBO.AddStudent(studentMajorVO)) { Response.Write("<script>alert('Student updated successfully');</script>"); } else { Response.Write("<script>alert('Error in updating student major');</script>"); } } } else { Response.Write("<script>alert('Student update Fail');</script>"); } } catch (CustomException ex) { Response.Write("<script>alert('" + ex.Message + "');</script>"); } catch (SqlException ex) { ExceptionUtility.LogException(ex, "Error Page"); Response.Write("<script>alert('" + ex.Message + "');</script>"); } catch (Exception ex) { ExceptionUtility.LogException(ex, "Error Page"); Response.Write("<script>alert('Student updation failed');</script>"); } }