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

📄 rkguanli.java

📁 基于Java——SQL2005 的java课程设计 仓库管理系统。主要功能
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
									   PreparedStatement pstmt1 = null;
									   String sql2 = "";
									   InputStream photoStream1 = new FileInputStream(file);	
									   sql2 = "insert tb_Stor( [Eqp_Name] , [Stor_Num] ,[Eqp_Style] , [Eqp_Para],[Eqp_Pot]) VALUES (?,?,?,?,?)";	
									   pstmt1 = ((java.sql.Connection) conn).prepareStatement(sql2);								      
									      pstmt1.setString(1, Eqp_Name.getText().trim());
									      pstmt1.setString(2, In_Num.getText().trim());				
									      pstmt1.setString(3, (String) Eqp_Style.getItemAt(Eqp_Style.getSelectedIndex()));
									      pstmt1.setString(4, Eqp_Para.getText().trim());
										  pstmt1.setBinaryStream(5, photoStream1, (int) file.length());
									      pstmt1.executeUpdate();
									      pstmt1.close();
									      conn.close();
								
								}   	
								else 
									{
									int j=i+set.getInt(2);
									Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
								      conn = DriverManager.getConnection("jdbc:odbc:Storage");					  
								      java.sql.Statement stmt1 = conn.createStatement();
									   stmt1.close();
									   PreparedStatement pstmt1 = null;
									   String sql2 = "";
									   String sql3 = "";
									   InputStream photoStream1 = new FileInputStream(file);	
									   sql2 = "insert tb_Stor( [Eqp_Name] , [Stor_Num] ,[Eqp_Style] , [Eqp_Para],[Eqp_Pot]) VALUES (?,?,?,?,?)";	
									   sql3= "DELETE FROM tb_Stor where "+ "Eqp_Name='" + Eqp_Name.getText().trim() +"'";
									   pstmt1 = ((java.sql.Connection) conn).prepareStatement(sql3);
									   pstmt1.executeUpdate();
									   pstmt1 = ((java.sql.Connection) conn).prepareStatement(sql2);								      
									      pstmt1.setString(1, Eqp_Name.getText().trim());
									      pstmt1.setLong(2, j);				
									      pstmt1.setString(3, (String) Eqp_Style.getItemAt(Eqp_Style.getSelectedIndex()));
									      pstmt1.setString(4, Eqp_Para.getText().trim());
										  pstmt1.setBinaryStream(5, photoStream1, (int) file.length());
									      pstmt1.executeUpdate();
									      pstmt1.close();
									      conn.close();
									}
						      
					    }
					    catch (Exception e3) {
					      e3.printStackTrace();
					      JOptionPane.showMessageDialog(null, "连接数据库错误!");
					    }
					}
					JOptionPane   j   =   new   JOptionPane("入库成功,是否继续执行入库操作?",   JOptionPane.QUESTION_MESSAGE,JOptionPane.YES_NO_OPTION,null,new   Object[]{"  是  ","  否  "});   
				Object[]   xx   =   j.getOptions();   
				int k=JOptionPane.showOptionDialog(RKGuanLi.this,"入库成功,是否继续执行入库操作??","E时代仓库信息管理系统入库管理提示",JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE,null,xx,"  否  ");  
				if(k==0)
				{
					CZ.doClick();
					In_ID.setText("E_IN_"+dateStr+getMaxId());
				}
				else
				dispose();	
				
				} 
				}
				
				catch(java.lang.NumberFormatException e1) 
				{
					JOptionPane.showConfirmDialog(RKGuanLi.this, "设备单价无效,请重新填入", "E时代仓库信息管理系统入库管理提示",JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE);
					Eqp_Price.setText("");
					Eqp_Price.requestFocus();		
					
				} catch (SQLException e2) {
					e2.printStackTrace();
				} 			
				}
			}			
		});
				
		Eqp_Style.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				Item selectedItem;
				if (!(Eqp_Style.getSelectedItem() instanceof Item)) {
					return;
				}
				selectedItem = (Item) Eqp_Style.getSelectedItem();
			}
			});
		
		
		photoLabel.addMouseListener(new MouseAdapter() {// 添加鼠标监听器
			public void mouseClicked(MouseEvent e) {
				if (e.getClickCount() == 2) {// 判断是否为双击
					JFileChooser fileChooser = new JFileChooser();// 创建文件选取对话框
					fileChooser.setFileFilter(new FileFilter() {// 为对话框添加文件过滤器
								public String getDescription() {// 设置提示信息
									return "图像文件(.jpg;.gif)";
								}

								public boolean accept(File file) {// 设置接受文件类型
									if (file.isDirectory())// 为文件夹则返回true
										return true;
									String fileName = file.getName()
											.toLowerCase();
									if (fileName.endsWith(".jpg")
											|| fileName
													.endsWith(".gif"))// 为JPG或JIF格式文件则返回true
										return true;
									return false;// 否则返回false,即不显示在文件选取对话框中
								}
							});
					int i = fileChooser.showOpenDialog(getParent());// 弹出文件选取对话框并接收用户的处理信息
					if (i == fileChooser.APPROVE_OPTION) {// 用户选取了照片
						file = fileChooser.getSelectedFile();// 获得用户选取的文件对象
						if (file != null) {
							ImageIcon icon = new ImageIcon(file
									.getAbsolutePath());// 创建照片对象
							photoLabel.setText(null);// 取消提示文字
							photoLabel.setIcon(icon);// 显示照片		
							
							
									
							
							
						}
					}
				}
			}
		});
		
		

		addInternalFrameListener(new initTasks());
		
	}
	
	
	
	
	private void initTimeField() {// 启动进货时间线程
		new Thread(new Runnable() {
			public void run() {
				try {
					while (true) {
						Date jhsjDate = new Date();
						In_Time.setText(jhsjDate.toLocaleString());
						Thread.sleep(100);
					}
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
			}
		}).start();
	}
	

	
	// 设置组件位置并添加到容器中
	private void setupComponet(JComponent component, int gridx, int gridy,
			int gridwidth, int gridheight,int ipadx, boolean fill) {
		final GridBagConstraints gridBagConstrains = new GridBagConstraints();
		gridBagConstrains.gridx = gridx;
		gridBagConstrains.gridy = gridy;
		if (gridwidth > 1)
			gridBagConstrains.gridwidth = gridwidth;
		if(gridheight >1)
			gridBagConstrains.gridheight = gridheight;
		if (ipadx > 0)
			gridBagConstrains.ipadx = ipadx;
		gridBagConstrains.insets = new Insets(5, 1, 3, 1);
		if (fill)
			gridBagConstrains.fill = GridBagConstraints.HORIZONTAL;
		getContentPane().add(component, gridBagConstrains);
	}
	
	/*
	// 获取入库表中设备编号的13位后面的最大ID
	private static String getMaxId() throws SQLException {
		String MaxId="";
		String sqlyuju = "select * from tb_In";
		ResultSet set = sql.query(sqlyuju);
		if(set.next())   
		{   
			set.last();
			String ID =set.getString("In_ID");
			MaxId =ID.substring(13,ID.length());	
			int i=Integer.parseInt(MaxId);
			i++;
			MaxId=""+i;	
			return MaxId;
		}   	
		else 
			{
			MaxId="1";//表为空时从0001开始
			return MaxId;
			}
	}
	*/
	
	// 获取入库表中设备编号的13位后面的最大ID
	private static String getMaxId() throws SQLException {
		String MaxId=""+2;
		String sqlyuju = "select * from tb_In";
		ResultSet set = sql.query(sqlyuju);
		if(!set.next())
		{
			MaxId="1";//表为空时从0001开始
			return MaxId;
		}
		
		int i=1;
		for(;set.next();)   
		{   
			String ID =set.getString("In_ID");
			MaxId =ID.substring(13,ID.length());
			
			int j=Integer.parseInt(MaxId);
			if(j>i){
				i=j;				
			}			
			MaxId=""+(i+1);	
		}		
		return MaxId;
			
	}
	
	
	
	public class InputKeyListener extends KeyAdapter {
		public void keyTyped(KeyEvent e) {
			String key="0123456789"+(char)8;
			if(key.indexOf(e.getKeyChar())<0){
				e.consume();
			}
		}//只容许输入0到9的数字,键盘侦听
	}
	
	public class InputKeyListener1 extends KeyAdapter {
		String key=".0123456789"+(char)8;
		public void keyTyped(KeyEvent e) {		
			if(key.indexOf(e.getKeyChar())<0){
				e.consume();
			}
			//else if(key.indexOf(e.getKeyChar())==0)
			//	key="0123456789"+(char)8;// 只任选输入一次小数点
		}//只容许输入0到9的数字和小数点,键盘侦听
	}

	// 窗体的初始化任务
	private final class initTasks extends InternalFrameAdapter {
		public void internalFrameActivated(InternalFrameEvent e) {
			super.internalFrameActivated(e);
			initTimeField();
			}
	}
}
	

⌨️ 快捷键说明

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