<file_sep>/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package Inventory;

import Admins.AdminActivity;
import Main.Admin;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.Statement;
import java.util.Vector;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author Saima
 */
public class stock extends javax.swing.JFrame {

    /**
     * Creates new form stock
     */
    public stock() {
        ImageIcon ic = new ImageIcon(getClass().getResource("/Images/icon_1.png"));
        this.setIconImage(ic.getImage());
        initComponents();
        loadData();
    }
 public void loadData() {
   try {  
             Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");  
             Connection connection = DriverManager.getConnection("jdbc:sqlserver://localhost:1433;databaseName=lab11;integratedSecurity=true");  
   
               Statement statement = connection.createStatement();  
               
             ResultSet rs = statement.executeQuery("SELECT  stock_id as StockId , product_id as ProductId ,quantity_on_stock as StockQuantity , stock_updated_date as Date FROM stock order by stock_id");  
             ResultSetMetaData  rsmetadata = rs.getMetaData(); 
              int  columns = rsmetadata.getColumnCount();   
              DefaultTableModel dtm = new DefaultTableModel(); 
              Vector columns_name=new Vector();
              Vector data_rows=new Vector();
              for(int  i= 1; i < columns+1; i++)  
                {             
                        columns_name.addElement (rsmetadata.getColumnLabel(i));  
                }                 
              
              dtm.setColumnIdentifiers(columns_name);
                   while (rs.next())  
           {  
               data_rows = new Vector(); 
               for (int j = 1; j <columns+1; j++)  
               {  
                   data_rows.addElement(rs.getString(j)) ;
               }  
               dtm.addRow(data_rows);  
               
       }   
          dDTable.setModel(dtm); 
             
         } catch (Exception e) {  
             e.printStackTrace();  
         }  
    }
    /**
     * 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">//GEN-BEGIN:initComponents
    private void initComponents() {

        name1 = new javax.swing.JLabel();
        pidField = new javax.swing.JTextField();
        id = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        dDTable = new javax.swing.JTable();
        sidField = new javax.swing.JTextField();
        jPanel6 = new javax.swing.JPanel();
        add_product = new javax.swing.JLabel();
        jLabel20 = new javax.swing.JLabel();
        jLabel21 = new javax.swing.JLabel();
        logout = new javax.swing.JLabel();
        backbtn = new javax.swing.JLabel();
        name = new javax.swing.JLabel();
        name2 = new javax.swing.JLabel();
        sQuantityField = new javax.swing.JTextField();
        sDateField = new javax.swing.JTextField();
        restobtn = new javax.swing.JButton();
        upstobtn = new javax.swing.JButton();
        delstobtn = new javax.swing.JButton();
        addstobtn = new javax.swing.JButton();
        clearstobtn = new javax.swing.JButton();
        search = new javax.swing.JButton();
        searchField1 = new javax.swing.JTextField();
        maxQuan = new javax.swing.JButton();
        quanHL = new javax.swing.JButton();
        name4 = new javax.swing.JLabel();
        quanLH1 = new javax.swing.JButton();
        minQuan1 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Stock");

        name1.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
        name1.setForeground(new java.awt.Color(0, 153, 153));
        name1.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        name1.setText("Date");

        pidField.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        pidField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                pidFieldActionPerformed(evt);
            }
        });

        id.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
        id.setForeground(new java.awt.Color(0, 153, 153));
        id.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        id.setText("Product Id");
        id.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);

        dDTable.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 [] {
                "Stock Id", "Prouduct Id", "StockQuantity", "Date"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        dDTable.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                dDTableMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(dDTable);

        sidField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                sidFieldActionPerformed(evt);
            }
        });

        jPanel6.setBackground(new java.awt.Color(0, 153, 153));

        add_product.setFont(new java.awt.Font("Arial", 0, 24)); // NOI18N
        add_product.setForeground(new java.awt.Color(255, 255, 255));
        add_product.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        add_product.setText("Stock");

        jLabel20.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jLabel20MouseClicked(evt);
            }
        });

        jLabel21.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jLabel21MouseClicked(evt);
            }
        });

        logout.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Icon/cross.png"))); // NOI18N
        logout.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                logoutMouseClicked(evt);
            }
        });

        backbtn.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Icon/backs.png"))); // NOI18N
        backbtn.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                backbtnMouseClicked(evt);
            }
        });

        javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
        jPanel6.setLayout(jPanel6Layout);
        jPanel6Layout.setHorizontalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(add_product, javax.swing.GroupLayout.PREFERRED_SIZE, 152, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(419, 419, 419)
                .addComponent(backbtn)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel21)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(logout)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel20, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        jPanel6Layout.setVerticalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel6Layout.createSequentialGroup()
                        .addComponent(logout)
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addGroup(jPanel6Layout.createSequentialGroup()
                        .addComponent(backbtn)
                        .addContainerGap(22, Short.MAX_VALUE))
                    .addGroup(jPanel6Layout.createSequentialGroup()
                        .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(add_product, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jLabel21, javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel20, javax.swing.GroupLayout.Alignment.LEADING))
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
        );

        name.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
        name.setForeground(new java.awt.Color(0, 153, 153));
        name.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        name.setText("Stock Id");

        name2.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
        name2.setForeground(new java.awt.Color(0, 153, 153));
        name2.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        name2.setText("Stock Quantity");

        sQuantityField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                sQuantityFieldActionPerformed(evt);
            }
        });

        sDateField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                sDateFieldActionPerformed(evt);
            }
        });

        restobtn.setBackground(new java.awt.Color(0, 153, 153));
        restobtn.setFont(new java.awt.Font("Tahoma", 0, 20)); // NOI18N
        restobtn.setForeground(new java.awt.Color(255, 255, 255));
        restobtn.setText("Refresh");
        restobtn.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                restobtnMouseClicked(evt);
            }
        });

        upstobtn.setBackground(new java.awt.Color(0, 153, 153));
        upstobtn.setFont(new java.awt.Font("Tahoma", 0, 20)); // NOI18N
        upstobtn.setForeground(new java.awt.Color(255, 255, 255));
        upstobtn.setText("Update");
        upstobtn.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                upstobtnMouseClicked(evt);
            }
        });

        delstobtn.setBackground(new java.awt.Color(0, 153, 153));
        delstobtn.setFont(new java.awt.Font("Tahoma", 0, 20)); // NOI18N
        delstobtn.setForeground(new java.awt.Color(255, 255, 255));
        delstobtn.setText("Delete");
        delstobtn.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                delstobtnMouseClicked(evt);
            }
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                delstobtnMouseEntered(evt);
            }
        });

        addstobtn.setBackground(new java.awt.Color(0, 153, 153));
        addstobtn.setFont(new java.awt.Font("Tahoma", 0, 20)); // NOI18N
        addstobtn.setForeground(new java.awt.Color(255, 255, 255));
        addstobtn.setText("Add");
        addstobtn.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                addstobtnMouseClicked(evt);
            }
        });

        clearstobtn.setBackground(new java.awt.Color(0, 153, 153));
        clearstobtn.setFont(new java.awt.Font("Tahoma", 0, 20)); // NOI18N
        clearstobtn.setForeground(new java.awt.Color(255, 255, 255));
        clearstobtn.setText("Clear");
        clearstobtn.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                clearstobtnMouseClicked(evt);
            }
        });

        search.setBackground(new java.awt.Color(0, 153, 153));
        search.setFont(new java.awt.Font("Tahoma", 0, 20)); // NOI18N
        search.setForeground(new java.awt.Color(255, 255, 255));
        search.setText("Search ");
        search.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                searchMouseClicked(evt);
            }
        });
        search.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                searchActionPerformed(evt);
            }
        });

        searchField1.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        searchField1.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        searchField1.setText("Enter Product Name");
        searchField1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                searchField1ActionPerformed(evt);
            }
        });

        maxQuan.setBackground(new java.awt.Color(0, 153, 153));
        maxQuan.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
        maxQuan.setForeground(new java.awt.Color(255, 255, 255));
        maxQuan.setText("Maximum Quantity");
        maxQuan.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                maxQuanMouseClicked(evt);
            }
        });
        maxQuan.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                maxQuanActionPerformed(evt);
            }
        });

        quanHL.setBackground(new java.awt.Color(0, 153, 153));
        quanHL.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
        quanHL.setForeground(new java.awt.Color(255, 255, 255));
        quanHL.setText("Quantity(High to low)");
        quanHL.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                quanHLMouseClicked(evt);
            }
        });
        quanHL.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                quanHLActionPerformed(evt);
            }
        });

        name4.setFont(new java.awt.Font("Tahoma", 0, 24)); // NOI18N
        name4.setForeground(new java.awt.Color(0, 153, 153));
        name4.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        name4.setText("Filters :");

        quanLH1.setBackground(new java.awt.Color(0, 153, 153));
        quanLH1.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
        quanLH1.setForeground(new java.awt.Color(255, 255, 255));
        quanLH1.setText("Quantity(Low to High)");
        quanLH1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                quanLH1MouseClicked(evt);
            }
        });
        quanLH1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                quanLH1ActionPerformed(evt);
            }
        });

        minQuan1.setBackground(new java.awt.Color(0, 153, 153));
        minQuan1.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
        minQuan1.setForeground(new java.awt.Color(255, 255, 255));
        minQuan1.setText("Minimum Quantity");
        minQuan1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                minQuan1MouseClicked(evt);
            }
        });
        minQuan1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                minQuan1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(22, 22, 22)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(name2, javax.swing.GroupLayout.PREFERRED_SIZE, 135, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(name, javax.swing.GroupLayout.PREFERRED_SIZE, 92, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(sidField, javax.swing.GroupLayout.PREFERRED_SIZE, 142, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(sQuantityField, javax.swing.GroupLayout.PREFERRED_SIZE, 138, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 88, Short.MAX_VALUE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(id, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(name1, javax.swing.GroupLayout.PREFERRED_SIZE, 76, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(pidField, javax.swing.GroupLayout.PREFERRED_SIZE, 138, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(sDateField, javax.swing.GroupLayout.PREFERRED_SIZE, 135, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(49, 49, 49))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(35, 35, 35)
                        .addComponent(addstobtn, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(36, 36, 36)
                        .addComponent(delstobtn)
                        .addGap(24, 24, 24)
                        .addComponent(upstobtn)
                        .addGap(25, 25, 25)
                        .addComponent(restobtn)
                        .addGap(34, 34, 34)
                        .addComponent(clearstobtn, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(139, 139, 139)
                                .addComponent(searchField1, javax.swing.GroupLayout.PREFERRED_SIZE, 207, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(229, 229, 229))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(search)
                                .addGroup(layout.createSequentialGroup()
                                    .addComponent(name4, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addGap(44, 44, 44)
                                    .addComponent(quanLH1)
                                    .addGap(18, 18, 18)
                                    .addComponent(quanHL))))
                        .addGap(86, 86, 86))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 434, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(maxQuan, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(minQuan1, javax.swing.GroupLayout.PREFERRED_SIZE, 181, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(20, 20, 20))))
            .addComponent(jPanel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(83, 83, 83)
                        .addComponent(minQuan1, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(maxQuan, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(53, 53, 53)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 237, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(name, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(sidField, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(id)
                                        .addComponent(pidField, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                .addGap(40, 40, 40)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(name2, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(sQuantityField, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(name1, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(sDateField, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE))))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 43, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addComponent(upstobtn, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(delstobtn, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(addstobtn, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(restobtn, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(clearstobtn, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 51, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(search, javax.swing.GroupLayout.PREFERRED_SIZE, 51, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(searchField1, javax.swing.GroupLayout.PREFERRED_SIZE, 51, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(42, 42, 42)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(quanHL, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(name4, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(quanLH1, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addGap(135, 135, 135))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void pidFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_pidFieldActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_pidFieldActionPerformed

    private void dDTableMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_dDTableMouseClicked
        // TODO add your handling code here:
        // get the model from the jtable
        DefaultTableModel model = (DefaultTableModel)dDTable.getModel();

        // get the selected row index
        int selectedRowIndex = dDTable.getSelectedRow();

        // set the selected row data into jtextfields
        sidField.setText(model.getValueAt(selectedRowIndex, 0).toString());
               pidField.setText(model.getValueAt(selectedRowIndex, 1).toString());
              
                sQuantityField.setText(model.getValueAt(selectedRowIndex, 2).toString());
        sDateField.setText(model.getValueAt(selectedRowIndex, 3).toString());
       
        //        quantityField.setText(model.getValueAt(selectedRowIndex, 3).toString());
        //        descriptionField.setText(model.getValueAt(selectedRowIndex, 4).toString());
    }//GEN-LAST:event_dDTableMouseClicked

    private void sidFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_sidFieldActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_sidFieldActionPerformed

    private void jLabel20MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel20MouseClicked

    }//GEN-LAST:event_jLabel20MouseClicked

    private void jLabel21MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel21MouseClicked

    }//GEN-LAST:event_jLabel21MouseClicked

    private void logoutMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_logoutMouseClicked
        Admin admin = new Admin();
        admin.setVisible(true);
        dispose();
    }//GEN-LAST:event_logoutMouseClicked

    private void backbtnMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_backbtnMouseClicked
        AdminActivity adActivity = new AdminActivity();
        adActivity.setVisible(true);
        dispose();
    }//GEN-LAST:event_backbtnMouseClicked

    private void sQuantityFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_sQuantityFieldActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_sQuantityFieldActionPerformed

    private void sDateFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_sDateFieldActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_sDateFieldActionPerformed

    private void restobtnMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_restobtnMouseClicked
        // TODO add your handling code here:
   try {
            Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
            Connection connection = DriverManager.getConnection("jdbc:sqlserver://localhost:1433;databaseName=lab11;integratedSecurity=true");

            Statement statement = connection.createStatement();

           ResultSet rs = statement.executeQuery("SELECT  stock_id as StockId , product_id as ProductId ,quantity_on_stock as StockQuantity , stock_updated_date as Date FROM stock order by stock_id");  
            ResultSetMetaData  rsmetadata = rs.getMetaData();
            int  columns = rsmetadata.getColumnCount();
            DefaultTableModel dtm = new DefaultTableModel();
            Vector columns_name=new Vector();
            Vector data_rows=new Vector();
            for(int  i= 1; i < columns+1; i++)
            {
                columns_name.addElement (rsmetadata.getColumnLabel(i));
            }

            dtm.setColumnIdentifiers(columns_name);
            while (rs.next())
            {
                data_rows = new Vector();
                for (int j = 1; j <columns+1; j++)
                {
                    data_rows.addElement(rs.getString(j)) ;
                }
                dtm.addRow(data_rows);

            }
            dDTable.setModel(dtm);
            JOptionPane.showMessageDialog(null, "Refreshed");

        } catch (Exception e) {
            e.printStackTrace();
        }
    }//GEN-LAST:event_restobtnMouseClicked

    private void upstobtnMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_upstobtnMouseClicked
        // TODO add your handling code here:
         String s1 = sidField.getText();
        String s2 = pidField.getText();
        String s3 = sQuantityField.getText();
   
                String s5= sDateField.getText();
             
        //        String s8 = descriptionField.getText();
        //        String s7 = priceField.getText();

        try {
            Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
            Connection connection = DriverManager.getConnection("jdbc:sqlserver://localhost:1433;databaseName=lab11;integratedSecurity=true");

            Statement statement = connection.createStatement();

            statement.execute("Update stock set stock_id =" + s1 + ", product_id =" + s2 + ", quantity_on_stock =" + s3 + ",stock_updated_date = "+" '"+ s5 +"' "+" where stock_id ="+ s1+"");

            JOptionPane.showMessageDialog(null, "Data Updated");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }//GEN-LAST:event_upstobtnMouseClicked

    private void delstobtnMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_delstobtnMouseClicked
        // TODO add your handling code here:
       String s1 = sidField.getText();

        try {
            Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
            Connection connection = DriverManager.getConnection("jdbc:sqlserver://localhost:1433;databaseName=lab11;integratedSecurity=true");

            Statement statement = connection.createStatement();

            statement.execute(" delete from stock "  + " where stock_id = (  "+s1+")" );

            JOptionPane.showMessageDialog(null, "Stock Id " + s1 + " has been deleted");
        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, "Stock named " + s1 + " not found");
        }
    }//GEN-LAST:event_delstobtnMouseClicked

    private void delstobtnMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_delstobtnMouseEntered
        // TODO add your handling code here:
    }//GEN-LAST:event_delstobtnMouseEntered

    private void addstobtnMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_addstobtnMouseClicked
        // TODO add your handling code here:
     String s1 = sidField.getText();
        String s2 = pidField.getText();
        String s3 = sQuantityField.getText();
      
                String s5= sDateField.getText();
                

        try {
            Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
            Connection connection = DriverManager.getConnection("jdbc:sqlserver://localhost:1433;databaseName=lab11;integratedSecurity=true");

            Statement statement = connection.createStatement();

            statement.execute(" insert into stock "  + " values ( '"+s1+"', '"+s2+"','"+s3+"', '"+s5+"')" );

            JOptionPane.showMessageDialog(null, " Saved");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }//GEN-LAST:event_addstobtnMouseClicked

    private void clearstobtnMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_clearstobtnMouseClicked
        // TODO add your handling code here:
       
        pidField.setText("");
        sidField.setText("");
// searchField1.setText("");
        sQuantityField.setText("");
           sDateField.setText("");
    }//GEN-LAST:event_clearstobtnMouseClicked

    private void searchMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_searchMouseClicked
        // TODO add your handling code here:
        String s1= searchField1.getText();
        try {
            Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
            Connection connection = DriverManager.getConnection("jdbc:sqlserver://localhost:1433;databaseName=lab11;integratedSecurity=true");

            Statement statement = connection.createStatement();

            ResultSet rs = statement.executeQuery("  select s.stock_id as Stock_Id ,p.product_name as ProductName,s.quantity_on_stock as StockQuantity,s.stock_updated_date as Date,p.product_price as ProductPrice\n" +
" \n" +
"  from product p\n" +
"  inner join stock s\n" +
"  on s.product_id=p.product_id\n" + "  where product_name = (  '"+s1+"') ");
            ResultSetMetaData  rsmetadata = rs.getMetaData();
            int  columns = rsmetadata.getColumnCount();
            DefaultTableModel dtm = new DefaultTableModel();
            Vector columns_name=new Vector();
            Vector data_rows=new Vector();
            for(int  i= 1; i < columns+1; i++)
            {
                columns_name.addElement (rsmetadata.getColumnLabel(i));
            }

            dtm.setColumnIdentifiers(columns_name);
            while (rs.next())
            {
                data_rows = new Vector();
                for (int j = 1; j <columns+1; j++)
                {
                    data_rows.addElement(rs.getString(j)) ;
                }
                dtm.addRow(data_rows);

            }
            dDTable.setModel(dtm);

        } catch (Exception e) {
            e.printStackTrace();
        }
    }//GEN-LAST:event_searchMouseClicked

    private void searchField1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_searchField1ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_searchField1ActionPerformed

    private void searchActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_searchActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_searchActionPerformed

    private void maxQuanMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_maxQuanMouseClicked
        // TODO add your handling code here:
        try {
            Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
            Connection connection = DriverManager.getConnection("jdbc:sqlserver://localhost:1433;databaseName=lab11;integratedSecurity=true");

            Statement statement = connection.createStatement();

            ResultSet rs = statement.executeQuery("  select  p.product_name,s.quantity_on_stock\n" +
" \n" +
"  from product p\n" +
"  inner join stock s\n" +
"  on p.product_id=s.product_id  \n" +
"  where s.quantity_on_stock=(\n" +
"  select MAX(s.quantity_on_stock) from stock s)");
            ResultSetMetaData  rsmetadata = rs.getMetaData();
            int  columns = rsmetadata.getColumnCount();
            DefaultTableModel dtm = new DefaultTableModel();
            Vector columns_name=new Vector();
            Vector data_rows=new Vector();
            for(int  i= 1; i < columns+1; i++)
            {
                columns_name.addElement (rsmetadata.getColumnLabel(i));
            }

            dtm.setColumnIdentifiers(columns_name);
            while (rs.next())
            {
                data_rows = new Vector();
                for (int j = 1; j <columns+1; j++)
                {
                    data_rows.addElement(rs.getString(j)) ;
                }
                dtm.addRow(data_rows);

            }
            dDTable.setModel(dtm);

        } catch (Exception e) {
            e.printStackTrace();
        }
    }//GEN-LAST:event_maxQuanMouseClicked

    private void maxQuanActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_maxQuanActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_maxQuanActionPerformed

    private void quanHLMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_quanHLMouseClicked
        // TODO add your handling code here:
        try {
            Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
            Connection connection = DriverManager.getConnection("jdbc:sqlserver://localhost:1433;databaseName=lab11;integratedSecurity=true");

            Statement statement = connection.createStatement();

            ResultSet rs = statement.executeQuery("     select  s.stock_id as Stock_Id ,p.product_name as ProductName,s.quantity_on_stock as StockQuantity,s.stock_updated_date as Date\n" +
" \n" +
"  from product p\n" +
"  inner join stock s\n" +
"  on p.product_id=s.product_id  \n" +
"  order by s.quantity_on_stock desc ");
            ResultSetMetaData  rsmetadata = rs.getMetaData();
            int  columns = rsmetadata.getColumnCount();
            DefaultTableModel dtm = new DefaultTableModel();
            Vector columns_name=new Vector();
            Vector data_rows=new Vector();
            for(int  i= 1; i < columns+1; i++)
            {
                columns_name.addElement (rsmetadata.getColumnLabel(i));
            }

            dtm.setColumnIdentifiers(columns_name);
            while (rs.next())
            {
                data_rows = new Vector();
                for (int j = 1; j <columns+1; j++)
                {
                    data_rows.addElement(rs.getString(j)) ;
                }
                dtm.addRow(data_rows);

            }
            dDTable.setModel(dtm);

        } catch (Exception e) {
            e.printStackTrace();
        }
    }//GEN-LAST:event_quanHLMouseClicked

    private void quanHLActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_quanHLActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_quanHLActionPerformed

    private void quanLH1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_quanLH1MouseClicked
        // TODO add your handling code here:
    }//GEN-LAST:event_quanLH1MouseClicked

    private void quanLH1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_quanLH1ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_quanLH1ActionPerformed

    private void minQuan1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_minQuan1MouseClicked
        // TODO add your handling code here:
         try {
            Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
            Connection connection = DriverManager.getConnection("jdbc:sqlserver://localhost:1433;databaseName=lab11;integratedSecurity=true");

            Statement statement = connection.createStatement();

            ResultSet rs = statement.executeQuery("  select  p.product_name,s.quantity_on_stock\n" +
" \n" +
"  from product p\n" +
"  inner join stock s\n" +
"  on p.product_id=s.product_id  \n" +
"  where s.quantity_on_stock=(\n" +
"  select min(s.quantity_on_stock) from stock s)");
            ResultSetMetaData  rsmetadata = rs.getMetaData();
            int  columns = rsmetadata.getColumnCount();
            DefaultTableModel dtm = new DefaultTableModel();
            Vector columns_name=new Vector();
            Vector data_rows=new Vector();
            for(int  i= 1; i < columns+1; i++)
            {
                columns_name.addElement (rsmetadata.getColumnLabel(i));
            }

            dtm.setColumnIdentifiers(columns_name);
            while (rs.next())
            {
                data_rows = new Vector();
                for (int j = 1; j <columns+1; j++)
                {
                    data_rows.addElement(rs.getString(j)) ;
                }
                dtm.addRow(data_rows);

            }
            dDTable.setModel(dtm);

        } catch (Exception e) {
            e.printStackTrace();
        }
    }//GEN-LAST:event_minQuan1MouseClicked

    private void minQuan1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_minQuan1ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_minQuan1ActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(stock.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(stock.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(stock.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(stock.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new stock().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel add_product;
    private javax.swing.JButton addstobtn;
    private javax.swing.JLabel backbtn;
    private javax.swing.JButton clearstobtn;
    private javax.swing.JTable dDTable;
    private javax.swing.JButton delstobtn;
    private javax.swing.JLabel id;
    private javax.swing.JLabel jLabel20;
    private javax.swing.JLabel jLabel21;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel logout;
    private javax.swing.JButton maxQuan;
    private javax.swing.JButton minQuan1;
    private javax.swing.JLabel name;
    private javax.swing.JLabel name1;
    private javax.swing.JLabel name2;
    private javax.swing.JLabel name4;
    private javax.swing.JTextField pidField;
    private javax.swing.JButton quanHL;
    private javax.swing.JButton quanLH1;
    private javax.swing.JButton restobtn;
    private javax.swing.JTextField sDateField;
    private javax.swing.JTextField sQuantityField;
    private javax.swing.JButton search;
    private javax.swing.JTextField searchField1;
    private javax.swing.JTextField sidField;
    private javax.swing.JButton upstobtn;
    // End of variables declaration//GEN-END:variables
}
<file_sep>/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package Inventory;

import Admins.AdminActivity;
import Main.Admin;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.Statement;
import java.util.Vector;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author Saima
 */
public class category extends javax.swing.JFrame {

