text: /*
   * To change this template, choose Tools | Templates
   * and open the template in the editor.
   */
  
  /*
   * DlgPenyakit.java
   *
   * Created on May 23, 2010, 12:57:16 AM
   */
  
  package khanzaantrianpoli;
  
  import fungsi.WarnaTable;
  import fungsi.batasInput;
  import fungsi.koneksiDB;
  import fungsi.sekuel;
  import fungsi.validasi;
  import fungsi.var;
  import java.awt.Cursor;
  import java.awt.Dimension;
  import java.awt.event.KeyEvent;
  import java.sql.Connection;
  import java.sql.PreparedStatement;
  import java.sql.ResultSet;
  import java.sql.SQLException;
  import javax.swing.JTable;
  import javax.swing.event.DocumentEvent;
  import javax.swing.table.DefaultTableModel;
  import javax.swing.table.TableColumn;
  
  /**
   *
   * @author dosen
   */
  public final class DlgCariPoli extends javax.swing.JDialog {
      private final DefaultTableModel tabMode;
      private sekuel Sequel=new sekuel();
      private validasi Valid=new validasi();
      private Connection koneksi=koneksiDB.condb();
      private PreparedStatement ps;
      private ResultSet rs;
      /** Creates new form DlgPenyakit
       * @param parent
       * @param modal */
      public DlgCariPoli(java.awt.Frame parent, boolean modal) {
          super(parent, modal);
          initComponents();
          this.setLocation(10,2);
          setSize(656,250);
  
          Object[] row={"Kode Unit","Nama Unit","Biaya Registrasi"};
          tabMode=new DefaultTableModel(null,row){
                @Override public boolean isCellEditable(int rowIndex, int colIndex){return false;}
          };
          tbKamar.setModel(tabMode);
          //tbPenyakit.setDefaultRenderer(Object.class, new WarnaTable(panelJudul.getBackground(),tbPenyakit.getBackground()));
          tbKamar.setPreferredScrollableViewportSize(new Dimension(500,500));
          tbKamar.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
  
          for (int i = 0; i < 3; i++) {
              TableColumn column = tbKamar.getColumnModel().getColumn(i);
              if(i==0){
                  column.setPreferredWidth(100);
              }else if(i==1){
                  column.setPreferredWidth(300);
              }else if(i==2){
                  column.setPreferredWidth(250);
              }
          }
          tbKamar.setDefaultRenderer(Object.class, new WarnaTable());
          TCari.setDocument(new batasInput((byte)100).getKata(TCari));
          TCari.getDocument().addDocumentListener(new javax.swing.event.DocumentListener(){
  
              @Override
              public void insertUpdate(DocumentEvent e) {
                  tampil();
              }
  
              @Override
              public void removeUpdate(DocumentEvent e) {
                  tampil();
              }
  
              @Override
              public void changedUpdate(DocumentEvent e) {
                  tampil();
              }
  
          });
          
          try {
              ps=koneksi.prepareStatement("select kd_poli, nm_poli, registrasi "+
                  " from poliklinik where kd_poli<>'IGDK' and kd_poli like ? or "+
                  " kd_poli<>'IGDK' and nm_poli like ? or "+
                  " kd_poli<>'IGDK' and registrasi like ? order by nm_poli");
          } catch (Exception e) {
          }
      }
  
      /** 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() {
  
          internalFrame1 = new widget.InternalFrame();
          Scroll = new widget.ScrollPane();
          tbKamar = new widget.Table();
          panelisi3 = new widget.panelisi();
          label9 = new widget.Label();
          TCari = new widget.TextBox();
          BtnCari = new widget.Button();
          BtnAll = new widget.Button();
          label10 = new widget.Label();
          LCount = new widget.Label();
          BtnKeluar = new widget.Button();
  
          setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
          setUndecorated(true);
          setResizable(false);
          addWindowListener(new java.awt.event.WindowAdapter() {
              public void windowActivated(java.awt.event.WindowEvent evt) {
                  formWindowActivated(evt);
              }
              public void windowOpened(java.awt.event.WindowEvent evt) {
                  formWindowOpened(evt);
              }
          });
  
          internalFrame1.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(240, 245, 235)), "::[ Unit/Poliklinik ]::", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 11), new java.awt.Color(50, 70, 40))); // NOI18N
          internalFrame1.setName("internalFrame1"); // NOI18N
          internalFrame1.setLayout(new java.awt.BorderLayout(1, 1));
  
          Scroll.setName("Scroll"); // NOI18N
          Scroll.setOpaque(true);
  
          tbKamar.setAutoCreateRowSorter(true);
          tbKamar.setToolTipText("Silahkan klik untuk memilih data yang mau diedit ataupun dihapus");
          tbKamar.setName("tbKamar"); // NOI18N
          tbKamar.addMouseListener(new java.awt.event.MouseAdapter() {
              public void mouseClicked(java.awt.event.MouseEvent evt) {
                  tbKamarMouseClicked(evt);
              }
          });
          tbKamar.addKeyListener(new java.awt.event.KeyAdapter() {
              public void keyPressed(java.awt.event.KeyEvent evt) {
                  tbKamarKeyPressed(evt);
              }
          });
          Scroll.setViewportView(tbKamar);
  
          internalFrame1.add(Scroll, java.awt.BorderLayout.CENTER);
  
          panelisi3.setName("panelisi3"); // NOI18N
          panelisi3.setPreferredSize(new java.awt.Dimension(100, 43));
          panelisi3.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT, 4, 9));
  
          label9.setText("Key Word :");
          label9.setName("label9"); // NOI18N
          label9.setPreferredSize(new java.awt.Dimension(68, 23));
          panelisi3.add(label9);
  
          TCari.setName("TCari"); // NOI18N
          TCari.setPreferredSize(new java.awt.Dimension(312, 23));
          TCari.addKeyListener(new java.awt.event.KeyAdapter() {
              public void keyPressed(java.awt.event.KeyEvent evt) {
                  TCariKeyPressed(evt);
              }
          });
          panelisi3.add(TCari);
  
          BtnCari.setIcon(new javax.swing.ImageIcon(getClass().getResource("/picture/accept.png"))); // NOI18N
          BtnCari.setMnemonic('1');
          BtnCari.setToolTipText("Alt+1");
          BtnCari.setName("BtnCari"); // NOI18N
          BtnCari.setPreferredSize(new java.awt.Dimension(28, 23));
          BtnCari.addActionListener(new java.awt.event.ActionListener() {
              public void actionPerformed(java.awt.event.ActionEvent evt) {
                  BtnCariActionPerformed(evt);
              }
          });
          BtnCari.addKeyListener(new java.awt.event.KeyAdapter() {
              public void keyPressed(java.awt.event.KeyEvent evt) {
                  BtnCariKeyPressed(evt);
              }
          });
          panelisi3.add(BtnCari);
  
          BtnAll.setIcon(new javax.swing.ImageIcon(getClass().getResource("/picture/Search-16x16.png"))); // NOI18N
          BtnAll.setMnemonic('2');
          BtnAll.setToolTipText("2Alt+2");
          BtnAll.setName("BtnAll"); // NOI18N
          BtnAll.setPreferredSize(new java.awt.Dimension(28, 23));
          BtnAll.addActionListener(new java.awt.event.ActionListener() {
              public void actionPerformed(java.awt.event.ActionEvent evt) {
                  BtnAllActionPerformed(evt);
              }
          });
          BtnAll.addKeyListener(new java.awt.event.KeyAdapter() {
              public void keyPressed(java.awt.event.KeyEvent evt) {
                  BtnAllKeyPressed(evt);
              }
          });
          panelisi3.add(BtnAll);
  
          label10.setText("Record :");
          label10.setName("label10"); // NOI18N
          label10.setPreferredSize(new java.awt.Dimension(60, 23));
          panelisi3.add(label10);
  
          LCount.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
          LCount.setText("0");
          LCount.setName("LCount"); // NOI18N
          LCount.setPreferredSize(new java.awt.Dimension(50, 23));
          panelisi3.add(LCount);
  
          BtnKeluar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/picture/exit.png"))); // NOI18N
          BtnKeluar.setMnemonic('4');
          BtnKeluar.setToolTipText("Alt+4");
          BtnKeluar.setName("BtnKeluar"); // NOI18N
          BtnKeluar.setPreferredSize(new java.awt.Dimension(28, 23));
          BtnKeluar.addActionListener(new java.awt.event.ActionListener() {
              public void actionPerformed(java.awt.event.ActionEvent evt) {
                  BtnKeluarActionPerformed(evt);
              }
          });
          panelisi3.add(BtnKeluar);
  
          internalFrame1.add(panelisi3, java.awt.BorderLayout.PAGE_END);
  
          getContentPane().add(internalFrame1, java.awt.BorderLayout.CENTER);
  
          pack();
      }// </editor-fold>//GEN-END:initComponents
  
  
      private void TCariKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_TCariKeyPressed
          if(evt.getKeyCode()==KeyEvent.VK_ENTER){
              BtnCariActionPerformed(null);
          }else if(evt.getKeyCode()==KeyEvent.VK_PAGE_DOWN){
              BtnCari.requestFocus();
          }else if(evt.getKeyCode()==KeyEvent.VK_PAGE_UP){
              BtnKeluar.requestFocus();
          }else if(evt.getKeyCode()==KeyEvent.VK_UP){
              tbKamar.requestFocus();
          }
  }//GEN-LAST:event_TCariKeyPressed
  
      private void BtnCariActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BtnCariActionPerformed
          tampil();
  }//GEN-LAST:event_BtnCariActionPerformed
  
      private void BtnCariKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_BtnCariKeyPressed
          if(evt.getKeyCode()==KeyEvent.VK_SPACE){
              BtnCariActionPerformed(null);
          }else{
              Valid.pindah(evt, TCari, BtnAll);
          }
  }//GEN-LAST:event_BtnCariKeyPressed
  
      private void BtnAllActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BtnAllActionPerformed
          TCari.setText("");
          tampil();
  }//GEN-LAST:event_BtnAllActionPerformed
  
      private void BtnAllKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_BtnAllKeyPressed
          if(evt.getKeyCode()==KeyEvent.VK_SPACE){
              BtnAllActionPerformed(null);
          }else{
              Valid.pindah(evt, BtnCari, TCari);
          }
  }//GEN-LAST:event_BtnAllKeyPressed
  
      private void tbKamarMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tbKamarMouseClicked
          if(tabMode.getRowCount()!=0){
              if(evt.getClickCount()==2){
                  dispose();
              }
          }
  }//GEN-LAST:event_tbKamarMouseClicked
  
      private void BtnKeluarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BtnKeluarActionPerformed
          dispose();
      }//GEN-LAST:event_BtnKeluarActionPerformed
  
      private void tbKamarKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tbKamarKeyPressed
          if(tabMode.getRowCount()!=0){
              if(evt.getKeyCode()==KeyEvent.VK_SPACE){
                  dispose();
              }else if(evt.getKeyCode()==KeyEvent.VK_SHIFT){
                  TCari.setText("");
                  TCari.requestFocus();
              }
          }
      }//GEN-LAST:event_tbKamarKeyPressed
  
      private void formWindowActivated(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowActivated
          emptTeks();
      }//GEN-LAST:event_formWindowActivated
  
      private void formWindowOpened(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowOpened
          tampil();
      }//GEN-LAST:event_formWindowOpened
  
      /**
      * @param args the command line arguments
      */
      public static void main(String args[]) {
          java.awt.EventQueue.invokeLater(() -> {
              DlgCariPoli dialog = new DlgCariPoli(new javax.swing.JFrame(), true);
              dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                  @Override
                  public void windowClosing(java.awt.event.WindowEvent e) {
                      System.exit(0);
                  }
              });
              dialog.setVisible(true);
          });
      }
  
      // Variables declaration - do not modify//GEN-BEGIN:variables
      private widget.Button BtnAll;
      private widget.Button BtnCari;
      private widget.Button BtnKeluar;
      private widget.Label LCount;
      private widget.ScrollPane Scroll;
      private widget.TextBox TCari;
      private widget.InternalFrame internalFrame1;
      private widget.Label label10;
      private widget.Label label9;
      private widget.panelisi panelisi3;
      private widget.Table tbKamar;
      // End of variables declaration//GEN-END:variables
  
      private void tampil() {
          Valid.tabelKosong(tabMode);
          try{            
              ps.setString(1,"%"+TCari.getText().trim()+"%");
              ps.setString(2,"%"+TCari.getText().trim()+"%");
              ps.setString(3,"%"+TCari.getText().trim()+"%");
              rs=ps.executeQuery();
              while(rs.next()){
                  tabMode.addRow(new Object[]{rs.getString(1),rs.getString(2),Valid.SetAngka(rs.getDouble(3))});
              }
          }catch(SQLException e){
              System.out.println("Error : "+e);
          }
          LCount.setText(""+tabMode.getRowCount());
      }
  
      public void emptTeks() {   
          TCari.requestFocus();
      }
    
      public JTable getTable(){
          return tbKamar;
      }
      
      
  }
  