/*
* Main.java
*
* Created on 6. September 2007, 19:17
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package tickettsystem;
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
import javax.swing.*;
/**
*
* @author tool
*/
public class Main extends JFrame implements ActionListener{
private ButtonGroup buttonGroup1;
private JButton senden1, senden2;
private JComboBox jcAbteilung, jcSoftware, jcDringlichkeit ;
private JLabel jlName, jlTelefon, jlAbteilung, jlEmail, jlDringlichkeit, jlStaus, jlTNummer, jlAntwort;
private JRadioButton rb1, rb2;
private JScrollPane jScrollPane1;
private JTextArea jTextArea1;
private JPanel panelTicket;
private JTextField tfAbteilung, tfEmail, tfName, tfTelefon, jtStatus, jtAntwort;
private JSeparator jSeparator1;
/** Creates a new instance of Main */
public Main() {
buttonGroup1 = new ButtonGroup();
jlName = new JLabel();
jlTelefon = new JLabel();
jlAbteilung = new JLabel();
jlEmail = new JLabel();
tfName = new JTextField();
tfTelefon = new JTextField();
tfEmail = new JTextField();
jcAbteilung = new JComboBox();
rb1 = new JRadioButton();
rb2 = new JRadioButton();
jcSoftware = new JComboBox();
jlDringlichkeit = new JLabel();
jcDringlichkeit = new JComboBox();
senden1 = new JButton();
senden2 = new JButton();
jScrollPane1 = new JScrollPane();
jTextArea1 = new JTextArea();
jSeparator1 = new JSeparator();
jlStaus = new JLabel();
jlTNummer = new JLabel();
jtStatus = new JTextField();
jlAntwort = new JLabel();
jtAntwort = new JTextField();
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
setTitle("Ticket Absenden / Status Abfragen");
jlName.setText("Name");
tfName.setText("");
jlTelefon.setText("Telefon");
tfTelefon.setText("");
jlAbteilung.setText("Abteilung");
jcAbteilung.setModel(new DefaultComboBoxModel(new String[] { "EDV"}));
jlEmail.setText("Email");
tfEmail.setText("");
rb1.setText("Hardware");
rb1.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
rb1.setMargin(new java.awt.Insets(0, 0, 0, 0));
rb2.setText("Software");
rb2.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
rb2.setMargin(new java.awt.Insets(0, 0, 0, 0));
jcSoftware.setModel(new DefaultComboBoxModel(new String[] { "", "Axapta", "Office Anwendung"}));
jlDringlichkeit.setText("Dringlichkeit");
jcDringlichkeit.setModel(new DefaultComboBoxModel(new String[] { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10" }));
senden1.setText("Absenden");
jTextArea1.setColumns(20);
jTextArea1.setRows(5);
jScrollPane1.setViewportView(jTextArea1);
jlStaus.setText("Statusabfrage");
jlTNummer.setText("Ticketnummer: ");
jtStatus.setText("");
jtStatus.setColumns(10);
senden2.setText("Absenden");
senden1.setActionCommand("Ticket");
senden1.addActionListener(this);
senden2.setActionCommand("Status");
senden2.addActionListener(this);
jlAntwort.setText("Antwort:");
jtAntwort.setText("");
buttonGroup1.add(rb1);
buttonGroup1.add(rb2);
buttonGroup1.getButtonCount();
GroupLayout layout = new GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addComponent(jSeparator1, GroupLayout.DEFAULT_SIZE, 798, Short.MAX_VALUE)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING, false)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addComponent(jlAbteilung)
.addComponent(jlEmail)
.addComponent(jlTelefon)
.addComponent(jlName))
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING, false)
.addComponent(jcAbteilung, 0, 93, Short.MAX_VALUE)
.addComponent(tfEmail)
.addComponent(tfTelefon)
.addComponent(tfName)))
.addComponent(rb1)
.addGroup(layout.createSequentialGroup()
.addComponent(rb2)
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jcSoftware, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
.addComponent(jlDringlichkeit)
.addComponent(jcDringlichkeit, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
.addComponent(senden1))
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jScrollPane1, GroupLayout.DEFAULT_SIZE, 650, Short.MAX_VALUE))
.addComponent(jlStaus)
.addGroup(layout.createSequentialGroup()
.addComponent(jlTNummer)
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jtStatus, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jlAntwort)
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jtAntwort, GroupLayout.PREFERRED_SIZE, 119, GroupLayout.PREFERRED_SIZE))
.addComponent(senden2))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.TRAILING, false)
.addComponent(jScrollPane1, GroupLayout.Alignment.LEADING)
.addGroup(GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
.addComponent(jlName)
.addComponent(tfName, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
.addComponent(jlTelefon)
.addComponent(tfTelefon, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
.addComponent(jlAbteilung)
.addComponent(jcAbteilung, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
.addComponent(jlEmail)
.addComponent(tfEmail, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addComponent(rb1)
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
.addComponent(rb2)
.addComponent(jcSoftware, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jlDringlichkeit)
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jcDringlichkeit, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addComponent(senden1)))
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jSeparator1, GroupLayout.PREFERRED_SIZE, 10, GroupLayout.PREFERRED_SIZE)
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jlStaus)
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
.addComponent(jlTNummer)
.addComponent(jtStatus, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
.addComponent(jlAntwort)
.addComponent(jtAntwort, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addComponent(senden2)
.addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
pack();
}
public static void Ticket(String user, String pw, String name, String telefon,String abteilung, String email, String problem, String software, String dringlichkeit, String hardware, String area, String swProblem){
String ticketnummer = "";
String sql = "insert into `ticket`(Person,Hardware,Software,Anliegen,dringlichkeit,email,telefon,abteilung,swproblem) values ("+name+","+hardware+","+software+","+area+","+dringlichkeit+","+email+","+telefon+","+abteilung+","+swProblem+")" ;
try {
String driver = "com.mysql.jdbc.Driver";
String url = "";
try {
url = lesen("server.txt");
} catch( FileNotFoundException e ) {
String ticketnr = "Datei nicht gefunden, \n" +
"bitte Informieren Sie ihren Administrator";
JDialog d1 = new JDialog();
JLabel nummer = new JLabel();
nummer.setText(ticketnr);
d1.add(nummer);
}
Class.forName(driver);
Connection con;
con = DriverManager.getConnection(url, user, pw);
Statement stmt = con.createStatement();
ResultSet rs ;
stmt.executeUpdate(sql);
rs = stmt.executeQuery("select `IDTicket`,`Anliegen` from Ticket Where `Anliegen` = "+area+" && 'Person' ="+name+" && Hardware = "+hardware+" && Software = "+software+";");
while (rs.next()){
String ticketnr = rs.getString("IDTicket");
System.out.println("Ticketnummer: "+ticketnr);
JFrame frame = new JFrame();
frame.setTitle("Ticketnummer");
frame.setSize(200, 200);
frame.setLocation(350, 300);
frame.setVisible(true);
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
JLabel nummer = new JLabel();
nummer.setText("Statusnummer: "+ticketnr);
frame.add(nummer);
System.out.print("nummer : "+nummer);
}
stmt.close();
rs.close();
con.close();
} catch(Exception ex) {
ex.printStackTrace();
}
}
public static String Status(String status, String pw, String user)
throws IOException{
String url = "";
try {
url = lesen("server.txt");
} catch( FileNotFoundException e ) {
String ticketnr = "Datei nicht gefunden, bitte Informieren Sie ihren Administrator";
JDialog d1 = new JDialog();
JLabel nummer = new JLabel();
nummer.setText(ticketnr);
d1.add(nummer);
}
String back = "";
String driver = "com.mysql.jdbc.Driver";
try {
Class.forName(driver);
Connection con;
con = DriverManager.getConnection(url, user, pw);
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("select `Status`, `IDTicket` from `ticket` where `IDTicket` = "+status+";");
rs = stmt.executeQuery("select `Status`, `IDTicket` from `ticket` where `IDTicket` = "+status+";");
while (rs.next()){
back = rs.getString("Status");
}
rs.close();
stmt.close();
con.close();
} catch(Exception ex) {
ex.printStackTrace();
}
int i = Integer.parseInt(back);
if (i == 0){
back = "Unbearbeitet";
}else{
if(i == 1){
back = "In Bearbeitung";
}else{
back = "Bearbeitet";
}
}
return back;
}
public void actionPerformed(ActionEvent e) {
String name = tfName.getText();
String telefon = tfTelefon.getText();
String abteilung = selectCB(jcAbteilung);
String email = tfEmail.getText();
String problem = "test";//buttonGroup1.getSelection().toString();
String hardware = selectRB(rb1, rb2);
String dringlichkeit = selectCB(jcSoftware);
String software = selectRB(rb2,rb1);
String area = jTextArea1.getText();
String user = "user";
String pw = "user";
String swProblem = selectCB(jcAbteilung);
String in = jtStatus.getText();
in = tauglich(in);
name = tauglich(name);
telefon = tauglich(telefon);
abteilung = tauglich(abteilung);
email = tauglich(email);
problem = tauglich(problem);
software = tauglich(software);
dringlichkeit = tauglich(dringlichkeit);
hardware = tauglich(hardware);
area = tauglich(area);
swProblem = tauglich(swProblem);
if (e.getActionCommand()== "Ticket"){
Ticket(user, pw, name, telefon, abteilung, email, problem, software, dringlichkeit, hardware, area, swProblem);
} else{
try{
jtAntwort.setText(Status(in, pw, user));
}catch (IOException ioe){
}
}
}
public static void main(String[] args) {
// TODO code application logic here
EventQueue.invokeLater(new Runnable() {
public void run() {
new Main().setVisible(true);
}
});
}
private String tauglich(String untauglich){
String neu = "'";
String neu2 = neu + untauglich + neu;
return neu2;
}
private String selectCB(JComboBox jb1){
String jb2 = jb1.getSelectedItem().toString();
return jb2;
}
private String selectRB(JRadioButton rb1, JRadioButton rb2){
String back = "";
if (rb1.isSelected()){//ist rb1 selektiert
back = "0";
}else{
back = "1";
}return back;
}
public static String lesen(String dateiname)
throws FileNotFoundException, IOException {
String line, inputstr = "";
try{
BufferedReader in = new BufferedReader(new FileReader(dateiname));
line = in.readLine();
inputstr = line;
in.close();
} catch( FileNotFoundException e ) {
String ticketnr = "Datei nicht gefunden, bitte Informieren Sie ihren Administrator";
JFrame frame = new JFrame();
frame.setTitle("Ticketnummer");
frame.setSize(200, 200);
frame.setLocation(350, 300);
frame.setVisible(true);
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
JLabel nummer = new JLabel();
nummer.setText(ticketnr);
frame.add(nummer);
}
return inputstr;
}
}