From 2b02a9421ab09eef36741e8bc9e163a3f54db086 Mon Sep 17 00:00:00 2001 From: Renzo Lanza Date: Tue, 22 Jan 2019 07:49:51 +0000 Subject: [PATCH] Integration : - Modifica lettura POLY per Contorno Libero (da "P(0,...),P(1,...)" a "P(...),A(...)") - Lettura config.ini (sezione EGALTECH: PATH_EXE e DIR_PATH), per avvio EgtCAM5 e salvataggio file BTL - Process Parameters Qnn stampati nel BTL come USERATTRIBUTE e solo se diversi da 0 - Lunghezza barra = [lunghezza Element + 2000] nel caso Ordine - Pulizia codice (Classe ErrorManager.cs eliminata, format e commenti vari) --- IntegrationEgaltech/BTL.cs | 58 ++++---- IntegrationEgaltech/Constants.cs | 15 -- IntegrationEgaltech/ErrorManager.cs | 70 --------- IntegrationEgaltech/Generator.cs | 136 +++++++----------- .../IntegrationEgaltech.csproj | 1 - 5 files changed, 81 insertions(+), 199 deletions(-) delete mode 100644 IntegrationEgaltech/ErrorManager.cs diff --git a/IntegrationEgaltech/BTL.cs b/IntegrationEgaltech/BTL.cs index 2fe97a0..233f189 100644 --- a/IntegrationEgaltech/BTL.cs +++ b/IntegrationEgaltech/BTL.cs @@ -20,9 +20,9 @@ namespace ib.essetre.integration.egaltech //I seguenti Id servono per il nome del file BTL public int productionId; public int patternId; - public string fileName; public int projectId; public int elementId; + public string fileName; public BTL() { @@ -37,10 +37,10 @@ namespace ib.essetre.integration.egaltech this.features = features; } - public string writeIntoFile(bool isFromProject) + public string writeIntoFile(bool isFromProject, string dirPath) { // La directory in cui salvare il file viene qui inizializzata - DirectoryInfo di = new DirectoryInfo(Path.GetTempPath() + @"FileBTL\"); + DirectoryInfo di = new DirectoryInfo(dirPath); // Se la directory non esiste viene creata if (!di.Exists) @@ -51,13 +51,18 @@ namespace ib.essetre.integration.egaltech //Il nome del file cambia a seconda che si tratti del caso Produzione o caso Ordine string typeName = null; if (isFromProject) + { typeName = "part"; + fileName = String.Format("{0}.btl", typeName + "_" + this.projectId + "_" + this.elementId); + } else + { typeName = "bar"; - + fileName = String.Format("{0}.btl", typeName + "_" + this.productionId + "_" + this.patternId); + } + // Si combina in un'unica stringa il percorso della directory e il nome del file da salvare - fileName = String.Format("{0}.btl", typeName + "_" + this.productionId + "_" + this.patternId); // DateTime.Now.ToString("yyyy-MM-dd HH.mm.ss"))); - string filePath = Path.Combine(di.FullName, fileName); // DateTime.Now.ToString("yyyy-MM-dd HH.mm.ss"))); + string filePath = Path.Combine(di.FullName, fileName); // Se un file txt (contenente messaggio di errore) con lo stesso nome esiste già viene cancellato if (File.Exists(filePath.Replace(".btl", ".txt"))) @@ -73,11 +78,7 @@ namespace ib.essetre.integration.egaltech tw.WriteLine(Constants.GENERAL); tw.WriteLine(Constants.PROJECT_NUMBER + this.projectNumber); tw.WriteLine(Constants.SCALE_UNIT + this.scaleUnit); - - if (isFromProject) - tw.WriteLine(Constants.USERATTRIBUTE + "\"BARLEN\":" + "\"N/A\""); // Nel caso Ordine non c'è il BarLength (colonna "l" nel DB) - else - tw.WriteLine(Constants.USERATTRIBUTE + "\"BARLEN\":" + "\"" + this.barLength + "\""); + tw.WriteLine(Constants.USERATTRIBUTE + "\"BARLEN\":" + "\"" + this.barLength + "\""); foreach (Part singlePart in parts) { @@ -100,10 +101,10 @@ namespace ib.essetre.integration.egaltech string posX = singlePart.x.ToString("0.00", System.Globalization.CultureInfo.InvariantCulture); tw.WriteLine(Constants.USERATTRIBUTE + "\"POSX\":" + "\"" + posX + "\""); - string inv = singlePart.inverted.ToString(); // "0.00", System.Globalization.CultureInfo.InvariantCulture); + string inv = singlePart.inverted.ToString(); tw.WriteLine(Constants.USERATTRIBUTE + "\"INVERTED\":" + "\"" + inv + "\""); - string rot = singlePart.rotated.ToString(); // "0.00", System.Globalization.CultureInfo.InvariantCulture); + string rot = singlePart.rotated.ToString(); tw.WriteLine(Constants.USERATTRIBUTE + "\"ROTATED\":" + "\"" + rot + "\""); if (isFromProject) @@ -133,22 +134,20 @@ namespace ib.essetre.integration.egaltech tw.Write("P" + i.ToString("D2") + ":" + MultAndConvertTo8(singleParameter) + " "); else tw.Write("P" + i.ToString("D2") + ":" + "\"\" "); // P15: "" + + if (i == 26) + tw.WriteLine(" "); // Vado a capo } else { - // Stampo i vari parametri Qnn preceduti da "COMMENT:" - if (i == 27) - { - tw.WriteLine(" "); // Vado a capo - tw.Write(Constants.COMMENT); - } - tw.Write("Q" + (i - 26).ToString("D2") + ":" + MultAndConvertTo8(singleParameter) + " "); + // Stampo i vari parametri Qnn diversi da 0, preceduti da "USERATTRIBUTE:" + if (!singleParameter.Equals("0")) + tw.WriteLine(Constants.USERATTRIBUTE + "\"Q" + (i - 26).ToString("D2") + "\":\"" + singleParameter + "\" "); } //Convert.ToInt16(i); i++; } - tw.WriteLine(" "); // Vado a capo tw.WriteLine(Constants.PROCESS_IDENT + singleFeature.processIdent); tw.WriteLine(Constants.PROCESS + singleFeature.process); } @@ -170,15 +169,16 @@ namespace ib.essetre.integration.egaltech { if (sag1 != "") { - string[] arrParam = sag1.Split(new string[] { "POLY([P(", ")],'P','C')", "),P(" }, StringSplitOptions.RemoveEmptyEntries); + string[] arrParam = sag1.Split(new string[] { "POLY([", "),", ")],'P','O')" }, StringSplitOptions.RemoveEmptyEntries); int count = 0; // Nel caso in cui ci troviamo alla fine di un Arco questa viene incrmentata di 1, in modo da scrivere il numero parametro corretto nei seguenti cicli Boolean flagArco = false; // Nel caso in cui ci troviamo all'inizio di un Arco questa viene posta a TRUE, in modo da passare nel percorso dedicato nel prossimo ciclo for (int i = 0; i < arrParam.Length; i++) { - string[] parts = arrParam[i].Split(','); // ogni parametro P di POLY viene splittato in più parti + char[] separators = { ',', '(' }; + string[] parts = arrParam[i].Split(separators); // ogni parametro P di POLY viene splittato in più parti switch (parts[0]) // il primo elemento di parts[] indica se ci troviamo all'inizio di un Arco o no { - case "0": + case "P": if (i == 0) // Caso StartPoint { tw.WriteLine(Constants.PROCESS_KEY + singleFeature.processKey + " " + singleFeature.designation); @@ -203,7 +203,6 @@ namespace ib.essetre.integration.egaltech tw.WriteLine(" "); tw.WriteLine(Constants.PROCESS_IDENT + (Convert.ToInt16(singleFeature.processIdent) + i - count)); tw.WriteLine(Constants.PROCESS + singleFeature.process); - //tw.WriteLine(Constants.USERATTRIBUTE + "\"TASKID\":" + "\"" + singleFeature.taskId + "\""); } else if (flagArco) // Caso FineArco { @@ -234,13 +233,12 @@ namespace ib.essetre.integration.egaltech tw.WriteLine(" "); tw.WriteLine(Constants.PROCESS_IDENT + (Convert.ToInt16(singleFeature.processIdent) + i - count)); tw.WriteLine(Constants.PROCESS + singleFeature.process); - //tw.WriteLine(Constants.USERATTRIBUTE + "\"TASK\":" + "\"" + singleFeature.taskId + "\""); } break; - case "1": // Caso InizioArco + case "A": // Caso InizioArco tw.WriteLine(Constants.PROCESS_KEY + singleFeature.processKey + " " + singleFeature.designation); tw.Write(Constants.PROCESS_PARAMETERS); - string[] nextParts = arrParam[i + 1].Split(','); + string[] nextParts = arrParam[i + 1].Split(separators); tw.Write("P01:" + MultAndConvertTo8(nextParts[1]) + " "); // x (EndPoint Arc) tw.Write("P02:" + MultAndConvertTo8(nextParts[2]) + " "); // y (EndPoint Arc) tw.Write("P03:" + MultAndConvertTo8(nextParts[3]) + " "); // z (Endpoint Arc) @@ -261,7 +259,6 @@ namespace ib.essetre.integration.egaltech tw.WriteLine(" "); tw.WriteLine(Constants.PROCESS_IDENT + (Convert.ToInt16(singleFeature.processIdent) + i - count)); tw.WriteLine(Constants.PROCESS + singleFeature.process); - //tw.WriteLine(Constants.USERATTRIBUTE + "\"TASK\":" + "\"" + singleFeature.taskId + "\""); flagArco = true; break; default: @@ -287,14 +284,13 @@ namespace ib.essetre.integration.egaltech tw.WriteLine(" "); tw.WriteLine(Constants.PROCESS_IDENT + (Convert.ToInt16(singleFeature.processIdent) + i - count)); tw.WriteLine(Constants.PROCESS + singleFeature.process); - //tw.WriteLine(Constants.USERATTRIBUTE + "\"TASK\":" + "\"" + singleFeature.taskId + "\""); break; } } } } - // Il seguente metodo prende il valore di un process parameter, lo moltiplica per 10^scaleUnit + // Il seguente metodo prende il valore di un Process Parameter, lo moltiplica per 10^scaleUnit // e lo converte in una stringa di 8 caratteri (i caratteri mancanti sono degli 0) public string MultAndConvertTo8(string processParameter) { diff --git a/IntegrationEgaltech/Constants.cs b/IntegrationEgaltech/Constants.cs index 29cddb8..39ce54c 100644 --- a/IntegrationEgaltech/Constants.cs +++ b/IntegrationEgaltech/Constants.cs @@ -37,20 +37,5 @@ namespace ib.essetre.integration.egaltech // Stringa contenente i parametri di connessione al DB public const string ConnectionString = @"Data Source=localhost\SQLEssetre;Initial Catalog=ESSETRE;User ID=sa;Password=essetre"; - // Query al DB che estrae i campi specificati dal join tra vw_Task e vw_Cut in base ad un patternId - // specificato laddove questa costante venga usata nel codice - public const string sqlSelectJoinTaskCutByPattern = "SELECT vw_Task.productionId, " + - "vw_Task.patternId, vw_Task.cutId ,taskId, info1, info2, enabled, level, " + - "inTools,outTools,isChecked,vw_Task.done,isoType,ax,ay,az, vw_Cut.x, vw_Cut.y, vw_Cut.z, " + - "vw_Task.flagDeleted, [group], [key], face, edge, des, p01, p02, p03, p04, p05, p06, " + - "p07, p08, p09, p10, p11, p12, p13, p14, p15, p16, p17, p18, p19, p20, p21, p22, p23, p24, p25, " + - "p26, q01, q02, q03, q04, q05, q06, q07, q08, q09, q10, q11, q12, q13, q14, q15, q16, q17, " + - "q18, q19, q20, priority, processIdent, processingQuality, sag1, projectId, elementId, cutStart, cutEnd, " + - "inverted, rotated, doneTime, startAngle, endAngle, referenceCutId, length, width, height " + - "FROM ESSETRE.dbo.vw_Task " + - "INNER JOIN vw_Cut ON " + - "(vw_Task.cutId = vw_Cut.cutId AND vw_Task.patternId = vw_Cut.patternId AND vw_Task.productionId = vw_Cut.productionId) " + - "WHERE vw_Task.patternId = "; - } } diff --git a/IntegrationEgaltech/ErrorManager.cs b/IntegrationEgaltech/ErrorManager.cs deleted file mode 100644 index 736bf29..0000000 --- a/IntegrationEgaltech/ErrorManager.cs +++ /dev/null @@ -1,70 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.IO; -using System.Linq; -using System.Reflection; -using System.Text; - -namespace ib.essetre.integration.egaltech -{ - static class ErrorManager - { - public enum ErrorType - { - [DescriptionAttribute("Nessun errore")] - NONE = 0, - - [DescriptionAttribute("Errore da definire 1")] - ERROR1 = 1, - - [DescriptionAttribute("Errore da definire 2")] - ERROR2 = 2, - - [DescriptionAttribute("Errore da definire 3")] - ERROR3 = 3, - - [DescriptionAttribute("Errore da definire 4")] - ERROR4 = 4 - } - - public static void writeErrorToFile(ErrorType et, string BTLname) - { - //DirectoryInfo di = new DirectoryInfo(Path.GetTempPath() + @"TestoErrore\"); - - //// Se la directory non esiste viene creata - //if (!di.Exists) - //{ - // di.Create(); - //} - - //string filename = Path.Combine(di.FullName, String.Format("{0}.txt", "Prova" + DateTime.Now.ToString("yyyy-MM-dd HH.mm.ss"))); - - string filePath = "C:\\Temp\\" + BTLname + ".txt"; - - using (StreamWriter writer = new StreamWriter(filePath, true)) - { - writer.WriteLine("Errore: " + (int)et); - writer.WriteLine(); - writer.WriteLine("Descrizione : " + GetDescription(et) + " (" + DateTime.Now.ToString() + ") "); - writer.WriteLine(); - } - } - - public static string GetDescription(this Enum currentEnum) - { - string description = String.Empty; - DescriptionAttribute da; - - FieldInfo fi = currentEnum.GetType().GetField(currentEnum.ToString()); - da = (DescriptionAttribute)Attribute.GetCustomAttribute(fi, typeof(DescriptionAttribute)); - - if (da != null) - description = da.Description; - else - description = currentEnum.ToString(); - - return description; - } - } -} diff --git a/IntegrationEgaltech/Generator.cs b/IntegrationEgaltech/Generator.cs index 88e08b7..bc401b7 100644 --- a/IntegrationEgaltech/Generator.cs +++ b/IntegrationEgaltech/Generator.cs @@ -58,16 +58,17 @@ namespace ib.essetre.integration.egaltech //campo data ultima modifica nel DATABASE [lastModified] private static void DoJob(InOutParameters parameters, ICallBack callback) { - PatternInfo.Results r = PatternInfo.Results.OK; - PatternInfo.Results o; - string msg; - parameters.Patterns[0].SetTaskState(0, 0, r, "prova"); - - if (parameters.Patterns[0].GetTaskState(0, 0, out o, out msg)) - System.Windows.Forms.MessageBox.Show("Result: " + o + "\n" + "Msg: " + msg); + //PatternInfo.Results r = PatternInfo.Results.OK; + //PatternInfo.Results o; + //string msg; + //parameters.Patterns[0].SetTaskState(0, 0, r, "prova"); + //if (parameters.Patterns[0].GetTaskState(0, 0, out o, out msg)) + // System.Windows.Forms.MessageBox.Show("Result: " + o + "\n" + "Msg: " + msg); callback.Progress(0, "Init"); + String percorsoExe = parameters.Read("EGALTECH", "PATH_EXE", ""); + //int configurationId = parameters.ConfigurationId; //id cofigurazione macchina condizione where per tool e parametri glob //String connectionString = parameters.ConnectionString; //stringa connessione db //parameters.Patterns //EventLogEntryCollection schemi da elaborare @@ -141,69 +142,57 @@ namespace ib.essetre.integration.egaltech else sql = sqlProduction; + //Connessione al DB ed esecuzione query var cn = new SqlConnection(Constants.ConnectionString); SqlCommand cmd = new SqlCommand(sql, cn); cn.Open(); var dataAdapter = new SqlDataAdapter(cmd); - //var commandBuilder = new SqlCommandBuilder(dataAdapter); + //Lettura DB e riempimento DataSEt var tempDs = new DataSet(); dataAdapter.Fill(tempDs); - //ds = tempDs; - //for(int iTable = 0; iTable < ds.Tables.Count; iTable++) - //{ - // if (AreTablesTheSame(ds.Tables[iTable], tempDs.Tables[0])) - // ds.Tables.Remove(ds.Tables[iTable]); - - //} - - //tempDs.Tables[0].TableName = "Table" + ds.Tables.Count; - //ds.Tables.Add(tempDs.Tables[0].Copy()); - - if(ds.Tables.Count != 0) + //Rimozione tabella precedente e aggiunta nuova nel DB. + //Questo è per evitare che venga aggiunta una tabella uguale ad una già presente, causando errore + if (ds.Tables.Count != 0) ds.Tables.Remove(ds.Tables[0]); ds.Tables.Add(tempDs.Tables[0].Copy()); - //tempDs.Tables[0].TableName = "Table1"; - //ds.Tables.Add(tempDs.Tables[0].Copy()); - //tempDs.Tables[0].TableName = "Table2"; - //ds.Tables.Add(tempDs.Tables[0].Copy()); - //string prova = ds.Tables[0].TableName; - //string prova2 = ds.Tables[1].TableName; - + //Verifica parametro isFromProject: nel caso Ordine viene ottenuta la lista dei Process, + //nel caso Produzione viene ottenuta la lista dei Task if (parameters.Patterns[i].IsFromProject) getListaProcesses(btlObject, i); else getListaTasks(btlObject, i); + //Dialog con Progress Bar System.Threading.Thread.Sleep(1000); // solo di test float progValue = (float)1 / numBars; - callback.Progress(progValue * (i+1), - " Progresso: " + (progValue * (i + 1) * 100) + "%" + "\n" + - " BTL generati: " + (i+1) + " su " + numBars); + callback.Progress(progValue * (i + 1), + " Progresso: " + (progValue * (i + 1) * 100) + "%" + "\n" + + " BTL generati: " + (i + 1) + " su " + numBars); - string filePath = btlObject.writeIntoFile(parameters.Patterns[i].IsFromProject); // Constants.fullPath); - //System.Windows.Forms.MessageBox.Show("File scritto!"); - //ErrorManager.writeErrorToFile(ErrorManager.ErrorType.NONE, btlObject.fileName); - - //System.Diagnostics.Process.Start(filePath); - string path = "\"" + filePath + "\" " + parameters.MachineName + " " + (int)parameters.UIMode + " " + parameters.Patterns[i].OutputFilename; - Process process = Process.Start("C:\\EgtProg\\EgtCAM5\\EgtCAM5R32.exe", path); // "\"" + filePath + "\" " - //+ parameters.MachineName + " " + parameters.UIMode + " " + parameters.Patterns[0].OutputFilename); + //Si ottiene il percorso delle cartelle in cui salvare i FileBTL e si + //esegue EgtCAM5 in base ad alcuni parametri passati nella string path + string percorsoDirBTL = parameters.Read("EGALTECH", "DIR_BTL", ""); + string filePath = btlObject.writeIntoFile(parameters.Patterns[i].IsFromProject, percorsoDirBTL); + string path = "\"" + filePath + "\" " + parameters.MachineName + " " + + (int)parameters.UIMode + " " + parameters.Patterns[i].OutputFilename; + Process process = Process.Start(percorsoExe, path); // Aspetta che il file txt dell'errore venga creato da EgtCAM5 while (!File.Exists(filePath.Replace(".btl", ".txt"))) { - // Se siamo ad un ciclo successivo al numero max di istanze che EgtCAM5 può aprire + // Se siamo ad un ciclo successivo al numero max di istanze che EgtCAM5 può aprire, // il programma cicla in questo while all'infinito ---> SISTEMARE System.Threading.Thread.Sleep(1000); } - string text = System.IO.File.ReadAllText(filePath.Replace(".btl", ".txt")); + + //string text = System.IO.File.ReadAllText(filePath.Replace(".btl", ".txt")); //parameters.Patterns[i].SetTaskState(btlObject.cutId, parameters.Patterns[i]. btlObject.features., PatternInfo.Results.ERROR, text); //parameters.Patterns[i].GetTaskState(cutId, taskId, PatternInfo.Results, text); - System.Windows.Forms.MessageBox.Show(text, "Error"); + //System.Windows.Forms.MessageBox.Show(text, "Error"); ////imposta le modifiche ////solo se parameters.Patterns[i].Transformable @@ -253,9 +242,6 @@ namespace ib.essetre.integration.egaltech //non implementata al momento } - // DA SISTEMARE: i vari ds.Tables[0] (e forse anche i Rows[0]) probabilmente han bisogno dell'indice i - // in conseguenza al vettore di travi in input (al posto del vettore singolo) - // Il seguente metodo prende i record visualizzati in ds (Caso: Produzione) e li carica in un oggetto BTL public static void getListaTasks(BTL btlObject, int i) { @@ -265,7 +251,7 @@ namespace ib.essetre.integration.egaltech btlObject.projectNumber = ds.Tables[i].Rows[0]["projectId"].ToString(); btlObject.scaleUnit = Convert.ToString(2); btlObject.barLength = Convert.ToString(getBarLengthP((int)ds.Tables[i].Rows[0]["patternId"], - (int)ds.Tables[i].Rows[i]["productionId"])); + (int)ds.Tables[i].Rows[0]["productionId"])); btlObject.parts = new List(); btlObject.productionId = (int)ds.Tables[i].Rows[0]["productionId"]; @@ -295,6 +281,7 @@ namespace ib.essetre.integration.egaltech readPart.x = (double)ds.Tables[i].Rows[ltc]["x"]; readPart.inverted = ds.Tables[i].Rows[ltc]["inverted"].ToString(); readPart.rotated = ds.Tables[i].Rows[ltc]["rotated"].ToString(); + readPart.cutId = (int)ds.Tables[i].Rows[ltc]["cutId"]; } readPart.features = new List(); @@ -387,8 +374,8 @@ namespace ib.essetre.integration.egaltech btlObject.projectNumber = ds.Tables[i].Rows[0]["projectId"].ToString(); btlObject.scaleUnit = Convert.ToString(2); - //btlObject.barLength = Convert.ToString(getBarLengthO((int)ds.Tables[0].Rows[0]["elementId"], - // (int)ds.Tables[0].Rows[0]["projectId"])); + btlObject.barLength = Convert.ToString(getBarLengthO((int)ds.Tables[i].Rows[0]["elementId"], + (int)ds.Tables[i].Rows[0]["projectId"])); btlObject.parts = new List(); btlObject.projectId = (int)ds.Tables[i].Rows[0]["projectId"]; @@ -418,6 +405,7 @@ namespace ib.essetre.integration.egaltech readPart.x = (double)ds.Tables[i].Rows[ltc]["x"]; readPart.inverted = ds.Tables[i].Rows[ltc]["inverted"].ToString(); readPart.rotated = ds.Tables[i].Rows[ltc]["rotated"].ToString(); + readPart.cutId = (int)ds.Tables[i].Rows[ltc]["cutId"]; //In realtà i Process non hanno il cutId, se non virtuale } readPart.features = new List(); @@ -428,7 +416,7 @@ namespace ib.essetre.integration.egaltech { BTL.Feature readFeature = new BTL.Feature(); - readFeature.processId = ds.Tables[i].Rows[f]["processId"].ToString(); //readFeature.taskId = ds.Tables[0].Rows[f]["taskId"].ToString(); + readFeature.processId = ds.Tables[i].Rows[f]["processId"].ToString(); readFeature.processKey = ds.Tables[i].Rows[f]["group"].ToString() + "-" + ds.Tables[i].Rows[f]["key"].ToString().Substring(1, 3) + @@ -502,7 +490,7 @@ namespace ib.essetre.integration.egaltech btlObject.parts.Sort((p, q) => p.x.CompareTo(q.x)); } - // Il seguente metodo si connette al Database per estrarre tramite una query i cutId della tabella vw_Cut + // Il seguente metodo si connette al DB per estrarre tramite una query i cutId della tabella vw_Cut // aventi patternId e ProductionId che corrispondono a quelli passati come argomento private static List getListaCutIdP(int patternId, int productionId) { @@ -525,7 +513,7 @@ namespace ib.essetre.integration.egaltech return ListaCutId; } - // Il seguente metodo si connette al Database per estrarre tramite una query i cutId della tabella vw_Cut + // Il seguente metodo si connette al DB per estrarre tramite una query i cutId della tabella vw_Cut // aventi elementId e projectId che corrispondono a quelli passati come argomento private static List getListaCutIdO(int elementId, int projectId) { @@ -548,8 +536,7 @@ namespace ib.essetre.integration.egaltech return ListaCutId; } - //Ottiene la lunghezza della barra ed è usato solo nel caso Produzione perché nelle tabelle - //del caso Ordine non c'è la colonna "l" + //Ottiene la lunghezza della barra nel caso Produzione (colonna "l") private static int getBarLengthP(int patternId, int productionId) { int barLength = 0; @@ -571,42 +558,27 @@ namespace ib.essetre.integration.egaltech return barLength; } - //private static int getBarLengthO(int elementId, int projectId) - //{ - // int barLength = 0; - - // // SISTEMARE: vw_Element non ha l come vW_Pattern - // string sqlBarLength = "SELECT l FROM dbo.vw_Element WHERE elementId = " + elementId + - // "AND projectId = " + projectId; - - // using (SqlConnection cn = new SqlConnection(Constants.ConnectionString)) - // { - // cn.Open(); - // SqlCommand sqlCommand = new SqlCommand(sqlBarLength, cn); - // SqlDataReader reader = sqlCommand.ExecuteReader(); - // while (reader.Read()) - // { - // barLength = Convert.ToInt16(reader["l"]); - // } - // cn.Close(); - // } - // return barLength; - //} - - public static bool AreTablesTheSame(DataTable tbl1, DataTable tbl2) + //Ottiene la lunghezza della barra nel caso Ordine (colonna "length", ovvero la lunghezza della singola trave) + //a cui aggiungiamo un valore fisso (es. 2000) + private static int getBarLengthO(int elementId, int projectId) { - if (tbl1.Rows.Count != tbl2.Rows.Count || tbl1.Columns.Count != tbl2.Columns.Count) - return false; + int barLength = 0; - for (int i = 0; i < tbl1.Rows.Count; i++) + string sqlBarLength = "SELECT length FROM dbo.vw_Element WHERE elementId = " + elementId + + "AND projectId = " + projectId; + + using (SqlConnection cn = new SqlConnection(Constants.ConnectionString)) { - for (int c = 0; c < tbl1.Columns.Count; c++) + cn.Open(); + SqlCommand sqlCommand = new SqlCommand(sqlBarLength, cn); + SqlDataReader reader = sqlCommand.ExecuteReader(); + while (reader.Read()) { - if (!Equals(tbl1.Rows[i][c], tbl2.Rows[i][c])) - return false; + barLength = Convert.ToInt16(reader["length"]); } + cn.Close(); } - return true; + return barLength + 2000; } } diff --git a/IntegrationEgaltech/IntegrationEgaltech.csproj b/IntegrationEgaltech/IntegrationEgaltech.csproj index 50e30a4..674c2e5 100644 --- a/IntegrationEgaltech/IntegrationEgaltech.csproj +++ b/IntegrationEgaltech/IntegrationEgaltech.csproj @@ -51,7 +51,6 @@ -