📄 smainmenu.java
字号:
jLabel11.setForeground(Color.yellow);
return;
}
sql = "insert into small values('" + tf1 + "','" + tf8 +
"','" + tf7 + "') ";
String maxInfo = "insert into big values('" + tf7 + "');";
if (SDBManager.dbUpdate(maxInfo)) { //隐式插入大类如果成功
if (SDBManager.dbUpdate(sql)) { //再执行的插入小类
clearFont();
JOptionPane.showMessageDialog(this, "恭喜!增加操作成功!");
sql = "select * from small";
jTable1.setModel(new DefaultTableModel(SDBManager.getAll(sql),
v_small));
clear();
} else {
JOptionPane.showMessageDialog(this,
"不好意思!增加操作失败!请检查:" + sql +
"");
}
} else {
JOptionPane.showMessageDialog(this,
"不好意思!增加操作失败!请检查:" + maxInfo + "");
}
break;
case 4:
sql = "select id from cclass where id = '" + tf1 + "'";
if(!isIdTrue(tf1,sql)){
return;
}
if (tf4.length() == 0) { //判断客户文本框是否为空
jLabel5.setForeground(Color.yellow);
jLabel11.setText(" 客户类型未填写!");
jLabel11.setForeground(Color.yellow);
return;
} else {
sql = "select class from cclass where class = '" + tf4 +
"'";
if (!SDBManager.getOne(sql).isEmpty()) { //判断客户类型是否存在
jLabel5.setForeground(Color.yellow);
jLabel11.setText(" 客户类型已存在!");
jLabel11.setForeground(Color.yellow);
return;
}
char[] ch = tf4.toCharArray(); //转换客户类型以做判断
for (int i = 0; i < ch.length; i++) {
if (Character.isDigit(ch[i])) {
jLabel5.setForeground(Color.yellow);
jLabel11.setText(" 客户类型不能为数字!");
jLabel11.setForeground(Color.yellow);
return;
}
}
}
sql = "insert into cclass values('" + tf1 + "','" + tf4 +
"','" + tf9 + "')";
sql2 = "select * from cclass";
if(!isLetter(tf9,sql,sql2,v_cclass)){
return;
}
break;
case 5:
sql = "select id from state where id = '" + tf1 + "'";
if(!isIdTrue(tf1,sql)){
return;
}
if (tf5.length() == 0) { //判断状态是否为空
jLabel6.setForeground(Color.yellow);
jLabel11.setText(" 状态未填写,请填写状态!");
jLabel11.setForeground(Color.yellow);
return;
}
if(tf5.length() > 20){
jLabel6.setForeground(Color.yellow);
jLabel11.setText(" 状态长度不得超过20位!");
jLabel11.setForeground(Color.yellow);
return;
}else {
sql = "select states from state where states = '" + tf5 +
"'";
if (!SDBManager.getOne(sql).isEmpty()) {
jLabel6.setForeground(Color.yellow);
jLabel11.setText(" 状态已存在!");
jLabel11.setForeground(Color.yellow);
return;
}
char[] ch = tf5.toCharArray(); //转换状态以做判断
for (int i = 0; i < ch.length; i++) {
if (Character.isDigit(ch[i])) {
jLabel6.setForeground(Color.yellow);
jLabel11.setText(" 状态不能为数字!");
jLabel11.setForeground(Color.yellow);
return;
}
}
}
sql = "insert into state values('" + tf1 + "','" + tf5 +
"','" + tf9 + "')";
sql2 = "select * from state";
if(!isLetter(tf9,sql,sql2,v_state)){
return;
}
break;
case 6:
sql = "select id from step where id = '" + tf1 + "'";
if(!isIdTrue(tf1,sql)){
return;
}
if (tf6.length() == 0) { //判断职务类型文本框是否为空
jLabel7.setForeground(Color.yellow);
jLabel11.setText(" 职务未填写,请填写职务!");
jLabel11.setForeground(Color.yellow);
return;
}
if(tf6.length() > 20){
jLabel7.setForeground(Color.yellow);
jLabel11.setText(" 职务长度不得超过20位!");
jLabel11.setForeground(Color.yellow);
return;
}else {
sql = "select steps from step where steps = '" + tf6 +
"'";
if (!SDBManager.getOne(sql).isEmpty()) {
jLabel7.setForeground(Color.yellow);
jLabel11.setText(" 职务已存在!");
jLabel11.setForeground(Color.yellow);
return;
}
char[] ch = tf6.toCharArray(); //转换职务类型以做判断
for (int i = 0; i < ch.length; i++) {
if (Character.isDigit(ch[i])) {
jLabel7.setForeground(Color.yellow);
jLabel11.setText(" 职务不能为数字!");
jLabel11.setForeground(Color.yellow);
return;
}
}
}
sql = "insert into step values('" + tf1 + "','" + tf6 +
"','" + tf9 + "')";
sql2 = "select * from step";
if(!isLetter(tf9,sql,sql2,v_step)){
return;
}
break;
}
}
/**
* JTable监听调用用此方法tableClick(MouseEvent e)
* 自动获取JTable表单,单元格值
* 并赋值给对应选项的对应文本框
*/
public void tableClick(MouseEvent e) {
jTable1.setSelectionBackground(Color.GREEN);
int row = jTable1.getSelectedRow();
int col = jTable1.getSelectedColumn();
if (row > -1 && choose == 1) {
jTextField4.setText(jTable1.getValueAt(row, 0).toString());
jTextField5.setText(jTable1.getValueAt(row, 1).toString());
jTextField12.setText(jTable1.getValueAt(row, 2).toString());
}
if (row > -1 && choose == 2) {
jTextField4.setText(jTable1.getValueAt(row, 0).toString());
jTextField6.setText(jTable1.getValueAt(row, 1).toString());
jTextField12.setText(jTable1.getValueAt(row, 2).toString());
}
if (row > -1 && choose == 3) {
jTextField4.setText(jTable1.getValueAt(row, 0).toString());
jTextField11.setText(jTable1.getValueAt(row, 1).toString());
jTextField10.setText(jTable1.getValueAt(row, 2).toString());
}
if (row > -1 && choose == 4) {
jTextField4.setText(jTable1.getValueAt(row, 0).toString());
jTextField7.setText(jTable1.getValueAt(row, 1).toString());
jTextField12.setText(jTable1.getValueAt(row, 2).toString());
}
if (row > -1 && choose == 5) {
jTextField4.setText(jTable1.getValueAt(row, 0).toString());
jTextField8.setText(jTable1.getValueAt(row, 1).toString());
jTextField12.setText(jTable1.getValueAt(row, 2).toString());
}
if (row > -1 && choose == 6) {
jTextField4.setText(jTable1.getValueAt(row, 0).toString());
jTextField9.setText(jTable1.getValueAt(row, 1).toString());
jTextField12.setText(jTable1.getValueAt(row, 2).toString());
}
}
/**
* 删除事务:
* 接收sql,sql2,sql3语句参数
* sql用来查询判断是否存在该记录
* sql2用来执行删除操作语句
* sql3用来查询整张表
* 判断是否有可删除的记录
* 如果通过则,执行先删除大类,再删除小类
*/
public void deleteLog(String sq1, String sql2, String sql3) {
if (SDBManager.getOne(sq1).isEmpty()) {
jLabel2.setForeground(Color.yellow);
jLabel11.setText(" 没有可删除的记录!");
jLabel11.setForeground(Color.yellow);
status();
return;
} else {
String tf1 = jTextField10.getText();
if (choose == 3) {
String sql4 = "select bigs from big where bigs = '" + tf1 + "'";
if (SDBManager.getOne(sql4).isEmpty()) {
jLabel8.setForeground(Color.yellow);
jLabel11.setText(" 没有可删除的大类记录!");
jLabel11.setForeground(Color.yellow);
status();
return;
}
}
//判断用户按的是“确定”还是“否”
int option = JOptionPane.showConfirmDialog(this, "是否确定要删除?", "删除?",
JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE, null);
if (option == JOptionPane.NO_OPTION) {
return;
}
SDBManager.dbUpdate("delete from big where bigs = '" + tf1 + "'"); //先删除大类
if (SDBManager.dbUpdate(sql2)) {
clearFont();
JOptionPane.showMessageDialog(this, "恭喜!删除成功!");
jTable1.setModel(new DefaultTableModel(SDBManager.getAll(sql3),
v_step));
clear();
status();
} else {
JOptionPane.showMessageDialog(this,
"不好意思!删除失败!请检查:" + sql2 + "");
}
}
}
/************************删除删除删除删除删除删除删除删除删除删除删除删除删除删除删除删除*******************/
public void jButton15_actionPerformed(ActionEvent e) { //删除按钮事件
jTextField5.setEditable(false);
jTextField6.setEditable(false);
jTextField7.setEditable(false);
jTextField8.setEditable(false);
jTextField9.setEditable(false);
jTextField10.setEditable(false);
jTextField11.setEditable(false);
jTextField12.setEditable(false);
String tf1 = jTextField4.getText();
String sql = null;
String sql2 = null;
String sql3 = null;
/**
* 对应不同的6个选项建立不同sql语句
* 并调用删除事务方法deleteLog(String sq1, String sql2, String sql3)
*/
switch (choose) {
case 1:
sql = "select id from style where id = '" + tf1 + "'";
sql2 = "delete from style where id = '" + tf1 + "'";
sql3 = "select * from style";
deleteLog(sql, sql2, sql3); //调用删除事务
break;
case 2:
sql = "select id from unit where id = '" + tf1 + "'";
sql2 = "delete from unit where id = '" + tf1 + "'";
sql3 = "select * from unit";
deleteLog(sql, sql2, sql3);
break;
case 3:
sql = "select id from small where id = '" + tf1 + "'";
sql2 = "delete from small where id = '" + tf1 + "'";
sql3 = "select * from small";
deleteLog(sql, sql2, sql3);
break;
case 4:
sql = "select id from cclass where id = '" + tf1 + "'";
sql2 = "delete from cclass where id = '" + tf1 + "'";
sql3 = "select * from cclass";
deleteLog(sql, sql2, sql3);
break;
case 5:
sql = "select id from state where id = '" + tf1 + "'";
sql2 = "delete from state where id = '" + tf1 + "'";
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -