1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197
|
package gui.dialog;
import java.sql.ResultSet;
import gui.MainFrame;
import gui.panel.CPProjectList;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JTextField;
import com.jgoodies.forms.builder.PanelBuilder;
import com.jgoodies.forms.layout.CellConstraints;
import com.jgoodies.forms.layout.FormLayout;
import model.ProjectListTableModel;
import utilities.DatabaseConnection;
public class DialogProjectEdit extends JDialog {
private MainFrame frame = MainFrame.getInstance();
private DatabaseConnection dbc = frame.getConnectedDB();
private int projId = 0;
private JButton btEdit;
private JButton btCancel;
private JTextField projektName;
private JTextField projektId;
private JTextField createdDate;
public DialogProjectEdit(JFrame frame, boolean modal, int i){
super(frame, modal);
this.setProjId(i);
initialize();
setModal(modal);
this.setLocationRelativeTo(null);
}
private void initialize() {
this.setTitle("Projekt Ändern");
this.setSize(450, 180);
FormLayout layout = new FormLayout(
"right:[40dlu,pref], 3dlu, 40dlu, 7dlu, "
+ "right:[40dlu,pref], 3dlu, 60dlu",
"p, 3dlu, p, 3dlu, p, 9dlu, p, 3dlu, p, 14dlu, p");
PanelBuilder builder = new PanelBuilder(layout);
builder.setDefaultDialogBorder();
CellConstraints cc = new CellConstraints();
int row = 1;
builder.addLabel("Projektname:", cc.xy(1, row));
builder.add(getPName(), cc.xyw(3, row++, 5));
row++;
builder.addLabel("ProjektID:", cc.xy(1, row));
builder.add(getPId(), cc.xyw(3, row++, 5));
row++;
builder.addLabel("Erstellt am", cc.xy(1, row));
builder.add(getCDate(), cc.xyw(3, row++, 5));
row++;
builder.add(getbtEdit(), cc.xy(5, row));
builder.add(getbtCancel(), cc.xy(7, row));
this.getValues();
this.setContentPane(builder.getPanel());
}
private void getValues(){
try{
ResultSet rs = dbc.abfrage("select * from project_table where project_id = "+ this.getProjId() +" ;");
while( rs.next() ) {
this.projektId.setText(rs.getString(1));
this.projektName.setText(rs.getString(2));
this.createdDate.setText(rs.getString(3));}
} catch (Exception e) {
e.printStackTrace();
}
}
private void setProjId(int i){
this.projId = i + 1;
}
private int getProjId(){
return this.projId;
}
/**
* This method initializes tfName
*
* @return javax.swing.JTextField
*/
private JTextField getPName() {
if (projektName == null) {
projektName = new JTextField();
}
return projektName;
}
/**
* This method initializes tfName
*
* @return javax.swing.JTextField
*/
private JTextField getPId() {
if (projektId == null) {
projektId = new JTextField();
}
return projektId;
}
/**
* This method initializes tfName
*
* @return javax.swing.JTextField
*/
private JTextField getCDate() {
if (createdDate == null) {
createdDate = new JTextField();
}
return createdDate;
}
/**
* This method initializes btEdit
*
* @return javax.swing.JButton
*/
private JButton getbtEdit() {
if (btEdit == null) {
btEdit = new JButton();
btEdit.setText("Ändern");
final int id = this.getProjId();
btEdit.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
String query = "UPDATE project_table " +
"set created_date = \'"
+ createdDate.getText() + "\' WHERE project_id = "+ id +";";
if(dbc.setEintrag(query))
System.out.println("Query Successed");
DialogProjectEdit.this.setVisible(false);
DialogProjectEdit.this.dispose();
frame.loadPanel(new CPProjectList());
}
});
}
return btEdit;
}
/**
* This method initializes btCancel
*
* @return javax.swing.JButton
*/
private JButton getbtCancel() {
if (btCancel == null) {
btCancel = new JButton();
btCancel.setText("Abbrechen");
btCancel.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
DialogProjectEdit.this.setVisible(false);
DialogProjectEdit.this.dispose();
}
});
}
return btCancel;
}
} |
Partager