Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Kursovoy_proekt Переделаный.docx
Скачиваний:
2
Добавлен:
01.05.2025
Размер:
724 Кб
Скачать
☆

Классы пользовательского интерфейса

/*

* StockView.java

*/

package stock;

import DAL.StockDatabase;

import Entities.Employee;

import Entities.Product;

import Entities.Shipment;

import Utils.Utils;

import org.jdesktop.application.Action;

import org.jdesktop.application.ResourceMap;

import org.jdesktop.application.SingleFrameApplication;

import org.jdesktop.application.FrameView;

import org.jdesktop.application.TaskMonitor;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.util.ArrayList;

import java.util.List;

import javax.swing.ComboBoxModel;

import javax.swing.DefaultComboBoxModel;

import javax.swing.Timer;

import javax.swing.Icon;

import javax.swing.JDialog;

import javax.swing.JFrame;

import javax.swing.table.DefaultTableModel;

import javax.swing.table.TableModel;

/**

* The application's main frame.

*/

public class StockView extends FrameView {

public StockView(SingleFrameApplication app) {

super(app);

initComponents();

// status bar initialization - message timeout, idle icon and busy animation, etc

ResourceMap resourceMap = getResourceMap();

int messageTimeout = resourceMap.getInteger("StatusBar.messageTimeout");

messageTimer = new Timer(messageTimeout, new ActionListener() {

public void actionPerformed(ActionEvent e) {

//statusMessageLabel.setText("");

}

});

messageTimer.setRepeats(false);

int busyAnimationRate = resourceMap.getInteger("StatusBar.busyAnimationRate");

for (int i = 0; i < busyIcons.length; i++) {

busyIcons[i] = resourceMap.getIcon("StatusBar.busyIcons[" + i + "]");

}

busyIconTimer = new Timer(busyAnimationRate, new ActionListener() {

public void actionPerformed(ActionEvent e) {

busyIconIndex = (busyIconIndex + 1) % busyIcons.length;

//statusAnimationLabel.setIcon(busyIcons[busyIconIndex]);

}

});

idleIcon = resourceMap.getIcon("StatusBar.idleIcon");

//statusAnimationLabel.setIcon(idleIcon);

//progressBar.setVisible(false);

// connecting action tasks to status bar via TaskMonitor

TaskMonitor taskMonitor = new TaskMonitor(getApplication().getContext());

taskMonitor.addPropertyChangeListener(new java.beans.PropertyChangeListener() {

public void propertyChange(java.beans.PropertyChangeEvent evt) {

/*String propertyName = evt.getPropertyName();

if ("started".equals(propertyName)) {

if (!busyIconTimer.isRunning()) {

statusAnimationLabel.setIcon(busyIcons[0]);

busyIconIndex = 0;

busyIconTimer.start();

}

progressBar.setVisible(true);

progressBar.setIndeterminate(true);

} else if ("done".equals(propertyName)) {

busyIconTimer.stop();

statusAnimationLabel.setIcon(idleIcon);

progressBar.setVisible(false);

progressBar.setValue(0);

} else if ("message".equals(propertyName)) {

String text = (String)(evt.getNewValue());

statusMessageLabel.setText((text == null) ? "" : text);

messageTimer.restart();

} else if ("progress".equals(propertyName)) {

int value = (Integer)(evt.getNewValue());

progressBar.setVisible(true);

progressBar.setIndeterminate(false);

progressBar.setValue(value);

}*/

}

});

//setResizable(false);

tableProducts.getColumnModel().getColumn(0).setMinWidth(0);

tableProducts.getColumnModel().getColumn(0).setMaxWidth(0);

tableProducts.getColumnModel().getColumn(0).setWidth(0);

RefillProductsTable();

RefillShipmentTable();

}

private void RefillProductsTable() {

List<Product> products = StockDatabase.getInstance().getProducts().GetAllProducts();

DefaultTableModel model = (DefaultTableModel) tableProducts.getModel();

model.setRowCount(0);

for(Product product : products){

model.addRow(new Object[]{product, product.getId(), product.getName(), product.getManufacturer(), product.getQuantityinstock() });

}

}

protected void RefillShipmentTable() {

RefillShipmentTable(StockDatabase.getInstance().getShipments().GetShipmentList(0, 0));

}

protected void RefillShipmentTable(List<Shipment> shipments) {

DefaultTableModel model = (DefaultTableModel) tableShipments.getModel();

model.setRowCount(0);

for(Shipment shipment : shipments){

model.addRow(new Object[]{

Utils.convertDateToDateString(shipment.getDatetime()),

shipment.getProductid(),

shipment.getQuantity(),

shipment.getResponsiblepersonid() });

}

}

protected ComboBoxModel getEmployeeModel() {

List<Employee> people = StockDatabase.getInstance().getEmployee().GetAllEmployees();

people.add(0, new Employee(0, "No filter"));

ComboBoxModel model = new DefaultComboBoxModel(people.toArray());

return model;

}

protected ComboBoxModel getProductsModel() {

List<Product> products = StockDatabase.getInstance().getProducts().GetAllProducts();

products.add(0, new Product(0, "No filter", 0));

ComboBoxModel model = new DefaultComboBoxModel(

products.toArray());

return model;

}

@Action

public void showAboutBox() {

if (aboutBox == null) {

JFrame mainFrame = StockApp.getApplication().getMainFrame();

aboutBox = new StockAboutBox(mainFrame);

aboutBox.setLocationRelativeTo(mainFrame);

}

StockApp.getApplication().show(aboutBox);

}

/** This method is called from within the constructor to

* initialize the form.

* WARNING: Do NOT modify this code. The content of this method is

* always regenerated by the Form Editor.

*/

@SuppressWarnings("unchecked")

// <editor-fold defaultstate="collapsed" desc="Generated Code">

private void initComponents() {

bindingGroup = new org.jdesktop.beansbinding.BindingGroup();

mainPanel = new javax.swing.JPanel();

jTabbedPane1 = new javax.swing.JTabbedPane();

jPanel2 = new javax.swing.JPanel();

jScrollPane1 = new javax.swing.JScrollPane();

tableProducts = new javax.swing.JTable();

btnRefresh = new javax.swing.JButton();

btnAddProduct = new javax.swing.JButton();

jPanel1 = new javax.swing.JPanel();

btnIncoming = new javax.swing.JButton();

btnOutcoming = new javax.swing.JButton();

jScrollPane2 = new javax.swing.JScrollPane();

tableShipments = new javax.swing.JTable();

dropdownEmployeeFilter = new javax.swing.JComboBox();

jLabel1 = new javax.swing.JLabel();

jButton2 = new javax.swing.JButton();

dropdownProductFilter = new javax.swing.JComboBox();

jPopupMenu = new javax.swing.JPopupMenu();

jMenuItem1 = new javax.swing.JMenuItem();

mainPanel.setMinimumSize(new java.awt.Dimension(507, 434));

mainPanel.setName("mainPanel"); // NOI18N

org.jdesktop.beansbinding.Binding binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, jPopupMenu, org.jdesktop.beansbinding.ObjectProperty.create(), mainPanel, org.jdesktop.beansbinding.BeanProperty.create("componentPopupMenu"));

bindingGroup.addBinding(binding);

jTabbedPane1.setName("jTabbedPane1"); // NOI18N

binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, jPopupMenu, org.jdesktop.beansbinding.ObjectProperty.create(), jTabbedPane1, org.jdesktop.beansbinding.BeanProperty.create("componentPopupMenu"));

