Browse files

created a users management screen

  • Loading branch information...
1 parent 6ca35b4 commit e7f1c07cd957c6e927bfa74262a5bff8715eebd9 @jdesulme committed May 10, 2012
View
29 src/ims/Controller/UserHandler.java
@@ -0,0 +1,29 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package ims.Controller;
+
+import ims.DataLayer.DataAccess;
+import ims.Model.Login;
+import java.util.ArrayList;
+
+/**
+ *
+ * @author Jean
+ */
+public class UserHandler {
+
+ public UserHandler() {
+
+ }
+
+ public ArrayList<Login> getData() {
+ DataAccess dataAccess = new DataAccess();
+
+ ArrayList<Login> userList = dataAccess.GetLogin();
+
+ return userList;
+
+ }
+}
View
36 src/ims/DataLayer/DataAccess.java
@@ -18,6 +18,42 @@
private PreparedStatement statement = null;
private ResultSet resultSet = null;
+
+ public ArrayList<Login> GetLogin(){
+ DataBase db = new DataBase(ConnectionType.MYSQL);
+ ArrayList<Login> loginInfo = new ArrayList<>();
+
+ try {
+ Connection conn = db.getConnection();
+ Statement pstmt = conn.createStatement();
+ ResultSet rs = pstmt.executeQuery("SELECT idLogin, username, password, accessType FROM login");
+
+ while( rs.next() ){
+ Login result = new Login( rs.getInt(1), rs.getString(2), rs.getString(3), rs.getString(4) );
+ loginInfo.add(result);
+ }
+
+ rs.close();
+ pstmt.close();
+ conn.close();
+ }
+ catch(SQLException e) {
+ System.err.println("SQL Error(s) as follows:");
+ while (e != null) {
+ System.err.println("SQL Return Code: " + e.getSQLState());
+ System.err.println(" Error Message: " + e.getMessage());
+ System.err.println(" Vendor Message: " + e.getErrorCode());
+ e = e.getNextException();
+ }
+ }
+ catch(Exception e) {
+ System.err.println(e);
+ }
+
+ return loginInfo;
+ }
+
+
public ArrayList<Login> GetLogin(String user){
DataBase db = new DataBase(ConnectionType.MYSQL);
View
10 src/ims/Model/Login.java
@@ -9,6 +9,7 @@
* @author Jean
*/
public class Login {
+ private int id;
private String username;
private String password;
private String accessType;
@@ -19,12 +20,19 @@ public Login(){
this.accessType = "";
}
+ public Login(int id, String username, String password, String accessType) {
+ this.id = id;
+ this.username = username;
+ this.password = password;
+ this.accessType = accessType;
+ }
+
public Login(String username, String password, String accessType) {
this.username = username;
this.password = password;
this.accessType = accessType;
}
-
+
public String getPassword() {
return password;
}
View
173 src/ims/UI/UserPage.form
@@ -1,6 +1,34 @@
<?xml version="1.0" encoding="UTF-8" ?>
<Form version="1.3" maxVersion="1.8" type="org.netbeans.modules.form.forminfo.JFrameFormInfo">
+ <NonVisualComponents>
+ <Container class="javax.swing.JScrollPane" name="jScrollPane1">
+ <AuxValues>
+ <AuxValue name="autoScrollPane" type="java.lang.Boolean" value="true"/>
+ </AuxValues>
+
+ <Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/>
+ <SubComponents>
+ <Component class="javax.swing.JTable" name="jTable1">
+ <Properties>
+ <Property name="model" type="javax.swing.table.TableModel" editor="org.netbeans.modules.form.editors2.TableModelEditor">
+ <Table columnCount="4" rowCount="4">
+ <Column editable="true" title="Title 1" type="java.lang.Object"/>
+ <Column editable="true" title="Title 2" type="java.lang.Object"/>
+ <Column editable="true" title="Title 3" type="java.lang.Object"/>
+ <Column editable="true" title="Title 4" type="java.lang.Object"/>
+ </Table>
+ </Property>
+ </Properties>
+ </Component>
+ </SubComponents>
+ </Container>
+ <Component class="javax.swing.JTextField" name="jTextField1">
+ <Properties>
+ <Property name="text" type="java.lang.String" value="jTextField1"/>
+ </Properties>
+ </Component>
+ </NonVisualComponents>
<Properties>
<Property name="defaultCloseOperation" type="int" value="3"/>
</Properties>
@@ -22,13 +50,154 @@
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
- <EmptySpace min="0" pref="400" max="32767" attributes="0"/>
+ <Group type="102" alignment="0" attributes="0">
+ <EmptySpace min="-2" pref="26" max="-2" attributes="0"/>
+ <Group type="103" groupAlignment="0" attributes="0">
+ <Group type="102" attributes="0">
+ <Group type="103" groupAlignment="0" max="-2" attributes="0">
+ <Group type="103" groupAlignment="1" attributes="0">
+ <Component id="jLabel1" min="-2" max="-2" attributes="0"/>
+ <Group type="102" attributes="0">
+ <Component id="jLabel2" min="-2" pref="65" max="-2" attributes="0"/>
+ <EmptySpace type="unrelated" max="-2" attributes="0"/>
+ <Component id="txtUser" min="-2" pref="156" max="-2" attributes="0"/>
+ </Group>
+ </Group>
+ <Group type="102" alignment="0" attributes="0">
+ <Group type="103" groupAlignment="0" attributes="0">
+ <Component id="jLabel3" min="-2" pref="65" max="-2" attributes="0"/>
+ <Component id="jLabel4" min="-2" max="-2" attributes="0"/>
+ </Group>
+ <EmptySpace type="unrelated" max="-2" attributes="0"/>
+ <Group type="103" groupAlignment="0" attributes="0">
+ <Component id="cmbType" max="32767" attributes="0"/>
+ <Component id="txtPass" max="32767" attributes="0"/>
+ </Group>
+ </Group>
+ </Group>
+ <EmptySpace pref="32" max="32767" attributes="0"/>
+ <Group type="103" groupAlignment="0" max="-2" attributes="0">
+ <Component id="btnDelete" max="32767" attributes="0"/>
+ <Component id="btnUpdate" pref="83" max="32767" attributes="0"/>
+ </Group>
+ </Group>
+ <Group type="102" alignment="0" attributes="0">
+ <EmptySpace min="-2" pref="11" max="-2" attributes="0"/>
+ <Component id="btnPrevious" min="-2" pref="97" max="-2" attributes="0"/>
+ <EmptySpace max="32767" attributes="0"/>
+ <Component id="btnNext" min="-2" pref="97" max="-2" attributes="0"/>
+ <EmptySpace min="-2" pref="37" max="-2" attributes="0"/>
+ </Group>
+ </Group>
+ <EmptySpace max="-2" attributes="0"/>
+ </Group>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
- <EmptySpace min="0" pref="300" max="32767" attributes="0"/>
+ <Group type="102" alignment="0" attributes="0">
+ <EmptySpace min="-2" pref="30" max="-2" attributes="0"/>
+ <Component id="jLabel1" min="-2" max="-2" attributes="0"/>
+ <EmptySpace min="-2" pref="25" max="-2" attributes="0"/>
+ <Group type="103" groupAlignment="3" attributes="0">
+ <Component id="jLabel2" alignment="3" min="-2" max="-2" attributes="0"/>
+ <Component id="txtUser" alignment="3" min="-2" max="-2" attributes="0"/>
+ <Component id="btnUpdate" alignment="3" min="-2" max="-2" attributes="0"/>
+ </Group>
+ <EmptySpace type="separate" max="-2" attributes="0"/>
+ <Group type="103" groupAlignment="0" max="-2" attributes="0">
+ <Group type="103" groupAlignment="3" attributes="0">
+ <Component id="jLabel3" alignment="3" min="-2" max="-2" attributes="0"/>
+ <Component id="btnDelete" alignment="3" min="-2" max="-2" attributes="0"/>
+ </Group>
+ <Group type="102" attributes="0">
+ <Component id="txtPass" max="32767" attributes="0"/>
+ <EmptySpace min="2" pref="2" max="-2" attributes="0"/>
+ </Group>
+ </Group>
+ <EmptySpace type="separate" max="-2" attributes="0"/>
+ <Group type="103" groupAlignment="3" attributes="0">
+ <Component id="jLabel4" alignment="3" min="-2" max="-2" attributes="0"/>
+ <Component id="cmbType" alignment="3" min="-2" max="-2" attributes="0"/>
+ </Group>
+ <EmptySpace pref="87" max="32767" attributes="0"/>
+ <Group type="103" groupAlignment="3" attributes="0">
+ <Component id="btnPrevious" alignment="3" min="-2" max="-2" attributes="0"/>
+ <Component id="btnNext" alignment="3" min="-2" max="-2" attributes="0"/>
+ </Group>
+ <EmptySpace min="-2" pref="37" max="-2" attributes="0"/>
+ </Group>
</Group>
</DimensionLayout>
</Layout>
+ <SubComponents>
+ <Component class="javax.swing.JLabel" name="jLabel1">
+ <Properties>
+ <Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor">
+ <Font name="Tahoma" size="14" style="0"/>
+ </Property>
+ <Property name="text" type="java.lang.String" value="User Management"/>
+ </Properties>
+ </Component>
+ <Component class="javax.swing.JLabel" name="jLabel2">
+ <Properties>
+ <Property name="text" type="java.lang.String" value="Username:"/>
+ </Properties>
+ </Component>
+ <Component class="javax.swing.JTextField" name="txtUser">
+ </Component>
+ <Component class="javax.swing.JLabel" name="jLabel3">
+ <Properties>
+ <Property name="text" type="java.lang.String" value="Password:"/>
+ </Properties>
+ </Component>
+ <Component class="javax.swing.JTextField" name="txtPass">
+ </Component>
+ <Component class="javax.swing.JLabel" name="jLabel4">
+ <Properties>
+ <Property name="text" type="java.lang.String" value="Access Type"/>
+ </Properties>
+ </Component>
+ <Component class="javax.swing.JComboBox" name="cmbType">
+ <Properties>
+ <Property name="model" type="javax.swing.ComboBoxModel" editor="org.netbeans.modules.form.editors2.ComboBoxModelEditor">
+ <StringArray count="4">
+ <StringItem index="0" value="Item 1"/>
+ <StringItem index="1" value="Item 2"/>
+ <StringItem index="2" value="Item 3"/>
+ <StringItem index="3" value="Item 4"/>
+ </StringArray>
+ </Property>
+ </Properties>
+ </Component>
+ <Component class="javax.swing.JButton" name="btnUpdate">
+ <Properties>
+ <Property name="text" type="java.lang.String" value="Update"/>
+ </Properties>
+ </Component>
+ <Component class="javax.swing.JButton" name="btnDelete">
+ <Properties>
+ <Property name="text" type="java.lang.String" value="Delete"/>
+ </Properties>
+ <Events>
+ <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnDeleteActionPerformed"/>
+ </Events>
+ </Component>
+ <Component class="javax.swing.JButton" name="btnPrevious">
+ <Properties>
+ <Property name="text" type="java.lang.String" value="Previous"/>
+ </Properties>
+ <Events>
+ <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnPreviousActionPerformed"/>
+ </Events>
+ </Component>
+ <Component class="javax.swing.JButton" name="btnNext">
+ <Properties>
+ <Property name="text" type="java.lang.String" value="Next"/>
+ </Properties>
+ <Events>
+ <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnNextActionPerformed"/>
+ </Events>
+ </Component>
+ </SubComponents>
</Form>
View
200 src/ims/UI/UserPage.java
@@ -4,29 +4,26 @@
*/
package ims.UI;
-import javax.swing.table.DefaultTableModel;
+import ims.Controller.UserHandler;
+import ims.Model.Login;
+import java.util.*;
+import javax.swing.JComboBox;
/**
*
* @author Jean
*/
public class UserPage extends javax.swing.JFrame {
- static final String[] columnNames = {
- "Username", "Password", "AccessType"
- };
-
- DefaultTableModel model = new DefaultTableModel(
- new Object [][] {
- {null, null, null, null},
- {null, null, null, null}
- },
- columnNames);
-
+ ArrayList<Login> userList = null;
+ int count = 0;
+
/**
* Creates new form UserPage
*/
public UserPage() {
initComponents();
+ initializeUI();
+
}
/**
@@ -38,22 +35,183 @@ public UserPage() {
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
+ jScrollPane1 = new javax.swing.JScrollPane();
+ jTable1 = new javax.swing.JTable();
+ jTextField1 = new javax.swing.JTextField();
+ jLabel1 = new javax.swing.JLabel();
+ jLabel2 = new javax.swing.JLabel();
+ txtUser = new javax.swing.JTextField();
+ jLabel3 = new javax.swing.JLabel();
+ txtPass = new javax.swing.JTextField();
+ jLabel4 = new javax.swing.JLabel();
+ cmbType = new javax.swing.JComboBox();
+ btnUpdate = new javax.swing.JButton();
+ btnDelete = new javax.swing.JButton();
+ btnPrevious = new javax.swing.JButton();
+ btnNext = new javax.swing.JButton();
+
+ jTable1.setModel(new javax.swing.table.DefaultTableModel(
+ new Object [][] {
+ {null, null, null, null},
+ {null, null, null, null},
+ {null, null, null, null},
+ {null, null, null, null}
+ },
+ new String [] {
+ "Title 1", "Title 2", "Title 3", "Title 4"
+ }
+ ));
+ jScrollPane1.setViewportView(jTable1);
+
+ jTextField1.setText("jTextField1");
+
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
+ jLabel1.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
+ jLabel1.setText("User Management");
+
+ jLabel2.setText("Username:");
+
+ jLabel3.setText("Password:");
+
+ jLabel4.setText("Access Type");
+
+ cmbType.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
+
+ btnUpdate.setText("Update");
+
+ btnDelete.setText("Delete");
+ btnDelete.addActionListener(new java.awt.event.ActionListener() {
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
+ btnDeleteActionPerformed(evt);
+ }
+ });
+
+ btnPrevious.setText("Previous");
+ btnPrevious.addActionListener(new java.awt.event.ActionListener() {
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
+ btnPreviousActionPerformed(evt);
+ }
+ });
+
+ btnNext.setText("Next");
+ btnNext.addActionListener(new java.awt.event.ActionListener() {
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
+ btnNextActionPerformed(evt);
+ }
+ });
+
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGap(0, 400, Short.MAX_VALUE)
+ .addGroup(layout.createSequentialGroup()
+ .addGap(26, 26, 26)
+ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addGroup(layout.createSequentialGroup()
+ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
+ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
+ .addComponent(jLabel1)
+ .addGroup(layout.createSequentialGroup()
+ .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
+ .addComponent(txtUser, javax.swing.GroupLayout.PREFERRED_SIZE, 156, javax.swing.GroupLayout.PREFERRED_SIZE)))
+ .addGroup(layout.createSequentialGroup()
+ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addComponent(jLabel4))
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
+ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addComponent(cmbType, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
+ .addComponent(txtPass))))
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 32, Short.MAX_VALUE)
+ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
+ .addComponent(btnDelete, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
+ .addComponent(btnUpdate, javax.swing.GroupLayout.DEFAULT_SIZE, 83, Short.MAX_VALUE)))
+ .addGroup(layout.createSequentialGroup()
+ .addGap(11, 11, 11)
+ .addComponent(btnPrevious, javax.swing.GroupLayout.PREFERRED_SIZE, 97, javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
+ .addComponent(btnNext, javax.swing.GroupLayout.PREFERRED_SIZE, 97, javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addGap(37, 37, 37)))
+ .addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGap(0, 300, Short.MAX_VALUE)
+ .addGroup(layout.createSequentialGroup()
+ .addGap(30, 30, 30)
+ .addComponent(jLabel1)
+ .addGap(25, 25, 25)
+ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
+ .addComponent(jLabel2)
+ .addComponent(txtUser, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addComponent(btnUpdate))
+ .addGap(18, 18, 18)
+ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
+ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
+ .addComponent(jLabel3)
+ .addComponent(btnDelete))
+ .addGroup(layout.createSequentialGroup()
+ .addComponent(txtPass)
+ .addGap(2, 2, 2)))
+ .addGap(18, 18, 18)
+ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
+ .addComponent(jLabel4)
+ .addComponent(cmbType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 87, Short.MAX_VALUE)
+ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
+ .addComponent(btnPrevious)
+ .addComponent(btnNext))
+ .addGap(37, 37, 37))
);
pack();
}// </editor-fold>//GEN-END:initComponents
+ private void initializeUI(){
+ //populate the combo box
+ String[] options = {"admin", "cashier", "branch", "warehouse"};
+ cmbType.setModel(new javax.swing.DefaultComboBoxModel(options));
+
+ //gets all the existing data
+ UserHandler handle = new UserHandler();
+ this.userList = handle.getData();
+
+ load();
+ }
+
+ private void load(){
+ validateRange();
+
+ String user = this.userList.get(count).getUsername();
+ String pass = this.userList.get(count).getPassword();
+ String access = this.userList.get(count).getAccessType();
+
+ txtUser.setText(user);
+ txtPass.setText(pass);
+ cmbType.setSelectedItem(access);
+ }
+
+
+ private void btnDeleteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDeleteActionPerformed
+ // TODO add your handling code here:
+ }//GEN-LAST:event_btnDeleteActionPerformed
+ private void btnPreviousActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnPreviousActionPerformed
+ count--;
+ load();
+ }//GEN-LAST:event_btnPreviousActionPerformed
+
+ private void btnNextActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnNextActionPerformed
+ count++;
+ load();
+ }//GEN-LAST:event_btnNextActionPerformed
+
+ private void validateRange() {
+ if (count > userList.size() || count <= 0 ) {
+ count = 0;
+ }
+ }
+
/**
* @param args the command line arguments
*/
@@ -96,5 +254,19 @@ public void run() {
});
}
// Variables declaration - do not modify//GEN-BEGIN:variables
+ private javax.swing.JButton btnDelete;
+ private javax.swing.JButton btnNext;
+ private javax.swing.JButton btnPrevious;
+ private javax.swing.JButton btnUpdate;
+ private javax.swing.JComboBox cmbType;
+ private javax.swing.JLabel jLabel1;
+ private javax.swing.JLabel jLabel2;
+ private javax.swing.JLabel jLabel3;
+ private javax.swing.JLabel jLabel4;
+ private javax.swing.JScrollPane jScrollPane1;
+ private javax.swing.JTable jTable1;
+ private javax.swing.JTextField jTextField1;
+ private javax.swing.JTextField txtPass;
+ private javax.swing.JTextField txtUser;
// End of variables declaration//GEN-END:variables
}

0 comments on commit e7f1c07

Please sign in to comment.