Package gui

Source Code of gui.PSAKullaniciTakipEkrani

package gui;

import hibernateSwingApi.component.CComboBox;
import hibernateSwingApi.component.TablePanel;
import hibernateSwingApi.hibernate.HibernateManager;

import java.awt.Color;
import java.awt.Font;
import java.awt.SystemColor;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTable;
import javax.swing.WindowConstants;
import javax.swing.border.EmptyBorder;
import javax.swing.border.LineBorder;

import org.hibernate.Query;
import org.hibernate.Session;

import pojos.Kullanici;
import pojos.KullaniciTakip;
import service.PSAUtil;

import com.toedter.calendar.JDateChooser;
import com.toedter.calendar.JTextFieldDateEditor;

public class PSAKullaniciTakipEkrani extends JFrame {

  private static final long serialVersionUID = 1L;
  private static PSAKullaniciTakipEkrani instance;
  private JPanel contentPane;
  private JPanel jPanelFiltre;
  private JDateChooser jDateChooserIlkTarih;
  private JDateChooser jDateChooserSonTarih;
  private JLabel jLabelIle;
  private JLabel jLabelTarihBilgi;
  private TablePanel cTablePanelKullaniciBilgi;
  private JButton jButtonGeri;
  private List<KullaniciTakip> kullaniciTakipListesi;
  private CComboBox<Kullanici> cComboBoxKullanici;
  private JLabel jLabelKullaniciBilgi;

  public static PSAKullaniciTakipEkrani getInstance() {
    instance = new PSAKullaniciTakipEkrani();
    return instance;
  }

  public PSAKullaniciTakipEkrani() {
    initialize();
  }

  public void initialize() {
    setTitle("PSA MERKEZ KULLANICI TAKİP");
    setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    setBounds(0, 0, 507, 519);
    setResizable(false);
    setIconImage(PSAUtil.getImageIconViaRelativePath("picture/psaIcon.png")
        .getImage());

    contentPane = new JPanel();
    contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
    setContentPane(contentPane);
    contentPane.setLayout(null);

    jPanelFiltre = new JPanel();
    jPanelFiltre.setLayout(null);
    jPanelFiltre.setBackground(SystemColor.controlShadow);
    jPanelFiltre.setBounds(10, 11, 468, 66);
    contentPane.add(jPanelFiltre);

    jDateChooserIlkTarih = new JDateChooser(new Date());
    jDateChooserIlkTarih.setBounds(201, 39, 110, 20);
    jPanelFiltre.add(jDateChooserIlkTarih);

    jDateChooserSonTarih = new JDateChooser(new Date());
    jDateChooserSonTarih.setBounds(348, 39, 110, 20);
    jPanelFiltre.add(jDateChooserSonTarih);

    ((JTextFieldDateEditor) jDateChooserIlkTarih.getDateEditor())
        .setEditable(false);
    ((JTextFieldDateEditor) jDateChooserIlkTarih.getDateEditor())
        .setFocusable(false);
    ((JTextFieldDateEditor) jDateChooserSonTarih.getDateEditor())
        .setEditable(false);
    ((JTextFieldDateEditor) jDateChooserSonTarih.getDateEditor())
        .setFocusable(false);

    jLabelIle = new JLabel();
    jLabelIle.setText("ile");
    jLabelIle.setFont(new Font("Tahoma", Font.BOLD, 15));
    jLabelIle.setBounds(321, 39, 24, 20);
    jPanelFiltre.add(jLabelIle);

    jLabelTarihBilgi = new JLabel();
    jLabelTarihBilgi.setText("Tarih aralığı seçiniz :");
    jLabelTarihBilgi.setFont(new Font("Tahoma", Font.BOLD, 14));
    jLabelTarihBilgi.setBounds(201, 11, 257, 20);
    jPanelFiltre.add(jLabelTarihBilgi);

    cComboBoxKullanici = new CComboBox<Kullanici>(Kullanici.class);
    cComboBoxKullanici.setBounds(10, 39, 181, 20);
    jPanelFiltre.add(cComboBoxKullanici);

    jLabelKullaniciBilgi = new JLabel();
    jLabelKullaniciBilgi.setText("Kullanıcı seçiniz :");
    jLabelKullaniciBilgi.setFont(new Font("Tahoma", Font.BOLD, 14));
    jLabelKullaniciBilgi.setBounds(10, 11, 147, 20);
    jPanelFiltre.add(jLabelKullaniciBilgi);

    cTablePanelKullaniciBilgi = new TablePanel((String) null,
        KullaniciTakip.class, true, true);
    cTablePanelKullaniciBilgi.getTable().setAutoResizeMode(
        JTable.AUTO_RESIZE_ALL_COLUMNS);
    cTablePanelKullaniciBilgi.setBorder(new LineBorder(new Color(0, 0, 0),
        2));
    cTablePanelKullaniciBilgi.setBounds(10, 88, 468, 335);
    contentPane.add(cTablePanelKullaniciBilgi);

    jButtonGeri = new JButton();
    jButtonGeri.setIcon(PSAUtil
        .getImageIconViaRelativePath("picture/geriButonu.png"));
    jButtonGeri.setText("GERİ DÖN");
    jButtonGeri.setFont(new Font("Tahoma", Font.BOLD, 15));
    jButtonGeri.setBounds(123, 434, 233, 41);
    contentPane.add(jButtonGeri);

    initListener();
    refreshComponent();
    dateControl();
  }