bindingGroup.addBinding(binding);

jTabbedPane1.addFocusListener(new java.awt.event.FocusAdapter() {

public void focusGained(java.awt.event.FocusEvent evt) {

jTabbedPane1FocusGained(evt);

}

});

jPanel2.setName("jPanel2"); // NOI18N

jScrollPane1.setName("jScrollPane1"); // NOI18N

tableProducts.setModel(new javax.swing.table.DefaultTableModel(

new Object [][] {

},

new String [] {

"ProductObject", "ID", "Name", "Manufacturer", "Quantity In Stock"

}

) {

Class[] types = new Class [] {

java.lang.Object.class, java.lang.Integer.class, java.lang.Object.class, java.lang.String.class, java.lang.Integer.class

};

boolean[] canEdit = new boolean [] {

false, false, false, false, false

};

public Class getColumnClass(int columnIndex) {

return types [columnIndex];

}

public boolean isCellEditable(int rowIndex, int columnIndex) {

return canEdit [columnIndex];

}

});

tableProducts.setName("tableProducts"); // NOI18N

jScrollPane1.setViewportView(tableProducts);

org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(stock.StockApp.class).getContext().getResourceMap(StockView.class);

tableProducts.getColumnModel().getColumn(0).setResizable(false);

tableProducts.getColumnModel().getColumn(0).setPreferredWidth(0);

