Solved

Using Triggers Problem

Posted on 2009-04-14
3
378 Views
Last Modified: 2012-05-06
Hi Sir,

                Iam using Tree view in my form.Iam using triggers to bind values.If Iam Using Triggers,
One problem is there.If Iam using update panel also page is refreshed.Another Problem is After selecting some thing in my form after that ,i press f5(refresh) page is not refreshed values in DropDownLists are not changed.Same values are display.I attach my code.
This aspx Page
 

<table border="0" cellpadding="0" cellspacing="0" class="border_table" height="350"

        width="100%">

        <tr>

            <td colspan="8" rowspan="1" style="height: 47px; width: 100%;" valign="top">

                <table style="height: 28px" width="100%">

                    <tbody align="center">

                        <tr>

                            <td align="left" class="Heading_Style_Header" style="width: 100%">

                                Trainer Training</td>

                        </tr>

                    </tbody>

                </table>

            </td>

        </tr>

        <tr>

            <td colspan="6" rowspan="2" style="width: 5%; height: 345px;" valign="top">

            </td>

            <td align="center" colspan="1" rowspan="2" style="width: 90%; height: 345px;" valign="top">

                <asp:ScriptManager id="ScriptManager1" runat="server">

                </asp:ScriptManager>

                 <asp:updatepanel id="updatepanel1" runat="server" ChildrenAsTriggers="False" UpdateMode="Conditional">

                    <contenttemplate>

<TABLE style="WIDTH: 100%"><TBODY><TR><TD style="WIDTH: 5%"></TD><TD style="WIDTH: 90%"><TABLE style="WIDTH: 100%"><TBODY><TR><TD style="WIDTH: 100%"><TABLE style="WIDTH: 100%"><TBODY><TR><TD style="WIDTH: 10%; TEXT-ALIGN: right">Batch:</TD><TD style="WIDTH: 13%; TEXT-ALIGN: left"><asp:DropDownList id="ddlBatch" runat="server" Width="101px" OnSelectedIndexChanged="ddlBatch_SelectedIndexChanged" AutoPostBack="True">

                                                    </asp:DropDownList></TD><TD style="WIDTH: 10%; TEXT-ALIGN: right">Course:</TD><TD style="WIDTH: 13%; TEXT-ALIGN: left"><asp:DropDownList id="ddlCourse" runat="server" Width="101px" OnSelectedIndexChanged="ddlCourse_SelectedIndexChanged" AutoPostBack="True">

                                                    </asp:DropDownList></TD><TD style="VERTICAL-ALIGN: top; WIDTH: 54%; TEXT-ALIGN: left" colSpan=3>&nbsp;&nbsp;&nbsp;<asp:Label style="VERTICAL-ALIGN: middle" id="lbl_Options" runat="server" __designer:wfdid="w3" Visible="False" CssClass="body_Text" Text="Options:"></asp:Label>&nbsp;<asp:DropDownList id="ddl_Items" runat="server" Width="101px" OnSelectedIndexChanged="ddl_Items_SelectedIndexChanged" AutoPostBack="True" __designer:wfdid="w4" Visible="False"></asp:DropDownList>&nbsp;<asp:Button style="BACKGROUND-IMAGE: url(But_back.png); BACKGROUND-COLOR: transparent" id="btnshow" onclick="btnshow_Click" runat="server" CausesValidation="False" Width="86px" __designer:wfdid="w5" Visible="False" Text="Freeze"></asp:Button></TD></TR><TR><TD style="WIDTH: 10%; TEXT-ALIGN: right"></TD><TD style="WIDTH: 13%; TEXT-ALIGN: left"></TD><TD style="WIDTH: 10%; TEXT-ALIGN: right"></TD><TD style="WIDTH: 13%; TEXT-ALIGN: left"></TD><TD style="WIDTH: 54%; TEXT-ALIGN: right" colSpan=3></TD></TR></TBODY></TABLE></TD></TR><TR><TD style="WIDTH: 100%"><TABLE style="WIDTH: 100%"><TBODY><TR><TD style="VERTICAL-ALIGN: top; WIDTH: 30%"><TABLE style="WIDTH: 100%"><TBODY><TR><TD style="WIDTH: 100%"><asp:TreeView style="WIDTH: 100%" id="TreeView1" runat="server" Width="100%" OnTreeNodeExpanded="TreeView1_TreeNodeExpanded" PopulateNodesFromClient="true" ShowExpandCollapse="true" ExpandDepth="0" OnSelectedNodeChanged="TreeView1_SelectedNodeChanged" ShowLines="True" OnTreeNodePopulate="TreeView1_TreeNodePopulate"></asp:TreeView> </TD></TR></TBODY></TABLE></TD><TD style="WIDTH: 70%"><TABLE style="WIDTH: 100%"><TBODY><TR><TD style="WIDTH: 100%"><asp:Label id="lbl_Result_Per" runat="server" CssClass="Body_Text" ForeColor="Blue"></asp:Label></TD></TR><TR><TD style="WIDTH: 100%"><asp:TextBox style="VERTICAL-ALIGN: top; TEXT-ALIGN: left" id="txtdesc" runat="server" Width="90%" Visible="False" TextMode="MultiLine" ReadOnly="True"></asp:TextBox></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE></TD></TR><TR><TD style="WIDTH: 100%"><TABLE style="WIDTH: 100%"><TBODY><TR><TD style="WIDTH: 30%"></TD><TD style="WIDTH: 70%"><TABLE style="WIDTH: 100%"><TBODY><TR><TD style="WIDTH: 25%; TEXT-ALIGN: right"><asp:Button id="btn_att" onclick="btn_att_Click" runat="server" Text="Attendance"></asp:Button></TD><TD style="WIDTH: 25%; TEXT-ALIGN: left"><asp:Button id="btn_Exam" onclick="btn_Exam_Click" runat="server" Text="Schedule Exam"></asp:Button></TD><TD style="WIDTH: 50%"></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE></TD><TD style="WIDTH: 5%"></TD></TR></TBODY></TABLE>

</contenttemplate>

<Triggers>

<asp:PostBackTrigger ControlID="btnshow"></asp:PostBackTrigger>

<asp:PostBackTrigger ControlID="ddlBatch"></asp:PostBackTrigger>

<asp:PostBackTrigger ControlID="ddlCourse"></asp:PostBackTrigger>

<asp:PostBackTrigger ControlID="ddl_Items"></asp:PostBackTrigger>

<asp:PostBackTrigger ControlID="TreeView1"></asp:PostBackTrigger>

<asp:PostBackTrigger ControlID="btn_att"></asp:PostBackTrigger>

<asp:PostBackTrigger ControlID="btn_Exam"></asp:PostBackTrigger>

</Triggers>
 

           </asp:updatepanel>

               </td>

            <td colspan="1" rowspan="2" style="width: 5%; height: 345px;" valign="top">

            </td>

        </tr>

        <tr>

        </tr>

    </table>
 
 

This is cs page for that one
 

using System;

using System.Data;

using System.Configuration;

using System.Collections;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Web.UI.HtmlControls;

using BusinessLayer;

using System.Data.SqlClient;

using ExceptionDetails;

using System.IO;

using System.Data.SqlClient;
 
 

public partial class CampusCenter_Creating_Users : System.Web.UI.Page

{

    InsertMaster Insert;

    UpdateMaster Update;

    DeleteMaster Delete;

    ExpDetails exDetails;

    SqlCommand cmd;

    SqlConnection con;

    SqlDataReader dr;

    TreeNode nodenew;

    string ClientIPAdd;

    string xmlPath;

    string scriptText;

    static Int32 option, checknodecount,flag;

    string nextsessionname, countparentid;

    Int32 session_order, nodecount;

    static Int32 flagcheck;

    string sname2;

    string OptionId = "";

    string session_status;

    Label lbl;

    protected void Page_Load(object sender, EventArgs e)

    {

        Session["ConStr"] = ConfigurationSettings.AppSettings["ConStr"].ToString();

       // Session["Branch_Id"] = "119";

        //Session["MURI"] = "109";
 

        string HostName = System.Net.Dns.GetHostName();

        ClientIPAdd = System.Net.Dns.GetHostAddresses(HostName).GetValue(0).ToString();

        xmlPath = Server.MapPath("~") + "\\Exception_XML_File\\ExceptionalDetails.xml";

        if (Request.Browser.Browser == "Firefox")

            Form.Attributes.Add("autocomplete", "off");

        if (Page.IsPostBack == false)

        {

            this.ScriptManager1.SetFocus(ddlBatch);

            BindBatch();

            TreeView1.Visible = true;

            btn_att.Visible = false;

            btn_Exam.Visible = false;

            lbl_Result_Per.Text = "";

            Session["node_Exists"] = "yes";        

            

        }

       

        if (Session["refresh"] == "yes")

        {

            btn_att.Visible = false;

            content();

            

        }

        if (Session["refresh2"] == "yes")

        {

                lbl = new Label();

                 lbl.Text = "";

                btn_att.Visible = false;

                btn_Exam.Visible = false;

                Result();

                content2();

           

        }

            

           if(Session["Attendance"] == "no")

           {

           }

           

           if(Session["Attendance"] == "yes")

           {

           

               NextSession();

               string selectedname = TreeView1.SelectedNode.Text;

               string qry8 = "select Record_Type from Admn_Course_Organization where Id='" + TreeView1.SelectedNode.Value + "'";

               DataTable dt_type = BusinessLayer.SelectMaster.GetDataTable(Session["ConStr"].ToString(), qry8);

               if (dt_type.Rows[0][0].ToString().Equals("SES") && nextsessionname == selectedname)

               {

                   lbl_Result_Per.Text = "";

                   Session["Session_id"] = TreeView1.SelectedNode.Value;

                   btn_att.Visible = true;

                   Session["Session_Name"] = TreeView1.SelectedNode.Text;

                   string strMsg = "Take attendance";

                   Label lbl = new Label();
 

                   lbl.Text = ("<script language=\'javascript\'>"
 

                   + (Environment.NewLine + ("window.alert(" + ("\'"

                   + (strMsg + ("\'" + ")</script>"))))));

                   Page.Controls.Add(lbl);

                   Session.Remove("Attendance");

               }

           }

        

       

    }

    public void SessionResult()

