Skip to content

Commit f8ba490

Browse files
TRIBUI106danhng876
andcommitted
chez1s: HotFix
Fix List : - Search trong bảng KhoHang - Tìm ngày / tiền ở bảng PhieuNhap - Tìm sản phẩm ở bảng XuatHang - Sync Data comboBox_NhaCungCap_NhapHang với data của panel NhaCungCap - Số lượng bị lỗi khi xoá, sửa Co-Authored-By: danhng876 <170338275+danhng876@users.noreply.github.com>
1 parent adfc756 commit f8ba490

5 files changed

Lines changed: 134 additions & 104 deletions

File tree

src/main/java/chezis/sof203/DAO/KhoHangDAO.java

Lines changed: 72 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,20 @@
1616
* @author Chezis P
1717
*/
1818
public interface KhoHangDAO {
19-
19+
2020
default List<MayTinh> getMayTinhData() {
2121
String SQL = "SELECT maMay, tenMay, soLuong, giaTien, tenCPU, tsRam, oCung FROM MayTinh";
2222
try (
23-
Connection conn = ConnectorHelper.getConnection();
24-
Statement stm = conn.createStatement();
25-
ResultSet rs = stm.executeQuery(SQL)
26-
)
27-
{
23+
Connection conn = ConnectorHelper.getConnection(); Statement stm = conn.createStatement(); ResultSet rs = stm.executeQuery(SQL)) {
2824
List<MayTinh> mtList = new ArrayList<>();
2925
while (rs.next()) {
3026
mtList.add(new MayTinh(
31-
rs.getString("maMay"),
32-
rs.getString("tenMay"),
27+
rs.getString("maMay"),
28+
rs.getString("tenMay"),
3329
rs.getInt("soLuong"),
34-
rs.getBigDecimal("giaTien"),
35-
rs.getString("tenCPU"),
36-
rs.getString("tsRam"),
30+
rs.getBigDecimal("giaTien"),
31+
rs.getString("tenCPU"),
32+
rs.getString("tsRam"),
3733
rs.getFloat("oCung")));
3834
}
3935
return mtList;
@@ -42,7 +38,7 @@ default List<MayTinh> getMayTinhData() {
4238
}
4339
return null;
4440
}
45-
41+
4642
default int getMaxMaMay(String maMay) {
4743
String SQL = "SELECT getMaxMaMay(?) as num";
4844
try (Connection conn = ConnectorHelper.getConnection(); PreparedStatement prstm = conn.prepareStatement(SQL)) {
@@ -58,7 +54,46 @@ default int getMaxMaMay(String maMay) {
5854
}
5955
return -1;
6056
}
61-
57+
58+
default ArrayList getSearchMayTinh(String keyword) {
59+
String SQL = "SELECT * FROM MayTinh WHERE maMay LIKE ? OR tenMay LIKE ?; ";
60+
try (Connection conn = ConnectorHelper.getConnection(); PreparedStatement prstm = conn.prepareStatement(SQL)) {
61+
String keywords = "%" + keyword + "%";
62+
prstm.setString(1, keywords);
63+
prstm.setString(2, keywords);
64+
ResultSet rs = prstm.executeQuery();
65+
66+
ArrayList<MayTinh> mtList = new ArrayList<>();
67+
int countMayTinh = 0;
68+
69+
while (rs.next()) {
70+
++countMayTinh;
71+
mtList.add(new MayTinh(
72+
rs.getString("maMay"),
73+
rs.getString("tenMay"),
74+
rs.getInt("soLuong"),
75+
rs.getBigDecimal("giaTien"),
76+
rs.getString("tenCPU"),
77+
rs.getString("tsRam"),
78+
rs.getFloat("oCung")));
79+
}
80+
81+
if ( countMayTinh == 0 ) {
82+
AnnounceDAO.announceWar("Không tìm được máy nào với mã " + keyword + " !");
83+
return null;
84+
}
85+
86+
AnnounceDAO.announceInfo("Tìm được " + countMayTinh + " máy tính với mã " + keyword);
87+
88+
return mtList;
89+
90+
} catch (SQLException ex) {
91+
ex.printStackTrace();
92+
}
93+
94+
return null;
95+
}
96+
6297
default List<MayTinh> getSortMayTinh(String sortOption) {
6398
String SQL = "";
6499

@@ -77,59 +112,53 @@ default List<MayTinh> getSortMayTinh(String sortOption) {
77112
SQL = "SELECT * FROM MayTinh ORDER BY giaTien DESC";
78113
break;
79114
default:
80-
SQL = "SELECT * FROM MayTinh";
115+
SQL = "SELECT * FROM MayTinh";
81116
break;
82117
}
83118

84-
85119
try (
86-
Connection conn = ConnectorHelper.getConnection();
87-
Statement stm = conn.createStatement();
88-
ResultSet rs = stm.executeQuery(SQL)
89-
) {
120+
Connection conn = ConnectorHelper.getConnection(); Statement stm = conn.createStatement(); ResultSet rs = stm.executeQuery(SQL)) {
90121
List<MayTinh> mtList = new ArrayList<>();
91122
while (rs.next()) {
92123
mtList.add(new MayTinh(
93-
rs.getString("maMay"),
94-
rs.getString("tenMay"),
95-
rs.getInt("soLuong"),
96-
rs.getBigDecimal("giaTien"),
97-
rs.getString("tenCPU"),
98-
rs.getString("tsRam"),
99-
rs.getFloat("oCung"))
124+
rs.getString("maMay"),
125+
rs.getString("tenMay"),
126+
rs.getInt("soLuong"),
127+
rs.getBigDecimal("giaTien"),
128+
rs.getString("tenCPU"),
129+
rs.getString("tsRam"),
130+
rs.getFloat("oCung"))
100131
);
101132
}
102133
return mtList;
103134
} catch (SQLException ex) {
104135
ex.printStackTrace();
105-
return null;
136+
return null;
106137
}
107138
}
108-
139+
109140
default List getAllmaMayDAO() {
110141
String SQL = "CALL GetAllMaMay; ";
111142
try (Connection conn = ConnectorHelper.getConnection(); Statement stm = conn.createStatement(); ResultSet rs = stm.executeQuery(SQL)) {
112143
List<String> maMayList = new ArrayList<>();
113-
114-
while ( rs.next() ) {
144+
145+
while (rs.next()) {
115146
maMayList.add(rs.getString("maMay"));
116147
}
117-
148+
118149
return maMayList;
119-
150+
120151
} catch (SQLException ex) {
121152
ex.printStackTrace();
122153
}
123154
return null;
124155
}
125-
156+
126157
default boolean addMayTinhDAO(String maMay, String tenMay, int soLuong, BigDecimal giaTien, String tenCPU, String tsRam, float oCung) {
127-
158+
128159
String SQL = "INSERT INTO MayTinh(maMay, tenMay, soLuong, giaTien, tenCPU, tsRam, oCung) VALUES (?, ?, ?, ?, ?, ?, ?)";
129160
try (
130-
Connection conn = ConnectorHelper.getConnection();
131-
PreparedStatement prstm = conn.prepareStatement(SQL);
132-
) {
161+
Connection conn = ConnectorHelper.getConnection(); PreparedStatement prstm = conn.prepareStatement(SQL);) {
133162
prstm.setString(1, maMay);
134163
prstm.setString(2, tenMay);
135164
prstm.setInt(3, soLuong);
@@ -147,14 +176,12 @@ default boolean addMayTinhDAO(String maMay, String tenMay, int soLuong, BigDecim
147176
return false;
148177
}
149178
}
150-
179+
151180
default boolean updateMayTinhDAO(String maMay, String tenMay, int soLuong, BigDecimal giaTien, String tenCPU, String tsRam, float oCung) {
152-
181+
153182
String SQL = "UPDATE MayTinh SET tenMay = ?, soLuong = ?, giaTien = ?, tenCPU = ?, tsRam = ?, oCung = ? WHERE maMay = ?";
154183
try (
155-
Connection conn = ConnectorHelper.getConnection();
156-
PreparedStatement prstm = conn.prepareStatement(SQL);
157-
) {
184+
Connection conn = ConnectorHelper.getConnection(); PreparedStatement prstm = conn.prepareStatement(SQL);) {
158185
prstm.setString(7, maMay);
159186
prstm.setString(1, tenMay);
160187
prstm.setInt(2, soLuong);
@@ -172,14 +199,12 @@ default boolean updateMayTinhDAO(String maMay, String tenMay, int soLuong, BigDe
172199
return false;
173200
}
174201
}
175-
202+
176203
default boolean deleteMayTinhDAO(String maMay) {
177-
204+
178205
String SQL = "DELETE FROM MayTinh WHERE maMay = ?";
179206
try (
180-
Connection conn = ConnectorHelper.getConnection();
181-
PreparedStatement prstm = conn.prepareStatement(SQL);
182-
) {
207+
Connection conn = ConnectorHelper.getConnection(); PreparedStatement prstm = conn.prepareStatement(SQL);) {
183208
prstm.setString(1, maMay);
184209
prstm.executeUpdate();
185210
return true;
@@ -192,5 +217,4 @@ default boolean deleteMayTinhDAO(String maMay) {
192217
}
193218
}
194219

195-
196220
}

src/main/java/chezis/sof203/DAO/NhapHangDAO.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,8 @@ public List<Map<String, Object>> getAllPhieuNhapSortedByTongTien(boolean isAscen
177177
+ "thoiGianTao, "
178178
+ "tongTien "
179179
+ "FROM PhieuNhap "
180-
+ "WHERE tongTien BETWEEN ? AND ? "
180+
// + "WHERE tongTien BETWEEN ? AND ? "
181+
+ "WHERE tongTien >= ? AND tongTien <= ?"
181182
+ "ORDER BY tongTien " + order;
182183

183184
try (Connection conn = ConnectorHelper.getConnection();
@@ -213,14 +214,15 @@ public List<Map<String, Object>> getAllPhieuNhapSortedByDate(boolean isAscending
213214
+ "thoiGianTao, "
214215
+ "tongTien "
215216
+ "FROM PhieuNhap "
216-
+ "WHERE thoiGianTao BETWEEN ? AND ? "
217-
+ "ORDER BY thoiGianTao ASC";
217+
+ "WHERE thoiGianTao >= ? AND thoiGianTao <= ?"
218+
+ "ORDER BY thoiGianTao ?";
218219

219220

220221
try (Connection conn = ConnectorHelper.getConnection();
221222
PreparedStatement stmt = conn.prepareStatement(SQL)) {
222223
stmt.setDate(1, startDate);
223224
stmt.setDate(2, endDate);
225+
stmt.setString(3, order);
224226
ResultSet rs = stmt.executeQuery();
225227

226228
List<Map<String, Object>> result = new ArrayList<>();

src/main/java/chezis/sof203/Services/KhoHangService.java

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -135,15 +135,7 @@ public boolean capNhatMayTinh( String maMay, String tenMay, String soLuong, Stri
135135

136136

137137
public List<MayTinh> searchMayTinh(String keyWord) {
138-
keyWord = keyWord.toLowerCase();
139-
List<MayTinh> allMayTinhList = getMayTinh();
140-
List<MayTinh> filteredList = new ArrayList<>();
141-
142-
for (MayTinh mt : allMayTinhList) {
143-
if (mt.getTenMay().toLowerCase().contains(keyWord) || mt.getMaMay().toLowerCase().contains(keyWord)) {
144-
filteredList.add(mt);
145-
}
146-
}
138+
ArrayList<MayTinh> filteredList = getSearchMayTinh(keyWord.toLowerCase());
147139
return filteredList;
148140
}
149141

src/main/java/chezis/sof203/View/IndexForm.form

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1965,7 +1965,7 @@
19651965
<EmptySpace max="-2" attributes="0"/>
19661966
<Component id="txtPN_SearchField" min="-2" pref="356" max="-2" attributes="0"/>
19671967
<EmptySpace type="unrelated" max="-2" attributes="0"/>
1968-
<Component id="btnPN_Reload" pref="104" max="32767" attributes="0"/>
1968+
<Component id="btnPN_Reload" pref="106" max="32767" attributes="0"/>
19691969
<EmptySpace max="-2" attributes="0"/>
19701970
</Group>
19711971
</Group>
@@ -3149,30 +3149,28 @@
31493149
<DimensionLayout dim="0">
31503150
<Group type="103" groupAlignment="0" attributes="0">
31513151
<Group type="102" alignment="0" attributes="0">
3152-
<EmptySpace min="-2" pref="20" max="-2" attributes="0"/>
3152+
<EmptySpace max="-2" attributes="0"/>
31533153
<Component id="jLabel7" min="-2" max="-2" attributes="0"/>
31543154
<EmptySpace max="-2" attributes="0"/>
3155-
<Component id="txtPX_FromPrice" min="-2" pref="172" max="-2" attributes="0"/>
3156-
<EmptySpace max="32767" attributes="0"/>
3155+
<Component id="jDateChooser1" min="-2" pref="208" max="-2" attributes="0"/>
3156+
<EmptySpace max="-2" attributes="0"/>
31573157
<Component id="jLabel8" min="-2" max="-2" attributes="0"/>
31583158
<EmptySpace max="-2" attributes="0"/>
3159-
<Component id="txtPX_ToPrice" min="-2" pref="172" max="-2" attributes="0"/>
3160-
<EmptySpace min="-2" pref="18" max="-2" attributes="0"/>
3159+
<Component id="jDateChooser2" min="-2" pref="208" max="-2" attributes="0"/>
3160+
<EmptySpace max="32767" attributes="0"/>
31613161
</Group>
31623162
</Group>
31633163
</DimensionLayout>
31643164
<DimensionLayout dim="1">
31653165
<Group type="103" groupAlignment="0" attributes="0">
31663166
<Group type="102" alignment="0" attributes="0">
3167-
<EmptySpace min="-2" pref="14" max="-2" attributes="0"/>
3167+
<EmptySpace min="-2" pref="24" max="-2" attributes="0"/>
31683168
<Group type="103" groupAlignment="0" attributes="0">
3169-
<Group type="103" alignment="0" groupAlignment="3" attributes="0">
3170-
<Component id="jLabel8" alignment="3" min="-2" max="-2" attributes="0"/>
3171-
<Component id="txtPX_ToPrice" alignment="3" min="-2" max="-2" attributes="0"/>
3172-
</Group>
3169+
<Component id="jDateChooser2" min="-2" pref="25" max="-2" attributes="0"/>
3170+
<Component id="jDateChooser1" alignment="0" min="-2" pref="25" max="-2" attributes="0"/>
31733171
<Group type="103" alignment="0" groupAlignment="3" attributes="0">
31743172
<Component id="jLabel7" alignment="3" min="-2" max="-2" attributes="0"/>
3175-
<Component id="txtPX_FromPrice" alignment="3" min="-2" max="-2" attributes="0"/>
3173+
<Component id="jLabel8" alignment="3" min="-2" max="-2" attributes="0"/>
31763174
</Group>
31773175
</Group>
31783176
<EmptySpace max="32767" attributes="0"/>
@@ -3189,25 +3187,25 @@
31893187
<Property name="text" type="java.lang.String" value="T&#x1eeb;"/>
31903188
</Properties>
31913189
</Component>
3192-
<Component class="javax.swing.JTextField" name="txtPX_FromPrice">
3190+
<Component class="javax.swing.JLabel" name="jLabel8">
31933191
<Properties>
31943192
<Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor">
3195-
<Font name="Segoe UI" size="24" style="0"/>
3193+
<Font name="Segoe UI" size="18" style="0"/>
31963194
</Property>
3195+
<Property name="text" type="java.lang.String" value="T&#x1edb;i"/>
31973196
</Properties>
31983197
</Component>
3199-
<Component class="javax.swing.JLabel" name="jLabel8">
3198+
<Component class="com.toedter.calendar.JDateChooser" name="jDateChooser1">
32003199
<Properties>
32013200
<Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor">
32023201
<Font name="Segoe UI" size="18" style="0"/>
32033202
</Property>
3204-
<Property name="text" type="java.lang.String" value="T&#x1edb;i"/>
32053203
</Properties>
32063204
</Component>
3207-
<Component class="javax.swing.JTextField" name="txtPX_ToPrice">
3205+
<Component class="com.toedter.calendar.JDateChooser" name="jDateChooser2">
32083206
<Properties>
32093207
<Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor">
3210-
<Font name="Segoe UI" size="24" style="0"/>
3208+
<Font name="Segoe UI" size="18" style="0"/>
32113209
</Property>
32123210
</Properties>
32133211
</Component>

0 commit comments

Comments
 (0)