-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQuanLyDocGia.java
1420 lines (1297 loc) · 68.2 KB
/
QuanLyDocGia.java
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
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package quanlythuvien;
import java.awt.Desktop;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.apache.poi.ss.usermodel.DateUtil;
import org.apache.poi.ss.util.NumberToTextConverter;
import org.apache.poi.xwpf.usermodel.IBodyElement;
import org.apache.poi.xwpf.usermodel.TableRowAlign;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.xwpf.usermodel.XWPFTable;
import org.apache.poi.xwpf.usermodel.XWPFTableRow;
/**
*
* @author Đình Phúc
*/
public class QuanLyDocGia extends javax.swing.JFrame {
/**
* Creates new form QuanLyDocGia
*/
DefaultTableModel model;
MyConnect myConnect = new MyConnect();
Connection conn = myConnect.connect();
PreparedStatement ps = null;
int rowID = 0;
boolean fileOut = true;
public QuanLyDocGia() {
initComponents();
model = (DefaultTableModel) Table1.getModel();
removeAllRow();
showTable(getListDG());
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
jPanel1 = new javax.swing.JPanel();
buttonGroup1 = new javax.swing.ButtonGroup();
jTabbedPane1 = new javax.swing.JTabbedPane();
jPanel3 = new javax.swing.JPanel();
jDesktopPane2 = new javax.swing.JDesktopPane();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jLabel4 = new javax.swing.JLabel();
jLabel7 = new javax.swing.JLabel();
maDG = new javax.swing.JTextField();
tenDG = new javax.swing.JTextField();
ngaySinh = new javax.swing.JTextField();
gioiTinh = new javax.swing.JTextField();
diaChi = new javax.swing.JTextField();
sDT = new javax.swing.JTextField();
cmnd = new javax.swing.JTextField();
jLabel5 = new javax.swing.JLabel();
jLabel6 = new javax.swing.JLabel();
Them = new javax.swing.JButton();
Sua = new javax.swing.JButton();
Xoa = new javax.swing.JButton();
jScrollPane1 = new javax.swing.JScrollPane();
Table1 = new javax.swing.JTable();
comboTimKiem = new javax.swing.JComboBox<>();
jButton10 = new javax.swing.JButton();
timKiem = new javax.swing.JTextField();
jLabel8 = new javax.swing.JLabel();
nhap = new javax.swing.JButton();
AddToDB = new javax.swing.JButton();
seeAll = new javax.swing.JButton();
jPanel5 = new javax.swing.JPanel();
jDesktopPane1 = new javax.swing.JDesktopPane();
TKDG = new javax.swing.JLabel();
jScrollPane3 = new javax.swing.JScrollPane();
Table2 = new javax.swing.JTable();
jButton7 = new javax.swing.JButton();
jButton8 = new javax.swing.JButton();
jButton9 = new javax.swing.JButton();
jLabel13 = new javax.swing.JLabel();
jButton4 = new javax.swing.JButton();
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 100, Short.MAX_VALUE)
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 100, Short.MAX_VALUE)
);
setTitle("LÊ ĐÌNH PHÚC _ 20163184 _ Quản Lý Độc Giả");
jTabbedPane1.setFont(new java.awt.Font("Tahoma", 0, 16)); // NOI18N
jDesktopPane2.setBackground(new java.awt.Color(51, 51, 51));
jLabel1.setFont(new java.awt.Font("Tahoma", 0, 16)); // NOI18N
jLabel1.setForeground(new java.awt.Color(255, 255, 255));
jLabel1.setText("Mã Độc Giả");
jLabel2.setFont(new java.awt.Font("Tahoma", 0, 16)); // NOI18N
jLabel2.setForeground(new java.awt.Color(255, 255, 255));
jLabel2.setText("Tên Độc Giả");
jLabel3.setFont(new java.awt.Font("Tahoma", 0, 16)); // NOI18N
jLabel3.setForeground(new java.awt.Color(255, 255, 255));
jLabel3.setText("Ngày Sinh");
jLabel4.setFont(new java.awt.Font("Tahoma", 0, 16)); // NOI18N
jLabel4.setForeground(new java.awt.Color(255, 255, 255));
jLabel4.setText("Giới Tính");
jLabel7.setFont(new java.awt.Font("Tahoma", 0, 16)); // NOI18N
jLabel7.setForeground(new java.awt.Color(255, 255, 255));
jLabel7.setText("CMND");
maDG.setFont(new java.awt.Font("Tahoma", 0, 16)); // NOI18N
tenDG.setFont(new java.awt.Font("Tahoma", 0, 16)); // NOI18N
ngaySinh.setFont(new java.awt.Font("Tahoma", 0, 16)); // NOI18N
gioiTinh.setFont(new java.awt.Font("Tahoma", 0, 16)); // NOI18N
gioiTinh.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
gioiTinhActionPerformed(evt);
}
});
diaChi.setFont(new java.awt.Font("Tahoma", 0, 16)); // NOI18N
diaChi.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
diaChiActionPerformed(evt);
}
});
sDT.setFont(new java.awt.Font("Tahoma", 0, 16)); // NOI18N
cmnd.setFont(new java.awt.Font("Tahoma", 0, 16)); // NOI18N
jLabel5.setFont(new java.awt.Font("Tahoma", 0, 16)); // NOI18N
jLabel5.setForeground(new java.awt.Color(255, 255, 255));
jLabel5.setText("Địa Chỉ");
jLabel6.setFont(new java.awt.Font("Tahoma", 0, 16)); // NOI18N
jLabel6.setForeground(new java.awt.Color(255, 255, 255));
jLabel6.setText("SĐT");
Them.setBackground(new java.awt.Color(102, 255, 102));
Them.setFont(new java.awt.Font("Tahoma", 0, 15)); // NOI18N
Them.setIcon(new javax.swing.ImageIcon(getClass().getResource("/quanlythuvien/icon/ínert.png"))); // NOI18N
Them.setText("Thêm");
Them.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
ThemActionPerformed(evt);
}
});
Sua.setBackground(new java.awt.Color(255, 255, 51));
Sua.setFont(new java.awt.Font("Tahoma", 0, 15)); // NOI18N
Sua.setIcon(new javax.swing.ImageIcon(getClass().getResource("/quanlythuvien/icon/sửa.png"))); // NOI18N
Sua.setText("Sửa");
Sua.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
SuaActionPerformed(evt);
}
});
Xoa.setBackground(new java.awt.Color(255, 0, 0));
Xoa.setFont(new java.awt.Font("Tahoma", 0, 15)); // NOI18N
Xoa.setIcon(new javax.swing.ImageIcon(getClass().getResource("/quanlythuvien/icon/remove.png"))); // NOI18N
Xoa.setText("Xóa");
Xoa.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
XoaActionPerformed(evt);
}
});
Table1.setFont(new java.awt.Font("Tahoma", 0, 15)); // NOI18N
Table1.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
},
new String [] {
" Mã Độc Giả", " Tên Độc Giả", " Ngày Sinh", " Giới Tính", " Địa Chỉ", " SĐT", " CMND"
}
) {
Class[] types = new Class [] {
java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class
};
public Class getColumnClass(int columnIndex) {
return types [columnIndex];
}
});
Table1.setRowHeight(28);
Table1.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
Table1MouseClicked(evt);
}
});
jScrollPane1.setViewportView(Table1);
comboTimKiem.setFont(new java.awt.Font("Tahoma", 0, 16)); // NOI18N
comboTimKiem.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Tìm Kiếm Theo Mã Độc Giả", "Tìm Kiếm Theo Tên Độc Giả", "Tìm Kiếm Theo Địa Chỉ", "Tìm Kiếm Theo SĐT", "Tìm Kiếm Theo CMND" }));
comboTimKiem.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
comboTimKiemActionPerformed(evt);
}
});
jButton10.setBackground(new java.awt.Color(0, 153, 51));
jButton10.setFont(new java.awt.Font("Tahoma", 0, 16)); // NOI18N
jButton10.setIcon(new javax.swing.ImageIcon(getClass().getResource("/quanlythuvien/icon/if_output-1_2916359.png"))); // NOI18N
jButton10.setText("Xuất File");
jButton10.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton10ActionPerformed(evt);
}
});
timKiem.setFont(new java.awt.Font("Tahoma", 0, 16)); // NOI18N
jLabel8.setFont(new java.awt.Font("Tahoma", 0, 16)); // NOI18N
jLabel8.setForeground(new java.awt.Color(255, 255, 255));
jLabel8.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
jLabel8.setText("Tìm Kiếm: ");
nhap.setFont(new java.awt.Font("Tahoma", 0, 15)); // NOI18N
nhap.setIcon(new javax.swing.ImageIcon(getClass().getResource("/quanlythuvien/icon/if_import-download-save_2931171.png"))); // NOI18N
nhap.setText("Nhập File");
nhap.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
nhapActionPerformed(evt);
}
});
AddToDB.setFont(new java.awt.Font("Tahoma", 0, 16)); // NOI18N
AddToDB.setIcon(new javax.swing.ImageIcon(getClass().getResource("/quanlythuvien/icon/add dâtbase.png"))); // NOI18N
AddToDB.setText("Thêm Vào CSDL");
AddToDB.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
AddToDBActionPerformed(evt);
}
});
seeAll.setFont(new java.awt.Font("Tahoma", 0, 15)); // NOI18N
seeAll.setIcon(new javax.swing.ImageIcon(getClass().getResource("/quanlythuvien/icon/see.png"))); // NOI18N
seeAll.setText("Hiện Thị Tất Cả");
seeAll.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
seeAllActionPerformed(evt);
}
});
jDesktopPane2.setLayer(jLabel1, javax.swing.JLayeredPane.DEFAULT_LAYER);
jDesktopPane2.setLayer(jLabel2, javax.swing.JLayeredPane.DEFAULT_LAYER);
jDesktopPane2.setLayer(jLabel3, javax.swing.JLayeredPane.DEFAULT_LAYER);
jDesktopPane2.setLayer(jLabel4, javax.swing.JLayeredPane.DEFAULT_LAYER);
jDesktopPane2.setLayer(jLabel7, javax.swing.JLayeredPane.DEFAULT_LAYER);
jDesktopPane2.setLayer(maDG, javax.swing.JLayeredPane.DEFAULT_LAYER);
jDesktopPane2.setLayer(tenDG, javax.swing.JLayeredPane.DEFAULT_LAYER);
jDesktopPane2.setLayer(ngaySinh, javax.swing.JLayeredPane.DEFAULT_LAYER);
jDesktopPane2.setLayer(gioiTinh, javax.swing.JLayeredPane.DEFAULT_LAYER);
jDesktopPane2.setLayer(diaChi, javax.swing.JLayeredPane.DEFAULT_LAYER);
jDesktopPane2.setLayer(sDT, javax.swing.JLayeredPane.DEFAULT_LAYER);
jDesktopPane2.setLayer(cmnd, javax.swing.JLayeredPane.DEFAULT_LAYER);
jDesktopPane2.setLayer(jLabel5, javax.swing.JLayeredPane.DEFAULT_LAYER);
jDesktopPane2.setLayer(jLabel6, javax.swing.JLayeredPane.DEFAULT_LAYER);
jDesktopPane2.setLayer(Them, javax.swing.JLayeredPane.DEFAULT_LAYER);
jDesktopPane2.setLayer(Sua, javax.swing.JLayeredPane.DEFAULT_LAYER);
jDesktopPane2.setLayer(Xoa, javax.swing.JLayeredPane.DEFAULT_LAYER);
jDesktopPane2.setLayer(jScrollPane1, javax.swing.JLayeredPane.DEFAULT_LAYER);
jDesktopPane2.setLayer(comboTimKiem, javax.swing.JLayeredPane.DEFAULT_LAYER);
jDesktopPane2.setLayer(jButton10, javax.swing.JLayeredPane.DEFAULT_LAYER);
jDesktopPane2.setLayer(timKiem, javax.swing.JLayeredPane.DEFAULT_LAYER);
jDesktopPane2.setLayer(jLabel8, javax.swing.JLayeredPane.DEFAULT_LAYER);
jDesktopPane2.setLayer(nhap, javax.swing.JLayeredPane.DEFAULT_LAYER);
jDesktopPane2.setLayer(AddToDB, javax.swing.JLayeredPane.DEFAULT_LAYER);
jDesktopPane2.setLayer(seeAll, javax.swing.JLayeredPane.DEFAULT_LAYER);
javax.swing.GroupLayout jDesktopPane2Layout = new javax.swing.GroupLayout(jDesktopPane2);
jDesktopPane2.setLayout(jDesktopPane2Layout);
jDesktopPane2Layout.setHorizontalGroup(
jDesktopPane2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jDesktopPane2Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jDesktopPane2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jDesktopPane2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addGroup(jDesktopPane2Layout.createSequentialGroup()
.addGroup(jDesktopPane2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jDesktopPane2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(jLabel1)
.addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jLabel4)
.addComponent(jLabel5)
.addComponent(jLabel6)
.addComponent(jLabel7)
.addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addComponent(Them))
.addGap(39, 39, 39)
.addGroup(jDesktopPane2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(sDT, javax.swing.GroupLayout.PREFERRED_SIZE, 240, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(cmnd, javax.swing.GroupLayout.PREFERRED_SIZE, 240, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(diaChi, javax.swing.GroupLayout.PREFERRED_SIZE, 240, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(gioiTinh, javax.swing.GroupLayout.PREFERRED_SIZE, 240, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(ngaySinh, javax.swing.GroupLayout.PREFERRED_SIZE, 240, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(tenDG, javax.swing.GroupLayout.PREFERRED_SIZE, 240, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(maDG, javax.swing.GroupLayout.PREFERRED_SIZE, 240, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jDesktopPane2Layout.createSequentialGroup()
.addGap(9, 9, 9)
.addComponent(Sua, javax.swing.GroupLayout.PREFERRED_SIZE, 95, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(Xoa, javax.swing.GroupLayout.PREFERRED_SIZE, 97, javax.swing.GroupLayout.PREFERRED_SIZE))))
.addGroup(jDesktopPane2Layout.createSequentialGroup()
.addComponent(comboTimKiem, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jButton10)))
.addGroup(jDesktopPane2Layout.createSequentialGroup()
.addComponent(jLabel8, javax.swing.GroupLayout.PREFERRED_SIZE, 103, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(26, 26, 26)
.addComponent(timKiem, javax.swing.GroupLayout.PREFERRED_SIZE, 240, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGroup(jDesktopPane2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jDesktopPane2Layout.createSequentialGroup()
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 336, Short.MAX_VALUE)
.addComponent(nhap)
.addGap(173, 173, 173)
.addComponent(AddToDB)
.addGap(115, 115, 115)
.addComponent(seeAll)
.addGap(63, 63, 63))
.addGroup(jDesktopPane2Layout.createSequentialGroup()
.addGap(68, 68, 68)
.addComponent(jScrollPane1))))
);
jDesktopPane2Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {diaChi, gioiTinh, maDG, ngaySinh, sDT, tenDG});
jDesktopPane2Layout.setVerticalGroup(
jDesktopPane2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jDesktopPane2Layout.createSequentialGroup()
.addGroup(jDesktopPane2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jDesktopPane2Layout.createSequentialGroup()
.addGap(23, 23, 23)
.addGroup(jDesktopPane2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(maDG, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel1))
.addGap(25, 25, 25)
.addGroup(jDesktopPane2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel2)
.addComponent(tenDG, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(24, 24, 24)
.addGroup(jDesktopPane2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel3)
.addComponent(ngaySinh, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(24, 24, 24)
.addGroup(jDesktopPane2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel4)
.addComponent(gioiTinh, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(26, 26, 26)
.addGroup(jDesktopPane2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(diaChi, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel5))
.addGap(27, 27, 27)
.addGroup(jDesktopPane2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(sDT, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel6))
.addGap(27, 27, 27)
.addGroup(jDesktopPane2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(cmnd, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel7))
.addGap(76, 76, 76)
.addGroup(jDesktopPane2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(Them, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(Sua)
.addComponent(Xoa))
.addGap(28, 28, 28)
.addGroup(jDesktopPane2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel8, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(timKiem, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addComponent(jScrollPane1))
.addGap(29, 29, 29)
.addGroup(jDesktopPane2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jDesktopPane2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(seeAll, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(nhap, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(AddToDB, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(jDesktopPane2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(comboTimKiem, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jButton10, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGap(22, 22, 22))
);
jDesktopPane2Layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {diaChi, gioiTinh, maDG, ngaySinh, sDT, tenDG});
javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
jPanel3.setLayout(jPanel3Layout);
jPanel3Layout.setHorizontalGroup(
jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jDesktopPane2)
);
jPanel3Layout.setVerticalGroup(
jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jDesktopPane2)
);
jTabbedPane1.addTab("Cập Nhật & Tìm Kiếm", jPanel3);
TKDG.setFont(new java.awt.Font("Tahoma", 0, 20)); // NOI18N
TKDG.setForeground(new java.awt.Color(255, 255, 255));
TKDG.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
TKDG.setText("Thống Kê Độc Giả");
TKDG.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
TKDG.setVerifyInputWhenFocusTarget(false);
TKDG.setVerticalTextPosition(javax.swing.SwingConstants.TOP);
Table2.setFont(new java.awt.Font("Tahoma", 0, 16)); // NOI18N
Table2.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
},
new String [] {
}
));
Table2.setRowHeight(26);
jScrollPane3.setViewportView(Table2);
jButton7.setFont(new java.awt.Font("Tahoma", 0, 16)); // NOI18N
jButton7.setIcon(new javax.swing.ImageIcon(getClass().getResource("/quanlythuvien/icon/statistic.png"))); // NOI18N
jButton7.setText("Theo Địa Chỉ");
jButton7.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton7ActionPerformed(evt);
}
});
jButton8.setFont(new java.awt.Font("Tahoma", 0, 16)); // NOI18N
jButton8.setIcon(new javax.swing.ImageIcon(getClass().getResource("/quanlythuvien/icon/statistic.png"))); // NOI18N
jButton8.setText("Theo Giới Tính");
jButton8.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton8ActionPerformed(evt);
}
});
jButton9.setFont(new java.awt.Font("Tahoma", 0, 16)); // NOI18N
jButton9.setIcon(new javax.swing.ImageIcon(getClass().getResource("/quanlythuvien/icon/statistic.png"))); // NOI18N
jButton9.setText("Theo Năm Sinh");
jButton9.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton9ActionPerformed(evt);
}
});
jLabel13.setFont(new java.awt.Font("Tahoma", 1, 20)); // NOI18N
jLabel13.setForeground(new java.awt.Color(255, 255, 255));
jLabel13.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
jLabel13.setText("GVHD: ThS. LÊ THỊ HOA");
jButton4.setBackground(new java.awt.Color(51, 153, 0));
jButton4.setFont(new java.awt.Font("Tahoma", 0, 16)); // NOI18N
jButton4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/quanlythuvien/icon/if_output-1_2916359.png"))); // NOI18N
jButton4.setText("Xuất File");
jButton4.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton4ActionPerformed(evt);
}
});
jDesktopPane1.setLayer(TKDG, javax.swing.JLayeredPane.DEFAULT_LAYER);
jDesktopPane1.setLayer(jScrollPane3, javax.swing.JLayeredPane.DEFAULT_LAYER);
jDesktopPane1.setLayer(jButton7, javax.swing.JLayeredPane.DEFAULT_LAYER);
jDesktopPane1.setLayer(jButton8, javax.swing.JLayeredPane.DEFAULT_LAYER);
jDesktopPane1.setLayer(jButton9, javax.swing.JLayeredPane.DEFAULT_LAYER);
jDesktopPane1.setLayer(jLabel13, javax.swing.JLayeredPane.DEFAULT_LAYER);
jDesktopPane1.setLayer(jButton4, javax.swing.JLayeredPane.DEFAULT_LAYER);
javax.swing.GroupLayout jDesktopPane1Layout = new javax.swing.GroupLayout(jDesktopPane1);
jDesktopPane1.setLayout(jDesktopPane1Layout);
jDesktopPane1Layout.setHorizontalGroup(
jDesktopPane1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jDesktopPane1Layout.createSequentialGroup()
.addGroup(jDesktopPane1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jDesktopPane1Layout.createSequentialGroup()
.addGap(39, 39, 39)
.addGroup(jDesktopPane1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addGroup(jDesktopPane1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addComponent(jButton7, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jButton9, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addComponent(jButton8, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGap(76, 76, 76)
.addComponent(jButton4))
.addGroup(jDesktopPane1Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel13, javax.swing.GroupLayout.PREFERRED_SIZE, 382, javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(TKDG, javax.swing.GroupLayout.PREFERRED_SIZE, 441, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, Short.MAX_VALUE)
.addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 1061, Short.MAX_VALUE))
);
jDesktopPane1Layout.setVerticalGroup(
jDesktopPane1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jDesktopPane1Layout.createSequentialGroup()
.addComponent(TKDG, javax.swing.GroupLayout.PREFERRED_SIZE, 68, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(jButton7)
.addGap(48, 48, 48)
.addGroup(jDesktopPane1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButton8)
.addComponent(jButton4, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(46, 46, 46)
.addComponent(jButton9)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jLabel13, javax.swing.GroupLayout.PREFERRED_SIZE, 56, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(62, 62, 62))
.addGroup(jDesktopPane1Layout.createSequentialGroup()
.addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 758, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(48, Short.MAX_VALUE))
);
javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
jPanel5.setLayout(jPanel5Layout);
jPanel5Layout.setHorizontalGroup(
jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jDesktopPane1)
);
jPanel5Layout.setVerticalGroup(
jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel5Layout.createSequentialGroup()
.addComponent(jDesktopPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(0, 0, Short.MAX_VALUE))
);
jTabbedPane1.addTab("Thống Kê", jPanel5);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jTabbedPane1)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jTabbedPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 793, Short.MAX_VALUE)
);
pack();
setLocationRelativeTo(null);
}// </editor-fold>//GEN-END:initComponents
// Xóa Tất Cả các dòng
public void removeAllRow() {
DefaultTableModel modelDelete = (DefaultTableModel) Table1.getModel();
modelDelete.setRowCount(0);
if (modelDelete.getRowCount() != 0) {
modelDelete.setRowCount(0);
}
}
public ArrayList<DocGia> getListDG() { //Đọc dữ liệu trong database
ArrayList<DocGia> docGia = new ArrayList<DocGia>();
String sql = "SELECT * FROM quanlythuvien.docgia";
try {
ps = conn.prepareStatement(sql);
ResultSet rs = ps.executeQuery();
while (rs.next()) {
DocGia dg = new DocGia();
dg.setMaDG(rs.getString(1));
dg.setTenDG(rs.getString(2));
dg.setNgaySinh(rs.getString(3));
dg.setGT(rs.getString(4));
dg.setDiaChi(rs.getString(5));
dg.setSDT(rs.getString(6));
dg.setCMND(rs.getString(7));
docGia.add(dg); //thêm vào mảng
}
} catch (SQLException ex) {
JOptionPane.showMessageDialog(null, "Error: " + ex.getMessage());
}
return docGia;
}
public void showTable(ArrayList<DocGia> docGia) {
for (DocGia dg : docGia) {
model.addRow(new Object[]{
dg.getMaDG(), dg.getTenDG(), dg.getNgaySinh(), dg.getGT(), dg.getDiaChi(), dg.getSDT(), dg.getCMND()
});
}
}
/*--------------------------------------------- Chức Năng Cập Nhật ----------------------------------------*/
public void clearData() {
maDG.setText("");
tenDG.setText("");
ngaySinh.setText("");
gioiTinh.setText("");
diaChi.setText("");
sDT.setText("");
cmnd.setText("");
}
public boolean addDG(DocGia dg) { //Thêm sách vào database
String sql = "INSERT INTO `quanlythuvien`.`docgia` "
+ "(`MaDG_LDP`, `TenDG_LDP`, `NgaySinh_LDP`, `GT_LDP`, `DiaChi_LDP`, `SDT_LDP`, `CMND_LDP`) "
+ "VALUES (?, ?, ?, ?, ?, ?, ?);";
try {
ps = conn.prepareStatement(sql);
ps.setString(1, dg.getMaDG());
ps.setString(2, dg.getTenDG());
ps.setString(3, dg.getNgaySinh());
ps.setString(4, dg.getGT());
ps.setString(5, dg.getDiaChi());
ps.setString(6, dg.getSDT());
ps.setString(7, dg.getCMND());
int kt = ps.executeUpdate();
if (kt != 0) {
JOptionPane.showMessageDialog(null, "Bạn đã thêm dữ liệu thành công !");
return true;
}
} catch (SQLException ex) {
JOptionPane.showMessageDialog(null, "Error: " + ex.getMessage());
}
return false;
}
// update database
public boolean update() {
String sql = "UPDATE `quanlythuvien`.`docgia` "
+ "SET `MaDG_LDP` = ?, `TenDG_LDP` = ?, `NgaySinh_LDP` = ?, `GT_LDP` = ?, "
+ "`DiaChi_LDP` = ?, `SDT_LDP` = ?, `CMND_LDP` = ? "
+ "WHERE (`MaDG_LDP` = ? );";
try {
ps = conn.prepareStatement(sql);
ps.setString(1, maDG.getText());
ps.setString(2, tenDG.getText());
ps.setString(3, ngaySinh.getText());
ps.setString(4, gioiTinh.getText());
ps.setString(5, diaChi.getText());
ps.setString(6, sDT.getText());
ps.setString(7, cmnd.getText());
ps.setString(8, (Table1.getValueAt(rowID, 0)).toString());
int kt = ps.executeUpdate();
if (kt != 0) {
JOptionPane.showMessageDialog(null, "Bạn đã cập nhật dữ liệu thành công");
// Xóa dòng tại vị trí rowID lấy từ action mouse click
model.removeRow(rowID);
// Thêm bản ghi vào bảng tại vị trí rowID lấy từ action event mouse click
model.insertRow(rowID, new Object[]{
maDG.getText(), tenDG.getText(), ngaySinh.getText(), gioiTinh.getText(),
diaChi.getText(), sDT.getText(), cmnd.getText()
});
clearData();
return true;
}
} catch (SQLException ex) {
JOptionPane.showMessageDialog(null, "Error: " + ex.getMessage());
}
return false;
}
public boolean remove() { //Xóa Sách khỏi database
String sql = "DELETE FROM `quanlythuvien`.`docgia` WHERE (`MaDG_LDP` = ?);";
try {
ps = conn.prepareStatement(sql);
ps.setString(1, Table1.getValueAt(rowID, 0).toString());
int kt = ps.executeUpdate();
if (kt != 0) {
JOptionPane.showMessageDialog(null, "Bạn đã xóa dữ liệu thành công !");
// Xóa dòng tại vị trí rowID với rowID lấy từ action mouse click
return true;
}
} catch (SQLException ex) {
// Logger.getLogger(QuanLySach.class.getName()).log(Level.SEVERE, null, ex);
JOptionPane.showMessageDialog(null, "Error => " + ex.getMessage());
}
return false;
}
/*------------------------------------------------- Tìm Kiếm ---------------------------------------------*/
//Tìm kiếm sách theo mã sách
public ArrayList<DocGia> tKTheoMaDG() {
ArrayList<DocGia> docGia = new ArrayList<DocGia>();
String sql = "SELECT * FROM DOCGIA WHERE (MaDG_LDP = '" + timKiem.getText() + "');";
try {
ps = conn.prepareStatement(sql);
ResultSet rs = ps.executeQuery();
while (rs.next()) {
DocGia dg = new DocGia();
dg.setMaDG(rs.getString(1));
dg.setTenDG(rs.getString(2));
dg.setNgaySinh(rs.getString(3));
dg.setGT(rs.getString(4));
dg.setDiaChi(rs.getString(5));
dg.setSDT(rs.getString(6));
dg.setCMND(rs.getString(7));
docGia.add(dg); //thêm vào mảng
}
} catch (SQLException ex) {
JOptionPane.showMessageDialog(null, "Error: " + ex.getMessage());
}
return docGia;
}
//Tìm kiếm sách theo tên sách
public ArrayList<DocGia> tKTheoTenDG() {
ArrayList<DocGia> docGia = new ArrayList<DocGia>();
String sql = "SELECT * FROM quanlythuvien.docgia"
+ " Where TenDG_LDP LIKE '%" + timKiem.getText() + "%';";
try {
ps = conn.prepareStatement(sql);
ResultSet rs = ps.executeQuery();
while (rs.next()) {
DocGia dg = new DocGia();
dg.setMaDG(rs.getString(1));
dg.setTenDG(rs.getString(2));
dg.setNgaySinh(rs.getString(3));
dg.setGT(rs.getString(4));
dg.setDiaChi(rs.getString(5));
dg.setSDT(rs.getString(6));
dg.setCMND(rs.getString(7));
docGia.add(dg); //thêm vào mảng
}
} catch (SQLException ex) {
JOptionPane.showMessageDialog(null, "Error: " + ex.getMessage());
}
return docGia;
}
//Tìm kiếm sách theo Thể loại
public ArrayList<DocGia> tKTheoDiaChi() {
ArrayList<DocGia> docGia = new ArrayList<DocGia>();
String sql = "SELECT * FROM quanlythuvien.docgia"
+ " Where DiaChi_LDP LIKE '%" + timKiem.getText() + "%';";
try {
ps = conn.prepareStatement(sql);
ResultSet rs = ps.executeQuery();
while (rs.next()) {
DocGia dg = new DocGia();
dg.setMaDG(rs.getString(1));
dg.setTenDG(rs.getString(2));
dg.setNgaySinh(rs.getString(3));
dg.setGT(rs.getString(4));
dg.setDiaChi(rs.getString(5));
dg.setSDT(rs.getString(6));
dg.setCMND(rs.getString(7));
docGia.add(dg); //thêm vào mảng
}
} catch (SQLException ex) {
JOptionPane.showMessageDialog(null, "Error: " + ex.getMessage());
}
return docGia;
}
//Tìm kiếm sách theo tên tác giả
public ArrayList<DocGia> tKTheoSDT() {
ArrayList<DocGia> docGia = new ArrayList<DocGia>();
String sql = "SELECT * FROM quanlythuvien.docgia"
+ " Where SDT_LDP = ?;";
try {
ps = conn.prepareStatement(sql);
ps.setInt(1, Integer.parseInt(timKiem.getText()));
ResultSet rs = ps.executeQuery();
while (rs.next()) {
DocGia dg = new DocGia();
dg.setMaDG(rs.getString(1));
dg.setTenDG(rs.getString(2));
dg.setNgaySinh(rs.getString(3));
dg.setGT(rs.getString(4));
dg.setDiaChi(rs.getString(5));
dg.setSDT(rs.getString(6));
dg.setCMND(rs.getString(7));
docGia.add(dg); //thêm vào mảng
}
} catch (SQLException ex) {
JOptionPane.showMessageDialog(null, "Error: " + ex.getMessage());
}
return docGia;
}
//Tìm kiếm sách theo Nhà Xuất Bản
public ArrayList<DocGia> tKTheoCMND() {
ArrayList<DocGia> docGia = new ArrayList<DocGia>();
String sql = "SELECT * FROM quanlythuvien.docgia"
+ " Where CMND_LDP LIKE '%" + Integer.parseInt(timKiem.getText()) + "%';";
try {
ps = conn.prepareStatement(sql);
ResultSet rs = ps.executeQuery();
while (rs.next()) {
DocGia dg = new DocGia();
dg.setMaDG(rs.getString(1));
dg.setTenDG(rs.getString(2));
dg.setNgaySinh(rs.getString(3));
dg.setGT(rs.getString(4));
dg.setDiaChi(rs.getString(5));
dg.setSDT(rs.getString(6));
dg.setCMND(rs.getString(7));
docGia.add(dg); //thêm vào mảng
}
} catch (SQLException ex) {
JOptionPane.showMessageDialog(null, "Error: " + ex.getMessage());
}
return docGia;
}
/*------------------------------------------------- Thống Kê ---------------------------------------------*/
public void removeAllRowTKe() {
DefaultTableModel modelDelete = (DefaultTableModel) Table2.getModel();
modelDelete.setRowCount(0);
if (modelDelete.getRowCount() != 0) {
modelDelete.setRowCount(0);
}
}
//Hàm thống kê Sách theo Tên Sách
public ArrayList<DocGia> tKeTheoTenDG() {
ArrayList<DocGia> docGia = new ArrayList<DocGia>();
String sql = "SELECT TenDG_LDP, Count(TenDG_LDP) "
+ "FROM quanlythuvien.nhadgien "
+ "GROUP BY TenDG_LDP;";
try {
ps = conn.prepareStatement(sql);
ResultSet rs = ps.executeQuery();
while (rs.next()) {
DocGia dg = new DocGia();
dg.setTenDG(rs.getString("TenDG_LDP"));
// dg.setSoLuong(rs.getInt("Count(TenDG_LDP)"));
docGia.add(dg); //thêm vào mảng
}
} catch (SQLException ex) {
JOptionPane.showMessageDialog(null, "Error: " + ex.getMessage());
}
return docGia;
}
//Hàm thống kê sách theo Thể Loại
public ArrayList<DocGia> tKeTheoGT() {
ArrayList<DocGia> docGia = new ArrayList<DocGia>();
String sql = "Select TheLoai_LDP,Sum(SoLuongCon_LDP),Sum(TongSoLuong_LDP) "
+ "from quanlythuvien.sach "
+ "group by TheLoai_LDP;";
try {
ps = conn.prepareStatement(sql);
ResultSet rs = ps.executeQuery();
while (rs.next()) {
DocGia dg = new DocGia();
//dg.setTheLoai(rs.getString("TheLoai_LDP"));
//dg.setSoLuongCon(rs.getInt("Sum(SoLuongCon_LDP)"));
//dg.setTongSoLuong(rs.getInt("Sum(TongSoLuong_LDP)"));
docGia.add(dg); //thêm vào mảng
}
} catch (SQLException ex) {
JOptionPane.showMessageDialog(null, "Error: " + ex.getMessage());
}
return docGia;
}
//Hàm thống kê sách theo Nhà Xuất Bản
public ArrayList<Sach> tKeTheoNXB() {
ArrayList<Sach> sach = new ArrayList<Sach>();
String sql = "Select NXB_LDP,Sum(SoLuongCon_LDP),Sum(TongSoLuong_LDP) "
+ "from quanlythuvien.sach "
+ "group by NXB_LDP;";
try {
ps = conn.prepareStatement(sql);
ResultSet rs = ps.executeQuery();
while (rs.next()) {
Sach s = new Sach();
s.setTheLoai(rs.getString("NXB_LDP"));
s.setSoLuongCon(rs.getInt("Sum(SoLuongCon_LDP)"));
s.setTongSoLuong(rs.getInt("Sum(TongSoLuong_LDP)"));
sach.add(s); //thêm vào mảng
}
} catch (SQLException ex) {
JOptionPane.showMessageDialog(null, "Error: " + ex.getMessage());
}
return sach;
}
private void gioiTinhActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_gioiTinhActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_gioiTinhActionPerformed
private void diaChiActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_diaChiActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_diaChiActionPerformed
private void jButton7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton7ActionPerformed
removeAllRowTKe();
TKDG.setText("Thống Kê Độc Giả Theo Địa Chỉ");
DefaultTableModel modelTK = (DefaultTableModel) Table2.getModel();
modelTK.setColumnIdentifiers(new Object[]{
" STT", " Địa Chỉ", " Số Lượng"
});
int i = 0;
String sql = "select diachi_LDP , count(DiaChi_LDP) \n"
+ "from quanlythuvien.docgia\n"
+ "group by DiaChi_LDP";
try {
ps = conn.prepareStatement(sql);
ResultSet rs = ps.executeQuery();
while (rs.next()) {
modelTK.addRow(new Object[]{
++i, rs.getString(1), rs.getString(2)
});
}
} catch (SQLException ex) {
Logger.getLogger(QuanLyDocGia.class.getName()).log(Level.SEVERE, null, ex);
}
}//GEN-LAST:event_jButton7ActionPerformed
private void jButton8ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton8ActionPerformed
removeAllRowTKe();
TKDG.setText("Thống Kê Độc Giả Theo Giới Tính");
DefaultTableModel modelTK = (DefaultTableModel) Table2.getModel();
modelTK.setColumnIdentifiers(new Object[]{
" STT", " Giới Tính", " Số Lượng"
});
int i = 0;
String sql = "select GT_LDP , count(GT_LDP) \n"
+ "from quanlythuvien.docgia\n"
+ "group by GT_LDP";
try {
ps = conn.prepareStatement(sql);
ResultSet rs = ps.executeQuery();
while (rs.next()) {
modelTK.addRow(new Object[]{
++i, rs.getString(1), rs.getString(2)
});
}
} catch (SQLException ex) {
Logger.getLogger(QuanLyDocGia.class.getName()).log(Level.SEVERE, null, ex);
}
}//GEN-LAST:event_jButton8ActionPerformed
private void jButton9ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton9ActionPerformed
removeAllRowTKe();
TKDG.setText("Thống Kê Độc Giả Theo Năm Sinh");
DefaultTableModel modelTK = (DefaultTableModel) Table2.getModel();
modelTK.setColumnIdentifiers(new Object[]{