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

📄 ioform.java

📁 一个货物管理系
💻 JAVA
字号:
package good;

import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;


public class Ioform extends JFrame {
	private static final Component InPrice = null;

	private Inventory inventory = new Inventory(100);

	private Invoice invoice = new Invoice(inventory);

	final JTextArea textArea_1 = new JTextArea(); //显示存货单的信息

	final JTextArea textArea_2 = new JTextArea(); //显示提货单的信息
	Imanufacturer supply=new Imanufacturer();
	Employee  employee =new Employee();
	Client client=new Client();
	Goods goods=new Goods();
	Goods price_1=new Goods();
	Goods price_2=new Goods();
    //boolean inventoryFlag=false;
    boolean invoiceFlag=false;
	public Ioform() {
		super();
		
		
		setTitle("商品库存管理系统");
		final JTabbedPane tabbedPane = new JTabbedPane();
		final JPanel panel_1 = new JPanel();
		final JPanel panel_2 = new JPanel();
		final JScrollPane scrollPane_1 = new JScrollPane(textArea_1);
		final JScrollPane scrollPane_2 = new JScrollPane(textArea_2);
		final JComboBox id_1 = new JComboBox(goods.GetAllGoodId()); //存货单某项的ID
		final JComboBox supplyName = new JComboBox(supply.GetAllSupplyName());
		final JComboBox employeeId = new JComboBox(employee.GetAllemployeeId()); 
		final JTextField number_1 = new JTextField(4); //欲修改的存货单某项的数量
		//final JTextField price_1=new JTextField("",10);
		final JTextField indate=new JTextField(" ",10);
		
		//final JTextField id_2 = new JTextField(4); //提货单某项的ID
		final JComboBox id_2 = new JComboBox(goods.GetAllGoodId());
		final JTextField number_2 = new JTextField(4); //欲修改的提货单某项的数量
		final JComboBox clientName = new JComboBox(client.GetAllclientName());
		final JComboBox employeeId_2 = new JComboBox(employee.GetAllemployeeId());
		final JTextField outdate=new JTextField("",10);
		final JTextField outprice=new JTextField("",10);
		
		final JPanel panelButton_1 = new JPanel();
		final JPanel panelButton_2 = new JPanel();
		final JPanel panelInput_1 = new JPanel();
		final JPanel panelInput_2 = new JPanel();
		
		final JButton inventoryAddButton = new JButton();
		final JButton inventoryRemoveButton = new JButton();
		
		final JButton invoiceAddButton = new JButton();
		final JButton invoiceDeleteButton = new JButton();
		
		

		getContentPane().add(tabbedPane, BorderLayout.CENTER);
		tabbedPane.add("存货单", panel_1);
		tabbedPane.add("提货单", panel_2);

		panel_1.setLayout(new BorderLayout());
		panel_1.add(scrollPane_1, BorderLayout.CENTER);
		panel_1.add(panelButton_1, BorderLayout.SOUTH);
		panel_1.add(panelInput_1, BorderLayout.NORTH);
		panelInput_1.setLayout(new GridLayout(1,6));
		panelInput_1.add(new JLabel("  存货单ID:"));
		panelInput_1.add(id_1);
		panelInput_1.add(new JLabel("  商品数量:"));
		panelInput_1.add(number_1);
		panelInput_1.add(new JLabel("  供应商名称:"));
		panelInput_1.add(supplyName);
		
		panelInput_1.add(new JLabel("  雇员ID:"));
		panelInput_1.add(employeeId);
		
		//panelInput_1.add(new JLabel("  价格"));
		//panelInput_1.add(price_1);
		panelInput_1.add(new JLabel("  进货日期"));
		panelInput_1.add(indate);
		
		//panelButton_1.setLayout(new GridLayout(1,6));
		panelButton_1.add(inventoryAddButton);		
		inventoryAddButton.setText("增加商品数量");
		//panelButton_1.add(inventoryRemoveButton);
		inventoryRemoveButton.setText("减少商品数量");
		textArea_1.setEditable(false);
		scrollPane_1.setViewportView(textArea_1);

		panel_2.setLayout(new BorderLayout());
		panel_2.add(scrollPane_2, BorderLayout.CENTER);
		panel_2.add(panelButton_2, BorderLayout.SOUTH);
		panel_2.add(panelInput_2, BorderLayout.NORTH);
		
		panelInput_2.add(new JLabel("提货单某项的ID:"));
		panelInput_2.add(id_2);
		panelInput_2.add(new JLabel("商品数量:"));
		panelInput_2.add(number_2);
		panelInput_2.add(new JLabel(" 客户名称:"));
		panelInput_2.add(clientName);
		panelInput_2.add(new JLabel("雇员ID:"));
		panelInput_2.add(employeeId_2);
		panelInput_2.add(new JLabel("出货价格:"));
		panelInput_2.add(outprice);
		panelInput_2.add(new JLabel("出货日期:"));
		panelInput_2.add(outdate);
		
		panelButton_2.add(invoiceAddButton);
		invoiceAddButton.setText("增加提货单");
		panelButton_2.add(invoiceDeleteButton);
		invoiceDeleteButton.setText("删除提货单");
		
		this.setBounds(100, 100, 800,600);	
		this.setVisible(true);
		
		textArea_2.setEditable(false);
		scrollPane_2.setViewportView(textArea_2);

		refreshInventory();
		refreshInvoice();
        
		inventoryAddButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				try {
					inventory.addUnits(id_1.getSelectedItem().toString(), Integer
							.parseInt(number_1.getText()));
					inventory.setEmployeeId(employeeId.getSelectedItem().toString());
					inventory.setGoodId(id_1.getSelectedItem().toString());
					inventory.setNumber(Integer.parseInt(number_1.getText()));
					inventory.setSupplyName(supplyName.getSelectedItem().toString());
					inventory.setInPrice(Double.parseDouble(number_1.getText()));
					inventory.setDate(indate.getText());
					inventory.InventoryAdd();
					//invoiceFlag=true;
				} catch (NumberFormatException e1) {
					JOptionPane.showMessageDialog(null, "输入的商品数量错误!", "警告",
							JOptionPane.ERROR_MESSAGE);
				}
				refreshInventory();
			}
		});
		
		
		

		
		inventoryRemoveButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				try {
					inventory.removeUnits(id_1.getSelectedItem().toString(),
							Integer.parseInt(number_1.getText()));
					
				} catch (NumberFormatException e1) {
					JOptionPane.showMessageDialog(null, "输入的商品数量错误!", "警告",
							JOptionPane.ERROR_MESSAGE);
				}
				refreshInventory();
			}
		});

		invoiceAddButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				boolean flag;
				try {
					flag=invoice.addItem(id_2.getSelectedItem().toString(), Integer.parseInt(number_2
							.getText()),Double.parseDouble(outprice.getText()));
					if (flag)
					{
					   invoice.setEmployeeId(employeeId.getSelectedItem().toString());
					   invoice.setGoodId(id_2.getSelectedItem().toString());
					   invoice.setOutnumber(Integer.parseInt(number_2.getText()));
					   invoice.setClientname(clientName.getSelectedItem().toString());
					   invoice.setOutPrice(Double.parseDouble(outprice.getText()));
					   invoice.setOutdate(outdate.getText());
					   invoice.Invoicedele();
					   invoiceFlag=true;
				   }
				} catch (NumberFormatException e1) {
					JOptionPane.showMessageDialog(null, "输入的商品数量错误!", "警告",
							JOptionPane.ERROR_MESSAGE);
				}
				refreshInvoice();
				//refreshInventory();
			}
		});

		invoiceDeleteButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				invoice.delItem(id_2.getSelectedItem().toString());
				refreshInvoice();
			}
		});
	}

	//刷新存货单的显示结果
	public void refreshInventory() {
		String str = null;
		String title="商品ID\t 数量 * 价格\t\t 商品名称 ";		
		for (int i = 0; i < inventory.list.length; i++) {
			str = inventory.toString() + "\n";
		}
		textArea_1.setText(title+"\n"+str);
		/*if (invoiceFlag)
		{	
		  refreshInvoice();
		  invoiceFlag=false;
		}*/		
	}

	//刷新提货单的显示结果
	public void refreshInvoice() {
		String str = null;
		String title="商品ID\t 数量 * 价格\t\t 商品名称 ";
		for (int i = 0; i < invoice.list.length; i++) {
			str = invoice.toString() + "\n";
		}
		textArea_2.setText(title+"\n"+str);
		if (invoiceFlag)
		{		
		  refreshInventory();
		  invoiceFlag=false;
		}
		
	}
	
}

⌨️ 快捷键说明

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