protected void Page_Load(object sender, EventArgs e)
        {
            DataAccess objGetRSIquestionList = new DataAccess();
            DataSet ds = new DataSet();
            Session["Candidateid"] = MHRISesstion.CandidateId;
            // Session["Candidateid"] = "2";
            if (!IsPostBack)
            {
                DataAccess DE = new DataAccess();
                List<DataEntity> lstCandidateDetails = DE.GetCandidateDetails(Convert.ToInt32(MHRISesstion.CandidateId), System.DateTime.Now.ToString("dd/MM/yyyy"));

                if (lstCandidateDetails.Count > 0)
                {                    
                    lblCandidateDetails.Text = "Welcome " + lstCandidateDetails[0].FirstNameTodisplayExampage;
                }
                
                ds = objGetRSIquestionList.GetListofQuestions("PSI");
                Session["ResultData"] = ds.Tables["QuesInfo"];
                GridView1.DataSource = ds.Tables["QuesInfo"];
                GridView1.DataBind();
                               
                CreateOldTable(OldTable);
                CopyDataOldTable((DataTable)Session["ResultData"]);
                strPSIRange = DataConstant.PSIRange;
            }

            lblmsg.ForeColor = System.Drawing.Color.Green;
            lblmsg.Text = "";
        }
        /// <summary>
        /// Authenticate User
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        /// 

        #region Button Event
        protected void HRloginButton_Click(object sender, ImageClickEventArgs e)
        {
            DataAccess IsValidLoginbool = new DataAccess();

            if (IsValidLoginbool.IsValidLogin(txtHRid.Text, txtHRpwd.Text))
            {
                lblmsg.ForeColor = System.Drawing.Color.Green;
                lblmsg.Text = "Sucessfull login";        
                Response.Redirect("../Forms/CandidateLogin.aspx",false);
            }
            else
            {
                lblmsg.ForeColor = System.Drawing.Color.Red;
                lblmsg.Text = "Invalid User";
            }

        }
        public void BindLocation()
        {
            try
            {
                List<DataEntity> lstLocation = new List<DataEntity>();
                DataAccess objda = new DataAccess();
                lstLocation = objda.GetAlllocation();

                if (lstLocation.Count > 0)
                {

                    ddllocation.DataValueField = "LocationId";
                    ddllocation.DataTextField = "LocationName";
                    ddllocation.DataSource = lstLocation;
                    ddllocation.DataBind();
                }
            }

            catch (Exception ex)
            {
                throw ex;
            }

        }
 protected void ImageButton1_Click1(object sender, ImageClickEventArgs e)
 {
     DataAccess objSaveData = new DataAccess();
     RememberOldValues();
     if (AreAllQuestionDone(OldTable))
     {
         if (AreValidateSum(OldTable))
         {
             //SaveUpdateRecords(OldTable);
             if (objSaveData.SaveUpdateRecords("PSI", Session["Candidateid"].ToString(), OldTable))
             {
                 lblmsg.ForeColor = System.Drawing.Color.Green;
                 lblmsg.Text = "Record saved sucessfully";
                 Response.Redirect("../Forms/Thankyou.aspx", false);
             }
             else
             {
                 lblmsg.ForeColor = System.Drawing.Color.Red;
                 lblmsg.Text = "Error while saving data";
             }                            
         }
         else
         {
             lblmsg.ForeColor = System.Drawing.Color.Red;
             //lblmsg.Text = "!!!!! Pair sum should be " + strPSIRange.ToString() + " !!!!!";
             lblmsg.Text = "Please enter valid digit i.e. (0,1,2,3,4,5)";
         }
     }
 }
        protected void BtnLogin_Click(object sender, ImageClickEventArgs e)
        {
            try
            {
                bool IsvalidMobile, IsvalidEmial, IsvalidPAN;
                IsvalidMobile = ValidateMobileControl();
                IsvalidEmial = ValidateEmailControl();
                IsvalidPAN = ValidatePANControl();

                if (IsvalidMobile && IsvalidEmial && IsvalidPAN)
                {


                    Boolean Flag;
                    Flag = false;
                    DataAccess AuthenCandidate = new DataAccess();
                    DataEntity DE = new DataEntity();
                    DE.FirstName = txtfirstname.Text;
                    DE.LastName = txtlastname.Text;
                    DE.MobileNo = txtmobile.Text;
                    DE.EmailId = txtEmail.Text;

                    //Flag = AuthenCandidate.AuthencateCandidate(DE);

                    Flag = true;
                    if (Flag == true)
                    {
                        DE.LocationID = Convert.ToInt32(ddllocation.SelectedValue);
                        DE.PositionID = Convert.ToInt32(ddlposition.SelectedValue);
                        DE.QualificationId = Convert.ToInt32(ddlQualification.SelectedValue);
                        DE.ExperienceId = Convert.ToInt32(ddlExpeience.SelectedValue);
                        DE.Day = ddlday.SelectedItem.Text;
                        DE.Month = ddldobmonth.SelectedItem.Text;
                        DE.Year = txtyear.Text;
                        if (chkdeclaration.Checked == true)
                        {
                            DE.AcceptDec = 1;
                        }
                        else
                        {
                            DE.AcceptDec = 0;
                        }

                        DE.PanNo = txtpanno.Text;
                                               

                        if (vadidateDOB(DE.Day, DE.Month, DE.Year))
                        {
                            if (chkdeclaration.Checked == true)
                            {
                                //Int32 can = AuthenCandidate.InsertCandidateDetails(DE);
                                MHRISesstion.CandidateId = Convert.ToString(AuthenCandidate.InsertCandidateDetails(DE));
                                MHRISesstion.HRCandidateFirstName = txtfirstname.Text;
                                //MHRISesstion.TimeLeftofCAFTest = null;
                                Session["TimeLeftofCAFTest"] = null;
                                Response.Redirect("../Forms/CAF.aspx", false);
                            }
                            else
                            {
                                lblErrorMessage.Visible = true;
                                lblErrorMessage.Text = "Please accept the declaration.";

                            }
                        }

                        else
                        {
                            lblErrorMessage.Visible = true;
                            lblErrorMessage.Text = "DOB Not Proper Format And Year Should be >=1753 !!!!";
                        }
                        
                    }
                    else
                    {
                        lblErrorMessage.Visible = true;
                        lblErrorMessage.Text = "You Are Not Authorised,Please Contact HR !!!!";

                    }
                }
            }

            catch (Exception ex)
            {

                throw ex;
            }
        }
        public void BindExperience()
        {
            try
            {
                List<DataEntity> lstExperience = new List<DataEntity>();
                DataAccess objda = new DataAccess();
                lstExperience = objda.GetAllExperience();

                if (lstExperience.Count > 0)
                {

                    ddlExpeience.DataValueField = "ExperienceId";
                    ddlExpeience.DataTextField = "Experience";
                    ddlExpeience.DataSource = lstExperience;
                    ddlExpeience.DataBind();
                }
            }

            catch (Exception ex)
            {
                throw ex;
            }

        }
        public void SendEmail( Int32 Canid, string pdate)
        {

            DataAccess DEmail = new DataAccess();
            List<DataEntity> lst = new List<DataEntity>();
            List<DataEntity> lstrsi = new List<DataEntity>();

             
            if (MHRISesstion.HREmailid != "")
            {

                Int32 Canditeid = Canid;

                String Pdate = pdate;
                lst = DEmail.GetCandidateDetails(Canditeid, Pdate);
                string body = "<html> Hi </br></br> Please find the report of the pre-employment test below:</br></br></br> Name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:[Name]</br> Email ID&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:[Emailid]</br> Mobile Number&nbsp;&nbsp;&nbsp;&nbsp;:[Mobile]</br> Position&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:[Position]</br> Exam Date&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:[ExamDate]</br>Exam Start Time&nbsp;&nbsp;:[StartTime]</br>Exam End Time&nbsp;&nbsp;&nbsp;:[EndTime] ";
                if (lst.Count > 0)
                {

                    body = body.Replace("[Name]", lst[0].FirstName);
                    Candidatename = lst[0].FirstName;
                    body = body.Replace("[Emailid]", lst[0].EmailId);
                    body = body.Replace("[Mobile]", lst[0].MobileNo);
                    body = body.Replace("[Position]", lst[0].Position);
                    body = body.Replace("[ExamDate]", lst[0].ExamDate);
                    body = body.Replace("[StartTime]", lst[0].StartTime);
                    body = body.Replace("[EndTime]", lst[0].EndTime);
                    
                }

                string CAFscore=DEmail.GetCAFScore(Canditeid, Pdate);

                //body = body + "</br></br></br></br> Section 1: CAF </br> Score obtained is " + CAFscore + " out of " + 15 + "</br></br> Section 2: RSI</br> The score of various career anchor are below : <table > ";
                body = body + "</br></br></br></br> Section 1: CAF </br> Score obtained is " + CAFscore + " out of " + 15;
                body = body + "</br> CAF Examination Duration is " + MHRISesstion.CandidateCAFduration.ToString() + "mins" ;
                body = body + "</br></br> Section 2: RSI</br> The score of various career anchor are below : <table > ";

                lstrsi = DEmail.GetRSIScore(Canditeid, Pdate);


                if (lstrsi.Count > 0)
                {
                    foreach (var obj in lstrsi)
                    {
                        DataEntity D1 = new DataEntity();



                        body = body + "<tr> <td>" + obj.QChar + "</td>" + "<td>" + obj.Quvalue + "</td></tr>";
                    }

                }

                body = body + "</table>";
                body = body + " </br></br> Section 3: PSI </br> The Profile according of PSI is :";//      +</html>";

                string psiscore = DEmail.GetPSIScore(Canditeid, Pdate);
                body = body + psiscore;




                string StrAbbreviations = DEmail.GetPSIAbbreviations(psiscore);

                if (StrAbbreviations != "")
                {
                    string bodypart = " </br> A short description of the same is below :- </br> <table > <tr> <td > </td> <td  >" + StrAbbreviations + "</td <td > </td> </tr> </table></html>";
                    body = body + bodypart;
                }

                else
                {
                    body = body + "</html>";
                }



                if (Candidatename != "")
                {
                    Subject = "Pre-Employment test score for candidate:-" + "  " + Candidatename;
                }
                
                else
                {
                    Subject = "Pre-Employment test score for candidate:-" + "  ";
                }

                

               
              EmailUtil.MHRISendMail(null, MHRISesstion.HREmailid, null, null, Subject, body, null, null, null, null, null);
             //EmailUtil.MHRISendMailTest(null, MHRISesstion.HREmailid, null, null, Subject, body, null, null, null, null, null);
            }
        }