diff --git "a/\347\254\2547\346\254\241\344\275\234\344\270\232/\345\274\240\347\233\212\351\243\236/Longer.aspx" "b/\347\254\2547\346\254\241\344\275\234\344\270\232/\345\274\240\347\233\212\351\243\236/Longer.aspx" index e73a5ac99385c40ae70c95e1816e98a8a8c81074..8025c74172a7526f644ba5e8e07d92e25d3d0f32 100644 --- "a/\347\254\2547\346\254\241\344\275\234\344\270\232/\345\274\240\347\233\212\351\243\236/Longer.aspx" +++ "b/\347\254\2547\346\254\241\344\275\234\344\270\232/\345\274\240\347\233\212\351\243\236/Longer.aspx" @@ -1,4 +1,4 @@ -<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Longer.aspx.cs" Inherits="WebApplication2.Baga.Longer" %> +<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Longer.aspx.cs" Inherits="WebApplication1.Daywtwo.Longer" %> @@ -9,12 +9,53 @@
+
+ +
- 账号: - 密码: - - - + + + + + + + + + + + + + + + + + + +
姓名: + +
邮箱: + +
信息: + +
+ +
+
+
+ + + + + + + + + + + + + +
diff --git "a/\347\254\2547\346\254\241\344\275\234\344\270\232/\345\274\240\347\233\212\351\243\236/Longer.aspx.cs" "b/\347\254\2547\346\254\241\344\275\234\344\270\232/\345\274\240\347\233\212\351\243\236/Longer.aspx.cs" index 1dcaf8ab8a41f065c926872348ce3694a16d1535..4e549460c8d144aacb66fd86d83709cbbb4ccade 100644 --- "a/\347\254\2547\346\254\241\344\275\234\344\270\232/\345\274\240\347\233\212\351\243\236/Longer.aspx.cs" +++ "b/\347\254\2547\346\254\241\344\275\234\344\270\232/\345\274\240\347\233\212\351\243\236/Longer.aspx.cs" @@ -1,95 +1,127 @@ using System; using System.Collections.Generic; -using System.Data; using System.Data.SqlClient; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; +using System.Data; + -namespace WebApplication2.Baga +namespace WebApplication1.Daywtwo { public partial class Longer : System.Web.UI.Page { - private Sqlserver sqlserver = new Sqlserver(); + Sqlhyper Sqlhyper = new Sqlhyper(); protected void Page_Load(object sender, EventArgs e) { - + if (!IsPostBack) + { + GridViewText(); + } } + private void GridViewText() { + //GridView1.DataKeyNames = new string[] { "stu_id" }; + GridView1.DataKeyNames = new string[] { "stu_id" }; + GridView1.DataSource = Sqlhyper.Gettable("select*from StudentInfo", null); + GridView1.DataBind(); + } + + //查找 protected void Button1_Click(object sender, EventArgs e) { + + + //'%' + @name + '%' + string sql = "select*from StudentInfo where stu_name like '%'+@TextBox1+'%'"; + SqlParameter[] parameters ={ + new SqlParameter("@TextBox1",TextBox1.Text) + }; - string sql = "select*from studentinfo where stu_name=@name and password=@paw"; - SqlParameter[] para ={ - new SqlParameter("@name",TextBox1.Text), - new SqlParameter("@paw",TextBox2.Text) - }; + GridView1.DataSource =Sqlhyper.Gettable(sql, parameters); + GridView1.DataBind(); + } - DataTable table= sqlserver.Get(sql, para); - if (table.Rows.Count > 0) + protected void Button2_Click(object sender, EventArgs e) + { + string sql = "insert into StudentInfo (stu_name,email,intro) values(@2,@3,@4)"; + SqlParameter[] parameters = { + new SqlParameter("@2",TextBox3.Text), + new SqlParameter("@3",TextBox4.Text), + new SqlParameter("@4",TextBox5.Text) + }; + if (Sqlhyper.NotFind(sql, parameters)) { - Session["name"] = TextBox1.Text; - Response.Redirect("sessend.aspx"); + Literal1.Text = "添加成功!!!"; + GridViewText(); } else { - Literal1.Text = "登入失败"; + Literal1.Text = "添加失败!!!"; } - - - - - - - - - // string connet = "server=LAPTOP-8HS8J7NL;uid=sa;pwd=2287431003a;database=Student_db"; - - // SqlConnection com = new SqlConnection(connet); - - // com.Open(); - - // string name = TextBox1.Text; - // string pwd = TextBox2.Text; - - // string sql = "select*from StudentInfo where stu_name=@name and password=@pwd"; - - // SqlParameter[] parameters ={ - // new SqlParameter("@name",name), - // new SqlParameter("@pwd",pwd) - // }; - - // SqlCommand cmd = new SqlCommand(sql, com); - // cmd.Parameters.AddRange(parameters); - - - // SqlDataReader reader = cmd.ExecuteReader(); - // //reader.Read(); - // //cmd.ExecuteScalar(); - - // if (reader.Read()) - // { - // Session["name"] = name; - // Response.Redirect("sessend.aspx"); - // } - // else - // { - // Response.Redirect("Longer.aspx"); - // } - } - protected void Button2_Click(object sender, EventArgs e) + protected void GridView1_RowEditing1(object sender, GridViewEditEventArgs e) { - - Response.Redirect("resgin.aspx"); + GridView1.EditIndex = e.NewEditIndex; + GridViewText(); } + protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e) + { + + string id = GridView1.DataKeys[e.RowIndex].Value.ToString(); + + string name = ((TextBox)GridView1.Rows[e.RowIndex].Cells[1].Controls[0]).Text; + string email = ((TextBox)GridView1.Rows[e.RowIndex].Cells[3].Controls[0]).Text; + string intro = ((TextBox)GridView1.Rows[e.RowIndex].Cells[4].Controls[0]).Text; + string paw= ((TextBox)GridView1.Rows[e.RowIndex].Cells[6].Controls[0]).Text; + + string sql = "update StudentInfo set stu_name=@1,email=@2,intro=@3,password=@4 where stu_id=@id"; + + SqlParameter[] parameters = { + new SqlParameter("@1",name), + new SqlParameter("@2",email), + new SqlParameter("@3",intro), + new SqlParameter("@4",paw), + new SqlParameter("@id",id) + }; + if (Sqlhyper.NotFind(sql, parameters)) + { + Literal1.Text = "更新成功!!!"; + GridViewText(); + } + else { + Literal1.Text = "更新失败!!!"; + } + } + + protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e) + { + GridView1.EditIndex = -1; + GridViewText(); + } - + protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e) + { + string id = GridView1.DataKeys[e.RowIndex].Value.ToString(); + string sql = "delete from StudentInfo where stu_id=@id"; + SqlParameter[] parameters = { + new SqlParameter("@id",id) + }; + if (Sqlhyper.NotFind(sql, parameters)) + { + Literal1.Text = "删除成功!!!"; + GridViewText(); + } + else + { + Literal1.Text = "删除失败!!!"; + } + } } } \ No newline at end of file diff --git "a/\347\254\2547\346\254\241\344\275\234\344\270\232/\345\274\240\347\233\212\351\243\236/SqlHelper.cs" "b/\347\254\2547\346\254\241\344\275\234\344\270\232/\345\274\240\347\233\212\351\243\236/SqlHelper.cs" deleted file mode 100644 index 24598434a50f976e31f0ed145fc8da463e4bd78a..0000000000000000000000000000000000000000 --- "a/\347\254\2547\346\254\241\344\275\234\344\270\232/\345\274\240\347\233\212\351\243\236/SqlHelper.cs" +++ /dev/null @@ -1,6 +0,0 @@ -namespace WebApplication2.Baga -{ - internal class SqlHelper - { - } -} \ No newline at end of file diff --git "a/\347\254\2547\346\254\241\344\275\234\344\270\232/\345\274\240\347\233\212\351\243\236/Sqlserver.cs" "b/\347\254\2547\346\254\241\344\275\234\344\270\232/\345\274\240\347\233\212\351\243\236/Sqlhyper.cs" similarity index 49% rename from "\347\254\2547\346\254\241\344\275\234\344\270\232/\345\274\240\347\233\212\351\243\236/Sqlserver.cs" rename to "\347\254\2547\346\254\241\344\275\234\344\270\232/\345\274\240\347\233\212\351\243\236/Sqlhyper.cs" index b1d5e94ae3dd27f5d9e867fe46155d205b5ab62c..2533fbe9e21cf92ede1a17f0cb21529172091ceb 100644 --- "a/\347\254\2547\346\254\241\344\275\234\344\270\232/\345\274\240\347\233\212\351\243\236/Sqlserver.cs" +++ "b/\347\254\2547\346\254\241\344\275\234\344\270\232/\345\274\240\347\233\212\351\243\236/Sqlhyper.cs" @@ -1,82 +1,79 @@ using System; using System.Collections.Generic; -using System.Data; -using System.Data.SqlClient; using System.Linq; using System.Web; +using System.Data.SqlClient; +using System.Data; -namespace WebApplication2.Baga +namespace WebApplication1.Daywtwo { - public class Sqlserver + public class Sqlhyper { - private string strs = "server=LAPTOP-8HS8J7NL;uid=sa;pwd=2287431003a;database=Student_db"; + private static string consql = "server=.;uid=sa;pwd=123456;database=Student_db"; + private SqlConnection con = null; - public Sqlserver() { - con = new SqlConnection(strs); + public Sqlhyper() { + con= new SqlConnection(consql); } - public DataTable Get(string sql, SqlParameter[] parameters) - { + public DataTable Gettable(string sql,SqlParameter[] p) { try { - if (con.State == ConnectionState.Closed) + + SqlCommand command = new SqlCommand(sql, con); + + if (p != null) { - con.Open(); + command.Parameters.AddRange(p); } - SqlCommand command = new SqlCommand(sql, con); - if (parameters != null && parameters.Length != 0) + if (con.State == ConnectionState.Closed) { - command.Parameters.AddRange(parameters); + con.Open(); } - //SqlDataReader reader = command.ExecuteReader(); - //if (reader.Read()) - //{ - // Response.Redirect("sessend.aspx"); - //} HelpLink null string SqlDataAdapter adapter = new SqlDataAdapter(command); - DataSet dataSet = new DataSet(); - adapter.Fill(dataSet); - - return dataSet.Tables[0]; + DataSet set = new DataSet(); + adapter.Fill(set); + return set.Tables[0]; } catch (Exception ex) { + throw new Exception(ex.Message); } - finally - { - if (con != null) + finally { + if (con!=null) { con.Close(); } - } - } + } + } - public bool Extern(string sql, SqlParameter[] parameters) - { + public bool NotFind(string sql,SqlParameter[] p) { try { - if (con.State == ConnectionState.Closed) + SqlCommand command = new SqlCommand(sql, con); + if (p != null) { - con.Open(); + command.Parameters.AddRange(p); } - SqlCommand command = new SqlCommand(sql, con); - if (parameters != null && parameters.Length != 0) + if (con.State == ConnectionState.Closed) { - command.Parameters.AddRange(parameters); + con.Open(); } - return command.ExecuteNonQuery()>0; + return command.ExecuteNonQuery() > 0; } catch (Exception ex) { throw new Exception(ex.Message); } + finally { + if (con!=null) + { + con.Close(); + } + } } - - - - } } \ No newline at end of file diff --git "a/\347\254\2547\346\254\241\344\275\234\344\270\232/\345\274\240\347\233\212\351\243\236/resgin.aspx" "b/\347\254\2547\346\254\241\344\275\234\344\270\232/\345\274\240\347\233\212\351\243\236/resgin.aspx" deleted file mode 100644 index b4cfbb36ccd7a2ab7923dab9de5b65a3d5265ee2..0000000000000000000000000000000000000000 --- "a/\347\254\2547\346\254\241\344\275\234\344\270\232/\345\274\240\347\233\212\351\243\236/resgin.aspx" +++ /dev/null @@ -1,21 +0,0 @@ -<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="resgin.aspx.cs" Inherits="WebApplication2.Baga.resgin" %> - - - - - - - - - -
-
-

注册页面

- 账号: - 密码: - - -
-
- - diff --git "a/\347\254\2547\346\254\241\344\275\234\344\270\232/\345\274\240\347\233\212\351\243\236/resgin.aspx.cs" "b/\347\254\2547\346\254\241\344\275\234\344\270\232/\345\274\240\347\233\212\351\243\236/resgin.aspx.cs" deleted file mode 100644 index f1caba88369c2fa15c48e9f93357d6e5d675f560..0000000000000000000000000000000000000000 --- "a/\347\254\2547\346\254\241\344\275\234\344\270\232/\345\274\240\347\233\212\351\243\236/resgin.aspx.cs" +++ /dev/null @@ -1,80 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Data.SqlClient; -using System.Linq; -using System.Web; -using System.Web.UI; -using System.Web.UI.WebControls; - -namespace WebApplication2.Baga -{ - public partial class resgin : System.Web.UI.Page - { - private Sqlserver sqlserver = new Sqlserver(); - protected void Page_Load(object sender, EventArgs e) - { - - } - - protected void Button1_Click(object sender, EventArgs e) - { - string sql = "insert into StudentInfo(stu_name,password) values(@1,@2)"; - SqlParameter[] parameters ={ - new SqlParameter("@1",TextBox1.Text), - new SqlParameter("@2",TextBox2.Text) - }; - - - if (sqlserver.Extern(sql, parameters)) - { - Response.Redirect("Longer.aspx"); - } - else - { - Response.Redirect("resgin.aspx"); - } - - - //Response.Redirect("resgin.aspx"); - } - - - - - - - - - - //string str = "server=LAPTOP-8HS8J7NL;uid=sa;pwd=2287431003a;database=Student_db"; - - //SqlConnection con = new SqlConnection(str); - //con.Open(); - - //string sql = "insert into StudentInfo (stu_name,password) values(@name,@pwd)"; - //string name = TextBox1.Text; - //string pwd = TextBox2.Text; - - //SqlParameter[] parameters = { - //new SqlParameter("@name",name), - //new SqlParameter("@pwd",pwd) - //}; - - //SqlCommand command = new SqlCommand(sql, con); - //command.Parameters.AddRange(parameters); - - //int num = command.ExecuteNonQuery(); - //if (num > 0) - //{ - // Literal1.Text = "添加成功!!!"; - // Response.Redirect("Longer.aspx"); - //} - //else - //{ - // Literal1.Text = "添加失败!!!请重新添加!"; - // Response.Redirect("resgin.aspx"); - - //} - - } - } diff --git "a/\347\254\2547\346\254\241\344\275\234\344\270\232/\345\274\240\347\233\212\351\243\236/sessend.aspx" "b/\347\254\2547\346\254\241\344\275\234\344\270\232/\345\274\240\347\233\212\351\243\236/sessend.aspx" deleted file mode 100644 index 1613a375df018b81a473a72035d21d758fa6026a..0000000000000000000000000000000000000000 --- "a/\347\254\2547\346\254\241\344\275\234\344\270\232/\345\274\240\347\233\212\351\243\236/sessend.aspx" +++ /dev/null @@ -1,17 +0,0 @@ -<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="sessend.aspx.cs" Inherits="WebApplication2.Baga.sessend" %> - - - - - - - - - -
-
- -
-
- - diff --git "a/\347\254\2547\346\254\241\344\275\234\344\270\232/\345\274\240\347\233\212\351\243\236/sessend.aspx.cs" "b/\347\254\2547\346\254\241\344\275\234\344\270\232/\345\274\240\347\233\212\351\243\236/sessend.aspx.cs" deleted file mode 100644 index a559302c5d1953b7ae7f5ee357d001dfa055bc6b..0000000000000000000000000000000000000000 --- "a/\347\254\2547\346\254\241\344\275\234\344\270\232/\345\274\240\347\233\212\351\243\236/sessend.aspx.cs" +++ /dev/null @@ -1,24 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Web; -using System.Web.UI; -using System.Web.UI.WebControls; - -namespace WebApplication2.Baga -{ - public partial class sessend : System.Web.UI.Page - { - protected void Page_Load(object sender, EventArgs e) - { - if (Session["name"] == null) - { - - } - else - { - Response.Write($"欢迎{Session["name"]} 成功登入了!!!"); - } - } - } -} \ No newline at end of file