/// <summary> /// Upgrade the schema to latest one. /// </summary> /// <param name="dBCommand"></param> private void UpgradeSchema(DbCommand dBCommand) { if (dBCommand.Connection.State != ConnectionState.Open) { dBCommand.Connection.Open(); } string currentDbVersion = dBCommand.ExecuteScalar(getVersionSql) as string; // Query the table for every upgrade greater than the current version using (DataTable upgradeTable = ImportInitialData.GetData("Upgrades.POSISUPGRADES")) { DataRow[] upgradeRows = upgradeTable.Select(string.Format("UPGRADEVERSION > '{0}'", currentDbVersion)); string upgradeVersion = null; int count = 0; foreach (DataRow upgradeRow in upgradeRows) { upgradeVersion = upgradeRow["UPGRADEVERSION"].ToString(); DisplayMessage(50609, ++count, upgradeRows.Length, upgradeVersion); dBCommand.ExecuteScript("Upgrades." + upgradeRow["UPGRADESCRIPT"].ToString()); DisplayMessage(50607, upgradeVersion); } if (upgradeVersion != null) { dBCommand.ExecuteNonQuery(string.Format(CultureInfo.CurrentCulture, setVersionSql, upgradeVersion)); } } }
/// <summary> /// Create Retail POS schema /// </summary> /// <param name="dBCommand"></param> /// <param name="dBUtil"></param> /// <param name="includeDemoData">Flag to signal if demo data is needed</param> private void CreateSchema(DbCommand dBCommand, DBUtil dBUtil, bool includeDemoData) { DisplayMessage(50604); //Running script dBCommand.ExecuteScript("DatabaseScript.txt"); DisplayMessage(50605); //Tables successfully created. if (includeDemoData) { // Import demo data DisplayMessage(50606); // Loading data into tables ImportInitialData importInitialData = new ImportInitialData(dBUtil, (tableName) => DisplayMessage(50607, tableName)); importInitialData.ImportData(); DisplayMessage(50608); // Data successfully loaded } string currentDbVersion = dBCommand.ExecuteScalar(getVersionSql) as string; // it seems that the version is set by the import data. // If the import data is set to false, no version will be set and the script to create schema will be run again. // This will fail if the tables already exists and the version was not set. if (currentDbVersion == null) { ImportInitialData importInitialData = new ImportInitialData(dBUtil, (tableName) => DisplayMessage(50607, tableName)); importInitialData.ImportInfoPosisInfo(); } }