📄 jfrmtpv.java
字号:
// Tina POS is a point of sales application designed for touch screens.
// Copyright (C) 2005 Adrian Romero Corchado.
// http://sourceforge.net/projects/tinapos
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
package net.adrianromero.tpv.forms;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.awt.event.*;
import java.rmi.RemoteException;
import java.util.Date;
import java.util.LinkedList;
import java.util.Properties;
import javax.swing.*;
import javax.imageio.ImageIO;
import net.adrianromero.tpv.printer.*;
import net.adrianromero.beans.*;
import net.adrianromero.tpv.util.ThumbNailBuilder;
import net.adrianromero.basic.BasicException;
import net.adrianromero.data.loader.BatchSentence;
import net.adrianromero.data.gui.MessageInf;
import net.adrianromero.data.gui.JMessageDialog;
import net.adrianromero.data.loader.Session;
import net.adrianromero.instance.InstanceManager;
import net.adrianromero.instance.InstanceQuery;
import net.adrianromero.instance.TinaMessage;
import net.adrianromero.tpv.data.DataLogic;
import net.adrianromero.tpv.data.DataLogicException;
import net.adrianromero.tpv.data.DataLogicProvider;
import net.adrianromero.tpv.scale.DeviceScale;
import net.adrianromero.tpv.scanpal2.DeviceScanner;
import net.adrianromero.tpv.scanpal2.DeviceScannerFactory;
public class JFrmTPV extends JFrame implements AppView, TinaMessage {
private AppViewConnection m_appcnt;
private DataLogicProvider m_dataprovider;
private Properties m_propsdb = null;
private Integer m_iActiveCashIndex;
private Date m_dActiveCashDateStart;
private Date m_dActiveCashDateEnd;
private Integer m_iInventoryLocation;
private DeviceScale m_Scale;
private DeviceScanner m_Scanner;
private DeviceTicket m_TP;
private TicketParser m_TTP;
// private JPrincipalApp m_principalapp = null;
private LinkedList m_principalset = new LinkedList();
// Gestor de que haya solo una instancia corriendo de Tina en cada maquina.
private InstanceManager m_instmanager = null;
/** Creates new form JFrmTPV */
private JFrmTPV() {
}
/** Arrancamos la aplicacion de TPV */
private boolean startTPV() {
/////////////////////////////////////////////////////////////////////////////////////////
// vemos si existe alguna instancia
InstanceQuery i = null;
try {
i = new InstanceQuery();
// se ha podido crear, entonces existe una instancia ya de Tina POS corriendo
i.getTinaMessage().restoreWindow(); // la mandamos restaurarse.
return false;
} catch (Exception e) {
// no se ha podido crear, yo soy la primera instancia, entonces sigo.
}
// Creo el instance manager ya que la instancia que corre voy a ser yo
try {
m_instmanager = new InstanceManager(this);
} catch (Exception e) {
// No se ha podido instanciar, bueno no importa.
}
/////////////////////////////////////////////////////////////////////////////////////////
// Inicializo los componentes visuales
initComponents ();
jScrollPane1.getVerticalScrollBar().setPreferredSize(new Dimension(35, 35));
// Los eventos de los elementos que existen
/////////////////////////////////////////////////////////////////////////////////////////
// Inicializo la conectividad
try {
m_appcnt = new AppViewConnection();
} catch (BasicException e) {
JMessageDialog.showMessage(this, new MessageInf(MessageInf.SGN_DANGER, e.getMessage(), e));
return false;
}
// Inicializo el dataLogic Provider
try {
m_dataprovider = new DataLogicProvider(m_appcnt.getSession());
} catch (DataLogicException e) {
JMessageDialog.showMessage(this, new MessageInf(MessageInf.SGN_DANGER, e.getMessage(), e));
return false;
}
// Comprobamos si existe la base de datos
String sDBVersion = getDataBaseVersion();
String sScript = lookupDataLogic(DataLogicSystem.class).getInitScript() + "_" + sDBVersion + ".sql";
if (JFrmTPV.class.getResource(sScript) != null) {
// hay un script para actualizar o crear la base de datos.
if (JOptionPane.showConfirmDialog(this
, AppLocal.getIntString("create".equals(sDBVersion) ? "message.createdatabase" : "message.updatedatabase")
, AppLocal.getIntString("message.title")
, JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE) == JOptionPane.YES_OPTION) {
do { // ejecutamos todos los scripts de upgrade disponibles...
try {
java.util.List l = new BatchSentence(m_appcnt.getSession(), sScript).list();
if (l.size() > 0) {
JMessageDialog.showMessage(this, new MessageInf(MessageInf.SGN_WARNING, AppLocal.getIntString("Database.ScriptWarning"), l.toArray(new Throwable[l.size()])));
}
} catch (BasicException e) {
JMessageDialog.showMessage(this, new MessageInf(MessageInf.SGN_DANGER, AppLocal.getIntString("Database.ScriptError"), e));
m_appcnt.disconnect();
return false;
}
sScript = lookupDataLogic(DataLogicSystem.class).getInitScript() + "_" + getDataBaseVersion() + ".sql";
} while (JFrmTPV.class.getResource(sScript) != null);
} else {
// sin base de datos no hay registradora.
m_appcnt.disconnect();
return false;
}
}
// Ponemos la version en el aption que no lo haciamos.
sDBVersion = getDataBaseVersion();
setTitle("Tina POS " + sDBVersion);
// Cargamos las propiedades de base de datos
m_propsdb = lookupDataLogic(DataLogicSystem.class).getResourceAsProperties(getHost() + "/properties");
if (m_propsdb == null) {
m_propsdb = new Properties();
// Compatibilidad hacia atras
String soldvalue = getProperty("machine.activecash");
if (soldvalue != null) {
m_propsdb.setProperty("activecash", soldvalue);
}
}
// creamos la caja activa si esta no existe
try {
try {
Integer iActiveCashIndex = Integer.valueOf(getMachineProperty("activecash"));
Object[] valcash = lookupDataLogic(DataLogicSystem.class).findActiveCash(iActiveCashIndex);
if (valcash == null || !getHost().equals(valcash[0])) {
// no la encuentro o no es de mi host por tanto creo una...
setActiveCash(lookupDataLogic(DataLogicSystem.class).getNextClosedCash(), new Date(), null);
// creamos la caja activa
lookupDataLogic(DataLogicSystem.class).execInsertCash(
new Object[] {getActiveCashIndex(), getHost(), getActiveCashDateStart(), getActiveCashDateEnd()});
} else {
setActiveCash(iActiveCashIndex, (Date) valcash[1], (Date) valcash[2]);
}
} catch (NumberFormatException e) {
// Creamos una nueva caja
setActiveCash(lookupDataLogic(DataLogicSystem.class).getNextClosedCash(), new Date(), null);
// creamos la caja activa
lookupDataLogic(DataLogicSystem.class).execInsertCash(
new Object[] {getActiveCashIndex(), getHost(), getActiveCashDateStart(), getActiveCashDateEnd()});
}
} catch (BasicException e) {
// Casco. Sin caja no hay tina pos
MessageInf msg = new MessageInf(MessageInf.SGN_NOTICE, AppLocal.getIntString("message.cannotclosecash"), e);
msg.show(this);
m_appcnt.disconnect();
return false;
}
// Leo la localizacion de la caja (Almacen).
try {
m_iInventoryLocation = Integer.valueOf(getMachineProperty("location"));
} catch (NumberFormatException e) {
m_iInventoryLocation = Integer.valueOf(0);
}
// Inicializo la impresora...
m_TP = new DeviceTicket(m_appcnt);
// Inicializamos
m_TTP = new TicketParser(getDeviceTicket(), lookupDataLogic(DataLogicSystem.class));
printerStart();
// Inicializamos la bascula
m_Scale = new DeviceScale(m_appcnt);
// Inicializamos la scanpal
m_Scanner = DeviceScannerFactory.createInstance(m_appcnt);
// Leemos los recursos basicos
BufferedImage imgicon = lookupDataLogic(DataLogicSystem.class).getResourceAsImage("Window.Logo");
m_jLblTitle.setIcon(imgicon == null ? null : new ImageIcon(imgicon));
m_jLblTitle.setText(lookupDataLogic(DataLogicSystem.class).getResourceAsText("Window.Title"));
String sWareHouse;
try {
sWareHouse = lookupDataLogic(DataLogicSystem.class).findLocationName(m_iInventoryLocation);
} catch (BasicException e) {
sWareHouse = null; // no he encontrado el almacen principal
}
m_jHost.setText(sWareHouse + " (" + getHost() + ")");
// Show Login
listPeople();
showView("login");
// showLogonView("logonname");
// Nos ponemos a la resolucion que hay que ponerse
changeDisplayMode(1024, 768);
// Mostramos el formulario principal...
setVisible(true);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -