protected void btnView_Click(object sender, EventArgs e)
    {
        string date1 = string.Empty;

        date1 = txtFromDate.Text.ToString();
        DateTime dt1         = new DateTime();// Convert.ToDateTime(datefrom.ToString());
        bool     isValidDate = DateTime.TryParseExact(date1, "dd/MM/yyyy", null, DateTimeStyles.None, out dt1);

        FpSpread1.Visible = false;
        string SelectQ = "select distinct (c.Course_Name+'-'+de.Dept_Name) as courceName,r.Batch_Year,r.degree_code,COUNT(r.app_no) as totalStudent from Registration r,Degree d,course c,Department de,doubledayorder do where r.degree_code=d.Degree_Code and de.Dept_Code=d.Dept_Code and c.Course_Id=d.Course_Id and d.Degree_Code=do.degreeCode and r.Batch_Year=do.batchYear and do.doubledate='" + dt1.ToString("MM/dd/yyyy") + "' and r.college_code=c.college_code and d.college_code=de.college_code and d.college_code=c.college_code and r.college_code='" + Convert.ToString(ddlCollege.SelectedValue) + "' and CC=0 and DelFlag =0 and Exam_Flag <>'DEBAR' and delflag=0 group by (c.Course_Name+'-'+de.Dept_Name),r.Batch_Year,r.degree_code order by (c.Course_Name+'-'+de.Dept_Name),r.Batch_Year,r.degree_code,totalStudent";

        DataTable dtsaveDate = dirAcc.selectDataTable(SelectQ);

        if (dtsaveDate.Rows.Count > 0)
        {
            int sno = 0;
            FpSpread1.Visible = true;
            //lblexportxl.Visible = false;
            FpSpread1.Sheets[0].RowCount                = 0;
            FpSpread1.Sheets[0].ColumnCount             = 0;
            FpSpread1.Sheets[0].SheetCorner.ColumnCount = 0;
            FpSpread1.Sheets[0].ColumnHeader.RowCount   = 1;
            FpSpread1.Sheets[0].ColumnCount             = 5;
            FpSpread1.Sheets[0].Columns[0].Width        = 70;
            FpSpread1.Sheets[0].Columns[1].Width        = 100;
            FpSpread1.Sheets[0].Columns[2].Width        = 250;
            FpSpread1.Sheets[0].Columns[3].Width        = 100;
            //FpSpread1.Sheets[0].Columns[4].Width = 100;
            FpSpread1.Sheets[0].ColumnHeader.Cells[0, 0].Text            = "S.No";
            FpSpread1.Sheets[0].ColumnHeader.Cells[0, 0].HorizontalAlign = HorizontalAlign.Center;
            FpSpread1.Sheets[0].ColumnHeader.Cells[0, 1].HorizontalAlign = HorizontalAlign.Center;
            FpSpread1.Sheets[0].ColumnHeader.Cells[0, 1].Text            = "Batch Year";
            FpSpread1.Sheets[0].ColumnHeader.Cells[0, 2].HorizontalAlign = HorizontalAlign.Center;
            FpSpread1.Sheets[0].ColumnHeader.Cells[0, 2].Text            = "Department Name";
            FpSpread1.Sheets[0].ColumnHeader.Cells[0, 3].Text            = "Student Count";
            FpSpread1.Sheets[0].ColumnHeader.Cells[0, 3].HorizontalAlign = HorizontalAlign.Center;
            FarPoint.Web.Spread.StyleInfo darkstyle = new FarPoint.Web.Spread.StyleInfo();
            darkstyle.BackColor = ColorTranslator.FromHtml("#0CA6CA");
            darkstyle.ForeColor = System.Drawing.Color.White;
            FpSpread1.ActiveSheetView.ColumnHeader.DefaultStyle = darkstyle;
            FpSpread1.CommandBar.Visible = false;
            FpSpread1.Sheets[0].ColumnHeader.Cells[0, 4].Text            = "Select";
            FpSpread1.Sheets[0].ColumnHeader.Cells[0, 4].HorizontalAlign = HorizontalAlign.Center;
            FarPoint.Web.Spread.CheckBoxCellType chkcell = new FarPoint.Web.Spread.CheckBoxCellType();
            FpSpread1.Sheets[0].RowCount = 0;
            FarPoint.Web.Spread.CheckBoxCellType chkcell1 = new FarPoint.Web.Spread.CheckBoxCellType();
            FpSpread1.Sheets[0].RowCount = FpSpread1.Sheets[0].RowCount + 1;
            FpSpread1.Sheets[0].Cells[FpSpread1.Sheets[0].RowCount - 1, 4].CellType        = chkcell1;
            FpSpread1.Sheets[0].Cells[FpSpread1.Sheets[0].RowCount - 1, 4].HorizontalAlign = HorizontalAlign.Center;
            FpSpread1.Sheets[0].SpanModel.Add(FpSpread1.Sheets[0].RowCount - 1, 0, 1, 4);
            chkcell1.AutoPostBack = true;
            FpSpread1.Sheets[0].FrozenRowCount = 1;
            FpSpread1.Sheets[0].AutoPostBack   = false;

            foreach (DataRow dr in dtsaveDate.Rows)
            {
                string BatchYear  = Convert.ToString(dr["batch_year"]).Trim();
                string DegreeCode = Convert.ToString(dr["degree_code"]).Trim();
                string CourceName = Convert.ToString(dr["courceName"]).Trim();
                string torstudent = Convert.ToString(dr["totalStudent"]).Trim();
                sno++;
                FpSpread1.Sheets[0].RowCount = FpSpread1.Sheets[0].RowCount + 1;
                FpSpread1.Sheets[0].Cells[FpSpread1.Sheets[0].RowCount - 1, 0].HorizontalAlign = HorizontalAlign.Center;
                FpSpread1.Sheets[0].Cells[FpSpread1.Sheets[0].RowCount - 1, 1].HorizontalAlign = HorizontalAlign.Center;
                FpSpread1.Sheets[0].Cells[FpSpread1.Sheets[0].RowCount - 1, 2].HorizontalAlign = HorizontalAlign.Center;
                FpSpread1.Sheets[0].Cells[FpSpread1.Sheets[0].RowCount - 1, 3].HorizontalAlign = HorizontalAlign.Center;
                FpSpread1.Sheets[0].Cells[FpSpread1.Sheets[0].RowCount - 1, 0].Text            = sno.ToString();
                FpSpread1.Sheets[0].Cells[FpSpread1.Sheets[0].RowCount - 1, 1].Text            = BatchYear;
                FpSpread1.Sheets[0].Cells[FpSpread1.Sheets[0].RowCount - 1, 2].Text            = CourceName;
                FpSpread1.Sheets[0].Cells[FpSpread1.Sheets[0].RowCount - 1, 2].Note            = DegreeCode;
                FpSpread1.Sheets[0].Cells[FpSpread1.Sheets[0].RowCount - 1, 3].Text            = torstudent;
                FpSpread1.Sheets[0].Cells[FpSpread1.Sheets[0].RowCount - 1, 4].CellType        = chkcell;
                FpSpread1.Sheets[0].Cells[FpSpread1.Sheets[0].RowCount - 1, 4].HorizontalAlign = HorizontalAlign.Center;
            }
            FpSpread1.Visible            = true;
            FpSpread1.Sheets[0].PageSize = FpSpread1.Sheets[0].RowCount;
            FpSpread1.SaveChanges();
            FpSpread1.Width   = 540;
            FpSpread1.Height  = 400;
            Btndelete.Visible = true;
            Div1.Visible      = true;
        }
        else
        {
            Div1.Visible      = false;
            Btndelete.Visible = false;
        }
        btnSave.Visible = false;
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["collegecode"] == null) //Aruna For Back Button
        {
            Response.Redirect("~/Default.aspx");
        }

        if (!IsPostBack)
        {
            if (flag == 0)
            {
                flag        = 1;
                CollegeCode = Session["CollegeCode"].ToString();

                Session["Stud_Type1"] = "0";
                Session["Stud_Type"]  = "0";
                Master1 = "select * from Master_Settings where usercode=" + Session["usercode"] + "";
                setcon.Close();
                setcon.Open();
                SqlDataReader mtrdr;
                Session["Rollflag"] = "0";
                Session["Regflag"]  = "0";
                Session["Studflag"] = "0";
                SqlCommand mtcmd = new SqlCommand(Master1, setcon);
                mtrdr = mtcmd.ExecuteReader();
                {
                    if (mtrdr.HasRows)
                    {
                        while (mtrdr.Read())
                        {
                            if (mtrdr["settings"].ToString() == "Roll No" && mtrdr["value"].ToString() == "1")
                            {
                                Session["Rollflag"] = "1";
                            }
                            if (mtrdr["settings"].ToString() == "Register No" && mtrdr["value"].ToString() == "1")
                            {
                                Session["Regflag"] = "1";
                            }
                            if (mtrdr["settings"].ToString() == "Student_Type" && mtrdr["value"].ToString() == "1")
                            {
                                Session["Studflag"] = "1";
                            }
                            if (mtrdr["settings"].ToString() == "Day Scholar" && mtrdr["value"].ToString() == "1")
                            {
                                Session["Stud_Type"] = "Day Scholar";
                            }
                            if (mtrdr["settings"].ToString() == "Hostel" && mtrdr["value"].ToString() == "1")
                            {
                                Session["Stud_Type1"] = "Hostler";
                            }
                        }
                    }
                }
                //individualsubstud.Sheets[0].AutoPostBack = true;
                HAllSpread.Sheets[0].RowHeader.Visible = false;
                HAllSpread.Sheets[0].ColumnCount       = 10;
                HAllSpread.Sheets[0].Columns[0].Locked = true;
                HAllSpread.Sheets[0].Columns[1].Locked = true;
                HAllSpread.Sheets[0].Columns[2].Locked = true;
                HAllSpread.Sheets[0].Columns[3].Locked = true;
                HAllSpread.Sheets[0].Columns[4].Locked = true;
                HAllSpread.Sheets[0].Columns[5].Locked = true;
                HAllSpread.Sheets[0].Columns[6].Locked = true;
                HAllSpread.Sheets[0].Columns[7].Locked = true;
                HAllSpread.Sheets[0].Columns[8].Locked = true;

                HAllSpread.Sheets[0].DefaultStyle.Font.Size = FontUnit.Medium;
                HAllSpread.Sheets[0].ColumnHeader.DefaultStyle.Font.Size = FontUnit.Medium;
                HAllSpread.Sheets[0].ColumnHeader.DefaultStyle.Font.Name = "Book Antiqua";
                HAllSpread.Sheets[0].ColumnHeader.DefaultStyle.Font.Bold = true;
                HAllSpread.Sheets[0].RowCount         = 0;
                HAllSpread.Sheets[0].Columns[0].Width = 40;
                HAllSpread.Sheets[0].Columns[1].Width = 40;
                FarPoint.Web.Spread.CheckBoxCellType chkcell = new FarPoint.Web.Spread.CheckBoxCellType();
                HAllSpread.Sheets[0].Columns[9].CellType        = chkcell;
                HAllSpread.Sheets[0].Columns[9].HorizontalAlign = HorizontalAlign.Center;
                HAllSpread.Sheets[0].RowCount = HAllSpread.Sheets[0].RowCount + 1;
                HAllSpread.Sheets[0].SpanModel.Add(HAllSpread.Sheets[0].RowCount - 1, 0, 1, 6);
                HAllSpread.Sheets[0].Cells[HAllSpread.Sheets[0].RowCount - 1, 9].CellType        = chkcell;
                HAllSpread.Sheets[0].Cells[HAllSpread.Sheets[0].RowCount - 1, 9].HorizontalAlign = HorizontalAlign.Center;
                HAllSpread.Sheets[0].FrozenRowCount = 1;
                chkcell.AutoPostBack = true;
                HAllSpread.Sheets[0].SheetCorner.RowCount = 2;
                HAllSpread.Sheets[0].ColumnHeaderSpanModel.Add(0, 0, 2, 1);
                HAllSpread.Sheets[0].ColumnHeaderSpanModel.Add(0, 1, 2, 1);
                HAllSpread.Sheets[0].ColumnHeaderSpanModel.Add(0, 2, 2, 1);
                HAllSpread.Sheets[0].ColumnHeaderSpanModel.Add(0, 3, 2, 1);
                HAllSpread.Sheets[0].ColumnHeaderSpanModel.Add(0, 4, 2, 1);
                HAllSpread.Sheets[0].ColumnHeaderSpanModel.Add(0, 5, 2, 1);
                HAllSpread.Sheets[0].ColumnHeaderSpanModel.Add(0, 9, 2, 1);
                HAllSpread.Sheets[0].ColumnHeaderSpanModel.Add(0, 6, 1, 3);
                HAllSpread.Sheets[0].ColumnHeader.Cells[0, 0].Text = "S.No";
                HAllSpread.Sheets[0].ColumnHeader.Cells[0, 1].Text = "Year";
                HAllSpread.Sheets[0].ColumnHeader.Cells[0, 2].Text = "Degree";
                HAllSpread.Sheets[0].ColumnHeader.Cells[0, 3].Text = "Course";
                HAllSpread.Sheets[0].ColumnHeader.Cells[0, 4].Text = "Sem";
                HAllSpread.Sheets[0].ColumnHeader.Cells[0, 5].Text = "Subjects";
                HAllSpread.Sheets[0].ColumnHeader.Cells[0, 6].Text = "Students";
                HAllSpread.Sheets[0].ColumnHeader.Cells[1, 6].Text = "Regular";
                HAllSpread.Sheets[0].ColumnHeader.Cells[1, 7].Text = "Arrear";
                HAllSpread.Sheets[0].ColumnHeader.Cells[1, 8].Text = "Total";
                HAllSpread.Sheets[0].ColumnHeader.Cells[1, 9].Text = "Select";
                HAllSpread.Sheets[0].Columns[0].Width = 60;
                HAllSpread.Sheets[0].Columns[1].Width = 60;
                HAllSpread.Sheets[0].Columns[2].Width = 80;
                HAllSpread.Sheets[0].Columns[3].Width = 150;
                HAllSpread.Sheets[0].Columns[4].Width = 60;
                HAllSpread.Sheets[0].Columns[5].Width = 150;
                HAllSpread.Sheets[0].Columns[6].Width = 100;
                HAllSpread.Sheets[0].Columns[7].Width = 100;
                HAllSpread.Sheets[0].Columns[8].Width = 100;
                HAllSpread.Sheets[0].Columns[9].Width = 60;

                HAllSpread.Sheets[0].Columns[5].Font.Size      = FontUnit.Medium;
                HAllSpread.Sheets[0].Columns[5].Font.Underline = true;
                HAllSpread.Sheets[0].Columns[5].ForeColor      = Color.Blue;
                HAllSpread.Sheets[0].Columns[5].Font.Size      = FontUnit.Medium;
                HAllSpread.Sheets[0].AutoPostBack = false;
                HAllSpread.CommandBar.Visible     = false;

                SqlCommand cmd = new SqlCommand("ProcExamTimeTableSelectSubjectData", con);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@CollegeCode", CollegeCode);
                SqlDataAdapter da     = new SqlDataAdapter(cmd);
                DataSet        examds = new DataSet();
                da.Fill(examds);
                HAllSpread.Sheets[0].RowCount = 2;
                int    count;
                int    countp;
                int    countA;
                int    countAP;
                int    Sno     = 0;
                string Temp    = "";
                string Arear   = "0";
                string Regular = "0";
                if (examds.Tables[0].Rows.Count > 0)
                {
                    for (int i = 0; i < examds.Tables[0].Rows.Count; i++)
                    {
                        SqlCommand cd = new SqlCommand("ProcExamTimeTableCount", con);
                        cd.CommandType = CommandType.StoredProcedure;
                        cd.Parameters.AddWithValue("@DegreeCode", examds.Tables[0].Rows[i]["DegreeCode"].ToString());
                        cd.Parameters.AddWithValue("@BatchYear", examds.Tables[0].Rows[i]["BatchYear"].ToString());
                        cd.Parameters.AddWithValue("@Semester", examds.Tables[0].Rows[i]["Semester"].ToString());
                        cd.Parameters.AddWithValue("@CollegeCode", CollegeCode);
                        SqlDataAdapter da1 = new SqlDataAdapter(cd);
                        DataSet        ds1 = new DataSet();
                        da1.Fill(ds1);
                        if (ds1.Tables[0].Rows.Count > 0)
                        {
                            for (int j = 0; j < ds1.Tables[0].Rows.Count; j++)
                            {
                                if (Temp != examds.Tables[0].Rows[i]["Department"].ToString())
                                {
                                    Sno = Sno + 1;
                                }
                                count = HAllSpread.Sheets[0].RowCount - 1;
                                HAllSpread.Sheets[0].Cells[count, 0].HorizontalAlign = HorizontalAlign.Center;
                                HAllSpread.Sheets[0].Cells[count, 4].HorizontalAlign = HorizontalAlign.Center;
                                HAllSpread.Sheets[0].Cells[count, 6].HorizontalAlign = HorizontalAlign.Center;
                                HAllSpread.Sheets[0].Cells[count, 7].HorizontalAlign = HorizontalAlign.Center;
                                HAllSpread.Sheets[0].Cells[count, 8].HorizontalAlign = HorizontalAlign.Center;
                                HAllSpread.Sheets[0].Cells[count, 0].Text            = Sno.ToString();
                                HAllSpread.Sheets[0].Cells[count, 1].Text            = examds.Tables[0].Rows[i]["Year"].ToString();
                                HAllSpread.Sheets[0].Cells[count, 1].Note            = examds.Tables[0].Rows[i]["BatchYear"].ToString();
                                HAllSpread.Sheets[0].Cells[count, 2].Text            = examds.Tables[0].Rows[i]["Course"].ToString();
                                HAllSpread.Sheets[0].Cells[count, 3].Text            = examds.Tables[0].Rows[i]["Department"].ToString();
                                HAllSpread.Sheets[0].Cells[count, 3].Note            = examds.Tables[0].Rows[i]["deptacronym"].ToString();
                                HAllSpread.Sheets[0].Cells[count, 4].Text            = examds.Tables[0].Rows[i]["Semester"].ToString();
                                HAllSpread.Sheets[0].Cells[count, 5].Text            = ds1.Tables[0].Rows[j]["SubjectName"].ToString();
                                HAllSpread.Sheets[0].Cells[count, 5].Note            = ds1.Tables[0].Rows[j]["SubjectNo"].ToString();
                                HAllSpread.Sheets[0].Cells[count, 5].Tag             = 0;
                                HAllSpread.Sheets[0].Rows[count].ForeColor           = Color.Blue;
                                HAllSpread.Sheets[0].Cells[count, 6].Text            = ds1.Tables[0].Rows[j]["RegularTheoryCount"].ToString();
                                HAllSpread.Sheets[0].Cells[count, 7].Text            = Arear.ToString();
                                HAllSpread.Sheets[0].Cells[count, 8].Text            = Convert.ToString(Convert.ToInt16(ds1.Tables[0].Rows[j]["RegularTheoryCount"].ToString()) + Convert.ToInt16(Arear.ToString()));
                                HAllSpread.Sheets[0].RowCount++;

                                Temp = examds.Tables[0].Rows[i]["Department"].ToString();
                            }
                        }

                        if (ds1.Tables[1].Rows.Count > 0)
                        {
                            for (int jp = 0; jp < ds1.Tables[1].Rows.Count; jp++)
                            {
                                if (Temp != examds.Tables[0].Rows[i]["Department"].ToString())
                                {
                                    Sno = Sno + 1;
                                }
                                countp = HAllSpread.Sheets[0].RowCount - 1;
                                HAllSpread.Sheets[0].Cells[countp, 0].HorizontalAlign = HorizontalAlign.Center;
                                HAllSpread.Sheets[0].Cells[countp, 4].HorizontalAlign = HorizontalAlign.Center;
                                HAllSpread.Sheets[0].Cells[countp, 6].HorizontalAlign = HorizontalAlign.Center;
                                HAllSpread.Sheets[0].Cells[countp, 7].HorizontalAlign = HorizontalAlign.Center;
                                HAllSpread.Sheets[0].Cells[countp, 8].HorizontalAlign = HorizontalAlign.Center;
                                HAllSpread.Sheets[0].Cells[countp, 0].Text            = Sno.ToString();
                                HAllSpread.Sheets[0].Cells[countp, 1].Text            = examds.Tables[0].Rows[i]["Year"].ToString();
                                HAllSpread.Sheets[0].Cells[countp, 1].Note            = examds.Tables[0].Rows[i]["BatchYear"].ToString();
                                HAllSpread.Sheets[0].Cells[countp, 2].Text            = examds.Tables[0].Rows[i]["Course"].ToString();
                                HAllSpread.Sheets[0].Cells[countp, 3].Text            = examds.Tables[0].Rows[i]["Department"].ToString();
                                HAllSpread.Sheets[0].Cells[countp, 3].Note            = examds.Tables[0].Rows[i]["deptacronym"].ToString();
                                HAllSpread.Sheets[0].Cells[countp, 4].Text            = examds.Tables[0].Rows[i]["Semester"].ToString();
                                HAllSpread.Sheets[0].Cells[countp, 5].Text            = ds1.Tables[1].Rows[jp]["SubjectName"].ToString();
                                HAllSpread.Sheets[0].Cells[countp, 5].Note            = ds1.Tables[1].Rows[jp]["SubjectNo"].ToString();
                                HAllSpread.Sheets[0].Cells[countp, 5].Tag             = 0;
                                HAllSpread.Sheets[0].Rows[countp].ForeColor           = Color.BlueViolet;
                                HAllSpread.Sheets[0].Cells[countp, 6].Text            = ds1.Tables[1].Rows[jp]["RegularPracticalCount"].ToString();
                                HAllSpread.Sheets[0].Cells[countp, 7].Text            = Arear.ToString();
                                HAllSpread.Sheets[0].Cells[countp, 8].Text            = Convert.ToString(Convert.ToInt16(ds1.Tables[1].Rows[jp]["RegularPracticalCount"].ToString()) + Convert.ToInt16(Arear.ToString()));
                                HAllSpread.Sheets[0].RowCount++;

                                Temp = examds.Tables[0].Rows[i]["Department"].ToString();
                            }
                        }


                        if (ds1.Tables[2].Rows.Count > 0)
                        {
                            for (int k = 0; k < ds1.Tables[2].Rows.Count; k++)
                            {
                                if (Temp != examds.Tables[0].Rows[i]["Department"].ToString())
                                {
                                    Sno = Sno + 1;
                                }
                                countA = HAllSpread.Sheets[0].RowCount - 1;
                                HAllSpread.Sheets[0].Cells[countA, 0].HorizontalAlign = HorizontalAlign.Center;
                                HAllSpread.Sheets[0].Cells[countA, 4].HorizontalAlign = HorizontalAlign.Center;
                                HAllSpread.Sheets[0].Cells[countA, 6].HorizontalAlign = HorizontalAlign.Center;
                                HAllSpread.Sheets[0].Cells[countA, 7].HorizontalAlign = HorizontalAlign.Center;
                                HAllSpread.Sheets[0].Cells[countA, 8].HorizontalAlign = HorizontalAlign.Center;
                                HAllSpread.Sheets[0].Cells[countA, 0].Text            = Sno.ToString();

                                HAllSpread.Sheets[0].Cells[countA, 1].Text  = examds.Tables[0].Rows[i]["Year"].ToString();
                                HAllSpread.Sheets[0].Cells[countA, 1].Note  = examds.Tables[0].Rows[i]["BatchYear"].ToString();
                                HAllSpread.Sheets[0].Cells[countA, 2].Text  = examds.Tables[0].Rows[i]["Course"].ToString();
                                HAllSpread.Sheets[0].Cells[countA, 3].Text  = examds.Tables[0].Rows[i]["Department"].ToString();
                                HAllSpread.Sheets[0].Cells[countA, 3].Note  = examds.Tables[0].Rows[i]["deptacronym"].ToString();
                                HAllSpread.Sheets[0].Cells[countA, 4].Text  = ds1.Tables[2].Rows[k]["semester"].ToString();
                                HAllSpread.Sheets[0].Cells[countA, 5].Text  = ds1.Tables[2].Rows[k]["SubjectName"].ToString();
                                HAllSpread.Sheets[0].Cells[countA, 5].Note  = ds1.Tables[2].Rows[k]["SubjectNo"].ToString();
                                HAllSpread.Sheets[0].Cells[countA, 5].Tag   = 1;
                                HAllSpread.Sheets[0].Rows[countA].ForeColor = Color.Orange;
                                HAllSpread.Sheets[0].Cells[countA, 6].Text  = Regular.ToString();
                                HAllSpread.Sheets[0].Cells[countA, 7].Text  = ds1.Tables[2].Rows[k]["ArearTheoryCount"].ToString();
                                HAllSpread.Sheets[0].Cells[countA, 8].Text  = Convert.ToString(Convert.ToInt16(ds1.Tables[2].Rows[k]["ArearTheoryCount"].ToString()) + Convert.ToInt16(Regular.ToString()));
                                HAllSpread.Sheets[0].RowCount++;

                                Temp = examds.Tables[0].Rows[i]["Department"].ToString();
                            }
                        }
                        if (ds1.Tables[3].Rows.Count > 0)
                        {
                            for (int kp = 0; kp < ds1.Tables[3].Rows.Count; kp++)
                            {
                                if (Temp != examds.Tables[0].Rows[i]["Department"].ToString())
                                {
                                    Sno = Sno + 1;
                                }
                                countAP = HAllSpread.Sheets[0].RowCount - 1;
                                HAllSpread.Sheets[0].Cells[countAP, 0].HorizontalAlign = HorizontalAlign.Center;
                                HAllSpread.Sheets[0].Cells[countAP, 4].HorizontalAlign = HorizontalAlign.Center;
                                HAllSpread.Sheets[0].Cells[countAP, 6].HorizontalAlign = HorizontalAlign.Center;
                                HAllSpread.Sheets[0].Cells[countAP, 7].HorizontalAlign = HorizontalAlign.Center;
                                HAllSpread.Sheets[0].Cells[countAP, 8].HorizontalAlign = HorizontalAlign.Center;
                                HAllSpread.Sheets[0].Cells[countAP, 0].Text            = Sno.ToString();
                                HAllSpread.Sheets[0].Cells[countAP, 1].Text            = examds.Tables[0].Rows[i]["Year"].ToString();
                                HAllSpread.Sheets[0].Cells[countAP, 1].Note            = examds.Tables[0].Rows[i]["BatchYear"].ToString();
                                HAllSpread.Sheets[0].Cells[countAP, 2].Text            = examds.Tables[0].Rows[i]["Course"].ToString();
                                HAllSpread.Sheets[0].Cells[countAP, 3].Text            = examds.Tables[0].Rows[i]["Department"].ToString();
                                HAllSpread.Sheets[0].Cells[countAP, 3].Note            = examds.Tables[0].Rows[i]["deptacronym"].ToString();
                                HAllSpread.Sheets[0].Cells[countAP, 4].Text            = ds1.Tables[3].Rows[kp]["Semester"].ToString();
                                HAllSpread.Sheets[0].Cells[countAP, 5].Text            = ds1.Tables[3].Rows[kp]["SubjectName"].ToString();
                                HAllSpread.Sheets[0].Cells[countAP, 5].Note            = ds1.Tables[3].Rows[kp]["SubjectNo"].ToString();
                                HAllSpread.Sheets[0].Cells[countAP, 5].Tag             = 1;
                                HAllSpread.Sheets[0].Rows[countAP].ForeColor           = Color.OrangeRed;
                                HAllSpread.Sheets[0].Cells[countAP, 6].Text            = Regular.ToString();
                                HAllSpread.Sheets[0].Cells[countAP, 7].Text            = ds1.Tables[3].Rows[kp]["ArearPracticalCount"].ToString();
                                HAllSpread.Sheets[0].Cells[countAP, 8].Text            = Convert.ToString(Convert.ToInt16(ds1.Tables[3].Rows[kp]["ArearPracticalCount"].ToString()) + Convert.ToInt16(Regular.ToString()));
                                HAllSpread.Sheets[0].RowCount++;

                                Temp = examds.Tables[0].Rows[i]["Department"].ToString();
                            }
                        }
                    }


                    HAllSpread.Sheets[0].SetColumnMerge(0, FarPoint.Web.Spread.Model.MergePolicy.Always);
                    HAllSpread.Sheets[0].SetColumnMerge(1, FarPoint.Web.Spread.Model.MergePolicy.Always);
                    HAllSpread.Sheets[0].SetColumnMerge(2, FarPoint.Web.Spread.Model.MergePolicy.Always);
                    HAllSpread.Sheets[0].SetColumnMerge(3, FarPoint.Web.Spread.Model.MergePolicy.Always);
                    rowcount = HAllSpread.Sheets[0].RowCount * 20;
                }
            }
            HAllSpread.Sheets[0].RowCount--;
            HAllSpread.Sheets[0].PageSize = rowcount;
            HAllSpread.Height             = rowcount;
        }
    }
    protected void btnGenerate_Click(object sender, EventArgs e)
    {
        string    valDegree    = string.Empty;
        string    valBatch     = string.Empty;
        DataTable dtCourceInfo = new DataTable();

        if (cblBatch.Items.Count > 0)
        {
            valBatch = rs.GetSelectedItemsValueAsString(cblBatch);
        }
        if (cblBranch.Items.Count > 0)
        {
            valDegree = rs.GetSelectedItemsValueAsString(cblBranch);
        }
        if (!string.IsNullOrEmpty(valBatch) && !string.IsNullOrEmpty(valDegree))
        {
            string SelectQ = "select distinct (c.Course_Name+'-'+de.Dept_Name) as courceName,r.Batch_Year,r.degree_code,COUNT(r.app_no) as totalStudent from Registration r,Degree d,course c,Department de where r.degree_code=d.Degree_Code and de.Dept_Code=d.Dept_Code and c.Course_Id=d.Course_Id and d.Degree_Code in('" + valDegree + "') and r.Batch_Year in('" + valBatch + "') and r.college_code=c.college_code and d.college_code=de.college_code and d.college_code=c.college_code and r.college_code='" + Convert.ToString(ddlCollege.SelectedValue) + "' and  CC=0 and DelFlag =0 and Exam_Flag <>'DEBAR' and delflag=0 group by (c.Course_Name+'-'+de.Dept_Name),r.Batch_Year,r.degree_code order by (c.Course_Name+'-'+de.Dept_Name),r.Batch_Year,r.degree_code,totalStudent ";
            dtCourceInfo = dirAcc.selectDataTable(SelectQ);
        }
        if (dtCourceInfo.Rows.Count > 0)
        {
            int sno = 0;
            FpSpread1.Visible = true;
            //lblexportxl.Visible = false;
            FpSpread1.Sheets[0].RowCount                                 = 0;
            FpSpread1.Sheets[0].ColumnCount                              = 0;
            FpSpread1.Sheets[0].SheetCorner.ColumnCount                  = 0;
            FpSpread1.Sheets[0].ColumnHeader.RowCount                    = 1;
            FpSpread1.CommandBar.Visible                                 = false;
            FpSpread1.Sheets[0].ColumnCount                              = 5;
            FpSpread1.Sheets[0].Columns[0].Width                         = 70;
            FpSpread1.Sheets[0].Columns[1].Width                         = 100;
            FpSpread1.Sheets[0].Columns[2].Width                         = 250;
            FpSpread1.Sheets[0].Columns[3].Width                         = 100;
            FpSpread1.Sheets[0].Columns[4].Width                         = 100;
            FpSpread1.Sheets[0].ColumnHeader.Cells[0, 0].Text            = "S.No";
            FpSpread1.Sheets[0].ColumnHeader.Cells[0, 0].HorizontalAlign = HorizontalAlign.Center;
            FpSpread1.Sheets[0].ColumnHeader.Cells[0, 1].Text            = "Batch Year";
            FpSpread1.Sheets[0].ColumnHeader.Cells[0, 1].HorizontalAlign = HorizontalAlign.Center;
            FpSpread1.Sheets[0].ColumnHeader.Cells[0, 2].Text            = "Department Name";
            FpSpread1.Sheets[0].ColumnHeader.Cells[0, 2].HorizontalAlign = HorizontalAlign.Center;
            FpSpread1.Sheets[0].ColumnHeader.Cells[0, 3].Text            = "Student Count";
            FpSpread1.Sheets[0].ColumnHeader.Cells[0, 3].HorizontalAlign = HorizontalAlign.Center;
            FpSpread1.Sheets[0].ColumnHeader.Cells[0, 4].Text            = "Select";
            FpSpread1.Sheets[0].ColumnHeader.Cells[0, 4].HorizontalAlign = HorizontalAlign.Center;
            FarPoint.Web.Spread.CheckBoxCellType chkcell = new FarPoint.Web.Spread.CheckBoxCellType();
            FpSpread1.Sheets[0].RowCount = 0;
            FarPoint.Web.Spread.CheckBoxCellType chkcell1 = new FarPoint.Web.Spread.CheckBoxCellType();
            FpSpread1.Sheets[0].RowCount = FpSpread1.Sheets[0].RowCount + 1;
            FpSpread1.Sheets[0].Cells[FpSpread1.Sheets[0].RowCount - 1, 4].CellType        = chkcell1;
            FpSpread1.Sheets[0].Cells[FpSpread1.Sheets[0].RowCount - 1, 4].HorizontalAlign = HorizontalAlign.Center;
            FpSpread1.Sheets[0].SpanModel.Add(FpSpread1.Sheets[0].RowCount - 1, 0, 1, 4);
            chkcell1.AutoPostBack = true;
            FpSpread1.Sheets[0].FrozenRowCount = 1;
            FpSpread1.Sheets[0].AutoPostBack   = false;
            FarPoint.Web.Spread.StyleInfo darkstyle = new FarPoint.Web.Spread.StyleInfo();
            darkstyle.BackColor = ColorTranslator.FromHtml("#0CA6CA");
            darkstyle.ForeColor = System.Drawing.Color.White;
            FpSpread1.ActiveSheetView.ColumnHeader.DefaultStyle = darkstyle;
            foreach (DataRow dr in dtCourceInfo.Rows)
            {
                string BatchYear  = Convert.ToString(dr["batch_year"]).Trim();
                string DegreeCode = Convert.ToString(dr["degree_code"]).Trim();
                string CourceName = Convert.ToString(dr["courceName"]).Trim();
                string torstudent = Convert.ToString(dr["totalStudent"]).Trim();
                sno++;
                FpSpread1.Sheets[0].RowCount = FpSpread1.Sheets[0].RowCount + 1;
                FpSpread1.Sheets[0].Cells[FpSpread1.Sheets[0].RowCount - 1, 0].HorizontalAlign = HorizontalAlign.Center;
                FpSpread1.Sheets[0].Cells[FpSpread1.Sheets[0].RowCount - 1, 1].HorizontalAlign = HorizontalAlign.Center;
                FpSpread1.Sheets[0].Cells[FpSpread1.Sheets[0].RowCount - 1, 2].HorizontalAlign = HorizontalAlign.Left;
                FpSpread1.Sheets[0].Cells[FpSpread1.Sheets[0].RowCount - 1, 3].HorizontalAlign = HorizontalAlign.Center;
                FpSpread1.Sheets[0].Cells[FpSpread1.Sheets[0].RowCount - 1, 0].Text            = sno.ToString();
                FpSpread1.Sheets[0].Cells[FpSpread1.Sheets[0].RowCount - 1, 1].Text            = BatchYear;
                FpSpread1.Sheets[0].Cells[FpSpread1.Sheets[0].RowCount - 1, 2].Text            = CourceName;
                FpSpread1.Sheets[0].Cells[FpSpread1.Sheets[0].RowCount - 1, 2].Note            = DegreeCode;
                FpSpread1.Sheets[0].Cells[FpSpread1.Sheets[0].RowCount - 1, 3].Text            = torstudent;
                FpSpread1.Sheets[0].Cells[FpSpread1.Sheets[0].RowCount - 1, 4].CellType        = chkcell;
                FpSpread1.Sheets[0].Cells[FpSpread1.Sheets[0].RowCount - 1, 4].HorizontalAlign = HorizontalAlign.Center;
            }
            //FpSpread1.Sheets[0].SetColumnMerge(2, FarPoint.Web.Spread.Model.MergePolicy.Always);
            //FpSpread1.Sheets[0].SetColumnMerge(1, FarPoint.Web.Spread.Model.MergePolicy.Always);
        }
        else
        {
        }
        btnSave.Visible              = true;
        FpSpread1.Visible            = true;
        Btndelete.Visible            = false;
        FpSpread1.Sheets[0].PageSize = FpSpread1.Sheets[0].RowCount;
        FpSpread1.SaveChanges();
        FpSpread1.Width  = 640;
        FpSpread1.Height = 400;
    }