⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 newpetget.java

📁 宠物医院管理系统 包含宠物的注册 管理 收费 诊断等一系列过程控制 还包含配应的数据库 Jar包
💻 JAVA
字号:
package yd.pethospital.petregister.jdbc;

import java.sql.*;
import javax.swing.*;
import java.util.regex.*;
import yd.pethospital.petregister.view.*;
import yd.pethospital.share.SystemShare;

public class NewPetGet {
	                       
	Statement st;
	public static String code,name,cate,sex,birth,face,owener,date,SQL;      //存取编号,名称,类型,性别,生日,外貌,主人,日期,数据库语句
	boolean check = false;
	public JFrame frame;

	public NewPetGet(JFrame frame){
		
		this.frame=frame;
		if(setDao(check)){
			
			frame.dispose();
		}
	}
	
	public boolean setDao(boolean check){
		
		try {
			
			if(NewPet.TNum.getText().trim().equals("")){                       //判断编号为空及处理
				
				JOptionPane.showMessageDialog(null,"宠物编号不允许为空!","新增宠物",JOptionPane.ERROR_MESSAGE);
				NewPet.TNum.requestFocus();
				return false;
			}
			
			Pattern codes=Pattern.compile("[0-9]{8}");                          //格式的判断及处理
			Matcher mcode=codes.matcher(NewPet.TNum.getText()); 
			
			if (!mcode.matches()){ 
				
				JOptionPane.showMessageDialog(null,"编号格式不符,重新输入!", "错误对话框",JOptionPane.ERROR_MESSAGE);
				NewPet.TNum.setText("");
				NewPet.TNum.requestFocus();
                return false;
			} 
			
			if(NewPet.TName.getText().trim().equals("")){
				
				JOptionPane.showMessageDialog(null,"宠物姓名不允许为空!","新增宠物",JOptionPane.ERROR_MESSAGE);
				NewPet.TName.requestFocus();
				return false;
			}
			
			if(NewPet.male.isSelected()){                                        //判断并得到性别
				sex="雄性";
			}
			else if(NewPet.female.isSelected()){
				sex="雌性";
			}
			
			if(NewPet.TBirth.getText().trim().equals("")){
				
				JOptionPane.showMessageDialog(null,"出生日期不允许为空!","新增宠物",JOptionPane.ERROR_MESSAGE);
				NewPet.TBirth.requestFocus();
				return false;
			}                             
			                                                                   //生日格式的判断及处理
			Pattern births=Pattern.compile("(([0-9]{3}[1-9]|[0-9]{2}[1-9][0-9]{1}|[0-9]{1}[1-9][0-9]{2}|[1-9][0-9]{3})-(((0[13578]|1[02])-(0[1-9]|[12][0-9]|3[01]))|((0[469]|11)-(0[1-9]|[12][0-9]|30))|(02-(0[1-9]|[1][0-9]|2[0-8]))))|((([0-9]{2})(0[48]|[2468][048]|[13579][26])|((0[48]|[2468][048]|[3579][26])00))-02-29) "); 
			Matcher mbirth=births.matcher(NewPet.TBirth.getText()); 
		
			if (!mbirth.matches()){ 
				
				JOptionPane.showMessageDialog(null,"出生日期格式不符,重新输入!", "错误对话框",JOptionPane.ERROR_MESSAGE);
				NewPet.TBirth.setText("");
				NewPet.TBirth.requestFocus();
                return false;
			} 
			
			if(NewPet.THost.getText().trim().equals("")){
				
				JOptionPane.showMessageDialog(null,"宠物主人不允许为空!","新增宠物",JOptionPane.ERROR_MESSAGE);
				NewPet.THost.requestFocus();
				return false;
			}
			
			if(NewPet.TDate.getText().trim().equals("")){
				
				JOptionPane.showMessageDialog(null,"登记日期不允许为空!","新增宠物",JOptionPane.ERROR_MESSAGE);
				NewPet.TDate.requestFocus();
				return false;
			}
                                                                          //登记限定格式
			Pattern dates=Pattern.compile("(([0-9]{3}[1-9]|[0-9]{2}[1-9][0-9]{1}|[0-9]{1}[1-9][0-9]{2}|[1-9][0-9]{3})-(((0[13578]|1[02])-(0[1-9]|[12][0-9]|3[01]))|((0[469]|11)-(0[1-9]|[12][0-9]|30))|(02-(0[1-9]|[1][0-9]|2[0-8]))))|((([0-9]{2})(0[48]|[2468][048]|[13579][26])|((0[48]|[2468][048]|[3579][26])00))-02-29) "); 
			Matcher mdate=dates.matcher(NewPet.TDate.getText()); 
			
			if (!mdate.matches()){
				
				JOptionPane.showMessageDialog(null,"登记日期格式不符,重新输入!", "错误对话框",JOptionPane.ERROR_MESSAGE);
				NewPet.TDate.setText("");
				NewPet.TDate.requestFocus();
                return false;
			}
			
			code=NewPet.TNum.getText();                                        //得到宠物编号
			name=NewPet.TName.getText();                                     //名称的判断及处理
			cate=NewPet.CType.getSelectedItem();			                     //得到类型
			birth=NewPet.TBirth.getText();                                     //出生日期的判断及处理
			face=NewPet.TFace.getText();                                 //宠物外貌
			owener=NewPet.THost.getText();                               //宠物主人
			date=NewPet.TDate.getText();                                   //登记日期
			
			String Srecord="('"+ code + "','"+name +"','" +cate +"','" +sex +"','" +birth+"','" +face+"','"+ owener+"','"+date+"')";
			SystemShare.SQL="insert into PetInfo values" + Srecord;

			SystemShare.getConnection();
			st=SystemShare.con.createStatement();
			st.executeUpdate(SystemShare.SQL);                        //处理数据库
				
			SystemShare.newsuccess();
			frame.dispose();
			new PetRegister();

			this.check=check;

		}catch (SQLException e) {
			SystemShare.newfail();
		}
		SystemShare.close();
		return false;
	} 
		
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -