Update DrukujBilet.java
This commit is contained in:
parent
2d9a141b32
commit
5f56b9f509
@ -1,25 +1,46 @@
|
||||
import javax.swing.AbstractButton;
|
||||
//import javax.swing.AbstractButton;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JOptionPane;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.ActionEvent;
|
||||
import javax.swing.JToggleButton;
|
||||
//import javax.swing.JToggleButton;
|
||||
import javax.swing.ListSelectionModel;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.awt.EventQueue;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Calendar;
|
||||
import java.util.GregorianCalendar;
|
||||
import java.util.TimeZone;
|
||||
import java.awt.Font;
|
||||
import java.awt.Color;
|
||||
import javax.swing.SwingConstants;
|
||||
import javax.swing.table.DefaultTableModel;
|
||||
|
||||
import net.proteanit.sql.DbUtils;
|
||||
|
||||
import javax.swing.JTable;
|
||||
//import javax.swing.JScrollPane;
|
||||
//import java.awt.*;
|
||||
//import javax.swing.JSplitPane;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.border.TitledBorder;
|
||||
import javax.swing.event.ListSelectionEvent;
|
||||
import javax.swing.event.ListSelectionListener;
|
||||
import javax.swing.UIManager;
|
||||
//import java.awt.event.MouseAdapter;
|
||||
//import java.awt.event.MouseEvent;
|
||||
//import java.awt.event.MouseListener;
|
||||
|
||||
import javax.swing.JTextArea;
|
||||
|
||||
public class DrukujBilet extends StolowkaZPM {
|
||||
|
||||
private JFrame MenuStolowkaZPM;
|
||||
String Dalej;
|
||||
|
||||
DefaultTableModel defaultTableModel = new DefaultTableModel();
|
||||
|
||||
@ -37,9 +58,64 @@ public class DrukujBilet extends StolowkaZPM {
|
||||
}
|
||||
|
||||
Connection conn=null;
|
||||
private JTable table_1;
|
||||
private JLabel lblClock;
|
||||
protected int sumaKoszt;
|
||||
protected int d1;
|
||||
protected int d2;
|
||||
protected int d3;
|
||||
protected int d4;
|
||||
protected int d5;
|
||||
protected int d6;
|
||||
protected String n1;
|
||||
protected String n2;
|
||||
protected String n3;
|
||||
protected String n4;
|
||||
protected String n5;
|
||||
protected String n6;
|
||||
protected int day;
|
||||
protected int month;
|
||||
protected int year;
|
||||
protected int sek;
|
||||
protected int min;
|
||||
protected int godz;
|
||||
//protected String OstatniIDbiletuString;
|
||||
//protected int OstatniIDbiletuInt;
|
||||
protected String dataIczas;
|
||||
|
||||
public void zegar() {
|
||||
Thread zegar = new Thread() {
|
||||
public void run() {
|
||||
try {
|
||||
for(;;) {
|
||||
Calendar cal = new GregorianCalendar();
|
||||
cal.setTimeZone(TimeZone.getTimeZone("Europe/Warsaw"));
|
||||
|
||||
int day = cal.get(Calendar.DAY_OF_MONTH);
|
||||
int month = cal.get(Calendar.MONTH);
|
||||
int year = cal.get(Calendar.YEAR);
|
||||
month=month+1;
|
||||
|
||||
int sek = cal.get(Calendar.SECOND);
|
||||
int min = cal.get(Calendar.MINUTE);
|
||||
int godz = cal.get(Calendar.HOUR);
|
||||
|
||||
lblClock.setText("Czas: "+godz+":"+min+":"+sek+" Data: "+day+"."+month+"."+year);
|
||||
dataIczas = year+"-"+month+"-"+day+" "+godz+":"+min+":"+sek;
|
||||
|
||||
sleep(1000);
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
};
|
||||
zegar.start();
|
||||
}
|
||||
|
||||
public DrukujBilet() throws SQLException {
|
||||
initialize();
|
||||
zegar();
|
||||
}
|
||||
|
||||
private void initialize() throws SQLException {
|
||||
@ -53,31 +129,291 @@ public class DrukujBilet extends StolowkaZPM {
|
||||
MenuStolowkaZPM.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
MenuStolowkaZPM.getContentPane().setLayout(null);
|
||||
MenuStolowkaZPM.setResizable(false);
|
||||
MenuStolowkaZPM.setSize(1700, 850);
|
||||
MenuStolowkaZPM.setSize(1700, 900);
|
||||
|
||||
JLabel lblMenu = new JLabel("MENU (Sto³ówka ZPM)");
|
||||
JLabel lblMenu = new JLabel("MENU (Sto\u0142\u00F3wka ZPM)");
|
||||
lblMenu.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
lblMenu.setBackground(Color.GREEN);
|
||||
lblMenu.setFont(new Font("Tahoma", Font.PLAIN, 70));
|
||||
lblMenu.setBounds(43, 13, 864, 97);
|
||||
lblMenu.setFont(new Font("Tahoma", Font.PLAIN, 50));
|
||||
lblMenu.setBounds(419, 32, 864, 91);
|
||||
MenuStolowkaZPM.getContentPane().add(lblMenu);
|
||||
|
||||
try {
|
||||
JLabel lblWybierzZMenu = new JLabel("Wybierz z tabeli co chcesz kupi\u0107");
|
||||
lblWybierzZMenu.setFont(new Font("Tahoma", Font.PLAIN, 35));
|
||||
lblWybierzZMenu.setBounds(280, 120, 1240, 76);
|
||||
MenuStolowkaZPM.getContentPane().add(lblWybierzZMenu);
|
||||
|
||||
JPanel TabelaMenu = new JPanel();
|
||||
TabelaMenu.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "", TitledBorder.CENTER, TitledBorder.BELOW_TOP, null, new Color(0, 0, 0)));
|
||||
TabelaMenu.setBounds(280, 189, 1206, 437);
|
||||
MenuStolowkaZPM.getContentPane().add(TabelaMenu);
|
||||
TabelaMenu.setLayout(null);
|
||||
|
||||
table_1 = new JTable();
|
||||
table_1.setFont(table_1.getFont().deriveFont(14f));
|
||||
table_1.setBounds(21, 56, 792, 368);
|
||||
TabelaMenu.add(table_1);
|
||||
table_1.setRowHeight(61);
|
||||
|
||||
//try {
|
||||
String query = "SELECT * FROM dania";
|
||||
PreparedStatement pst = conn.prepareStatement(query);
|
||||
ResultSet danie = pst.executeQuery();
|
||||
//table.setModel(DbUtils.resultSetToTableModel(rs))
|
||||
ResultSet rs = pst.executeQuery();
|
||||
table_1.setModel(DbUtils.resultSetToTableModel(rs));
|
||||
|
||||
Object[] columnData = new Object[3];
|
||||
JLabel lblId = new JLabel("ID");
|
||||
lblId.setFont(new Font("Tahoma", Font.PLAIN, 25));
|
||||
lblId.setBounds(118, 14, 39, 28);
|
||||
TabelaMenu.add(lblId);
|
||||
|
||||
JLabel lblNazwa = new JLabel("Nazwa");
|
||||
lblNazwa.setFont(new Font("Tahoma", Font.PLAIN, 25));
|
||||
lblNazwa.setBounds(366, 14, 94, 28);
|
||||
TabelaMenu.add(lblNazwa);
|
||||
|
||||
JLabel lblKosztz = new JLabel("Koszt (z\u0142)");
|
||||
lblKosztz.setFont(new Font("Tahoma", Font.PLAIN, 25));
|
||||
lblKosztz.setBounds(615, 15, 136, 27);
|
||||
TabelaMenu.add(lblKosztz);
|
||||
|
||||
lblClock = new JLabel("New label");
|
||||
lblClock.setFont(new Font("Tahoma", Font.PLAIN, 20));
|
||||
lblClock.setBounds(1277, 13, 405, 25);
|
||||
MenuStolowkaZPM.getContentPane().add(lblClock);
|
||||
|
||||
JTextArea txtrWybrano = new JTextArea();
|
||||
txtrWybrano.setEditable(false);
|
||||
txtrWybrano.setText("Suma kosztow wybranych da\u0144: 25 z\u0142");
|
||||
txtrWybrano.setForeground(Color.BLACK);
|
||||
txtrWybrano.setBackground(Color.WHITE);
|
||||
txtrWybrano.setLineWrap(true);
|
||||
txtrWybrano.setFont(new Font("Monospaced", Font.PLAIN, 20));
|
||||
txtrWybrano.setBounds(852, 37, 282, 51);
|
||||
TabelaMenu.add(txtrWybrano);
|
||||
txtrWybrano.setText("");
|
||||
|
||||
JTextArea textArea = new JTextArea();
|
||||
textArea.setLineWrap(true);
|
||||
textArea.setBounds(852, 101, 126, 28);
|
||||
TabelaMenu.add(textArea);
|
||||
textArea.setText("");
|
||||
|
||||
JTextArea textArea_1 = new JTextArea();
|
||||
textArea_1.setText("");
|
||||
textArea_1.setLineWrap(true);
|
||||
textArea_1.setBounds(852, 142, 126, 28);
|
||||
TabelaMenu.add(textArea_1);
|
||||
|
||||
JTextArea textArea_2 = new JTextArea();
|
||||
textArea_2.setText("");
|
||||
textArea_2.setLineWrap(true);
|
||||
textArea_2.setBounds(852, 183, 126, 28);
|
||||
TabelaMenu.add(textArea_2);
|
||||
|
||||
JTextArea textArea_3 = new JTextArea();
|
||||
textArea_3.setText("");
|
||||
textArea_3.setLineWrap(true);
|
||||
textArea_3.setBounds(852, 224, 126, 28);
|
||||
TabelaMenu.add(textArea_3);
|
||||
|
||||
JTextArea textArea_4 = new JTextArea();
|
||||
textArea_4.setText("");
|
||||
textArea_4.setLineWrap(true);
|
||||
textArea_4.setBounds(852, 265, 126, 28);
|
||||
TabelaMenu.add(textArea_4);
|
||||
|
||||
JTextArea textArea_5 = new JTextArea();
|
||||
textArea_5.setText("");
|
||||
textArea_5.setLineWrap(true);
|
||||
textArea_5.setBounds(852, 306, 126, 28);
|
||||
TabelaMenu.add(textArea_5);
|
||||
|
||||
JButton btnNewButton_1 = new JButton("Kasuj wybrane");
|
||||
btnNewButton_1.setBackground(Color.RED);
|
||||
btnNewButton_1.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent arg0) {
|
||||
d1 = 0;
|
||||
d2 = 0;
|
||||
d3 = 0;
|
||||
d4 = 0;
|
||||
d5 = 0;
|
||||
d6 = 0;
|
||||
n1 = "";
|
||||
n2 = "";
|
||||
n3 = "";
|
||||
n4 = "";
|
||||
n5 = "";
|
||||
n6 = "";
|
||||
sumaKoszt = 0;
|
||||
textArea.setText("");
|
||||
textArea_1.setText("");
|
||||
textArea_2.setText("");
|
||||
textArea_3.setText("");
|
||||
textArea_4.setText("");
|
||||
textArea_5.setText("");
|
||||
txtrWybrano.setText("");
|
||||
}
|
||||
});
|
||||
btnNewButton_1.setBounds(1000, 162, 149, 112);
|
||||
TabelaMenu.add(btnNewButton_1);
|
||||
|
||||
JLabel lblInfo = new JLabel("INFO");
|
||||
lblInfo.setBounds(852, 4, 282, 38);
|
||||
TabelaMenu.add(lblInfo);
|
||||
|
||||
sumaKoszt = 0;
|
||||
d1 = 0;
|
||||
d2 = 0;
|
||||
d3 = 0;
|
||||
d4 = 0;
|
||||
d5 = 0;
|
||||
d6 = 0;
|
||||
|
||||
ListSelectionModel model=table_1.getSelectionModel();
|
||||
model.addListSelectionListener(new ListSelectionListener() {
|
||||
public void valueChanged(ListSelectionEvent e) {
|
||||
if (! model.isSelectionEmpty()) {
|
||||
|
||||
int selectedRow=model.getMaxSelectionIndex();
|
||||
|
||||
|
||||
if (selectedRow == 0) {
|
||||
String Danie1 = "1";
|
||||
try {
|
||||
String query = "SELECT * FROM dania WHERE IDdania=?";
|
||||
PreparedStatement pst = conn.prepareStatement(query);
|
||||
pst.setString(1, Danie1);
|
||||
ResultSet rs = pst.executeQuery();
|
||||
String Koszt1 = rs.getString("KosztDania");
|
||||
n1 = rs.getString("NazwaDania");
|
||||
int k1 = Integer.parseInt(Koszt1);
|
||||
sumaKoszt = sumaKoszt+k1;
|
||||
d1 = d1+1;
|
||||
textArea.setText(d1+" szt "+n1);
|
||||
|
||||
} catch (Exception e1){
|
||||
JOptionPane.showMessageDialog(null, e1);
|
||||
}
|
||||
}
|
||||
|
||||
if (selectedRow == 1) {
|
||||
String Danie1 = "2";
|
||||
try {
|
||||
String query = "SELECT * FROM dania WHERE IDdania=?";
|
||||
PreparedStatement pst = conn.prepareStatement(query);
|
||||
pst.setString(1, Danie1);
|
||||
ResultSet rs = pst.executeQuery();
|
||||
String Koszt2 = rs.getString("KosztDania");
|
||||
n2 = rs.getString("NazwaDania");
|
||||
int k1 = Integer.parseInt(Koszt2);
|
||||
sumaKoszt = sumaKoszt+k1;
|
||||
d2 = d2+1;
|
||||
textArea_1.setText(d2+" szt "+n2);
|
||||
|
||||
} catch (Exception e1){
|
||||
JOptionPane.showMessageDialog(null, e1);
|
||||
}
|
||||
}
|
||||
|
||||
if (selectedRow == 2) {
|
||||
String Danie1 = "3";
|
||||
try {
|
||||
String query = "SELECT * FROM dania WHERE IDdania=?";
|
||||
PreparedStatement pst = conn.prepareStatement(query);
|
||||
pst.setString(1, Danie1);
|
||||
ResultSet rs = pst.executeQuery();
|
||||
String Koszt3 = rs.getString("KosztDania");
|
||||
n3 = rs.getString("NazwaDania");
|
||||
int k1 = Integer.parseInt(Koszt3);
|
||||
sumaKoszt = sumaKoszt+k1;
|
||||
d3 = d3+1;
|
||||
textArea_2.setText(d3+" szt "+n3);
|
||||
|
||||
} catch (Exception e1){
|
||||
JOptionPane.showMessageDialog(null, e1);
|
||||
}
|
||||
}
|
||||
|
||||
if (selectedRow == 3) {
|
||||
String Danie1 = "4";
|
||||
try {
|
||||
String query = "SELECT * FROM dania WHERE IDdania=?";
|
||||
PreparedStatement pst = conn.prepareStatement(query);
|
||||
pst.setString(1, Danie1);
|
||||
ResultSet rs = pst.executeQuery();
|
||||
String Koszt4 = rs.getString("KosztDania");
|
||||
n4 = rs.getString("NazwaDania");
|
||||
int k1 = Integer.parseInt(Koszt4);
|
||||
sumaKoszt = sumaKoszt+k1;
|
||||
d4 = d4+1;
|
||||
textArea_3.setText(d4+" szt "+n4);
|
||||
|
||||
} catch (Exception e1){
|
||||
JOptionPane.showMessageDialog(null, e1);
|
||||
}
|
||||
}
|
||||
|
||||
if (selectedRow == 4) {
|
||||
String Danie1 = "5";
|
||||
try {
|
||||
String query = "SELECT * FROM dania WHERE IDdania=?";
|
||||
PreparedStatement pst = conn.prepareStatement(query);
|
||||
pst.setString(1, Danie1);
|
||||
ResultSet rs = pst.executeQuery();
|
||||
String Koszt5 = rs.getString("KosztDania");
|
||||
n5 = rs.getString("NazwaDania");
|
||||
int k1 = Integer.parseInt(Koszt5);
|
||||
sumaKoszt = sumaKoszt+k1;
|
||||
d5 = d5+1;
|
||||
textArea_4.setText(d5+" szt "+n5);
|
||||
|
||||
} catch (Exception e1){
|
||||
JOptionPane.showMessageDialog(null, e1);
|
||||
}
|
||||
}
|
||||
|
||||
if (selectedRow == 5) {
|
||||
String Danie1 = "6";
|
||||
try {
|
||||
String query = "SELECT * FROM dania WHERE IDdania=?";
|
||||
PreparedStatement pst = conn.prepareStatement(query);
|
||||
pst.setString(1, Danie1);
|
||||
ResultSet rs = pst.executeQuery();
|
||||
String Koszt6 = rs.getString("KosztDania");
|
||||
n6 = rs.getString("NazwaDania");
|
||||
int k1 = Integer.parseInt(Koszt6);
|
||||
sumaKoszt = sumaKoszt+k1;
|
||||
d6 = d6+1;
|
||||
textArea_5.setText(d6+" szt "+n6);
|
||||
|
||||
} catch (Exception e1){
|
||||
JOptionPane.showMessageDialog(null, e1);
|
||||
}
|
||||
}
|
||||
|
||||
//@SuppressWarnings("unused")
|
||||
//int jakiWiersz = selectedRow;
|
||||
JOptionPane.showMessageDialog(null,"WYBRANO");
|
||||
txtrWybrano.setText("Suma kosztów wybranych pozycji: "+sumaKoszt+" z³");
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
rs.close();
|
||||
pst.close();
|
||||
|
||||
/*
|
||||
int count = 0;
|
||||
while (danie.next()) {
|
||||
while (rs.next()) {
|
||||
count=count+1;
|
||||
columnData[0] = danie.getString("IDdania");
|
||||
columnData[1] = danie.getString("NazwaDania");
|
||||
columnData[2] = danie.getString("KosztDania");
|
||||
|
||||
defaultTableModel.addRow(columnData);
|
||||
//columnData[0] = danie.getString("IDdania");
|
||||
//columnData[1] = danie.getString("NazwaDania");
|
||||
//columnData[2] = danie.getString("KosztDania");
|
||||
|
||||
//defaultTableModel.addRow(columnData);
|
||||
|
||||
//JToggleButton Baton = new JToggleButton(NazwaDania);
|
||||
//Baton.setBounds(192, 66, 137, 25);
|
||||
@ -85,25 +421,62 @@ public class DrukujBilet extends StolowkaZPM {
|
||||
}
|
||||
danie.close();
|
||||
pst.close();
|
||||
} catch (Exception e1){
|
||||
JOptionPane.showMessageDialog(null, e1);
|
||||
}
|
||||
*/
|
||||
//} catch (Exception e1){
|
||||
// JOptionPane.showMessageDialog(null, e1);
|
||||
//}
|
||||
|
||||
JButton btnNewButton = new JButton("Wybierz zaznaczone / Drukuj bilet");
|
||||
JButton btnNewButton = new JButton("Drukuj bilet");
|
||||
btnNewButton.setForeground(Color.BLACK);
|
||||
btnNewButton.setBackground(Color.GREEN);
|
||||
btnNewButton.setFont(new Font("Tahoma", Font.PLAIN, 40));
|
||||
btnNewButton.setBounds(514, 629, 696, 127);
|
||||
btnNewButton.setBounds(515, 692, 694, 91);
|
||||
MenuStolowkaZPM.getContentPane().add(btnNewButton);
|
||||
|
||||
btnNewButton.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
|
||||
|
||||
//try {
|
||||
/*
|
||||
try {
|
||||
String query = "SELECT * FROM bilety";
|
||||
PreparedStatement pst = conn.prepareStatement(query);
|
||||
ResultSet rs = pst.executeQuery();
|
||||
OstatniIDbiletuString = rs.getString("IDbiletu");
|
||||
int count = 0;
|
||||
while (rs.next()) {
|
||||
count=count+1;
|
||||
}
|
||||
if (count == 1) {
|
||||
JOptionPane.showMessageDialog(null, OstatniIDbiletuString+" OSTATNI ROW");
|
||||
}
|
||||
//int OstatniIDbiletuInt = Integer.parseInt(OstatniIDbiletuString);
|
||||
JOptionPane.showMessageDialog(null, OstatniIDbiletuString);
|
||||
rs.close();
|
||||
pst.close();
|
||||
|
||||
} catch (Exception e1){
|
||||
JOptionPane.showMessageDialog(null, e1);
|
||||
}
|
||||
*/
|
||||
|
||||
try {
|
||||
//OstatniIDbiletuInt = OstatniIDbiletuInt+1;
|
||||
//String OstatniIDbiletuString = Integer.toString(OstatniIDbiletuInt);
|
||||
String sumaKosztString = Integer.toString(sumaKoszt);
|
||||
String query = "INSERT INTO bilety(KtoZabralID,DataCzas,KosztBiletu,CzyZaplacony) VALUES (?,?,?,?)";
|
||||
PreparedStatement pst = conn.prepareStatement(query);
|
||||
pst.setInt(1, 1);
|
||||
pst.setDate(year, x);
|
||||
pst.setInt(3, 36);
|
||||
pst.setString(4, "nie");
|
||||
rs.close();
|
||||
pst.close();
|
||||
//JOptionPane.showMessageDialog(null, " ** "+IDuzytkownika+" ** "+dataIczas+" ** "+sumaKosztString+" ** "+"nie");
|
||||
MenuStolowkaZPM.setVisible(false);
|
||||
|
||||
// } catch (Exception e1){
|
||||
// JOptionPane.showMessageDialog(null, e1);
|
||||
//}
|
||||
} catch (Exception e1){
|
||||
JOptionPane.showMessageDialog(null, e1);
|
||||
}
|
||||
|
||||
}});
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user