Lesson 7
Add Text Area
if(1==1){
T.append(
"\n"+t1.getText()+"\t\t"+t2.getText()+"\t\t"+t3.getText()+"\t\t"+t4.getText()+"\n"
);
}
Add Table
String sql = "select * from Sell";
try {
st = c.prepareStatement(sql);
rs = st.executeQuery();
b3.setModel(DbUtils.resultSetToTableModel(rs));
} catch (Exception e) {
}
Print and Print Confirmation
int J = JOptionPane.showConfirmDialog(null, "Confirm print", "Print", JOptionPane.YES_NO_OPTION);
if(J==0){
try{
T.print();
String S = "insert into SOwner (Date, Money) values (?,?)";
st = c.prepareStatement(S);
st.setString(1, D.getText());
st.setString(2, r3.getText());
st.execute();
String sql = "delete from Sell";
st = c.prepareStatement(sql);
st.execute();
// JOptionPane.showMessageDialog(null, "Delete");
st.close();
rs.close();
}
catch(Exception e){}
Combo Box Selected
String R = c1.getSelectedItem().toString();
t1.setText(R);
try{
String sql = "select * from Product where Name like ? ";
st = c.prepareStatement(sql);
st.setString(1, t1.getText());
rs = st.executeQuery();
if(rs.next()){
t2.setText(rs.getString("Price"));
}
}
catch(Exception e){
}}
Get row selected from Table
int row = b3.getSelectedRow();
t1.setText(b3.getModel().getValueAt(row, 0).toString());
String sql = "select * from Sell where Item = '"+ t1.getText()+"' ";
try {
st = c.prepareStatement(sql);
rs = st.executeQuery();
if (rs.next()) {
t2.setText(rs.getString("Price"));
t3.setText(rs.getString("Amount"));
t4.setText(rs.getString("Total"));
}
} catch (Exception e) {
}
Calculate Price
float sum = 0;
//int sum1 = 0;
for(int i=0; i<b3.getRowCount();i++){
sum = sum + Float.parseFloat(b3.getValueAt(i, 3).toString());
//sum1 = sum1 + Integer.parseInt(b3.getValueAt(i, 2).toString());
}
r3.setText(String.format("%.2f", sum));
float R = Float.parseFloat(r1.getText());
R = sum/R;
r4.setText(String.format("%.2f", R));
float R1 = Float.parseFloat(r2.getText());
R1 = sum/R1;
r5.setText(String.format("%.2f", R1));
T.append("\n\n\t\t\t\t\tລວມ\tກີບ "+r3.getText()+"\n\t\t\t\t\t\tບາດ "+r4.getText()+"\n\t\t\t\t\t\tໂດລາ "+r5.getText());
Log in
String a = ttt.getText();
String b = ttt1.getText();
if(a == "" || b == ""){
JOptionPane.showMessageDialog(null, "Check User ແລະ Password");}
else{
String sql = "select * from Login where Users = ? and Pass = ?";
try {
st = c.prepareStatement(sql);
st.setString(1, ttt.getText());
st.setString(2, ttt1.getText());
rs = st.executeQuery();
if(rs.next()){
String R = rs.getString("Status");
switch(R){
case "Staff":
Staff P2 = new Staff();
P2.setVisible(true);
break;
case "Admin":
Owner P1 = new Owner();
P1.setVisible(true);
break;
default:
JOptionPane.showMessageDialog(null, "Incorrect");
}
}
// WinClose();
//MainStaff R = new MainStaff();
//R.setVisible(true);
}
catch (Exception e) {
JOptionPane.showMessageDialog(null, " ");
}
finally {
try {
rs.close();
st.close();
} catch (Exception e) {
}
}
}