From 647a162da248470eb76470b68a865a65eebd3746 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E8=B7=91=E8=B7=91?= <1599857331@qq.com> Date: Fri, 25 Jun 2021 12:08:32 +0000 Subject: [PATCH 1/2] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=20?= =?UTF-8?q?=E7=AC=AC7=E6=AC=A1=E4=BD=9C=E4=B8=9A/=E5=BC=A0=E7=9B=8A?= =?UTF-8?q?=E9=A3=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Longer.aspx" | 21 ---- .../Longer.aspx.cs" | 95 ------------------- .../SqlHelper.cs" | 6 -- .../Sqlserver.cs" | 82 ---------------- .../resgin.aspx" | 21 ---- .../resgin.aspx.cs" | 80 ---------------- .../sessend.aspx" | 17 ---- .../sessend.aspx.cs" | 24 ----- 8 files changed, 346 deletions(-) delete mode 100644 "\347\254\2547\346\254\241\344\275\234\344\270\232/\345\274\240\347\233\212\351\243\236/Longer.aspx" delete mode 100644 "\347\254\2547\346\254\241\344\275\234\344\270\232/\345\274\240\347\233\212\351\243\236/Longer.aspx.cs" delete mode 100644 "\347\254\2547\346\254\241\344\275\234\344\270\232/\345\274\240\347\233\212\351\243\236/SqlHelper.cs" delete mode 100644 "\347\254\2547\346\254\241\344\275\234\344\270\232/\345\274\240\347\233\212\351\243\236/Sqlserver.cs" delete mode 100644 "\347\254\2547\346\254\241\344\275\234\344\270\232/\345\274\240\347\233\212\351\243\236/resgin.aspx" delete mode 100644 "\347\254\2547\346\254\241\344\275\234\344\270\232/\345\274\240\347\233\212\351\243\236/resgin.aspx.cs" delete mode 100644 "\347\254\2547\346\254\241\344\275\234\344\270\232/\345\274\240\347\233\212\351\243\236/sessend.aspx" delete mode 100644 "\347\254\2547\346\254\241\344\275\234\344\270\232/\345\274\240\347\233\212\351\243\236/sessend.aspx.cs" 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" deleted file mode 100644 index e73a5ac..0000000 --- "a/\347\254\2547\346\254\241\344\275\234\344\270\232/\345\274\240\347\233\212\351\243\236/Longer.aspx" +++ /dev/null @@ -1,21 +0,0 @@ -<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Longer.aspx.cs" Inherits="WebApplication2.Baga.Longer" %> - - - - - - - - - -
-
- 账号: - 密码: - - - -
-
- - 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" deleted file mode 100644 index 1dcaf8a..0000000 --- "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" +++ /dev/null @@ -1,95 +0,0 @@ -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; - -namespace WebApplication2.Baga -{ - public partial class Longer : 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 = "select*from studentinfo where stu_name=@name and password=@paw"; - - SqlParameter[] para ={ - new SqlParameter("@name",TextBox1.Text), - new SqlParameter("@paw",TextBox2.Text) - }; - - - DataTable table= sqlserver.Get(sql, para); - if (table.Rows.Count > 0) - { - Session["name"] = TextBox1.Text; - Response.Redirect("sessend.aspx"); - } - else { - 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) - { - - Response.Redirect("resgin.aspx"); - } - - - - - - } -} \ 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 2459843..0000000 --- "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/Sqlserver.cs" deleted file mode 100644 index b1d5e94..0000000 --- "a/\347\254\2547\346\254\241\344\275\234\344\270\232/\345\274\240\347\233\212\351\243\236/Sqlserver.cs" +++ /dev/null @@ -1,82 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Data; -using System.Data.SqlClient; -using System.Linq; -using System.Web; - -namespace WebApplication2.Baga -{ - public class Sqlserver - { - private string strs = "server=LAPTOP-8HS8J7NL;uid=sa;pwd=2287431003a;database=Student_db"; - private SqlConnection con = null; - - public Sqlserver() { - con = new SqlConnection(strs); - } - public DataTable Get(string sql, SqlParameter[] parameters) - { - try - { - if (con.State == ConnectionState.Closed) - { - con.Open(); - } - SqlCommand command = new SqlCommand(sql, con); - if (parameters != null && parameters.Length != 0) - { - command.Parameters.AddRange(parameters); - } - //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]; - } - catch (Exception ex) - { - throw new Exception(ex.Message); - } - finally - { - if (con != null) - { - con.Close(); - } - } - } - - public bool Extern(string sql, SqlParameter[] parameters) - { - try - { - if (con.State == ConnectionState.Closed) - { - con.Open(); - } - SqlCommand command = new SqlCommand(sql, con); - if (parameters != null && parameters.Length != 0) - { - command.Parameters.AddRange(parameters); - } - return command.ExecuteNonQuery()>0; - } - catch (Exception ex) - { - - throw new Exception(ex.Message); - } - } - - - - - - } -} \ 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 b4cfbb3..0000000 --- "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 f1caba8..0000000 --- "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 1613a37..0000000 --- "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 a559302..0000000 --- "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 -- Gitee From 5fd5ebbd7ea2b108f3f1b8d38576ad14f8a21625 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E8=B7=91=E8=B7=91?= <1599857331@qq.com> Date: Fri, 25 Jun 2021 12:08:50 +0000 Subject: [PATCH 2/2] =?UTF-8?q?=E5=90=AC=E4=B8=8D=E6=87=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Longer.aspx" | 62 +++++++++ .../Longer.aspx.cs" | 127 ++++++++++++++++++ .../Sqlhyper.cs" | 79 +++++++++++ 3 files changed, 268 insertions(+) create mode 100644 "\347\254\2547\346\254\241\344\275\234\344\270\232/\345\274\240\347\233\212\351\243\236/Longer.aspx" create mode 100644 "\347\254\2547\346\254\241\344\275\234\344\270\232/\345\274\240\347\233\212\351\243\236/Longer.aspx.cs" create mode 100644 "\347\254\2547\346\254\241\344\275\234\344\270\232/\345\274\240\347\233\212\351\243\236/Sqlhyper.cs" 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" new file mode 100644 index 0000000..8025c74 --- /dev/null +++ "b/\347\254\2547\346\254\241\344\275\234\344\270\232/\345\274\240\347\233\212\351\243\236/Longer.aspx" @@ -0,0 +1,62 @@ +<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Longer.aspx.cs" Inherits="WebApplication1.Daywtwo.Longer" %> + + + + + + + + + +
+
+ +
+
+ + + + + + + + + + + + + + + + + + +
姓名: + +
邮箱: + +
信息: + +
+ +
+
+
+ + + + + + + + + + + + + + +
+
+ + 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" new file mode 100644 index 0000000..4e54946 --- /dev/null +++ "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" @@ -0,0 +1,127 @@ +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; +using System.Data; + + +namespace WebApplication1.Daywtwo +{ + public partial class Longer : System.Web.UI.Page + { + 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) + }; + + + GridView1.DataSource =Sqlhyper.Gettable(sql, parameters); + GridView1.DataBind(); + + } + + 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)) + { + Literal1.Text = "添加成功!!!"; + GridViewText(); + } + else { + Literal1.Text = "添加失败!!!"; + } + } + + protected void GridView1_RowEditing1(object sender, GridViewEditEventArgs e) + { + 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/Sqlhyper.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" new file mode 100644 index 0000000..2533fbe --- /dev/null +++ "b/\347\254\2547\346\254\241\344\275\234\344\270\232/\345\274\240\347\233\212\351\243\236/Sqlhyper.cs" @@ -0,0 +1,79 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; +using System.Data.SqlClient; +using System.Data; + +namespace WebApplication1.Daywtwo +{ + public class Sqlhyper + { + private static string consql = "server=.;uid=sa;pwd=123456;database=Student_db"; + + private SqlConnection con = null; + + public Sqlhyper() { + con= new SqlConnection(consql); + } + public DataTable Gettable(string sql,SqlParameter[] p) { + try + { + + SqlCommand command = new SqlCommand(sql, con); + + if (p != null) + { + command.Parameters.AddRange(p); + } + if (con.State == ConnectionState.Closed) + { + con.Open(); + } + SqlDataAdapter adapter = new SqlDataAdapter(command); + DataSet set = new DataSet(); + adapter.Fill(set); + return set.Tables[0]; + } + catch (Exception ex) + { + + throw new Exception(ex.Message); + } + finally { + if (con!=null) + { + con.Close(); + } + } + } + + public bool NotFind(string sql,SqlParameter[] p) { + try + { + SqlCommand command = new SqlCommand(sql, con); + if (p != null) + { + command.Parameters.AddRange(p); + } + if (con.State == ConnectionState.Closed) + { + con.Open(); + } + return command.ExecuteNonQuery() > 0; + } + catch (Exception ex) + { + + throw new Exception(ex.Message); + } + finally { + if (con!=null) + { + con.Close(); + } + } + } + + } +} \ No newline at end of file -- Gitee