    {

        try

        {

            string maxid = "select Max(Id) from Stu_Batch_Course_Percentage where Session_Id='" + TreeView1.SelectedNode.Value + "'";

            DataTable dt_maxid = BusinessLayer.SelectMaster.GetDataTable(Session["ConStr"].ToString(), maxid);

            if (dt_maxid.Rows[0][0].ToString().Equals(""))

            {

                content();

            }

            else

            {

                string exam = "select Exam_Name from Stu_Batch_Course_Percentage where Id='" + dt_maxid.Rows[0][0].ToString() + "'";

                DataTable dt_exam = BusinessLayer.SelectMaster.GetDataTable(Session["ConStr"].ToString(), exam);

                string qry6 = "select Count_Qualified,Attended_Strength from Stu_Batch_Course_Percentage where   Batch_Id='" + ddlBatch.SelectedValue + "' and Session_Id='" + TreeView1.SelectedNode.Value + "' and Exam_Name='" + dt_exam.Rows[0][0].ToString() + "' ";

                DataTable dt_per = BusinessLayer.SelectMaster.GetDataTable(Session["ConStr"].ToString(), qry6);

                if (dt_per.Rows.Count == 0)

                {

                    Session["Result_Per"] = "0.00";

                }

                else

                {

                    if (dt_per.Rows[0][0].ToString().Equals(""))

                    {

                        Session["Result_Per"] = "0.00";

                    }

                    else

                    {

                        string qualified_count = dt_per.Rows[0][0].ToString();

                        string present_strength = dt_per.Rows[0][1].ToString();
 

                        float passed_count = float.Parse(qualified_count);

                        float total = float.Parse(present_strength);

                        float result_per = ((passed_count) / (total)) * 100;
 

                        if (result_per > 60)

                        {

                            Session["Result_Per"] = result_per;

                            Update = new UpdateMaster();

                            Update.UpdateTo("Stu_Exam_Course_Status", "Status", "Y", Session["MURI"].ToString(), "Session_Id", TreeView1.SelectedNode.Value );
 
 

                        }

                        else

                        {

                            Session["Result_Per"] = result_per;

                            flagcheck = 2;
 

                        }

                    }

                    string result_per1 = Session["Result_Per"].ToString();

                    float pr11 = float.Parse(result_per1);

                    lbl_Result_Per.Visible = true;

                    //"Attendance submitted!<br><br>Total No of students:&nbsp;<b>" + total + "<br>No of students present:&nbsp;<b>" + countp + "<br>No of students absent:&nbsp;<b>" + counta + "<br>Present Percentage:&nbsp;<b>" + per + "";

                    lbl_Result_Per.Text = "Result for <b>'" + TreeView1.SelectedNode.Text + "' :&nbsp;<b>" + pr11 + "";

                  

                }

                content();

            }

           

        }

        catch (Exception ex)

        {

            scriptText = "window.alert('Sorry for inconvenience ,The data is not processed will get back to you soon');";

            Insert = new InsertMaster();

            Insert.DLInsert("Exception_Handling", "Module", "Training Center", "Page", "Trainer_Training.aspx.aspx", "Method", "SessionResult", "Client_IP", ClientIPAdd, "1");

            string sqlQuery = "SELECT MAX(Id) AS ID FROM Exception_Handling WHERE (Module = 'Training Center') AND (Page = 'Trainer_Training.aspx.aspx') AND";

            sqlQuery += " (Method = 'SessionResult') AND (Client_IP = '" + ClientIPAdd + "') AND (URI = '1')";

            try

            {

                DataTable dt_ExpDetails = BusinessLayer.SelectMaster.GetDataTable(Session["ConStr"].ToString(), sqlQuery);

                int expID = Convert.ToInt32(dt_ExpDetails.Rows[0][0].ToString());

                exDetails = new ExpDetails();

                exDetails.toXml(xmlPath, expID, ex.Message);

            }

            catch

            {
 

            }
 

            ScriptManager.RegisterClientScriptBlock(this, typeof(Page), "validationAlert", scriptText, true);

        }

    }

    //To Calculate Result for current scheduled session and Display it

    public void Result()

    {

        try

        {

            string qry6 = "select Count_Qualified,Attended_Strength from Stu_Batch_Course_Percentage where   Batch_Id='" + Session["Batch_Id"].ToString() + "' and Session_Id='" + Session["Session_id"].ToString() + "' and Exam_Name='" + Session["Sess_Name"].ToString() + "' ";

            DataTable dt_per = BusinessLayer.SelectMaster.GetDataTable(Session["ConStr"].ToString(), qry6);

            if (dt_per.Rows.Count == 0)

            {

                Session["Result_Percentage"] = "0.00";

            }

            else

            {

                if (dt_per.Rows[0][0].ToString().Equals(""))

                {

                    Session["Result_Percentage"] = "0.00";

                }

                else

                {

                    string qualified_count = dt_per.Rows[0][0].ToString();

                    string present_strength = dt_per.Rows[0][1].ToString();

                    string qry_completed = "select count(*)from Stu_Exam_Status where  Status='Y' and  Exam_Name='" + Session["Sess_Name"].ToString() + "' ";

                    DataTable dt_completed = BusinessLayer.SelectMaster.GetDataTable(Session["ConStr"].ToString(), qry_completed);

                    if (dt_completed.Rows.Count > 1)

                    {
 

                        if (present_strength == dt_completed.Rows[0][0].ToString())

                        {

                            float passed_count = float.Parse(qualified_count);

                            float total = float.Parse(present_strength);

                            float result_per = ((passed_count) / (total)) * 100;
 

                            if (result_per > 60)

                            {

                                Session["Result_Percentage"] = result_per;

                                Update = new UpdateMaster();

                                Update.UpdateTo("Stu_Exam_Course_Status", "Status", "Y", Session["MURI"].ToString(), "Session_Id", Session["Session_id"].ToString());
 

                            }

                            else

                            {

                                flagcheck = 7;

                                Session["Result_Percentage"] = result_per;

                                // ScriptManager.RegisterClientScriptBlock(this, typeof(Page), "ClientScript", "{debugger; alert('Reschedule the '" + lbl_Examname.Text + "' session as reult is less than 60%'); }", true);

                            }

                            string result_per1 = Session["Result_Percentage"].ToString();

                            float pr11 = float.Parse(result_per1);

                            lbl_Result_Per.Visible = true;

                            //"Attendance submitted!<br><br>Total No of students:&nbsp;<b>" + total + "<br>No of students present:&nbsp;<b>" + countp + "<br>No of students absent:&nbsp;<b>" + counta + "<br>Present Percentage:&nbsp;<b>" + per + "";

                            lbl_Result_Per.Text = "Result for <b>'" + Session["Sess_Name"].ToString() + "' :&nbsp;<b>" + pr11 + "";

                        }

                        if (present_strength != dt_completed.Rows[0][0].ToString())

                        {

                            flagcheck = 6;

                        }

                    }

                    else

                    {

                        string comp = dt_completed.Rows[0][0].ToString();

                        Int32 i = Int32.Parse(comp);

                        if (i == 0)

                        {

                            flagcheck = 8;

                        }

                    }

                }

            

            }

        }

        catch (Exception ex)

        {

            scriptText = "window.alert('Sorry for inconvenience ,The data is not processed will get back to you soon');";

            Insert = new InsertMaster();

            Insert.DLInsert("Exception_Handling", "Module", "Training Center", "Page", "Trainer_Training.aspx.aspx", "Method", "Result", "Client_IP", ClientIPAdd, "1");

            string sqlQuery = "SELECT MAX(Id) AS ID FROM Exception_Handling WHERE (Module = 'Training Center') AND (Page = 'Trainer_Training.aspx.aspx') AND";

            sqlQuery += " (Method = 'Result') AND (Client_IP = '" + ClientIPAdd + "') AND (URI = '1')";

            try

            {

                DataTable dt_ExpDetails = BusinessLayer.SelectMaster.GetDataTable(Session["ConStr"].ToString(), sqlQuery);

                int expID = Convert.ToInt32(dt_ExpDetails.Rows[0][0].ToString());

                exDetails = new ExpDetails();

                exDetails.toXml(xmlPath, expID, ex.Message);

            }

            catch

            {
 

            }
 

            ScriptManager.RegisterClientScriptBlock(this, typeof(Page), "validationAlert", scriptText, true);

        }

    }

    //To check top level option  after freeze

    private void checkdata()

    {

        try

        {

            SelectMaster SelectMaster = new SelectMaster();

            string qrynode = "select Parent_Id from Admn_Batch_Course_Structure where Parent_Id IS NULL and  Course_Id='" + ddlCourse.SelectedValue + "' and Batch_Id='" + ddlBatch.SelectedValue + "'";

            DataTable dt_nodes = BusinessLayer.SelectMaster.GetDataTable(Session["ConStr"].ToString(), qrynode);

            if (dt_nodes.Rows.Count > 0)

            {

                btnshow.Attributes.Remove("onclick");

            }

            else

            {

                //ScriptManager.RegisterStartupScript(this, this.GetType(), "script", "confirm('Are you sure you want to Freeze the Option..?');", true);

                btnshow.Attributes.Add("onclick", "if(confirm('Are you sure you want to freeze the option..?')){}else{return false}");
 

            }

        }

        catch (Exception ex)

        {

            scriptText = "window.alert('Sorry for inconvenience ,the data is not processed will get back to you soon');";

            Insert = new InsertMaster();

            Insert.DLInsert("Exception_Handling", "Module", "Training Center", "Page", "Trainer_Training.aspx.aspx", "Method", "checkdata", "Client_IP", ClientIPAdd, "1");

            string sqlQuery = "SELECT MAX(Id) AS ID FROM Exception_Handling WHERE (Module = 'Training Center') AND (Page = 'Trainer_Training.aspx.aspx') AND";

            sqlQuery += " (Method = 'checkdata') AND (Client_IP = '" + ClientIPAdd + "') AND (URI = '1')";

            try

            {

                DataTable dt_ExpDetails = BusinessLayer.SelectMaster.GetDataTable(Session["ConStr"].ToString(), sqlQuery);

                int expID = Convert.ToInt32(dt_ExpDetails.Rows[0][0].ToString());

                exDetails = new ExpDetails();

                exDetails.toXml(xmlPath, expID, ex.Message);

            }

            catch

            {
 

            }
 

            ScriptManager.RegisterClientScriptBlock(this, typeof(Page), "validationAlert", scriptText, true);

        }

       

    }

    //Check Options after it gets freezed

    private void checkoptions()

    {

        try

        {

            string p = Session["OptionId"].ToString();

            string opt = "select * from Admn_Course_Organization where Record_Type='OPT' and Course_Id='" + ddlCourse.SelectedValue + "' and Id='" + Session["OptionId"].ToString() + "' ";

            DataTable dt_opt = BusinessLayer.SelectMaster.GetDataTable(Session["ConStr"].ToString(), opt);

            if (dt_opt.Rows.Count > 0)

            {

                btnshow.Attributes.Add("onclick", "if(confirm('Are you sure you want to freeze the option..?')){}else{return false}");
 

            }

            else

            {

                btnshow.Attributes.Remove("onclick");

            }

        }

        catch (Exception ex)

        {

            scriptText = "window.alert('Sorry for inconvenience ,The data is not processed will get back to you soon');";

            Insert = new InsertMaster();

            Insert.DLInsert("Exception_Handling", "Module", "Training Center", "Page", "Trainer_Training.aspx.aspx", "Method", "checkoptions", "Client_IP", ClientIPAdd, "1");

            string sqlQuery = "SELECT MAX(Id) AS ID FROM Exception_Handling WHERE (Module = 'Training Center') AND (Page = 'Trainer_Training.aspx.aspx') AND";

            sqlQuery += " (Method = 'checkoptions') AND (Client_IP = '" + ClientIPAdd + "') AND (URI = '1')";

            try

            {

                DataTable dt_ExpDetails = BusinessLayer.SelectMaster.GetDataTable(Session["ConStr"].ToString(), sqlQuery);

                int expID = Convert.ToInt32(dt_ExpDetails.Rows[0][0].ToString());

                exDetails = new ExpDetails();

                exDetails.toXml(xmlPath, expID, ex.Message);

            }

            catch

            {
 

            }
 

            ScriptManager.RegisterClientScriptBlock(this, typeof(Page), "validationAlert", scriptText, true);

        }

    }

    //To Bind top level options before and after freeze

    public void checknodes()

