Exemplo n.º 1
0
    public static Result SetSessionByExamList()
    {
        ExamBO oExamBO = new ExamBO();
        Result oResult = new Result();

        List<Exam> oListExam = new List<Exam>();

        try
        {
            oResult = oExamBO.ExamGetFromDatabaseForSetSession();

            if (oResult.ResultIsSuccess)
            {
                oListExam = (List<Exam>)oResult.ResultObject;

                Utils.SetSession(SessionManager.csStoredExam, oListExam);
            }
        }
        catch (Exception oEx)
        {
            oResult.ResultIsSuccess = false;
            oResult.ResultException = oEx;
            oResult.ResultMessage = "Exception occured during Set Session By ExamList.";
        }

        return oResult;
    }
    //private void LoadSelectionRadioList()
    //{
    //    rdo_SelectConstraint.Items.Clear();
    //    rdo_SelectConstraint.Items.Add("Partial Marking");
    //    rdo_SelectConstraint.Items.Add("Negative Marking");
    //}
    protected void btn_ExamEntry_Click(object sender, EventArgs e)
    {
        try
        {
            Exam oExam = new Exam();
            ExamBO oExamBO = new ExamBO();
            Result oResult = new Result();
            DateTime oDateTime = new DateTime();

            String sDateTime = String.Empty;

            String sHiddenFieldDate = HiddenFieldForDate.Value.Trim();
            String sYear = sHiddenFieldDate.Substring(0, sHiddenFieldDate.IndexOf('/', 0));
            sHiddenFieldDate = sHiddenFieldDate.Substring(sHiddenFieldDate.IndexOf('/', 0) + 1);
            String sMonth = sHiddenFieldDate.Substring(0, sHiddenFieldDate.IndexOf('/', 0));
            sHiddenFieldDate = sHiddenFieldDate.Substring(sHiddenFieldDate.IndexOf('/', 0) + 1);
            String sDate = sHiddenFieldDate;

            if (sMonth.Length == 1)
            {
                sMonth = "0" + sMonth;
            }

            if (sDate.Length == 1)
            {
                sDate = "0" + sDate;
            }

            if (IsValidExamName(txt_ExamName.Text) && IsValidExamTotalMarks(txt_TotalMarks.Text) && IsValidExamDurationHour(txt_Duration.Text) && IsValidYearMonthDateHour(sYear, "Y") && IsValidYearMonthDateHour(sMonth, "M") && IsValidYearMonthDateHour(sDate, "D") && IsValidYearMonthDateHour(dr_Hour.SelectedValue, "H") && IsValidAMPM(dr_AMPM.SelectedValue))
            {
                sDateTime = sMonth + "/" + sDate + "/" + sYear + " " + dr_Hour.SelectedValue + ":" + dr_Minute.SelectedValue + " " + dr_AMPM.SelectedValue;

                //oDateTime = DateTime.ParseExact(sDateTime, "MM/dd/yyyy hh:mm tt", null);

                oDateTime = DateTime.Parse(sDateTime);

                if (IsValidExamDateWithStartingTime(oDateTime))
                {
                    oExam.ExamName = txt_ExamName.Text;
                    oExam.ExamDurationinHour = float.Parse(txt_Duration.Text);
                    oExam.ExamTotalMarks = int.Parse(txt_TotalMarks.Text);
                    oExam.ExamDateWithStartingTime = oDateTime;
                     //&& IsValidConstraint(rdo_SelectConstraint.SelectedValue)
                    //if (IsAnySelectedConstraint(rdo_SelectConstraint.SelectedValue)) //if no constrained selected then default constraint =0
                    //{
                    //    oExam.ExamConstraint = rdo_SelectConstraint.SelectedIndex + 1;  //0=Full Marking,1=Partial Marking, 2=Negative Marking
                    //}

                    if (!chk_Partial.Checked && !chk_Negative.Checked)
                    {
                        oExam.ExamConstraint = 0;
                    }
                    else if (chk_Partial.Checked && !chk_Negative.Checked)
                    {
                        oExam.ExamConstraint = 1;
                    }
                    else if (!chk_Partial.Checked && chk_Negative.Checked)
                    {
                        oExam.ExamConstraint = 2;
                    }
                    else if (chk_Partial.Checked && chk_Negative.Checked)
                    {
                        oExam.ExamConstraint = 3;
                    }

                    oResult = oExamBO.ExamEntry(oExam);

                    if (oResult.ResultIsSuccess)
                    {
                        lbl_error.ForeColor = Color.Green;
                        lbl_error.Text = oResult.ResultMessage;

                        Utils.SetSessionByExamList();

                        clearControlValue();
                    }
                    else
                    {
                        lbl_error.ForeColor = Color.Red;
                        lbl_error.Text = oResult.ResultMessage;
                    }
                }
                else
                {
                    lbl_error.ForeColor = Color.Red;
                    lbl_error.Text = "Exam Date should be greater than curren DateTime(+1 Hour).";
                }

            }
            else
            {
                lbl_error.ForeColor = Color.Red;
                lbl_error.Text = "Enter all value in corrected format.";
            }

            //LoadSelectionRadioList();
        }
        catch (Exception oEx)
        {
            lbl_error.ForeColor = Color.Red;
            lbl_error.Text = "Exception occured during Exam Entry.";
        }
    }