📄 smainmenu.java~626~
字号:
jb = (JButton) v.elementAt(i - 1);
if (choose == i) {
jb.setIcon(n1);
} else {
jb.setIcon(null);
}
}
}
public void baseButton(ActionEvent e){ //基础按钮调用基础信息版面
cardLayout1.show(jPanel3, "jPanel6"); //利用卡片容器显示基础版面
baseTree(); //调用基础版面的数型结构
jTextField4.setEditable(false);
jTextField5.setEditable(false);
jTextField6.setEditable(false);
jTextField7.setEditable(false);
jTextField8.setEditable(false);
jTextField9.setEditable(false);
jTextField10.setEditable(false);
jTextField11.setEditable(false);
jTextField12.setEditable(false);
}
public void jButton1_actionPerformed(ActionEvent e) {//基础信息按纽
this.baseButton(e);
}
public void showTable(String sql,Vector vt){ //显示表格
Vector v = SDBManager.getAll(sql);
jTable1.setModel(new DefaultTableModel(v, vt));
}
public void jButton7_actionPerformed(ActionEvent e) { //款式显示表格
choose = 1;
adIcon(); //自动变更图标
clear(); //清空文本框
clearFont(); //清空字体和颜色
status(); //自动设置是否可编辑
showTable("select * from style",v_style); //传参数利用模型显示JTable
}
public void jButton8_actionPerformed(ActionEvent e) { //单位显示表格
choose = 2;
adIcon();
clear();
clearFont();
status();
showTable("select * from unit",v_unit);
}
public void jButton9_actionPerformed(ActionEvent e) { //大小类显示表格
choose = 3;
adIcon();
clear();
clearFont();
status();
showTable("select * from small",v_small);
}
public void jButton10_actionPerformed(ActionEvent e) { //客户显示表格
choose = 4;
adIcon();
clear();
clearFont();
status();
showTable("select * from cclass",v_cclass);
}
public void jButton11_actionPerformed(ActionEvent e) { //状态显示表格
choose = 5;
adIcon();
clear();
clearFont();
status();
showTable("select * from state",v_state);
}
public void jButton12_actionPerformed(ActionEvent e) { //职务显示表格
choose = 6;
adIcon();
clear();
clearFont();
status();
showTable("select * from step",v_step);
}
public boolean isIdTrue(String tf, String sql){ //增加按纽的事务,判断编号
if (tf.length() == 0) { //判断编号文本框是否为空
jLabel2.setForeground(Color.yellow); //设置颜色等
jLabel11.setText(" 编号未填写,请填写编号!");
jLabel11.setForeground(Color.yellow);
return false;
} else {
if (!SDBManager.getOne(sql).isEmpty()) { //如果不为空,则查询数据库判断编号是否存在
jLabel2.setForeground(Color.yellow);
jLabel11.setText(" 该编号已存在,重新输入!");
jLabel11.setForeground(Color.yellow);
return false;
}
}
if(tf.length() > 20){
jLabel2.setForeground(Color.yellow); //判断长度
jLabel11.setText(" 编号未填写,请填写编号!");
jLabel11.setForeground(Color.yellow);
return false;
}
return true;
}
public boolean isLetter(String tf,String sql,String sql2,Vector v){//增加按纽的事务,判断拼音码,并执行增加操作
if (tf.length() == 0) { //判断拼音码是否为空
jLabel10.setForeground(Color.yellow);
jLabel11.setText(" 拼音码未填写!");
jLabel11.setForeground(Color.yellow);
return false;
}
if(tf.length() > 20){
jLabel10.setForeground(Color.yellow);
jLabel11.setText(" 拼音码长度不得超过20位!");
jLabel11.setForeground(Color.yellow);
return false;
} else {
char[] ch = tf.toCharArray();
for (int i = 0; i < ch.length; i++) { //判断拼音码不能是字母以外的字符
if (!Character.isLetter(ch[i])) {
jLabel10.setForeground(Color.red);
jLabel11.setText(" 拼音码只能为字母!");
jLabel11.setForeground(Color.red);
return false;
}
}
}
if (SDBManager.dbUpdate(sql)) { //连接数据库---执行增加操作
clearFont();
JOptionPane.showMessageDialog(this, "恭喜!增加操作成功!");
jTable1.setModel(new DefaultTableModel(SDBManager.getAll(sql2),v));
clear();
} else {
JOptionPane.showMessageDialog(this,
"不好意思!增加操作失败!请检查:" + sql + "");
}
return true;
}
/***************增加增加增加增加增加增加增加增加增加增加增加增加增加增加增加增加增加增加*******************/
public void jButton14_actionPerformed(ActionEvent e) { //增加按钮事件
String tf1 = jTextField4.getText();
String tf2 = jTextField5.getText();
String tf3 = jTextField6.getText();
String tf4 = jTextField7.getText();
String tf5 = jTextField8.getText();
String tf6 = jTextField9.getText();
String tf7 = jTextField10.getText();
String tf8 = jTextField11.getText();
String tf9 = jTextField12.getText();
switch (choose) { //对应款式表的判断
case 1:
String sql = "select id from style where id = '" + tf1 + "'";
if(!isIdTrue(tf1,sql)){
return;
}
if (tf2.length() == 0) { //判断款式是否为空
jLabel3.setForeground(Color.yellow);
jLabel11.setText(" 款式未填写,请填写款式!");
jLabel11.setForeground(Color.yellow);
return;
}
if(tf2.length() > 20){
jLabel3.setForeground(Color.yellow);
jLabel11.setText(" 款式长度不得超过20位!");
jLabel11.setForeground(Color.yellow);
return;
}else {
sql = "select styles from style where styles = '" + tf2 +
"'";
if (!SDBManager.getOne(sql).isEmpty()) {
jLabel3.setForeground(Color.yellow);
jLabel11.setText(" 该款式已存在,重新输入!");
jLabel11.setForeground(Color.yellow);
return;
}
}
sql = "insert into style values('" + tf1 + "','" + tf2 +
"','" + tf9 + "')";
String sql2 = "select * from style";
if(!isLetter(tf9,sql,sql2,v_style)){
return;
}
break;
case 2:
sql = "select id from unit where id = '" + tf1 + "'";
if(!isIdTrue(tf1,sql)){
return;
}
if (tf3.length() == 0) { //判断单位是否为空
jLabel4.setForeground(Color.yellow);
jLabel11.setText(" 单位未填写,请填写单位!");
jLabel11.setForeground(Color.yellow);
return;
}
if(tf3.length() > 20){
jLabel4.setForeground(Color.yellow);
jLabel11.setText(" 单位长度不得超过20位!");
jLabel11.setForeground(Color.yellow);
return;
}
sql = "insert into unit values('" + tf1 + "','" + tf3 +
"','" + tf9 + "')";
sql2 = "select * from unit";
if(!isLetter(tf9,sql,sql2,v_unit)){
return;
}
break;
case 3:
sql = "select id from small where id = '" + tf1 + "'";
if(!isIdTrue(tf1,sql)){
return;
}
if (tf7.length() == 0) { //判断大类是否为空
jLabel8.setForeground(Color.yellow);
jLabel11.setText(" 大类未填写,请填写大类!");
jLabel11.setForeground(Color.yellow);
return;
}
if(tf7.length() > 20){
jLabel8.setForeground(Color.yellow);
jLabel11.setText(" 大类长度不得超过20位!");
jLabel11.setForeground(Color.yellow);
return;
}else {
sql = "select bigs from big where bigs = '" + tf7 + "'"; //查询大类表bigs字段
if (!SDBManager.getOne(sql).isEmpty()) {
jLabel8.setForeground(Color.yellow);
jLabel11.setText(" 大类已存在,重新输入!");
jLabel11.setForeground(Color.yellow);
return;
}
}
if (tf8.length() == 0) { //判断小类是否为空
jLabel9.setForeground(Color.yellow);
jLabel11.setText(" 小类未填写,请填写小类!");
jLabel11.setForeground(Color.yellow);
return;
}else if(tf8.length() > 20){
jLabel9.setForeground(Color.yellow);
jLabel11.setText(" 小类长度不得超过20位!");
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(" 客户类型已存在!");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -