📄 add_doctor.java
字号:
column27.setTableName("doctor");
column27.setWidth(14);
column27.setServerColumnName("email");
column27.setSqlType(1);
jPanel1.setBorder(BorderFactory.createEtchedBorder());
jPanel1.setBounds(new Rectangle(8, 237, 652, 164));
jPanel1.setLayout(null);
jPanel3.setBorder(BorderFactory.createEtchedBorder());
jPanel3.setBounds(new Rectangle(63, 49, 667, 408));
jPanel3.setLayout(null);
this.add(jLabel7);
this.add(jPanel3);
jPanel1.add(jPassword2);
jPanel1.add(jLabel5);
jPanel1.add(jLabel3);
jPanel1.add(jLabel1);
jPanel1.add(jTextName);
jPanel1.add(jPassword1);
jPanel1.add(jTNumber);
jPanel1.add(jTEmail);
jPanel1.add(jComboBox1);
jPanel1.add(jLabel2);
jPanel1.add(jLabel4);
jPanel1.add(jLabel6);
jPanel1.add(jBExit);
jPanel1.add(jBAdd);
jPanel3.add(jScrollPane1);
jPanel3.add(jPanel1);
jScrollPane1.getViewport().add(jdbTable1);
jComboBox1.addItem("");
jComboBox1.addItem("牙科");
jComboBox1.addItem("内科");
jComboBox1.addItem("外科");
jComboBox1.addItem("骨科");
jComboBox1.addItem("妇科");
queryDataSet1.setColumns(new Column[] {column20, column24, column25,
column27});
}
JScrollPane jScrollPane1 = new JScrollPane();
JdbTable jdbTable1 = new JdbTable();
Border border1 = BorderFactory.createEmptyBorder();
Border border2 = new TitledBorder(border1, "dfdf");
JButton jBAdd = new JButton();
JButton jBExit = new JButton();
JTextField jTextName = new JTextField();
JTextField jTNumber = new JTextField();
JTextField jTEmail = new JTextField();
JPasswordField jPassword1 = new JPasswordField();
JPasswordField jPassword2 = new JPasswordField();
JLabel jLabel1 = new JLabel();
JLabel jLabel2 = new JLabel();
JLabel jLabel3 = new JLabel();
JLabel jLabel4 = new JLabel();
JLabel jLabel5 = new JLabel();
JLabel jLabel6 = new JLabel();
Column column1 = new Column();
Column column2 = new Column();
Column column3 = new Column();
Column column4 = new Column();
Column column5 = new Column();
Column column6 = new Column();
Column column7 = new Column();
Column column8 = new Column();
Column column9 = new Column();
Column column10 = new Column();
Column column11 = new Column();
Column column12 = new Column();
Column column13 = new Column();
Column column14 = new Column();
Column column15 = new Column();
Column column16 = new Column();
Column column17 = new Column();
Database database1 = new Database();
javax.swing.JComboBox jComboBox1 = new JComboBox();
TitledBorder titledBorder1 = new TitledBorder("");
javax.swing.JLabel jLabel7 = new JLabel();
Column column18 = new Column();
Column column19 = new Column();
Column column21 = new Column();
Column column22 = new Column();
Column column23 = new Column();
QueryDataSet queryDataSet1 = new QueryDataSet();
Column column20 = new Column();
Column column24 = new Column();
Column column25 = new Column();
Column column27 = new Column();
javax.swing.JPanel jPanel1 = new JPanel();
javax.swing.JPanel jPanel3 = new JPanel();
public void jBAdd_actionPerformed(ActionEvent e) {
String strEmail=jTEmail.getText();
a=jPassword1.getText();
b=jPassword2.getText();
if(jTextName.getText().length()==0)
{
JOptionPane.showMessageDialog(null,"请输入要添加医生的姓名!");
jTextName.requestFocus();
}
else if(jComboBox1.getSelectedItem().equals(""))
{
JOptionPane.showMessageDialog(null,"请选择医生的职业!");
jComboBox1.requestFocus();
}
else if(!a.equals(b))
{
JOptionPane.showMessageDialog(null,"两次输入的密码不一致,请重新输入密码!");
jPassword1.setText("");
jPassword2.setText("");
jPassword1.requestFocus();
}
else if(jTNumber.getText().length()==0)
{
JOptionPane.showMessageDialog(null,"请输入医生的电话号码!");
jTNumber.requestFocus();
}
else if(Phone()==false)
{
JOptionPane.showMessageDialog(null,"你输入的电话号码有误,请重新输入!");
jTNumber.setText("");
jTNumber.requestFocus();
}
else if(jTEmail.getText().length()==0)
{
JOptionPane.showMessageDialog(null,"请输入医生的电子邮件!");
jTEmail.requestFocus();
}
else
{
String s = jTEmail.getText();
checkEmailID che = new checkEmailID(s);
if(!che.f)
{
jTEmail.setText("");
jTEmail.requestFocus();
}
else
{
adddoctor();
}
}
}
private void adddoctor()
{
try {
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
} catch (ClassNotFoundException ce) {
System.out.println(ce);
}
try {
String url = "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=clinique";
Connection con = DriverManager.getConnection(url,"sa","");
String sqlStr;
sqlStr="insert into doctor(name,password,profession,phonenumber,email) values(\'"+jTextName.getText()+"\',\'"+a+"\',\'"+jComboBox1.getSelectedItem()+"\',\'"+jTNumber.getText()+"\',\'"+jTEmail.getText()+"\')";
Statement s = con.createStatement();
s.executeUpdate(sqlStr);
JOptionPane.showMessageDialog(null,"数据添加成功!");
jTextName.setText("");
jComboBox1.setSelectedItem("");
jPassword1.setText("");
jPassword2.setText("");
jTNumber.setText("");
jTEmail.setText("");
s.close();
con.close();
queryDataSet1.refresh();
} catch (SQLException ce) {
System.out.println(ce);
}
}
private boolean Phone()
{
Phostr=jTNumber.getText();
for(int i=0;i<Phostr.length();i++)
{
char ch=Phostr.charAt(i);
if(ch<'0'||ch>'9')
return false;
}
return true;
}
public void jBExit_actionPerformed(ActionEvent e) {
jTextName.setText("");
jComboBox1.setSelectedItem("");
jPassword1.setText("");
jPassword2.setText("");
jTNumber.setText("");
jTEmail.setText("");
}
public void jBRefurbish_actionPerformed(ActionEvent e) {
main_frame zhu=new main_frame();
//zhu.jPanel1.removeAll();
// zhu.jPanel1.add(zhu.jpicture);
//zhu.jPanel1.add(jpicture);
// zhu.jpicture.setBounds(1,2,795,540);
//zhu.jpicture
// zhu.jPanel1.setVisible(true);
//about ab=new about();
// zhu.jPanel1.removeAll();
// zhu.jPanel1.add(ab);
//ab.setBounds(1,2,795,540);
//zhu.jPanel1.setVisible(true);
}
class EmailException extends Exception{
EmailException(){
super("你所输入的邮件格式错误,请重新输入!");
JOptionPane.showMessageDialog(null,"你所输入的邮件格式错误,请重新输入!","Error",JOptionPane.WARNING_MESSAGE);
}
}
class checkEmailID{
Boolean f;
String strEmail;
public checkEmailID(String s)
{
strEmail=s;
f=false;
try{
check(strEmail);
f=true;
}
catch(EmailException e){
System.out.println(e);
}
}
void check(String s) throws EmailException{
int a=strEmail.indexOf("@");
int b=strEmail.indexOf(".");
if(a<1||b==-1||a>b||b==(strEmail.length()-1)||strEmail.indexOf("@",a+1)!=strEmail.indexOf(".",b+1))
throw new EmailException();
}
}
}
class add_doctor_jBExit_actionAdapter implements ActionListener {
private add_doctor adaptee;
add_doctor_jBExit_actionAdapter(add_doctor adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jBExit_actionPerformed(e);
}
}
class add_doctor_jBAdd_actionAdapter implements ActionListener {
private add_doctor adaptee;
add_doctor_jBAdd_actionAdapter(add_doctor adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jBAdd_actionPerformed(e);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -