-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathForm4.cs
More file actions
1450 lines (1351 loc) · 55.9 KB
/
Copy pathForm4.cs
File metadata and controls
1450 lines (1351 loc) · 55.9 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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using AntdUI;
using MySql.Data.MySqlClient;
namespace _012
{
public partial class Form4 : Form
{
public Form1 form1_;
public List<Book> books;
private List<WorkOrder> workorders;
private User user = new User();
//创建验证码存储变量
private int EmailVerifyCode;
private int EmailVerifyCode_right = 0;
//创建定时器,用于发送验证码之后进行时间限制
private System.Windows.Forms.Timer timer;
private System.Windows.Forms.Timer timer_right;
//创建验证码有效时间
private int EmailVerifyTime;
//创建用户列表
List<User> users = Form4Class.GetAllUsers();
// private Form1 form1_;
public Form4(Form1 form1)
{
//加载form1
form1_ = form1;
//窗体初始化
InitializeComponent();
//设置用户信息
try
{
user.uname = form1_.RegisterTextBox.Text;
user.GetUserInfo();
}
catch (Exception e)
{
MessageBox.Show(e.Message);
throw;
}
// Form1.user000.
MessageBox.Show("登录成功");
//创建保存图书信息的变量
books = Form4Class.GetAllBooks();
//创建保存工单信息的变量
workorders = getWorkOrder();
//备份图书数据
// var books_backup = new List<Book>(books);
//用户类型,如果不是管理员,则隐藏管理界面
if (form1_.UserType == "用户")
{
// MessageBox.Show("该账号不是管理员");
tabPage7.Parent = null;
}
//公告列表加载数据
// dataGridView1.DataSource = dataGridView1_LoadNotices(dataGridView1);
dataGridView1_LoadNotices(dataGridView1);
//图书推荐列表加载数据
DataGridView2_LoadBookInfo(dataGridView2);
//设置头像
pictureBox1.Image = form1_.RegisterPictureBox.Image;
//设置用户名
label2.Text = form1_.RegisterTextBox.Text;
//设置用户组
label3.Text = form1_.UserType;
//设置label4
label4.Text = "今天是" +
DateTime.Now.ToString("yyyy-MM-dd") +
",啊,真是美好的一天\n-----leetoxi";
this.FormClosing += Form_Close;
//工单管理界面加载数据
Table1_load(table1, workorders);
//工单搜索界面
input1.TextChanged += Search_TextChanged_Table1;
//工单处理按钮
button5.Click += button_Click;
button6.Click += button_Click;
//工单处理界面刷新按钮
button7.Click += button7_Click;
//加载借书列表
datagridView3_Load(dataGridView3, books); //借书界面
datagridView3_Load(dataGridView4, books); //还书界面
//搜索框搜索书籍,在借书和查找书籍界面添加
textBox2.TextChanged += Search_TextChanged_lend;
textBox3.TextChanged += Search_TextChanged_lend;
textBox4.TextChanged += Search_TextChanged_lend;
textBox5.TextChanged += Search_TextChanged_lend;
//借书页面获得相关信息
dataGridView3.CellClick += dataGridView3_CellClick;
//搜索界面点击表格获取相关信息
dataGridView4.CellClick += dataGridView4_CellClick;
//借按钮添加函数
button2.Click += button2_Click;
//查找书籍界面
textBox6.TextChanged += Search_TextChanged_SEARCH;
textBox7.TextChanged += Search_TextChanged_SEARCH;
textBox8.TextChanged += Search_TextChanged_SEARCH;
textBox9.TextChanged += Search_TextChanged_SEARCH;
//借书界面和搜书界面添加手动搜索按钮
button1.Click += button4_Click;
button4.Click += button4_Click;
//用户还书界面代码
//还书界面表格加载数据
Table2_load(table2, workorders);
//还书界面手动刷新表格按钮
button8.Click += button8_Click;
//还书页面通过isbn搜索工单
input2.TextChanged += Search_TextChanged_Table2;
//还书界面button11
button11.Click += button11_Click;
//验证码函数
//实例化timer
timer = new System.Windows.Forms.Timer();
timer_right = new System.Windows.Forms.Timer();
//设置触发时间间隔1000ms
timer.Interval = 1000;
timer_right.Interval = 1000;
//添加定时器触发函数
timer.Tick += timer_Tick;
timer_right.Tick += timer_Tick_pwd;
//个人信息界面
//加载用户数据
tabPage4_Load();
//左下更改邮箱验证码时的发送验证码按钮
button10.Click += button10_Click;
//左下用户提交更改信息
button12.Click += button12_Click;
//右下角发送验证码
button13.Click += button13_Click;
//右下角密码修改提交按钮
button14.Click += button14_Click;
//图书录入界面
button15.Click += button15_Click;
//图书修改界面,数据加载
dataGridView5_load(books);
//图书修改界面,数据搜索
// textBox1.TextChanged += Search_TextChanged_Manager;
// textBox10.TextChanged += Search_TextChanged_Manager;
// textBox11.TextChanged += Search_TextChanged_Manager;
textBox12.TextChanged += Search_TextChanged_Manager;
//图书修改界面点击显示图书详细信息
table4.CellClick += table4_CellClick;
//图书修改界面下架按钮
button17.Click += button17_Click;
//图书修改界面
button16.Click += button16_Click;
//用户管理界面
try
{
table3_Load(users);
}
catch (Exception e)
{
Console.WriteLine(e);
throw;
}
//用户管理搜索界面
textBox16.TextChanged += Search_TextChanged_UsersManager;
//用户管理页面选择函数
table3.CellClick += table3_CellClick;
//用户管理页面修改提交按钮
button20.Click += button20_Click;
}
//工单界面的刷新按钮button7
private void button7_Click(object sender, EventArgs e)
{
//刷新工单列表
workorders = getWorkOrder();
Table1_load(table1, workorders);
}
//工单界面的处理按钮,表示该工单处理完成button5和button6
private void button_Click(object sender, EventArgs e)
{
string target = "已处理";
//判断是那个按钮点击
if (sender == button5)
{
target = "已处理";
}
else if (sender == button6)
{
target = "已拒绝";
}
//如果selectedIndex为-1,则是没有选中
if (table1.SelectedIndex == -1)
{
MessageBox.Show("请选择工单进行操作");
return;
}
// MessageBox.Show(workorder_id);
//更新工单状态
// 连接数据库
try
{
//获取选择到的工单的工单号
string workorder_id = workorders[table1.SelectedIndex - 1].wid.ToString();
using (MySqlConnection connect = new MySqlConnection(Form1.ConnectCfg))
{
connect.Open();
string sql =
"update work_order set wstatus = @target,wpublisher=@uname,wdate_process = @date where wid = @wid";
MySqlCommand command = new MySqlCommand(sql, connect);
command.Parameters.AddWithValue("@target", target);
command.Parameters.AddWithValue("@wid", workorder_id);
command.Parameters.AddWithValue("@uname", form1_.RegisterTextBox.Text);
command.Parameters.AddWithValue("@date", DateTime.Now.ToString("yyyy-MM-dd"));
command.ExecuteNonQuery();
}
//刷新工单列表
workorders = getWorkOrder();
Table1_load(table1, workorders);
}
catch (Exception exception)
{
// Console.WriteLine(exception);
// AntdUI.
MessageBox.Show(exception.Message);
throw;
}
}
//工单处理界面的查询按钮button3
private void button3_Click(object sender, EventArgs e)
{
//调用更新工单列表的函数
Search_TextChanged_Table1(null, null);
}
//窗体关闭时打开form1
public void Form_Close(object sender, FormClosingEventArgs e)
{
form1_.Show();
}
private void tabControl2_SelectedIndexChanged(object sender, EventArgs e)
{
}
//公告列表加载数据
private void dataGridView1_LoadNotices(DataGridView dataGridViewNotices)
{
List<Notice> list = Form4Class.GetAllNotices();
dataGridViewNotices.AutoGenerateColumns = true; // 自动为数据源生成列
dataGridViewNotices.DataSource = null; // 清空现有数据源
dataGridViewNotices.DataSource = list;
//更改列名
dataGridViewNotices.Columns["Ncontent"].HeaderText = "公告内容";
dataGridViewNotices.Columns["Npublisher"].HeaderText = "发布人";
dataGridViewNotices.Columns["Ndate"].HeaderText = "发布时间";
//设置相对列宽
dataGridViewNotices.Columns[1].FillWeight = 0.6f;
dataGridViewNotices.Columns[2].FillWeight = 0.2f;
dataGridViewNotices.Columns[0].FillWeight = 0.2f;
dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
// dataGridView1.RowHeadersWidth = 10;
dataGridView1.RowHeadersVisible = false;
}
//每日推荐,现阶段推荐采取的是随机推荐
//考虑的是根据每个学生的借阅记录,来推荐图书
private void DataGridView2_LoadBookInfo(DataGridView dataGridViewBookInfo)
{
dataGridViewBookInfo.AutoGenerateColumns = false; // 不自动为数据源生成列
dataGridViewBookInfo.DataSource = null; // 清空现有数据源
dataGridViewBookInfo.RowHeadersVisible = false; //删除开头的空列
//增加数据列5列
DataGridViewTextBoxColumn column0 = new DataGridViewTextBoxColumn();
column0.DataPropertyName = "Bname"; // 数据源中的字段名
column0.HeaderText = "书名"; // 显示在列头的文本
dataGridViewBookInfo.Columns.Add(column0);
DataGridViewTextBoxColumn column1 = new DataGridViewTextBoxColumn();
column1.DataPropertyName = "Bauthor";
column1.HeaderText = "作者";
dataGridViewBookInfo.Columns.Add(column1);
DataGridViewTextBoxColumn column2 = new DataGridViewTextBoxColumn();
column2.DataPropertyName = "Bpublisher";
column2.HeaderText = "出版社";
dataGridViewBookInfo.Columns.Add(column2);
DataGridViewTextBoxColumn column3 = new DataGridViewTextBoxColumn();
column3.DataPropertyName = "Bcategory";
column3.HeaderText = "类别";
dataGridViewBookInfo.Columns.Add(column3);
//加载数据源(随机抽取12本书)
Random random = new Random();
var books_out = new List<Book>();
var books_tmp = new List<Book>(books);
for (int i = 0; i < 11; i++)
{
int index = random.Next(books_tmp.Count);
books_out.Add(books_tmp[index]);
books_tmp.RemoveAt(index);
}
dataGridViewBookInfo.DataSource = books_out;
//设置列宽
dataGridViewBookInfo.Columns[0].FillWeight = 0.4f;
dataGridViewBookInfo.Columns[1].FillWeight = 0.2f;
dataGridViewBookInfo.Columns[2].FillWeight = 0.2f;
dataGridViewBookInfo.Columns[3].FillWeight = 0.2f;
dataGridViewBookInfo.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
}
//还书界面,第一次运行时加载所有的书籍,然后通过各类搜索来列入所获取到的书籍
private void datagridView3_Load(DataGridView dataGridView3, List<Book> books)
{
//关闭自动设置列名
dataGridView3.AutoGenerateColumns = true;
dataGridView3.DataSource = null; //清空数据
dataGridView3.RowHeadersVisible = false; //删除开头的空列
//第一例设置
DataGridViewTextBoxColumn column0 = new DataGridViewTextBoxColumn();
column0.DataPropertyName = "ISBN"; //数据源中的字段名
column0.HeaderText = "ISBN";
dataGridView3.Columns.Add(column0);
//第二例设置
DataGridViewTextBoxColumn column1 = new DataGridViewTextBoxColumn();
column1.DataPropertyName = "Bname"; // 数据源中的字段名
column1.HeaderText = "书名"; // 显示在列头的文本
dataGridView3.Columns.Add(column1);
//第三例设置
DataGridViewTextBoxColumn column2 = new DataGridViewTextBoxColumn();
column2.DataPropertyName = "Bauthor";
column2.HeaderText = "作者";
dataGridView3.Columns.Add(column2);
//第四例设置
DataGridViewTextBoxColumn column3 = new DataGridViewTextBoxColumn();
column3.DataPropertyName = "Bpublisher";
column3.HeaderText = "出版社";
dataGridView3.Columns.Add(column3);
//第五例设置
DataGridViewTextBoxColumn column4 = new DataGridViewTextBoxColumn();
column4.DataPropertyName = "Bcategory";
column4.HeaderText = "类别";
dataGridView3.Columns.Add(column4);
//第六列设置
DataGridViewTextBoxColumn column5 = new DataGridViewTextBoxColumn();
column5.DataPropertyName = "Bquantity";
column5.HeaderText = "库存";
dataGridView3.Columns.Add(column5);
//第七列
DataGridViewTextBoxColumn column6 = new DataGridViewTextBoxColumn();
column6.DataPropertyName = "Blend";
column6.HeaderText = "已借出";
dataGridView3.Columns.Add(column6);
//加载数据
dataGridView3.DataSource = books;
//列宽自动填充
dataGridView3.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
}
//借书界面搜索框
private void Search_TextChanged_lend(object sender, EventArgs e)
{
//判断四个搜索框为空则返回原本的书籍列表
if (textBox2.Text == "" && textBox3.Text == "" && textBox4.Text == "" && textBox5.Text == "")
{
datagridView3_Load(dataGridView3, books);
return;
}
//获取搜索的条件
List<string> search_list = new List<string>()
{ textBox2.Text, textBox3.Text, textBox4.Text, textBox5.Text };
//创建要展示的书籍列表
//复制书籍列表
List<Book> books_tmp = new List<Book>(books);
List<Book> books_out = new List<Book>();
books_out.Clear();
try
{
foreach (var item in books_tmp)
{
if (
(!string.IsNullOrEmpty(search_list[0]) && item.ISBN.Contains(search_list[0])) ||
(!string.IsNullOrEmpty(search_list[1]) && item.Bname.Contains(search_list[1])) ||
(!string.IsNullOrEmpty(search_list[2]) && item.Bauthor.Contains(search_list[2])) ||
(!string.IsNullOrEmpty(search_list[3]) && item.Bpublisher.Contains(search_list[3]))
)
{
books_out.Add(item);
}
}
//显示书籍
datagridView3_Load(dataGridView3, books_out);
}
catch (Exception exception)
{
Console.WriteLine(exception);
throw;
}
}
//搜书界面搜索框
private void Search_TextChanged_SEARCH(object sender, EventArgs e)
{
//判断四个搜索框为空则返回原本的书籍列表
if (textBox9.Text == "" && textBox8.Text == "" && textBox7.Text == "" && textBox6.Text == "")
{
datagridView3_Load(dataGridView4, books);
return;
}
//获取搜索的条件
List<string> search_list = new List<string>()
{ textBox9.Text, textBox8.Text, textBox7.Text, textBox6.Text };
//创建要展示的书籍列表
//复制书籍列表
List<Book> books_tmp = new List<Book>(books);
List<Book> books_out = new List<Book>();
books_out.Clear();
try
{
foreach (var item in books_tmp)
{
if (
(!string.IsNullOrEmpty(search_list[0]) && item.ISBN.Contains(search_list[0])) ||
(!string.IsNullOrEmpty(search_list[1]) && item.Bname.Contains(search_list[1])) ||
(!string.IsNullOrEmpty(search_list[2]) && item.Bauthor.Contains(search_list[2])) ||
(!string.IsNullOrEmpty(search_list[3]) && item.Bpublisher.Contains(search_list[3]))
)
{
books_out.Add(item);
}
}
//显示书籍
datagridView3_Load(dataGridView4, books_out);
}
catch (Exception exception)
{
Console.WriteLine(exception);
throw;
}
}
private void tabPage12_Click(object sender, EventArgs e)
{
}
//手动查询按钮
private void button4_Click(object sender, EventArgs e)
{
//判断是button4还是button1
if (sender == button1)
{
Search_TextChanged_lend(sender, e);
return;
}
Search_TextChanged_SEARCH(sender, e);
}
//点击书的列表之后的操作函数-->借书界面
private void dataGridView3_CellClick(object sender, DataGridViewCellEventArgs e)
{
try
{
//设置书名
label12.Text = dataGridView3.CurrentRow.Cells[1].Value.ToString();
//设置作者
label13.Text = dataGridView3.CurrentRow.Cells[2].Value.ToString();
//设置出版社
label14.Text = dataGridView3.CurrentRow.Cells[3].Value.ToString();
//设置类别
label16.Text = dataGridView3.CurrentRow.Cells[4].Value.ToString();
}
catch (Exception exception)
{
Console.WriteLine(exception);
throw;
}
}
//点击书的列表之后的操作函数-->搜索书籍界面
private void dataGridView4_CellClick(object sender, DataGridViewCellEventArgs e)
{
try
{
//设置书名
label20.Text = dataGridView4.CurrentRow.Cells[1].Value.ToString();
//设置作者
label17.Text = dataGridView4.CurrentRow.Cells[2].Value.ToString();
//设置出版社
label19.Text = dataGridView4.CurrentRow.Cells[3].Value.ToString();
//设置类别
label18.Text = dataGridView4.CurrentRow.Cells[4].Value.ToString();
}
catch (Exception exception)
{
Console.WriteLine(exception);
throw;
}
}
//点击借按钮时的函数
private void button2_Click(object sender, EventArgs e)
{
try
{
string ISBN = dataGridView3.CurrentRow.Cells[0].Value.ToString();
if (ISBN == "")
{
MessageBox.Show("请选择要借的书");
return;
}
//链接数据库.提交借书预约信息
string sql = "insert into work_order(uname,wdate_submit,wtype,ISBN,wstatus)" +
"values (@uname,@wdate_submi,@wtype,@ISBN,@wstatus)";
using (MySqlConnection conn = new MySqlConnection(Form1.ConnectCfg))
{
conn.Open();
MySqlCommand command = new MySqlCommand(sql, conn);
command.Parameters.AddWithValue("@uname", label2.Text);
command.Parameters.AddWithValue("@wdate_submi", DateTime.Now);
command.Parameters.AddWithValue("@wtype", "借");
command.Parameters.AddWithValue("@ISBN", ISBN);
command.Parameters.AddWithValue("@wstatus", "未处理");
command.ExecuteNonQuery();
MessageBox.Show("借书预约成功\n请到图书馆取书");
}
}
catch (Exception exception)
{
Console.WriteLine(exception);
throw;
}
}
//工单处理界面
//从数据库加载工单内容
private List<WorkOrder> getWorkOrder()
{
List<WorkOrder> workorders = new List<WorkOrder>();
//链接数据库
try
{
//按照时间降序排序
string sql = "select * from work_order order by wdate_submit desc";
using (MySqlConnection conn = new MySqlConnection(Form1.ConnectCfg))
{
conn.Open();
MySqlCommand command = new MySqlCommand(sql, conn);
MySqlDataReader reader = command.ExecuteReader();
while (reader.Read())
{
WorkOrder workorder = new WorkOrder();
workorder.wid = reader.GetInt32(0);
workorder.uname = reader.GetString(1);
workorder.wdate_submit = reader.GetDateTime(2).ToString("yyyy-MM-dd");
workorder.wtype = reader.GetString(3);
workorder.ISBN = reader.GetString(4);
workorder.wstatus = reader.GetString(5);
workorder.wpublisher = reader.GetString(6);
workorder.wdate_process = reader.GetDateTime(7).ToString("yyyy-MM-dd");
workorders.Add(workorder);
}
}
return workorders;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
return null;
}
}
//加载工单数据到工单gridPanel
private void Table1_load(Table table, List<WorkOrder> workorders)
{
try
{
//清空数据
table.DataSource = null;
table.DataSource = workorders;
// table.Columns[0].Visible = false;
// table.Columns[0].Key = "wid";
table.Columns = new Column[]
{
new Column("wid", "工单号"),
new Column("uname", "用户名"),
new Column("wdate_submit", "提交时间"),
new Column("wtype", "类型"),
new Column("ISBN", "ISBN"),
new Column("wstatus", "状态"),
new Column("wpublisher", "处理人"),
new Column("wdate_process", "处理时间")
};
}
catch (Exception exception)
{
Console.WriteLine(exception);
throw;
}
}
//工单处理界面的搜索框搜索用户名
private void Search_TextChanged_Table1(object sender, EventArgs e)
{
//创建临时工单数据
List<WorkOrder> workorders_tmp = new List<WorkOrder>();
try
{
if (input1.Text == "")
{
Table1_load(table1, workorders);
}
else
{
//搜索用户名
foreach (WorkOrder workorder in workorders)
{
if (workorder.uname.Contains(input1.Text))
{
workorders_tmp.Add(workorder);
}
}
Table1_load(table1, workorders_tmp);
}
}
catch (Exception exception)
{
Console.WriteLine(exception);
throw;
}
}
private void avatar1_Click(object sender, EventArgs e)
{
}
private void panel7_Click(object sender, EventArgs e)
{
}
//还书界面
//table2加载工单数据
private void Table2_load(Table table, List<WorkOrder> workorders)
{
try
{
//首先处理数据,因为还书只需要还自己的
List<WorkOrder> workorders_tmp = new List<WorkOrder>();
foreach (WorkOrder workorder in workorders)
{
if (workorder.uname == label2.Text &&
workorder.wstatus == "未处理" &&
workorder.wtype == "借")
{
workorders_tmp.Add(workorder);
}
}
//获取完成,展示数据
table.DataSource = null;
table.DataSource = workorders_tmp;
table.Columns = new Column[]
{
new Column("wid", "工单号"),
new Column("uname", "用户名"),
new Column("wdate_submit", "提交时间"),
new Column("wtype", "类型"),
new Column("ISBN", "ISBN"),
new Column("wstatus", "状态"),
new Column("wpublisher", "处理人"),
new Column("wdate_process", "处理时间")
};
if (workorders_tmp.Count == 0)
{
label3.Text = "暂无工单";
}
else
{
label3.Text = "";
}
}
catch (Exception exception)
{
Console.WriteLine(exception);
throw;
}
}
//还书界面手动刷新按钮button8
private void button8_Click(object sender, EventArgs e)
{
workorders = getWorkOrder();
Table2_load(table2, workorders);
}
//还书界面搜索工单的input2,通过搜索ISBN来查询工单
private void Search_TextChanged_Table2(object sender, EventArgs e)
{
//如果搜索框被清空
if (input2.Text == "")
{
workorders = getWorkOrder();
Table2_load(table2, workorders);
return;
}
//获取当前工单数据
List<WorkOrder> workorders_tmp = new List<WorkOrder>();
foreach (WorkOrder workorder in workorders)
{
if (workorder.uname == label2.Text &&
workorder.wstatus == "未处理" &&
workorder.ISBN.Contains(input2.Text) &&
workorder.wtype == "借"
)
{
workorders_tmp.Add(workorder);
}
}
//加载数据
Table2_load(table2, workorders_tmp);
}
//button11手动查询按钮
private void button11_Click(object sender, EventArgs e)
{
Search_TextChanged_Table2(sender, e);
}
//还书按钮button9
private void button9_Click(object sender, EventArgs e)
{
try
{
//首先获取工单
if (table2.SelectedIndex == -1)
{
MessageBox.Show("请选择要还的书");
return;
}
//获取工单id
string wid = workorders[table2.SelectedIndex].wid.ToString();
//开启数据库链接
using (MySqlConnection connection = new MySqlConnection(Form1.ConnectCfg))
{
connection.Open();
//提交还书工单
string sql = "Insert into work_order(uname,wdate_submit,wtype,ISBN,wstatus) " +
"values(@uname,@wdate_submit,'还',@ISBN,'未处理')";
MySqlCommand command = new MySqlCommand(sql, connection);
command.Parameters.AddWithValue("@uname", label2.Text);
command.Parameters.AddWithValue("@wdate_submit", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
command.Parameters.AddWithValue("@ISBN", workorders[table2.SelectedIndex].ISBN);
command.ExecuteNonQuery();
connection.Close();
}
//还书工单成功
MessageBox.Show("预约还书成功!\n请携书前往图书馆");
}
catch (Exception exception)
{
MessageBox.Show("异常");
throw;
}
}
private void label47_Click(object sender, EventArgs e)
{
}
//个人信息页面
//个人信息界面加载数据
private void tabPage4_Load()
{
//设置头像
pictureBox2.Image = form1_.RegisterPictureBox.Image;
avatar3.Image = form1_.RegisterPictureBox.Image;
//设置用户名
label31.Text = user.uname;
label33.Text = user.uname;
//设置用户组
label30.Text = user.ugroup;
label34.Text = user.ugroup;
//设置邮箱
label36.Text = user.uemail;
//设置电话号码
label37.Text = user.uphone;
}
//个人信息界面的左下侧发送验证码,只有更改邮箱的时候需要发送,其它信息直接修改
private void button10_Click(object sender, EventArgs e)
{
//邮箱为空,说明该用户不修改邮箱
if (input4.Text == "")
{
MessageBox.Show("修改邮箱才需要发送验证码");
return;
}
//修改了邮箱,所以需要发送验证码
string email = user.uemail;
//执行发送验证码函数
EmailVerifyCode = Email.SendVerificationCode(email, user.uname);
//验证码发送成功,开始倒计时,600秒内有效
EmailVerifyTime = 600;
timer.Start();
}
//验证码发送函数
private void timer_Tick(object sender, EventArgs e)
{
//验证码有效时间
// int time = 600;
if (EmailVerifyTime > 0)
{
button12.BackColor = Color.FloralWhite;
//设置显示组件
label41.Text = $"{EmailVerifyTime}s 内有效";
//设置按钮可用
button12.Enabled = true;
//每秒减一
EmailVerifyTime--;
}
else
{
label41.Text = "验证码已失效";
button12.Enabled = false;
button12.BackColor = Color.Red;
timer.Stop();
}
}
//修改个人信息时的提交按钮,首先用户是否更改邮箱,更改的话需要查看是否有验证码,没有则需要发送验证码
private void button12_Click(object sender, EventArgs e)
{
bool isChangeEmail = false;
// 创建临时数据
User user_tmp = user;
// 首先用户是否更改邮箱,更改的话需要查看是否有验--嶳鬱™证码,没有则需要发送验证码
if (input4.Text != "")
{
if (input6.Text != EmailVerifyCode.ToString())
{
MessageBox.Show("验证码错误");
return;
}
else if (input6.Text == "")
{
MessageBox.Show("请先输入验证码");
return;
}
else if (input6.Text == EmailVerifyCode.ToString())
{
//说明用户需要修改邮箱
isChangeEmail = true;
}
}
//邮箱检查结束,开始修改个人信息
//判断其它三个信息是否为空,为空则代表用户什么都没写就点击了提交按钮
if (input3.Text == "" &&
input5.Text == "")
{
MessageBox.Show("请输入需要修改的信息");
return;
}
//开始判断用户需要修改的是那个信息
if (input3.Text != "")
{
//修改用户名
user.uname = input3.Text;
}
if (input5.Text != "")
{
//修改电话号码
user.uphone = input5.Text;
}
if (isChangeEmail)
{
//修改邮箱
user.uemail = input4.Text;
}
//开始更新数据
try
{
//链接数据库
using (MySqlConnection connection = new MySqlConnection(Form1.ConnectCfg))
{
connection.Open();
string sql = "update user_info set " +
"uname = @uname,uphone = @uphone,uemail = @uemail " +
"where uname = @uname_tmp";
MySqlCommand command = new MySqlCommand(sql, connection);
command.Parameters.AddWithValue("@uname", user.uname);
command.Parameters.AddWithValue("@uphone", user.uphone);
command.Parameters.AddWithValue("@uemail", user.uemail);
command.Parameters.AddWithValue("@uname_tmp", user_tmp.uname);
command.ExecuteNonQuery();
MessageBox.Show("修改成功");
}
}
catch (Exception exception)
{
MessageBox.Show("异常" + exception.Message);
//修改失败,返回以前的数据
user = user_tmp;
throw;
}
}
//个人信息界面,右下角发送验证码
private void button13_Click(object sender, EventArgs e)
{
if (input9.Text != "")
{
MessageBox.Show("采用原密码修改时不用发送验证码");
return;
}
//修改了邮箱,所以需要发送验证码
string email = user.uemail;
//执行发送验证码函数
EmailVerifyCode_right = Email.SendVerificationCode(email, user.uname);
//验证码发送成功,开始倒计时,600秒内有效
EmailVerifyTime = 600;
timer.Start();
}
//验证码发送函数
private void timer_Tick_pwd(object sender, EventArgs e)
{
//验证码有效时间
// int time = 600;
if (EmailVerifyTime > 0)
{
button14.BackColor = Color.FloralWhite;
//设置显示组件
label48.Text = $"{EmailVerifyTime}s 内有效";
//设置按钮可用
button14.Enabled = true;
//每秒减一
EmailVerifyTime--;
}
else
{
label48.Text = "验证码已失效";
button14.Enabled = false;
button14.BackColor = Color.Red;
timer.Stop();
}
}
//右侧修改密码时的提交按钮
private void button14_Click(object sender, EventArgs e)
{
// 创建临时数据
User user_tmp = user;
//首先检查原密码是否输入
if (input9.Text == "")
{
//检查是否输入验证码
if (input10.Text == "")
{