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");

        }
    }
    protected void fill_Click(object sender, EventArgs e)
    {
        string professor = Session["Professor_Username"].ToString();
        main_class m = new main_class();

        for (int i = 0; i < attendence.Rows.Count; i++)
        {
            string result = "";
                RadioButtonList rb = attendence.Rows[i].Cells[4].FindControl("rblist") as RadioButtonList;
                if (rb.Items[0].Selected == true)
                {
                    result = "Present";
                }
                if (rb.Items[1].Selected == true)
                {
                    result = "Absent";
                }

            int max_id=m.get_maxid("attendence");
            string ins_attn = string.Format("insert into attendence values ({0},'{1}','{2}','{3}','{4}','{5}','{6}','{7}',{8}) ",
                max_id,
                attendence.Rows[i].Cells[0].Text,
                attendence.Rows[i].Cells[1].Text,
                attendence.Rows[i].Cells[2].Text,
                result,
                professor,
                date.Text.ToString(),
                subject.Text,
                attendence.Rows[i].Cells[3].Text);
            m.insertvalues(ins_attn);
        }
    }
    protected void approve_Click(object sender, EventArgs e)
    {
        object ID = ((Button)sender).CommandArgument;
        Response.Write(ID.ToString());

        main_class m = new main_class();
        string update = string.Format("update professor set approved = 'Yes' where Professor_Id= {0} ",ID);
        m.insertvalues(update);

        bind_profesor();
    }
    protected void add_Click(object sender, EventArgs e)
    {
        string admin= Session["User"].ToString();

        main_class m = new main_class();

        int max_id = m.get_maxid("Department");
        string ins = string.Format("insert into department values ({0},'{1}','{2}') ",max_id,department.Text,admin);
        m.insertvalues(ins);

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

        string img_path = "";

        //Image Upload Code
        if (FileUpload1.HasFile)
        {
            try { System.IO.File.Delete(MapPath(img.ImageUrl)); }
            catch { }
            img_path = "/images/ProfilePic_Student/" + FileUpload1.FileName;
            FileUpload1.SaveAs(MapPath(img_path));

        }
        else
        {
            img_path = img.ImageUrl;
        }

        //
        string username = Session["Student_Username"].ToString();
        int id = m.get_idfromusername("student",username);

        string update = string.Format("update student set fname='{0}',"+
        "mname='{1}',"+
        "lname='{2}',"+
        "email='{3}',"+
        "contactno={4},"+
        "profilepic='{5}',"+
        "school='{6}',"+
        "college='{7}',"+
        "bdate='{8}',"+
        "gender='{9}',"+
        "enrollno='{10}',"+
        "department = '{11}' where student_id = {12}",
        first_name.Text,
        Middle_name.Text,
        last_name.Text,
        mail_id.Text,
        contactno.Text,
        img_path,
        high_school.Text,
        college.Text,
        bdate_date.Text,
        gender.Text,
        enrollmentno.Text,
        department.Text, id );

        m.insertvalues(update);
        m = null;
    }
    protected void save_Click(object sender, EventArgs e)
    {
        main_class m = new main_class();

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

        string img_path = "";

        //Image Upload Code
        if (FileUpload1.HasFile)
        {
            try { System.IO.File.Delete(MapPath(img.ImageUrl)); }
            catch { }
            img_path = "/images/ProfilePic_Professor/" + FileUpload1.FileName;
            FileUpload1.SaveAs(MapPath(img_path));

        }
        else
        {
            img_path = img.ImageUrl;
        }

        string update = string.Format("update Professor set fname='{0}',Mname='{1}',Lname='{2}',Profilepic='{3}',contactno={4},bdate='{5}',email='{6}',institute='{7}',gender='{8}',department='{9}' where username='******'",
                                         first_name.Text,
                                         Middle_name.Text,
                                         last_name.Text,
                                         img_path,
                                         contactno.Text,
                                         bdate_date.Text,
                                         mail_id.Text,
                                         college.Text,
                                         gender.Text,
                                         department.Text,
                                         username);
            m.insertvalues(update);
            Response.Redirect("Professor_Home.aspx");
    }
    protected void Upload_doc_Click(object sender, EventArgs e)
    {
        string professor = Session["Professor_Username"].ToString();
        main_class m = new main_class();
            if (FileUpload1.HasFile)
            {
                string ext = Path.GetExtension(FileUpload1.FileName);
                if (ext == ".PPTX" || ext == ".pptx" || ext == ".PPT" || ext == ".ppt" || ext == ".pdf" || ext == ".PDF" || ext == ".txt" || ext == ".TXT" || ext == ".DOC" || ext == ".doc" || ext == ".DOCX" || ext == ".docx")
                {
                    string q = "/Docs/" + FileUpload1.FileName;
                    FileUpload1.SaveAs(MapPath(q));

                    int max_id = m.get_maxid("docs");
                    //Inserting in db
                    string q1 = string.Format("insert into docs values ({0},'{1}','{2}','{3}') ", max_id, professor, q, doc_title.Text);
                    m.insertvalues(q1);
                    Response.Write("File Uploaded");

                    bind_files();
                }
                else
                {
                    Response.Write("Only PDF Files allowed");
                }
            }
    }