diff --git a/IntegrationEgaltech/Generator.cs b/IntegrationEgaltech/Generator.cs index 8339694..8f3636d 100644 --- a/IntegrationEgaltech/Generator.cs +++ b/IntegrationEgaltech/Generator.cs @@ -37,9 +37,9 @@ namespace ib.essetre.integration.egaltech { callback.Progress( 0, "Init") ; - GetToolParams(parameters); + //GetToolParams(parameters); - GetMachineParams(parameters); + //GetMachineParams(parameters); SqlConnectionStr = parameters.ConnectionString ; @@ -154,9 +154,9 @@ namespace ib.essetre.integration.egaltech int ErrCutId = ( pattInfo.IsFromProject ? pattInfo.ElementId : pattInfo.PatternId) ; using ( var tw = new StreamWriter( Path.ChangeExtension( BtlPath, ".txt"), false)) { tw.WriteLine( "ERR=10") ; + tw.WriteLine( "BTL vuoto") ; tw.WriteLine( "CUTID=" + ErrCutId.ToString()) ; tw.WriteLine( "TASKID=0") ; - tw.WriteLine( "BTL vuoto") ; } // elimino eventuale file Cn già presente if ( parameters.UIMode == InOutParameters.UIModes.HIDDEN) { @@ -167,47 +167,62 @@ namespace ib.essetre.integration.egaltech } // Recupero il risultato - int cutId = 0 ; - int taskId = 0 ; - PatternInfo.Results resExe = PatternInfo.Results.NONE ; - string textErr = "" ; + bool bErrors = false ; + int nLastErr = 0 ; + string sLastMsg = "" ; if ( File.Exists( Path.ChangeExtension( BtlPath, ".txt"))) { + int nErr = 0 ; + string sMsg = "" ; + int cutId = 0 ; + int taskId = 0 ; string[] lines = System.IO.File.ReadAllLines( Path.ChangeExtension( BtlPath, ".txt")) ; foreach ( string line in lines) { if ( line.StartsWith( "ERR=")) { int? nVal = GetVal(line, "ERR") ; - if ( nVal == 0) - resExe = PatternInfo.Results.OK ; - else - resExe = PatternInfo.Results.ERROR ; + nErr = ( nVal != null ? nVal.Value : 0) ; + sMsg = "" ; + cutId = 0 ; + taskId = 0 ; } else if ( line.StartsWith( "CUTID=")) { int? nVal = GetVal( line, "CUTID") ; - if ( nVal != null) - cutId = nVal.Value ; + cutId = ( nVal != null ? nVal.Value : 0) ; } else if ( line.StartsWith( "TASKID=")) { int? nVal = GetVal( line, "TASKID") ; - if ( nVal != null) - taskId = nVal.Value ; + taskId = ( nVal != null ? nVal.Value : 0) ; + PatternInfo.Results resExe = PatternInfo.Results.OK ; + if ( nErr > 0) { + resExe = PatternInfo.Results.ERROR ; + bErrors = true ; + nLastErr = nErr ; + sLastMsg = sMsg ; + } + pattInfo.SetTaskState( cutId, taskId, resExe, sMsg) ; } else if ( ! string.IsNullOrWhiteSpace( line)) - textErr = line ; + sMsg = line ; } } - pattInfo.SetTaskState( cutId, taskId, resExe, textErr) ; - if ( resExe == PatternInfo.Results.OK) { + if ( ! bErrors) { pattInfo.Result = PatternInfo.Results.OK ; - pattInfo.DetailResult = PatternInfo.DetailResults.ALL_OK ; + pattInfo.DetailResult = PatternInfo.DetailResults.MEMORY ; } else { - pattInfo.Result = PatternInfo.Results.ERROR ; - pattInfo.DetailResult = PatternInfo.DetailResults.MEMORY ; + if ( nLastErr != 17) { + pattInfo.Result = PatternInfo.Results.ERROR ; + pattInfo.DetailResult = PatternInfo.DetailResults.MEMORY ; + } + else { + pattInfo.Result = PatternInfo.Results.ERROR ; + pattInfo.DetailResult = PatternInfo.DetailResults.ALL_KO ; + pattInfo.Message = sLastMsg ; + } } pattInfo.EstimatedTime = 32.7 ; // Lettura OutputFilename e scrittura nel parametro stringa Iso (solo nel caso UIModes.HIDDEN) - if ( resExe == PatternInfo.Results.OK && parameters.UIMode == InOutParameters.UIModes.HIDDEN) { + if ( ! bErrors && parameters.UIMode == InOutParameters.UIModes.HIDDEN) { string CncPath = Path.ChangeExtension( BtlPath, ".cnc") ; if ( File.Exists( CncPath)) { @@ -525,183 +540,130 @@ namespace ib.essetre.integration.egaltech return barLength ; } - //Import necessario per l'uso della funzione per scrivere sui file INI + //------------------------------------------------------------------------------------------------------------- + // Dati utensili e macchina + //------------------------------------------------------------------------------------------------------------- + // Import della funzione di sistema per la scrittura su file INI [DllImport("kernel32", CharSet = CharSet.Unicode)] - static extern long WritePrivateProfileString(string Section, string Key, string Value, string FilePath); + static extern long WritePrivateProfileString( string Section, string Key, string Value, string FilePath) ; - //Scrive il file ToolConfig.ini che include gli utensili e i relativi parametri presi dal DB - private static void GetToolParams(InOutParameters parameters) + // Scrive il file ToolConfig.ini che include gli utensili e i relativi parametri presi dal DB + private static void GetToolParams( InOutParameters parameters) { - SqlConnectionStr = parameters.ConnectionString; - DataSet dsTools = new DataSet(); + // Direttorio di scrittura del file e sua creazione se non esiste + String BtlDir = parameters.Read( "EGALTECH", "DIR_BTL", "") ; + DirectoryInfo di = new DirectoryInfo( BtlDir) ; + if ( ! di.Exists) + di.Create() ; - String BtlDir = parameters.Read("EGALTECH", "DIR_BTL", ""); - // Se la directory in cui salvare il file non esiste viene creata - DirectoryInfo di = new DirectoryInfo(BtlDir); - if (!di.Exists) - di.Create(); + // Path del file INI e sua cancellazione se già esiste + string IniPath = Path.Combine( BtlDir, "ToolConfig.ini") ; + if ( File.Exists( IniPath)) + File.Delete( IniPath) ; - //string sql = "SELECT * FROM dbo.vw_Tool"; + // Preparazione interrogazione del DB + SqlConnectionStr = parameters.ConnectionString ; + DataSet dsTools = new DataSet() ; string sqlTool = "SELECT [vw_Tool].[toolId], [code], [jobType], [toolType], " + - "[enabled], [note], [position], [file3ds], [rpm], [feed], [srot], " + - "[number], [vw_Tool].[configurationId], [vw_Tool].[flagDeleted], [lastModified], " + - "[key], [value] " + - "FROM [ESSETRE].[dbo].[vw_Tool] " + - "INNER JOIN [ESSETRE].[dbo].[vw_ToolParam] " + - "ON [vw_Tool].[toolId] = [vw_ToolParam].[toolId] "; - - // Connessione al DB ed esecuzione query - using (SqlConnection cn = new SqlConnection(SqlConnectionStr)) - { - cn.Open(); - using (SqlCommand cmd = new SqlCommand(sqlTool, cn)) - { - var dataAdapter = new SqlDataAdapter(cmd); + "[enabled], [note], [position], [file3ds], [rpm], [feed], [srot], " + + "[number], [vw_Tool].[configurationId], [vw_Tool].[flagDeleted], [lastModified], " + + "[key], [value] " + + "FROM [ESSETRE].[dbo].[vw_Tool] " + + "INNER JOIN [ESSETRE].[dbo].[vw_ToolParam] " + + "ON [vw_Tool].[toolId] = [vw_ToolParam].[toolId] "; + // Connessione al DB ed esecuzione query + using ( SqlConnection cn = new SqlConnection( SqlConnectionStr)) { + cn.Open() ; + using ( SqlCommand cmd = new SqlCommand( sqlTool, cn)) { + var dataAdapter = new SqlDataAdapter( cmd) ; // Lettura DB e riempimento DataSet - dsTools.Clear(); - dataAdapter.Fill(dsTools); + dsTools.Clear() ; + dataAdapter.Fill( dsTools) ; } } - // Scrittura del file INI - string IniName = "ToolConfig.ini"; - // Path completa del nome del file INI da salvare - string IniPath = Path.Combine(BtlDir, IniName); + // Scrittura del file + foreach ( DataTable table in dsTools.Tables) { - String Section = ""; - String Key = ""; - String Value = ""; + int toolId = 0 ; + String Section = "" ; - foreach (DataTable table in dsTools.Tables) - { - int toolId = 0; + foreach ( DataRow row in table.Rows) { - foreach (DataRow row in table.Rows) - { - bool spaceBeforeSection = false; + String Key = "" ; + String Value = "" ; - if ((int)row["toolId"] != toolId) - { - spaceBeforeSection = true; - toolId = (int)row["toolId"]; - Section = "Tool_" + toolId.ToString("00"); //row["code"].ToString(); + if ( (int)row["toolId"] != toolId) { + // Nuovo utensile + toolId = (int)row["toolId"] ; + Section = "Tool_" + toolId.ToString("00") ; //row["code"].ToString(); - //Questo foreach è all'interno dell'if in modo da essere eseguito una volta sola - foreach (DataColumn column in table.Columns) - { - if (!(column.ColumnName.Equals("key") || column.ColumnName.Equals("value"))) - { - Key = column.ColumnName; - Value = row[column].ToString(); - - WritePrivateProfileString(Section, Key, Value, IniPath); + // Dati utensile presenti in ogni riga + foreach ( DataColumn column in table.Columns) { + if ( ! ( column.ColumnName.Equals( "key") || column.ColumnName.Equals( "value"))) { + Key = column.ColumnName ; + Value = row[column].ToString() ; + WritePrivateProfileString( Section, Key, Value, IniPath) ; } } } - //Questo è all'esterno dell'if perché va eseguito più volte, per key e value di ogni ToolParam - Key = row["key"].ToString(); - Value = row["value"].ToString(); - - WritePrivateProfileString(Section, Key, Value, IniPath); - - if (spaceBeforeSection) - { - var txtLines = File.ReadAllLines(IniPath).ToList(); //Fill a list with the lines from the txt file. - var sectionIni = "[" + Section + "]"; - if (txtLines.IndexOf(sectionIni) > 0) - { - var lineBeforeSection = txtLines[txtLines.IndexOf(sectionIni) - 1].ToString(); - if (!String.IsNullOrEmpty(lineBeforeSection)) - { - txtLines.Insert(txtLines.IndexOf(sectionIni), Environment.NewLine); - File.WriteAllLines(IniPath, txtLines); - } - } - } - + // Altri dati utensile + Key = row["key"].ToString() ; + Value = row["value"].ToString() ; + WritePrivateProfileString( Section, Key, Value, IniPath) ; } } } - //Scrive il file MachConfig_[MachineName].ini che include i parametri macchina presi dal DB - private static void GetMachineParams(InOutParameters parameters) + // Scrive il file MachConfig_[MachineName].ini che include i parametri macchina presi dal DB + private static void GetMachineParams( InOutParameters parameters) { - SqlConnectionStr = parameters.ConnectionString; - DataSet dsMachs = new DataSet(); + // Direttorio di scrittura del file e sua creazione se non esiste + String BtlDir = parameters.Read( "EGALTECH", "DIR_BTL", "") ; + DirectoryInfo di = new DirectoryInfo( BtlDir) ; + if ( ! di.Exists) + di.Create() ; - String BtlDir = parameters.Read("EGALTECH", "DIR_BTL", ""); - // Se la directory in cui salvare il file non esiste viene creata - DirectoryInfo di = new DirectoryInfo(BtlDir); - if (!di.Exists) - di.Create(); + // Path del file INI e sua cancellazione se già esiste + string IniName = "MachConfig_" + parameters.MachineName + ".ini" ; + string IniPath = Path.Combine( BtlDir, IniName) ; + if ( File.Exists( IniPath)) + File.Delete( IniPath) ; + + // Preparazione interrogazione del DB + SqlConnectionStr = parameters.ConnectionString ; + DataSet dsMachs = new DataSet() ; string sqlMach = "SELECT [group], [key], [value] " + - "FROM [ESSETRE].[dbo].[vw_MachineParam] " + - "WHERE [group] = 'OFFSETS' " + - "OR [group] = 'TRAVE' "; - - // Connessione al DB ed esecuzione query - using (SqlConnection cn = new SqlConnection(SqlConnectionStr)) - { - cn.Open(); - using (SqlCommand cmd = new SqlCommand(sqlMach, cn)) - { - var dataAdapter = new SqlDataAdapter(cmd); + "FROM [ESSETRE].[dbo].[vw_MachineParam] " + + "WHERE [group] = 'OFFSETS' " + + "OR [group] = 'TRAVE' "; + // Connessione al DB ed esecuzione query + using ( SqlConnection cn = new SqlConnection(SqlConnectionStr)) { + cn.Open() ; + using ( SqlCommand cmd = new SqlCommand(sqlMach, cn)) { + var dataAdapter = new SqlDataAdapter( cmd) ; // Lettura DB e riempimento DataSet - dsMachs.Clear(); - dataAdapter.Fill(dsMachs); + dsMachs.Clear() ; + dataAdapter.Fill(dsMachs) ; } } - // Scrittura del file INI - string IniName = "MachConfig_" + parameters.MachineName + ".ini"; - // Path completa del nome del file INI da salvare - string IniPath = Path.Combine(BtlDir, IniName); + // Scrittura del file INI + foreach ( DataTable table in dsMachs.Tables) { - String Section = ""; - String Key = ""; - String Value = ""; - - foreach (DataTable table in dsMachs.Tables) - { - - foreach (DataRow row in table.Rows) - { - bool spaceBeforeSection = false; - - if ((string)row["group"] != Section) - spaceBeforeSection = true; - - //Questo è all'esterno dell'if perché va eseguito più volte, per key e value di ogni MachineParam - Section = row["group"].ToString(); - Key = row["key"].ToString(); - Value = row["value"].ToString(); - - WritePrivateProfileString(Section, Key, Value, IniPath); - - if (spaceBeforeSection) - { - var txtLines = File.ReadAllLines(IniPath).ToList(); //Fill a list with the lines from the txt file. - var sectionIni = "[" + Section + "]"; - if (txtLines.IndexOf(sectionIni) > 0) - { - var lineBeforeSection = txtLines[txtLines.IndexOf(sectionIni) - 1].ToString(); - if (!String.IsNullOrEmpty(lineBeforeSection)) - { - txtLines.Insert(txtLines.IndexOf(sectionIni), Environment.NewLine); - File.WriteAllLines(IniPath, txtLines); - } - } - } + foreach ( DataRow row in table.Rows) { + String Section = row["group"].ToString() ; + String Key = row["key"].ToString() ; + String Value = row["value"].ToString() ; + WritePrivateProfileString( Section, Key, Value, IniPath) ; } } - } - } } diff --git a/IntegrationEgaltech/Properties/AssemblyInfo.cs b/IntegrationEgaltech/Properties/AssemblyInfo.cs index 8baf3a6..59d2044 100644 --- a/IntegrationEgaltech/Properties/AssemblyInfo.cs +++ b/IntegrationEgaltech/Properties/AssemblyInfo.cs @@ -36,5 +36,5 @@ using System.Runtime.InteropServices; // È possibile specificare tutti i valori oppure impostare valori predefiniti per i numeri relativi alla revisione e alla build // usando l'asterisco '*' come illustrato di seguito: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("2.1.5.1")] -[assembly: AssemblyFileVersion("2.1.5.1")] +[assembly: AssemblyVersion("2.1.7.2")] +[assembly: AssemblyFileVersion("2.1.7.2")]