diff --git a/IntegrationEgaltech/BTL.cs b/IntegrationEgaltech/BTL.cs index 2def1a6..3db5e67 100644 --- a/IntegrationEgaltech/BTL.cs +++ b/IntegrationEgaltech/BTL.cs @@ -8,334 +8,314 @@ using System.Threading.Tasks; namespace ib.essetre.integration.egaltech { - // La classe BTL rappresenta un singolo file BTL e come esso può contenere una o più Part (ovvero le travi di legno) - // ed ogni Part può contenere una o più Feature (ovvero i tagli da effettuare) - public class BTL - { - public string projectNumber; - public string scaleUnit; - public string barLength; - public List parts; - public List features; - //I seguenti Id servono per il nome del file BTL - public int productionId; - public int patternId; - public int projectId; - public int elementId; - public string fileName; + // La classe BTL rappresenta un singolo file BTL e come esso può contenere una o più Part (ovvero le travi di legno) + // ed ogni Part può contenere una o più Feature (ovvero i tagli da effettuare) + public class BTL + { + public string projectNumber; + public string scaleUnit; + public string barLength; + public List parts; + public List features; + //I seguenti Id servono per il nome del file BTL + public int productionId; + public int patternId; + public int projectId; + public int elementId; + public string fileName; - public BTL() - { + public BTL() + {} - } + public BTL( string projectNumber, string scaleUnit, List parts, List features) + { + this.projectNumber = projectNumber; + this.scaleUnit = scaleUnit; + this.parts = parts; + this.features = features; + } - public BTL(string projectNumber, string scaleUnit, List parts, List features) - { - this.projectNumber = projectNumber; - this.scaleUnit = scaleUnit; - this.parts = parts; - this.features = features; - } + public string writeIntoFile( bool isFromProject, string dirPath) + { + // Se la directory in cui salvare il file non esiste viene creata + DirectoryInfo di = new DirectoryInfo( dirPath) ; + if ( ! di.Exists) + di.Create() ; - public string writeIntoFile(bool isFromProject, string dirPath) - { - // La directory in cui salvare il file viene qui inizializzata - DirectoryInfo di = new DirectoryInfo(dirPath); - - // Se la directory non esiste viene creata - if (!di.Exists) - { - di.Create(); - } - - //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); - } + // Il nome del file cambia a seconda che si tratti del caso Produzione o caso Ordine + if ( isFromProject) + fileName = "Part_" + projectId.ToString() + "_" + elementId.ToString() + ".btl" ; + else + fileName = "Bar_" + productionId.ToString() + "_" + patternId.ToString() + ".btl"; - // Si combina in un'unica stringa il percorso della directory e il nome del file da salvare - string filePath = Path.Combine(di.FullName, fileName); + // Path completa del nome del file da salvare + 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"))) - { - File.Delete(filePath.Replace(".btl", ".txt")); - } + // Se un file txt (contenente messaggio di errore) con lo stesso nome esiste già viene cancellato + if ( File.Exists( Path.ChangeExtension( filePath, ".txt"))) + File.Delete( Path.ChangeExtension( filePath, ".txt")) ; - // Il seguente blocco 'using' si occupa della scrittura del file di testo, poi salvato in .btl - using (var tw = new StreamWriter(filePath, false)) - { - tw.WriteLine(Constants.VERSION); - tw.WriteLine(Constants.BUILD); - tw.WriteLine(Constants.GENERAL); - tw.WriteLine(Constants.PROJECT_NUMBER + this.projectNumber); - tw.WriteLine(Constants.SCALE_UNIT + this.scaleUnit); - tw.WriteLine(Constants.USERATTRIBUTE + "\"BARLEN\":" + "\"" + this.barLength + "\""); + // Se non esistono pezzi, non faccio alcunché + if ( parts == null) + return filePath ; - foreach (Part singlePart in parts) - { - tw.WriteLine(Constants.PART); - tw.WriteLine(Constants.SINGLE_MEMBER_NUMBER + singlePart.singleMemberNumber); - tw.WriteLine(Constants.COUNT + singlePart.count); + // Il seguente blocco 'using' si occupa della scrittura del file di testo, poi salvato in .btl + using ( var tw = new StreamWriter( filePath, false)) { - double len = (Convert.ToDouble(singlePart.length)) * Math.Pow(10, Constants.scaleUnit); - int intLen = (Convert.ToInt32(len)); - tw.WriteLine(Constants.LENGTH + intLen.ToString("D8")); + tw.WriteLine(Constants.VERSION); + tw.WriteLine(Constants.BUILD); + tw.WriteLine(Constants.GENERAL); + tw.WriteLine(Constants.PROJECT_NUMBER + this.projectNumber); + tw.WriteLine(Constants.SCALE_UNIT + this.scaleUnit); + tw.WriteLine(Constants.USERATTRIBUTE + "\"BARLEN\":" + "\"" + this.barLength + "\""); - double hei = (Convert.ToDouble(singlePart.height)) * Math.Pow(10, Constants.scaleUnit); - int intHei = (Convert.ToInt32(hei)); - tw.WriteLine(Constants.HEIGHT + intHei.ToString("D8")); + foreach ( Part singlePart in parts) { + tw.WriteLine(Constants.PART); + tw.WriteLine(Constants.SINGLE_MEMBER_NUMBER + singlePart.singleMemberNumber); + tw.WriteLine(Constants.COUNT + singlePart.count); - double wid = (Convert.ToDouble(singlePart.width)) * Math.Pow(10, Constants.scaleUnit); - int intWid = (Convert.ToInt32(wid)); - tw.WriteLine(Constants.WIDTH + intWid.ToString("D8")); + double len = (Convert.ToDouble(singlePart.length)) * Math.Pow(10, Constants.scaleUnit); + int intLen = (Convert.ToInt32(len)); + tw.WriteLine(Constants.LENGTH + intLen.ToString("D8")); - string posX = singlePart.x.ToString("0.00", System.Globalization.CultureInfo.InvariantCulture); - tw.WriteLine(Constants.USERATTRIBUTE + "\"POSX\":" + "\"" + posX + "\""); + double hei = (Convert.ToDouble(singlePart.height)) * Math.Pow(10, Constants.scaleUnit); + int intHei = (Convert.ToInt32(hei)); + tw.WriteLine(Constants.HEIGHT + intHei.ToString("D8")); - string inv = singlePart.inverted.ToString(); - tw.WriteLine(Constants.USERATTRIBUTE + "\"INVERTED\":" + "\"" + inv + "\""); + double wid = (Convert.ToDouble(singlePart.width)) * Math.Pow(10, Constants.scaleUnit); + int intWid = (Convert.ToInt32(wid)); + tw.WriteLine(Constants.WIDTH + intWid.ToString("D8")); - string rot = singlePart.rotated.ToString(); - tw.WriteLine(Constants.USERATTRIBUTE + "\"ROTATED\":" + "\"" + rot + "\""); + string posX = singlePart.x.ToString("0.00", System.Globalization.CultureInfo.InvariantCulture); + tw.WriteLine(Constants.USERATTRIBUTE + "\"POSX\":" + "\"" + posX + "\""); - if (isFromProject) - tw.WriteLine(Constants.USERATTRIBUTE + "\"ELEMENTID\":" + "\"" + singlePart.elementId + "\""); - else - tw.WriteLine(Constants.USERATTRIBUTE + "\"CUTID\":" + "\"" + singlePart.cutId + "\""); + string inv = singlePart.inverted.ToString(); + tw.WriteLine(Constants.USERATTRIBUTE + "\"INVERTED\":" + "\"" + inv + "\""); - foreach (Feature singleFeature in singlePart.features) - { - // se il processKey contiene "250" allora si tratta di un Contorno Libero e viene analizzato come tale - if (singleFeature.processKey.Contains("250")) - { - FreeContourAnalyzer(singleFeature.sag1, tw, singleFeature); + string rot = singlePart.rotated.ToString(); + tw.WriteLine(Constants.USERATTRIBUTE + "\"ROTATED\":" + "\"" + rot + "\""); + + if ( isFromProject) + tw.WriteLine(Constants.USERATTRIBUTE + "\"ELEMENTID\":" + "\"" + singlePart.elementId + "\""); + else + tw.WriteLine(Constants.USERATTRIBUTE + "\"CUTID\":" + "\"" + singlePart.cutId + "\""); + + foreach ( Feature singleFeature in singlePart.features) { + // se il processKey contiene "250" allora si tratta di un Contorno Libero e viene analizzato come tale + if ( singleFeature.processKey.Contains( "250")) { + FreeContourAnalyzer( singleFeature.sag1, tw, singleFeature); + } + else { + tw.WriteLine( Constants.PROCESS_KEY + singleFeature.processKey + " " + singleFeature.designation); + + tw.Write( Constants.PROCESS_PARAMETERS); + int i = 1 ; + foreach ( string singleParameter in singleFeature.processParameters) { + // I parametri Pnn arrivano al 26, dopo arrivano i parametri Qnn + if ( i < 27) { + + // Stampo i vari parametri Pnn + if ( i != 15 || ! (singleFeature.processKey.Contains("060") || singleFeature.processKey.Contains("061"))) + tw.Write("P" + i.ToString("D2") + ":" + MultAndConvertTo8(singleParameter) + " "); + else + tw.Write("P" + i.ToString("D2") + ":" + "\"" + singleParameter + "\" "); + + if ( i == 26) + tw.WriteLine(" "); // Vado a capo } - else - { - tw.WriteLine(Constants.PROCESS_KEY + singleFeature.processKey + " " + singleFeature.designation); - - tw.Write(Constants.PROCESS_PARAMETERS); - int i = 1; - foreach (string singleParameter in singleFeature.processParameters) - { - if (i < 27) // I parametri Pnn arrivano al 26, dopo arrivano i parametri Qnn - { - // Stampo i vari parametri Pnn - if (i != 15) - 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 diversi da 0, preceduti da "USERATTRIBUTE:" - if (!singleParameter.Equals("0")) - { - string rp = singleParameter.Replace(",", "."); - tw.WriteLine(Constants.USERATTRIBUTE + "\"Q" + (i - 26).ToString("D2") + "\":\"" + singleParameter + "\" "); - } - } - //Convert.ToInt16(i); - i++; - } - - tw.WriteLine(Constants.PROCESS_IDENT + singleFeature.processIdent); - tw.WriteLine(Constants.PROCESS + singleFeature.process); + else { + // Stampo i vari parametri Qnn diversi da 0, preceduti da "USERATTRIBUTE:" + if ( ! singleParameter.Equals( "0")) { + string rp = singleParameter.Replace(",", "."); + tw.WriteLine(Constants.USERATTRIBUTE + "\"Q" + (i - 26).ToString("D2") + "\":\"" + singleParameter + "\" "); + } } + i++; + } - if (isFromProject) - tw.WriteLine(Constants.USERATTRIBUTE + "\"PROCESSID\":" + "\"" + singleFeature.processId + "\""); - else - tw.WriteLine(Constants.USERATTRIBUTE + "\"TASKID\":" + "\"" + singleFeature.taskId + "\""); + tw.WriteLine(Constants.PROCESS_IDENT + singleFeature.processIdent); + tw.WriteLine(Constants.PROCESS + singleFeature.process); + } - } - } + if ( isFromProject) + tw.WriteLine(Constants.USERATTRIBUTE + "\"PROCESSID\":" + "\"" + singleFeature.processId + "\""); + else + tw.WriteLine(Constants.USERATTRIBUTE + "\"TASKID\":" + "\"" + singleFeature.taskId + "\""); + } } - return filePath; - } + } + return filePath; + } - // Il seguente metodo analizza il campo sag1 della singleFeature passata: se non è vuoto allora la stringa - // viene splittata nei parametri P di POLY ed analizzata - public void FreeContourAnalyzer(string sag1, StreamWriter tw, Feature singleFeature) - { - if (sag1 != "") - { - string[] arrParam = sag1.Split(new string[] { "POLY([", "),", ")],'P','O')" }, StringSplitOptions.RemoveEmptyEntries); + // Il seguente metodo analizza il campo sag1 della singleFeature passata: se non è vuoto allora la stringa + // viene splittata nei parametri P di POLY ed analizzata + public void FreeContourAnalyzer(string sag1, StreamWriter tw, Feature singleFeature) + { + if ( sag1 == "") + return ; - if (singleFeature.processParameters[37].Equals(1)) // Se il parametro Q10 è 1, l'ordine dell'array viene invertito - Array.Reverse(arrParam); + 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 incrementata 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++) - { - 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 "P": - if (i == 0) // Caso StartPoint - { - tw.WriteLine(Constants.PROCESS_KEY + singleFeature.processKey + " " + singleFeature.designation); - tw.Write(Constants.PROCESS_PARAMETERS); - tw.Write("P01:" + MultAndConvertTo8(parts[1]) + " "); // x - tw.Write("P02:" + MultAndConvertTo8(parts[2]) + " "); // y - tw.Write("P03:" + MultAndConvertTo8(parts[3]) + " "); // z - tw.Write("P05:" + Constants.EIGHT_ZEROS + " "); - tw.Write("P06:" + Constants.EIGHT_ZEROS + " "); - tw.Write("P07:" + Constants.EIGHT_ZEROS + " "); - tw.Write("P08:" + Constants.EIGHT_ZEROS + " "); - if (i == arrParam.Length - 1) // Verifica se ci troviamo all'ultimo parametro di POLY - tw.Write("P09:" + Constants.EIGHT_ZEROS + " "); // L'ultimo elemento di POLY deve avere "P09: 00000000" - else - tw.Write("P09:" + MultAndConvertTo8((Convert.ToDouble(singleFeature.processParameters[8]) + i - count).ToString()) + " "); - tw.Write("P10:" + Constants.EIGHT_ZEROS + " "); - tw.Write("P11:" + Constants.EIGHT_ZEROS + " "); - tw.Write("P12:" + Constants.EIGHT_ZEROS + " "); - tw.Write("P13:" + Constants.EIGHT_ZEROS + " "); - tw.Write("P14:" + Constants.EIGHT_ZEROS + " "); - tw.Write("P15:" + Constants.EIGHT_ZEROS + " "); - tw.WriteLine(" "); - tw.WriteLine(Constants.PROCESS_IDENT + (Convert.ToInt16(singleFeature.processIdent) + i - count)); - tw.WriteLine(Constants.PROCESS + singleFeature.process); - } - else if (flagArco) // Caso FineArco - { - count++; - flagArco = false; - } - else // Caso StraightLine - { - tw.WriteLine(Constants.PROCESS_KEY + singleFeature.processKey + " " + singleFeature.designation); - tw.Write(Constants.PROCESS_PARAMETERS); - tw.Write("P01:" + MultAndConvertTo8(parts[1]) + " "); // x - tw.Write("P02:" + MultAndConvertTo8(parts[2]) + " "); // y - tw.Write("P03:" + MultAndConvertTo8(parts[3]) + " "); // z - tw.Write("P05:" + Constants.EIGHT_ZEROS + " "); - tw.Write("P06:" + Constants.EIGHT_ZEROS + " "); - tw.Write("P07:" + Constants.EIGHT_ZEROS + " "); - tw.Write("P08:" + "00000100" + " "); - if (i == arrParam.Length - 1) - tw.Write("P09:" + Constants.EIGHT_ZEROS + " "); - else - tw.Write("P09:" + MultAndConvertTo8((Convert.ToDouble(singleFeature.processParameters[8]) + i - count).ToString()) + " "); - tw.Write("P10:" + Constants.EIGHT_ZEROS + " "); - tw.Write("P11:" + Constants.EIGHT_ZEROS + " "); - tw.Write("P12:" + Constants.EIGHT_ZEROS + " "); - tw.Write("P13:" + Constants.EIGHT_ZEROS + " "); - tw.Write("P14:" + Constants.EIGHT_ZEROS + " "); - tw.Write("P15:" + Constants.EIGHT_ZEROS + " "); - tw.WriteLine(" "); - tw.WriteLine(Constants.PROCESS_IDENT + (Convert.ToInt16(singleFeature.processIdent) + i - count)); - tw.WriteLine(Constants.PROCESS + singleFeature.process); - } - break; - case "A": // Caso InizioArco - tw.WriteLine(Constants.PROCESS_KEY + singleFeature.processKey + " " + singleFeature.designation); - tw.Write(Constants.PROCESS_PARAMETERS); - 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) - tw.Write("P05:" + Constants.EIGHT_ZEROS + " "); - tw.Write("P06:" + Constants.EIGHT_ZEROS + " "); - tw.Write("P07:" + Constants.EIGHT_ZEROS + " "); - tw.Write("P08:" + "00000200" + " "); - if (i == arrParam.Length - 1) - tw.Write("P09:" + Constants.EIGHT_ZEROS + " "); - else - tw.Write("P09:" + MultAndConvertTo8((Convert.ToDouble(singleFeature.processParameters[8]) + i - count).ToString()) + " "); - tw.Write("P10:" + MultAndConvertTo8(parts[1]) + " "); // x (Point on Arc) - tw.Write("P11:" + MultAndConvertTo8(parts[2]) + " "); // y (Point on Arc) - tw.Write("P12:" + MultAndConvertTo8(parts[3]) + " "); // z (Point on Arc) - tw.Write("P13:" + Constants.EIGHT_ZEROS + " "); - tw.Write("P14:" + Constants.EIGHT_ZEROS + " "); - tw.Write("P15:" + Constants.EIGHT_ZEROS + " "); - tw.WriteLine(" "); - tw.WriteLine(Constants.PROCESS_IDENT + (Convert.ToInt16(singleFeature.processIdent) + i - count)); - tw.WriteLine(Constants.PROCESS + singleFeature.process); - flagArco = true; - break; - default: - tw.WriteLine(Constants.PROCESS_KEY + singleFeature.processKey + " " + singleFeature.designation); - tw.Write(Constants.PROCESS_PARAMETERS); - tw.Write("P01:" + MultAndConvertTo8(parts[1]) + " "); - tw.Write("P02:" + MultAndConvertTo8(parts[2]) + " "); - tw.Write("P03:" + MultAndConvertTo8(parts[3]) + " "); - tw.Write("P05:" + Constants.EIGHT_ZEROS + " "); - tw.Write("P06:" + Constants.EIGHT_ZEROS + " "); - tw.Write("P07:" + Constants.EIGHT_ZEROS + " "); - tw.Write("P08:" + Constants.EIGHT_ZEROS + " "); - if (i == arrParam.Length - 1) - tw.Write("P09:" + Constants.EIGHT_ZEROS + " "); - else - tw.Write("P09:" + MultAndConvertTo8((Convert.ToDouble(singleFeature.processParameters[8]) + i - count).ToString()) + " "); - tw.Write("P10:" + Constants.EIGHT_ZEROS + " "); - tw.Write("P11:" + Constants.EIGHT_ZEROS + " "); - tw.Write("P12:" + Constants.EIGHT_ZEROS + " "); - tw.Write("P13:" + Constants.EIGHT_ZEROS + " "); - tw.Write("P14:" + Constants.EIGHT_ZEROS + " "); - tw.Write("P15:" + Constants.EIGHT_ZEROS + " "); - tw.WriteLine(" "); - tw.WriteLine(Constants.PROCESS_IDENT + (Convert.ToInt16(singleFeature.processIdent) + i - count)); - tw.WriteLine(Constants.PROCESS + singleFeature.process); - break; - } - } + // Se il parametro Q10 è 1, l'ordine dell'array viene invertito + if ( singleFeature.processParameters[37].Equals(1)) + Array.Reverse( arrParam) ; + + int count = 0; // Nel caso in cui ci troviamo alla fine di un Arco questa viene incrementata 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++) { + char[] separators = { ',', '(' }; + string[] parts = arrParam[i].Split(separators); // ogni parametro P di POLY viene splittato in più parti + // il primo elemento di parts[] indica se ci troviamo all'inizio di un Arco o no + switch (parts[0]) { + case "P": + // Se StartPoint + if ( i == 0) { + tw.WriteLine(Constants.PROCESS_KEY + singleFeature.processKey + " " + singleFeature.designation); + tw.Write(Constants.PROCESS_PARAMETERS); + tw.Write("P01:" + MultAndConvertTo8(parts[1]) + " "); // x + tw.Write("P02:" + MultAndConvertTo8(parts[2]) + " "); // y + tw.Write("P03:" + MultAndConvertTo8(parts[3]) + " "); // z + tw.Write("P05:" + Constants.EIGHT_ZEROS + " "); + tw.Write("P06:" + Constants.EIGHT_ZEROS + " "); + tw.Write("P07:" + Constants.EIGHT_ZEROS + " "); + tw.Write("P08:" + Constants.EIGHT_ZEROS + " "); + if ( i == arrParam.Length - 1) // Verifica se ci troviamo all'ultimo parametro di POLY + tw.Write("P09:" + Constants.EIGHT_ZEROS + " "); // L'ultimo elemento di POLY deve avere "P09: 00000000" + else + tw.Write("P09:" + MultAndConvertTo8((Convert.ToDouble(singleFeature.processParameters[8]) + i - count).ToString()) + " "); + tw.Write("P10:" + Constants.EIGHT_ZEROS + " "); + tw.Write("P11:" + Constants.EIGHT_ZEROS + " "); + tw.Write("P12:" + Constants.EIGHT_ZEROS + " "); + tw.Write("P13:" + Constants.EIGHT_ZEROS + " "); + tw.Write("P14:" + Constants.EIGHT_ZEROS + " "); + tw.Write("P15:" + Constants.EIGHT_ZEROS + " "); + tw.WriteLine(" "); + tw.WriteLine(Constants.PROCESS_IDENT + (Convert.ToInt16(singleFeature.processIdent) + i - count)); + tw.WriteLine(Constants.PROCESS + singleFeature.process); + } + // altrimenti se FineArco + else if ( flagArco) { + count++; + flagArco = false ; + } + // altrimenti FineSegmento + else { + tw.WriteLine(Constants.PROCESS_KEY + singleFeature.processKey + " " + singleFeature.designation); + tw.Write(Constants.PROCESS_PARAMETERS); + tw.Write("P01:" + MultAndConvertTo8(parts[1]) + " "); // x + tw.Write("P02:" + MultAndConvertTo8(parts[2]) + " "); // y + tw.Write("P03:" + MultAndConvertTo8(parts[3]) + " "); // z + tw.Write("P05:" + Constants.EIGHT_ZEROS + " "); + tw.Write("P06:" + Constants.EIGHT_ZEROS + " "); + tw.Write("P07:" + Constants.EIGHT_ZEROS + " "); + tw.Write("P08:" + "00000100" + " "); + if ( i == arrParam.Length - 1) + tw.Write("P09:" + Constants.EIGHT_ZEROS + " "); + else + tw.Write("P09:" + MultAndConvertTo8((Convert.ToDouble(singleFeature.processParameters[8]) + i - count).ToString()) + " "); + tw.Write("P10:" + Constants.EIGHT_ZEROS + " "); + tw.Write("P11:" + Constants.EIGHT_ZEROS + " "); + tw.Write("P12:" + Constants.EIGHT_ZEROS + " "); + tw.Write("P13:" + Constants.EIGHT_ZEROS + " "); + tw.Write("P14:" + Constants.EIGHT_ZEROS + " "); + tw.Write("P15:" + Constants.EIGHT_ZEROS + " "); + tw.WriteLine(" "); + tw.WriteLine(Constants.PROCESS_IDENT + (Convert.ToInt16(singleFeature.processIdent) + i - count)); + tw.WriteLine(Constants.PROCESS + singleFeature.process); + } + break; + case "A": // Caso InizioArco + tw.WriteLine(Constants.PROCESS_KEY + singleFeature.processKey + " " + singleFeature.designation); + tw.Write(Constants.PROCESS_PARAMETERS); + 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) + tw.Write("P05:" + Constants.EIGHT_ZEROS + " "); + tw.Write("P06:" + Constants.EIGHT_ZEROS + " "); + tw.Write("P07:" + Constants.EIGHT_ZEROS + " "); + tw.Write("P08:" + "00000200" + " "); + if ( i == arrParam.Length - 1) + tw.Write("P09:" + Constants.EIGHT_ZEROS + " "); + else + tw.Write("P09:" + MultAndConvertTo8((Convert.ToDouble(singleFeature.processParameters[8]) + i - count).ToString()) + " "); + tw.Write("P10:" + MultAndConvertTo8(parts[1]) + " "); // x (Point on Arc) + tw.Write("P11:" + MultAndConvertTo8(parts[2]) + " "); // y (Point on Arc) + tw.Write("P12:" + MultAndConvertTo8(parts[3]) + " "); // z (Point on Arc) + tw.Write("P13:" + Constants.EIGHT_ZEROS + " "); + tw.Write("P14:" + Constants.EIGHT_ZEROS + " "); + tw.Write("P15:" + Constants.EIGHT_ZEROS + " "); + tw.WriteLine(" "); + tw.WriteLine(Constants.PROCESS_IDENT + (Convert.ToInt16(singleFeature.processIdent) + i - count)); + tw.WriteLine(Constants.PROCESS + singleFeature.process); + flagArco = true; + break; + default: + tw.WriteLine(Constants.PROCESS_KEY + singleFeature.processKey + " " + singleFeature.designation); + tw.Write(Constants.PROCESS_PARAMETERS); + tw.Write("P01:" + MultAndConvertTo8(parts[1]) + " "); + tw.Write("P02:" + MultAndConvertTo8(parts[2]) + " "); + tw.Write("P03:" + MultAndConvertTo8(parts[3]) + " "); + tw.Write("P05:" + Constants.EIGHT_ZEROS + " "); + tw.Write("P06:" + Constants.EIGHT_ZEROS + " "); + tw.Write("P07:" + Constants.EIGHT_ZEROS + " "); + tw.Write("P08:" + Constants.EIGHT_ZEROS + " "); + if ( i == arrParam.Length - 1) + tw.Write("P09:" + Constants.EIGHT_ZEROS + " "); + else + tw.Write("P09:" + MultAndConvertTo8((Convert.ToDouble(singleFeature.processParameters[8]) + i - count).ToString()) + " "); + tw.Write("P10:" + Constants.EIGHT_ZEROS + " "); + tw.Write("P11:" + Constants.EIGHT_ZEROS + " "); + tw.Write("P12:" + Constants.EIGHT_ZEROS + " "); + tw.Write("P13:" + Constants.EIGHT_ZEROS + " "); + tw.Write("P14:" + Constants.EIGHT_ZEROS + " "); + tw.Write("P15:" + Constants.EIGHT_ZEROS + " "); + tw.WriteLine(" "); + tw.WriteLine(Constants.PROCESS_IDENT + (Convert.ToInt16(singleFeature.processIdent) + i - count)); + tw.WriteLine(Constants.PROCESS + singleFeature.process); + break; } - } + } + } - // 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) - { - double sp = 0; - string rp = processParameter.Replace(",", "."); - sp = (Convert.ToDouble(rp, CultureInfo.InvariantCulture)) * Math.Pow(10, Constants.scaleUnit); - int intSp = (Convert.ToInt32(sp)); - string s8 = intSp.ToString("D8"); - return s8; - } + // 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) + { + double sp = 0; + string rp = processParameter.Replace(",", "."); + sp = (Convert.ToDouble(rp, CultureInfo.InvariantCulture)) * Math.Pow(10, Constants.scaleUnit); + int intSp = (Convert.ToInt32(sp)); + string s8 = intSp.ToString("D8"); + return s8; + } - // Le 2 seguenti struct dichiarano i campi necessari alla costruzione di una Part e di una Feature - public struct Part - { - public string singleMemberNumber; - public string count; - public string length; - public string height; - public string width; - public List features; - public double x; - public string inverted; - public string rotated; - public int elementId; - public int cutId; - } - - public struct Feature - { - public string taskId; - public string processKey; - public string designation; - public List processParameters; - public string processIdent; - public string process; - public string sag1; - public string processId; - } + // Le 2 seguenti struct dichiarano i campi necessari alla costruzione di una Part e di una Feature + public struct Part + { + public string singleMemberNumber; + public string count; + public string length; + public string height; + public string width; + public List features; + public double x; + public string inverted; + public string rotated; + public int elementId; + public int cutId; + } + public struct Feature + { + public string taskId; + public string processKey; + public string designation; + public List processParameters; + public string processIdent; + public string process; + public string sag1; + public string processId; + } } } diff --git a/IntegrationEgaltech/Generator.cs b/IntegrationEgaltech/Generator.cs index a44f0e1..9a6b26f 100644 --- a/IntegrationEgaltech/Generator.cs +++ b/IntegrationEgaltech/Generator.cs @@ -13,630 +13,529 @@ using ib.essetre.integration.egaltech; namespace ib.essetre.integration.egaltech { - public class Generator : ib.essetre.integration.IGenerator - { - public System.Threading.Thread _thread; - public static DataSet ds = new DataSet(); - //public static BTL btlObject = new BTL(); + public class Generator : ib.essetre.integration.IGenerator + { + public System.Threading.Thread _thread; + public static DataSet ds = new DataSet(); + //public static BTL btlObject = new BTL(); - public Generator() - { - Console.WriteLine("Inizializzato"); - } + public Generator() + { + Console.WriteLine("Inizializzato"); + } - //public void Run(BTL btlObject, ICallBack callback) - //{ - // _thread = new Thread(() => DoJob(btlObject, callback)); - // _thread.Start(); - //} + public void Run(InOutParameters parameters, ICallBack callback) + { + _thread = new Thread(() => DoJob( parameters, callback)) ; - //private static void DoJob(BTL btlObject, ICallBack callback) - //{ - // string filePath = btlObject.writeIntoFile(); // Constants.fullPath); - // System.Windows.Forms.MessageBox.Show("File scritto!"); - // //System.Diagnostics.Process.Start(filePath); - // Process process = Process.Start("C:\\EgtProg\\EgtCAM5\\EgtCAM5R32.exe", "\"" + filePath + "\""); - // string cMyProcessName = process.ProcessName; - // Process[] processlist = Process.GetProcessesByName(cMyProcessName); - // while (processlist.Length != 0) - // { - // Console.WriteLine("Il processo EgtCAM5 è attivo."); - // Thread.Sleep(10000); - // processlist = Process.GetProcessesByName(cMyProcessName); - // } - //} + _thread.Start() ; + } - public void Run(InOutParameters parameters, ICallBack callback) - { - _thread = new Thread(() => DoJob(parameters, callback)); + private delegate void dDoJob( InOutParameters parameters, ICallBack callback) ; - _thread.Start(); - } + // campo data ultima modifica nel DATABASE [lastModified] + private static void DoJob( InOutParameters parameters, ICallBack callback) + { + callback.Progress( 0, "Init") ; - private delegate void dDoJob(InOutParameters parameters, ICallBack callback); + String ExePath = parameters.Read( "EGALTECH", "PATH_EXE", "") ; + String BtlDir = parameters.Read( "EGALTECH", "DIR_BTL", "") ; - //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); + int numBars = parameters.Patterns.Length ; - callback.Progress(0, "Init"); + for ( int i = 0; i < numBars; i++) { - String percorsoExe = parameters.Read("EGALTECH", "PATH_EXE", ""); + BTL btlObject = new BTL() ; - //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 - //int timeout = parameters.Timeout; //numero millisecondo per l'elaborazione + String sqlProduction = "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 = " + (Int32)parameters.Patterns[i].PatternId + + " and vw_Task.productionId = " + (Int32)parameters.Patterns[i].ProductionId; - //parameters.UIMode = InOutParameters.UIModes.HIDDEN //nascosto - //parameters.UIMode = InOutParameters.UIModes.SHOWUI //con interfaccia - //parameters.Owner // Form padre da specificare, opzionale - //CHECK = 3, - //HIDDEN = 0, - //SHOWUI = 1, - //SIMULAZIONE = 2 + String sqlProject = "SELECT vw_Process.projectId, " + + "vw_Process.elementId, cutId, processId, info1, info2, enabled, level, " + + "inTools, outTools, isChecked, vw_Process.done, isoType, ax, ay, az, vw_Process.x, vw_Process.y, vw_Process.z, " + + "vw_Process.flagDeleted, vw_Process.[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, productionId, patternId, cutId, cutStart, cutEnd, " + + "inverted, rotated, doneTime, startAngle, endAngle, referenceCutId, vw_Cut.length, vw_Cut.width, vw_Cut.height " + + "FROM ESSETRE.dbo.vw_Process " + + "INNER JOIN vw_Cut ON " + + "(vw_Cut.projectId = vw_Process.projectId AND vw_Cut.elementId = vw_Process.elementId) " + + "WHERE vw_Process.projectId = " + (Int32)parameters.Patterns[i].ProjectId + + " and vw_Process.elementId = " + (Int32)parameters.Patterns[i].ElementId; - //String percorsoExe = parameters.Read("EGTCAM5", "PATH_EXE", ""); //Config.ini - //String connectionString = parameters.ConnectionString; - //parameters.Patterns(0).OutputFilename + string sql = null ; - // 2 PARAMETRI AGGIUNTI DA NOI - //parameters.Flag; - //parameters.Modifiable; + // Se il parametro IsFromProject è TRUE viene eseguita la query sulle tabelle Project, + // se invece è FALSE viene eseguita la query sulle tabelle Production + if ( parameters.Patterns[i].IsFromProject) + sql = sqlProject ; + else + sql = sqlProduction ; - //using (System.Data.SqlClient.SqlConnection cn = new System.Data.SqlClient.SqlConnection(connectionString)) - //{ - //cn.Open(); + // 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) ; - //String sql = $"SELECT [cutId],[projectId],[elementId],[x],[y],[z],[cutStart],[cutEnd],[inverted],[rotated],[done],[doneTime], [startAngle],[endAngle]," - // + "[referenceCutId], [length], [width], [height] FROM[dbo].[vw_Cut] WHERE[productionId] = @productionId and[patternId] = @patternId"; + // Lettura DB e riempimento DataSet + var tempDs = new DataSet() ; + dataAdapter.Fill( tempDs) ; - int numBars = parameters.Patterns.Length; + // 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]) ; - for (int i = 0; i < numBars; i++) - { - BTL btlObject = new BTL(); + ds.Tables.Add( tempDs.Tables[0].Copy()) ; - String sqlProduction = "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 = " + (Int32)parameters.Patterns[i].PatternId + - " and vw_Task.productionId = " + (Int32)parameters.Patterns[i].ProductionId; + // 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, 0) ; + else + getListaTasks( btlObject, 0) ; - String sqlProject = "SELECT vw_Process.projectId, " + - "vw_Process.elementId, cutId, processId, info1, info2, enabled, level, " + - "inTools, outTools, isChecked, vw_Process.done, isoType, ax, ay, az, vw_Process.x, vw_Process.y, vw_Process.z, " + - "vw_Process.flagDeleted, vw_Process.[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, productionId, patternId, cutId, cutStart, cutEnd, " + - "inverted, rotated, doneTime, startAngle, endAngle, referenceCutId, vw_Cut.length, vw_Cut.width, vw_Cut.height " + - "FROM ESSETRE.dbo.vw_Process " + - //"INNER JOIN vw_Element ON " + - //"(vw_Process.projectId = vw_Element.projectId AND vw_Process.elementId = vw_Element.elementId) " + - "INNER JOIN vw_Cut ON " + - "(vw_Cut.projectId = vw_Process.projectId AND vw_Cut.elementId = vw_Process.elementId) " + - "WHERE vw_Process.projectId = " + (Int32)parameters.Patterns[i].ProjectId + - " and vw_Process.elementId = " + (Int32)parameters.Patterns[i].ElementId; + // Dialog con Progress Bar + float progValue = (float)1 / numBars ; + callback.Progress( progValue * (i + 1), + " Progresso: " + (progValue * (i + 1) * 100) + "%" + "\n" + + " BTL generati: " + (i + 1) + " su " + numBars) ; - string sql = null; + // 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 BtlPath = btlObject.writeIntoFile( parameters.Patterns[i].IsFromProject, BtlDir) ; - // Se il parametro IsFromProject è TRUE viene eseguita la query sulle tabelle Project, - // se invece è FALSE viene eseguita la query sulle tabelle Production - if (parameters.Patterns[i].IsFromProject) - sql = sqlProject; - else - sql = sqlProduction; + string path = "\"" + BtlPath + "\" " + parameters.MachineName + " " + + (int)parameters.UIMode + " " + parameters.Patterns[i].OutputFilename ; + Process process = Process.Start( ExePath, path) ; - //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); - - //Lettura DB e riempimento DataSEt - var tempDs = new DataSet(); - dataAdapter.Fill(tempDs); - - //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()); - - //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); - - //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); - - //Lettura OutputFilename e scrittura nel parametro stringa Iso (solo nel caso UIModes.HIDDEN) - if (parameters.UIMode == InOutParameters.UIModes.HIDDEN) - { - string[] lines = System.IO.File.ReadAllLines(parameters.Patterns[i].OutputFilename); //"C:\\TechnoEssetre7\\Catalog\\Iso\\000003\\1.xpi" - var sb = new System.Text.StringBuilder(); - for (int line = 0; line < lines.Length; line ++) - { - sb.AppendLine(lines[line].ToString()); - } - parameters.Patterns[i].Iso += sb.ToString(); - - //Lascio qui di seguito commentato ciò che facevamo prima, ovvero - //scrivere il file .xpi e salvarne il percorso in Iso - //string txtToXpi = filePath.Replace(".btl", ".txt"); - //using (var txtWrite = new StreamWriter(txtToXpi, false)) - //{ - // foreach (string line in lines) - // { - // txtWrite.WriteLine(line); - // } - //} - //if (File.Exists(txtToXpi.Replace(".txt", ".xpi"))) - // File.Delete(txtToXpi.Replace(".txt", ".xpi")); - //File.Move(txtToXpi, Path.ChangeExtension(txtToXpi, ".xpi")); - ////string fileCN = String.Format("{0}.xpi", txtToXpi); - //DateTime d1 = File.GetLastWriteTime(txtToXpi.Replace(".txt", ".xpi")); - //DateTime d2 = File.GetLastWriteTime(filePath); - //if (DateTime.Compare(d1, d2) >= 0) - //{ - // //Se la data modifica del file .xpi è più recente del BTL: OK, restuirlo alla stringa Iso, altrimenti niente, non restituirlo a Iso - // parameters.Patterns[i].Iso = txtToXpi.Replace(".txt", ".xpi"); - //} - } - - - - 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, - // il programma cicla in questo while all'infinito ---> SISTEMARE - System.Threading.Thread.Sleep(1000); - } - - int cutId = 1; - int taskId = 2; - string text = System.IO.File.ReadAllText(filePath.Replace(".btl", ".txt")); - if(text.Contains("ERR=0")) - parameters.Patterns[i].SetTaskState(cutId, taskId, PatternInfo.Results.OK, text); - else - parameters.Patterns[i].SetTaskState(cutId, taskId, PatternInfo.Results.ERROR, text); - - PatternInfo.Results res; - string msg; - parameters.Patterns[i].GetTaskState(cutId, taskId, out res, out msg); - System.Windows.Forms.MessageBox.Show(msg, res.ToString()); - - string cMyProcessName = "EgtCAM5R32"; - Process[] processlist = Process.GetProcessesByName(cMyProcessName); - while (processlist.Length != 0) - { - processlist = Process.GetProcessesByName(cMyProcessName); - while (processlist.Length != 0) //(processlist.Length == 0) - { - Thread.Sleep(5000); - processlist = Process.GetProcessesByName(cMyProcessName); - } - } - - ////imposta le modifiche - ////solo se parameters.Patterns[i].Transformable - //parameters.Patterns[i].AddCutChange(2, "inverted", 180); - //parameters.Patterns[i].AddPatternChange("StartX", 20); - - //public enum Results - //{ - // NONE = 0, - // OK = 1, - // ERROR = 2 - //} - - ////fattibile o non fattibile - ////parameters.Patterns[i].Iso;=.... //stringa iso - ////parameters.Patterns[i].OutputFilename; //nome file da generare - ////parameters.Patterns[i].SetTaskState(cutId, taskId, value, message); //Cutid del db - //parameters.Patterns[i].Result = PatternInfo.Results.OK; - //parameters.Patterns[i].Message = ""; //eventuale errore messaggio - // } - - //esempio di apertura db, usare solo le viste (iniziano per vw_) - // chiavi - //parameters.Patterns(0).ProductionId - - //cn.Close(); - //} - - } - - //callback.Progress(0, "Init"); //mostra descrizione a video con progressione 0-1 (0-100%) - //System.Threading.Thread.Sleep(5000); //qui calcola 'pausa solo di test - //callback.Progress(0.5F, "Init2"); - //System.Threading.Thread.Sleep(5000); // solo di test - //callback.Progress(1, "End"); - - //per tutti gli schemi parameters.Patterns.Length - //parameters.UIMode = InOutParameters.UIModes.SHOWUI //mostrare il vostro programma - - callback.Progress(1, "End"); - - callback.Done(parameters); //fine - } - - public void Abort() - { - //non implementata al momento - } - - // 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) - { - Int32 listaTasksCount = ds.Tables[i].Rows.Count; - Int32 TaskElementsCount = ds.Tables[i].Columns.Count; - - 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[0]["productionId"])); - btlObject.parts = new List(); - - btlObject.productionId = (int)ds.Tables[i].Rows[0]["productionId"]; - btlObject.patternId = (int)ds.Tables[i].Rows[0]["patternId"]; - - List ListaCutParts = new List(); - ListaCutParts = getListaCutIdP((int)ds.Tables[i].Rows[0]["patternId"], - (int)ds.Tables[i].Rows[i]["productionId"]); - - //RunIntegration(); - - if (listaTasksCount > 0) - { - for (int c = 0; c < ListaCutParts.Count; c++) - { - BTL.Part readPart = new BTL.Part(); - - for (int ltc = 0; ltc < listaTasksCount; ltc++) - { - if ((int)ds.Tables[i].Rows[ltc]["cutId"] == ListaCutParts[c]) - { - readPart.singleMemberNumber = ds.Tables[i].Rows[ltc]["productionId"].ToString(); - readPart.count = Convert.ToString(1); // Deve essere 1 o tanto quante sono le Part? - readPart.length = ds.Tables[i].Rows[ltc]["length"].ToString(); - readPart.height = ds.Tables[i].Rows[ltc]["height"].ToString(); - readPart.width = ds.Tables[i].Rows[ltc]["width"].ToString(); - 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(); - - for (int f = 0; f < listaTasksCount; f++) - { - if ((int)ds.Tables[i].Rows[f]["cutId"] == ListaCutParts[c]) - { - BTL.Feature readFeature = new BTL.Feature(); - - readFeature.taskId = ds.Tables[i].Rows[f]["taskId"].ToString(); - - readFeature.processKey = ds.Tables[i].Rows[f]["group"].ToString() + - "-" + ds.Tables[i].Rows[f]["key"].ToString().Substring(1, 3) + - "-" + ds.Tables[i].Rows[f]["face"].ToString(); - readFeature.designation = ds.Tables[i].Rows[f]["des"].ToString(); - readFeature.processIdent = ds.Tables[i].Rows[f]["processIdent"].ToString(); - readFeature.sag1 = ds.Tables[i].Rows[f]["sag1"].ToString(); - - if (Convert.ToInt16(ds.Tables[i].Rows[f]["enabled"]) == 1) - readFeature.process = Convert.ToString("YES"); - else if (Convert.ToInt16(ds.Tables[i].Rows[f]["enabled"]) == 0) - readFeature.process = Convert.ToString("NO"); - - readFeature.processParameters = new List(); - readFeature.processParameters.Add(ds.Tables[i].Rows[f]["p01"].ToString()); - readFeature.processParameters.Add(ds.Tables[i].Rows[f]["p02"].ToString()); - readFeature.processParameters.Add(ds.Tables[i].Rows[f]["p03"].ToString()); - readFeature.processParameters.Add(ds.Tables[i].Rows[f]["p04"].ToString()); - readFeature.processParameters.Add(ds.Tables[i].Rows[f]["p05"].ToString()); - readFeature.processParameters.Add(ds.Tables[i].Rows[f]["p06"].ToString()); - readFeature.processParameters.Add(ds.Tables[i].Rows[f]["p07"].ToString()); - readFeature.processParameters.Add(ds.Tables[i].Rows[f]["p08"].ToString()); - readFeature.processParameters.Add(ds.Tables[i].Rows[f]["p09"].ToString()); - readFeature.processParameters.Add(ds.Tables[i].Rows[f]["p10"].ToString()); - readFeature.processParameters.Add(ds.Tables[i].Rows[f]["p11"].ToString()); - readFeature.processParameters.Add(ds.Tables[i].Rows[f]["p12"].ToString()); - readFeature.processParameters.Add(ds.Tables[i].Rows[f]["p13"].ToString()); - readFeature.processParameters.Add(ds.Tables[i].Rows[f]["p14"].ToString()); - readFeature.processParameters.Add(ds.Tables[i].Rows[f]["p15"].ToString()); - readFeature.processParameters.Add(ds.Tables[i].Rows[f]["p16"].ToString()); - readFeature.processParameters.Add(ds.Tables[i].Rows[f]["p17"].ToString()); - readFeature.processParameters.Add(ds.Tables[i].Rows[f]["p18"].ToString()); - readFeature.processParameters.Add(ds.Tables[i].Rows[f]["p19"].ToString()); - readFeature.processParameters.Add(ds.Tables[i].Rows[f]["p20"].ToString()); - readFeature.processParameters.Add(ds.Tables[i].Rows[f]["p21"].ToString()); - readFeature.processParameters.Add(ds.Tables[i].Rows[f]["p22"].ToString()); - readFeature.processParameters.Add(ds.Tables[i].Rows[f]["p23"].ToString()); - readFeature.processParameters.Add(ds.Tables[i].Rows[f]["p24"].ToString()); - readFeature.processParameters.Add(ds.Tables[i].Rows[f]["p25"].ToString()); - readFeature.processParameters.Add(ds.Tables[i].Rows[f]["p26"].ToString()); - - readFeature.processParameters.Add(ds.Tables[i].Rows[f]["q01"].ToString()); - readFeature.processParameters.Add(ds.Tables[i].Rows[f]["q02"].ToString()); - readFeature.processParameters.Add(ds.Tables[i].Rows[f]["q03"].ToString()); - readFeature.processParameters.Add(ds.Tables[i].Rows[f]["q04"].ToString()); - readFeature.processParameters.Add(ds.Tables[i].Rows[f]["q05"].ToString()); - readFeature.processParameters.Add(ds.Tables[i].Rows[f]["q06"].ToString()); - readFeature.processParameters.Add(ds.Tables[i].Rows[f]["q07"].ToString()); - readFeature.processParameters.Add(ds.Tables[i].Rows[f]["q08"].ToString()); - readFeature.processParameters.Add(ds.Tables[i].Rows[f]["q09"].ToString()); - readFeature.processParameters.Add(ds.Tables[i].Rows[f]["q10"].ToString()); - readFeature.processParameters.Add(ds.Tables[i].Rows[f]["q11"].ToString()); - readFeature.processParameters.Add(ds.Tables[i].Rows[f]["q12"].ToString()); - readFeature.processParameters.Add(ds.Tables[i].Rows[f]["q13"].ToString()); - readFeature.processParameters.Add(ds.Tables[i].Rows[f]["q14"].ToString()); - readFeature.processParameters.Add(ds.Tables[i].Rows[f]["q15"].ToString()); - readFeature.processParameters.Add(ds.Tables[i].Rows[f]["q16"].ToString()); - readFeature.processParameters.Add(ds.Tables[i].Rows[f]["q17"].ToString()); - readFeature.processParameters.Add(ds.Tables[i].Rows[f]["q18"].ToString()); - readFeature.processParameters.Add(ds.Tables[i].Rows[f]["q19"].ToString()); - readFeature.processParameters.Add(ds.Tables[i].Rows[f]["q20"].ToString()); - - readPart.features.Add(readFeature); - } - } - } - btlObject.parts.Add(readPart); - } + // Attendo il termine del processo + while ( ! process.HasExited) { + process.Refresh() ; + System.Threading.Thread.Sleep( 50) ; } - // L'ordinamento delle Part in un oggetto BTL avviene col confronto del parametro x, estratto dalla tabella vw_Cut - btlObject.parts.Sort((p, q) => p.x.CompareTo(q.x)); - } - // Il seguente metodo prende i record visualizzati in ds (Caso: Ordine) e li carica in un oggetto BTL - public static void getListaProcesses(BTL btlObject, int i) - { - Int32 listaProcessesCount = ds.Tables[i].Rows.Count; - Int32 ProcessElementsCount = ds.Tables[i].Columns.Count; - - btlObject.projectNumber = ds.Tables[i].Rows[0]["projectId"].ToString(); - btlObject.scaleUnit = Convert.ToString(2); - 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"]; - btlObject.elementId = (int)ds.Tables[i].Rows[0]["elementId"]; - - List ListaCutParts = new List(); - ListaCutParts = getListaCutIdO((int)ds.Tables[i].Rows[0]["elementId"], - (int)ds.Tables[i].Rows[0]["projectId"]); - - //RunIntegration(); - - if (listaProcessesCount > 0) - { - for (int c = 0; c < ListaCutParts.Count; c++) - { - BTL.Part readPart = new BTL.Part(); - - for (int ltc = 0; ltc < listaProcessesCount; ltc++) - { - if ((int)ds.Tables[i].Rows[ltc]["cutId"] == ListaCutParts[c]) - { - readPart.singleMemberNumber = " "; // ds.Tables[0].Rows[ltc]["productionId"].ToString(); //In questo caso ci vuole? - readPart.count = Convert.ToString(1); // Deve essere 1 o tanto quante sono le Part? - readPart.length = ds.Tables[i].Rows[ltc]["length"].ToString(); - readPart.height = ds.Tables[i].Rows[ltc]["height"].ToString(); - readPart.width = ds.Tables[i].Rows[ltc]["width"].ToString(); - 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(); - - for (int f = 0; f < listaProcessesCount; f++) - { - if ((int)ds.Tables[i].Rows[f]["cutId"] == ListaCutParts[c]) - { - BTL.Feature readFeature = new BTL.Feature(); - - 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) + - "-" + ds.Tables[i].Rows[f]["face"].ToString(); - readFeature.designation = ds.Tables[i].Rows[f]["des"].ToString(); - readFeature.processIdent = ds.Tables[i].Rows[f]["processIdent"].ToString(); - readFeature.sag1 = ds.Tables[i].Rows[f]["sag1"].ToString(); - - if (Convert.ToInt16(ds.Tables[i].Rows[f]["enabled"]) == 1) - readFeature.process = Convert.ToString("YES"); - else if (Convert.ToInt16(ds.Tables[i].Rows[f]["enabled"]) == 0) - readFeature.process = Convert.ToString("NO"); - - readFeature.processParameters = new List(); - readFeature.processParameters.Add(ds.Tables[i].Rows[f]["p01"].ToString()); - readFeature.processParameters.Add(ds.Tables[i].Rows[f]["p02"].ToString()); - readFeature.processParameters.Add(ds.Tables[i].Rows[f]["p03"].ToString()); - readFeature.processParameters.Add(ds.Tables[i].Rows[f]["p04"].ToString()); - readFeature.processParameters.Add(ds.Tables[i].Rows[f]["p05"].ToString()); - readFeature.processParameters.Add(ds.Tables[i].Rows[f]["p06"].ToString()); - readFeature.processParameters.Add(ds.Tables[i].Rows[f]["p07"].ToString()); - readFeature.processParameters.Add(ds.Tables[i].Rows[f]["p08"].ToString()); - readFeature.processParameters.Add(ds.Tables[i].Rows[f]["p09"].ToString()); - readFeature.processParameters.Add(ds.Tables[i].Rows[f]["p10"].ToString()); - readFeature.processParameters.Add(ds.Tables[i].Rows[f]["p11"].ToString()); - readFeature.processParameters.Add(ds.Tables[i].Rows[f]["p12"].ToString()); - readFeature.processParameters.Add(ds.Tables[i].Rows[f]["p13"].ToString()); - readFeature.processParameters.Add(ds.Tables[i].Rows[f]["p14"].ToString()); - readFeature.processParameters.Add(ds.Tables[i].Rows[f]["p15"].ToString()); - readFeature.processParameters.Add(ds.Tables[i].Rows[f]["p16"].ToString()); - readFeature.processParameters.Add(ds.Tables[i].Rows[f]["p17"].ToString()); - readFeature.processParameters.Add(ds.Tables[i].Rows[f]["p18"].ToString()); - readFeature.processParameters.Add(ds.Tables[i].Rows[f]["p19"].ToString()); - readFeature.processParameters.Add(ds.Tables[i].Rows[f]["p20"].ToString()); - readFeature.processParameters.Add(ds.Tables[i].Rows[f]["p21"].ToString()); - readFeature.processParameters.Add(ds.Tables[i].Rows[f]["p22"].ToString()); - readFeature.processParameters.Add(ds.Tables[i].Rows[f]["p23"].ToString()); - readFeature.processParameters.Add(ds.Tables[i].Rows[f]["p24"].ToString()); - readFeature.processParameters.Add(ds.Tables[i].Rows[f]["p25"].ToString()); - readFeature.processParameters.Add(ds.Tables[i].Rows[f]["p26"].ToString()); - - readFeature.processParameters.Add(ds.Tables[i].Rows[f]["q01"].ToString()); - readFeature.processParameters.Add(ds.Tables[i].Rows[f]["q02"].ToString()); - readFeature.processParameters.Add(ds.Tables[i].Rows[f]["q03"].ToString()); - readFeature.processParameters.Add(ds.Tables[i].Rows[f]["q04"].ToString()); - readFeature.processParameters.Add(ds.Tables[i].Rows[f]["q05"].ToString()); - readFeature.processParameters.Add(ds.Tables[i].Rows[f]["q06"].ToString()); - readFeature.processParameters.Add(ds.Tables[i].Rows[f]["q07"].ToString()); - readFeature.processParameters.Add(ds.Tables[i].Rows[f]["q08"].ToString()); - readFeature.processParameters.Add(ds.Tables[i].Rows[f]["q09"].ToString()); - readFeature.processParameters.Add(ds.Tables[i].Rows[f]["q10"].ToString()); - readFeature.processParameters.Add(ds.Tables[i].Rows[f]["q11"].ToString()); - readFeature.processParameters.Add(ds.Tables[i].Rows[f]["q12"].ToString()); - readFeature.processParameters.Add(ds.Tables[i].Rows[f]["q13"].ToString()); - readFeature.processParameters.Add(ds.Tables[i].Rows[f]["q14"].ToString()); - readFeature.processParameters.Add(ds.Tables[i].Rows[f]["q15"].ToString()); - readFeature.processParameters.Add(ds.Tables[i].Rows[f]["q16"].ToString()); - readFeature.processParameters.Add(ds.Tables[i].Rows[f]["q17"].ToString()); - readFeature.processParameters.Add(ds.Tables[i].Rows[f]["q18"].ToString()); - readFeature.processParameters.Add(ds.Tables[i].Rows[f]["q19"].ToString()); - readFeature.processParameters.Add(ds.Tables[i].Rows[f]["q20"].ToString()); - - readPart.features.Add(readFeature); - } - } - } - btlObject.parts.Add(readPart); - } + // Recupero il risultato + int cutId = 0 ; + int taskId = 0 ; + PatternInfo.Results resExe = PatternInfo.Results.NONE ; + string textErr = "" ; + if ( File.Exists( Path.ChangeExtension( BtlPath, ".txt"))) { + 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 ; + } + else if ( line.StartsWith( "CUTID=")) { + int? nVal = GetVal( line, "CUTID") ; + if ( nVal != null) + cutId = nVal.Value ; + } + else if ( line.StartsWith( "TASKID=")) { + int? nVal = GetVal( line, "TASKID") ; + if ( nVal != null) + taskId = nVal.Value ; + } + else if ( ! string.IsNullOrWhiteSpace( line)) + textErr = line ; + } } - // L'ordinamento delle Part in un oggetto BTL avviene col confronto del parametro x, estratto dalla tabella vw_Cut - btlObject.parts.Sort((p, q) => p.x.CompareTo(q.x)); - } + parameters.Patterns[i].SetTaskState( cutId, taskId, resExe, textErr) ; - // 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) - { - List ListaCutId = new List(); + PatternInfo.Results res ; + string msg ; + parameters.Patterns[i].GetTaskState( cutId, taskId, out res, out msg) ; + System.Windows.Forms.MessageBox.Show( msg, res.ToString()) ; - string sqlCutId = "SELECT cutId FROM dbo.vw_Cut WHERE patternId = " + patternId + - "AND productionId = " + productionId; + // Lettura OutputFilename e scrittura nel parametro stringa Iso (solo nel caso UIModes.HIDDEN) + if ( parameters.UIMode == InOutParameters.UIModes.HIDDEN) { - using (SqlConnection cn = new SqlConnection(Constants.ConnectionString)) - { - cn.Open(); - SqlCommand sqlCommand = new SqlCommand(sqlCutId, cn); - SqlDataReader reader = sqlCommand.ExecuteReader(); - while (reader.Read()) - { - ListaCutId.Add((int)reader["cutId"]); - } - cn.Close(); + string CncPath = Path.ChangeExtension( BtlPath, ".cnc") ; + if ( File.Exists( CncPath)) { + string lines = System.IO.File.ReadAllText( CncPath) ; + parameters.Patterns[i].Iso = lines ; + } + else + parameters.Patterns[i].Iso = "" ; + + ////imposta le modifiche + ////solo se parameters.Patterns[i].Transformable + //parameters.Patterns[i].AddCutChange(2, "inverted", 180); + //parameters.Patterns[i].AddPatternChange("StartX", 20); + + //public enum Results + //{ + // NONE = 0, + // OK = 1, + // ERROR = 2 + //} + + ////fattibile o non fattibile + ////parameters.Patterns[i].Iso;=.... //stringa iso + ////parameters.Patterns[i].OutputFilename; //nome file da generare + ////parameters.Patterns[i].SetTaskState(cutId, taskId, value, message); //Cutid del db + //parameters.Patterns[i].Result = PatternInfo.Results.OK; + //parameters.Patterns[i].Message = ""; //eventuale errore messaggio + // } + + //esempio di apertura db, usare solo le viste (iniziano per vw_) + // chiavi + //parameters.Patterns(0).ProductionId + + //cn.Close(); + //} } - return ListaCutId; - } + } - // 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) - { - List ListaCutId = new List(); + callback.Progress( 1, "End") ; - string sqlCutId = "SELECT cutId FROM dbo.vw_Cut WHERE elementId = " + elementId + - "AND projectId = " + projectId; + callback.Done( parameters) ; //fine + } - using (SqlConnection cn = new SqlConnection(Constants.ConnectionString)) - { - cn.Open(); - SqlCommand sqlCommand = new SqlCommand(sqlCutId, cn); - SqlDataReader reader = sqlCommand.ExecuteReader(); - while (reader.Read()) - { - ListaCutId.Add((int)reader["cutId"]); - } - cn.Close(); + private static int? GetVal( string sText, string sKey) + { + string[] sParts = sText.Split( new Char[] { '=' }) ; + if (string.Compare( sParts[0], sKey) != 0) + return null ; + int nVal ; + if ( ! int.TryParse(sParts[1], out nVal)) + return null ; + else + return nVal ; + } + + public void Abort() + { + //non implementata al momento + } + + // 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) + { + Int32 listaTasksCount = ds.Tables[i].Rows.Count; + if ( listaTasksCount == 0) + return; + + 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[0]["productionId"])) ; + btlObject.parts = new List() ; + + btlObject.productionId = (int)ds.Tables[i].Rows[0]["productionId"]; + btlObject.patternId = (int)ds.Tables[i].Rows[0]["patternId"]; + + List ListaCutParts = getListaCutIdP( (int)ds.Tables[i].Rows[0]["patternId"], + (int)ds.Tables[i].Rows[i]["productionId"]); + + for ( int c = 0; c < ListaCutParts.Count; c++) { + BTL.Part readPart = new BTL.Part() ; + + for ( int ltc = 0; ltc < listaTasksCount; ltc++) { + if ( (int)ds.Tables[i].Rows[ltc]["cutId"] == ListaCutParts[c]) { + readPart.singleMemberNumber = ds.Tables[i].Rows[ltc]["productionId"].ToString(); + readPart.count = Convert.ToString(1); // Deve essere 1 o tanto quante sono le Part? + readPart.length = ds.Tables[i].Rows[ltc]["length"].ToString(); + readPart.height = ds.Tables[i].Rows[ltc]["height"].ToString(); + readPart.width = ds.Tables[i].Rows[ltc]["width"].ToString(); + 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(); + + for ( int f = 0; f < listaTasksCount; f++) { + if ( (int)ds.Tables[i].Rows[f]["cutId"] == ListaCutParts[c]) { + BTL.Feature readFeature = new BTL.Feature(); + + readFeature.taskId = ds.Tables[i].Rows[f]["taskId"].ToString(); + + readFeature.processKey = ds.Tables[i].Rows[f]["group"].ToString() + + "-" + ds.Tables[i].Rows[f]["key"].ToString().Substring(1, 3) + + "-" + ds.Tables[i].Rows[f]["face"].ToString(); + readFeature.designation = ds.Tables[i].Rows[f]["des"].ToString(); + readFeature.processIdent = ds.Tables[i].Rows[f]["processIdent"].ToString(); + readFeature.sag1 = ds.Tables[i].Rows[f]["sag1"].ToString(); + + if ( Convert.ToInt16(ds.Tables[i].Rows[f]["enabled"]) == 1) + readFeature.process = Convert.ToString("YES"); + else if ( Convert.ToInt16(ds.Tables[i].Rows[f]["enabled"]) == 0) + readFeature.process = Convert.ToString("NO"); + + readFeature.processParameters = new List(); + readFeature.processParameters.Add(ds.Tables[i].Rows[f]["p01"].ToString()); + readFeature.processParameters.Add(ds.Tables[i].Rows[f]["p02"].ToString()); + readFeature.processParameters.Add(ds.Tables[i].Rows[f]["p03"].ToString()); + readFeature.processParameters.Add(ds.Tables[i].Rows[f]["p04"].ToString()); + readFeature.processParameters.Add(ds.Tables[i].Rows[f]["p05"].ToString()); + readFeature.processParameters.Add(ds.Tables[i].Rows[f]["p06"].ToString()); + readFeature.processParameters.Add(ds.Tables[i].Rows[f]["p07"].ToString()); + readFeature.processParameters.Add(ds.Tables[i].Rows[f]["p08"].ToString()); + readFeature.processParameters.Add(ds.Tables[i].Rows[f]["p09"].ToString()); + readFeature.processParameters.Add(ds.Tables[i].Rows[f]["p10"].ToString()); + readFeature.processParameters.Add(ds.Tables[i].Rows[f]["p11"].ToString()); + readFeature.processParameters.Add(ds.Tables[i].Rows[f]["p12"].ToString()); + readFeature.processParameters.Add(ds.Tables[i].Rows[f]["p13"].ToString()); + readFeature.processParameters.Add(ds.Tables[i].Rows[f]["p14"].ToString()); + readFeature.processParameters.Add(ds.Tables[i].Rows[f]["p15"].ToString()); + readFeature.processParameters.Add(ds.Tables[i].Rows[f]["p16"].ToString()); + readFeature.processParameters.Add(ds.Tables[i].Rows[f]["p17"].ToString()); + readFeature.processParameters.Add(ds.Tables[i].Rows[f]["p18"].ToString()); + readFeature.processParameters.Add(ds.Tables[i].Rows[f]["p19"].ToString()); + readFeature.processParameters.Add(ds.Tables[i].Rows[f]["p20"].ToString()); + readFeature.processParameters.Add(ds.Tables[i].Rows[f]["p21"].ToString()); + readFeature.processParameters.Add(ds.Tables[i].Rows[f]["p22"].ToString()); + readFeature.processParameters.Add(ds.Tables[i].Rows[f]["p23"].ToString()); + readFeature.processParameters.Add(ds.Tables[i].Rows[f]["p24"].ToString()); + readFeature.processParameters.Add(ds.Tables[i].Rows[f]["p25"].ToString()); + readFeature.processParameters.Add(ds.Tables[i].Rows[f]["p26"].ToString()); + + readFeature.processParameters.Add(ds.Tables[i].Rows[f]["q01"].ToString()); + readFeature.processParameters.Add(ds.Tables[i].Rows[f]["q02"].ToString()); + readFeature.processParameters.Add(ds.Tables[i].Rows[f]["q03"].ToString()); + readFeature.processParameters.Add(ds.Tables[i].Rows[f]["q04"].ToString()); + readFeature.processParameters.Add(ds.Tables[i].Rows[f]["q05"].ToString()); + readFeature.processParameters.Add(ds.Tables[i].Rows[f]["q06"].ToString()); + readFeature.processParameters.Add(ds.Tables[i].Rows[f]["q07"].ToString()); + readFeature.processParameters.Add(ds.Tables[i].Rows[f]["q08"].ToString()); + readFeature.processParameters.Add(ds.Tables[i].Rows[f]["q09"].ToString()); + readFeature.processParameters.Add(ds.Tables[i].Rows[f]["q10"].ToString()); + readFeature.processParameters.Add(ds.Tables[i].Rows[f]["q11"].ToString()); + readFeature.processParameters.Add(ds.Tables[i].Rows[f]["q12"].ToString()); + readFeature.processParameters.Add(ds.Tables[i].Rows[f]["q13"].ToString()); + readFeature.processParameters.Add(ds.Tables[i].Rows[f]["q14"].ToString()); + readFeature.processParameters.Add(ds.Tables[i].Rows[f]["q15"].ToString()); + readFeature.processParameters.Add(ds.Tables[i].Rows[f]["q16"].ToString()); + readFeature.processParameters.Add(ds.Tables[i].Rows[f]["q17"].ToString()); + readFeature.processParameters.Add(ds.Tables[i].Rows[f]["q18"].ToString()); + readFeature.processParameters.Add(ds.Tables[i].Rows[f]["q19"].ToString()); + readFeature.processParameters.Add(ds.Tables[i].Rows[f]["q20"].ToString()); + + readPart.features.Add(readFeature); + } + } } - return ListaCutId; - } + btlObject.parts.Add(readPart); + } + // L'ordinamento delle Part in un oggetto BTL avviene col confronto del parametro x, estratto dalla tabella vw_Cut + btlObject.parts.Sort((p, q) => p.x.CompareTo(q.x)); + } - //Ottiene la lunghezza della barra nel caso Produzione (colonna "l") - private static int getBarLengthP(int patternId, int productionId) - { - int barLength = 0; + // Il seguente metodo prende i record visualizzati in ds (Caso: Ordine) e li carica in un oggetto BTL + public static void getListaProcesses( BTL btlObject, int i) + { + Int32 listaProcessesCount = ds.Tables[i].Rows.Count; + if ( listaProcessesCount == 0) + return; - string sqlBarLength = "SELECT l FROM dbo.vw_Pattern WHERE patternId = " + patternId + - "AND productionId = " + productionId; + btlObject.projectNumber = ds.Tables[i].Rows[0]["projectId"].ToString(); + btlObject.scaleUnit = Convert.ToString(2); + btlObject.barLength = Convert.ToString( getBarLengthO((int)ds.Tables[i].Rows[0]["elementId"], + (int)ds.Tables[i].Rows[0]["projectId"])); + btlObject.parts = new List(); - 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(); + btlObject.projectId = (int)ds.Tables[i].Rows[0]["projectId"]; + btlObject.elementId = (int)ds.Tables[i].Rows[0]["elementId"]; + + List ListaCutParts = getListaCutIdO( (int)ds.Tables[i].Rows[0]["elementId"], + (int)ds.Tables[i].Rows[0]["projectId"]); + + for ( int c = 0; c < ListaCutParts.Count; c++) { + BTL.Part readPart = new BTL.Part(); + + for ( int ltc = 0; ltc < listaProcessesCount; ltc++) { + if ( (int)ds.Tables[i].Rows[ltc]["cutId"] == ListaCutParts[c]) { + readPart.singleMemberNumber = " "; // ds.Tables[0].Rows[ltc]["productionId"].ToString(); //In questo caso ci vuole? + readPart.count = Convert.ToString(1); // Deve essere 1 o tanto quante sono le Part? + readPart.length = ds.Tables[i].Rows[ltc]["length"].ToString(); + readPart.height = ds.Tables[i].Rows[ltc]["height"].ToString(); + readPart.width = ds.Tables[i].Rows[ltc]["width"].ToString(); + 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(); + + for ( int f = 0; f < listaProcessesCount; f++) { + if ( (int)ds.Tables[i].Rows[f]["cutId"] == ListaCutParts[c]) { + BTL.Feature readFeature = new BTL.Feature() ; + + 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) + + "-" + ds.Tables[i].Rows[f]["face"].ToString(); + readFeature.designation = ds.Tables[i].Rows[f]["des"].ToString(); + readFeature.processIdent = ds.Tables[i].Rows[f]["processIdent"].ToString(); + readFeature.sag1 = ds.Tables[i].Rows[f]["sag1"].ToString(); + + if ( Convert.ToInt16(ds.Tables[i].Rows[f]["enabled"]) == 1) + readFeature.process = Convert.ToString("YES"); + else if ( Convert.ToInt16(ds.Tables[i].Rows[f]["enabled"]) == 0) + readFeature.process = Convert.ToString("NO"); + + readFeature.processParameters = new List(); + readFeature.processParameters.Add(ds.Tables[i].Rows[f]["p01"].ToString()); + readFeature.processParameters.Add(ds.Tables[i].Rows[f]["p02"].ToString()); + readFeature.processParameters.Add(ds.Tables[i].Rows[f]["p03"].ToString()); + readFeature.processParameters.Add(ds.Tables[i].Rows[f]["p04"].ToString()); + readFeature.processParameters.Add(ds.Tables[i].Rows[f]["p05"].ToString()); + readFeature.processParameters.Add(ds.Tables[i].Rows[f]["p06"].ToString()); + readFeature.processParameters.Add(ds.Tables[i].Rows[f]["p07"].ToString()); + readFeature.processParameters.Add(ds.Tables[i].Rows[f]["p08"].ToString()); + readFeature.processParameters.Add(ds.Tables[i].Rows[f]["p09"].ToString()); + readFeature.processParameters.Add(ds.Tables[i].Rows[f]["p10"].ToString()); + readFeature.processParameters.Add(ds.Tables[i].Rows[f]["p11"].ToString()); + readFeature.processParameters.Add(ds.Tables[i].Rows[f]["p12"].ToString()); + readFeature.processParameters.Add(ds.Tables[i].Rows[f]["p13"].ToString()); + readFeature.processParameters.Add(ds.Tables[i].Rows[f]["p14"].ToString()); + readFeature.processParameters.Add(ds.Tables[i].Rows[f]["p15"].ToString()); + readFeature.processParameters.Add(ds.Tables[i].Rows[f]["p16"].ToString()); + readFeature.processParameters.Add(ds.Tables[i].Rows[f]["p17"].ToString()); + readFeature.processParameters.Add(ds.Tables[i].Rows[f]["p18"].ToString()); + readFeature.processParameters.Add(ds.Tables[i].Rows[f]["p19"].ToString()); + readFeature.processParameters.Add(ds.Tables[i].Rows[f]["p20"].ToString()); + readFeature.processParameters.Add(ds.Tables[i].Rows[f]["p21"].ToString()); + readFeature.processParameters.Add(ds.Tables[i].Rows[f]["p22"].ToString()); + readFeature.processParameters.Add(ds.Tables[i].Rows[f]["p23"].ToString()); + readFeature.processParameters.Add(ds.Tables[i].Rows[f]["p24"].ToString()); + readFeature.processParameters.Add(ds.Tables[i].Rows[f]["p25"].ToString()); + readFeature.processParameters.Add(ds.Tables[i].Rows[f]["p26"].ToString()); + + readFeature.processParameters.Add(ds.Tables[i].Rows[f]["q01"].ToString()); + readFeature.processParameters.Add(ds.Tables[i].Rows[f]["q02"].ToString()); + readFeature.processParameters.Add(ds.Tables[i].Rows[f]["q03"].ToString()); + readFeature.processParameters.Add(ds.Tables[i].Rows[f]["q04"].ToString()); + readFeature.processParameters.Add(ds.Tables[i].Rows[f]["q05"].ToString()); + readFeature.processParameters.Add(ds.Tables[i].Rows[f]["q06"].ToString()); + readFeature.processParameters.Add(ds.Tables[i].Rows[f]["q07"].ToString()); + readFeature.processParameters.Add(ds.Tables[i].Rows[f]["q08"].ToString()); + readFeature.processParameters.Add(ds.Tables[i].Rows[f]["q09"].ToString()); + readFeature.processParameters.Add(ds.Tables[i].Rows[f]["q10"].ToString()); + readFeature.processParameters.Add(ds.Tables[i].Rows[f]["q11"].ToString()); + readFeature.processParameters.Add(ds.Tables[i].Rows[f]["q12"].ToString()); + readFeature.processParameters.Add(ds.Tables[i].Rows[f]["q13"].ToString()); + readFeature.processParameters.Add(ds.Tables[i].Rows[f]["q14"].ToString()); + readFeature.processParameters.Add(ds.Tables[i].Rows[f]["q15"].ToString()); + readFeature.processParameters.Add(ds.Tables[i].Rows[f]["q16"].ToString()); + readFeature.processParameters.Add(ds.Tables[i].Rows[f]["q17"].ToString()); + readFeature.processParameters.Add(ds.Tables[i].Rows[f]["q18"].ToString()); + readFeature.processParameters.Add(ds.Tables[i].Rows[f]["q19"].ToString()); + readFeature.processParameters.Add(ds.Tables[i].Rows[f]["q20"].ToString()); + + readPart.features.Add(readFeature); + } + } } - return barLength; - } + btlObject.parts.Add(readPart); + } + // L'ordinamento delle Part in un oggetto BTL avviene col confronto del parametro x, estratto dalla tabella vw_Cut + btlObject.parts.Sort((p, q) => p.x.CompareTo(q.x)); + } - //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) - { - int barLength = 0; + // 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) + { + List ListaCutId = new List(); - string sqlBarLength = "SELECT length FROM dbo.vw_Element WHERE elementId = " + elementId + - "AND projectId = " + projectId; + string sqlCutId = "SELECT cutId FROM dbo.vw_Cut WHERE patternId = " + patternId + + "AND productionId = " + productionId; - 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["length"]); - } - cn.Close(); + using (SqlConnection cn = new SqlConnection(Constants.ConnectionString)) { + cn.Open(); + SqlCommand sqlCommand = new SqlCommand(sqlCutId, cn); + SqlDataReader reader = sqlCommand.ExecuteReader(); + while (reader.Read()) { + ListaCutId.Add((int)reader["cutId"]); } - return barLength + 2000; - } + cn.Close(); + } + return ListaCutId; + } + + // 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) + { + List ListaCutId = new List(); + + string sqlCutId = "SELECT cutId FROM dbo.vw_Cut WHERE elementId = " + elementId + + "AND projectId = " + projectId; + + using (SqlConnection cn = new SqlConnection(Constants.ConnectionString)) { + cn.Open(); + SqlCommand sqlCommand = new SqlCommand(sqlCutId, cn); + SqlDataReader reader = sqlCommand.ExecuteReader(); + while (reader.Read()) { + ListaCutId.Add((int)reader["cutId"]); + } + cn.Close(); + } + return ListaCutId; + } + + //Ottiene la lunghezza della barra nel caso Produzione (colonna "l") + private static int getBarLengthP(int patternId, int productionId) + { + int barLength = 0; + + string sqlBarLength = "SELECT l FROM dbo.vw_Pattern WHERE patternId = " + patternId + + "AND productionId = " + productionId; + + 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; + } + + //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) + { + int barLength = 0; + + string sqlBarLength = "SELECT length 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["length"]); + } + cn.Close(); + } + return barLength + 2000; + } } } diff --git a/IntegrationEgaltech/IntegrationEgaltech.csproj b/IntegrationEgaltech/IntegrationEgaltech.csproj index 674c2e5..8f78775 100644 --- a/IntegrationEgaltech/IntegrationEgaltech.csproj +++ b/IntegrationEgaltech/IntegrationEgaltech.csproj @@ -18,14 +18,14 @@ true full false - C:\TechnoEssetre7\ + bin\Debug\ DEBUG;TRACE prompt 4 - x86 + AnyCPU - pdbonly + none true bin\Release\ diff --git a/IntegrationEgaltech/Properties/AssemblyInfo.cs b/IntegrationEgaltech/Properties/AssemblyInfo.cs index c1ab4b7..5467c21 100644 --- a/IntegrationEgaltech/Properties/AssemblyInfo.cs +++ b/IntegrationEgaltech/Properties/AssemblyInfo.cs @@ -5,12 +5,12 @@ using System.Runtime.InteropServices; // Le informazioni generali relative a un assembly sono controllate dal seguente // set di attributi. Modificare i valori di questi attributi per modificare le informazioni // associate a un assembly. -[assembly: AssemblyTitle("IntegrationEgaltech")] #if DEBUG -[assembly: AssemblyDescription("IntegrationEgaltech Debug")] +[assembly: AssemblyTitle("IntegrationEgaltech Debug")] #else -[assembly: AssemblyDescription("IntegrationEgaltech")] +[assembly: AssemblyTitle("IntegrationEgaltech")] #endif +[assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("EgalTech s.r.l.")] [assembly: AssemblyProduct("IntegrationEgaltech")] @@ -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.1.5")] -[assembly: AssemblyFileVersion("2.1.1.5")] +[assembly: AssemblyVersion("2.1.2.1")] +[assembly: AssemblyFileVersion("2.1.2.1")]