二、项目源码Model层
DAL 层
DBHelper 类
using System ;using System .Collections .Generic ;using System .Data ;using System .Data .SqlClient ;using System .Linq ;using System .Text ;using System .Threading .Tasks ;namespace DAL { public class DBHelper { public static string ConnStr = "server=.;database=FinanceDB;uid=sa;pwd=123"; /// <summary> /// DBHelper 中的查询 /// </summary> /// <param name="sql"></param> /// <returns></returns> public static DataTable SelectBySql (string sql ) { SqlConnection connn = new SqlConnection (ConnStr ); connn .Open (); SqlDataAdapter sda = new SqlDataAdapter (sql ,connn ); DataTable tab = new DataTable (); sda .Fill (tab ); connn .Close (); return tab ; } /// <summary> /// DBHelper 中的 增加 删除 修改 /// </summary> /// <param name="sql"></param> /// <returns></returns> public static bool UpdOrDelOrIns (string sql ) { SqlConnection connn = new SqlConnection (ConnStr ); connn .Open (); SqlCommand command = new SqlCommand (sql , connn ); int result =command .ExecuteNon
Query (); connn .Close (); if (result >0) { return true ; }1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
RecordsDAL 类
BLL 层
return false ; } }}
47
48
49
50
51
52using System ;using System .Collections .Generic ;using System .Data ;using System .Linq ;usin
g System .Text ;using System .Threading .Tasks ;namespace DAL { /// <summary> /// DAL 层 /// </summary> public class RecordsDAL { /// <summary> /// DAL 层:查询方法 /// </summary> /// <returns></returns> public DataTable SelectDAL () { string sql = "select * from Records"; return DBHelper .SelectBySql (sql ); } /// <summary> /// DAL 层:删除方法 /// </summary> /// <param name="id"></param> /// <returns></returns> public bool DelDAL (int id ) { string sql = $"delete from Records where id ='{id}'"; return DBHelper .UpdOrDelOrIns (sql ); } }}1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
bootstrap 520
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37using System ;1
WEB 层
aspx 前端页面
using System .Collections .Generic ;using System .Data ;using System .Linq ;using System .Text ;using System .Threading .Tasks ;using DAL ;namespace BLL { /// <summary> /// BLL 层 /// </summary> public class RecordsBLL { /// <summary> /// BLL 层 查询方法 /// </sum
mary> /// <returns></returns> public DataTable SelectBLL () { RecordsDAL dal = new RecordsDAL (); return dal .SelectDAL (); } /// <summary> /// BLL 层 删除方法 /// </summary> /// <returns></returns> public bool DelBLL (int id ) { RecordsDAL dal = new RecordsDAL (); return dal .DelDAL (id ); } }}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37<head runat ="server"> <meta http-equiv ="Content-Type" content ="text/html; charset=utf-8" /> <title></title> <link href ="Css/bootstrap.css" rel ="stylesheet" /></head><body> <form id ="form1" runat ="server"> <div class ="container"> <asp:Repeater ID ="Repeater1" runat ="server"> <HeaderTemplate>1
2
3
4
5
6
7
8
9
10
CS 后端代码
<table class ="table table-hover text-center"> <thead class ="thead-light"> <tr> <th>编号</th> <th>时间</th> <th>名称</th> <th>类别</th> <th>金额</th> <th>操作</th> </tr> </thead> </HeaderTemplate> <ItemTemplate> <tbody> <tr> <td><%# Eval ("ID") %></td> <td><%# Eval ("OccurDate") %></td> <td><%# Eval ("Title")
%></td> <td><%# Eval ("Category") %></td> <td><%# Eval ("Amount") %></td> <%--OnCommand 生成事件属性 CommandArgument 获取选中ID --%> <td><asp:LinkButton Text ="删除" runat ="server"
ID ="BtnDel" OnCommand ="BtnDel_Command" CommandArgument ='<%# Eval ("ID") %>' /></td>
</tr> </tbody> </ItemTemplate> <FooterTemplate> </table> </FooterTemplate> </asp:Repeater> </div> </form></body></html>
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
3233
34
35
36
37
38
39
40
41
42
43using System ;using System .Collections .Generic ;using System .Linq ;using System .Web ;using System .Web .UI ;using System .Web .UI .WebControls ;using BLL ;namespace WEB { public partial class Index : System .Web .UI .Page {1
2
3
4
5
6
7
8
9
10
11
12
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论