void Professor_Professor_EditProfile_LoadComplete(object sender, EventArgs e)
    {
        main_class m = new main_class();

        string username = "";
        try {  username = Session["Professor_Username"].ToString();}
        catch (Exception ex) { Response.Redirect("Professor_login.aspx"); }
        string load_data = string.Format("select * from Professor where username = '******' ", username);
        DataTable dt = m.filldt(load_data);

        string get_dept = string.Format("select distinct department_name from department");
        DataTable dt1 = m.filldt(get_dept);

        department.DataSource = dt1;
        department.DataBind();

        first_name.Text = dt.Rows[0]["fname"].ToString();
        Middle_name.Text = dt.Rows[0]["mname"].ToString();
        last_name.Text = dt.Rows[0]["lname"].ToString();
        mail_id.Text = dt.Rows[0]["email"].ToString();
        img.ImageUrl = dt.Rows[0]["ProfilePic"].ToString();
        contactno.Text = dt.Rows[0]["contactno"].ToString();
        //high_school.Text = dt.Rows[0]["school"].ToString();
        college.Text = dt.Rows[0]["INSTITUTE"].ToString();
        gender.Text = dt.Rows[0]["gender"].ToString();
        bdate_date.Text = dt.Rows[0]["bdate"].ToString();
        enrollmentno.Text = dt.Rows[0]["Professor_Id"].ToString();
        department.SelectedValue = dt.Rows[0]["department"].ToString();

        m.cn.Close();

        m = null;
    }
    void Professor_Professor_Home_LoadComplete(object sender, EventArgs e)
    {
        main_class m = new main_class();

        string username = "";
        try { username = Session["Professor_Username"].ToString(); }
        catch (Exception ex) { Response.Redirect("Professor_Login.aspx"); }

        string load_data=string.Format("select * from Professor where username = '******' ", username);
        DataTable dt=m.filldt(load_data);

        first_name.Text = dt.Rows[0]["fname"].ToString();
        Middle_name.Text = dt.Rows[0]["mname"].ToString();
        last_name.Text = dt.Rows[0]["lname"].ToString();
        mail_id.Text = dt.Rows[0]["email"].ToString();
        img.ImageUrl = dt.Rows[0]["ProfilePic"].ToString();
        contactno.Text = dt.Rows[0]["contactno"].ToString();
        //high_school.Text = dt.Rows[0]["school"].ToString();
        college.Text = dt.Rows[0]["institute"].ToString();

        try {
            if (int.Parse(dt.Rows[0]["gender"].ToString()) == 0)
            {
                gender.Text = "Male";
            }
            else if (int.Parse(dt.Rows[0]["gender"].ToString()) == 1)
            {
                gender.Text = "Female";
            }
            else
            {
                gender.Text = dt.Rows[0]["gender"].ToString();
            }

        }
        catch (Exception ec) { gender.Text = "Update Gender"; }

        bdate_date.Text = dt.Rows[0]["bdate"].ToString();
        enrollmentno.Text = dt.Rows[0]["Professor_id"].ToString();
           department.Text=dt.Rows[0]["department"].ToString();

        //bind subjects
        string get_sub = string.Format("select * from professor_subjects where Professor_username = '******' ",username);
        DataTable dt_sub = m.filldt(get_sub);

        Professor_Subjects.DataSource = dt_sub;
        Professor_Subjects.DataBind();

        m.cn.Close();

        m = null;
    }
    protected void login_Click(object sender, EventArgs e)
    {
        main_class m = new main_class();

        string get = string.Format("select * from student where username = '******' and password = '******' ", student_username.Text,student_password.Text);
        DataTable dt =  m.filldt(get);

        m.cn.Close();
        m = null;

        if (dt.Rows.Count != 0)
        {
            if (dt.Rows[0]["Approved"].ToString() != "Yes")
            {
                approval.Visible = true;
            }
            else
            {
                Session["Student_Username"] = student_username.Text;
                Response.Redirect("student_home.aspx");
            }

        }
        else { wrong.Visible = true; }
    }
    void Student_View_attendance_LoadComplete(object sender, EventArgs e)
    {
        main_class m=new main_class();

        //string student = Session["Student_Username"].ToString();
        string student = "";
        try { student = Session["Student_Username"].ToString(); }
        catch (Exception ex) { Response.Redirect("Student_login.aspx"); }

        int student_id = int.Parse(m.get_idfromusername("student",student).ToString());
        string attn = string.Format("select * from attendence where student_id = {0} ORDER BY attendence_ID DESC ", student_id);
        DataTable dt = m.filldt(attn);

        attendence.DataSource = dt;
        attendence.DataBind();

        int count = 0;

        for (int i = 0; i < attendence.Rows.Count; i++)
        {
            if (attendence.Rows[i].Cells[3].Text == "Present")
            {
                count++;
            }

        }

           int per = (count * 100) / attendence.Rows.Count ;
        percentage.Text = per + " %";
    }
    protected void signup_Click(object sender, EventArgs e)
    {
        main_class m = new main_class();

        //check
        string check = string.Format("select * from professor where username = '******' ",Profesor_usrname.Text);
        DataTable dt = m.filldt(check);

        if (dt.Rows.Count != 0)
        {
            exists.Visible = true;
        }
        else
        {
            int id = m.get_maxid("professor");

            string professor_register = string.Format("insert into professor (professor_Id,FName,Email,Contactno,Username,Password,approved,institute) values  ({0},'{1}','{2}',{3},'{4}','{5}' , 'No' , '{6}') ",
                id,
                Profesor_name.Text,
                Profesor_email.Text,
                Profesor_no.Text,
                Profesor_usrname.Text,
                Profesor_passwrd.Text,
                institute.Text);
            m.insertvalues(professor_register);

            //dispose
            m.cn.Close();
            m = null;

            Response.Redirect("Professor_login.aspx");

        }
    }
    void Bind_students()
    {
        main_class m = new main_class();

        string get_students = string.Format("select * from student where approved = 'No' ");
        DataTable dt = m.filldt(get_students);

        students.DataSource = dt;
        students.DataBind();

        m.cn.Close();
    }
    protected void searchbtn_Click(object sender, EventArgs e)
    {
        main_class m = new main_class();

        string get_docs = string.Format("SELECT * FROM docs WHERE doc_title LIKE '%{0}%' ", search.Text );
        DataTable dt = m.filldt(get_docs);

        docs.DataSource = dt;
        docs.DataBind();

        m.cn.Close();
        m = null;
    }
    protected void dept_TextChanged(object sender, EventArgs e)
    {
        main_class m = new main_class();

            string get_students = string.Format("select * from student where department = '{0}' ", dept.SelectedValue.ToString());
            DataTable students = m.filldt(get_students);

            attendence.DataSource = students;
            attendence.DataBind();

            m.cn.Close();
            m = null;
    }
    public void bind_files()
    {
        main_class m = new main_class();

        string admin = Session["admin"].ToString();

        string get_docs = string.Format("select * from department where admin_name = '{0}' ", admin);

        DataTable dt = m.filldt(get_docs);

        dept.DataSource = dt;
        dept.DataBind();
    }
    void Student_student_home_LoadComplete(object sender, EventArgs e)
    {
        main_class m = new main_class();

        string username = "";
        try { username = Session["Student_Username"].ToString(); }
        catch (Exception ex) { Response.Redirect("Student_login.aspx"); }

        string load_data = string.Format("select * from Student where username = '******' ", username);
        DataTable dt = m.filldt(load_data);

        first_name.Text = dt.Rows[0]["fname"].ToString();
        Middle_name.Text = dt.Rows[0]["mname"].ToString();
        last_name.Text = dt.Rows[0]["lname"].ToString();
        mail_id.Text = dt.Rows[0]["email"].ToString();
        img.ImageUrl = dt.Rows[0]["ProfilePic"].ToString();
        contactno.Text = dt.Rows[0]["contactno"].ToString();
        //high_school.Text = dt.Rows[0]["school"].ToString();
        college.Text = dt.Rows[0]["college"].ToString();
        department.Text=dt.Rows[0]["department"].ToString();

        try
        {
            if (int.Parse(dt.Rows[0]["gender"].ToString()) == 0)
            {
                gender.Text = "Male";
            }
            else if (int.Parse(dt.Rows[0]["gender"].ToString()) == 1)
            {
                gender.Text = "Female";
            }
            else
            {
                gender.Text = dt.Rows[0]["gender"].ToString();
            }

        }
        catch (Exception)
        {

        }

        bdate.Text = dt.Rows[0]["bdate"].ToString();
        enrollmentno.Text = dt.Rows[0]["EnrollNo"].ToString();

        m.cn.Close();

        m = null;
    }
    void bind_profesor()
    {
        main_class m = new main_class();

        //string get_students = string.Format("select * from professor where approved = 'No' ");

        string get_students = string.Format("select * from professor where  approved = 'No' ");

        DataTable dt = m.filldt(get_students);

        professor.DataSource = dt;
        professor.DataBind();

        m.cn.Close();
        m = null;
    }
    protected void search_professor_TextChanged(object sender, EventArgs e)
    {
        if (IsPostBack)
        {
            main_class m = new main_class();

            string search_pro = string.Format("select * from Professor where Fname LIKE '%{0}%'  OR Lname LIKE '%{0}%' ", search_professor.Text);

            DataTable dt = m.filldt(search_pro);

            professor.DataSource = dt;
            professor.DataBind();

            m.cn.Close();
            m = null;
        }
    }
    protected void download_Click(object sender, EventArgs e)
    {
        main_class m = new main_class();

        string i = ((Button)sender).CommandArgument.ToString();
        string d = string.Format("select * from docs where docs_id = {0}", i);
        DataTable dt = m.filldt(d);

        string q = dt.Rows[0]["doc_path"].ToString();
        string filePath = q;
        Response.ContentType = ContentType;
        Response.AppendHeader("Content-Disposition", "attachment; filename=" + Path.GetFileName(filePath));
        Response.WriteFile(filePath);
        Response.End();

        m.cn.Close();
    }
    protected void login_Click(object sender, EventArgs e)
    {
        main_class m = new main_class();

        string get = string.Format("select * from admin where admin_name = '{0}' and Admin_password = '******'", username.Text, password.Text);
        DataTable dt = m.filldt(get);

        m.cn.Close();
        m = null;

        if (dt.Rows.Count != 0)
        {
            Session["admin"] = username.Text;
            Response.Redirect("admin_home.aspx");
        }
        else { wrong.Visible = true; }
    }
    protected void docs_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        main_class m = new main_class();

        string i = docs.Rows[e.RowIndex].Cells[0].Text;
        string deleterow = string.Format("delete from docs where Id = {0}", i);
        SqlCommand delete_cmd = new SqlCommand(deleterow,m.cn);
        delete_cmd.ExecuteNonQuery();

        string get_docs = string.Format("select * from docs where Professor_username = '******' ", professor);

        DataTable dt = m.filldt(get_docs);

        docs.DataSource = dt;
        docs.DataBind();

        m.cn.Close();
        i = null;

        delete_cmd.Dispose();
    }
    public void bind_files()
    {
        main_class m = new main_class();

        string professor = Session["Professor_Username"].ToString();

        string get_docs = string.Format("select * from docs where Professor_username = '******' order by docs_id DESC ",professor);

        DataTable dt = m.filldt(get_docs);
        dt.Columns.Add("doc_name");
        dt.Columns.Add("filename");
        for (int i = 0; i < dt.Rows.Count; i++)
        {
            FileInfo f = new FileInfo( MapPath( dt.Rows[i]["doc_path"].ToString()));
            dt.Rows[i]["doc_name"] = getsize(f.Length);
            dt.Rows[i]["filename"] = f.Name;
        }

        docs.DataSource = dt;
        docs.DataBind();
    }
    protected void view_Click(object sender, EventArgs e)
    {
        main_class m = new main_class();
        string i = ((Button)sender).CommandArgument.ToString();
        string get = string.Format("select * from docs where docs_id = '{0}' ",i);
        DataTable dt = m.filldt(get);

        string outputPdfFile = dt.Rows[0]["doc_path"].ToString();

        Response.ContentType = "Application/pdf";
        Response.TransmitFile(outputPdfFile);
    }
    void Professor_fil_attendence_LoadComplete(object sender, EventArgs e)
    {
        string username = "";

        try { username = Session["Professor_Username"].ToString(); }
        catch (Exception ex) { Response.Redirect("Professor_Login.aspx"); }

        if (!IsPostBack)
        {

            main_class m = new main_class();

            //get departments
            string get_dept = string.Format("select * from department");
            DataTable dept_dt = m.filldt(get_dept);
            dept.DataSource = dept_dt;
            dept.DataBind();

            //get students
            string get_students = string.Format("select * from student where department = '{0}' ", dept.SelectedValue.ToString());
            DataTable students = m.filldt(get_students);

            attendence.DataSource = students;
            attendence.DataBind();

            m.cn.Close();
            m = null;
        }
    }