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

📄 paper.java

📁 报刊管理系统java做的
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
              	      {//当库中报刊数多于输入,进行订报操作
              	     	String fff = "insert into pbook values("+userNum+","+Pnumber+","+amount+","+ff+","+btime+")";//输入的sql语句
					   statement.executeUpdate(fff);//订阅信息插入库存					   
              	    
              	        
					   String jian="update paper set total=total-"+amount;
					        statement.executeUpdate(jian);//修改paper表的数量
					   
					   
					   	String jie ="SELECT paper.Pname FROM paper where paper.Pnumber="+Pnumber; //查询订阅的报刊名
					   		resultSet = statement.executeQuery(jie );					   		
					   		while(resultSet.next())
					   		{
					   	     ppp=resultSet.getString("Pname");	
					   		}		
					   	   
					   	 JFrame pp=new JFrame("");
					      String title="友情提示信息";				   	 
					   	 int type=JOptionPane.PLAIN_MESSAGE;
					      type=JOptionPane.INFORMATION_MESSAGE;
					   	  String   message="订阅该报成功,报刊名: "+ppp;
					      JOptionPane.showMessageDialog(f,message,title,type);			
					      pp.setLocation(400,400);
					      f.dispose();
					  }            	     	
              	     	
              	     	else{
					   	 JFrame pp=new JFrame("");
					      String title="错误提示信息";				   	 
					   	 int type=JOptionPane.PLAIN_MESSAGE;
					      type=JOptionPane.INFORMATION_MESSAGE;
					   	  String   message="报刊数量不足!";
					      JOptionPane.showMessageDialog(f,message,title,type);			
					      pp.setLocation(400,400);
					      //f.dispose();
					      }
					       		 
                      }    
                     
              	   }           	   
              	  
   	
                     
               }catch ( SQLException sqlex ) { 
                                               sqlex.printStackTrace();
                                               
                                               JFrame pp=new JFrame("");
					      String title="错误提示信息";				   	 
					   	 int type=JOptionPane.PLAIN_MESSAGE;
					      type=JOptionPane.INFORMATION_MESSAGE;
					   	  String   message="你输入的数据与表中有冲突,号码不存在或已订阅";
					      JOptionPane.showMessageDialog(pp,message,title,type);			
					      pp.setLocation(400,400);
					      f.dispose();
					                           
                                                
                                          }
                                          
                        
                                           
    }
               }
    });
      JButton cal=new JButton("取消");
      cal.addActionListener(new ActionListener(){
    	public void actionPerformed(ActionEvent ev){
    	 
    	if((ev.getActionCommand()).equals("取消")) 
    	 
              { f.dispose();
               }	 
    	
    	
    	}
    });    
      p1.add(l1);//
      p1.add(t1);//文本  
        
      p1.add(l2);//
      p1.add(t2);//文本  
      p1.add(l3);//
      p1.add(t3);//文本  
      p1.add(l4);//
      p1.add(t4);//文本 
     p1.add(l5);//
      p1.add(t5);//文本   
    
    p1.add(que);
    p1.add(cal);  
    contentPane.add(p1);    
    f.setLocation(400,300);
    f.setSize(300,200);
    	//f.pack();        
    	f.show();        
    	f.addWindowListener(new WindowAdapter() {            
    		public void windowClosing(WindowEvent e) {                    
    			f.dispose();          
    		}        
    	});  
}


