From 329ffeca8f8b7aabde74e29050c7fc54d4a31e0d Mon Sep 17 00:00:00 2001 From: Milan Hanajik Date: Mon, 2 Mar 2020 10:42:27 +0100 Subject: [PATCH] 1. DB creation and import via Settings/Profiles menu item fixed, 2. Each scale must have a drain valve. --- .../MettlerToledo/TankDraining.cs | 2 ++ TBF/UI/Settings/DatabaseSettingsDlg.cs | 32 +++++++++++-------- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/TBF/BenchControl/MettlerToledo/TankDraining.cs b/TBF/BenchControl/MettlerToledo/TankDraining.cs index 557eced95..85956655e 100644 --- a/TBF/BenchControl/MettlerToledo/TankDraining.cs +++ b/TBF/BenchControl/MettlerToledo/TankDraining.cs @@ -77,6 +77,8 @@ namespace TBF.BenchControl.MettlerToledo drainValve = TbfComponents.FindComponent(tankDrainingCfg.DrainValve) as IValve; evaporationCmpnt = TbfComponents.FindComponent(tankDrainingCfg.Evaporation) as IEvaporation; + if (drainValve == null) throw new Exception(string.Format("{0} is missing a drain valve", Name)); + openTheDrainValveOp = new Elde.SetValvesOp(StateMachine.ControlBoard, drainValve, null); closeTheDrainValveOp = new Elde.SetValvesOp(StateMachine.ControlBoard, null, drainValve); waitTankIsEmptyOp = new WaitTankEmptyOp(this); diff --git a/TBF/UI/Settings/DatabaseSettingsDlg.cs b/TBF/UI/Settings/DatabaseSettingsDlg.cs index da193cd4f..3b3c23277 100644 --- a/TBF/UI/Settings/DatabaseSettingsDlg.cs +++ b/TBF/UI/Settings/DatabaseSettingsDlg.cs @@ -1,13 +1,13 @@ /// -/// Copyright (c) 2013-2019 Sensus Slovensko a.s. +/// Copyright (c) 2013-2020 Sensus Slovensko a.s. /// using System; using System.Drawing; +using System.IO; using System.Windows.Forms; using log4net; using Results; using TBF.Resources; -using System.IO; namespace TBF.UI.Settings { @@ -18,6 +18,8 @@ namespace TBF.UI.Settings { static readonly ILog log = LogManager.GetLogger(typeof(DatabaseSettingsDlg)); + const string CredFileName = "tempfile"; + // Reference to bench DB settins (not a local copy) Config.DatabaseSettings bench; @@ -193,8 +195,14 @@ namespace TBF.UI.Settings } catch (Exception exception) { + if (File.Exists(CredFileName)) File.Delete(CredFileName); Cursor.Current = Cursors.Default; - MessageBox.Show(Strings.Error_while_creating_DB_Reason + exception.Message, Strings.Error); + string msg = string.Format("{0}{1}{2}", Strings.Error_while_creating_DB_Reason, Environment.NewLine, exception.Message); + if (exception.InnerException != null) + { + msg += Environment.NewLine + exception.InnerException.Message; + } + MessageBox.Show(msg, Strings.Error, MessageBoxButtons.OK, MessageBoxIcon.Error); } } } @@ -236,8 +244,9 @@ namespace TBF.UI.Settings } catch (Exception exception) { + if (File.Exists(CredFileName)) File.Delete(CredFileName); Cursor.Current = Cursors.Default; - string msg = Strings.Error_while_creating_DB_Reason + Environment.NewLine + exception.Message; + string msg = string.Format("{0}{1}{2}", Strings.Error_while_creating_DB_Reason, Environment.NewLine, exception.Message); if (exception.InnerException != null) { msg += Environment.NewLine + exception.InnerException.Message; @@ -371,6 +380,7 @@ namespace TBF.UI.Settings } catch (Exception exc) { + if (File.Exists(CredFileName)) File.Delete(CredFileName); log.FatalFormat("Failed to import database '{0}' from file {1}: {2}", databaseName, inputFileName, exc.Message); } } @@ -394,8 +404,7 @@ namespace TBF.UI.Settings /// Database name void ExecuteMySqlCmd(string command, string userName, string password, string databaseToBeUsed) { - string credFileName = "tempfile"; - using (TextWriter writer = new StreamWriter(credFileName)) + using (TextWriter writer = new StreamWriter(CredFileName)) { writer.WriteLine("[mysql]"); writer.WriteLine(string.Format("user={0}", userName)); @@ -409,11 +418,11 @@ namespace TBF.UI.Settings proc.StartInfo.FileName = @"C:\xampp\mysql\bin\mysql.exe"; if (string.IsNullOrEmpty(databaseToBeUsed)) { - proc.StartInfo.Arguments = string.Format("--defaults-file={0}", credFileName); + proc.StartInfo.Arguments = string.Format("--defaults-file={0}", CredFileName); } else { - proc.StartInfo.Arguments = string.Format("--defaults-file={0} --database={1}", credFileName, databaseToBeUsed); + proc.StartInfo.Arguments = string.Format("--defaults-file={0} --database={1}", CredFileName, databaseToBeUsed); } proc.StartInfo.UseShellExecute = false; /// Must be false to redirect standard input or standard output proc.StartInfo.RedirectStandardOutput = false; @@ -426,14 +435,9 @@ namespace TBF.UI.Settings System.Diagnostics.Debug.WriteLine(command); log.Warn(command); proc.StandardInput.WriteLine("exit"); - while (!proc.StandardOutput.EndOfStream) - { - string line = proc.StandardOutput.ReadLine(); - Console.WriteLine(line); - } proc.WaitForExit(); - File.Delete(credFileName); + File.Delete(CredFileName); } } } \ No newline at end of file