    {

        try

        {

            SelectMaster SelectMaster = new SelectMaster();

            string qrynode = "select Parent_Id from Admn_Batch_Course_Structure where Parent_Id IS NULL and  Course_Id='" + ddlCourse.SelectedValue + "' and Batch_Id='" + ddlBatch.SelectedValue + "'";

            DataTable dt_nodes = BusinessLayer.SelectMaster.GetDataTable(Session["ConStr"].ToString(), qrynode);

            if (dt_nodes.Rows.Count > 0)

            {

                btnshow.Visible = true;

                btnshow.Enabled = true;

                btnshow.Text = "Show";

                ddl_Items.Visible = false;

                lbl_Options.Visible = false;

                Session["node_Exists"] = "noo";

                btnshow.Attributes.Remove("onclick");
 
 

            }

            else

            {

                btnshow.Visible = true;

                btnshow.Enabled = true;

                btnshow.Text = "Freeze";

                ddl_Items.Visible = true;

                lbl_Options.Visible = true;

                Session["node_Exists"] = "yes";

                BindItems();

            }

        }

        catch (Exception ex)

        {

            scriptText = "window.alert('Sorry for inconvenience ,The data is not processed will get back to you soon');";

            Insert = new InsertMaster();

            Insert.DLInsert("Exception_Handling", "Module", "Training Center", "Page", "Trainer_Training.aspx.aspx", "Method", "checknodes", "Client_IP", ClientIPAdd, "1");

            string sqlQuery = "SELECT MAX(Id) AS ID FROM Exception_Handling WHERE (Module = 'Training Center') AND (Page = 'Trainer_Training.aspx.aspx') AND";

            sqlQuery += " (Method = 'checknodes') AND (Client_IP = '" + ClientIPAdd + "') AND (URI = '1')";

            try

            {

                DataTable dt_ExpDetails = BusinessLayer.SelectMaster.GetDataTable(Session["ConStr"].ToString(), sqlQuery);

                int expID = Convert.ToInt32(dt_ExpDetails.Rows[0][0].ToString());

                exDetails = new ExpDetails();

                exDetails.toXml(xmlPath, expID, ex.Message);

            }

            catch

            {
 

            }
 

            ScriptManager.RegisterClientScriptBlock(this, typeof(Page), "validationAlert", scriptText, true);

        }

    }
 

    public void BindBatch()

    {

        SelectMaster SelectMaster = new SelectMaster();

        string batch = "SELECT Admn_Batch_Branch.Batch_Id, Admn_Batch_Mast.Batch_Name";

        batch += " FROM Admn_Batch_Branch INNER JOIN";

        batch += " Admn_Batch_Mast ON Admn_Batch_Branch.Batch_Id = Admn_Batch_Mast.Batch_Id";

        batch += " WHERE(Admn_Batch_Branch.Branch_Id =  '" + Session["Branch_Id"].ToString() + "' )";

         DataTable dt_Fill1 = BusinessLayer.SelectMaster.GetDataTable(Session["ConStr"].ToString(), batch);

        ddlBatch.DataSource = dt_Fill1;

        ddlBatch.DataTextField = dt_Fill1.Columns["Batch_Name"].ColumnName.ToString();

        ddlBatch.DataValueField = dt_Fill1.Columns["Batch_Id"].ColumnName.ToString();

        ddlBatch.DataBind();

        ddlBatch.Items.Add("-Select-");

        ddl_Items.Items.Add("-Select-");

        ddlCourse.Items.Add("-Select-");

        ddlBatch.SelectedIndex = ddlBatch.Items.Count - 1;

    }

    //Binding Options of Particular Course

    public void BindItems()

    {

       

        SelectMaster SelectMaster = new SelectMaster();

        string items = "select * from Admn_Course_Organization where Record_Type='OPT' and Course_Id='" + ddlCourse.SelectedValue + "' and Parent_Id IS NULL";

        DataTable dt_items = BusinessLayer.SelectMaster.GetDataTable(Session["ConStr"].ToString(), items);

        ddl_Items.DataSource = dt_items;

        ddl_Items.DataTextField = dt_items.Columns["Name"].ColumnName.ToString();

        ddl_Items.DataValueField = dt_items.Columns["Id"].ColumnName.ToString();

        ddl_Items.DataBind();

        ddl_Items.Items.Add("-Select-");

        ddl_Items.SelectedIndex = ddl_Items.Items.Count - 1;

               
 

    }

    

    public void BindCourse()

    {

        SelectMaster SelectMaster = new SelectMaster();

        string course = "SELECT Admn_Batch_Course.Course_Id, Admn_Internal_Course_Mast.Name";

        course += " FROM Admn_Batch_Course INNER JOIN";

        course += " Admn_Internal_Course_Mast ON Admn_Batch_Course.Course_Id = Admn_Internal_Course_Mast.Course_Id INNER JOIN";

        course += " Admn_Batch_Mast ON Admn_Batch_Course.Batch_Id = Admn_Batch_Mast.Batch_Id and Admn_Batch_Course.Batch_Id ='"+ddlBatch.SelectedValue+"' ";

        DataTable dt_Fill3 = BusinessLayer.SelectMaster.GetDataTable(Session["ConStr"].ToString(), course);

        ddlCourse.DataSource = dt_Fill3;

        ddlCourse.DataTextField = dt_Fill3.Columns["Name"].ColumnName.ToString();

        ddlCourse.DataValueField = dt_Fill3.Columns["Course_Id"].ColumnName.ToString();

        ddlCourse.DataBind();

        ddlCourse.Items.Add("-Select-");

        ddl_Items.Items.Add("-Select-");

        ddlCourse.SelectedIndex = ddlCourse.Items.Count - 1;

       
 
 

    }

   

    protected void ddlBatch_SelectedIndexChanged(object sender, EventArgs e)

    {

        if (ddlBatch.SelectedItem.Text == "-Select-")

        {

            ddlCourse.Items.Clear();

            ddlCourse.Items.Add("-Select-");
 

            ddl_Items.Items.Clear();

            ddl_Items.Items.Add("-Select-");

            TreeView1.Nodes.Clear();

            txtdesc.Visible = false;

            lbl_Result_Per.Text="";

        }

        else

        {

            lbl_Result_Per.Text="";

            TreeView1.Nodes.Clear();

            txtdesc.Visible = false;

            ddl_Items.Items.Clear();

            ddl_Items.SelectedIndex = ddl_Items.Items.Count - 1;

            Session["Batch_Id"] = ddlBatch.SelectedValue;

            Session["Batch_Name"] = ddlBatch.SelectedItem.Text;

            BindCourse();

            this.ScriptManager1.SetFocus(ddlCourse);

        }
 

    }

    protected void ddlCourse_SelectedIndexChanged(object sender, EventArgs e)

    {

        if (ddlCourse.SelectedItem.Text == "-Select-")

        {

            lbl_Result_Per.Text="";

            ddl_Items.Items.Clear();

            //ddl_Items.Items.Clear();

            ddl_Items.Items.Add("-Select-");

            ScriptManager.RegisterClientScriptBlock(this, typeof(Page), "ClientScript", "{debugger; alert('Select the course'); }", true);

            TreeView1.Nodes.Clear();

            txtdesc.Visible = false;

        }

        else

         {

            lbl_Result_Per.Text="";

            Session["Course_Id"] = ddlCourse.SelectedValue;

            Session["Course_Name"] = ddlCourse.SelectedItem.Text;

            TreeView1.Nodes.Clear();

            txtdesc.Visible = false;

            checknodes();

            this.ScriptManager1.SetFocus(btnshow);

        }

    }

    protected void ddl_Items_SelectedIndexChanged(object sender, EventArgs e)

    {

        

            if (ddl_Items.SelectedItem.Text == "-Select-")

            {

                TreeView1.Nodes.Clear();

                  lbl_Result_Per.Text="";

                ScriptManager.RegisterClientScriptBlock(this, typeof(Page), "ClientScript", "{debugger; alert('Select the item'); }", true);

            }

            else

             {

                lbl_Result_Per.Text="";

                TreeView1.Visible = true;

                string qry_desc = "select Description from Admn_Course_Organization where Id='" + ddl_Items.SelectedValue + "' and Record_Type='OPT'";

                DataTable dt_Description = BusinessLayer.SelectMaster.GetDataTable(Session["ConStr"].ToString(), qry_desc);
 

                string desc = dt_Description.Rows[0][0].ToString();

                if (desc.Equals(""))

                {

                    txtdesc.Visible = false;

                }

                else

                {

                    txtdesc.Visible = true;

                    txtdesc.Text = dt_Description.Rows[0][0].ToString();

                }

                btnshow.Enabled = true;
 

                Session["OptionId"] = ddl_Items.SelectedValue;
 

            }

            checkdata();

            if (Session["node_Exists"] == "N0")

            {

                checkoptions();

            }

            TreeView1.Visible = true;

    }      

    //Adding the root to the Tree View Control.

    public void Populateroot()

    {

        try

        {

            txtdesc.Text = "";
 

            string qry = "select Id,Name,(select count(*) FROM Admn_Course_Organization " + "WHERE Parent_Id=sc.Id) childnodecount FROM Admn_Course_Organization sc where Id='" + ddl_Items.SelectedValue + "' and Course_Id='" + ddlCourse.SelectedValue + "'  ";

            DataTable dt_Fill_TV = BusinessLayer.SelectMaster.GetDataTable(Session["ConStr"].ToString(), qry);

            PopulateNodes(dt_Fill_TV, TreeView1.Nodes);

        }
 

        catch (Exception ex)

        {

            scriptText = "window.alert('Sorry for inconvenience ,The data is not processed will get back to you soon');";

            Insert = new InsertMaster();

            Insert.DLInsert("Exception_Handling", "Module", "Training Center", "Page", "Trainer_Training.aspx.aspx", "Method", "Populateroot", "Client_IP", ClientIPAdd, "1");

            string sqlQuery = "SELECT MAX(Id) AS ID FROM Exception_Handling WHERE (Module = 'Training Center') AND (Page = 'Trainer_Training.aspx.aspx') AND";

            sqlQuery += " (Method = 'Populateroot') AND (Client_IP = '" + ClientIPAdd + "') AND (URI = '1')";

            try

            {

                DataTable dt_ExpDetails = BusinessLayer.SelectMaster.GetDataTable(Session["ConStr"].ToString(), sqlQuery);

                int expID = Convert.ToInt32(dt_ExpDetails.Rows[0][0].ToString());

                exDetails = new ExpDetails();

                exDetails.toXml(xmlPath, expID, ex.Message);

            }

            catch

            {
 

            }
 

            ScriptManager.RegisterClientScriptBlock(this, typeof(Page), "validationAlert", scriptText, true);

        }
 

           
 

    }

    //Adding Sub Options before and after freeze

    private void PopulateNodes(DataTable dt, TreeNodeCollection nodes)

    {

            foreach (DataRow dr in dt.Rows)

            {

                TreeNode tn = new TreeNode();

                tn.Text = dr["Name"].ToString();

                tn.Value = dr["Id"].ToString();

                nodes.Add(tn);

             

                //If node has child nodes, then enable on-demand populating

                tn.PopulateOnDemand = ((int)dr["childnodecount"] > 0);

            }

       

    }

    //Adding Sessions before Freezing

    private void PopulateSubLevel(int parentid, TreeNode parentNode)