tableProducts.getColumnModel().getColumn(0).setHeaderValue(resourceMap.getString("tableProducts.columnModel.title4")); // NOI18N

tableProducts.getColumnModel().getColumn(1).setPreferredWidth(50);

tableProducts.getColumnModel().getColumn(1).setHeaderValue(resourceMap.getString("tableProducts.columnModel.title0")); // NOI18N

tableProducts.getColumnModel().getColumn(2).setHeaderValue(resourceMap.getString("tableProducts.columnModel.title1")); // NOI18N

tableProducts.getColumnModel().getColumn(3).setHeaderValue(resourceMap.getString("tableProducts.columnModel.title2")); // NOI18N

tableProducts.getColumnModel().getColumn(4).setHeaderValue(resourceMap.getString("tableProducts.columnModel.title3")); // NOI18N

btnRefresh.setText(resourceMap.getString("btnRefresh.text")); // NOI18N

btnRefresh.setName("btnRefresh"); // NOI18N

btnRefresh.addMouseListener(new java.awt.event.MouseAdapter() {

public void mouseClicked(java.awt.event.MouseEvent evt) {

btnRefreshMouseClicked(evt);

}

});

btnAddProduct.setText(resourceMap.getString("btnAddProduct.text")); // NOI18N

btnAddProduct.setName("btnAddProduct"); // NOI18N

btnAddProduct.addMouseListener(new java.awt.event.MouseAdapter() {

public void mouseClicked(java.awt.event.MouseEvent evt) {

btnAddProductMouseClicked(evt);

}

});

javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);

jPanel2.setLayout(jPanel2Layout);

jPanel2Layout.setHorizontalGroup(

jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()

.addContainerGap()

.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)

.addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 487, Short.MAX_VALUE)

.addGroup(jPanel2Layout.createSequentialGroup()

.addComponent(btnAddProduct)

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 313, Short.MAX_VALUE)

.addComponent(btnRefresh)))

.addContainerGap())

);

jPanel2Layout.setVerticalGroup(

jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()

.addContainerGap()

.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 379, Short.MAX_VALUE)

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)

.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)

.addComponent(btnRefresh)

.addComponent(btnAddProduct))

.addContainerGap())

);

jTabbedPane1.addTab(resourceMap.getString("jPanel2.TabConstraints.tabTitle"), jPanel2); // NOI18N

jPanel1.setName("jPanel1"); // NOI18N

btnIncoming.setText(resourceMap.getString("btnIncoming.text")); // NOI18N

btnIncoming.setName("btnIncoming"); // NOI18N

btnIncoming.addMouseListener(new java.awt.event.MouseAdapter() {

public void mouseClicked(java.awt.event.MouseEvent evt) {

btnIncomingMouseClicked(evt);

}

});

btnOutcoming.setText(resourceMap.getString("btnOutcoming.text")); // NOI18N

btnOutcoming.setName("btnOutcoming"); // NOI18N

btnOutcoming.addMouseListener(new java.awt.event.MouseAdapter() {

public void mouseClicked(java.awt.event.MouseEvent evt) {

btnOutcomingMouseClicked(evt);

}

});

jScrollPane2.setName("jScrollPane2"); // NOI18N

tableShipments.setModel(new javax.swing.table.DefaultTableModel(

new Object [][] {

},

new String [] {

"Date and time", "Product", "Quantity", "Responsible Person"

}

));

tableShipments.setName("tableShipments"); // NOI18N

jScrollPane2.setViewportView(tableShipments);

dropdownEmployeeFilter.setModel(getEmployeeModel());

dropdownEmployeeFilter.setMaximumSize(new java.awt.Dimension(100, 20));

dropdownEmployeeFilter.setMinimumSize(new java.awt.Dimension(100, 20));

dropdownEmployeeFilter.setName("dropdownEmployeeFilter"); // NOI18N

dropdownEmployeeFilter.setPreferredSize(new java.awt.Dimension(100, 20));

jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N

jLabel1.setName("jLabel1"); // NOI18N

jButton2.setText(resourceMap.getString("jButton2.text")); // NOI18N

jButton2.setName("jButton2"); // NOI18N

jButton2.addMouseListener(new java.awt.event.MouseAdapter() {

public void mouseClicked(java.awt.event.MouseEvent evt) {

jButton2MouseClicked(evt);

}

});

dropdownProductFilter.setModel(getProductsModel());

dropdownProductFilter.setMaximumSize(new java.awt.Dimension(100, 20));

dropdownProductFilter.setMinimumSize(new java.awt.Dimension(100, 20));

dropdownProductFilter.setName("dropdownProductFilter"); // NOI18N

dropdownProductFilter.setPreferredSize(new java.awt.Dimension(100, 20));

javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);

jPanel1.setLayout(jPanel1Layout);

jPanel1Layout.setHorizontalGroup(

jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(jPanel1Layout.createSequentialGroup()

.addContainerGap()

.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 487, Short.MAX_VALUE)

.addGroup(jPanel1Layout.createSequentialGroup()

.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(jPanel1Layout.createSequentialGroup()

.addComponent(btnIncoming)

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)

.addComponent(btnOutcoming))

.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()

.addComponent(jLabel1)

.addGap(81, 81, 81)

.addComponent(dropdownProductFilter, javax.swing.GroupLayout.PREFERRED_SIZE, 145, javax.swing.GroupLayout.PREFERRED_SIZE)

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)

.addComponent(dropdownEmployeeFilter, javax.swing.GroupLayout.PREFERRED_SIZE, 145, javax.swing.GroupLayout.PREFERRED_SIZE)))

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)

.addComponent(jButton2)))

.addContainerGap())

);

jPanel1Layout.setVerticalGroup(

jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(jPanel1Layout.createSequentialGroup()

.addContainerGap()

.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)

.addComponent(jLabel1)

.addComponent(jButton2)

.addComponent(dropdownEmployeeFilter, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

.addComponent(dropdownProductFilter, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)

.addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 350, Short.MAX_VALUE)

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)

.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)

.addComponent(btnIncoming)

.addComponent(btnOutcoming))

.addContainerGap())

);

jTabbedPane1.addTab(resourceMap.getString("jPanel1.TabConstraints.tabTitle"), jPanel1); // NOI18N

javax.swing.GroupLayout mainPanelLayout = new javax.swing.GroupLayout(mainPanel);

mainPanel.setLayout(mainPanelLayout);

mainPanelLayout.setHorizontalGroup(

mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, mainPanelLayout.createSequentialGroup()

.addContainerGap()

.addComponent(jTabbedPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 512, Short.MAX_VALUE)

.addContainerGap())

);

mainPanelLayout.setVerticalGroup(

mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(mainPanelLayout.createSequentialGroup()

.addContainerGap()

.addComponent(jTabbedPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 458, Short.MAX_VALUE)

.addContainerGap())

);

jPopupMenu.setName("jPopupMenu"); // NOI18N

javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(stock.StockApp.class).getContext().getActionMap(StockView.class, this);

jMenuItem1.setAction(actionMap.get("showAboutBox")); // NOI18N

jMenuItem1.setName("jMenuItem1"); // NOI18N

jPopupMenu.add(jMenuItem1);

setComponent(mainPanel);

bindingGroup.bind();

}// </editor-fold>

private void btnRefreshMouseClicked(java.awt.event.MouseEvent evt) {

// TODO add your handling code here:

RefillProductsTable();

}

private void btnIncomingMouseClicked(java.awt.event.MouseEvent evt) {

if (addShipmentBox == null) {

JFrame mainFrame = StockApp.getApplication().getMainFrame();

addShipmentBox = new AddShipmentDialog(mainFrame);

addShipmentBox.setLocationRelativeTo(mainFrame);

}

addShipmentBox.Initialize(true);

StockApp.getApplication().show(addShipmentBox);

RefillShipmentTable();

RefillProductsTable();

}

private void btnOutcomingMouseClicked(java.awt.event.MouseEvent evt) {

if (addShipmentBox == null) {

JFrame mainFrame = StockApp.getApplication().getMainFrame();

addShipmentBox = new AddShipmentDialog(mainFrame);

addShipmentBox.setLocationRelativeTo(mainFrame);

}

addShipmentBox.Initialize(false);

StockApp.getApplication().show(addShipmentBox);

RefillShipmentTable();

RefillProductsTable();

}

private void jTabbedPane1FocusGained(java.awt.event.FocusEvent evt) {

}

// Refresh with filter button

private void jButton2MouseClicked(java.awt.event.MouseEvent evt) {

Employee employeeFilter = (Employee)dropdownEmployeeFilter.getSelectedItem();

Product productFilter = (Product)dropdownProductFilter.getSelectedItem();

RefillShipmentTable(

StockDatabase.getInstance().getShipments().GetShipmentList(

employeeFilter.getId(), productFilter.getId()));

}

private void btnAddProductMouseClicked(java.awt.event.MouseEvent evt) {

// TODO add your handling code here:

if (addProductBox == null) {

JFrame mainFrame = StockApp.getApplication().getMainFrame();

addProductBox = new AddProductDialog(mainFrame);

addProductBox.setLocationRelativeTo(mainFrame);

}

StockApp.getApplication().show(addProductBox);

RefillProductsTable();

dropdownProductFilter.setModel(getProductsModel());

}

// Variables declaration - do not modify

private javax.swing.JButton btnAddProduct;

private javax.swing.JButton btnIncoming;

private javax.swing.JButton btnOutcoming;

private javax.swing.JButton btnRefresh;

private javax.swing.JComboBox dropdownEmployeeFilter;

private javax.swing.JComboBox dropdownProductFilter;

private javax.swing.JButton jButton2;

private javax.swing.JLabel jLabel1;

private javax.swing.JMenuItem jMenuItem1;

private javax.swing.JPanel jPanel1;

private javax.swing.JPanel jPanel2;

private javax.swing.JPopupMenu jPopupMenu;

private javax.swing.JScrollPane jScrollPane1;

private javax.swing.JScrollPane jScrollPane2;

private javax.swing.JTabbedPane jTabbedPane1;

private javax.swing.JPanel mainPanel;

private javax.swing.JTable tableProducts;

private javax.swing.JTable tableShipments;

private org.jdesktop.beansbinding.BindingGroup bindingGroup;

// End of variables declaration

private final Timer messageTimer;

private final Timer busyIconTimer;

private final Icon idleIcon;

private final Icon[] busyIcons = new Icon[15];

private int busyIconIndex = 0;

private JDialog aboutBox;

private AddShipmentDialog addShipmentBox;

private AddProductDialog addProductBox;

}

/*

* To change this template, choose Tools | Templates

* and open the template in the editor.

*/

/*

* LoginForm.java

*

* Created on 19.03.2011, 18:23:01

*/

package stock;

import DAL.StockDatabase;

import Entities.Product;

/**

*

* @author Humanity

*/

public class AddProductDialog extends javax.swing.JDialog {

/** Creates new form LoginForm */

public AddProductDialog(java.awt.Frame parent) {

super(parent);

initComponents();

ClearForm();

this.setModal(true);

}

public AddProductDialog() {

initComponents();

ClearForm();

}

private void ClearForm() {

txtName.setText("");

txtManufacturer.setText("");

}

/** This method is called from within the constructor to

* initialize the form.

* WARNING: Do NOT modify this code. The content of this method is

* always regenerated by the Form Editor.

*/

@SuppressWarnings("unchecked")

// <editor-fold defaultstate="collapsed" desc="Generated Code">

private void initComponents() {

btnRegister = new javax.swing.JButton();

jLabel4 = new javax.swing.JLabel();

lblStatus = new javax.swing.JLabel();

txtName = new javax.swing.JTextField();

txtManufacturer = new javax.swing.JTextField();

jLabel5 = new javax.swing.JLabel();

setTitle("Add product");

setModal(true);

setName("Form"); // NOI18N

setResizable(false);

javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(stock.StockApp.class).getContext().getActionMap(AddProductDialog.class, this);

btnRegister.setAction(actionMap.get("RegisterClick")); // NOI18N

btnRegister.setText("Add Product");

btnRegister.setName("btnRegister"); // NOI18N

btnRegister.addMouseListener(new java.awt.event.MouseAdapter() {

public void mouseClicked(java.awt.event.MouseEvent evt) {

btnRegisterMouseClicked(evt);

}

});

jLabel4.setText("Product name");

jLabel4.setName("jLabel4"); // NOI18N

lblStatus.setName("lblStatus"); // NOI18N

txtName.setName("txtName"); // NOI18N

txtManufacturer.setName("txtManufacturer"); // NOI18N

jLabel5.setText("Manufacturer");

jLabel5.setName("jLabel5"); // NOI18N

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());

getContentPane().setLayout(layout);

layout.setHorizontalGroup(

layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(layout.createSequentialGroup()

.addContainerGap()

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(layout.createSequentialGroup()

.addComponent(jLabel4)

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 64, Short.MAX_VALUE)

.addComponent(txtName, javax.swing.GroupLayout.PREFERRED_SIZE, 161, javax.swing.GroupLayout.PREFERRED_SIZE))

.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()

.addComponent(jLabel5)

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 65, Short.MAX_VALUE)

.addComponent(txtManufacturer, javax.swing.GroupLayout.PREFERRED_SIZE, 161, javax.swing.GroupLayout.PREFERRED_SIZE))

.addComponent(lblStatus, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 291, Short.MAX_VALUE)

.addComponent(btnRegister, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 291, Short.MAX_VALUE))

.addContainerGap())

);

layout.setVerticalGroup(

layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(layout.createSequentialGroup()

.addContainerGap()

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)

.addComponent(jLabel4)

.addComponent(txtName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)

.addComponent(txtManufacturer, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

.addComponent(jLabel5))

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)

.addComponent(lblStatus, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE)

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)

.addComponent(btnRegister, javax.swing.GroupLayout.PREFERRED_SIZE, 21, Short.MAX_VALUE)

.addContainerGap())

);

pack();

}// </editor-fold>

private void btnRegisterMouseClicked(java.awt.event.MouseEvent evt) {

String name = txtName.getText();

String manufacturer = txtManufacturer.getText();

if (name.length() == 0) {

lblStatus.setText("Enter a product name please");

return;

}

if (manufacturer.length() == 0) {

lblStatus.setText("Enter manufacturer's name please");

return;

}

Product product = new Product(0, name, manufacturer, 0);

if (StockDatabase.getInstance().getProducts().InsertProduct(product)) {

//success

setVisible(false);

} else {

lblStatus.setText("An error occured");

return;

}

}

/**

* @param args the command line arguments

*/

public static void main(String args[]) {

java.awt.EventQueue.invokeLater(new Runnable() {

public void run() {

new AddShipmentDialog().setVisible(true);

}

});

}

// Variables declaration - do not modify

private javax.swing.JButton btnRegister;

private javax.swing.JLabel jLabel4;

private javax.swing.JLabel jLabel5;

private javax.swing.JLabel lblStatus;

private javax.swing.JTextField txtManufacturer;

private javax.swing.JTextField txtName;

// End of variables declaration

}

/*

* To change this template, choose Tools | Templates

* and open the template in the editor.

*/

/*

* LoginForm.java

*

* Created on 19.03.2011, 18:23:01

*/

package stock;

import DAL.StockDatabase;

import Entities.Employee;

import Entities.Product;

import Entities.Shipment;

import java.awt.Component;

import java.util.Date;

import java.util.Vector;

import javax.swing.ComboBoxModel;

import javax.swing.DefaultComboBoxModel;

import javax.swing.JOptionPane;

import org.jdesktop.application.Action;

/**

*

* @author Humanity

*/

public class AddShipmentDialog extends javax.swing.JDialog {

/** Creates new form LoginForm */

public AddShipmentDialog(java.awt.Frame parent) {

super(parent);

initComponents();

//getRootPane().setDefaultButton(btnLogIn);

quantityRatio = 1;

this.setModal(true);

}

public AddShipmentDialog() {

initComponents();

quantityRatio = 1;

}

// Positive for incoming goods, negative for outcoming

private int quantityRatio;

public void Initialize(boolean isIncoming){

quantityRatio = isIncoming ? 1 : -1;

setTitle(isIncoming

? "Incoming Shipment"

: "Outcoming Shipment");

}

protected ComboBoxModel getProductsModel() {

ComboBoxModel model = new DefaultComboBoxModel(

StockDatabase.getInstance().getProducts().GetAllProducts().toArray());

return model;

}

protected ComboBoxModel getEmployeeModel() {

ComboBoxModel model = new DefaultComboBoxModel(

StockDatabase.getInstance().getEmployee().GetAllEmployees().toArray());

return model;

}

/** This method is called from within the constructor to

* initialize the form.

* WARNING: Do NOT modify this code. The content of this method is

* always regenerated by the Form Editor.

*/

@SuppressWarnings("unchecked")

// <editor-fold defaultstate="collapsed" desc="Generated Code">

private void initComponents() {

btnRegister = new javax.swing.JButton();

jLabel4 = new javax.swing.JLabel();

lblStatus = new javax.swing.JLabel();

dropdownProduct = new javax.swing.JComboBox();

dateChooser = new com.toedter.calendar.JDateChooser();

spinQuantity = new javax.swing.JSpinner();

dropdownPerson = new javax.swing.JComboBox();

jLabel1 = new javax.swing.JLabel();

jLabel2 = new javax.swing.JLabel();

jLabel3 = new javax.swing.JLabel();

setTitle("Incoming Shipment");

setModal(true);

setName("Form"); // NOI18N

setResizable(false);

javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(stock.StockApp.class).getContext().getActionMap(AddShipmentDialog.class, this);

btnRegister.setAction(actionMap.get("RegisterClick")); // NOI18N

btnRegister.setText("Add Shipment");

btnRegister.setName("btnRegister"); // NOI18N

btnRegister.addMouseListener(new java.awt.event.MouseAdapter() {

public void mouseClicked(java.awt.event.MouseEvent evt) {

btnRegisterMouseClicked(evt);

}

});

jLabel4.setText("Product");

jLabel4.setName("jLabel4"); // NOI18N

lblStatus.setName("lblStatus"); // NOI18N

dropdownProduct.setModel(getProductsModel());

dropdownProduct.setName("dropdownProduct"); // NOI18N

dateChooser.setDate(new Date());

dateChooser.setName("dateChooser"); // NOI18N

spinQuantity.setModel(new javax.swing.SpinnerNumberModel(Integer.valueOf(1), Integer.valueOf(1), null, Integer.valueOf(1)));

spinQuantity.setName("spinQuantity"); // NOI18N

dropdownPerson.setModel(getEmployeeModel());

dropdownPerson.setName("dropdownPerson"); // NOI18N

jLabel1.setText("Quantity");

jLabel1.setName("jLabel1"); // NOI18N

jLabel2.setText("Date");

jLabel2.setName("jLabel2"); // NOI18N

jLabel3.setText("Responsible person");

jLabel3.setName("jLabel3"); // NOI18N

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());

getContentPane().setLayout(layout);

layout.setHorizontalGroup(

layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()

.addContainerGap()

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)

.addComponent(btnRegister, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 291, Short.MAX_VALUE)

.addGroup(layout.createSequentialGroup()

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addComponent(jLabel4)

.addComponent(jLabel1)

.addComponent(jLabel2)

.addComponent(jLabel3))

.addGap(18, 18, 18)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)