  private void refreshComponent() {
    Kullanici kul = new Kullanici();
    kul.setKullaniciAdi("TÜMÜ");
    cComboBoxKullanici.setInitialObject(kul);
    cComboBoxKullanici.refresh();
  }

  private void initListener() {

    addWindowListener(new WindowAdapter() {
      @Override
      public void windowClosing(WindowEvent e) {
        anaEkranSetEnabled();
      }
    });

    jDateChooserIlkTarih.getDateEditor().addPropertyChangeListener(
        new PropertyChangeListener() {
          @Override
          public void propertyChange(PropertyChangeEvent evt) {
            if (evt.getPropertyName().equals("date")) {
              dateControl();
            }
          }
        });

    jDateChooserSonTarih.getDateEditor().addPropertyChangeListener(
        new PropertyChangeListener() {
          @Override
          public void propertyChange(PropertyChangeEvent evt) {
            if (evt.getPropertyName().equals("date")) {
              dateControl();
            }
          }
        });

    jButtonGeri.addActionListener(new ActionListener() {
      @Override
      public void actionPerformed(ActionEvent arg0) {
        anaEkranSetEnabled();
      }
    });

    cComboBoxKullanici.addItemListener(new ItemListener() {
      @Override
      public void itemStateChanged(ItemEvent e) {
        if (e.getStateChange() == ItemEvent.DESELECTED) {
          return;
        }
        dateControl();
      }
    });
  }

  protected void anaEkranSetEnabled() {
    PSAAnaEkran.getInstance(null).setEnabled(true);
    instance.dispose();
  }

  @SuppressWarnings("unchecked")
  protected void dateControl() {
    cTablePanelKullaniciBilgi.getTable().clearSelection();
    kullaniciTakipListesi = (List<KullaniciTakip>) girisCikisHqlQuery(
        cComboBoxKullanici.getSelectedItem().toString(),
        jDateChooserIlkTarih.getDate(), jDateChooserSonTarih.getDate());
    cTablePanelKullaniciBilgi.setObjects(kullaniciTakipListesi);
  }

  private static List<?> girisCikisHqlQuery(String kullaniciAdi, Date from,
      Date to) {
    Calendar cal = Calendar.getInstance();
    cal.setTime(from);
    cal.set(Calendar.HOUR_OF_DAY, 0);
    cal.set(Calendar.MINUTE, 0);
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);
    from = cal.getTime();

    cal.setTime(to);
    cal.set(Calendar.HOUR_OF_DAY, 23);
    cal.set(Calendar.MINUTE, 59);
    cal.set(Calendar.SECOND, 59);
    cal.set(Calendar.MILLISECOND, 99);
    to = cal.getTime();

    Session openSession = HibernateManager.getInstance().openSession();
    openSession.beginTransaction();
    StringBuilder sBuilder = new StringBuilder();

    sBuilder.append("from KullaniciTakip where ");
    if (!kullaniciAdi.equals("TÜMÜ")) {
      sBuilder.append("kullaniciAdi ='").append(kullaniciAdi)
          .append("' and ");
    }
    sBuilder.append("girisSaat >= ").append(":from");
    sBuilder.append(" and girisSaat <= ").append(":to");
    sBuilder.append(" and cikisSaat >= ").append(":from");
    sBuilder.append(" and cikisSaat <= ").append(":to");
    sBuilder.append(" and systemName = '").append(
        HibernateManager.getInstance().getSystemName() + "'");

    String hql = sBuilder.toString();
    Query createQuery = openSession.createQuery(hql);
    createQuery.setParameter("from", from);
    createQuery.setParameter("to", to);

    List<?> list = createQuery.list();
    openSession.close();

    return list;
  }
}
TOP

Related Classes of gui.PSAKullaniciTakipEkrani

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.