📄 smainmenu.java
字号:
*/
public void jPanel5_mouseClicked(MouseEvent e) {
int num = (int) Math.round(Math.random() * 9);
ImageIcon image = new ImageIcon("/Jewelry/desktop/20050118xy001_(" +
num + ").jpg");
jLabel1.setIcon(image);
}
/**
* 实现自动跟随按钮显示图标
*/
public void adIcon() {
Vector v = new Vector();
JButton jb = null;
v.addElement(jButton7);v.addElement(jButton8);v.addElement(jButton9);
v.addElement(jButton10);v.addElement(jButton11);v.addElement(jButton12);
v.addElement(jButton13);
for (int i = 1; i <= v.size(); i++) {
jb = (JButton) v.elementAt(i - 1);
if (choose == i) {
jb.setIcon(n1);
} else {
jb.setIcon(null);
}
}
}
/**
* baseButton()方法,接受传入的事件源执行
* 1,利用卡片容器显示基础版面内容
* 2,调用基础版面的数型结构
*/
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);
}
/**
* 基础信息按纽
* 调用baseButton()方法传入事件源
*/
public void jButton1_actionPerformed(ActionEvent e) {//
this.baseButton(e);
}
/**
* 接收传入的,sql语句,和vt表头
* 设置JTable模型,并显示
*/
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; //对应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);
}
/**
* 增加按纽的事务,判断编号
* 返回值boolean型,true通过验证,反之false不合标准
* 是否为空,是否已存在,是否长度小于20位
*/
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;
}
/**
* 增加按纽的事务
* 返回值boolean型,true通过验证,反之false不合标准
* 判断拼音码是否为空,是否长度小于20位,是否为字母
* 字母为true,其他false
* 如果通过则执行增加操作
*/
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位!");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -