protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
    {
        string role = "学生";
        for (int i = 0; i < Role.Items.Count;i++)
        {
            if (Role.Items[i].Selected)
            {
                role = Role.Items[i].Text;
            }

        }
        //Response.Write("<script>alert('用户名。。'" + username.Text+password.Text+role+"');</script>");
        md5Manger md5 = new md5Manger();
        if (role == "学生")
        {
            judge("select * from student where student_ID='" + username.Text + "' and password='******'and role='" + role + "'", role);
        }
        else if (role == "管理员")
        {
            judge("select * from admin where admin_ID='" + username.Text + "'and password='******'and role='" + role + "'", role);
        }
        else 
        {
            judge("select * from teacher where teacher_ID='" + username.Text + "'and password='******'", role);
        }

        }
示例#2
0
    protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
    {
        string role = "学生";

        for (int i = 0; i < Role.Items.Count; i++)
        {
            if (Role.Items[i].Selected)
            {
                role = Role.Items[i].Text;
            }
        }
        //Response.Write("<script>alert('用户名。。'" + username.Text+password.Text+role+"');</script>");
        md5Manger md5 = new md5Manger();

        if (role == "学生")
        {
            judge("select * from student where student_ID='" + username.Text + "' and password='******'and role='" + role + "'", role);
        }
        else if (role == "管理员")
        {
            judge("select * from admin where admin_ID='" + username.Text + "'and password='******'and role='" + role + "'", role);
        }
        else
        {
            judge("select * from teacher where teacher_ID='" + username.Text + "'and password='******'", role);
        }
    }
    protected void change_Click(object sender, EventArgs e)
    {
        DB db = new DB();
        DataSet ds = db.Select("select * from admin where admin_ID='" + Session["username"] + "'", db.DBconn());
        try
        {     string password = ds.Tables[0].Rows[0][2].ToString();
            md5Manger md5 = new md5Manger();
             password = md5.Md5Decrypt(password);
            //解密
       
            string oldpassword = this.oldpassword.Text.Trim();
            string newpassword = this.newpassword.Text.Trim();
            if (password.Equals(oldpassword))
            {
                newpassword = md5.Md5Encrypt(newpassword);//加密
                string updatepassword = "******" + newpassword + "' WHERE admin_ID ='" + Session["username"].ToString() + "'";
                bool result = db.Update(updatepassword, db.DBconn());
                // Response.Write("<script language='javascript'>alert('您的jieguo为:" + result + "')</script>");
                if (result)
                {


                    this.message.Text = "密码更改成功!";

                }

                else
                {
                    this.message.Text = "数据库更新失败!";

                }

            }

            else
            {
                this.message.Text = "对不起,您的密码输入错误,请重新输入";

            }
        
        }
        catch
        {
            Response.Write("<script>alert('数据库获取用户密码错误。');location='Default.aspx'</script>");
        }
       finally
       {
           ds.Clear();
       }
    }
示例#4
0
    protected void change_Click(object sender, EventArgs e)
    {
        DB db = new DB();

        DataSet ds = db.Select("select * from student where student_ID='" + Session["username"] + "'", db.DBconn());

        try
        {
            string password = ds.Tables[0].Rows[0][4].ToString();

            md5Manger md5 = new md5Manger();
            password = md5.Md5Decrypt(password);
            //解密
            string oldpassword = this.oldpassword.Text.Trim();
            string newpassword = this.newpassword.Text.Trim();

            if (password.Equals(oldpassword))
            {
                newpassword = md5.Md5Encrypt(newpassword);//加密
                string updatepassword = "******" + newpassword + "' WHERE student_ID ='" + Session["username"].ToString() + "'";
                bool   result         = db.Update(updatepassword, db.DBconn());
                // Response.Write("<script language='javascript'>alert('您的jieguo为:" + result + "')</script>");
                if (result)
                {
                    this.message.Text = "密码更改成功!";
                }
                else
                {
                    this.message.Text = "数据库更新失败!";
                }
            }
            else
            {
                this.message.Text = "对不起,您的密码输入错误,请重新输入";
            }
        }
        catch
        {
            Response.Write("<script>alert('数据库获取用户密码错误。');location='Default.aspx'</script>");
        }
        finally
        {
            ds.Clear();
        }
    }
    protected void DataTableToDB(string _strExcelFileName)//插入操作
    {
        EXCELtoSQL ets = new EXCELtoSQL();
        md5Manger md5 = new md5Manger();
        try
        {
            DataTable dtExcel = ets.ExcelToDataTable(_strExcelFileName, "Sheet1");
            for (int i = 0; i < dtExcel.Rows.Count; i++)//按行读取
            {
                // Response.Write("<script language='javascript'>alert('读取的数据为" + dtExcel.Rows[i][0].ToString() + "');</script>");
                string insert = "insert into teacher(department,teacher_ID,name,sex,age,birthday,zhicheng,position,Email,password,role)  values('" + dtExcel.Rows[i][0].ToString() +
                    "','" + dtExcel.Rows[i][1].ToString() + "','" + dtExcel.Rows[i][2].ToString() + "','" + dtExcel.Rows[i][3].ToString() +
                    "','" + dtExcel.Rows[i][4].ToString() + "','" + dtExcel.Rows[i][5].ToString() + "','" + dtExcel.Rows[i][6].ToString() +
                    "','" + dtExcel.Rows[i][7].ToString() + "','" + dtExcel.Rows[i][8].ToString() + "','" + md5.Md5Encrypt( dtExcel.Rows[i][5].ToString() )+ "','" + "教师" + "')";

                bool result = ets.InsertDataToSQL(insert);
                if (result)
                {
                    this.Label2.Text = "导入数据库成功!";
                    this.GridView1.Visible = false;
                }
                else
                {
                    this.Label2.Text = "导入数据库失败!可能教师号字段重复。";
                }
                Panel2.Visible = false;
                this.Label2.Visible = true;
         
       
    


            }

        }
        catch (SqlException e)
        {
             Panel2.Visible = false;
            this.Label2.Visible = true;
            this.Label2.Text = "导入数据库失败!" + e.Message;

        }
    }
    protected void DataTableToDB(string _strExcelFileName)//插入操作
    {
        EXCELtoSQL ets = new EXCELtoSQL();

        try
        {
            DataTable dtExcel = ets.ExcelToDataTable(_strExcelFileName, "Sheet1");
            for (int i = 0; i < dtExcel.Rows.Count; i++)//按行读取
            {
                //密码加密
                md5Manger md5 =new md5Manger();
                string pwd = md5.Md5Encrypt(dtExcel.Rows[i][4].ToString());
                // Response.Write("<script language='javascript'>alert('读取的数据为" + dtExcel.Rows[i][0].ToString() + "');</script>");
                string insert = "insert into student(class,student_ID,name,sex,birthday,birthplace,entranceDate,nation,specialty,zyfx,college,IDcard,grade,phonenumber,Email,password,role)  values('" + dtExcel.Rows[i][0].ToString() + 
                    "','" + dtExcel.Rows[i][1].ToString() + "','" + dtExcel.Rows[i][2].ToString() + "','" + dtExcel.Rows[i][3].ToString() +
                    "','" + dtExcel.Rows[i][4].ToString() + "','" + dtExcel.Rows[i][5].ToString() + "','" + dtExcel.Rows[i][6].ToString() + 
                    "','" + dtExcel.Rows[i][7].ToString() + "','" + dtExcel.Rows[i][8].ToString() + "','" + dtExcel.Rows[i][9].ToString() +
                    "','" + dtExcel.Rows[i][10].ToString() + "','" +dtExcel.Rows[i][11].ToString() + "','" + dtExcel.Rows[i][12].ToString() +
                    "','" + dtExcel.Rows[i][13].ToString() + "','" + dtExcel.Rows[i][14].ToString() + "','" + pwd + "','" + "学生" + "')";
            
                bool result=ets.InsertDataToSQL(insert);
                if (result)
                {
                    this.Label2.Text = "导入数据库成功!";
                    this.GridView1.Visible = false;
                }
                else
                {
                    this.Label2.Text = "导入数据库失败!可能学号字段重复。";
                }
                Panel2.Visible = false;
                this.Label2.Visible = true;

            }

        }
        catch 
        {

        }

    }
    protected void DataTableToDB(string _strExcelFileName)//插入操作
    {
        EXCELtoSQL ets = new EXCELtoSQL();

        try
        {
            DataTable dtExcel = ets.ExcelToDataTable(_strExcelFileName, "Sheet1");
            for (int i = 0; i < dtExcel.Rows.Count; i++)//按行读取
            {
                //密码加密
                md5Manger md5 = new md5Manger();
                string    pwd = md5.Md5Encrypt(dtExcel.Rows[i][4].ToString());
                // Response.Write("<script language='javascript'>alert('读取的数据为" + dtExcel.Rows[i][0].ToString() + "');</script>");
                string insert = "insert into student(class,student_ID,name,sex,birthday,birthplace,entranceDate,nation,specialty,zyfx,college,IDcard,grade,phonenumber,Email,password,role)  values('" + dtExcel.Rows[i][0].ToString() +
                                "','" + dtExcel.Rows[i][1].ToString() + "','" + dtExcel.Rows[i][2].ToString() + "','" + dtExcel.Rows[i][3].ToString() +
                                "','" + dtExcel.Rows[i][4].ToString() + "','" + dtExcel.Rows[i][5].ToString() + "','" + dtExcel.Rows[i][6].ToString() +
                                "','" + dtExcel.Rows[i][7].ToString() + "','" + dtExcel.Rows[i][8].ToString() + "','" + dtExcel.Rows[i][9].ToString() +
                                "','" + dtExcel.Rows[i][10].ToString() + "','" + dtExcel.Rows[i][11].ToString() + "','" + dtExcel.Rows[i][12].ToString() +
                                "','" + dtExcel.Rows[i][13].ToString() + "','" + dtExcel.Rows[i][14].ToString() + "','" + pwd + "','" + "学生" + "')";

                bool result = ets.InsertDataToSQL(insert);
                if (result)
                {
                    this.Label2.Text       = "导入数据库成功!";
                    this.GridView1.Visible = false;
                }
                else
                {
                    this.Label2.Text = "导入数据库失败!可能学号字段重复。";
                }
                Panel2.Visible      = false;
                this.Label2.Visible = true;
            }
        }
        catch
        {
        }
    }
    protected void DataTableToDB(string _strExcelFileName)//插入操作
    {
        EXCELtoSQL ets = new EXCELtoSQL();
        md5Manger  md5 = new md5Manger();

        try
        {
            DataTable dtExcel = ets.ExcelToDataTable(_strExcelFileName, "Sheet1");
            for (int i = 0; i < dtExcel.Rows.Count; i++)//按行读取
            {
                // Response.Write("<script language='javascript'>alert('读取的数据为" + dtExcel.Rows[i][0].ToString() + "');</script>");
                string insert = "insert into teacher(department,teacher_ID,name,sex,age,birthday,zhicheng,position,Email,password,role)  values('" + dtExcel.Rows[i][0].ToString() +
                                "','" + dtExcel.Rows[i][1].ToString() + "','" + dtExcel.Rows[i][2].ToString() + "','" + dtExcel.Rows[i][3].ToString() +
                                "','" + dtExcel.Rows[i][4].ToString() + "','" + dtExcel.Rows[i][5].ToString() + "','" + dtExcel.Rows[i][6].ToString() +
                                "','" + dtExcel.Rows[i][7].ToString() + "','" + dtExcel.Rows[i][8].ToString() + "','" + md5.Md5Encrypt(dtExcel.Rows[i][5].ToString()) + "','" + "教师" + "')";

                bool result = ets.InsertDataToSQL(insert);
                if (result)
                {
                    this.Label2.Text       = "导入数据库成功!";
                    this.GridView1.Visible = false;
                }
                else
                {
                    this.Label2.Text = "导入数据库失败!可能教师号字段重复。";
                }
                Panel2.Visible      = false;
                this.Label2.Visible = true;
            }
        }
        catch (SqlException e)
        {
            Panel2.Visible      = false;
            this.Label2.Visible = true;
            this.Label2.Text    = "导入数据库失败!" + e.Message;
        }
    }