protected void Page_Load(object sender, EventArgs e)
    {
        string pageName = Path.GetFileNameWithoutExtension(Page.AppRelativeVirtualPath);
        
        if (System.Web.HttpContext.Current.User != null)
        {
            loggedStatus = System.Web.HttpContext.Current.User.Identity.IsAuthenticated;
            if (loggedStatus)
            {
                DatabaseFunctions d = new DatabaseFunctions();
                string UserID = Membership.GetUser().ProviderUserKey.ToString();
                StudentID = d.GetCandidateID(UserID);
                Page.Form.Attributes.Add("enctype", "multipart/form-data");
                if (!IsPostBack)
                {
                    DatabaseFunctions db = new DatabaseFunctions();

                    DataSet appStatus = db.getApplication_ID(Request.QueryString["ApplicationID"].ToString());
                    if (appStatus.Tables[0].Rows.Count > 0)
                    {
                        if (appStatus.Tables[0].Rows[0]["formfilled"].ToString() != "Yes")
                        {

                            int programID = 0;

                            DataSet ds = db.getProgramIDbyApplicationID(Convert.ToInt32(Request.QueryString["ApplicationID"].ToString()));
                            if (ds.Tables[0].Rows.Count > 0)
                            {
                                programID = Convert.ToInt16(ds.Tables[0].Rows[0]["programID"].ToString());
                                ViewState["programID"] = programID;

                                ViewState["formnum"] = (ds.Tables[0].Rows[0]["FormNumber"].ToString());
                                loadbirthDay_Dropdowns();

                                int JambForm = Convert.ToInt16(ds.Tables[0].Rows[0]["HasJambData"].ToString());  //1
                                int BioForm = Convert.ToInt16(ds.Tables[0].Rows[0]["HasBioDataSection"].ToString());//2
                                int OlevelForm = Convert.ToInt16(ds.Tables[0].Rows[0]["HasOlevelResult"].ToString());//3
                                int PreviousRecordForm = Convert.ToInt16(ds.Tables[0].Rows[0]["HasPreviousRecord"].ToString());//4
                                int CbtScheduleForm = Convert.ToInt16(ds.Tables[0].Rows[0]["HasCBTSchedule"].ToString());//5


                                int progressBarAlgo = 0;
                                if (JambForm == 1)
                                {
                                    progressBarAlgo = progressBarAlgo + 1;
                                }
                                if (BioForm == 1)
                                {
                                    progressBarAlgo = progressBarAlgo + 1;
                                }
                                if (OlevelForm == 1)
                                {
                                    progressBarAlgo = progressBarAlgo + 1;
                                }
                                if (PreviousRecordForm == 1)
                                {
                                    progressBarAlgo = progressBarAlgo + 1;
                                }
                                if (CbtScheduleForm == 1)
                                {
                                    progressBarAlgo = progressBarAlgo + 1;
                                }

                                int startingPercentage = 0;
                                if (progressBarAlgo > 0)
                                {
                                    startingPercentage = 100 / progressBarAlgo;
                                }
                                else { startingPercentage = 100; }

                                progressBar.InnerHtml = "<div aria-valuemax=\"100\" aria-valuemin=\"0\"  role=\"progressbar\" class=\"progress-bar progress-bar-striped active\" style=\"width: " + startingPercentage + "%;height:30px;font-size:30px;padding-top:5px\">" + startingPercentage + "%</div>";
                                ViewState["stepsIncrement"] = startingPercentage;
                                ViewState["progressValue"] = startingPercentage;


                                var dt = ds.Tables[0];



                                ViewState["panelInfo"] = dt;
                                ViewState["NextPanel"] = "";
                                ViewState["PreviousPanel"] = "";
                                ViewState["CurrentPanel"] = "";
                                ViewState["previousPanelName"] = "";
                                ViewState["FirstPanel"] = "";
                                ViewState["CurrentPanelName"] = "";

                                string validationGroup = string.Empty;
                                for (int c = 2; c < ds.Tables[0].Columns.Count; c++)
                                {
                                    if (ds.Tables[0].Rows[0][c].ToString() == "1")
                                    {
                                        string colName = ds.Tables[0].Columns[c].ColumnName.ToString();
                                        Panel paneltx = this.Master.FindControl("ContentPlaceHolder1").FindControl(colName) as Panel;
                                        if (paneltx != null)
                                        {
                                            if (ViewState["CurrentPanel"] == "")
                                            {
                                                if (colName == "HasJambData")
                                                {
                                                    validationGroup = "appForm";
                                                }
                                                else if (colName == "HasBioDataSection")
                                                {
                                                    validationGroup = "appForm_biodata";
                                                }
                                                else if (colName == "HasOlevelResult")
                                                {
                                                    validationGroup = "appForm_Olevel";
                                                }
                                                else if (colName == "HasPreviousRecord")
                                                {
                                                    validationGroup = "appPreviousRecord";
                                                }
                                                else if (colName == "HasCBTSchedule")
                                                {
                                                    validationGroup = "appCBT";
                                                }



                                                ViewState["previousPanelName"] = colName;
                                                ViewState["FirstPanel"] = colName;
                                                ViewState["CurrentPanelName"] = colName;
                                                paneltx.Visible = true;
                                                ViewState["CurrentPanel"] = c;

                                                loadTabsInfo(colName);

                                                btnSave.ValidationGroup = validationGroup;
                                                btnSave.Visible = true;
                                            }
                                            else
                                            {
                                                ViewState["NextPanel"] = c;
                                                btnNext.ValidationGroup = validationGroup;
                                                btnNext.Visible = true;
                                                break;
                                            }
                                        }


                                    }
                                }


                                lblCbtUsername.Text = ViewState["formnum"].ToString();





                                if (ViewState["NextPanel"] != "")
                                {
                                    btnNext.Visible = true;
                                    btnNext.ValidationGroup = validationGroup;
                                    btnPreview.Visible = false;
                                }
                                else
                                {
                                    btnSave.Visible = false;
                                    btnNext.Visible = false;
                                    btnPreview.ValidationGroup = validationGroup;
                                    btnPreview.Visible = true;
                                }
                            }



                            string imgD = hidden_dpImage.Value;
                            if (imgD != "")
                            {
                                imgDisplay.Src = "profilepics/" + imgD.ToString();
                                imgDisplay.Style.Add("display", "inline");
                            }
                        }
                        else
                        {
                            Response.Redirect("Profilepage.aspx");
                        }
                    }

                }

            }
            else
            {
                Response.Redirect("Login.aspx?ReturnUrl=" + pageName + ".aspx");
            }
        }
    }
    public void formPreview()
    {
        btnSave.Visible = false;
        btnNext.Visible = false;
        btnPrevious.Visible = false;
        btnPreview.Visible = false;

        DataSet ds = new DataSet();
        DatabaseFunctions db = new DatabaseFunctions();

        ds = db.getProgramIDbyApplicationID(Convert.ToInt32(Request.QueryString["ApplicationID"].ToString()));
        if (ds.Tables[0].Rows.Count > 0)
        {
            int JambForm = Convert.ToInt16(ds.Tables[0].Rows[0]["HasJambData"].ToString());  //1
            int BioForm = Convert.ToInt16(ds.Tables[0].Rows[0]["HasBioDataSection"].ToString());//2
            int OlevelForm = Convert.ToInt16(ds.Tables[0].Rows[0]["HasOlevelResult"].ToString());//3
            int PreviousRecordForm = Convert.ToInt16(ds.Tables[0].Rows[0]["HasPreviousRecord"].ToString());//4
            int CbtScheduleForm = Convert.ToInt16(ds.Tables[0].Rows[0]["HasCBTSchedule"].ToString());//5

            if (OlevelForm == 0)
            {
                HasOlevelResult.Visible = false;
            }
            if (PreviousRecordForm == 0)
            {
                panelpreview_PreviousRecord.Visible = false;
            }
            if (CbtScheduleForm == 0)
            {
                HasCBTSchedule.Visible = false;
            }

        }

        string previousColName = ViewState["CurrentPanelName"].ToString();
        Panel panelprev = this.Master.FindControl("ContentPlaceHolder1").FindControl(previousColName) as Panel;
        if (panelprev != null)
        {
            panelprev.Visible = false;
        }

        panelPreview.Visible = true;


        ds = new DataSet();


        ds = db.getAlluserRelatedInfo((Membership.GetUser().ProviderUserKey.ToString()));
        if (ds.Tables[0].Rows.Count > 0)
        {
            string programName = string.Empty;
            string img = ds.Tables[0].Rows[0]["profilepic"].ToString();
            string course = string.Empty;

            if (img != "")
            {
                imgDp.Src = "profilepics/" + img.ToString(); ;
                imgDp.Visible = true;

            }
            else
            {
                imgDp.Visible = false;
            }


            DataSet pgName = db.getProgramByID(Convert.ToInt32(ViewState["programID"]));
            if (pgName.Tables[0].Rows.Count > 0)
            {
                programName = pgName.Tables[0].Rows[0]["ProgramName"].ToString();
            }



            lblSuname.Text = ds.Tables[0].Rows[0]["surname"].ToString();
            lblFname.Text = ds.Tables[0].Rows[0]["firstname"].ToString();
            lblOtherName.Text = ds.Tables[0].Rows[0]["othername"].ToString();

            lblGender.Text = ds.Tables[0].Rows[0]["gender"].ToString();
            lblPhonenum.Text = ds.Tables[0].Rows[0]["phonenumber"].ToString();

            lblProgram.Text = programName;
            lblCourse.Text = db.getApplication_Courses(Convert.ToInt32(ViewState["programID"]), Convert.ToInt32(Request.QueryString["ApplicationID"]));
            lblstateoforigin.Text = ds.Tables[0].Rows[0]["statenew"].ToString();
            lblLocalGotArea.Text = ds.Tables[0].Rows[0]["govtnew"].ToString();

            lblJambRegno.Text = ds.Tables[0].Rows[0]["JAMBRegno"].ToString();
            lblJambExamyear.Text = ds.Tables[0].Rows[0]["JambExamyear"].ToString();
            lblJambFullName.Text = ds.Tables[0].Rows[0]["JambFullName"].ToString();
            lblInstitutionAttended.Text = ds.Tables[0].Rows[0]["institutionNew"].ToString();
            lblCourseName.Text = ds.Tables[0].Rows[0]["CourseName"].ToString();
            courseType.Text = ds.Tables[0].Rows[0]["CourseType"].ToString();
            lblCourseGrade.Text = ds.Tables[0].Rows[0]["CourseGrade"].ToString();
            yearCompleted.Text = ds.Tables[0].Rows[0]["YearCompleted"].ToString();

            lblIndustrialStart.Text = ds.Tables[0].Rows[0]["IndTrainingStart"].ToString();
            lblIndustrialEnd.Text = ds.Tables[0].Rows[0]["IndTrainingEnd"].ToString();

            lblCbtSchedule.Text = ds.Tables[0].Rows[0]["ScheduleDate"].ToString() + ", " + ds.Tables[0].Rows[0]["ScheduleTime"].ToString();
            labelCbtUser.Text = ds.Tables[0].Rows[0]["CbtUserName"].ToString();
            lblCbtPass.Text = ds.Tables[0].Rows[0]["CbtPassword"].ToString();

            lblRegistrationNum.Text = ViewState["formnum"].ToString(); ;

        }
    }