.addComponent(dropdownProduct, 0, 180, Short.MAX_VALUE)

.addComponent(spinQuantity, javax.swing.GroupLayout.DEFAULT_SIZE, 180, Short.MAX_VALUE)

.addComponent(dateChooser, javax.swing.GroupLayout.DEFAULT_SIZE, 180, Short.MAX_VALUE)

.addComponent(dropdownPerson, 0, 180, Short.MAX_VALUE)))

.addComponent(lblStatus, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 291, Short.MAX_VALUE))

.addContainerGap())

);

layout.setVerticalGroup(

layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(layout.createSequentialGroup()

.addContainerGap()

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)

.addComponent(jLabel4)

.addComponent(dropdownProduct, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)

.addComponent(spinQuantity, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

.addComponent(jLabel1))

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)

.addComponent(dateChooser, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

.addComponent(jLabel2))

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)

.addComponent(dropdownPerson, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

.addComponent(jLabel3))

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)

.addComponent(lblStatus, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE)

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)

.addComponent(btnRegister, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)

.addContainerGap())

);

pack();

}// </editor-fold>

private void btnRegisterMouseClicked(java.awt.event.MouseEvent evt) {

Product product = (Product) dropdownProduct.getSelectedItem();

int quantity = (Integer) spinQuantity.getValue();

Date date = dateChooser.getDate();

Employee person = (Employee) dropdownPerson.getSelectedItem();

if (quantity <= 0) {

lblStatus.setText("Quantity must be positive");

return;

}

if (product == null) {

lblStatus.setText("Select a product please");

return;

}

if (person == null) {

lblStatus.setText("Select a responsive person please");

return;

}

// Positive for incoming goods, negative for outcoming

quantity = quantityRatio * quantity;

Product p = StockDatabase.getInstance().getProducts().GetProductById(product.getId());

if (quantity < 0 &&

p.getQuantityinstock() < Math.abs(quantity)) {

// trying to take TOO MUCH from stock...

lblStatus.setText("There are only "+p.getQuantityinstock()+" items of this product in stock.");

return;

}

Shipment shipment = new Shipment();

shipment.setProductid(product);

shipment.setQuantity(quantity);

shipment.setDatetime(date);

shipment.setResponsiblepersonid(person);

if (StockDatabase.getInstance().getShipments().InsertShipment(shipment)) {

//success

setVisible(false);

} else {

lblStatus.setText("An error occured");

return;

}

}

/**

* @param args the command line arguments

*/

public static void main(String args[]) {

java.awt.EventQueue.invokeLater(new Runnable() {

public void run() {

new AddShipmentDialog().setVisible(true);

}

});

}

// Variables declaration - do not modify

private javax.swing.JButton btnRegister;

private com.toedter.calendar.JDateChooser dateChooser;

private javax.swing.JComboBox dropdownPerson;

private javax.swing.JComboBox dropdownProduct;

private javax.swing.JLabel jLabel1;

private javax.swing.JLabel jLabel2;

private javax.swing.JLabel jLabel3;

private javax.swing.JLabel jLabel4;

private javax.swing.JLabel lblStatus;

private javax.swing.JSpinner spinQuantity;

// End of variables declaration

}

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]