protected void btnSubmit_Click(object sender, EventArgs e)
    {
        try
        {
            string applicationID = Request.QueryString["ApplicationID"].ToString();

            //      ScriptManager.RegisterStartupScript(this.Page, GetType(), "ClosePopup", "alertNew('Application Submitted Successfully !','0');", true);

            DatabaseFunctions db = new DatabaseFunctions();
            db.updateApplicationStatus_Submit(Convert.ToInt32(applicationID));

            DataSet appData = db.getApplication_ID((applicationID));
            if (appData != null)
            {
                int programID = Convert.ToInt32(appData.Tables[0].Rows[0]["ProgramID"].ToString());
                DataSet pDate = db.getProgramByID(programID);
                if (pDate.Tables[0].Rows.Count > 0)
                {
                    int instantadmission = Convert.ToInt16(pDate.Tables[0].Rows[0]["InstantAdmission"].ToString());
                    if (instantadmission == 1)
                    {
                        string programName = appData.Tables[0].Rows[0]["programName"].ToString();
                        string CourseName = appData.Tables[0].Rows[0]["Course1"].ToString();
                        string campus = appData.Tables[0].Rows[0]["Campus"].ToString();
                        string regno = appData.Tables[0].Rows[0]["formnumber"].ToString();

                        db.insertInstantAdmissiondata(regno, programName, CourseName, campus);
                        //db.AssignAcceptanceFee()
                        ScriptManager.RegisterStartupScript(this.Page, GetType(), "ClosePopup2", "alertNew('You have been successfully awarded admission !','0');", true);
                        DatabaseFunctions d = new DatabaseFunctions();
                        d.AssignAcceptanceFee(StudentID, programID, 0);
                        ///// Generate acceptance fee and send a message. 
                        d.InsertIntoStudentInfoTableNew(programID, "ND1", StudentID, 0, 1, "0", DateTime.Now.Year.ToString());
                        int BatchID = d.GetBatchID(DateTime.Now.Year.ToString());
                        string matricno=DateTime.Now.Year+"-"+programName+"-"+StudentID;
                        d.InsertIntoAddmissionTableNew(programID, StudentID, 0, "Merit", matricno, BatchID);
                        double AcceptanceFee = d.GetAcceptanceFeeForProgram(programID);
                        ///// Update Admission Status to 1 . 
                        ///// Insert Values to StudentInfo_tbl and AddmissionList (New One) 

                        if(AcceptanceFee!=-1)
                        {
                            string Message = "Acceptence Fee Of " +AcceptanceFee+ " Has Been Assigned to You <br> Please Submit This Fees with in One Week";
                            d.SendMessage(StudentID, Message, "Acceptance Fee", 0);
                        }

                    }
                    else
                    {
                        ScriptManager.RegisterStartupScript(this.Page, GetType(), "ClosePopup", "alertNew('Application Submitted Successfully !','0');", true);
                    }
                }
            }
        }
        catch (Exception ex)
        {
            ScriptManager.RegisterStartupScript(this.Page, GetType(), "ClosePopup", "alertNew('Error Submiting Application!','1');", true);
        }
    }
    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(); ;

        }
    }