import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableColumnModel;
import java.io.*;
import java.sql.*;
import java.util.*;
import java.util.ArrayList;
public class Combo extends JFrame implements WindowListener, ActionListener
{
private JButton sendButton = new JButton("Send Messages");
SammelMail main = new SammelMail();
JComboBox combo = new JComboBox();
JTable table = new JTable();
String INIEmailFrom;
String INIHost;
BufferedReader b;
String line;
String[] tmp = null;
int counter=0;
String DBServer;
String DBName;
String DBUser;
String DBPassword;
Connection connection;
public Combo()
{
super("Java email client");
Container contentPane = this.getContentPane();
contentPane.setLayout(new BorderLayout());
JPanel button = new JPanel();
button.setLayout(new FlowLayout(FlowLayout.LEFT));
button.add(sendButton);
contentPane.add(button);
sendButton.setEnabled(false);
sendButton.addActionListener(this);
String comboinhalt[] =
{
"Wählen Sie bitte eine Auftragsart", "Kundenaufträge", "lfd. Angebote", "Lieferscheine", "Rechnungen", "Historische Angebote", "Umsatzdaten", "Tool schliessen"
};
try
{
File Data = new File("C:/Dokumente und Einstellungen/Lempert/Desktop/Project/Data.ini");
b = new BufferedReader(new InputStreamReader(new FileInputStream(Data)));
while ((line = b.readLine()) != null)
{
tmp = line.split(": ");
if (counter==0)
INIEmailFrom=tmp[1];
else if (counter==1)
INIHost=tmp[1];
else if (counter==2)
DBServer=tmp[1];
else if (counter==3)
DBName=tmp[1];
else if (counter==4)
DBUser=tmp[1];
else if (counter==5)
DBPassword=tmp[1];
counter++;
}
b.close();
}
catch (IOException e)
{
System.out.println("Error during data reading");
}
try
{
String resultauftrag=new String();
Class.forName("oracle.jdbc.driver.OracleDriver");
//DriverManager.registerDriver (new oracle.jdbc.driver.OracleDriver());
String url = "jdbc:oracle:thin:@"+DBServer+":1521:"+DBName;
connection = DriverManager.getConnection(url, DBUser, DBPassword);
connection.setAutoCommit(true);
}
catch(ClassNotFoundException e1)
{
e1.printStackTrace();
}
catch(Exception e2)
{
e2.printStackTrace();
}
String[] title = new String[]
{
"KundenID", "AuftragsNr.", "Komm.Nr.", "Gedruckt am", "Umsatzwert", "WE", "Zustand"
};
final DefaultTableModel model = new DefaultTableModel (title,0);
table = new JTable(model)
{
public boolean isCellEditable(int rowIndex, int vColIndex)
{
return false;
}
};
getContentPane().add(new JScrollPane(table), BorderLayout.SOUTH );
TableColumnModel columnModel = table.getColumnModel();
columnModel.getColumn(0).setPreferredWidth(90);
columnModel.getColumn(1).setPreferredWidth(100);
columnModel.getColumn(2).setPreferredWidth(100);
columnModel.getColumn(3).setPreferredWidth(110);
columnModel.getColumn(4).setPreferredWidth(100);
columnModel.getColumn(5).setPreferredWidth(45);
columnModel.getColumn(6).setPreferredWidth(80);
table.getTableHeader().setReorderingAllowed(false);
setResizable(false);
table.setColumnSelectionAllowed(true);
table.setRowSelectionAllowed(false);
for (int i = 0; i < comboinhalt.length; i++)
combo.addItem(comboinhalt[i]);
getContentPane().add(combo, BorderLayout.WEST);
combo.addItemListener(new ItemListener()
{
public void itemStateChanged(ItemEvent e)
{
String resultauftrag=new String();
JComboBox selectedChoice = (JComboBox)e.getSource();
if (selectedChoice.getSelectedItem().equals("Tool schliessen"))
System.exit(0);
else if (selectedChoice.getSelectedItem().equals("Kundenaufträge"))
try
{
Statement auftrag = connection.createStatement();
resultauftrag = "SELECT customerid, AUF001, AUF012, AUF004, AUF015, AUF016, AUF020 FROM Auftrag WHERE customerid in (SELECT customerid FROM customer)";
ResultSet rs = auftrag.executeQuery(resultauftrag);
java.util.List customerid= new ArrayList();
java.util.List auf001 = new ArrayList();
java.util.List auf012 = new ArrayList();
java.util.List auf004 = new ArrayList();
java.util.List auf015 = new ArrayList();
java.util.List auf016 = new ArrayList();
java.util.List auf020 = new ArrayList();
while (rs.next())
{
customerid.add(rs.getString(1));
auf001.add(rs.getString(2));
auf012.add(rs.getString(3));
auf004.add(rs.getString(4));
auf015.add(rs.getString(5));
auf016.add(rs.getString(6));
auf020.add(rs.getString(7));
}
Map map = new HashMap();
map.put("CustomerID", customerid);
map.put("Auftragsnummer", auf001);
map.put("Kommissionsnummer", auf012);
map.put("Gedruckt am", auf004);
map.put("Umsatzwert", auf015);
map.put("WE", auf016);
map.put("Zustand", auf020);
java.util.List listcustomerid = (java.util.List) map.get("CustomerID");
java.util.List listauf001 = (java.util.List) map.get("Auftragsnummer");
java.util.List listauf012 = (java.util.List) map.get("Kommissionsnummer");
java.util.List listauf004 = (java.util.List) map.get("Gedruckt am");
java.util.List listauf015 = (java.util.List) map.get("Umsatzwert");
java.util.List listauf016 = (java.util.List) map.get("WE");
java.util.List listauf020 = (java.util.List) map.get("Zustand");
String outcustomerid;
String outlist001;
String outlist012;
String outlist004;
String outlist015;
String outlist016;
String outlist020;
int len=listauf001.size();
int count=model.getRowCount();
for (int o=0;o<count;o++)
{
model.removeRow(0);
}
for (int n=0;n<len;n++)
{
outcustomerid = (String) listcustomerid.get(n);
outlist001 = (String) listauf001.get(n);
outlist012 = (String) listauf012.get(n);
outlist004 = (String) listauf004.get(n);
outlist015 = (String) listauf015.get(n);
outlist016 = (String) listauf016.get(n);
outlist020 = (String) listauf020.get(n);
model.addRow(new String[] {outcustomerid, outlist001, outlist012, outlist004, outlist015, outlist016, outlist020});
}
sendButton.setEnabled(true);
}
catch(Exception e2)
{
e2.printStackTrace();
}
}
});
}
public static void main(String args[])
{
Combo frame = new Combo();
frame.setDefaultCloseOperation(Combo.EXIT_ON_CLOSE);
frame.setVisible(true);
frame.pack();
}
public void actionPerformed(ActionEvent e)
{
if (e.getSource() == sendButton)
{
int[] selectedRows = table.getSelectedRows();
int[] selectedColumns = table.getSelectedColumns();
for (int x=0; x<=table.getRowCount()-1;x++)
{
for (int y=0; y<=selectedColumns.length-1;y++)
{
Object yourValue = table.getModel().getValueAt(x, selectedColumns[y]);
SammelMail.main.appendText(yourValue + "\n"); // NEU
}
}
main.show();
}
}
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
public void windowActivated(WindowEvent e) {
}
public void windowClosed(WindowEvent e) {
}
public void windowDeactivated(WindowEvent e) {
}
public void windowDeiconified(WindowEvent e) {
}
public void windowIconified(WindowEvent e) {
}
public void windowOpened(WindowEvent e) {
}
}