    /**
     * Creates new form category
     */
    public category() {
             ImageIcon ic = new ImageIcon(getClass().getResource("/Images/icon_1.png"));
        this.setIconImage(ic.getImage());
        initComponents();
        loadData();
    }
public void loadData() {
   try {  
             Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");  
             Connection connection = DriverManager.getConnection("jdbc:sqlserver://localhost:1433;databaseName=lab11;integratedSecurity=true");  
   
               Statement statement = connection.createStatement();  
               
             ResultSet rs = statement.executeQuery("SELECT category_id as CategoryId , category_name CategoryName , category_status CategoryStatus FROM category order by category_id");  
             ResultSetMetaData  rsmetadata = rs.getMetaData(); 
              int  columns = rsmetadata.getColumnCount();   
              DefaultTableModel dtm = new DefaultTableModel(); 
              Vector columns_name=new Vector();
              Vector data_rows=new Vector();
              for(int  i= 1; i < columns+1; i++)  
                {             
                        columns_name.addElement (rsmetadata.getColumnLabel(i));  
                }                 
              
              dtm.setColumnIdentifiers(columns_name);
                   while (rs.next())  
           {  
               data_rows = new Vector(); 
               for (int j = 1; j <columns+1; j++)  
               {  
                   data_rows.addElement(rs.getString(j)) ;
               }  
               dtm.addRow(data_rows);  
               
       }   
          dDTable.setModel(dtm); 
             
         } catch (Exception e) {  
             e.printStackTrace();  
         }  
    }
    /**
     * 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">//GEN-BEGIN:initComponents
    private void initComponents() {

        jDialog1 = new javax.swing.JDialog();
        jDialog2 = new javax.swing.JDialog();
        name1 = new javax.swing.JLabel();
        cnameField = new javax.swing.JTextField();
        cidField = new javax.swing.JTextField();
        id = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        dDTable = new javax.swing.JTable();
        jPanel6 = new javax.swing.JPanel();
        add_product = new javax.swing.JLabel();
        jLabel20 = new javax.swing.JLabel();
        jLabel21 = new javax.swing.JLabel();
        logout = new javax.swing.JLabel();
        backbtn = new javax.swing.JLabel();
        cstatusField = new javax.swing.JTextField();
        name2 = new javax.swing.JLabel();
        recatbtn = new javax.swing.JButton();
        upcatbtn = new javax.swing.JButton();
        delcatbtn = new javax.swing.JButton();
        addcatbtn = new javax.swing.JButton();
        clearcatbtn = new javax.swing.JButton();
        name3 = new javax.swing.JLabel();
        search = new javax.swing.JButton();
        searchPriceField = new javax.swing.JTextField();
        sortAZ = new javax.swing.JButton();
        sortZA = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        availcat = new javax.swing.JButton();
        showAvailcat = new javax.swing.JTextField();
        searchField1 = new javax.swing.JTextField();
        sortHL = new javax.swing.JButton();
        name = new javax.swing.JLabel();

        javax.swing.GroupLayout jDialog1Layout = new javax.swing.GroupLayout(jDialog1.getContentPane());
        jDialog1.getContentPane().setLayout(jDialog1Layout);
        jDialog1Layout.setHorizontalGroup(
            jDialog1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 400, Short.MAX_VALUE)
        );
        jDialog1Layout.setVerticalGroup(
            jDialog1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 300, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout jDialog2Layout = new javax.swing.GroupLayout(jDialog2.getContentPane());
        jDialog2.getContentPane().setLayout(jDialog2Layout);
        jDialog2Layout.setHorizontalGroup(
            jDialog2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 400, Short.MAX_VALUE)
        );
        jDialog2Layout.setVerticalGroup(
            jDialog2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 300, Short.MAX_VALUE)
        );

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Category");

        name1.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
        name1.setForeground(new java.awt.Color(0, 153, 153));
        name1.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        name1.setText("Category Name");

        cnameField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cnameFieldActionPerformed(evt);
            }
        });

        cidField.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        cidField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cidFieldActionPerformed(evt);
            }
        });

        id.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
        id.setForeground(new java.awt.Color(0, 153, 153));
        id.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        id.setText("Category Id");
        id.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);

        dDTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null},
                {null, null},
                {null, null},
                {null, null}
            },
            new String [] {
                "Category Id", "Category Name"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        dDTable.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                dDTableMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(dDTable);

        jPanel6.setBackground(new java.awt.Color(0, 153, 153));

        add_product.setFont(new java.awt.Font("Arial", 0, 24)); // NOI18N
        add_product.setForeground(new java.awt.Color(255, 255, 255));
        add_product.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        add_product.setText("Category");

        jLabel20.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jLabel20MouseClicked(evt);
            }
        });

        jLabel21.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jLabel21MouseClicked(evt);
            }
        });

        logout.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Icon/cross.png"))); // NOI18N
        logout.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                logoutMouseClicked(evt);
            }
        });

        backbtn.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Icon/backs.png"))); // NOI18N
        backbtn.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                backbtnMouseClicked(evt);
            }
        });

        javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
        jPanel6.setLayout(jPanel6Layout);
        jPanel6Layout.setHorizontalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addGap(604, 604, 604)
                .addComponent(add_product, javax.swing.GroupLayout.PREFERRED_SIZE, 152, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel6Layout.createSequentialGroup()
                        .addGap(643, 643, 643)
                        .addComponent(jLabel21)
                        .addGap(168, 168, 168)
                        .addComponent(jLabel20, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel6Layout.createSequentialGroup()
                        .addGap(436, 436, 436)
                        .addComponent(backbtn)
                        .addGap(18, 18, 18)
                        .addComponent(logout)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel6Layout.setVerticalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(add_product, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel6Layout.createSequentialGroup()
                        .addComponent(jLabel20)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel21)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(backbtn)
                            .addComponent(logout))
                        .addGap(6, 6, 6)))
                .addContainerGap(16, Short.MAX_VALUE))
        );

        cstatusField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cstatusFieldActionPerformed(evt);
            }
        });

        name2.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
        name2.setForeground(new java.awt.Color(0, 153, 153));
        name2.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        name2.setText("Category Status");

        recatbtn.setBackground(new java.awt.Color(0, 153, 153));
        recatbtn.setFont(new java.awt.Font("Tahoma", 0, 20)); // NOI18N
        recatbtn.setForeground(new java.awt.Color(255, 255, 255));
        recatbtn.setText("Refresh");
        recatbtn.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                recatbtnMouseClicked(evt);
            }
        });

        upcatbtn.setBackground(new java.awt.Color(0, 153, 153));
        upcatbtn.setFont(new java.awt.Font("Tahoma", 0, 20)); // NOI18N
        upcatbtn.setForeground(new java.awt.Color(255, 255, 255));
        upcatbtn.setText("Update");
        upcatbtn.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                upcatbtnMouseClicked(evt);
            }
        });

        delcatbtn.setBackground(new java.awt.Color(0, 153, 153));
        delcatbtn.setFont(new java.awt.Font("Tahoma", 0, 20)); // NOI18N
        delcatbtn.setForeground(new java.awt.Color(255, 255, 255));
        delcatbtn.setText("Delete");
        delcatbtn.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                delcatbtnMouseClicked(evt);
            }
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                delcatbtnMouseEntered(evt);
            }
        });

        addcatbtn.setBackground(new java.awt.Color(0, 153, 153));
        addcatbtn.setFont(new java.awt.Font("Tahoma", 0, 20)); // NOI18N
        addcatbtn.setForeground(new java.awt.Color(255, 255, 255));
        addcatbtn.setText("Add");
        addcatbtn.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                addcatbtnMouseClicked(evt);
            }
        });

        clearcatbtn.setBackground(new java.awt.Color(0, 153, 153));
        clearcatbtn.setFont(new java.awt.Font("Tahoma", 0, 20)); // NOI18N
        clearcatbtn.setForeground(new java.awt.Color(255, 255, 255));
        clearcatbtn.setText("Clear");
        clearcatbtn.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                clearcatbtnMouseClicked(evt);
            }
        });

        name3.setFont(new java.awt.Font("Tahoma", 0, 24)); // NOI18N
        name3.setForeground(new java.awt.Color(0, 153, 153));
        name3.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        name3.setText("Price (High to Low) :");

        search.setBackground(new java.awt.Color(0, 153, 153));
        search.setFont(new java.awt.Font("Tahoma", 0, 20)); // NOI18N
        search.setForeground(new java.awt.Color(255, 255, 255));
        search.setText("Search ");
        search.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                searchMouseClicked(evt);
            }
        });

        searchPriceField.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        searchPriceField.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        searchPriceField.setText("Enter the Product Name");
        searchPriceField.setToolTipText("Enter the Product Name");
        searchPriceField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                searchPriceFieldActionPerformed(evt);
            }
        });

        sortAZ.setBackground(new java.awt.Color(0, 153, 153));
        sortAZ.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
        sortAZ.setForeground(new java.awt.Color(255, 255, 255));
        sortAZ.setText("Category Name (A-Z)");
        sortAZ.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                sortAZMouseClicked(evt);
            }
        });
        sortAZ.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                sortAZActionPerformed(evt);
            }
        });

        sortZA.setBackground(new java.awt.Color(0, 153, 153));
        sortZA.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
        sortZA.setForeground(new java.awt.Color(255, 255, 255));
        sortZA.setText("Category Name (Z-A)");
        sortZA.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                sortZAMouseClicked(evt);
            }
        });
        sortZA.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                sortZAActionPerformed(evt);
            }
        });

        availcat.setBackground(new java.awt.Color(0, 153, 153));
        availcat.setFont(new java.awt.Font("Tahoma", 0, 20)); // NOI18N
        availcat.setForeground(new java.awt.Color(255, 255, 255));
        availcat.setText("Available Category");
        availcat.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                availcatMouseClicked(evt);
            }
        });
        availcat.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                availcatActionPerformed(evt);
            }
        });

        showAvailcat.setEditable(false);
        showAvailcat.setBackground(new java.awt.Color(255, 255, 255));
        showAvailcat.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        showAvailcat.setHorizontalAlignment(javax.swing.JTextField.CENTER);

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(31, 31, 31)
                .addComponent(availcat, javax.swing.GroupLayout.PREFERRED_SIZE, 232, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(showAvailcat, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(29, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(39, 39, 39)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(availcat, javax.swing.GroupLayout.DEFAULT_SIZE, 41, Short.MAX_VALUE)
                    .addComponent(showAvailcat))
                .addContainerGap(38, Short.MAX_VALUE))
        );

        searchField1.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        searchField1.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        searchField1.setText("Enter the Brand Name");
        searchField1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                searchField1ActionPerformed(evt);
            }
        });

        sortHL.setBackground(new java.awt.Color(0, 153, 153));
        sortHL.setFont(new java.awt.Font("Tahoma", 0, 20)); // NOI18N
        sortHL.setForeground(new java.awt.Color(255, 255, 255));
        sortHL.setText("Sort");
        sortHL.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                sortHLMouseClicked(evt);
            }
        });

        name.setFont(new java.awt.Font("Tahoma", 0, 24)); // NOI18N
        name.setForeground(new java.awt.Color(0, 153, 153));
        name.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        name.setText("Filters :");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel6, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addGap(47, 47, 47)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGap(117, 117, 117)
                        .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(57, 57, 57)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(name3)
                                .addGap(29, 29, 29)
                                .addComponent(searchPriceField, javax.swing.GroupLayout.PREFERRED_SIZE, 285, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(44, 44, 44)
                                .addComponent(sortHL, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(name, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(sortAZ)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(sortZA)))
                        .addGap(0, 220, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(addcatbtn, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(28, 28, 28)
                                .addComponent(delcatbtn)
                                .addGap(32, 32, 32)
                                .addComponent(upcatbtn)
                                .addGap(25, 25, 25)
                                .addComponent(recatbtn)
                                .addGap(34, 34, 34)
                                .addComponent(clearcatbtn, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(id, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(name2, javax.swing.GroupLayout.PREFERRED_SIZE, 135, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(4, 4, 4)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(cidField, javax.swing.GroupLayout.PREFERRED_SIZE, 145, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(cstatusField, javax.swing.GroupLayout.PREFERRED_SIZE, 145, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(18, 18, 18)
                                .addComponent(name1, javax.swing.GroupLayout.PREFERRED_SIZE, 135, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(10, 10, 10)
                                .addComponent(cnameField, javax.swing.GroupLayout.PREFERRED_SIZE, 146, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(83, 83, 83)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(search)
                                .addGap(18, 18, 18)
                                .addComponent(searchField1, javax.swing.GroupLayout.PREFERRED_SIZE, 299, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 520, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(43, 43, 43)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(3, 3, 3)
                                .addComponent(id)
                                .addGap(58, 58, 58)
                                .addComponent(name2, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(cidField, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(49, 49, 49)
                                .addComponent(cstatusField, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(name1, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(1, 1, 1)
                                .addComponent(cnameField, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(129, 129, 129))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 192, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(46, 46, 46)))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(addcatbtn, javax.swing.GroupLayout.PREFERRED_SIZE, 51, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(delcatbtn, javax.swing.GroupLayout.PREFERRED_SIZE, 51, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(upcatbtn, javax.swing.GroupLayout.PREFERRED_SIZE, 51, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(recatbtn, javax.swing.GroupLayout.PREFERRED_SIZE, 51, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(clearcatbtn, javax.swing.GroupLayout.PREFERRED_SIZE, 51, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(search, javax.swing.GroupLayout.PREFERRED_SIZE, 51, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(searchField1, javax.swing.GroupLayout.PREFERRED_SIZE, 51, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(93, 93, 93)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(179, 179, 179))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(name, javax.swing.GroupLayout.PREFERRED_SIZE, 46, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(sortZA, javax.swing.GroupLayout.PREFERRED_SIZE, 49, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(sortAZ, javax.swing.GroupLayout.PREFERRED_SIZE, 49, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(searchPriceField, javax.swing.GroupLayout.PREFERRED_SIZE, 51, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(sortHL, javax.swing.GroupLayout.PREFERRED_SIZE, 51, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(name3, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(150, 150, 150))))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void cnameFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cnameFieldActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_cnameFieldActionPerformed

    private void cidFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cidFieldActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_cidFieldActionPerformed

    private void dDTableMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_dDTableMouseClicked
        // TODO add your handling code here:
        // get the model from the jtable
        DefaultTableModel model = (DefaultTableModel)dDTable.getModel();

        // get the selected row index
        int selectedRowIndex = dDTable.getSelectedRow();

        // set the selected row data into jtextfields
//        bidField.setText(model.getValueAt(selectedRowIndex, 0).toString());
        //       cidField.setText(model.getValueAt(selectedRowIndex, 1).toString());
        //       bidField.setText(model.getValueAt(selectedRowIndex, 2).toString());
        cnameField.setText(model.getValueAt(selectedRowIndex, 1).toString());
        cidField.setText(model.getValueAt(selectedRowIndex, 0).toString());
                cstatusField.setText(model.getValueAt(selectedRowIndex, 2).toString());
        //        descriptionField.setText(model.getValueAt(selectedRowIndex, 4).toString());
    }//GEN-LAST:event_dDTableMouseClicked

    private void jLabel20MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel20MouseClicked

    }//GEN-LAST:event_jLabel20MouseClicked

    private void jLabel21MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel21MouseClicked

    }//GEN-LAST:event_jLabel21MouseClicked

    private void logoutMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_logoutMouseClicked
        Admin admin = new Admin();
        admin.setVisible(true);
        dispose();
    }//GEN-LAST:event_logoutMouseClicked

    private void backbtnMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_backbtnMouseClicked
        AdminActivity adActivity = new AdminActivity();
        adActivity.setVisible(true);
        dispose();
    }//GEN-LAST:event_backbtnMouseClicked

    private void cstatusFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cstatusFieldActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_cstatusFieldActionPerformed

    private void recatbtnMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_recatbtnMouseClicked
        // TODO add your handling code here:
     try {
            Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
            Connection connection = DriverManager.getConnection("jdbc:sqlserver://localhost:1433;databaseName=lab11;integratedSecurity=true");

            Statement statement = connection.createStatement();

            ResultSet rs = statement.executeQuery("SELECT category_id as CategoryId ,category_name as CategoryName , category_status CategoryStatus FROM category order by category_id");
            ResultSetMetaData  rsmetadata = rs.getMetaData();
            int  columns = rsmetadata.getColumnCount();
            DefaultTableModel dtm = new DefaultTableModel();
            Vector columns_name=new Vector();
            Vector data_rows=new Vector();
            for(int  i= 1; i < columns+1; i++)
            {
                columns_name.addElement (rsmetadata.getColumnLabel(i));
            }

            dtm.setColumnIdentifiers(columns_name);
            while (rs.next())
            {
                data_rows = new Vector();
                for (int j = 1; j <columns+1; j++)
                {
                    data_rows.addElement(rs.getString(j)) ;
                }
                dtm.addRow(data_rows);

            }
            dDTable.setModel(dtm);
            JOptionPane.showMessageDialog(null, "Refreshed");

        } catch (Exception e) {
            e.printStackTrace();
        }
    }//GEN-LAST:event_recatbtnMouseClicked

    private void upcatbtnMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_upcatbtnMouseClicked
        // TODO add your handling code here:
      String s1 = cnameField.getText();
        String s2 = cidField.getText();
        String s3 = cstatusField.getText();
        //        String s6 = quantityField.getText();
        //        String s8 = descriptionField.getText();
        //        String s7 = priceField.getText();

        try {
            Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
            Connection connection = DriverManager.getConnection("jdbc:sqlserver://localhost:1433;databaseName=lab11;integratedSecurity=true");

            Statement statement = connection.createStatement();

            statement.execute("Update category set category_id =" + s2 + ", category_name ="+" '"+ s1 +"' , category_status ="+" '"+ s3 +"'  where category_name ="+"'"+ s1+"'");

            JOptionPane.showMessageDialog(null, "Data Updated");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }//GEN-LAST:event_upcatbtnMouseClicked

    private void delcatbtnMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_delcatbtnMouseClicked
        // TODO add your handling code here:
           String s1= cnameField.getText();

        try {
            Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
            Connection connection = DriverManager.getConnection("jdbc:sqlserver://localhost:1433;databaseName=lab11;integratedSecurity=true");

            Statement statement = connection.createStatement();

            statement.execute(" delete from category "  + " where category_name = (  '"+s1+"')" );

            JOptionPane.showMessageDialog(null, "Category " + s1 + " has been deleted");
        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, "Category named " + s1 + " not found");
        }
    }//GEN-LAST:event_delcatbtnMouseClicked

    private void delcatbtnMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_delcatbtnMouseEntered
        // TODO add your handling code here:

    }//GEN-LAST:event_delcatbtnMouseEntered

    private void addcatbtnMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_addcatbtnMouseClicked
        // TODO add your handling code here:
       String s1= cidField.getText();
        String s2= cnameField.getText();
        String s3= cstatusField.getText();
        try {
            Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
            Connection connection = DriverManager.getConnection("jdbc:sqlserver://localhost:1433;databaseName=lab11;integratedSecurity=true");

            Statement statement = connection.createStatement();

            statement.execute(" insert into category "  + " values ( '"+s1+"', '"+s2+"', '"+s3+"')" );

            JOptionPane.showMessageDialog(null, " Saved");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }//GEN-LAST:event_addcatbtnMouseClicked

    private void clearcatbtnMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_clearcatbtnMouseClicked
        // TODO add your handling code here:
   cnameField.setText("");
        cidField.setText("");
        cstatusField.setText("");
        showAvailcat.setText("");
    }//GEN-LAST:event_clearcatbtnMouseClicked

    private void searchMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_searchMouseClicked
        // TODO add your handling code here:
        String s1= searchPriceField.getText();
        try {
            Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
            Connection connection = DriverManager.getConnection("jdbc:sqlserver://localhost:1433;databaseName=lab11;integratedSecurity=true");

            Statement statement = connection.createStatement();

            ResultSet rs = statement.executeQuery(" select * from category "  + " where category_name = (  '"+s1+"')");
            ResultSetMetaData  rsmetadata = rs.getMetaData();
            int  columns = rsmetadata.getColumnCount();
            DefaultTableModel dtm = new DefaultTableModel();
            Vector columns_name=new Vector();
            Vector data_rows=new Vector();
            for(int  i= 1; i < columns+1; i++)
            {
                columns_name.addElement (rsmetadata.getColumnLabel(i));
            }

            dtm.setColumnIdentifiers(columns_name);
            while (rs.next())
            {
                data_rows = new Vector();
                for (int j = 1; j <columns+1; j++)
                {
                    data_rows.addElement(rs.getString(j)) ;
                }
                dtm.addRow(data_rows);

            }
            dDTable.setModel(dtm);

        } catch (Exception e) {
            e.printStackTrace();
        }
    }//GEN-LAST:event_searchMouseClicked

    private void searchPriceFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_searchPriceFieldActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_searchPriceFieldActionPerformed

    private void sortAZMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_sortAZMouseClicked
        // TODO add your handling code here:
        try {
            Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
            Connection connection = DriverManager.getConnection("jdbc:sqlserver://localhost:1433;databaseName=lab11;integratedSecurity=true");

            Statement statement = connection.createStatement();

            ResultSet rs = statement.executeQuery(" select * from category  order by category_name ");
            ResultSetMetaData  rsmetadata = rs.getMetaData();
            int  columns = rsmetadata.getColumnCount();
            DefaultTableModel dtm = new DefaultTableModel();
            Vector columns_name=new Vector();
            Vector data_rows=new Vector();
            for(int  i= 1; i < columns+1; i++)
            {
                columns_name.addElement (rsmetadata.getColumnLabel(i));
            }

            dtm.setColumnIdentifiers(columns_name);
            while (rs.next())
            {
                data_rows = new Vector();
                for (int j = 1; j <columns+1; j++)
                {
                    data_rows.addElement(rs.getString(j)) ;
                }
                dtm.addRow(data_rows);

            }
            dDTable.setModel(dtm);

        } catch (Exception e) {
            e.printStackTrace();
        }
    }//GEN-LAST:event_sortAZMouseClicked

    private void sortAZActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_sortAZActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_sortAZActionPerformed

    private void sortZAMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_sortZAMouseClicked
        // TODO add your handling code here:
               try {
            Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
            Connection connection = DriverManager.getConnection("jdbc:sqlserver://localhost:1433;databaseName=lab11;integratedSecurity=true");

            Statement statement = connection.createStatement();

            ResultSet rs = statement.executeQuery(" select * from category order by category_name desc ");
            ResultSetMetaData  rsmetadata = rs.getMetaData();
            int  columns = rsmetadata.getColumnCount();
            DefaultTableModel dtm = new DefaultTableModel();
            Vector columns_name=new Vector();
            Vector data_rows=new Vector();
            for(int  i= 1; i < columns+1; i++)
            {
                columns_name.addElement (rsmetadata.getColumnLabel(i));
            }

            dtm.setColumnIdentifiers(columns_name);
            while (rs.next())
            {
                data_rows = new Vector();
                for (int j = 1; j <columns+1; j++)
                {
                    data_rows.addElement(rs.getString(j)) ;
                }
                dtm.addRow(data_rows);

            }
            dDTable.setModel(dtm);

        } catch (Exception e) {
            e.printStackTrace();
        }
    }//GEN-LAST:event_sortZAMouseClicked

    private void sortZAActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_sortZAActionPerformed
        // TODO add your handling code here:
 
    }//GEN-LAST:event_sortZAActionPerformed

    private void availcatMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_availcatMouseClicked
        // TODO add your handling code here:
        try {
            Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
            Connection connection = DriverManager.getConnection("jdbc:sqlserver://localhost:1433;databaseName=lab11;integratedSecurity=true");

            Statement statement = connection.createStatement();

            ResultSet rs = statement.executeQuery(" select * from category " + "where category_status = 'active' ");
            ResultSetMetaData  rsmetadata = rs.getMetaData();
            int  columns = rsmetadata.getColumnCount();
            DefaultTableModel dtm = new DefaultTableModel();
            Vector columns_name=new Vector();
            Vector data_rows=new Vector();
            for(int  i= 1; i < columns+1; i++)
            {
                columns_name.addElement (rsmetadata.getColumnLabel(i));
            }

            dtm.setColumnIdentifiers(columns_name);
            while (rs.next())
            {
                data_rows = new Vector();
                for (int j = 1; j <columns+1; j++)
                {
                    data_rows.addElement(rs.getString(j)) ;
                }
                dtm.addRow(data_rows);

            }
            dDTable.setModel(dtm);

        } catch (Exception e) {
            e.printStackTrace();
        }
    }//GEN-LAST:event_availcatMouseClicked

    private void availcatActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_availcatActionPerformed
        // TODO add your handling code here:
        try{
            //String sasdast = jComboBox1.getSelectedItem().toString();
            Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
            Connection connection = DriverManager.getConnection("jdbc:sqlserver://localhost:1433;databaseName=lab11;integratedSecurity=true");
            Statement st = connection.createStatement();
            ResultSet rs = st.executeQuery("select count(category_id) from category where  category_status = 'active'");
            if (rs.next()) {
                showAvailcat.setText(rs.getString(1));
            }
        }
        catch (Exception e) {
            e.printStackTrace();
        }
    }//GEN-LAST:event_availcatActionPerformed

    private void searchField1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_searchField1ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_searchField1ActionPerformed

    private void sortHLMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_sortHLMouseClicked
        // TODO add your handling code here:
        String s1= searchPriceField.getText();
        try {
            Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
            Connection connection = DriverManager.getConnection("jdbc:sqlserver://localhost:1433;databaseName=lab11;integratedSecurity=true");

            Statement statement = connection.createStatement();

            ResultSet rs = statement.executeQuery("   select c.category_name,p.product_name,p.product_price\n" +
" \n" +
"  from product p\n" +
"  inner join category c\n" +
"  on c.category_id=p.category_id\n" +
"  \n" +
"  where p.product_name='"+s1+"'\n" +
"  \n" +
"  group by c.category_name,p.product_name,p.product_price\n" +
"  order by p.product_price desc  ");
            ResultSetMetaData rsmetadata = rs.getMetaData();
            int columns = rsmetadata.getColumnCount();
            DefaultTableModel dtm = new DefaultTableModel();
            Vector columns_name = new Vector();
            Vector data_rows = new Vector();
            for (int i = 1; i < columns + 1; i++) {
                columns_name.addElement(rsmetadata.getColumnLabel(i));
            }

            dtm.setColumnIdentifiers(columns_name);
            while (rs.next()) {
                data_rows = new Vector();
                for (int j = 1; j < columns + 1; j++) {
                    data_rows.addElement(rs.getString(j));
                }
                dtm.addRow(data_rows);

            }
            dDTable.setModel(dtm);

        } catch (Exception e) {
            e.printStackTrace();
        }
    }//GEN-LAST:event_sortHLMouseClicked

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(category.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(category.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(category.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(category.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new category().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel add_product;
    private javax.swing.JButton addcatbtn;
    private javax.swing.JButton availcat;
    private javax.swing.JLabel backbtn;
    private javax.swing.JTextField cidField;
    private javax.swing.JButton clearcatbtn;
    private javax.swing.JTextField cnameField;
    private javax.swing.JTextField cstatusField;
    private javax.swing.JTable dDTable;
    private javax.swing.JButton delcatbtn;
    private javax.swing.JLabel id;
    private javax.swing.JDialog jDialog1;
    private javax.swing.JDialog jDialog2;
    private javax.swing.JLabel jLabel20;
    private javax.swing.JLabel jLabel21;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel logout;
    private javax.swing.JLabel name;
    private javax.swing.JLabel name1;
    private javax.swing.JLabel name2;
    private javax.swing.JLabel name3;
    private javax.swing.JButton recatbtn;
    private javax.swing.JButton search;
    private javax.swing.JTextField searchField1;
    private javax.swing.JTextField searchPriceField;
    private javax.swing.JTextField showAvailcat;
    private javax.swing.JButton sortAZ;
    private javax.swing.JButton sortHL;
    private javax.swing.JButton sortZA;
    private javax.swing.JButton upcatbtn;
    // End of variables declaration//GEN-END:variables
}