    {

        
 

            SqlConnection con = new SqlConnection(Session["ConStr"].ToString());

            con.Open();

            SqlCommand cmd = new SqlCommand("select Id,Name,(select count(*) FROM Admn_Course_Organization " + "WHERE Parent_Id=sc.Id) childnodecount FROM Admn_Course_Organization sc where  Parent_Id=@Parent_Id and Course_Id='" + ddlCourse.SelectedValue + "' and Record_Type='SES'  order by Sort_Order", con);

            cmd.Parameters.Add("@Parent_Id", SqlDbType.Int).Value = parentid;

            DataSet ds = new DataSet();

            SqlDataAdapter da1 = new SqlDataAdapter(cmd);

            DataTable dt1 = new DataTable();

            da1.Fill(dt1);

            SqlDataAdapter da = new SqlDataAdapter(cmd);

            DataTable dt = new DataTable();

            da.Fill(dt);

            con.Close();
 
 

            string optcount = "select Id from Admn_Course_Organization where Parent_Id='" + ddl_Items.SelectedValue + "' and  Record_Type='OPT' ";

            DataTable dt_optcount = BusinessLayer.SelectMaster.GetDataTable(Session["ConStr"].ToString(), optcount);

            if (dt_optcount.Rows.Count > 0)

            {

                Session["Id"] = dt_optcount.Rows[0][0].ToString();

                nodecount = TreeView1.Nodes.Count;

                PopulateNodes(dt, parentNode.ChildNodes);

                nodenew = new TreeNode("Options");

                parentNode.ChildNodes.Add(nodenew);

                

            }

            else

            {

                PopulateNodes(dt, parentNode.ChildNodes);

            }

         
 

           

    }

    //Adding sessions after Freezing

    public void PopulateSubLevelAfterFreeze(int parentid, TreeNode parentNode)

    {

        try

        {

            lbl = new Label();

            lbl.Text = "";

             string qrynode = "select Option_Id from Admn_Batch_Course_Structure where  Course_Id='" + ddlCourse.SelectedValue + "' and Batch_Id='" + ddlBatch.SelectedValue + "' and Parent_Id IS NOT NULL";

                DataTable dt_nodes = BusinessLayer.SelectMaster.GetDataTable(Session["ConStr"].ToString(), qrynode);

                if (dt_nodes.Rows.Count > 0)

                {

                    for (int i = 0; i <= dt_nodes.Rows.Count - 1; i++)

                    {

                        OptionId = dt_nodes.Rows[i][0].ToString() + "," + OptionId;
 

                    }

                    int l = OptionId.Length;
 

                    OptionId = OptionId.Substring(0, l - 1);

                }
 

                SqlConnection con = new SqlConnection(Session["ConStr"].ToString());

                con.Open();

                string qry19 = "select Id,Name,(select count(*) FROM Admn_Course_Organization " + "WHERE Parent_Id=sc.Id) childnodecount from Admn_Course_Organization sc where Parent_Id=@Parent_Id and Record_Type='SES' order by Sort_Order";

                SqlCommand cmd = new SqlCommand(qry19, con);

                cmd.Parameters.Add("@Parent_Id", SqlDbType.Int).Value = parentid;

                //DataSet ds = new DataSet();

                //SqlDataAdapter da1 = new SqlDataAdapter(cmd);

                //DataTable dt1 = new DataTable();

                //da1.Fill(dt1);

                SqlDataAdapter da = new SqlDataAdapter(cmd);

                DataTable dt = new DataTable();

                da.Fill(dt);

               

                if (dt.Rows.Count == 0)

                {

                }

                else

                {

                    PopulateNodes(dt, parentNode.ChildNodes);

                }

                con.Close();

        }

        catch (Exception ex)

        {

            scriptText = "window.alert('Sorry for inconvenience ,The data is not processed will get back to you soon');";

            Insert = new InsertMaster();

            Insert.DLInsert("Exception_Handling", "Module", "Training Center", "Page", "Trainer_Training.aspx.aspx", "Method", "PopulateSubLevelAfterFreeze", "Client_IP", ClientIPAdd, "1");

            string sqlQuery = "SELECT MAX(Id) AS ID FROM Exception_Handling WHERE (Module = 'Training Center') AND (Page = 'Trainer_Training.aspx.aspx') AND";

            sqlQuery += " (Method = 'PopulateSubLevelAfterFreeze') AND (Client_IP = '" + ClientIPAdd + "') AND (URI = '1')";

            try

            {

                DataTable dt_ExpDetails = BusinessLayer.SelectMaster.GetDataTable(Session["ConStr"].ToString(), sqlQuery);

                int expID = Convert.ToInt32(dt_ExpDetails.Rows[0][0].ToString());

                exDetails = new ExpDetails();

                exDetails.toXml(xmlPath, expID, ex.Message);

            }

            catch

            {
 

            }
 

            ScriptManager.RegisterClientScriptBlock(this, typeof(Page), "validationAlert", scriptText, true);

        }

    }
 
 

    //TreeNode Populate before and after freezing

    protected void TreeView1_TreeNodePopulate(object sender, TreeNodeEventArgs e)

    {

       

            int a = Convert.ToInt32(e.Node.Value);

            if (Session["node_Exists"] == "noo")

            {

                PopulateSubLevelAfterFreeze(a, e.Node);

            }

            else

            {

                Int32 pid = Int32.Parse(ddl_Items.SelectedValue);
 
 

                string option_name = "select Record_Type from Admn_Course_Organization where Id='" + a.ToString() + "' and Parent_Id IS NOT NULL";

                DataTable dt_option_name = BusinessLayer.SelectMaster.GetDataTable(Session["ConStr"].ToString(), option_name);
 

                if (dt_option_name.Rows.Count > 0)

                {

                    if (dt_option_name.Rows[0][0].ToString().Equals("OPT") && pid != a)

                    {

                        TreeView1.Visible = true;

                        PopulateSubLevel(a, e.Node);

                    }

                }
 

                if (pid.Equals(a))

                {

                    TreeView1.Visible = true;

                    PopulateSubLevel(a, e.Node);

                }

                else

                {

                }
 

            }

        

    }

    //Freeze and Show Click

    protected void btnshow_Click(object sender, EventArgs e)

    {

        try

        {

            txtdesc.Visible = false;

            if (Session["node_Exists"] == "yes")

            {

                if (ddl_Items.SelectedItem.Text == "-Select-")

                {

                    string strMsg = "Select the option";

                    Label lbl = new Label();
 

                    lbl.Text = ("<script language=\'javascript\'>"
 

                    + (Environment.NewLine + ("window.alert(" + ("\'"

                    + (strMsg + ("\'" + ")</script>"))))));

                    Page.Controls.Add(lbl);

                }

                else

                {

                    btnshow.Text = "Freeze";

                    Insert = new InsertMaster();

                    Insert.DLInsert("Admn_Batch_Course_Structure", "Name", ddl_Items.SelectedItem.Text, "Batch_Id", ddlBatch.SelectedValue, "Course_Id", ddlCourse.SelectedValue, "Option_Id", ddl_Items.SelectedValue, Session["MURI"].ToString());

                    Session["count"] = "1";
 

                    Populateroot();

                    btnshow.Enabled = false;

                }
 

            }

            string s = Session["node_Exists"].ToString();

            if (Session["node_Exists"].ToString() == "N0")

            {

                btnshow.Text = "Freeze";

                if (ddl_Items.SelectedItem.Text == "-Select-")

                {

                    string strMsg = "Select the option";

                    Label lbl = new Label();
 

                    lbl.Text = ("<script language=\'javascript\'>"
 

                    + (Environment.NewLine + ("window.alert(" + ("\'"

                    + (strMsg + ("\'" + ")</script>"))))));

                    Page.Controls.Add(lbl);

                }

                else

                {

                    string qryname = "select Parent_Id from Admn_Course_Organization where Id='" + ddl_Items.SelectedValue + "'";

                    DataTable dt_qryname = BusinessLayer.SelectMaster.GetDataTable(Session["ConStr"].ToString(), qryname);

                    countparentid = dt_qryname.Rows[0][0].ToString();

                    Insert = new InsertMaster();

                    Insert.DLInsert("Admn_Batch_Course_Structure", "Name", ddl_Items.SelectedItem.Text, "Batch_Id", ddlBatch.SelectedValue, "Course_Id", ddlCourse.SelectedValue, "Parent_Id", dt_qryname.Rows[0][0].ToString(), "Option_Id", ddl_Items.SelectedValue,Session["MURI"].ToString());

                    Populateroot();

                    btnshow.Enabled = false;

                }

            }

            if (Session["node_Exists"].ToString() == "noo")

            {
 
 

                TreeView1.Nodes.Clear();

           

                PopulaterootAfterFreeze();

                btnshow.Enabled = false;

               

            }

            if (Session["node_Exists"].ToString() == "abc")

            {
 

                TreeView1.Visible = true;

                Populateroot();

                btnshow.Enabled = false;
 
 
 

            }

        }

        catch (Exception ex)

        {

            scriptText = "window.alert('Sorry for inconvenience ,The data is not processed will get back to you soon');";

            Insert = new InsertMaster();

            Insert.DLInsert("Exception_Handling", "Module", "Training Center", "Page", "Trainer_Training.aspx.aspx", "Method", "btnshow_Click", "Client_IP", ClientIPAdd, "1");

            string sqlQuery = "SELECT MAX(Id) AS ID FROM Exception_Handling WHERE (Module = 'Training Center') AND (Page = 'Trainer_Training.aspx.aspx') AND";

            sqlQuery += " (Method = 'btnshow_Click') AND (Client_IP = '" + ClientIPAdd + "') AND (URI = '1')";

            try

            {

                DataTable dt_ExpDetails = BusinessLayer.SelectMaster.GetDataTable(Session["ConStr"].ToString(), sqlQuery);

                int expID = Convert.ToInt32(dt_ExpDetails.Rows[0][0].ToString());

                exDetails = new ExpDetails();

                exDetails.toXml(xmlPath, expID, ex.Message);

            }

            catch

            {
 

            }
 

            ScriptManager.RegisterClientScriptBlock(this, typeof(Page), "validationAlert", scriptText, true);

        }

    }

    //Adding Root after Freeze to Treeview Control

    public void  PopulaterootAfterFreeze()

