package service;
import hibernateSwingApi.component.CTextField;
import hibernateSwingApi.hibernate.HibernateManager;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Frame;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingConstants;
import javax.swing.UIManager;
import satis.pojos.BekleyenSatis;
public class SatisBilgi extends JDialog {
private static final long serialVersionUID = 1L;
private JPanel jPanelSatisKodBilgi;
private JLabel jLabelSatisKoduBilgi;
private CTextField cTextFieldBarkod;
private JButton jButtonSatisBeklet;
private JButton jButtonIptal;
private String satisKod = null;
public SatisBilgi(Frame owner) {
super(owner, true);
setSize(470, 300);
locateFrameToMiddle();
setResizable(false);
setModal(false);
setModalityType(ModalityType.DOCUMENT_MODAL);
setTitle("PSA SATIŞ BİLGİ EKRANI");
setIconImage(PSAUtil.getImageIconViaRelativePath("picture/psaIcon.png")
.getImage());
jPanelSatisKodBilgi = new JPanel();
jPanelSatisKodBilgi.setBackground(UIManager.getColor("Button.shadow"));
GroupLayout groupLayout = new GroupLayout(getContentPane());
groupLayout.setHorizontalGroup(groupLayout.createParallelGroup(
Alignment.LEADING).addGroup(
groupLayout
.createSequentialGroup()
.addContainerGap()
.addComponent(jPanelSatisKodBilgi,
GroupLayout.DEFAULT_SIZE, 589, Short.MAX_VALUE)
.addContainerGap()));
groupLayout.setVerticalGroup(groupLayout.createParallelGroup(
Alignment.LEADING).addGroup(
groupLayout
.createSequentialGroup()
.addContainerGap()
.addComponent(jPanelSatisKodBilgi,
GroupLayout.DEFAULT_SIZE, 92, Short.MAX_VALUE)
.addGap(10)));
jLabelSatisKoduBilgi = new JLabel();
jLabelSatisKoduBilgi
.setText("Beklemeye alınacak satışın satis kodu : ");
jLabelSatisKoduBilgi.setFont(new Font("Tahoma", Font.BOLD, 14));
cTextFieldBarkod = new CTextField(11);
cTextFieldBarkod.setHorizontalAlignment(SwingConstants.CENTER);
cTextFieldBarkod.setFont(new Font("Tahoma", Font.PLAIN, 13));
jButtonSatisBeklet = new JButton();
jButtonSatisBeklet.setText("SATIŞ BEKLET");
jButtonSatisBeklet.setIcon(PSAUtil
.getImageIconViaRelativePath("picture/satisBeklet.png"));
jButtonSatisBeklet.setFont(new Font("Tahoma", Font.BOLD, 15));
jButtonIptal = new JButton();
jButtonIptal.setText("İPTAL");
jButtonIptal.setIcon(PSAUtil
.getImageIconViaRelativePath("picture/geriButonu.png"));
jButtonIptal.setFont(new Font("Tahoma", Font.BOLD, 15));
GroupLayout gl_jPanelSatisKodBilgi = new GroupLayout(
jPanelSatisKodBilgi);
gl_jPanelSatisKodBilgi
.setHorizontalGroup(gl_jPanelSatisKodBilgi
.createParallelGroup(Alignment.LEADING)
.addGroup(
gl_jPanelSatisKodBilgi
.createSequentialGroup()
.addGap(79)
.addGroup(
gl_jPanelSatisKodBilgi
.createParallelGroup(
Alignment.LEADING)
.addGroup(
gl_jPanelSatisKodBilgi
.createSequentialGroup()
.addComponent(
jLabelSatisKoduBilgi,
GroupLayout.DEFAULT_SIZE,
276,
Short.MAX_VALUE)
.addGap(10)
.addComponent(
cTextFieldBarkod,
GroupLayout.DEFAULT_SIZE,
141,
Short.MAX_VALUE))
.addGroup(
gl_jPanelSatisKodBilgi
.createSequentialGroup()
.addComponent(
jButtonIptal,
GroupLayout.DEFAULT_SIZE,
200,
Short.MAX_VALUE)
.addGap(27)
.addComponent(
jButtonSatisBeklet,
GroupLayout.DEFAULT_SIZE,
200,
Short.MAX_VALUE)))
.addGap(83)));
gl_jPanelSatisKodBilgi
.setVerticalGroup(gl_jPanelSatisKodBilgi
.createParallelGroup(Alignment.LEADING)
.addGroup(
gl_jPanelSatisKodBilgi
.createSequentialGroup()
.addGap(11)
.addGroup(
gl_jPanelSatisKodBilgi
.createParallelGroup(
Alignment.LEADING)
.addGroup(
gl_jPanelSatisKodBilgi
.createSequentialGroup()
.addComponent(
jLabelSatisKoduBilgi,
GroupLayout.DEFAULT_SIZE,
20,
Short.MAX_VALUE)
.addGap(1))
.addGroup(
gl_jPanelSatisKodBilgi
.createSequentialGroup()
.addGap(1)
.addComponent(
cTextFieldBarkod,
GroupLayout.PREFERRED_SIZE,
20,
Short.MAX_VALUE)))
.addGap(10)
.addGroup(
gl_jPanelSatisKodBilgi
.createParallelGroup(
Alignment.LEADING)
.addComponent(
jButtonIptal,
GroupLayout.DEFAULT_SIZE,
GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE)
.addComponent(
jButtonSatisBeklet,
GroupLayout.PREFERRED_SIZE,
40,
GroupLayout.PREFERRED_SIZE))
.addGap(9)));
jPanelSatisKodBilgi.setLayout(gl_jPanelSatisKodBilgi);
getContentPane().setLayout(groupLayout);
initListener();
pack();
}
private void locateFrameToMiddle() {
Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
int w = this.getSize().width;
int h = this.getSize().height;
int x = (dim.width - w) / 2;
int y = (dim.height - h) / 2;
setLocation(x, y);
}
private void initListener() {
addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
closeFrame();
}
});
cTextFieldBarkod.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent event) {
if (event.getKeyCode() == KeyEvent.VK_ENTER) {
satisBekletClicked();
}
}
});
jButtonSatisBeklet.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
satisBekletClicked();
}
});
jButtonIptal.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
closeFrame();
}
});
}
protected void closeFrame() {
satisKod = null;
dispose();
}
protected void satisBekletClicked() {
if (cTextFieldBarkod.getText().trim().equals("")) {
AutoClosingMessageDialog.showAutoClosingMessageDialog(
"Satış bekletme kodunu giriniz.", 2);
return;
}
BekleyenSatis bs = (BekleyenSatis) HibernateManager.getInstance()
.getObjectWithUniqueColumn(BekleyenSatis.class, "satisKod",
cTextFieldBarkod.getText());
if (bs != null) {
AutoClosingMessageDialog.showAutoClosingMessageDialog(
"Satış kodunuz sistemde bulunmakta tekrar giriniz.", 2);
return;
}
satisKod = cTextFieldBarkod.getText().toUpperCase();
dispose();
}
public String showDialog() {
setVisible(true);
return satisKod;
}
}