📄 newbacteriaget.java
字号:
package yd.pethospital.bacteriaregister.jdbc;
import java.sql.*;
import javax.swing.*;
import java.util.regex.*;
import yd.pethospital.bacteriaregister.view.*;
import yd.pethospital.share.SystemShare;
public class NewBacteriaGet {
Statement st;
public static String SQL,code,name,type,things; //存储:数据库语句、疫苗编号、疫苗名称、疫苗类型、注意事项
boolean check = false;
public JFrame frame;
public NewBacteriaGet(JFrame frame){
this.frame=frame;
if(setDao(check)){
frame.dispose();
}
}
public boolean setDao(boolean check){
try {
if(NewBacteria.TNum.getText().trim().equals("")){ //编号为空处理
JOptionPane.showMessageDialog(null,"疫苗编号不允许为空!","新增疫苗",JOptionPane.ERROR_MESSAGE);
NewBacteria.TNum.requestFocus();
return false;
}
Pattern codes=Pattern.compile("[0-9]{5}"); //编号格式处理
Matcher mcode=codes.matcher(NewBacteria.TNum.getText());
if (!mcode.matches()){
JOptionPane.showMessageDialog(null,"编号格式不符,重新输入!", "错误对话框",JOptionPane.ERROR_MESSAGE);
NewBacteria.TNum.setText("");
NewBacteria.TNum.requestFocus();
return false;
}
if(NewBacteria.TName.getText().trim().equals("")){ //新增疫苗名称
JOptionPane.showMessageDialog(null,"疫苗姓名不允许为空!","新增疫苗",JOptionPane.ERROR_MESSAGE);
NewBacteria.TName.requestFocus();
return false;
}
if(NewBacteria.CType.getSelectedItem().equals("多种动物用灭活疫苗")){ //新增疫苗类型
type="11";
}
else if(NewBacteria.CType.getSelectedItem().equals("马牛羊用灭活疫苗")){
type="12";
}
else if(NewBacteria.CType.getSelectedItem().equals("猪用活疫苗")){
type="13";
}
else if(NewBacteria.CType.getSelectedItem().equals("禽用活疫苗")){
type="14";
}
else if(NewBacteria.CType.getSelectedItem().equals("其它动物用活疫苗")){
type="15";
}
else if(NewBacteria.CType.getSelectedItem().equals("治疗用抗血清")){
type="31";
}
else if(NewBacteria.CType.getSelectedItem().equals("诊断制剂")){
type="41";
}
else if(NewBacteria.CType.getSelectedItem().equals("微生态制剂")){
type="51";
}
code=NewBacteria.TNum.getText(); //新增疫苗编号
name=NewBacteria.TName.getText();
things=NewBacteria.TAttention.getText(); //新增注意事项
String Srecord="('"+ code + "','"+name +"','" +type +"','" +things +"')"; //数据库语句
SystemShare.SQL="insert into BacterinInfo values" + Srecord;
SystemShare.getConnection();
st=SystemShare.con.createStatement();
st.executeUpdate(SystemShare.SQL); //处理数据库
SystemShare.newsuccess();
frame.dispose();
new BacteriaRegister();
this.check=check;
}catch (SQLException e) {
SystemShare.newfail();
}
SystemShare.close();
return false;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -