From 510ca913dae891d1d1d9e6e32280a2bcc4589fa3 Mon Sep 17 00:00:00 2001 From: guillermo Date: Wed, 27 Jul 2022 11:10:13 +0200 Subject: [PATCH] bugs solved --- setup.iss | 4 +-- src/main.js | 73 ++++++++++++++++++++++++++++------------------------- 2 files changed, 40 insertions(+), 37 deletions(-) diff --git a/setup.iss b/setup.iss index a02a634..3b44b84 100644 --- a/setup.iss +++ b/setup.iss @@ -1,8 +1,8 @@ #define MyAppName "Verdnatura" -#define MyAppVersion "3" +#define MyAppVersion "4" #define MyAppPublisher "Verdnatura" -#define MyAppURL "http://www.verdnatura.es/" +#define MyAppURL "https://www.verdnatura.es/" [Setup] ; NOTE: The value of AppId uniquely identifies this application. diff --git a/src/main.js b/src/main.js index 113af15..128f0a9 100755 --- a/src/main.js +++ b/src/main.js @@ -129,6 +129,9 @@ var App = { var password = this.regRead(Conf.dsPath, 'PWD'); var remember = this.regRead(Conf.regPath, 'remember'); + this.$('branch').value = this.getBranch(); + this.onChangeBranchChange(); + if (user) this.$('user').value = user; @@ -138,9 +141,6 @@ var App = { this.onEnterClick(); } else this.resetForm(true); - - this.$('branch').value = this.getBranch(); - this.onChangeBranchChange(); }, resetForm: function(clearPassword) { @@ -205,7 +205,6 @@ var App = { } catch (e) {} } } - this.showMessage(_('Cache files have been deleted'), 'notice'); }, @@ -361,23 +360,12 @@ var App = { // Obtains the local version number from the MDB file - var localVersion; + var localVersion = this.mdbGetValue( + 'SELECT Version FROM tblVariables', + 'Version', parseInt + ); + if (!localVersion) localVersion = false; - try { - var mdbConn = new ActiveXObject('ADODB.Connection'); - mdbConn.open(this.getOdbcString({ - 'Provider': 'Microsoft.Jet.OLEDB.4.0', - 'Data Source': this.mdbFile - })); - - var oRs = new ActiveXObject('ADODB.Recordset'); - oRs.Open('SELECT Version FROM tblVariables', mdbConn); - localVersion = oRs.EOF ? false : parseInt(oRs('Version')); - - oRs.close(); - mdbConn.close(); - } catch (e) {} - // Determines if should download return !localVersion || version === false || localVersion != version @@ -385,6 +373,31 @@ var App = { : null; }, + mdbGetValue: function(query, field, parseFn) { + var value; + + try { + if (this.fso.fileExists(this.mdbFile)) { + var mdbConn = new ActiveXObject('ADODB.Connection'); + mdbConn.open(this.getOdbcString({ + 'Provider': 'Microsoft.Jet.OLEDB.4.0', + 'Data Source': this.mdbFile + })); + + try { + var rs = new ActiveXObject('ADODB.Recordset'); + rs.Open(query, mdbConn); + value = rs.EOF ? null : parseFn(rs(field)); + rs.close(); + } catch (e) {} + + mdbConn.close(); + } + } catch (e) {} + + return value; + }, + getOdbcString: function(options) { var optionsArray = []; for (var option in options) @@ -559,21 +572,11 @@ var App = { * @return {string} Branch name, master if cannot */ getBranch: function() { - var branch = Conf.defaultBranch; - try { - var mdbConn = new ActiveXObject('ADODB.Connection'); - mdbConn.open(this.getOdbcString({ - 'Provider': 'Microsoft.Jet.OLEDB.4.0', - 'Data Source': this.mdbFile - })); - - var rs = new ActiveXObject('ADODB.Recordset'); - rs.Open('SELECT branch FROM tblVariables', mdbConn); - branch = String(rs('branch')); - rs.close(); - mdbConn.close(); - } catch (e) {} - return branch; + var branch = this.mdbGetValue( + 'SELECT branch FROM tblVariables', + 'branch', String + ); + return branch || Conf.defaultBranch; } };