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

📄 booksale.java

📁 站长这都是自己写的 一定要帮我开通啊谢谢了
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
	public void mouseClicked(MouseEvent event){}
	public void mouseEntered(MouseEvent event)
	{
		int red=(int)Math.floor(Math.random()*256);
		int green=(int)Math.floor(Math.random()*256);
		int blue=(int)Math.floor(Math.random()*256);
		selectstock.setForeground(new Color(red,green,blue));
		selectstat.setForeground(new Color(green,red,blue));
		selectsale.setForeground(new Color(blue,red,green));
		selectexit.setForeground(new Color(red,blue,green));
		selectback.setForeground(new Color(green,blue,red));
		selectadd.setForeground(new Color(red,red,green));
		selectdelete.setForeground(new Color(blue,green,green));
		selectquery.setForeground(new Color(blue,green,red));
	}
	public void mouseExited(MouseEvent event)
	{
		selectstock.setForeground(Color.black);
		selectstat.setForeground(Color.black);
		selectsale.setForeground(Color.black);
		selectback.setForeground(Color.black);
		selectexit.setForeground(Color.black);
		selectadd.setForeground(Color.black);
		selectdelete.setForeground(Color.black);
		selectquery.setForeground(Color.black);
	}
}


//销售窗口
class sale extends JFrame implements ActionListener
{
	private static final long serialVersionUID = 1L;
	
	method methods=new method();//实例化
	
	//下面是sale类的局部变量
	int buyamount=0;//buyamount为读者购书的数量
	float sellprice=0;//sellprice为每次卖书的总价格
	int leftmount=0;//售出书后剩余的书的数量
	
    Font myFont=new Font("宋体",Font.PLAIN,16);
	
    JButton saleconfirm;//确定
    JButton salereturntoselect;//返回到主界面
    JButton saleclear;//清除
	JLabel salebookname;//salehint 显示"书名"
	JTextField Tsalename;//书名
	JLabel saleamount;//showlist显示"数量"
	JTextField Tsaleamount;//数量
	JLabel showbookinf;//showsaleinf显示"本书的详细信息如下"
	JLabel showbookinf1;//showsaleinf显示"本次交易的信息"
	JTextArea saleshow=new JTextArea();//statshow用来显示某书的销售的详细信息
	JScrollPane saleshowscroll=new JScrollPane(saleshow);
	JTextArea saleshow1=new JTextArea();//statshow用来显示某书的销售的详细信息
	JScrollPane saleshowscroll1=new JScrollPane(saleshow1);
 	
 	selectface selectface;
 	
 	public sale(selectface selectptr)
 	{
        super("欢迎进入图书销售系统销售界面");
        
        selectface=selectptr;
 		
 		salebookname=new JLabel("书名");                            
 		salebookname.setFont(myFont);
 		salebookname.setForeground(Color.blue);
 		salebookname.setSize(80,25);
 		salebookname.setLocation(10,10);
 		
 		Tsalename=new JTextField();
 		Tsalename.setFont(myFont);
 		Tsalename.setForeground(Color.blue);
 		Tsalename.setSize(200,25);
 		Tsalename.setLocation(80,10);
	 
 		saleamount=new JLabel("数量");
 		saleamount.setFont(myFont);
 		saleamount.setForeground(Color.blue);
 		saleamount.setSize(80,25);
 		saleamount.setLocation(10,50);
 		
 		Tsaleamount=new JTextField();
 		Tsaleamount.setFont(myFont);
 		Tsaleamount.setForeground(Color.blue);
 		Tsaleamount.setSize(200,25);
 		Tsaleamount.setLocation(80,50);
	    	    
	    showbookinf=new JLabel("本书的详细信息:");                            
	    showbookinf.setFont(myFont);
	    showbookinf.setForeground(Color.blue);
	    showbookinf.setSize(150,20);
	    showbookinf.setLocation(10,80);
	    
	    showbookinf1=new JLabel("本次交易信息:");                            
	    showbookinf1.setFont(myFont);
	    showbookinf1.setForeground(Color.blue);
	    showbookinf1.setSize(150,20);
	    showbookinf1.setLocation(155,80);
	    
	    saleshowscroll.setFont(myFont);
	    saleshowscroll.setForeground(Color.blue);
	    saleshowscroll.setBackground(new Color(240,248,255));
	    saleshowscroll.setSize(135,150);
	    saleshowscroll.setLocation(10,110);
	    
	    saleshowscroll1.setFont(myFont);
	    saleshowscroll1.setForeground(Color.blue);
	    saleshowscroll1.setBackground(new Color(240,248,255));
	    saleshowscroll1.setSize(135,150);
	    saleshowscroll1.setLocation(155,110);
	    
	    salereturntoselect=new JButton("返回");
	    salereturntoselect.setFont(myFont);
	    salereturntoselect.setSize(80,20);
	    salereturntoselect.setLocation(15,300);
	    
				
	    saleconfirm=new JButton("确定");
	    saleconfirm.setFont(myFont);
	    saleconfirm.setSize(80,20);
	    saleconfirm.setLocation(105,300);
	    
	    saleclear=new JButton("清除");
	    saleclear.setFont(myFont);
	    saleclear.setSize(80,20);
	    saleclear.setLocation(195,300);
				
		Container salecp=getContentPane();	
		salecp.setLayout(null);//将布局方式设置为空
				
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setSize(310,400);
						
		salecp.add(salebookname);
		salecp.add(Tsalename);
		salecp.add(saleamount);
		salecp.add(Tsaleamount);
		salecp.add(showbookinf);
		salecp.add(showbookinf1);
		salecp.add(saleshowscroll);
		salecp.add(saleshowscroll1);
		salecp.add(salereturntoselect);
		salecp.add(saleconfirm);
		salecp.add(saleclear);
		salereturntoselect.addActionListener(this);
		saleconfirm.addActionListener(this);
	    saleclear.addActionListener(this);
		
	    salecp.setBackground(new Color(230,230,250));
		setVisible(false);//将窗口设置为不可见
 	}
 	
	public void actionPerformed(ActionEvent e)
    {
		if(e.getSource()==salereturntoselect)//salereturntoselect回到选择界面
		{
			this.setVisible(false);
			selectface.setVisible(true);
		}
		else if(e.getSource()==saleclear)
		{
        	clear();
        	Tsalename.requestFocus();
		}	
		else
		try{
			String getbookname=Tsalename.getText();
			String getsaleamount=Tsaleamount.getText();			
			buyamount=Integer.parseInt(getsaleamount);//将字符串型的getsaleamount转化为整型的buyamount	
            String querysql="select * from kucun where bookname='"+getbookname+"'";//通过书名进行查询 
            
            if(e.getSource()==saleconfirm)
            {    
            	methods.querykucun(querysql,saleshow);//调用实例methodsd的方法
                
            	float kucunprice=methods.kucunprice;//将库存的图书的价格赋值给kucunprice
            	String bookisbn=methods.bookisbn;//将库存的图书的isbn编号赋值给bookisbn
                int nowmount=methods.nowmount;//将库存中书的数量赋值给nowmount
                
                if(methods.querykucun(querysql,saleshow)==0)//读者需要的书在库存中不存在的情况
 	            {
 	        	   JOptionPane.showMessageDialog(null,"对不起,本店没有您需要的书!"); 
 	        	   Tsalename.setText(null);
 	        	   Tsaleamount.setText(null);
 	            }
 	            else if(buyamount>nowmount)//读者需要的书的数量大于库存的书的数量的情况
 	        	   {	        	      
 	        		  JOptionPane.showMessageDialog(null,"库存的书的数量不够!");
 	        		  clear();
 	        	   }
 	        	   else
 	        	   {   
 	        		  if(nowmount<23)//符合要求时的情况
 	        		  {
 	        			  JOptionPane.showMessageDialog(null,"可以购买本书,但库存量不足"+"("+nowmount+")"+"请及时进货");
 	        		  }	
 	        		  
 	        		  sellprice=kucunprice*buyamount;//计算卖出的书的总额
 	        		  
 	        		  String insertsql="insert into rxiaoshou values('"+getbookname+"','"+bookisbn+"',"+kucunprice+",'"+methods.returnTime()+"',"+buyamount+","+sellprice+")";
 	        	      methods.change(insertsql);//将售书的信息插入到日销售库中
 	        	      
 	        	      leftmount=nowmount-buyamount;//算出剩余的库存量
 	        	      
 	        	      String updatesql="update kucun set nowmount="+(leftmount)+" where ISBN='"+bookisbn+"'";
 	        	      methods.change(updatesql);
 	        	      saleshow1.setText("售书时间:"+methods.returnTime()+"\n数量为:"+buyamount+"\n单价为:"+kucunprice+"\n总金额为:"+sellprice);
 	        	      JOptionPane.showMessageDialog(null,"恭喜,销售已经成功~~");
 	        	  }	
            }               
	        }catch(NumberFormatException e1){JOptionPane.showMessageDialog(null,"书名错误或数量或者输入的格式错误");}
    }

	private void clear() 
	{
		Tsalename.setText(null);
		Tsaleamount.setText(null);
		saleshow.setText(null);
		saleshow1.setText(null);
	}
}

//进货操作界面
class stock extends JFrame implements ActionListener
{
	private static final long serialVersionUID = 1L;
	
	method methods=new method();
	
    Font myFont=new Font("宋体",Font.PLAIN,16);
	
    JButton stockreturntoselect;//返回
    JButton stockclear;//清除
    JButton stockconfirm;//确定
    JButton stockquery;//查询
	JLabel stockISBN;//salehint 显示"ISBN编号"
	JTextField TstockISBN;//ISBN编号
	JLabel stockamount;//stockamount显示"进货数量"
	JTextField Tstockamount;//进货数量
	JLabel stockbookinf;//showsaleinf显示"进货后本书的详细信息如下"
	JLabel stockbookinf1;
	JTextArea stockshow=new JTextArea();//statshow用来显示某书的销售的详细信息
	JScrollPane stockshowscroll=new JScrollPane(stockshow);
	JTextArea stockshow1=new JTextArea();//statshow用来显示某书的销售的详细信息
	JScrollPane stockshowscroll1=new JScrollPane(stockshow1);
		
 	selectface selectface;
 	
 	public stock(selectface selectptr)
 	{
        super("欢迎进入图书销售系统进货界面");
        
        selectface=selectptr;
 		
        stockISBN=new JLabel("ISBN编号*");                            
        stockISBN.setFont(myFont);
        stockISBN.setForeground(Color.blue);
        stockISBN.setSize(80,25);
        stockISBN.setLocation(10,10);
 		
        TstockISBN=new JTextField();
        TstockISBN.setFont(myFont);
        TstockISBN.setForeground(Color.blue);
        TstockISBN.setSize(185,25);
        TstockISBN.setLocation(100,10);
	 
        stockamount=new JLabel("进货数量*");
        stockamount.setFont(myFont);
        stockamount.setForeground(Color.blue);
        stockamount.setSize(80,25);
        stockamount.setLocation(10,50);
 		
        Tstockamount=new JTextField();
        Tstockamount.setFont(myFont);
        Tstockamount.setForeground(Color.blue);
        Tstockamount.setSize(185,25);
        Tstockamount.setLocation(100,50);
	    	    
        stockbookinf=new JLabel("进货书籍详细信息");                            
        stockbookinf.setFont(myFont);
        stockbookinf.setForeground(Color.blue);
        stockbookinf.setSize(135,25);
        stockbookinf.setLocation(10,85);
        
        stockbookinf1=new JLabel("本次进货详细信息");                            
        stockbookinf1.setFont(myFont);
        stockbookinf1.setForeground(Color.blue);
        stockbookinf1.setSize(135,25);
        stockbookinf1.setLocation(155,85);
	    
        stockshowscroll.setFont(myFont);
        stockshowscroll.setForeground(Color.blue);
        stockshowscroll.setBackground(Color.white);
        stockshowscroll.setSize(135,150);
        stockshowscroll.setLocation(10,115);
        
        stockshowscroll1.setFont(myFont);
        stockshowscroll1.setForeground(Color.blue);
        stockshowscroll1.setBackground(Color.white);
        stockshowscroll1.setSize(135,150);
        stockshowscroll1.setLocation(155,115);
        
        stockreturntoselect=new JButton("返回");
        stockreturntoselect.setFont(myFont);
        stockreturntoselect.setSize(80,20);
        stockreturntoselect.setLocation(155,315);	
				
        stockquery=new JButton("查询");
        stockquery.setFont(myFont);
        stockquery.setSize(80,20);
        stockquery.setLocation(45,285);		
        
        stockclear=new JButton("清除");
        stockclear.setFont(myFont);
        stockclear.setSize(80,20);
        stockclear.setLocation(45,315);
        
        stockconfirm=new JButton("确定");
        stockconfirm.setFont(myFont);
        stockconfirm.setSize(80,20);
        stockconfirm.setLocation(155,285);
        stockconfirm.setEnabled(false);
				
		Container stockcp=getContentPane();	
		stockcp.setBackground(new Color(240,248,255));
		stockcp.setLayout(null);//将布局方式设置为空
		
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setSize(310,400);
						
		stockcp.add(stockISBN);
		stockcp.add(TstockISBN);
		stockcp.add(stockamount);
		stockcp.add(Tstockamount);
		stockcp.add(stockbookinf);
		stockcp.add(stockbookinf1);
		stockcp.add(stockshowscroll);
		stockcp.add(stockshowscroll1);
		stockcp.add(stockreturntoselect);
		stockcp.add(stockclear);
		stockcp.add(stockquery);
		stockcp.add(stockconfirm);
		stockreturntoselect.addActionListener(this);
		stockquery.addActionListener(this);
		stockclear.addActionListener(this);
		stockconfirm.addActionListener(this);

		setVisible(false);//将窗口设置为可见
 	}
 	
	public void actionPerformed(ActionEvent e)
	{
		if(e.getSource()==stockreturntoselect)
		{
			this.setVisible(false);
			selectface.setVisible(true);
		}
		else if(e.getSource()==stockclear)
		{
			TstockISBN.setText(null);
			Tstockamount.setText(null);
			stockshow.setText(null);
			stockshow1.setText(null);
		}    
		else		
		try{
	    int stockmount1=0;//买书的数量
	    int kucuntotalmount=0;//将买进的图书的数量插入库存后的数量
		String querykucunsql="select * from kucun where nowmount<23";
		if(e.getSource()==stockquery)//检查是否有要购买的书籍
		{	
			stockconfirm.setEnabled(true);
			Tstockamount.setText(null);
			methods.querykucun(querykucunsql,stockshow);
			if(methods.querykucun(querykucunsql,stockshow)==0)
		    {
			    JOptionPane.showMessageDialog(null,"不需要进货!");
		    }
			else
			{   
				TstockISBN.setText(methods.bookisbn);
 				JOptionPane.showMessageDialog(null,"请输入要购买的书的数量");				
			}				
		}
		else if(e.getSource()==stockconfirm)//将购书信息加入进货库 并更新图书库
		{   
			stockmount1=Integer.parseInt(Tstockamount.getText());
			kucuntotalmount=methods.nowmount+stockmount1;
            //由于数据库中的查询总是显示的是最后一条纪录,对price采用降序的排列,就可以获得相应购买书籍的最小价格	
			String queryprovidersql="select * from provider where ISBN='"+methods.bookisbn+"'order by price desc";
			methods.queryprovider(queryprovidersql);
			String insertsql="insert into jhuoku values('"+methods.stockbookname+"','"+methods.stockISBN1+"',"+methods.stockprice+",'"+methods.stockprovider+"','"+methods.returnTime()+"',"+stockmount1+","+methods.stockprice*stockmount1+")";
			methods.change(insertsql);
			String updatesql="update kucun set nowmount="+kucuntotalmount+" where ISBN='"+methods.bookisbn+"'";
		    methods.change(updatesql);
		    stockshow1.setText("进货时间"+methods.returnTime()+"\n数量为:"+stockmount1+"\n单价为:"+methods.stockprice+"\n总金额为:"+methods.stockprice*stockmount1);

⌨️ 快捷键说明

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