    {

        try

        {

            txtdesc.Text = "";

           

            SelectMaster SelectMaster = new SelectMaster();
 

            string root = "select Option_Id from Admn_Batch_Course_Structure where Parent_Id IS NULL and  Course_Id='" + ddlCourse.SelectedValue + "' and Batch_Id='" + ddlBatch.SelectedValue + "'";

            DataTable dt_root = BusinessLayer.SelectMaster.GetDataTable(Session["ConStr"].ToString(), root);
 

            string qrynode = "select Option_Id from Admn_Batch_Course_Structure where  Course_Id='" + ddlCourse.SelectedValue + "' and Batch_Id='" + ddlBatch.SelectedValue + "'";

            DataTable dt_nodes = BusinessLayer.SelectMaster.GetDataTable(Session["ConStr"].ToString(), qrynode);

            if (dt_nodes.Rows.Count > 0)

            {

                for (int i = 0; i <= dt_nodes.Rows.Count - 1; i++)

                {

                    OptionId = dt_nodes.Rows[i][0].ToString() + "," + OptionId;
 

                }

                int l = OptionId.Length;
 

               OptionId  = OptionId.Substring(0, l - 1);

               // OptionId = OptionId.Substring(0, OptionId.LastIndexOf(','));

               string qry = "select Id,Name,(select count(*) FROM Admn_Course_Organization " + "WHERE Parent_Id=sc.Id) childnodecount FROM Admn_Course_Organization sc where (Id IN(" +OptionId + "))";

                DataTable dt_Fill_TV = BusinessLayer.SelectMaster.GetDataTable(Session["ConStr"].ToString(), qry);

               PopulateNodes(dt_Fill_TV, TreeView1.Nodes);

            }

        }

        catch (Exception ex)

        {

            scriptText = "window.alert('Sorry for inconvenience ,The data is not processed will get back to you soon');";

            Insert = new InsertMaster();

            Insert.DLInsert("Exception_Handling", "Module", "Training Center", "Page", "Trainer_Training.aspx.aspx", "Method", "PopulaterootAfterFreeze", "Client_IP", ClientIPAdd, "1");

            string sqlQuery = "SELECT MAX(Id) AS ID FROM Exception_Handling WHERE (Module = 'Training Center') AND (Page = 'Trainer_Training.aspx.aspx') AND";

            sqlQuery += " (Method = 'PopulaterootAfterFreeze') AND (Client_IP = '" + ClientIPAdd + "') AND (URI = '1')";

            try

            {

                DataTable dt_ExpDetails = BusinessLayer.SelectMaster.GetDataTable(Session["ConStr"].ToString(), sqlQuery);

                int expID = Convert.ToInt32(dt_ExpDetails.Rows[0][0].ToString());

                exDetails = new ExpDetails();

                exDetails.toXml(xmlPath, expID, ex.Message);

            }

            catch

            {
 

            }
 

            ScriptManager.RegisterClientScriptBlock(this, typeof(Page), "validationAlert", scriptText, true);

        }
 

    }

    protected void TreeView1_SelectedNodeChanged(object sender, EventArgs e)

    {

        TreeView1.Visible = true;

              

            if (TreeView1.SelectedNode.Text == "Options")

            {
 

                TreeView1.Visible = true;

                if (Session["count"] == "1")

                {

                    btn_att.Visible = false;

                    SelectMaster SelectMaster = new SelectMaster();

                    Session["node_Exists"] = "N0";

                    string opt = "select * from Admn_Course_Organization where Record_Type='OPT' and Course_Id='" + ddlCourse.SelectedValue + "' and Parent_Id='" + Session["OptionId"].ToString() + "' ";

                    DataTable dt_opt = BusinessLayer.SelectMaster.GetDataTable(Session["ConStr"].ToString(), opt);

                    ddl_Items.Items.Clear();

                    ddl_Items.DataSource = dt_opt;

                    ddl_Items.DataTextField = dt_opt.Columns["Name"].ColumnName.ToString();

                    ddl_Items.DataValueField = dt_opt.Columns["Id"].ColumnName.ToString();

                    ddl_Items.DataBind();
 

                    ddl_Items.Items.Add("-Select-");

                    ddl_Items.SelectedIndex = ddl_Items.Items.Count - 1;

                    btnshow.Enabled = true;
 
 

                }
 

                if (Session["count"] != "1")

                {

                    btn_att.Visible = false;

                    Session["node_Exists"] = "abc";

                    ddl_Items.Items.Clear();

                    string opt = "select  Option_Id,Name  from Admn_Batch_Course_Structure  where  Course_Id='" + ddlCourse.SelectedValue + "' and Batch_Id='" + ddlBatch.SelectedValue + "' and Parent_Id IS NOT NULL ";

                    DataTable dt_opt = BusinessLayer.SelectMaster.GetDataTable(Session["ConStr"].ToString(), opt);

                    // ddl_Items.Items.Clear();

                    ddl_Items.DataSource = dt_opt;

                    ddl_Items.DataTextField = dt_opt.Columns["Name"].ColumnName.ToString();

                    ddl_Items.DataValueField = dt_opt.Columns["Option_Id"].ColumnName.ToString();

                    ddl_Items.DataBind();
 

                    ddl_Items.Items.Add("-Select-");

                    ddl_Items.SelectedIndex = ddl_Items.Items.Count - 1;

                    btnshow.Enabled = true;

                }
 
 

            }

            if (Session["node_Exists"] == "noo" && Session["refresh2"] != "yes")

            

            {

                SessionResult();

                //content();

              
 

            }

    }

    public void NextSession()

    {

        string Status = "select  Status  from Stu_Exam_Course_Status where  Batch_Id='"+ddlBatch.SelectedValue+"' and Course_Id='" + ddlCourse.SelectedValue + "'  and Session_Id ='" + TreeView1.SelectedNode.Value + "' ";

        DataTable dt_Status = BusinessLayer.SelectMaster.GetDataTable(Session["ConStr"].ToString(), Status);

        if (dt_Status.Rows.Count > 0)

        {

             session_status = dt_Status.Rows[0][0].ToString();

        }
 
 

        string parent = "select  Parent_Id  from Admn_Course_Organization where  Course_Id='" + ddlCourse.SelectedValue + "'  and Id ='" + TreeView1.SelectedNode.Value + "' ";

        DataTable dt_parent = BusinessLayer.SelectMaster.GetDataTable(Session["ConStr"].ToString(), parent);

        string root = "select  Parent_Id  from Admn_Course_Organization  where Id='" + dt_parent.Rows[0][0].ToString() + "'";

        DataTable dt_root = BusinessLayer.SelectMaster.GetDataTable(Session["ConStr"].ToString(), root);
 

     

        if (dt_root.Rows[0][0].ToString() != (""))

        {

            string sessCount = "select Count(*) from Admn_Course_Organization  where  Record_Type='SES' and Parent_Id='" + dt_root.Rows[0][0].ToString() + "'";

            DataTable dt_sessCount = BusinessLayer.SelectMaster.GetDataTable(Session["ConStr"].ToString(), sessCount);

            Int32 totsesscount = Int32.Parse(dt_sessCount.Rows[0][0].ToString());

            string sessCountComp = "select ecs.Status from Admn_Course_Organization aco,Stu_Exam_Course_Status ecs where aco.Id=ecs.Session_Id and aco.Record_Type='SES' and aco.Parent_Id='" + dt_root.Rows[0][0].ToString() + "' and ecs.Status='Y' ";

            DataTable dt_sessCountComp = BusinessLayer.SelectMaster.GetDataTable(Session["ConStr"].ToString(), sessCountComp);

            if (totsesscount == dt_sessCountComp.Rows.Count)

            {

                string sessCount2 = "select Count(*) from Admn_Course_Organization  where  Record_Type='SES' and Parent_Id='" + dt_parent.Rows[0][0].ToString() + "'";

                DataTable dt_sessCount2 = BusinessLayer.SelectMaster.GetDataTable(Session["ConStr"].ToString(), sessCount2);

                Int32 totsesscount2 = Int32.Parse(dt_sessCount2.Rows[0][0].ToString());

                string sessCountComp2 = "select ecs.Status from Admn_Course_Organization aco,Stu_Exam_Course_Status ecs where aco.Id=ecs.Session_Id and aco.Record_Type='SES' and aco.Parent_Id='" + dt_parent.Rows[0][0].ToString() + "' and ecs.Status='Y' ";

                DataTable dt_sessCountComp2 = BusinessLayer.SelectMaster.GetDataTable(Session["ConStr"].ToString(), sessCountComp2);
 

                if (totsesscount2 != dt_sessCountComp2.Rows.Count && dt_sessCountComp2.Rows.Count == 0)

                {

                    string min = "select Min(Sort_Order)  from Admn_Course_Organization  where Record_Type='SES' and Parent_Id='" + dt_parent.Rows[0][0].ToString() + "' ";

                       DataTable dt_min = BusinessLayer.SelectMaster.GetDataTable(Session["ConStr"].ToString(), min);

                    string Sort = "select Name  from Admn_Course_Organization  where Record_Type='SES' and Parent_Id='" + dt_parent.Rows[0][0].ToString() + "' and Sort_Order='"+ dt_min.Rows[0][0].ToString()+"' group by Name";

                    DataTable dt_Sort = BusinessLayer.SelectMaster.GetDataTable(Session["ConStr"].ToString(), Sort);

                     nextsessionname = dt_Sort.Rows[0][0].ToString();

                }

                if (totsesscount2 != dt_sessCountComp2.Rows.Count && dt_sessCountComp2.Rows.Count > 0)

                {

                    string max = "Select  Max(Id) from Stu_Exam_Course_Status where Status='Y'and Batch_Id='" + ddlBatch.SelectedValue + "' and Course_Id='" + ddlCourse.SelectedValue + "'";

                    DataTable dt_max = BusinessLayer.SelectMaster.GetDataTable(Session["ConStr"].ToString(), max);

                    string details = "Select  Session_Id from Stu_Exam_Course_Status where Status='Y'and Batch_Id='" + ddlBatch.SelectedValue + "' and Course_Id='" + ddlCourse.SelectedValue + "' and Id='" + dt_max.Rows[0][0].ToString() + "'";

                    DataTable dt_details = BusinessLayer.SelectMaster.GetDataTable(Session["ConStr"].ToString(), details);
 

                    string next = "Select Sort_Order from Admn_Course_Organization where Course_Id='" + ddlCourse.SelectedValue + "'and  Record_Type='SES' and Id='" + dt_details.Rows[0][0].ToString() + "'";

                      DataTable dt_next = BusinessLayer.SelectMaster.GetDataTable(Session["ConStr"].ToString(), next);

                      string nextsesorder = dt_next.Rows[0][0].ToString();

                      Int32 nextsess = Int32.Parse(nextsesorder)+1;

                      string nextsessName = "Select Name,Id from Admn_Course_Organization where Course_Id='" + ddlCourse.SelectedValue + "' and Record_Type='SES' and Sort_Order='" + nextsess + "'and Parent_Id='"+dt_parent.Rows[0][0].ToString()+"'";

                        DataTable dt_nextsessName = BusinessLayer.SelectMaster.GetDataTable(Session["ConStr"].ToString(), nextsessName);

                        nextsessionname = dt_nextsessName.Rows[0][0].ToString();
 

                }
 

            }

            if (totsesscount != dt_sessCountComp.Rows.Count &&  dt_sessCountComp.Rows.Count>0)

            {

                string max = "Select  Max(Id) from Stu_Exam_Course_Status where Status='Y'and Batch_Id='" + ddlBatch.SelectedValue + "' and Course_Id='" + ddlCourse.SelectedValue + "'";

                DataTable dt_max = BusinessLayer.SelectMaster.GetDataTable(Session["ConStr"].ToString(), max);

                string details = "Select  Session_Id from Stu_Exam_Course_Status where Status='Y'and Batch_Id='" + ddlBatch.SelectedValue + "' and Course_Id='" + ddlCourse.SelectedValue + "' and Id='" + dt_max.Rows[0][0].ToString() + "'";

                DataTable dt_details = BusinessLayer.SelectMaster.GetDataTable(Session["ConStr"].ToString(), details);

                

                string next = "Select Sort_Order from Admn_Course_Organization where Course_Id='" + ddlCourse.SelectedValue + "'and  Record_Type='SES' and Id='" + dt_details.Rows[0][0].ToString() + "'";

                DataTable dt_next = BusinessLayer.SelectMaster.GetDataTable(Session["ConStr"].ToString(), next);

                string nextsesorder = dt_next.Rows[0][0].ToString();

                Int32 nextsess = Int32.Parse(nextsesorder) + 1;

                string nextsessName = "Select Name,Id from Admn_Course_Organization where Course_Id='" + ddlCourse.SelectedValue + "' and Record_Type='SES' and Sort_Order='" + nextsess + "'and Parent_Id='" + dt_root.Rows[0][0].ToString() + "'";

                DataTable dt_nextsessName = BusinessLayer.SelectMaster.GetDataTable(Session["ConStr"].ToString(), nextsessName);

              nextsessionname = dt_nextsessName.Rows[0][0].ToString();
 
 

            }

            if (totsesscount != dt_sessCountComp.Rows.Count && dt_sessCountComp.Rows.Count == 0)

            {

                string min = "select Min(Sort_Order)  from Admn_Course_Organization  where Record_Type='SES' and Parent_Id='" + dt_root.Rows[0][0].ToString() + "' ";

                DataTable dt_min = BusinessLayer.SelectMaster.GetDataTable(Session["ConStr"].ToString(), min);

                string Sort = "select Name  from Admn_Course_Organization  where Record_Type='SES' and Parent_Id='" + dt_root.Rows[0][0].ToString() + "' and Sort_Order='" + dt_min.Rows[0][0].ToString() + "' group by Name";

                DataTable dt_Sort = BusinessLayer.SelectMaster.GetDataTable(Session["ConStr"].ToString(), Sort);
 

                nextsessionname = dt_Sort.Rows[0][0].ToString();

            }

        }

        if (dt_root.Rows[0][0].ToString().Equals(""))

        {
 

            string sessCount = "select Count(*) from Admn_Course_Organization  where  Record_Type='SES' and Parent_Id='" + dt_parent.Rows[0][0].ToString() + "'";

            DataTable dt_sessCount = BusinessLayer.SelectMaster.GetDataTable(Session["ConStr"].ToString(), sessCount);

            Int32 totsesscount = Int32.Parse(dt_sessCount.Rows[0][0].ToString());

            string sessCountComp = "select ecs.Status from Admn_Course_Organization aco,Stu_Exam_Course_Status ecs where aco.Id=ecs.Session_Id and aco.Record_Type='SES' and aco.Parent_Id='" + dt_parent.Rows[0][0].ToString() + "' and ecs.Status='Y' ";

            DataTable dt_sessCountComp = BusinessLayer.SelectMaster.GetDataTable(Session["ConStr"].ToString(), sessCountComp);

            if (totsesscount == dt_sessCountComp.Rows.Count)

            {

                flagcheck = 3;

               

            }

            if (totsesscount != dt_sessCountComp.Rows.Count && dt_sessCountComp.Rows.Count==0)

            {

                string min = "select Min(Sort_Order)  from Admn_Course_Organization  where Record_Type='SES' and Parent_Id='" + dt_parent.Rows[0][0].ToString() + "' ";

                DataTable dt_min = BusinessLayer.SelectMaster.GetDataTable(Session["ConStr"].ToString(), min);

                string Sort = "select Name  from Admn_Course_Organization  where Record_Type='SES' and Parent_Id='" + dt_parent.Rows[0][0].ToString() + "' and Sort_Order='" + dt_min.Rows[0][0].ToString() + "' group by Name";

                DataTable dt_Sort = BusinessLayer.SelectMaster.GetDataTable(Session["ConStr"].ToString(), Sort);

               

                 nextsessionname = dt_Sort.Rows[0][0].ToString();

            }

            if (totsesscount != dt_sessCountComp.Rows.Count && dt_sessCountComp.Rows.Count>0)

            {

                string max = "Select  Max(Id) from Stu_Exam_Course_Status where Status='Y'and Batch_Id='" + ddlBatch.SelectedValue + "' and Course_Id='" + ddlCourse.SelectedValue + "'";

                DataTable dt_max = BusinessLayer.SelectMaster.GetDataTable(Session["ConStr"].ToString(), max);

                string details = "Select  Session_Id from Stu_Exam_Course_Status where Status='Y'and Batch_Id='"+ddlBatch.SelectedValue+"' and Course_Id='"+ddlCourse.SelectedValue+"' and Id='"+dt_max.Rows[0][0].ToString()+"'";

                DataTable dt_details = BusinessLayer.SelectMaster.GetDataTable(Session["ConStr"].ToString(), details);

                string next = "Select Sort_Order from Admn_Course_Organization where Course_Id='" + ddlCourse.SelectedValue + "'and  Record_Type='SES' and Id='" + dt_details.Rows[0][0].ToString() + "'";

                DataTable dt_next = BusinessLayer.SelectMaster.GetDataTable(Session["ConStr"].ToString(), next);

                string nextsesorder = dt_next.Rows[0][0].ToString();

                Int32 nextsess = Int32.Parse(nextsesorder) + 1;

                string nextsessName = "Select Name,Id from Admn_Course_Organization where Course_Id='" + ddlCourse.SelectedValue + "' and Record_Type='SES' and Sort_Order='" + nextsess + "'and Parent_Id='" + dt_parent.Rows[0][0].ToString() + "'";

                DataTable dt_nextsessName = BusinessLayer.SelectMaster.GetDataTable(Session["ConStr"].ToString(), nextsessName);

               nextsessionname = dt_nextsessName.Rows[0][0].ToString();
 
 

            }

        }
 

    }
 

    //After attendance

    public void content()

    {

        try

        {

            if (Session["refresh2"] != "yes" && Session["Result_Percentage"] == null)

            {

                string date = DateTime.Now.ToString();

              

                string qry7 = "select Session_Id from Stu_Attendance_Mast where Session_Id='" + TreeView1.SelectedNode.Value + "'";

                DataTable dt_sessAtt = BusinessLayer.SelectMaster.GetDataTable(Session["ConStr"].ToString(), qry7);
 

                string qry8 = "select Record_Type from Admn_Course_Organization where Id='" + TreeView1.SelectedNode.Value + "'";

                DataTable dt_type = BusinessLayer.SelectMaster.GetDataTable(Session["ConStr"].ToString(), qry8);
 

                string Status = "select  Status  from Stu_Exam_Course_Status where  Batch_Id='" + ddlBatch.SelectedValue + "' and Course_Id='" + ddlCourse.SelectedValue + "'  and Session_Id ='" + TreeView1.SelectedNode.Value + "' ";

                DataTable dt_Status = BusinessLayer.SelectMaster.GetDataTable(Session["ConStr"].ToString(), Status);

                if (dt_Status.Rows.Count > 0)

                {

                    session_status = dt_Status.Rows[0][0].ToString();

                    flagcheck = 4;

                }

               

                    NextSession();

                

              
 

                string selectedid = TreeView1.SelectedNode.Value;

                string selectedname = TreeView1.SelectedNode.Text;
 

                Session["Session_id"] = TreeView1.SelectedNode.Value;

                Session["Session_Name"] = TreeView1.SelectedNode.Text;
 

                if (Session["percentage"] == null)

                {

                    

                        if (flagcheck == 2 && dt_type.Rows[0][0].ToString().Equals("SES") && nextsessionname == selectedname)

                        {

                            lbl_Result_Per.Text = "";

                            Session["Session_id"] = TreeView1.SelectedNode.Value;

                            btn_att.Visible = true;

                            Session["Session_Name"] = TreeView1.SelectedNode.Text;

                            string strMsg = "Take attendance";

                            Label lbl = new Label();
 

                            lbl.Text = ("<script language=\'javascript\'>"
 

                            + (Environment.NewLine + ("window.alert(" + ("\'"

                            + (strMsg + ("\'" + ")</script>"))))));

                            Page.Controls.Add(lbl);

                            //ScriptManager.RegisterClientScriptBlock(this, typeof(Page), "ClientScript", "{debugger; alert('Take attendance'); }", true);

                        }

                        if (dt_type.Rows[0][0].ToString().Equals("SES") && nextsessionname == selectedname)

                        {

                            lbl_Result_Per.Text = "";

                            Session["Session_id"] = TreeView1.SelectedNode.Value;

                            btn_att.Visible = true;

                            Session["Session_Name"] = TreeView1.SelectedNode.Text;

                            string strMsg = "Take attendance";

                            Label lbl = new Label();
 

                            lbl.Text = ("<script language=\'javascript\'>"
 

                            + (Environment.NewLine + ("window.alert(" + ("\'"

                            + (strMsg + ("\'" + ")</script>"))))));

                            Page.Controls.Add(lbl);

                            Session["Attendance"] = "no";

                            // ScriptManager.RegisterClientScriptBlock(this, typeof(Page), "ClientScript", "{debugger; alert('Take attendance'); }", true);

                        }

                        if (dt_type.Rows[0][0].ToString().Equals("SES") && nextsessionname != selectedname && session_status!="Y" )

                        {

                            lbl_Result_Per.Text = "";

                            Session["Session_id"] = TreeView1.SelectedNode.Value;

                            btn_att.Visible = false; ;

                            Session["Session_Name"] = TreeView1.SelectedNode.Text;

                            string strMsg = "Cannot take this session,complete the above session first";

                            Label lbl = new Label();
 

                            lbl.Text = ("<script language=\'javascript\'>"
 

                            + (Environment.NewLine + ("window.alert(" + ("\'"

                            + (strMsg + ("\'" + ")</script>"))))));

                            Page.Controls.Add(lbl);

                            //ScriptManager.RegisterClientScriptBlock(this, typeof(Page), "ClientScript", "{debugger; alert('Cannot take this session,complete the above session first'); }", true);

                        }

                    

                    if (dt_Status.Rows.Count > 0)

                    {

                        if (dt_type.Rows[0][0].ToString().Equals("SES") && session_status.Equals("Y") && flagcheck == 4)

                        {

                            btn_att.Visible = false;

                            string strMsg = "Already completed the session";

                            Label lbl = new Label();
 

                            lbl.Text = ("<script language=\'javascript\'>"
 

                            + (Environment.NewLine + ("window.alert(" + ("\'"

                            + (strMsg + ("\'" + ")</script>"))))));

                            Page.Controls.Add(lbl);

                            string result_per1 = Session["Result_Per"].ToString();

                            float pr11 = float.Parse(result_per1);

                            lbl_Result_Per.Visible = true;

                            //"Attendance submitted!<br><br>Total No of students:&nbsp;<b>" + total + "<br>No of students present:&nbsp;<b>" + countp + "<br>No of students absent:&nbsp;<b>" + counta + "<br>Present Percentage:&nbsp;<b>" + per + "";

                            lbl_Result_Per.Text = "Result for <b>'" + TreeView1.SelectedNode.Text + "' :&nbsp;<b>" + pr11 + "";

                          

                            //lbl_Result_Per.Text = "";
 

                        }

                      
 

                        if (dt_type.Rows[0][0].ToString().Equals("SES") && session_status.Equals("Y") && flagcheck == 3)

                        {

                            lbl_Result_Per.Text = "";

                            btn_att.Visible = false;

                            string strMsg = "Already completed the session";

                            Label lbl = new Label();
 

                            lbl.Text = ("<script language=\'javascript\'>"
 

                            + (Environment.NewLine + ("window.alert(" + ("\'"

                            + (strMsg + ("\'" + ")</script>"))))));

                            Page.Controls.Add(lbl);

                            string result_per1 = Session["Result_Per"].ToString();

                            float pr11 = float.Parse(result_per1);

                            lbl_Result_Per.Visible = true;

                            //"Attendance submitted!<br><br>Total No of students:&nbsp;<b>" + total + "<br>No of students present:&nbsp;<b>" + countp + "<br>No of students absent:&nbsp;<b>" + counta + "<br>Present Percentage:&nbsp;<b>" + per + "";

                            lbl_Result_Per.Text = "Result for <b>'" + TreeView1.SelectedNode.Text + "' :&nbsp;<b>" + pr11 + "";

                           

                           // lbl_Result_Per.Text = "";

                            //ScriptManager.RegisterClientScriptBlock(this, typeof(Page), "ClientScript", "{debugger; alert('Already completed the session'); }", true);

                        }

                    }
 

                }

            

                if (Session["Result_Percentage"] == null && Session["percentage"] != null)

                {

                    string node = TreeView1.SelectedNode.Value;

                    SelectMaster SelectMaster = new SelectMaster();

                    string qry = "select Content_Id from Admn_Course_Organization where Id='" + TreeView1.SelectedNode.Value + "'";

                    DataTable dt_Fill_TV = BusinessLayer.SelectMaster.GetDataTable(Session["ConStr"].ToString(), qry);

                    string cid = dt_Fill_TV.Rows[0][0].ToString();
 

                    string qry1 = "select File_Path  from Admn_Content_Mast where Id='" + cid.ToString() + "'";

                    DataTable dt_Fill_TV1 = BusinessLayer.SelectMaster.GetDataTable(Session["ConStr"].ToString(), qry1);

                    string path = dt_Fill_TV1.Rows[0][0].ToString();
 

                    string strPath = Server.MapPath("..\\Head_Office_Content") + "\\" + path.ToString();

                    Session["path"] = strPath;
 
 

                    Session["Session_id"] = TreeView1.SelectedNode.Value;

                    Session["Session_Name"] = TreeView1.SelectedNode.Text;
 

                    string pr = Session["percentage"].ToString();

                    string id = Session["Session_id"].ToString();

                    string dd = Session["Session_Date"].ToString();

                    Int32 value = Int32.Parse(id);
 
 

                    float pr1 = float.Parse(pr);

                    string qrytype = "select Record_Type from Admn_Course_Organization where Id='" + TreeView1.SelectedNode.Value + "'";

                    DataTable dt_type1 = BusinessLayer.SelectMaster.GetDataTable(Session["ConStr"].ToString(), qrytype);
 

                    string SName = TreeView1.SelectedNode.Text;

                    string sessionName = Session["S_Name"].ToString();
 

                    if (pr1 >= 60)

                    {

                        if (flagcheck == 2 && dt_type1.Rows[0][0].ToString().Equals("SES")  && nextsessionname == selectedname)

                        {

                            btn_Exam.Visible = true;

                            //System.Diagnostics.Process myProcess = new System.Diagnostics.Process();

                            //myProcess.EnableRaisingEvents = false;

                            //myProcess.StartInfo.FileName = strPath;

                            //myProcess.Start();

                            Session["refresh"] = "no";

                           // Session.Remove("refresh");
 

                        }
 

                        if (dt_type1.Rows[0][0].ToString().Equals("SES") && SName == sessionName)

                        {

                            btn_Exam.Visible = true;

                            //System.Diagnostics.Process myProcess = new System.Diagnostics.Process();

                            //myProcess.EnableRaisingEvents = false;

                            //myProcess.StartInfo.FileName = strPath;

                            //myProcess.Start();

                            Session["refresh"] = "no";

                            btn_Exam.Visible = true;

                        }

                        

                        if (dt_sessAtt.Rows.Count == 0 && dt_type.Rows[0][0].ToString().Equals("SES")  && SName != sessionName && SName != nextsessionname)

                        {

                            lbl_Result_Per.Text = "";

                             btn_Exam.Visible = false;

                            string strMsg = "The above session is not yet completed";

                            Label lbl = new Label();
 

                            lbl.Text = ("<script language=\'javascript\'>"
 

                            + (Environment.NewLine + ("window.alert(" + ("\'"

                            + (strMsg + ("\'" + ")</script>"))))));

                            Page.Controls.Add(lbl);

                            //ScriptManager.RegisterClientScriptBlock(this, typeof(Page), "ClientScript", "{debugger; alert('The above session is not yet completed'); }", true);

                        }

                        if (dt_Status.Rows.Count > 0)

                        {

                            if (dt_type.Rows[0][0].ToString().Equals("SES") && session_status.Equals("Y") && SName != sessionName)

                            {

                                btn_Exam.Visible = false;

                                string strMsg = "You have already completed the session";

                                Label lbl = new Label();
 

                                lbl.Text = ("<script language=\'javascript\'>"
 

                                + (Environment.NewLine + ("window.alert(" + ("\'"

                                + (strMsg + ("\'" + ")</script>"))))));

                                Page.Controls.Add(lbl);

                                //ScriptManager.RegisterClientScriptBlock(this, typeof(Page), "ClientScript", "{debugger; alert('You have already completed the session'); }", true);

                            }

                        }
 

                    }

                    if (pr1 < 60)

                    {

                        if (dt_sessAtt.Rows.Count == 0 && dt_type1.Rows[0][0].ToString().Equals("SES") && SName == sessionName)

                        {

                            string strMsg = "Unable to view the contents as class attendance is less than 60%";

                            Label lbl = new Label();
 

                            lbl.Text = ("<script language=\'javascript\'>"
 

                            + (Environment.NewLine + ("window.alert(" + ("\'"

                            + (strMsg + ("\'" + ")</script>"))))));

                            Page.Controls.Add(lbl);

                           // ScriptManager.RegisterClientScriptBlock(this, typeof(Page), "ClientScript", "{debugger; alert('Unable to view the contents as class attendance is less than 60%'); }", true);

                        }
 

                       

                        if (dt_Status.Rows.Count > 0)

                        {

                            if (dt_type.Rows[0][0].ToString().Equals("SES") && session_status.Equals("Y"))

                            {

                                string strMsg = "You have already completed the session";

                                Label lbl = new Label();
 

                                lbl.Text = ("<script language=\'javascript\'>"
 

                                + (Environment.NewLine + ("window.alert(" + ("\'"

                                + (strMsg + ("\'" + ")</script>"))))));

                                Page.Controls.Add(lbl);

                                // ScriptManager.RegisterClientScriptBlock(this, typeof(Page), "ClientScript", "{debugger; alert('You have already completed the session'); }", true);

                            }

                        }

                        if (dt_sessAtt.Rows.Count == 0 && dt_type.Rows[0][0].ToString().Equals("SES")  && SName != sessionName && SName != nextsessionname)

                        {

                            lbl_Result_Per.Text = "";

                            string strMsg = "The above session is not yet completed";

                            Label lbl = new Label();
 

                            lbl.Text = ("<script language=\'javascript\'>"
 

                            + (Environment.NewLine + ("window.alert(" + ("\'"

                            + (strMsg + ("\'" + ")</script>"))))));

                            Page.Controls.Add(lbl);

                            //ScriptManager.RegisterClientScriptBlock(this, typeof(Page), "ClientScript", "{debugger; alert('The above session is not yet completed'); }", true);

                        }
 

                    }
 
 
 

                }

            }

        }

        catch (Exception ex)

        {

            scriptText = "window.alert('Sorry for inconvenience ,The data is not processed will get back to you soon');";

            Insert = new InsertMaster();

            Insert.DLInsert("Exception_Handling", "Module", "Training Center", "Page", "Trainer_Training.aspx.aspx", "Method", "content", "Client_IP", ClientIPAdd, "1");

            string sqlQuery = "SELECT MAX(Id) AS ID FROM Exception_Handling WHERE (Module = 'Training Center') AND (Page = 'Trainer_Training.aspx.aspx') AND";

            sqlQuery += " (Method = 'content') AND (Client_IP = '" + ClientIPAdd + "') AND (URI = '1')";

            try

            {

                DataTable dt_ExpDetails = BusinessLayer.SelectMaster.GetDataTable(Session["ConStr"].ToString(), sqlQuery);

                int expID = Convert.ToInt32(dt_ExpDetails.Rows[0][0].ToString());

                exDetails = new ExpDetails();

                exDetails.toXml(xmlPath, expID, ex.Message);

            }

            catch

            {
 

            }
 

            ScriptManager.RegisterClientScriptBlock(this, typeof(Page), "validationAlert", scriptText, true);

        }

      

    }

    //After Scheduling Exam

    public void content2()

    {

        try

        {
 

            NextSession();

            if (flagcheck == 8)

            {

                string Status = "select  Status  from Stu_Exam_Course_Status where  Batch_Id='" + ddlBatch.SelectedValue + "' and Course_Id='" + ddlCourse.SelectedValue + "'  and Session_Id ='" + TreeView1.SelectedNode.Value + "' ";

                DataTable dt_Status = BusinessLayer.SelectMaster.GetDataTable(Session["ConStr"].ToString(), Status);

                if (dt_Status.Rows.Count > 0)

                {

                    session_status = dt_Status.Rows[0][0].ToString();

                    

                }

                string qry9 = "select Record_Type from Admn_Course_Organization where Id='" + TreeView1.SelectedNode.Value + "'";

                DataTable dt_type2 = BusinessLayer.SelectMaster.GetDataTable(Session["ConStr"].ToString(), qry9);
 

                string sid1 = TreeView1.SelectedNode.Value;

                string sname1 = TreeView1.SelectedNode.Text;

                string id = Session["Sess_Id"].ToString();

                sname2 = Session["SessionName"].ToString();

                string ename = Session["Sess_Name"].ToString();

                string date1 = Session["Sess_Date"].ToString();

                string date2 = DateTime.Now.ToString();

                string qrysid = "select Session_Id from Stu_Attendance_Mast where Session_Id='" + TreeView1.SelectedNode.Value + "'";

                DataTable dt_sid3 = BusinessLayer.SelectMaster.GetDataTable(Session["ConStr"].ToString(), qrysid);

               

                if (dt_type2.Rows[0][0].ToString().Equals("SES") && sname1 != sname2 && sname1 != nextsessionname)

                {

                    lbl_Result_Per.Text = "";

                    btn_att.Visible = false;

                    btn_Exam.Visible = false;

                    string strMsg = "Cannot take this session unless you complete the prevoius one";

                     lbl = new Label();
 

                    lbl.Text = ("<script language=\'javascript\'>"
 

                    + (Environment.NewLine + ("window.alert(" + ("\'"

                    + (strMsg + ("\'" + ")</script>"))))));

                    Page.Controls.Add(lbl);

                    //ScriptManager.RegisterClientScriptBlock(this, typeof(Page), "ClientScript", "{debugger; alert('Cannot take this session unless you complete the prevoius one'); }", true);
 

                }

                if (dt_Status.Rows.Count > 0)

                {

                    if (dt_type2.Rows[0][0].ToString().Equals("SES") && sname1 != sname2 && session_status.Equals("Y"))

                    {

                        lbl_Result_Per.Text = "";

                        btn_att.Visible = false;

                        btn_Exam.Visible = false;

                        string strMsg = "Already completed the session";

                        lbl = new Label();
 

                        lbl.Text = ("<script language=\'javascript\'>"
 

                        + (Environment.NewLine + ("window.alert(" + ("\'"

                        + (strMsg + ("\'" + ")</script>"))))));

                        Page.Controls.Add(lbl);

                        //ScriptManager.RegisterClientScriptBlock(this, typeof(Page), "ClientScript", "{debugger; alert('Already completed the session'); }", true);
 

                    }

                }

                if (dt_type2.Rows[0][0].ToString().Equals("SES") && sname1 == sname2)

                {

                    string strMsg = "Please wait as no student has completed the test";

                     lbl = new Label();

                    lbl.Text = ("<script language=\'javascript\'>"

                    + (Environment.NewLine + ("window.alert(" + ("\'"

                    + (strMsg + ("\'" + ")</script>"))))));

                    Page.Controls.Add(lbl);

                    btn_att.Visible = false;

                    btn_Exam.Visible = false;

                }

                

            }
 

            else

            {

                

                string Status = "select  Status  from Stu_Exam_Course_Status where  Batch_Id='" + ddlBatch.SelectedValue + "' and Course_Id='" + ddlCourse.SelectedValue + "'  and Session_Id ='" + TreeView1.SelectedNode.Value + "' ";

                DataTable dt_Status = BusinessLayer.SelectMaster.GetDataTable(Session["ConStr"].ToString(), Status);

                if (dt_Status.Rows.Count > 0)

                {

                    session_status = dt_Status.Rows[0][0].ToString();

                    flagcheck = 4;

                }

                string qry9 = "select Record_Type from Admn_Course_Organization where Id='" + TreeView1.SelectedNode.Value + "'";

                DataTable dt_type2 = BusinessLayer.SelectMaster.GetDataTable(Session["ConStr"].ToString(), qry9);
 

                string sid1 = TreeView1.SelectedNode.Value;

                string sname1 = TreeView1.SelectedNode.Text;
 

                string result_per = Session["Result_Percentage"].ToString();

                string id = Session["Sess_Id"].ToString();

                sname2 = Session["SessionName"].ToString();

                string ename = Session["Sess_Name"].ToString();

                string date1 = Session["Sess_Date"].ToString();

                float pr1 = float.Parse(result_per);
 

                string date2 = DateTime.Now.ToString();

                string qrysid = "select Session_Id from Stu_Attendance_Mast where Session_Id='" + TreeView1.SelectedNode.Value + "'";

                DataTable dt_sid3 = BusinessLayer.SelectMaster.GetDataTable(Session["ConStr"].ToString(), qrysid);

               

                if (pr1 >= 60)

                {

                    if (dt_Status.Rows.Count > 0)

                    {

                        if (dt_type2.Rows[0][0].ToString().Equals("SES") && sname1 == sname2 && session_status.Equals("Y"))

                        {

                            lbl_Result_Per.Visible = true;

                            //"Attendance submitted!<br><br>Total No of students:&nbsp;<b>" + total + "<br>No of students present:&nbsp;<b>" + countp + "<br>No of students absent:&nbsp;<b>" + counta + "<br>Present Percentage:&nbsp;<b>" + per + "";

                            lbl_Result_Per.Text = "Result for <b>'" + sname2 + "' :&nbsp;<b>" + pr1 + "";

                            string strMsg = "Completed the session as result was greater than 60%";

                             lbl = new Label();

                            lbl.Text = ("<script language=\'javascript\'>"

                            + (Environment.NewLine + ("window.alert(" + ("\'"

                            + (strMsg + ("\'" + ")</script>"))))));

                            Page.Controls.Add(lbl);

                            // ScriptManager.RegisterClientScriptBlock(this, typeof(Page), "ClientScript", "{debugger; alert('Completed the session as result was greater than 60%'); }", true);

                            btn_att.Visible = false;

                            btn_Exam.Visible = false;
 

                        }

                    }

                  
 

                    if (dt_type2.Rows[0][0].ToString().Equals("SES") && sname1 != sname2 && sname1 == nextsessionname && dt_sid3.Rows.Count == 0 )

                    {

                        lbl_Result_Per.Text = "";

                     

                        Session.Remove("Result_Percentage");

                        Session.Remove("percentage");

                        Session.Remove("refresh2");

                      

                        

                    }

                    if (dt_type2.Rows[0][0].ToString().Equals("SES") && sname1 != sname2 && sname1 != nextsessionname && dt_sid3.Rows.Count == 0 && flagcheck != 4)

                    {

                        lbl_Result_Per.Text = "";

                        btn_att.Visible = false;

                        btn_Exam.Visible = false;

                        string strMsg = "Cannot take this session unless you complete the prevoius one";

                         lbl = new Label();
 

                        lbl.Text = ("<script language=\'javascript\'>"
 

                        + (Environment.NewLine + ("window.alert(" + ("\'"

                        + (strMsg + ("\'" + ")</script>"))))));

                        Page.Controls.Add(lbl);

                        //ScriptManager.RegisterClientScriptBlock(this, typeof(Page), "ClientScript", "{debugger; alert('Cannot take this session unless you complete the prevoius one'); }", true);
 

                    }

                    if (dt_Status.Rows.Count > 0)

                    {

                        if (dt_type2.Rows[0][0].ToString().Equals("SES") && sname1 != sname2 && session_status.Equals("Y") && flagcheck == 4)

                        {

                            lbl_Result_Per.Text = "";

                            btn_att.Visible = false;

                            btn_Exam.Visible = false;

                            string strMsg = "Already completed the session";

                           lbl = new Label();
 

                            lbl.Text = ("<script language=\'javascript\'>"
 

                            + (Environment.NewLine + ("window.alert(" + ("\'"

                            + (strMsg + ("\'" + ")</script>"))))));

                            Page.Controls.Add(lbl);

                            //ScriptManager.RegisterClientScriptBlock(this, typeof(Page), "ClientScript", "{debugger; alert('Already completed the session'); }", true);
 

                        }

                    }

                }

                if (pr1 < 60)

                {

                    if (dt_type2.Rows[0][0].ToString().Equals("SES") && sname1 == sname2 && flagcheck==7)

                    {

                        lbl_Result_Per.Visible = true;

                        lbl_Result_Per.Text = "Result for <b>'" + sname2 + "' :&nbsp;<b>" + pr1 + "";

                        string strMsg = "Reschedule the  session as result is less than 60%";

                         lbl = new Label();
 

                        lbl.Text = ("<script language=\'javascript\'>"
 

                        + (Environment.NewLine + ("window.alert(" + ("\'"

                        + (strMsg + ("\'" + ")</script>"))))));

                        Page.Controls.Add(lbl);

                        //ScriptManager.RegisterClientScriptBlock(this, typeof(Page), "ClientScript", "{debugger; alert('Reschedule the  session as result is less than 60%'); }", true);

                        btn_Exam.Visible = true;

                      

                    }

                    if (dt_type2.Rows[0][0].ToString().Equals("SES") && sname1 == sname2 && flagcheck == 6)

                    {

                        string strMsg = "Please wait for results,as all students have not yet completed the exam";

                         lbl = new Label();

                        lbl.Text = ("<script language=\'javascript\'>"

                        + (Environment.NewLine + ("window.alert(" + ("\'"

                        + (strMsg + ("\'" + ")</script>"))))));

                        Page.Controls.Add(lbl);

                        btn_att.Visible = false;

                        btn_Exam.Visible = false;
 

                    }
 

                    if (dt_type2.Rows[0][0].ToString().Equals("SES") && sname1 != sname2 && sname1 != nextsessionname && dt_sid3.Rows.Count == 0 )

                    {

                        lbl_Result_Per.Text = "";

                        btn_att.Visible = false;

                        btn_Exam.Visible = false;

                        string strMsg = "Cannot take this session unless you complete the prevoius one";

                    lbl = new Label();
 

                        lbl.Text = ("<script language=\'javascript\'>"
 

                        + (Environment.NewLine + ("window.alert(" + ("\'"

                        + (strMsg + ("\'" + ")</script>"))))));

                        Page.Controls.Add(lbl);

                        //ScriptManager.RegisterClientScriptBlock(this, typeof(Page), "ClientScript", "{debugger; alert('Cannot take this session unless you complete the prevoius one'); }", true);

                       

                    }

                    if (dt_Status.Rows.Count > 0)

                    {

                        if (dt_type2.Rows[0][0].ToString().Equals("SES") && sname1 != sname2 && session_status.Equals("Y"))

                        {

                            lbl_Result_Per.Text = "";

                            btn_att.Visible = false;

                            btn_Exam.Visible = false;

                            string strMsg = "Already completed the session";

                             lbl = new Label();
 

                            lbl.Text = ("<script language=\'javascript\'>"
 

                            + (Environment.NewLine + ("window.alert(" + ("\'"

                            + (strMsg + ("\'" + ")</script>"))))));

                            Page.Controls.Add(lbl);

                            //ScriptManager.RegisterClientScriptBlock(this, typeof(Page), "ClientScript", "{debugger; alert('Already completed the session'); }", true);
 

                        }

                    }
 

                   

                }

                
 

            }

        }
 

        catch (Exception ex)

        {

            scriptText = "window.alert('Sorry for inconvenience ,The data is not processed will get back to you soon');";

            Insert = new InsertMaster();

            Insert.DLInsert("Exception_Handling", "Module", "Training Center", "Page", "Trainer_Training.aspx.aspx", "Method", "content2", "Client_IP", ClientIPAdd, "1");

            string sqlQuery = "SELECT MAX(Id) AS ID FROM Exception_Handling WHERE (Module = 'Training Center') AND (Page = 'Trainer_Training.aspx.aspx') AND";

            sqlQuery += " (Method = 'content2') AND (Client_IP = '" + ClientIPAdd + "') AND (URI = '1')";

            try

            {

                DataTable dt_ExpDetails = BusinessLayer.SelectMaster.GetDataTable(Session["ConStr"].ToString(), sqlQuery);

                int expID = Convert.ToInt32(dt_ExpDetails.Rows[0][0].ToString());

                exDetails = new ExpDetails();

                exDetails.toXml(xmlPath, expID, ex.Message);

            }

            catch

            {
 

            }
 

            ScriptManager.RegisterClientScriptBlock(this, typeof(Page), "validationAlert", scriptText, true);

        }
 
 

    }

    

    protected void btn_att_Click(object sender, EventArgs e)

    {

        Session["Attendance"] = "yes";

        ScriptManager.RegisterClientScriptBlock(this, typeof(Page), "pop", "window.open('Attendance_PopUp.aspx',null,'height=500,width=500,location=no,status=no,toolbar=no,scrollbars=yes,dialog=yes,resizable=no')", true);

        btn_att.Visible = false;

    }

   

    protected void btn_Exam_Click(object sender, EventArgs e)

    {

        

        ScriptManager.RegisterClientScriptBlock(this, typeof(Page), "pop", "window.open('Schedule_Exam_Popup.aspx',null,'height=500,width=500,location=no,status=no,toolbar=no,scrollbars=yes,dialog=yes,resizable=no')", true);

        btn_Exam.Visible = false;

      

    }

    

    protected void TreeView1_TreeNodeExpanded(object sender, TreeNodeEventArgs e)

    {
 

    }

   
 

}

Open in new window

0
Comment
Question by:mannevenu
  • 2
3 Comments
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 24146701
Adding this to triggers may help
EventName="Click"

This is for buttons. For ddl, it would be selectedindexchanged etc.
0
 

Author Comment

by:mannevenu
ID: 24155840
Where I can write this one.
0
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 500 total points
ID: 24155886
Inside all of these lines
<asp:PostBackTrigger ControlID="btnshow"></asp:PostBackTrigger>
 as
<asp:PostBackTrigger ControlID="btnshow" EventName="Click"></asp:PostBackTrigger>
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now