// Database start
try {
session = AppViewConnection.createSession(m_props);
} catch (BasicException e) {
JMessageDialog.showMessage(this, new MessageInf(MessageInf.SGN_DANGER, e.getMessage(), e));
return false;
}
m_dlSystem = (DataLogicSystem) getBean("com.openbravo.pos.forms.DataLogicSystem");
// Create or upgrade the database if database version is not the expected
String sDBVersion = readDataBaseVersion();
if (!AppLocal.APP_VERSION.equals(sDBVersion)) {
// Create or upgrade database
String sScript = sDBVersion == null
? m_dlSystem.getInitScript() + "-create.sql"
: m_dlSystem.getInitScript() + "-upgrade-" + sDBVersion + ".sql";
if (JRootApp.class.getResource(sScript) == null) {
JMessageDialog.showMessage(this, new MessageInf(MessageInf.SGN_DANGER, sDBVersion == null
? AppLocal.getIntString("message.databasenotsupported", session.DB.getName()) // Create script does not exists. Database not supported
: AppLocal.getIntString("message.noupdatescript"))); // Upgrade script does not exist.
session.close();
return false;
} else {
// Create or upgrade script exists.
if (JOptionPane.showConfirmDialog(this
, AppLocal.getIntString(sDBVersion == null ? "message.createdatabase" : "message.updatedatabase")
, AppLocal.getIntString("message.title")
, JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE) == JOptionPane.YES_OPTION) {
try {
BatchSentence bsentence = new BatchSentenceResource(session, sScript);
bsentence.putParameter("APP_ID", Matcher.quoteReplacement(AppLocal.APP_ID));
bsentence.putParameter("APP_NAME", Matcher.quoteReplacement(AppLocal.APP_NAME));
bsentence.putParameter("APP_VERSION", Matcher.quoteReplacement(AppLocal.APP_VERSION));
java.util.List l = bsentence.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));
session.close();
return false;
}
} else {
session.close();
return false;
}
}
}
// Cargamos las propiedades de base de datos
m_propsdb = m_dlSystem.getResourceAsProperties(m_props.getHost() + "/properties");
// creamos la caja activa si esta no existe
try {
String sActiveCashIndex = m_propsdb.getProperty("activecash");
Object[] valcash = sActiveCashIndex == null
? null
: m_dlSystem.findActiveCash(sActiveCashIndex);
if (valcash == null || !m_props.getHost().equals(valcash[0])) {
// no la encuentro o no es de mi host por tanto creo una...
setActiveCash(UUID.randomUUID().toString(), m_dlSystem.getSequenceCash(m_props.getHost()) + 1, new Date(), null);
// creamos la caja activa
m_dlSystem.execInsertCash(
new Object[] {getActiveCashIndex(), m_props.getHost(), getActiveCashSequence(), getActiveCashDateStart(), getActiveCashDateEnd()});
} else {
setActiveCash(sActiveCashIndex, (Integer) valcash[1], (Date) valcash[2], (Date) valcash[3]);
}
} catch (BasicException e) {
// Casco. Sin caja no hay pos
MessageInf msg = new MessageInf(MessageInf.SGN_NOTICE, AppLocal.getIntString("message.cannotclosecash"), e);
msg.show(this);
session.close();
return false;
}
// Leo la localizacion de la caja (Almacen).