protected void ibtnExportPDFAppTableDoc_Click(object sender, EventArgs e)
 {
     GridExamForms.AllowPaging        = false;
     GridExamForms.DataSource         = GetDataSource();
     GridExamForms.Columns[0].Visible = false;
     GridExamForms.DataBind();
     if (GridExamForms.Rows.Count > 0)
     {
         Response.ContentType = "application/pdf";
         Response.AddHeader("content-disposition",
                            "attachment;filename=ExaminationFormRollNumberNotGenerated.pdf");
         Response.Cache.SetCacheability(HttpCacheability.NoCache);
         StringWriter   sw = new StringWriter();
         HtmlTextWriter hw = new HtmlTextWriter(sw);
         GridExamForms.RenderControl(hw);
         StringReader sr         = new StringReader(sw.ToString());
         Document     pdfDoc     = new Document(PageSize.A4, 10f, 10f, 10f, 0f);
         HTMLWorker   htmlparser = new HTMLWorker(pdfDoc);
         PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
         pdfDoc.Open();
         htmlparser.Parse(sr);
         pdfDoc.Close();
         Response.Write(pdfDoc);
         Response.End();
     }
 }
 protected void Page_Load(object sender, EventArgs e)
 {
     try
     {
         if (Convert.ToString(Server.HtmlEncode(Request.Cookies["MyLogin"]["PWD"])) == "")
         {
             Response.Redirect("../Login.aspx");
         }
         if (!IsPostBack)
         {
             txtYearSeason.Text = DateTime.Now.Year.ToString();
             string yr  = DateTime.Now.Year.ToString();
             maikal dev = new maikal();
             int    se  = dev.chksession();
             if (se == 0)
             {
                 ddlExamSeason.SelectedValue = "Sum";
             }
             else
             {
                 ddlExamSeason.SelectedValue = "Win";
             }                                            // lblFromName.Text = "Membership No:";
             txtYearSeason.Text       = DateTime.Now.Year.ToString();
             lblExamSeasonHidden.Text = ddlExamSeason.SelectedValue.ToString() + "" + txtYearSeason.Text.ToString();
             ddlExamSeason.Focus();
             GridExamForms.DataSource = GetDataSource();
             GridExamForms.DataBind();
         }
     }
     catch (NullReferenceException ex)
     {
         Response.Redirect("../Login.aspx");
     }
 }
    protected void btnView_Onclick(object sender, EventArgs e)
    {
        string query = "";

        if (ddlmarks.SelectedValue.ToString() == "Approved")
        {
            if (ddlViewType.SelectedValue.ToString() == "All")
            {
                query = "select ef.SID,ef.IMID, std.Name ,ef.Stream,ef.Course,ef.Part,ef.CenterCode,ef.CenterName,ef.RollNo,ef.City from ExamForms ef, Student std where ef.SID  in(select efs.SID from ExamForm efs where efs.ExamSession='" + lblExamSeasonHidden.Text.ToString() + "' and  efs.SID=ef.SID and  efs.MarkStatus='Approved' or efs.MarkStatus='Submitted') and ef.ExamSeason='" + lblExamSeasonHidden.Text.ToString() + "' and ef.SID=std.SID";
            }
            else if (ddlViewType.SelectedValue.ToString() == "IM")
            {
                query = "select ef.SID,ef.IMID, std.Name ,ef.Stream,ef.Course,ef.Part,ef.CenterCode,ef.CenterName,ef.RollNo,ef.City from ExamForms ef, Student std where ef.SID  in(select efs.SID from ExamForm efs where efs.ExamSession='" + lblExamSeasonHidden.Text.ToString() + "' and  efs.SID=ef.SID and  efs.MarkStatus='Approved' or efs.MarkStatus='Submitted'  and efs.IMID='" + txtIMID.Text.ToString() + "') and ef.ExamSeason='" + lblExamSeasonHidden.Text.ToString() + "' and ef.SID=std.SID and ef.IMID='" + txtIMID.Text.ToString() + "'";
            }
            else if (ddlViewType.SelectedValue.ToString() == "Student")
            {
                query = "select ef.SID,ef.IMID, std.Name ,ef.Stream,ef.Course,ef.Part,ef.CenterCode,ef.CenterName,ef.RollNo,ef.City from ExamForms ef, Student std where ef.SID  in(select efs.SID from ExamForm efs where efs.ExamSession='" + lblExamSeasonHidden.Text.ToString() + "' and  efs.SID='" + txtStudent.Text.ToString() + "' and  efs.MarkStatus='Approved' or efs.MarkStatus='Submitted') and ef.ExamSeason='" + lblExamSeasonHidden.Text.ToString() + "' and ef.SID=std.SID ";
            }
        }
        else if (ddlmarks.SelectedValue.ToString() == "Submitted")
        {
            if (ddlViewType.SelectedValue.ToString() == "All")
            {
                query = "select ef.SID,ef.IMID, std.Name ,ef.Stream,ef.Course,ef.Part,ef.CenterCode,ef.CenterName,ef.RollNo,ef.City from ExamForms ef, Student std where ef.SID  in(select efs.SID from ExamForm efs where efs.ExamSession='" + lblExamSeasonHidden.Text.ToString() + "' and  efs.SID=ef.SID and  efs.MarkStatus='Submitted') and ef.ExamSeason='" + lblExamSeasonHidden.Text.ToString() + "' and ef.SID=std.SID";
            }
            else if (ddlViewType.SelectedValue.ToString() == "IM")
            {
                query = "select ef.SID,ef.IMID, std.Name ,ef.Stream,ef.Course,ef.Part,ef.CenterCode,ef.CenterName,ef.RollNo,ef.City from ExamForms ef, Student std where ef.SID  in(select efs.SID from ExamForm efs where efs.ExamSession='" + lblExamSeasonHidden.Text.ToString() + "' and  efs.SID=ef.SID and  efs.MarkStatus='Submitted'  and efs.IMID='" + txtIMID.Text.ToString() + "') and ef.ExamSeason='" + lblExamSeasonHidden.Text.ToString() + "' and ef.SID=std.SID and ef.IMID='" + txtIMID.Text.ToString() + "'";
            }
            else if (ddlViewType.SelectedValue.ToString() == "Student")
            {
                query = "select ef.SID,ef.IMID, std.Name ,ef.Stream,ef.Course,ef.Part,ef.CenterCode,ef.CenterName,ef.RollNo,ef.City from ExamForms ef, Student std where ef.SID  in(select efs.SID from ExamForm efs where efs.ExamSession='" + lblExamSeasonHidden.Text.ToString() + "' and  efs.SID='" + txtStudent.Text.ToString() + "' and  efs.MarkStatus='Submitted') and ef.ExamSeason='" + lblExamSeasonHidden.Text.ToString() + "' and ef.SID=std.SID ";
            }
        }
        else if (ddlmarks.SelectedValue.ToString() == "NotSubmitted")
        {
            if (ddlViewType.SelectedValue.ToString() == "All")
            {
                query = "select ef.SID,ef.IMID, std.Name ,ef.Stream,ef.Course,ef.Part,ef.CenterCode,ef.CenterName,ef.RollNo,ef.City from ExamForms ef, Student std where ef.SID  in(select efs.SID from ExamForm efs where efs.ExamSession='" + lblExamSeasonHidden.Text.ToString() + "' and  efs.SID=ef.SID and  efs.MarkStatus='NotSubmitted') and ef.ExamSeason='" + lblExamSeasonHidden.Text.ToString() + "' and ef.SID=std.SID";
            }
            else if (ddlViewType.SelectedValue.ToString() == "IM")
            {
                query = "select ef.SID,ef.IMID, std.Name ,ef.Stream,ef.Course,ef.Part,ef.CenterCode,ef.CenterName,ef.RollNo,ef.City from ExamForms ef, Student std where ef.SID  in(select efs.SID from ExamForm efs where efs.ExamSession='" + lblExamSeasonHidden.Text.ToString() + "' and  efs.SID=ef.SID and  efs.MarkStatus='NotSubmitted'  and efs.IMID='" + txtIMID.Text.ToString() + "') and ef.ExamSeason='" + lblExamSeasonHidden.Text.ToString() + "' and ef.SID=std.SID and ef.IMID='" + txtIMID.Text.ToString() + "'";
            }
            else if (ddlViewType.SelectedValue.ToString() == "Student")
            {
                query = "select ef.SID,ef.IMID, std.Name ,ef.Stream,ef.Course,ef.Part,ef.CenterCode,ef.CenterName,ef.RollNo,ef.City from ExamForms ef, Student std where ef.SID  in(select efs.SID from ExamForm efs where efs.ExamSession='" + lblExamSeasonHidden.Text.ToString() + "' and  efs.SID='" + txtStudent.Text.ToString() + "' and  efs.MarkStatus='NotSubmitted') and ef.ExamSeason='" + lblExamSeasonHidden.Text.ToString() + "' and ef.SID=std.SID ";
            }
        }
        SqlDataAdapter ad = new SqlDataAdapter(query, con);
        DataSet        ds = new DataSet();

        ad.Fill(ds);
        GridExamForms.DataSource = ds;
        GridExamForms.DataBind();
        btnView.Focus();
    }
    protected void btnViewMembershipNo_Onclick(object sender, EventArgs e)
    {
        SqlDataAdapter ad = new SqlDataAdapter("select ExamForm.SubID,ExamForm.SubName,ExamForms.Status,ExamForms.City, ExamForms.RollNo from ExamForm inner join ExamForms on ExamForm.SN=ExamForms.SN Where ExamForms.SID='" + lblEnrolment.Text.ToString() + "' and ExamForms.ExamSeason='" + lblExamSeasonHidden.Text.ToString() + "'", con);
        DataSet        ds = new DataSet();

        ad.Fill(ds);
        GridExamForms.DataSource = ds;
        GridExamForms.DataBind();
        btnSubmit.Focus();
    }
    protected void btnViewMarks_Onclick(object sender, EventArgs e)
    {
        SqlDataAdapter ad = new SqlDataAdapter("select * from SExamMarks where IMID='" + GridExamForms.SelectedRow.Cells[2].Text.ToString() + "' and ExamSeason='" + lblExamSeasonHidden.Text.ToString() + "' and SID='" + GridExamForms.SelectedRow.Cells[1].Text.ToString() + "'", con);
        DataSet        ds = new DataSet();

        ad.Fill(ds);
        GridExamForms.DataSource = ds;
        GridExamForms.DataBind();
        btnApprove.Focus();
    }
    protected void btnView_Onclick(object sender, EventArgs e)
    {
        SqlCommand cmd = new SqlCommand();

        con.Close(); con.Open();
        DataTable      dtDatas = (DataTable)ViewState["dtDatas"];
        SqlDataAdapter ad      = new SqlDataAdapter("select distinct ef.SID, st.Name, st.IMID from ExamForm ef, Student st where ef.MarkStatus='Approved' and ef.ExamSession='" + lblSessionHiddend.Text.ToString() + "' and ef.Course='" + ddlCourse.SelectedValue.ToString() + "' and ef.Part='" + ddlPart.SelectedValue.ToString() + "' and ef.SID=st.SID", con);
        DataSet        ds      = new DataSet();

        ad.Fill(ds);
        GridSID.DataSource = ds;
        GridSID.DataBind();
        for (int i = 0; i < GridSID.Rows.Count; i++)
        {
            cmd = new SqlCommand("select CourseID from ExamCurrent where SID='" + GridSID.Rows[i].Cells[0].Text.ToString() + "'", con);
            string cid = Convert.ToString(cmd.ExecuteScalar());
            fillddl(cid, GridSID.Rows[i].Cells[0].Text.ToString());
            int k = 0;
            for (int jj = 0; jj < ddlSyllabus.Items.Count; jj++)
            {
                cmd = new SqlCommand("select SID from SExamMarks where SID='" + GridSID.Rows[i].Cells[0].Text.ToString() + "' and SubID='" + ddlSyllabus.Items[jj].Value.ToString() + "' and Status='Pass' and MarkStatus='Submitted'", con);
                string id = Convert.ToString(cmd.ExecuteScalar());

                if (id != "")
                {
                    k = k + 1;
                }
                if (ddlPart.SelectedValue.ToString() == "SectionB")
                {
                    if (k == 10)
                    {
                        k = ddlSyllabus.Items.Count;
                    }
                }
            }
            if (k >= ddlSyllabus.Items.Count)
            {
                // cmd = new SqlCommand("update SExamMarks set MarkStatus='Approved' where SID='" + GridSID.Rows[i].Cells[0].Text.ToString() + "' and Part='" + ddlPart.SelectedValue.ToString() + "'", con);
                // cmd.ExecuteNonQuery();
                DataRow drNewRow = dtDatas.NewRow();
                drNewRow["SID"]    = GridSID.Rows[i].Cells[0].Text.ToString();
                drNewRow["Name"]   = GridSID.Rows[i].Cells[1].Text.ToString();
                drNewRow["Stream"] = lblHiddendStream.Text.ToString();
                drNewRow["Course"] = ddlCourse.SelectedValue.ToString();
                drNewRow["Part"]   = ddlPart.SelectedValue.ToString();
                drNewRow["IMID"]   = GridSID.Rows[i].Cells[2].Text.ToString();
                dtDatas.Rows.Add(drNewRow);
                GridExamForms.DataSource = dtDatas;
                GridExamForms.DataBind();
            }
        }
        con.Close();
        con.Dispose();
        btnView.Focus();
    }
 protected void rbtnNotGenerated_CheckedChanged(object sender, EventArgs e)
 {
     if (txtIMID.Text != "")
     {
         GridExamForms.DataSource = GetDataSource();
         GridExamForms.DataBind();
         lblMsg.Text = "";
     }
     else
     {
         lblMsg.Text = "Enter IMID";
     }
     if (GridExamForms.Rows.Count > 0)
     {
         GridExamForms.Focus();
     }
     else
     {
         txtIMID.Focus();
     }
 }
 protected void ibtnExportDocAppTableDoc_click(object sender, ImageClickEventArgs e)
 {
     GridExamForms.AllowPaging = false;
     GridExamForms.DataSource  = GetDataSource();
     GridExamForms.DataBind();
     if (GridExamForms.Rows.Count > 0)
     {
         Response.Clear();
         Response.Buffer = true;
         Response.AddHeader("content-disposition",
                            "attachment;filename=ExaminationFormRollNumberNotGenerated.doc");
         Response.Charset     = "";
         Response.ContentType = "application/vnd.ms-word ";
         StringWriter   sw = new StringWriter();
         HtmlTextWriter hw = new HtmlTextWriter(sw);
         GridExamForms.RenderControl(hw);
         Response.Output.Write(sw.ToString());
         Response.Flush();
         Response.End();
     }
 }
 private void ok()
 {
     lblExceptionOK.Text = "";
     try
     {
         con.Close(); con.Open();
         int        i   = 0;
         SqlCommand cmd = new SqlCommand();
         cmd = new SqlCommand("select SID,Part from ExamForms where SID='" + txticesn.Text.ToString() + "' and  ExamSeason='" + lblExamSeasonHidden.Text.ToString() + "'", con);
         string        apno = "", Part = "";
         SqlDataReader reader;
         reader = cmd.ExecuteReader();
         if (reader.Read())
         {
             apno = reader["SID"].ToString(); lblPart.Text = reader["Part"].ToString();
         }
         reader.Close();
         if (apno != "")
         {
             lblEnrolment.Text = apno.ToString();
             apno = "1";
         }
         else
         {
             string sn = txticesn.Text.ToString();
             cmd    = new SqlCommand("select Enrolment,Part from AppRecord where Exam= 'E" + sn.ToString() + "' and Session='" + lblExamSeasonHidden.Text.ToString() + "'", con);
             reader = cmd.ExecuteReader();
             if (reader.Read())
             {
                 apno = reader["Enrolment"].ToString(); Part = reader["Part"].ToString();
             }
             reader.Close();
             if (apno != "")
             {
                 lblEnrolment.Text = apno.ToString();
                 apno = "2";
                 cmd  = new SqlCommand("select SN from ExamForms where SID='" + lblEnrolment.Text.ToString() + "' and Part='" + Part.ToString() + "' and  ExamSeason='" + lblExamSeasonHidden.Text.ToString() + "'", con);
                 string chk = Convert.ToString(cmd.ExecuteScalar());
                 if (chk != "")
                 {
                     lblSN.Text = chk.ToString();
                 }
                 else
                 {
                 }
             }
             else
             {
                 lblExceptionOK.Text = "Record Not Found !"; lblName.Text = ""; lblCourse.Text = ""; lblIMID.Text = ""; BindExamGrid(); GridExamForms.DataBind(); pnlDetails.Visible = false;
             }
             if (apno == "2")
             {
                 SqlCommand    cmdg = new SqlCommand("select * from AppRecord where Exam ='E" + sn + "' and Session='" + lblExamSeasonHidden.Text.ToString() + "'", con);
                 SqlDataReader sdr;
                 sdr = cmdg.ExecuteReader();
                 while (sdr.Read())
                 {
                     lblIMID.Text      = sdr["IMID"].ToString();
                     lblName.Text      = sdr["Name"].ToString() + " s/o " + sdr["FName"].ToString();
                     lblCourse.Text    = sdr["Stream"].ToString() + ", " + sdr["Course"].ToString();
                     lblPart.Text      = sdr["Part"].ToString();
                     lblIMID.Text      = "IMID: " + sdr["IMID"].ToString();
                     lblEnrolment.Text = sdr["Enrolment"].ToString();
                     if (lblEnrolment.Text == sdr["AppNo"].ToString())
                     {
                         lblTempEnrol.Text = "[TEMP]";
                     }
                     else
                     {
                         lblTempEnrol.Text = "";
                     }
                     lblExceptionOK.Text = "";
                 }
                 sdr.Close(); BindExamGrid(); GridExam.Focus();
                 sdr.Dispose();
             }
         }
         if (apno == "1")
         {
             cmd    = new SqlCommand("select * from ExamForms where SID='" + txticesn.Text.ToString() + "' and Part='" + lblPart.Text.ToString() + "' and  ExamSeason='" + lblExamSeasonHidden.Text.ToString() + "'", con);
             reader = cmd.ExecuteReader();
             while (reader.Read())
             {
                 lblName.Text      = "";
                 lblCourse.Text    = reader["Course"].ToString() + "- " + reader["Part"].ToString();
                 lblPart.Text      = reader["Part"].ToString();
                 lblIMID.Text      = "IMID: " + reader["IMID"].ToString();
                 lblEnrolment.Text = reader["SID"].ToString();
                 lblSN.Text        = reader["SN"].ToString();
             }
             reader.Close(); BindExamGrid(); GridExam.Focus();
             reader.Dispose();
         }
     }
     catch (SqlException ex) { lblExceptionOK.Text = ex.ToString(); }
     catch (FormatException ex) { lblExceptionOK.Text = ex.ToString(); }
     finally { con.Close(); con.Dispose(); }
 }
 private void BindGridExamForms()
 {
     adp = new SqlDataAdapter("select ExamForm.SubID,ExamForm.SubName,ExamForms.Status,ExamForms.City, ExamForms.RollNo from ExamForm inner join ExamForms on ExamForm.SN=ExamForms.SN and ExamForms.SID='" + lblEnrolment.Text.ToString() + "' and  ExamForms.ExamSeason='" + lblExamSeasonHidden.Text.ToString() + "' and ExamForms.SN='" + GridExam.SelectedDataKey.Value + "'", con);
     DataSet ds = new DataSet(); adp.Fill(ds); GridExamForms.DataSource = ds; GridExamForms.DataBind();
 }
    protected void DeleteRecord(object sender, GridViewDeleteEventArgs e)
    {
        con.Open();
        string SN = GridExam.DataKeys[e.RowIndex].Value.ToString();

        cmd = con.CreateCommand();
        SqlTransaction trans;

        trans           = con.BeginTransaction("RangeTrans");
        cmd.Connection  = con;
        cmd.Transaction = trans;
        try
        {
            cmd.CommandText = "delete ExamForms where SN='" + SN + "' and Part='" + lblPart.Text + "' and ExamSeason='" + lblExamSeasonHidden.Text.ToString() + "'";
            cmd.ExecuteNonQuery();
            cmd.CommandText = "delete ExamForm where SN='" + SN + "'";
            cmd.ExecuteNonQuery();
            if (lblPart.Text == "PartII")
            {
                cmd.CommandText = "update ExamCurrent set CourseStatus=@CourseStatus where SId='" + lblEnrolment.Text.ToString() + "'";
                cmd.Parameters.AddWithValue("@CourseStatus", "Approved");
            }
            else
            {
                cmd.CommandText = "update ExamCurrent set ExamStatus=@ExamStatus where SId='" + lblEnrolment.Text.ToString() + "'";
                cmd.Parameters.AddWithValue("@ExamStatus", "Approved");
            }
            cmd.ExecuteNonQuery();
            trans.Commit();
            ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "success", "alert('Record Re-Submit successfully !')", true); BindExamGrid(); GridExamForms.DataBind(); pnlDetails.Visible = false; lblEnrolment.Text = ""; txticesn.Text = ""; txticesn.Focus();
        }
        catch (Exception ex)
        {
            ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "success", "alert('Not deleted.!')", true); BindExamGrid(); pnlDetails.Visible = false;  lblEnrolment.Text = ""; txticesn.Text = ""; txticesn.Focus();
            try { trans.Rollback(); }
            catch (Exception ex2)
            {
                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "success", "alert('Not deleted due to transaction rollback fail.!')", true); BindExamGrid(); pnlDetails.Visible = false; BindGridExamForms(); lblEnrolment.Text = ""; txticesn.Text = ""; txticesn.Focus();
            }
        }
        finally { con.Close(); con.Dispose(); }
    }