-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathForm4Class.cs
More file actions
191 lines (179 loc) · 6.08 KB
/
Copy pathForm4Class.cs
File metadata and controls
191 lines (179 loc) · 6.08 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
using MySql.Data.MySqlClient;
namespace _012;
//创建用户对象
public class User
{
// uname,ugroup,uemail,uphone
public string uname { get; set; }
public string ugroup { get; set; }
public string uemail { get; set; }
public string uphone { get; set; }
public string upassword { get; set; }
public void GetUserInfo()
{
try
{
using (MySqlConnection conn = new MySqlConnection(Form1.ConnectCfg))
{
conn.Open();
using (MySqlCommand cmd = new MySqlCommand("select uname,ugroup,uemail,uphone,upwd from user_info where uname=@uname", conn))
{
cmd.Parameters.AddWithValue("@uname", this.uname);
using (MySqlDataReader reader = cmd.ExecuteReader())
{
if (reader.Read())
{
this.uname = reader.GetString("uname");
this.ugroup = reader.GetString("ugroup");
this.uemail = reader.GetString("uemail");
this.uphone = reader.GetString("uphone");
this.upassword = reader.GetString("upwd");
}
}
}
}
}
catch (Exception e)
{
MessageBox.Show(e.Message);
// Console.WriteLine(e);
throw;
}
}
}
//创建工单对象
public class WorkOrder
{
public int wid { get; set; }
public string uname { get; set; }
public string wdate_submit { get; set; }
public string wtype { get; set; }
public string ISBN { get; set; }
public string wstatus { get; set; }
public string wpublisher { get; set; }
public string wdate_process { get; set; }
}
//创建公告对象
public class Notice
{
// public int Nid { get; set; }
public string Ndate { get; set; }
public string Ncontent { get; set; }
public string Npublisher { get; set; }
}
//创建书籍对象
public class Book
{
public string ISBN { get; set; }
public string Bname { get; set; }
public string Bauthor { get; set; }
public string Bpublisher { get; set; }
public string Bcategory { get; set; }
public int Bquantity { get; set; }
public int Blend { get; set; }
// 辅助方法,根据索引获取Book对象的属性值
public string GetPropertyByIndex(Book book, int index)
{
switch (index)
{
case 0: return book.ISBN;
case 1: return book.Bname;
case 2: return book.Bauthor;
case 3: return book.Bpublisher;
default: return string.Empty;
}
}
}
public class Form4Class
{
//获取公告列表的数据
public static List<Notice> GetAllNotices()
{
//创建公告列表
List<Notice> notices = new List<Notice>();
try
{
//连接数据库
using (MySqlConnection connection = new MySqlConnection(Form1.ConnectCfg))
{
connection.Open();
//公告按照时间降序排序
MySqlCommand command = new MySqlCommand("select * from notice order by ndate desc", connection);
MySqlDataReader reader = command.ExecuteReader();
while (reader.Read())
{
//把每条数据都加到notices列表中
Notice notice = new Notice();
// notice.Nid = reader.GetInt32(0);//id不需要显示
notice.Ndate = reader.GetDateTime(1).ToString("yyyy-MM-dd");
notice.Ncontent = reader.GetString(2);
notice.Npublisher = reader.GetString(3);
notices.Add(notice);
}
}
}
catch (Exception e)
{
MessageBox.Show(e.Message);
}
return notices;
}
//从数据库获取书籍列表
public static List<Book> GetAllBooks()
{
List<Book> books = new List<Book>();
//创建数据库链接
try
{
using (MySqlConnection conntection = new MySqlConnection(Form1.ConnectCfg))
{
conntection.Open();
MySqlCommand command = new MySqlCommand("select * from book_info", conntection);
MySqlDataReader reader = command.ExecuteReader();
while (reader.Read())
{
Book book = new Book();
book.ISBN = reader[0].ToString();
book.Bname = reader.GetString(1);
book.Bauthor = reader.GetString(2);
book.Bpublisher = reader.GetString(3);
book.Bcategory = reader.GetString(4);
book.Bquantity = reader.GetInt32(5);
book.Blend = reader.GetInt32(6);
books.Add(book);
}
}
}catch(Exception e){
MessageBox.Show(e.Message);
}
return books;
}
//获取所有用户的信息
public static List<User> GetAllUsers()
{
List<User> users = new List<User>();
try
{
using (MySqlConnection connection = new MySqlConnection(Form1.ConnectCfg))
{
connection.Open();
MySqlCommand command = new MySqlCommand("select uname,ugroup,uemail,uphone from user_info", connection);
MySqlDataReader reader = command.ExecuteReader();
while (reader.Read())
{
User user = new User();
user.uname = reader.GetString(0);
user.ugroup = reader.GetString(1);
user.uemail = reader.GetString(2);
user.uphone = reader.GetString(3);
user.upassword = "";
users.Add(user);
}
}
return users;
}catch(Exception e){
MessageBox.Show(e.Message);
return users;
}
}
}