📄 silooutupdatedialog.java
字号:
}
}
else if (this.action == this.DELETE) {
try {
if (params[0].getText() == null || params[0].getText().length() <= 0) {
JOptionPane.showMessageDialog(this, "请输入要删除的记录的序号!!", "错误提示!",
JOptionPane.ERROR_MESSAGE);
}
else {
String checkSql = "select * from " + Type.SILOOUTTABLE + " where 序号=" +
params[0].getText();
Statement sta1 = con.createStatement();
ResultSet set = sta1.executeQuery(checkSql);
if (set.next()) {
String sql = "delete from " + Type.SILOOUTTABLE + " where 序号=" +
params[0].getText();
sta1.close();
Statement sta = con.createStatement();
sta.executeUpdate(sql);
sta.close();
updateView();
JOptionPane.showMessageDialog(this, "记录删除成功!!!", "删除记录",
JOptionPane.INFORMATION_MESSAGE);
kit.beep();
clearFields();
}
else {
JOptionPane.showMessageDialog(this, "您输入的记录序号不存在,请确认后重新输入!!!",
"错误提示",
JOptionPane.ERROR_MESSAGE);
sta1.close();
}
}
}
catch (SQLException ex) {
JOptionPane.showMessageDialog(this, "删除错误!!!", "错误!!",
JOptionPane.ERROR_MESSAGE);
System.err.println(ex.toString());
}
}
}
class SiloOutUpdateDialog_okButt_actionAdapter
implements ActionListener {
private SiloOutUpdateDialog adaptee;
SiloOutUpdateDialog_okButt_actionAdapter(SiloOutUpdateDialog adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.okButt_actionPerformed(e);
}
}
class SiloOutUpdateDialog_cancelButt_actionAdapter
implements ActionListener {
private SiloOutUpdateDialog adaptee;
SiloOutUpdateDialog_cancelButt_actionAdapter(SiloOutUpdateDialog adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.cancelButt_actionPerformed(e);
}
}
class SiloOutUpdateDialog_deleteRadio_actionAdapter
implements ActionListener {
private SiloOutUpdateDialog adaptee;
SiloOutUpdateDialog_deleteRadio_actionAdapter(SiloOutUpdateDialog adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.deleteRadio_actionPerformed(e);
}
}
class SiloOutUpdateDialog_createRadio_actionAdapter
implements ActionListener {
private SiloOutUpdateDialog adaptee;
SiloOutUpdateDialog_createRadio_actionAdapter(SiloOutUpdateDialog adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.createRadio_actionPerformed(e);
}
}
private long getNextId() {
String nextId = "";
long longId = 0;
try {
Statement sta = con.createStatement();
ResultSet set = sta.executeQuery("select nextid from " +
Type.SILOOUTIDTABLE);
set.next();
nextId = set.getString(1);
set.close();
sta.close();
longId = Long.valueOf(nextId).longValue();
if (longId == Long.MAX_VALUE) {
longId = 10000;
}
sta = con.createStatement();
set = sta.executeQuery("select * from " + Type.SILOOUTTABLE +
" where 序号=" +
longId);
while (set.next()) {
longId++;
set.close();
sta.close();
sta = con.createStatement();
set = sta.executeQuery("select * from " + Type.SILOOUTTABLE +
" where 序号=" +
longId);
}
if (set != null) {
set.close();
set = null;
}
if (sta != null) {
sta.close();
sta = null;
}
sta = con.createStatement();
int col = sta.executeUpdate("update " + Type.SILOOUTIDTABLE +
" set nextId=" +
longId); //10001);
}
catch (SQLException e) {
System.err.println(e.toString());
e.printStackTrace();
}
return longId;
}
private boolean checkCanOut(String name, String outQuantity) {
Statement sta = null;
ResultSet set = null;
boolean result = false;
boolean canOut = false;
float floatQuantity = Float.parseFloat(outQuantity);
try {
sta = con.createStatement();
set = sta.executeQuery("select 数量 from " + Type.SILOTABLE +
" where 原料名='" + name + "'");
result = set.next();
float quantity = set.getFloat(1);
totalQuantity = quantity;
if (quantity >= floatQuantity) {
canOut = true;
}
set.close();
sta.close();
boolean returnValue = false;
returnValue = (result && canOut);
return returnValue;
}
catch (SQLException ex) {
JOptionPane.showMessageDialog(this, "请确认要出库的物品是否存在于原料库中!!", "错误提示", JOptionPane.INFORMATION_MESSAGE);
clearFields();
ex.printStackTrace();
return false;
}
}
private String insertDate(String sql) {
Calendar ca = Calendar.getInstance();
Date date = new Date(ca.getTime().getTime());
sql += "'" + date + "',";
int len = sql.length();
sql = sql.substring(0, len - 1);
sql += ")";
return sql;
}
private void updateView() {
try {
Statement sta = con.createStatement();
ResultSet set = sta.executeQuery("select * from " + Type.SILOOUTTABLE);
ResultSetMetaData meta = set.getMetaData();
int colCount = meta.getColumnCount();
int rowCount = parentPanel.tablePanel.tbModel.getRowCount();
for (int i = 0; i < rowCount; i++) {
parentPanel.tablePanel.tbModel.removeRow(0);
}
Vector colNames = new Vector();
Vector row;
for (int i = 1; i <= colCount; i++) {
colNames.add(meta.getColumnLabel(i));
}
parentPanel.tablePanel.tbModel.setColumnIdentifiers(colNames);
while (set.next()) {
row = new Vector();
for (int i = 1; i <= colCount; i++) {
String temp = set.getString(i);
if (temp.indexOf(" ") >= 0) {
temp = temp.substring(0, temp.indexOf(" "));
}
row.add(temp);
}
parentPanel.tablePanel.tbModel.addRow(row);
} //end while
if (parentPanel.tablePanel.tbModel.getRowCount() <= 0) {
kit.beep();
JOptionPane.showMessageDialog(this, "对不起,没有符合查找条件的记录,请修改数据重新查找!!");
}
}
catch (SQLException ex) {
System.err.println(ex.toString());
kit.beep();
JOptionPane.showMessageDialog(this, "查询错误,请检查输入是否正确!!");
}
catch (Exception ex2) {
System.err.println(ex2);
kit.beep();
JOptionPane.showMessageDialog(this, "查询错误!!!!");
}
validate();
repaint();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -