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

📄 addbooks.java

📁 基于UML的书店采购管理系统设计主要是供书店管理员使用。系统提供了管理员登陆
💻 JAVA
字号:
/* * To change this template, choose Tools | Templates * and open the template in the editor. */package book_booking;import java.awt.*;import java.awt.event.*;import javax.swing.*;import javax.swing.event.*;import java.util.*;import java.sql.*;/** * * @author Administrator */public class Addbooks extends JPanel implements ActionListener{      JTextField bookid,bookname,bookauthor,bookprice,bookpress,booknum;      JButton 录入,重置;//      JLabel jl = null; //      ImageIcon img = null;       public Addbooks()      {//          img = new ImageIcon("D:/book_booking/image/book"); //jl = new JLabel(img); //this.setLayout(new BorderLayout()); //this.add(jl, BorderLayout.CENTER);          bookid=new JTextField(10);          bookname=new JTextField(10);          bookauthor=new JTextField(10);          bookprice=new JTextField(10);          bookpress=new JTextField(10);          booknum=new JTextField(10);          录入=new JButton("录入",new ImageIcon("D:/book_booking/image/45.jpg"));	  重置=new JButton("重置",new ImageIcon("D:/book_booking/image/62.jpg"));	  录入.addActionListener(this);	  重置.addActionListener(this);                    Box box1=Box.createHorizontalBox();	  box1.add(new JLabel("书籍号:",JLabel.CENTER));	  box1.add(bookid);			  Box box2=Box.createHorizontalBox();	  box2.add(new JLabel("书名:",JLabel.CENTER));	  box2.add(bookname);			  Box box3=Box.createHorizontalBox();	  box3.add(new JLabel("作者:",JLabel.CENTER));	  box3.add(bookauthor);			  Box box4=Box.createHorizontalBox();	  box4.add(new JLabel("价格:",JLabel.CENTER));	  box4.add(bookprice);		          Box box5=Box.createHorizontalBox();	  box5.add(new JLabel("出版社:",JLabel.CENTER));	  box5.add(bookpress);                    Box box6=Box.createHorizontalBox();	  box6.add(new JLabel("进货量:",JLabel.CENTER));	  box6.add(booknum);			  Box boxH=Box.createVerticalBox();			  boxH.add(box1);	  boxH.add(box2);	  boxH.add(box3);	  boxH.add(box4);	  boxH.add(box5);	  boxH.add(box6);	  boxH.add(Box.createVerticalGlue());			  JPanel pCenter=new JPanel();	  pCenter.add(boxH);	  setLayout(new BorderLayout());	  add(pCenter,BorderLayout.CENTER);	  JPanel pSouth=new JPanel();	  pSouth.add(录入);	  pSouth.add(重置);	  add(pSouth,BorderLayout.SOUTH);	  validate();                         }      public void actionPerformed(ActionEvent e)	{	   if(e.getSource()==录入)             {		String number="";		number=bookid.getText().trim();//                String count="";//                int count=Integer.parseInt(booknum.getText().trim());                String count=booknum.getText().trim();		if(number.length()>0)		  { boolean boo=false;		    try{		  	 SqlBean sqlBean1=new SqlBean();                         String sqlStr="select * from books";                         ResultSet result=sqlBean1.executeQuery(sqlStr);		  	 		         while(result.next())		             {   		               String snumber="";		               snumber=result.getString("bookID");		  	       if(snumber.equals(number))		  	         {		  	   	   boo=true;	                           //String warning="该书籍基本信息已经存在,请到修改页面修改:";		  	   	   //JOptionPane.showMessageDialog(this,warning,"警告",JOptionPane.WARNING_MESSAGE);		  	          }		              }		           sqlBean1.CloseDataBase();		          }		     catch(Exception ee)		  	  {		  	  }		         if(boo==true)                         {                             String m="基本信息将被录入!";		  	   int ok=JOptionPane.showConfirmDialog(this,m,"确认",JOptionPane.YES_NO_OPTION,JOptionPane.INFORMATION_MESSAGE);                           if(ok==JOptionPane.YES_OPTION)                           {                               try                               {                                SqlBean sqlBean2=new SqlBean();                                String sqlStr="update books set bookCount=bookCount+"+"'"+count+"'"+" where bookID="+"'"+number+"'";                                int result=sqlBean2.executeUpdate(sqlStr);                                 sqlBean2.CloseDataBase();                               }                               catch(Exception ee)                               {                                                           }                               bookid.setText(null);                             bookname.setText(null);                             bookauthor.setText(null);                             bookprice.setText(null);                             bookpress.setText(null);                             booknum.setText(null);                           }                         }                         else if(boo==false)		  	 {		  	   	String m="基本信息将被录入!";		  	   	int ok=JOptionPane.showConfirmDialog(this,m,"确认",JOptionPane.YES_NO_OPTION,JOptionPane.INFORMATION_MESSAGE);		  	   	if(ok==JOptionPane.YES_OPTION)		  	   	  {		  	   	     String name=bookname.getText();		  	   	     String author=bookauthor.getText();		  	   	     String price=bookprice.getText();		  	   	     String press=bookpress.getText();                                     String num=booknum.getText();		  	   	     try{		  	   	  	  SqlBean sqlBean3=new SqlBean();                                          String sqlStr="insert into books values"+"("+"'"+number+"','"+name+"','"+author+"',"+price+",'"+press+"',"+num+")";                                          int result=sqlBean3.executeUpdate(sqlStr);                                           sqlBean3.CloseDataBase();		  	   	  	}		  	   	     catch(Exception ee)		  	   	  	{		  	   	        }		  	   	     bookid.setText(null);		  	   	     bookname.setText(null);		  	   	     bookauthor.setText(null);		  	   	     bookprice.setText(null);		  	   	     bookpress.setText(null);                                     booknum.setText(null);		  	   	  			  	   	   }		  	  }		  }		else		  {		  	String warning="必须输入书籍号!";JOptionPane.showMessageDialog(this,warning,"警告",JOptionPane.WARNING_MESSAGE);		  }		}	if(e.getSource()==重置)	  {	  	bookid.setText(null);		bookname.setText(null);	        bookauthor.setText(null);		bookprice.setText(null);		bookpress.setText(null);                booknum.setText(null);	  }		  	}                                                                  }

⌨️ 快捷键说明

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