////////////////////////////////////////////////////////////////////////////部门订阅
public void dbook()
{
	final JFrame f=new JFrame("部门报刊订阅");     
       Container contentPane=f.getContentPane();
       contentPane.setLayout(new BorderLayout());	
    JPanel p1=new JPanel();
    p1.setLayout(new GridLayout(6,2));
    p1.setBorder(BorderFactory.createTitledBorder("输入下列信息"));	 
    
    
      JLabel l1=new JLabel("订单号");
     final JTextField t1=new JTextField(); 
     
      JLabel l2=new JLabel("报刊号");
     final JTextField t2=new JTextField(); 
     
       
     
      JLabel l3=new JLabel("定购数量");
     final JTextField t3=new JTextField();
      
        
      JLabel l4=new JLabel("订阅期限");
     final JTextField t4=new JTextField();  
     
      JLabel l5=new JLabel("订阅日期");
     final JTextField t5=new JTextField();  
     
     JButton que=new JButton("确定");
    	 
    que.addActionListener(new ActionListener(){
    	public void actionPerformed(ActionEvent ev){
    	 
    	if((ev.getActionCommand()).equals("确定")) 
    	 
              {//响应事件
                 int bookNum=0,amount=0,btime=0,s=0,pf=0;
                 String  Pnumber,atime,p="";
                             bookNum=Integer.parseInt(t1.getText());//
                             Pnumber=t2.getText();
                             amount =Integer.parseInt(t3.getText()); 
			                 btime=Integer.parseInt(t4.getText());
			                 String ff=t5.getText();
                      dataBase();            
            try { //执行SQL语句 
                       
                          String ppp="",an=""; 
						String query ="SELECT bookNum ,Pnumber FROM Dbook"; //接受输入的sql语句查找是否订阅报纸
						statement = connection.createStatement(); 
						resultSet = statement.executeQuery( query );
                 while(resultSet.next())
					 {	
					     s=resultSet.getInt("bookNum");
					     p=resultSet.getString("Pnumber");				    
	    	if(bookNum==s&&(Pnumber.equals(p)))//当输入的数据与数据库中的相同
              	        {  
              	        	 JFrame pp=new JFrame("");
					      String title="错误提示信息";				   	 
					   	 int type=JOptionPane.PLAIN_MESSAGE;
					      type=JOptionPane.INFORMATION_MESSAGE;
					   	  String   message="该部门已经订阅过了该报";
					      JOptionPane.showMessageDialog(f,message,title,type);			
					      pp.setLocation(400,400);
              	        
              	       }
              else{//没有重复              	     	
              	     	 	String cha ="SELECT total FROM paper";//找报纸数量
					   	   resultSet = statement.executeQuery(cha );					   		
					   		while(resultSet.next())
					   		{
					   	      pf=resultSet.getInt("total");	
					   		}		
					   
              	      if(pf>amount)
              	      {//当库中报刊数多于输入,进行订报操作
              	     	
              	    
              	         String fff = "insert into Dbook values("+bookNum+","+Pnumber+","+amount+","+ff+","+btime+")";//输入的sql语句
					     statement.executeUpdate(fff);//更新数据 
					   
					   String jian="update paper set total=total-"+amount;
					        statement.executeUpdate(jian);//修改paper表的数量
					   
					   
					   	String jie ="SELECT paper.Pname FROM paper where paper.Pnumber="+Pnumber; //查询订阅的报刊名
					   		resultSet = statement.executeQuery(jie );					   		
					   		while(resultSet.next())
					   		{
					   	     ppp=resultSet.getString("Pname");	
					   		}		
					   	   
					   	 JFrame pp=new JFrame("");
					      String title="友情提示信息";				   	 
					   	 int type=JOptionPane.PLAIN_MESSAGE;
					      type=JOptionPane.INFORMATION_MESSAGE;
					   	  String   message="订阅该报成功,报刊名: "+ppp;
					      JOptionPane.showMessageDialog(f,message,title,type);			
					      pp.setLocation(400,400);
					      f.dispose();
					  }
					  else{
					  	     JFrame pp=new JFrame("");
					      String title="错误提示信息";				   	 
					   	 int type=JOptionPane.PLAIN_MESSAGE;
					      type=JOptionPane.INFORMATION_MESSAGE;
					   	  String   message="报刊数量不足!";
					      JOptionPane.showMessageDialog(f,message,title,type);			
					      pp.setLocation(400,400);				    
					  	
					      }
					       		 
                      }//else end   
                     
              	   } 
               }catch ( SQLException sqlex ) { 
                                               sqlex.printStackTrace();                                               
                                               JFrame pp=new JFrame("");
					      String title="错误提示信息";				   	 
					   	 int type=JOptionPane.PLAIN_MESSAGE;
					      type=JOptionPane.INFORMATION_MESSAGE;
					   	  String   message="你输入有冲突,可能号码不存在";
					      JOptionPane.showMessageDialog(f,message,title,type);			
					      pp.setLocation(400,400);
					      f.dispose();        
                                                
                  }
                                          
                        
                                           
    }
               }
    });
      JButton cal=new JButton("取消");
      cal.addActionListener(new ActionListener(){
    	public void actionPerformed(ActionEvent ev){
    	 
    	if((ev.getActionCommand()).equals("取消")) 
    	 
              { f.dispose();
               }	 
    	
    	
    	}
    });    
      p1.add(l1);//
      p1.add(t1);//文本  
        
      p1.add(l2);//
      p1.add(t2);//文本  
      p1.add(l3);//
      p1.add(t3);//文本  
      p1.add(l4);//
      p1.add(t4);//文本 
     p1.add(l5);//
      p1.add(t5);//文本   
    
    p1.add(que);
    p1.add(cal);  
    contentPane.add(p1);    
    f.setLocation(400,300);
    f.setSize(300,200);
    	//f.pack();        
    	f.show();        
    	f.addWindowListener(new WindowAdapter() {            
    		public void windowClosing(WindowEvent e) {                    
    			f.dispose();         
    		}        
    	});  


}

//============================================================连接数据库	
public void dataBase()
{
 String url = "jdbc:odbc:baozhi";//url中指定ODBC中设置的DSN名称paper  
               String username = ""; 
              String password = ""; 
try { //加载驱动程序以连接数据库 
       Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver" ); 
       connection = DriverManager.getConnection( url, username, password ); 
} catch ( ClassNotFoundException cnfex ) 
     {//捕获加载驱动程序异常  
       System.err.println("装载 JDBC/ODBC 驱动程序失败。" ); 
       cnfex.printStackTrace(); 
       System.exit( 1 ); // terminate program 
     }

       //捕获连接数据库异常 
  catch ( SQLException sqlex )
   { 
     System.err.println( "无法连接数据库" ); 
     sqlex.printStackTrace(); 
     System.exit( 1 ); // terminate program 
    }    
}	
	

//===================================================改变背景函数
public void changGround()
{
	   JFileChooser fileChooser = null;            
           fileChooser = new JFileChooser("D:\\");//建立一个FileChooser对象,并指定D:的目录为默认文件对话框路径.         
            File file=null;
            fileChooser.setApproveButtonText("确定");
            fileChooser.setDialogTitle("打开文件");
         int result = fileChooser.showOpenDialog(this);        
           
            if (result == JFileChooser.APPROVE_OPTION)
            {
                file = fileChooser.getSelectedFile();
             picture=file.getName();                
                
                System.out.print(file.getName());                
                
            }
            else if(result == JFileChooser.CANCEL_OPTION)
            {
               
            }
           im=Toolkit.getDefaultToolkit().getImage(file.getName());//装载背景图片     
             //repaint();

}//chbackground end

//===================================================改音乐
public void changMusic()
{
	
	    JFileChooser fileChooser = null;
           fileChooser = new JFileChooser("D:");//建立一个FileChooser对象,并指定C的目录为默认文件对话框路径.         
            File file=null;
            fileChooser.setApproveButtonText("确定");
            fileChooser.setDialogTitle("打开文件");          

         int result = fileChooser.showOpenDialog(this);         
           
            if (result == JFileChooser.APPROVE_OPTION)//如果按下的是确定
            {
                file = fileChooser.getSelectedFile(); 
                
                AudioPlayer.player.stop(cas);//停止原来的音乐
                            
                try{//循环播放声音
                
	   	       InputStream in = new FileInputStream(file.getName());
               AudioStream ass = new AudioStream(in);// Create AudioData source
               AudioData data = ass.getData();
               cas2 = new ContinuousAudioDataStream (data);             
               AudioPlayer.player.start(cas2);// Play audio.            
                 }catch(FileNotFoundException e){
	              System.out.print("FileNotFoundException ");
                }
           catch(IOException e){
		   System.out.print("音频文件有错误,没有打开");}   
	  
            }
            else if(result == JFileChooser.CANCEL_OPTION)//如果按下的是取消

⌨️ 快捷键说明

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