Пример #1
0
    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>");
        }
    }
Пример #2
0
    protected void btnSave_Click(object sender, EventArgs e)
    {
        ILMPVO ilmpVO = new ILMPVO();

        try
        {
            ilmpVO.Name = txtName.Text;
            if (txtStudentId.Text.Trim() != "")
            {
                try
                {
                    ilmpVO.StudentId = Int32.Parse(txtStudentId.Text);
                }
                catch (ParseException)
                {
                    ScriptManager.RegisterClientScriptBlock(this.Page, this.Page.GetType(), "alert", "alert(' StudentId is not valid ');", true);
                    // Response.Write("<script>alert('StudentId is not valid');</script>");
                    return;
                }
            }
            else
            {
                ScriptManager.RegisterClientScriptBlock(this.Page, this.Page.GetType(), "alert", "alert(' Please enter student id');", true);
                // Response.Write("<script>alert('Please enter student id');</script>");
                return;
            }
            ilmpVO.Active      = ddActive.SelectedItem.Text;
            ilmpVO.Description = txtDescription.Text;
            List <ILMPCourseVO> templateCourses = new List <ILMPCourseVO>();
            if (ViewState["CurrentTable"] != null)
            {
                DataTable dt = (DataTable)ViewState["CurrentTable"];

                // storing the grid values in KeyValue Pair because every semester will have multiple entries, it should be consolidated to store in database
                if (dt.Rows.Count > 0)
                {
                    ILMPCourseVO ilmpCourseVO = new ILMPCourseVO();
                    for (int i = 0; i < dt.Rows.Count - 1; i++)
                    {
                        ilmpCourseVO = new ILMPCourseVO();
                        Label        courseCode = (Label)gvIlmp.Rows[i].Cells[0].FindControl("lblCourseCode");
                        DropDownList ddl1       = (DropDownList)gvIlmp.Rows[i].Cells[1].FindControl("ddCourseType");
                        DropDownList ddl2       = (DropDownList)gvIlmp.Rows[i].Cells[2].FindControl("ddSemester");
                        DropDownList ddl3       = (DropDownList)gvIlmp.Rows[i].Cells[3].FindControl("ddYear");
                        string       courseType = ddl1.SelectedItem.Text;
                        int          semester   = Int32.Parse(ddl2.SelectedItem.Text);
                        int          year       = 0;
                        if (ddl3.SelectedItem.Text != null && ddl3.SelectedItem.Text != "Select")
                        {
                            year = Int32.Parse(ddl3.SelectedItem.Text);
                        }
                        ilmpCourseVO.CourseCode = courseCode.Text;
                        ilmpCourseVO.Semester   = semester;
                        ilmpCourseVO.Year       = year;
                        ilmpCourseVO.CourseType = courseType;
                        templateCourses.Add(ilmpCourseVO);
                    }
                    ilmpVO.IlmpCourses = templateCourses;
                    ilmpVO.TemplateId  = int.Parse(hfTemplateId.Value);
                    ILMPBO ilmpBO = new ILMPBO();
                    string status = ilmpBO.AddILMP(ilmpVO);
                    ScriptManager.RegisterClientScriptBlock(this.Page, this.Page.GetType(), "alert", "alert('" + status + "');", true);
                    //Response.Write("<script>alert('" + status + "');</script>");

                    /* if (status.Contains("success"))
                     * {
                     * //  btnSave.Enabled = false;
                     * }
                     * else
                     * {
                     *   btnSave.Enabled = true;
                     * }*/
                }
                else
                {
                    ScriptManager.RegisterClientScriptBlock(this.Page, this.Page.GetType(), "alert", "alert('There are no courses added in ILMP');", true);
                    // Response.Write("<script>alert('There are no courses added in ILMP');</script>");
                }
            }
        }
        catch (CustomException ex)
        {
            ScriptManager.RegisterClientScriptBlock(this.Page, this.Page.GetType(), "alert", "alert('" + ex.Message + "');", true);
        }
    }