From a4d08380362c5c9f387401ee41751f812fedca3d Mon Sep 17 00:00:00 2001 From: Dario Sassi Date: Mon, 11 Feb 2019 07:56:52 +0000 Subject: [PATCH] Integration : - ulteriori affinamenti. --- IntegrationEgaltech/BTL.cs | 232 +++++++--------- IntegrationEgaltech/Constants.cs | 52 ++-- IntegrationEgaltech/Generator.cs | 464 ++++++++++++++----------------- 3 files changed, 333 insertions(+), 415 deletions(-) diff --git a/IntegrationEgaltech/BTL.cs b/IntegrationEgaltech/BTL.cs index 9177ee6..8aae8cc 100644 --- a/IntegrationEgaltech/BTL.cs +++ b/IntegrationEgaltech/BTL.cs @@ -12,149 +12,112 @@ namespace ib.essetre.integration.egaltech // 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 string projectNumber ; + public string scaleUnit ; + public string barLength ; + public List parts ; + // 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( string projectNumber, string scaleUnit, List parts, List features) + public bool WriteIntoFile( string filePath, bool IsFromProject) { - 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() ; - - // 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"; - - // 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( Path.ChangeExtension( filePath, ".txt"))) File.Delete( Path.ChangeExtension( filePath, ".txt")) ; // Se non esistono pezzi, non faccio alcunché if ( parts == null) - return filePath ; + return false ; // 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 + "\""); + 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 + "\"") ; foreach ( Part singlePart in parts) { - tw.WriteLine(Constants.PART); - tw.WriteLine(Constants.SINGLE_MEMBER_NUMBER + singlePart.singleMemberNumber); - tw.WriteLine(Constants.COUNT + singlePart.count); + tw.WriteLine( Constants.PART) ; + tw.WriteLine( Constants.SINGLE_MEMBER_NUMBER + singlePart.singleMemberNumber) ; + tw.WriteLine( Constants.COUNT + singlePart.count) ; - double len = (Convert.ToDouble(singlePart.length)) * Math.Pow(10, Constants.scaleUnit); - int intLen = (Convert.ToInt32(len)); - tw.WriteLine(Constants.LENGTH + intLen.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")) ; - double hei = (Convert.ToDouble(singlePart.height)) * Math.Pow(10, Constants.scaleUnit); - int intHei = (Convert.ToInt32(hei)); - tw.WriteLine(Constants.HEIGHT + intHei.ToString("D8")); + double hei = Convert.ToDouble( singlePart.height) * Math.Pow( 10, Constants.scaleUnit) ; + int intHei = Convert.ToInt32( hei) ; + tw.WriteLine( Constants.HEIGHT + intHei.ToString( "D8")) ; - double wid = (Convert.ToDouble(singlePart.width)) * Math.Pow(10, Constants.scaleUnit); - int intWid = (Convert.ToInt32(wid)); - tw.WriteLine(Constants.WIDTH + intWid.ToString("D8")); + double wid = Convert.ToDouble( singlePart.width) * Math.Pow( 10, Constants.scaleUnit) ; + int intWid = Convert.ToInt32( wid) ; + tw.WriteLine( Constants.WIDTH + intWid.ToString( "D8")) ; - string posX = singlePart.x.ToString("0.00", System.Globalization.CultureInfo.InvariantCulture); - tw.WriteLine(Constants.USERATTRIBUTE + "\"POSX\":" + "\"" + posX + "\""); + string posX = singlePart.x.ToString( "0.00", System.Globalization.CultureInfo.InvariantCulture) ; + tw.WriteLine( Constants.USERATTRIBUTE + "\"POSX\":" + "\"" + posX + "\"") ; - string inv = singlePart.inverted.ToString(); - tw.WriteLine(Constants.USERATTRIBUTE + "\"INVERTED\":" + "\"" + inv + "\""); + string inv = singlePart.inverted.ToString() ; + tw.WriteLine( Constants.USERATTRIBUTE + "\"INVERTED\":" + "\"" + inv + "\"") ; - string rot = singlePart.rotated.ToString(); - tw.WriteLine(Constants.USERATTRIBUTE + "\"ROTATED\":" + "\"" + rot + "\""); + 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 + "\""); + tw.WriteLine( Constants.USERATTRIBUTE + "\"CUTID\":" + "\"" + ( IsFromProject ? singlePart.elementId : 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 + // Se Contorno Libero (processo "250") elaborazione speciale if ( singleFeature.processKey.Contains( "250")) { - FreeContourAnalyzer( singleFeature.sag1, tw, singleFeature); + FreeContourAnalyzer( singleFeature, tw) ; } 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 { - // 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++; + // Tipo di Process + tw.WriteLine( Constants.PROCESS_KEY + singleFeature.processKey + " " + singleFeature.designation) ; + // Parametri standard del Process ( 1 .. 26) + tw.Write( Constants.PROCESS_PARAMETERS) ; + for ( int i = 1 ; i <= 26 ; ++ i) { + string singleParameter = singleFeature.processParameters[i-1] ; + 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 + "\" ") ; } - - tw.WriteLine(Constants.PROCESS_IDENT + singleFeature.processIdent); - tw.WriteLine(Constants.PROCESS + singleFeature.process); + tw.WriteLine( "") ; + // Parametri speciali Q diversi da 0, preceduti da "USERATTRIBUTE:" + for ( int i = 1 ; i <= 20 ; ++ i) { + string singleParameter = singleFeature.processParameters[i+25] ; + if ( ! singleParameter.Equals( "0")) { + singleParameter = singleParameter.Replace( ",", ".") ; + tw.WriteLine( Constants.USERATTRIBUTE + "\"Q" + i.ToString( "D2") + "\":\"" + singleParameter + "\" ") ; + } + } + 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 + "\""); + tw.WriteLine( Constants.USERATTRIBUTE + "\"TASKID\":" + "\"" + ( IsFromProject ? singleFeature.processId : singleFeature.taskId) + "\"") ; } } } - return filePath; + return true ; } // 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) + public void FreeContourAnalyzer( Feature singleFeature, StreamWriter tw) { - if ( sag1 == "") + if ( singleFeature.sag1 == "") return ; - string[] arrParam = sag1.Split(new string[] { "POLY([", "),", ")],'P','O')" }, StringSplitOptions.RemoveEmptyEntries); + string[] arrParam = singleFeature.sag1.Split( new string[] { "POLY([", "),", ")],'P','O')" }, StringSplitOptions.RemoveEmptyEntries) ; // Se il parametro Q10 è 1, l'ordine dell'array viene invertito if ( singleFeature.processParameters[35] == "1") @@ -163,10 +126,10 @@ namespace ib.essetre.integration.egaltech 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 + 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]) { + switch ( parts[0]) { case "P": // Se StartPoint if ( i == 0) { @@ -276,46 +239,53 @@ namespace ib.essetre.integration.egaltech break; } } + // Parametri speciali Q diversi da 0, preceduti da "USERATTRIBUTE:" + for ( int i = 1 ; i <= 20 ; ++ i) { + string singleParameter = singleFeature.processParameters[i+25] ; + if ( ! singleParameter.Equals( "0")) { + singleParameter = singleParameter.Replace( ",", ".") ; + tw.WriteLine( Constants.USERATTRIBUTE + "\"Q" + i.ToString( "D2") + "\":\"" + singleParameter + "\" ") ; + } + } } // 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) + 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; + string rp = processParameter.Replace( ",", ".") ; + double 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 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; + 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/Constants.cs b/IntegrationEgaltech/Constants.cs index 39ce54c..430243c 100644 --- a/IntegrationEgaltech/Constants.cs +++ b/IntegrationEgaltech/Constants.cs @@ -8,34 +8,34 @@ namespace ib.essetre.integration.egaltech { class Constants { - // Le seguenti costanti sottoforma di stringa sono delle componenti di testo da scrivere - // all'interno del file BTL da generare - public const string VERSION = "VERSION: BTL V10.6"; - public const string BUILD = "BUILD: \"10600\""; - public const string GENERAL = "[GENERAL]"; - public const string PART = "[PART]"; - public const string PROJECT_NUMBER = "PROJECTNUMBER: "; - public const string SCALE_UNIT = "SCALEUNIT: "; - public const string SINGLE_MEMBER_NUMBER = "SINGLEMEMBERNUMBER: "; - public const string DESIGNATION = "DESIGNATION: "; - public const string COUNT = "COUNT: "; - public const string LENGTH = "LENGTH: "; - public const string HEIGHT = "HEIGHT: "; - public const string WIDTH = "WIDTH: "; - public const string PROCESS_KEY = "PROCESSKEY: "; - public const string PROCESS_PARAMETERS = "PROCESSPARAMETERS: "; - public const string PROCESS_IDENT = "PROCESSIDENT: "; - public const string PROCESS = "PROCESS: "; - public const string COMMENT = "COMMENT: "; - public const string USERATTRIBUTE = "USERATTRIBUTE: "; - public const string EIGHT_ZEROS = "00000000"; + // Le seguenti costanti stringa sono parti di testo del file BTL di output + public const string VERSION = "VERSION: BTL V10.6" ; + public const string BUILD = "BUILD: \"10600\"" ; + public const string GENERAL = "[GENERAL]" ; + public const string PART = "[PART]" ; + public const string PROJECT_NUMBER = "PROJECTNUMBER: " ; + public const string SCALE_UNIT = "SCALEUNIT: " ; + public const string SINGLE_MEMBER_NUMBER = "SINGLEMEMBERNUMBER: " ; + public const string DESIGNATION = "DESIGNATION: " ; + public const string COUNT = "COUNT: " ; + public const string LENGTH = "LENGTH: " ; + public const string HEIGHT = "HEIGHT: " ; + public const string WIDTH = "WIDTH: " ; + public const string PROCESS_KEY = "PROCESSKEY: " ; + public const string PROCESS_PARAMETERS = "PROCESSPARAMETERS: " ; + public const string PROCESS_IDENT = "PROCESSIDENT: " ; + public const string PROCESS = "PROCESS: " ; + public const string COMMENT = "COMMENT: " ; + public const string USERATTRIBUTE = "USERATTRIBUTE: " ; + public const string EIGHT_ZEROS = "00000000" ; - // Questa costante specifica l'esponente della potenza in base 10 per cui moltiplicare alcuni - // parametri come length, width, height e i process parameters - public const int scaleUnit = 2; + // Numero di cifre decimali dei valori dei parametri BTL + public const int scaleUnit = 2 ; - // Stringa contenente i parametri di connessione al DB - public const string ConnectionString = @"Data Source=localhost\SQLEssetre;Initial Catalog=ESSETRE;User ID=sa;Password=essetre"; + // Allungamento della barra per pezzi singoli da Vista + public const double BarAddLen = 2000 ; + // Sovramateriale di testa per pezzi singoli di Vista + public const double HeadOverMat = 10 ; } } diff --git a/IntegrationEgaltech/Generator.cs b/IntegrationEgaltech/Generator.cs index f8891a2..81598f6 100644 --- a/IntegrationEgaltech/Generator.cs +++ b/IntegrationEgaltech/Generator.cs @@ -15,20 +15,18 @@ 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 System.Threading.Thread _thread ; + public static DataSet ds = new DataSet() ; + public static string SqlConnectionStr = "" ; public Generator() { - Console.WriteLine("Inizializzato"); } public void Run(InOutParameters parameters, ICallBack callback) { - _thread = new Thread(() => DoJob(parameters, callback)); - - _thread.Start(); + _thread = new Thread(() => DoJob( parameters, callback)) ; + _thread.Start() ; } private delegate void dDoJob( InOutParameters parameters, ICallBack callback) ; @@ -38,61 +36,68 @@ namespace ib.essetre.integration.egaltech { callback.Progress( 0, "Init") ; + SqlConnectionStr = parameters.ConnectionString ; + String ExePath = parameters.Read( "EGALTECH", "PATH_EXE", "") ; String BtlDir = parameters.Read( "EGALTECH", "DIR_BTL", "") ; + // Se la directory in cui salvare il file non esiste viene creata + DirectoryInfo di = new DirectoryInfo( BtlDir) ; + if ( ! di.Exists) + di.Create() ; int numBars = parameters.Patterns.Length ; for ( int i = 0; i < numBars; i++) { + PatternInfo pattInfo = parameters.Patterns[i] ; + BTL btlObject = new BTL() ; // Se il parametro IsFromProject è TRUE viene eseguita la query sulle tabelle Project, // se invece è FALSE viene eseguita la query sulle tabelle Production string sql = "" ; - if ( parameters.Patterns[i].IsFromProject) { + if ( pattInfo.IsFromProject) { sql = "SELECT P.projectId, " + "P.elementId, 0 cutId, processId, info1, info2, enabled, level, " + "inTools, outTools, isChecked, P.done, isoType, ax, ay, az, P.x, P.y, P.z, " + "P.flagDeleted, P.[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, P.projectId, P.elementId, P.processId, 10 cutStart, 0 cutEnd, " + + "priority, processIdent, processingQuality, sag1, P.projectId, P.elementId, P.processId, 0 cutStart, 0 cutEnd, " + "E.inverted, E.rotated, 0 doneTime, 0 startAngle, 0 endAngle, -1 referenceCutId, E.length, E.width, E.height " + - "FROM dbo.vw_Process P " + - "INNER JOIN dbo.vw_Element E ON P.projectId=E.projectId and P.elementId=E.elementId " + - "WHERE P.projectId = @firstId" + - " and E.elementId = @secondId"; + "FROM dbo.vw_Process AS P " + + "INNER JOIN dbo.vw_Element AS E " + + "ON P.projectId=E.projectId AND P.elementId=E.elementId " + + "WHERE P.projectId = @firstId AND E.elementId = @secondId" ; } else { sql = "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.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 = @firstId" + - " and vw_Task.productionId = @secondId"; + "FROM 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 = @firstId AND vw_Task.productionId = @secondId" ; } // Connessione al DB ed esecuzione query - using ( SqlConnection cn = new SqlConnection( parameters.ConnectionString)) { + using ( SqlConnection cn = new SqlConnection( SqlConnectionStr)) { cn.Open() ; using (SqlCommand cmd = new SqlCommand( sql, cn)) { cmd.Parameters.Add( "@firstId", SqlDbType.Int) ; cmd.Parameters.Add( "@secondId", SqlDbType.Int) ; - if ( parameters.Patterns[i].IsFromProject) { - cmd.Parameters["@firstId"].Value = (Int32)parameters.Patterns[i].ProjectId ; - cmd.Parameters["@secondId"].Value = (Int32)parameters.Patterns[i].ElementId ; + if ( pattInfo.IsFromProject) { + cmd.Parameters["@firstId"].Value = (Int32)pattInfo.ProjectId ; + cmd.Parameters["@secondId"].Value = (Int32)pattInfo.ElementId ; } else { - cmd.Parameters["@firstId"].Value = (Int32)parameters.Patterns[i].PatternId ; - cmd.Parameters["@secondId"].Value = (Int32)parameters.Patterns[i].ProductionId ; + cmd.Parameters["@firstId"].Value = (Int32)pattInfo.PatternId ; + cmd.Parameters["@secondId"].Value = (Int32)pattInfo.ProductionId ; } var dataAdapter = new SqlDataAdapter( cmd) ; @@ -104,22 +109,30 @@ namespace ib.essetre.integration.egaltech // 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) ; + if ( pattInfo.IsFromProject) + GetListaProcesses( btlObject) ; else - getListaTasks( btlObject, 0) ; + GetListaTasks( btlObject) ; // 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); + 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 BtlPath = btlObject.writeIntoFile(parameters.Patterns[i].IsFromProject, BtlDir); - string path = "\"" + BtlPath + "\" " + parameters.MachineName + " " + - (int)parameters.UIMode + " " + parameters.Patterns[i].OutputFilename ; + // Scrittura del file BTL + // Il nome del file cambia a seconda che si tratti del caso Produzione o caso Ordine + string BtlName ; + if ( pattInfo.IsFromProject) + BtlName = "Part_" + btlObject.projectId.ToString() + "_" + btlObject.elementId.ToString() + ".btl" ; + else + BtlName = "Bar_" + btlObject.productionId.ToString() + "_" + btlObject.patternId.ToString() + ".btl" ; + // Path completa del nome del file da salvare + string BtlPath = Path.Combine( BtlDir, BtlName) ; + btlObject.WriteIntoFile( BtlPath, pattInfo.IsFromProject) ; + + // Esecuzione di EgtCAM5 con parametri path BTL, nome macchina e modo + string path = "\"" + BtlPath + "\" " + parameters.MachineName + " " + (int)parameters.UIMode ; Process process = Process.Start( ExePath, path) ; // Attendo il termine del processo @@ -135,13 +148,13 @@ namespace ib.essetre.integration.egaltech string textErr = "" ; if ( File.Exists( Path.ChangeExtension( BtlPath, ".txt"))) { string[] lines = System.IO.File.ReadAllLines( Path.ChangeExtension( BtlPath, ".txt")) ; - foreach (string line in lines) { + 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; + resExe = PatternInfo.Results.ERROR ; } else if ( line.StartsWith( "CUTID=")) { int? nVal = GetVal( line, "CUTID") ; @@ -149,18 +162,15 @@ namespace ib.essetre.integration.egaltech cutId = nVal.Value ; } else if ( line.StartsWith( "TASKID=")) { - int? nVal = GetVal(line, "TASKID") ; + int? nVal = GetVal( line, "TASKID") ; if ( nVal != null) - taskId = nVal.Value; + taskId = nVal.Value ; } - else if (!string.IsNullOrWhiteSpace(line)) - textErr = line; + else if ( ! string.IsNullOrWhiteSpace( line)) + textErr = line ; } } - parameters.Patterns[i].SetTaskState( cutId, taskId, resExe, textErr) ; - - //parameters.Patterns[i].GetTaskState( cutId, taskId, out PatternInfo.Results res, out string msg) ; - //System.Windows.Forms.MessageBox.Show( msg, res.ToString()) ; + pattInfo.SetTaskState( cutId, taskId, resExe, textErr) ; // Lettura OutputFilename e scrittura nel parametro stringa Iso (solo nel caso UIModes.HIDDEN) if ( parameters.UIMode == InOutParameters.UIModes.HIDDEN) { @@ -168,42 +178,15 @@ namespace ib.essetre.integration.egaltech string CncPath = Path.ChangeExtension( BtlPath, ".cnc") ; if ( File.Exists( CncPath)) { string lines = System.IO.File.ReadAllText(CncPath) ; - parameters.Patterns[i].Iso = lines ; - parameters.Patterns[i].Result = PatternInfo.Results.OK ; - parameters.Patterns[i].DetailResult = PatternInfo.DetailResults.ALL_OK ; + pattInfo.Iso = lines ; + pattInfo.Result = PatternInfo.Results.OK ; + pattInfo.DetailResult = PatternInfo.DetailResults.ALL_OK ; } else { - parameters.Patterns[i].Iso = "" ; - parameters.Patterns[i].Result = PatternInfo.Results.ERROR ; - parameters.Patterns[i].DetailResult = PatternInfo.DetailResults.ALL_KO ; + pattInfo.Iso = "" ; + pattInfo.Result = PatternInfo.Results.ERROR ; + pattInfo.DetailResult = PatternInfo.DetailResults.ALL_KO ; } - - ////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(); - //} } } @@ -229,9 +212,9 @@ namespace ib.essetre.integration.egaltech } // 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) + public static void GetListaTasks( BTL btlObject) { - DataTable dTab = ds.Tables[i] ; + DataTable dTab = ds.Tables[0] ; Int32 listaTasksCount = dTab.Rows.Count ; if ( listaTasksCount == 0) return ; @@ -239,12 +222,12 @@ namespace ib.essetre.integration.egaltech DataRow dRow0 = dTab.Rows[0] ; btlObject.projectNumber = dRow0["projectId"].ToString() ; btlObject.scaleUnit = "2" ; - btlObject.barLength = Convert.ToString( getBarLengthP( (int)dRow0["patternId"], (int)dRow0["productionId"])) ; + btlObject.barLength = Convert.ToString( GetBarLengthP( (int)dRow0["patternId"], (int)dRow0["productionId"])) ; btlObject.productionId = (int)dRow0["productionId"] ; btlObject.patternId = (int)dRow0["patternId"] ; btlObject.parts = new List() ; - List ListaCutParts = getListaCutIdP( (int)dRow0["patternId"], (int)dTab.Rows[i]["productionId"]) ; + List ListaCutParts = GetListaCutIdP() ; for ( int c = 0 ; c < ListaCutParts.Count ; c++) { @@ -271,71 +254,64 @@ namespace ib.essetre.integration.egaltech readPart.features = new List() ; } - BTL.Feature readFeature = new BTL.Feature() ; - - readFeature.taskId = dRowF["taskId"].ToString() ; - - readFeature.processKey = dRowF["group"].ToString() + - "-" + dRowF["key"].ToString().Substring( 1, 3) + - "-" + dRowF["face"].ToString() ; - readFeature.designation = dRowF["des"].ToString() ; - readFeature.processIdent = dRowF["processIdent"].ToString() ; - readFeature.sag1 = dRowF["sag1"].ToString() ; - - if ( Convert.ToInt16( dRowF["enabled"]) == 1) - readFeature.process = "YES" ; - else - readFeature.process = "NO" ; - - readFeature.processParameters = new List( 46) ; - readFeature.processParameters.Add( dRowF["p01"].ToString()) ; - readFeature.processParameters.Add( dRowF["p02"].ToString()) ; - readFeature.processParameters.Add( dRowF["p03"].ToString()) ; - readFeature.processParameters.Add( dRowF["p04"].ToString()) ; - readFeature.processParameters.Add( dRowF["p05"].ToString()) ; - readFeature.processParameters.Add( dRowF["p06"].ToString()) ; - readFeature.processParameters.Add( dRowF["p07"].ToString()) ; - readFeature.processParameters.Add( dRowF["p08"].ToString()) ; - readFeature.processParameters.Add( dRowF["p09"].ToString()) ; - readFeature.processParameters.Add( dRowF["p10"].ToString()) ; - readFeature.processParameters.Add( dRowF["p11"].ToString()) ; - readFeature.processParameters.Add( dRowF["p12"].ToString()) ; - readFeature.processParameters.Add( dRowF["p13"].ToString()) ; - readFeature.processParameters.Add( dRowF["p14"].ToString()) ; - readFeature.processParameters.Add( dRowF["p15"].ToString()) ; - readFeature.processParameters.Add( dRowF["p16"].ToString()) ; - readFeature.processParameters.Add( dRowF["p17"].ToString()) ; - readFeature.processParameters.Add( dRowF["p18"].ToString()) ; - readFeature.processParameters.Add( dRowF["p19"].ToString()) ; - readFeature.processParameters.Add( dRowF["p20"].ToString()) ; - readFeature.processParameters.Add( dRowF["p21"].ToString()) ; - readFeature.processParameters.Add( dRowF["p22"].ToString()) ; - readFeature.processParameters.Add( dRowF["p23"].ToString()) ; - readFeature.processParameters.Add( dRowF["p24"].ToString()) ; - readFeature.processParameters.Add( dRowF["p25"].ToString()) ; - readFeature.processParameters.Add( dRowF["p26"].ToString()) ; - - readFeature.processParameters.Add( dRowF["q01"].ToString()) ; - readFeature.processParameters.Add( dRowF["q02"].ToString()) ; - readFeature.processParameters.Add( dRowF["q03"].ToString()) ; - readFeature.processParameters.Add( dRowF["q04"].ToString()) ; - readFeature.processParameters.Add( dRowF["q05"].ToString()) ; - readFeature.processParameters.Add( dRowF["q06"].ToString()) ; - readFeature.processParameters.Add( dRowF["q07"].ToString()) ; - readFeature.processParameters.Add( dRowF["q08"].ToString()) ; - readFeature.processParameters.Add( dRowF["q09"].ToString()) ; - readFeature.processParameters.Add( dRowF["q10"].ToString()) ; - readFeature.processParameters.Add( dRowF["q11"].ToString()) ; - readFeature.processParameters.Add( dRowF["q12"].ToString()) ; - readFeature.processParameters.Add( dRowF["q13"].ToString()) ; - readFeature.processParameters.Add( dRowF["q14"].ToString()) ; - readFeature.processParameters.Add( dRowF["q15"].ToString()) ; - readFeature.processParameters.Add( dRowF["q16"].ToString()) ; - readFeature.processParameters.Add( dRowF["q17"].ToString()) ; - readFeature.processParameters.Add( dRowF["q18"].ToString()) ; - readFeature.processParameters.Add( dRowF["q19"].ToString()) ; - readFeature.processParameters.Add( dRowF["q20"].ToString()) ; - + BTL.Feature readFeature = new BTL.Feature() { + taskId = dRowF["taskId"].ToString(), + processKey = dRowF["group"].ToString() + + "-" + dRowF["key"].ToString().Substring( 1, 3) + + "-" + dRowF["face"].ToString(), + designation = dRowF["des"].ToString(), + processIdent = dRowF["processIdent"].ToString(), + sag1 = dRowF["sag1"].ToString(), + process = ( Convert.ToInt16( dRowF["enabled"]) == 1) ? "YES" : "NO", + processParameters = new List( 46) { + dRowF["p01"].ToString(), + dRowF["p02"].ToString(), + dRowF["p03"].ToString(), + dRowF["p04"].ToString(), + dRowF["p05"].ToString(), + dRowF["p06"].ToString(), + dRowF["p07"].ToString(), + dRowF["p08"].ToString(), + dRowF["p09"].ToString(), + dRowF["p10"].ToString(), + dRowF["p11"].ToString(), + dRowF["p12"].ToString(), + dRowF["p13"].ToString(), + dRowF["p14"].ToString(), + dRowF["p15"].ToString(), + dRowF["p16"].ToString(), + dRowF["p17"].ToString(), + dRowF["p18"].ToString(), + dRowF["p19"].ToString(), + dRowF["p20"].ToString(), + dRowF["p21"].ToString(), + dRowF["p22"].ToString(), + dRowF["p23"].ToString(), + dRowF["p24"].ToString(), + dRowF["p25"].ToString(), + dRowF["p26"].ToString(), + dRowF["q01"].ToString(), + dRowF["q02"].ToString(), + dRowF["q03"].ToString(), + dRowF["q04"].ToString(), + dRowF["q05"].ToString(), + dRowF["q06"].ToString(), + dRowF["q07"].ToString(), + dRowF["q08"].ToString(), + dRowF["q09"].ToString(), + dRowF["q10"].ToString(), + dRowF["q11"].ToString(), + dRowF["q12"].ToString(), + dRowF["q13"].ToString(), + dRowF["q14"].ToString(), + dRowF["q15"].ToString(), + dRowF["q16"].ToString(), + dRowF["q17"].ToString(), + dRowF["q18"].ToString(), + dRowF["q19"].ToString(), + dRowF["q20"].ToString() + }, + } ; readPart.features.Add( readFeature) ; } btlObject.parts.Add( readPart) ; @@ -345,17 +321,17 @@ namespace ib.essetre.integration.egaltech } // 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) + public static void GetListaProcesses( BTL btlObject) { - DataTable dTab = ds.Tables[i] ; - Int32 listaProcessesCount = dTab.Rows.Count ; + DataTable dTab = ds.Tables[0] ; + int listaProcessesCount = dTab.Rows.Count ; if ( listaProcessesCount == 0) return ; DataRow dRow0 = dTab.Rows[0] ; btlObject.projectNumber = dRow0["projectId"].ToString() ; btlObject.scaleUnit = " 2" ; - btlObject.barLength = Convert.ToString( getBarLengthO( (int)dRow0["elementId"], (int)dRow0["projectId"])) ; + btlObject.barLength = Convert.ToString( GetBarLengthO( (int)dRow0["elementId"], (int)dRow0["projectId"])) ; btlObject.projectId = (int)dRow0["projectId"] ; btlObject.elementId = (int)dRow0["elementId"] ; btlObject.parts = new List() ; @@ -380,7 +356,7 @@ namespace ib.essetre.integration.egaltech readPart.length = dRowF["length"].ToString() ; readPart.height = dRowF["height"].ToString() ; readPart.width = dRowF["width"].ToString() ; - readPart.x = (double)dRowF["x"] ; + readPart.x = Constants.HeadOverMat ; readPart.inverted = dRowF["inverted"].ToString() ; readPart.rotated = dRowF["rotated"].ToString() ; readPart.elementId = (int)dRowF["elementId"] ; @@ -388,71 +364,64 @@ namespace ib.essetre.integration.egaltech readPart.features = new List() ; } - BTL.Feature readFeature = new BTL.Feature() ; - - readFeature.processId = dRowF["processId"].ToString() ; - - readFeature.processKey = dRowF["group"].ToString() + - "-" + dRowF["key"].ToString().Substring( 1, 3) + - "-" + dRowF["face"].ToString() ; - readFeature.designation = dRowF["des"].ToString() ; - readFeature.processIdent = dRowF["processIdent"].ToString() ; - readFeature.sag1 = dRowF["sag1"].ToString() ; - - if ( Convert.ToInt16( dRowF["enabled"]) == 1) - readFeature.process = "YES" ; - else - readFeature.process = "NO" ; - - readFeature.processParameters = new List( 46) ; - readFeature.processParameters.Add( dRowF["p01"].ToString()) ; - readFeature.processParameters.Add( dRowF["p02"].ToString()) ; - readFeature.processParameters.Add( dRowF["p03"].ToString()) ; - readFeature.processParameters.Add( dRowF["p04"].ToString()) ; - readFeature.processParameters.Add( dRowF["p05"].ToString()) ; - readFeature.processParameters.Add( dRowF["p06"].ToString()) ; - readFeature.processParameters.Add( dRowF["p07"].ToString()) ; - readFeature.processParameters.Add( dRowF["p08"].ToString()) ; - readFeature.processParameters.Add( dRowF["p09"].ToString()) ; - readFeature.processParameters.Add( dRowF["p10"].ToString()) ; - readFeature.processParameters.Add( dRowF["p11"].ToString()) ; - readFeature.processParameters.Add( dRowF["p12"].ToString()) ; - readFeature.processParameters.Add( dRowF["p13"].ToString()) ; - readFeature.processParameters.Add( dRowF["p14"].ToString()) ; - readFeature.processParameters.Add( dRowF["p15"].ToString()) ; - readFeature.processParameters.Add( dRowF["p16"].ToString()) ; - readFeature.processParameters.Add( dRowF["p17"].ToString()) ; - readFeature.processParameters.Add( dRowF["p18"].ToString()) ; - readFeature.processParameters.Add( dRowF["p19"].ToString()) ; - readFeature.processParameters.Add( dRowF["p20"].ToString()) ; - readFeature.processParameters.Add( dRowF["p21"].ToString()) ; - readFeature.processParameters.Add( dRowF["p22"].ToString()) ; - readFeature.processParameters.Add( dRowF["p23"].ToString()) ; - readFeature.processParameters.Add( dRowF["p24"].ToString()) ; - readFeature.processParameters.Add( dRowF["p25"].ToString()) ; - readFeature.processParameters.Add( dRowF["p26"].ToString()) ; - - readFeature.processParameters.Add( dRowF["q01"].ToString()) ; - readFeature.processParameters.Add( dRowF["q02"].ToString()) ; - readFeature.processParameters.Add( dRowF["q03"].ToString()) ; - readFeature.processParameters.Add( dRowF["q04"].ToString()) ; - readFeature.processParameters.Add( dRowF["q05"].ToString()) ; - readFeature.processParameters.Add( dRowF["q06"].ToString()) ; - readFeature.processParameters.Add( dRowF["q07"].ToString()) ; - readFeature.processParameters.Add( dRowF["q08"].ToString()) ; - readFeature.processParameters.Add( dRowF["q09"].ToString()) ; - readFeature.processParameters.Add( dRowF["q10"].ToString()) ; - readFeature.processParameters.Add( dRowF["q11"].ToString()) ; - readFeature.processParameters.Add( dRowF["q12"].ToString()) ; - readFeature.processParameters.Add( dRowF["q13"].ToString()) ; - readFeature.processParameters.Add( dRowF["q14"].ToString()) ; - readFeature.processParameters.Add( dRowF["q15"].ToString()) ; - readFeature.processParameters.Add( dRowF["q16"].ToString()) ; - readFeature.processParameters.Add( dRowF["q17"].ToString()) ; - readFeature.processParameters.Add( dRowF["q18"].ToString()) ; - readFeature.processParameters.Add( dRowF["q19"].ToString()) ; - readFeature.processParameters.Add( dRowF["q20"].ToString()) ; - + BTL.Feature readFeature = new BTL.Feature() { + processId = dRowF["processId"].ToString(), + processKey = dRowF["group"].ToString() + + "-" + dRowF["key"].ToString().Substring( 1, 3) + + "-" + dRowF["face"].ToString(), + designation = dRowF["des"].ToString(), + processIdent = dRowF["processIdent"].ToString(), + sag1 = dRowF["sag1"].ToString(), + process = ( Convert.ToInt16( dRowF["enabled"]) == 1) ? "YES" : "NO", + processParameters = new List( 46) { + dRowF["p01"].ToString(), + dRowF["p02"].ToString(), + dRowF["p03"].ToString(), + dRowF["p04"].ToString(), + dRowF["p05"].ToString(), + dRowF["p06"].ToString(), + dRowF["p07"].ToString(), + dRowF["p08"].ToString(), + dRowF["p09"].ToString(), + dRowF["p10"].ToString(), + dRowF["p11"].ToString(), + dRowF["p12"].ToString(), + dRowF["p13"].ToString(), + dRowF["p14"].ToString(), + dRowF["p15"].ToString(), + dRowF["p16"].ToString(), + dRowF["p17"].ToString(), + dRowF["p18"].ToString(), + dRowF["p19"].ToString(), + dRowF["p20"].ToString(), + dRowF["p21"].ToString(), + dRowF["p22"].ToString(), + dRowF["p23"].ToString(), + dRowF["p24"].ToString(), + dRowF["p25"].ToString(), + dRowF["p26"].ToString(), + dRowF["q01"].ToString(), + dRowF["q02"].ToString(), + dRowF["q03"].ToString(), + dRowF["q04"].ToString(), + dRowF["q05"].ToString(), + dRowF["q06"].ToString(), + dRowF["q07"].ToString(), + dRowF["q08"].ToString(), + dRowF["q09"].ToString(), + dRowF["q10"].ToString(), + dRowF["q11"].ToString(), + dRowF["q12"].ToString(), + dRowF["q13"].ToString(), + dRowF["q14"].ToString(), + dRowF["q15"].ToString(), + dRowF["q16"].ToString(), + dRowF["q17"].ToString(), + dRowF["q18"].ToString(), + dRowF["q19"].ToString(), + dRowF["q20"].ToString() + }, + } ; readPart.features.Add( readFeature) ; } btlObject.parts.Add( readPart) ; @@ -463,41 +432,33 @@ namespace ib.essetre.integration.egaltech // 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) + private static List GetListaCutIdP() { List ListaCutId = new List() ; - string sqlCutId = "SELECT cutId FROM dbo.vw_Cut WHERE patternId = @firstId " + - "AND productionId = @secondId"; - - // Connessione al DB ed esecuzione query - using ( SqlConnection cn = new SqlConnection( Constants.ConnectionString)) { - cn.Open() ; - using ( SqlCommand sqlCommand = new SqlCommand( sqlCutId, cn)) { - sqlCommand.Parameters.Add( "@firstId", SqlDbType.Int) ; - sqlCommand.Parameters.Add( "@secondId", SqlDbType.Int) ; - sqlCommand.Parameters["@firstId"].Value = patternId ; - sqlCommand.Parameters["@secondId"].Value = productionId ; - SqlDataReader reader = sqlCommand.ExecuteReader() ; - while ( reader.Read()) { - ListaCutId.Add( (int)reader["cutId"]) ; - } - } + DataTable dTab = ds.Tables[0] ; + int listaTasksCount = dTab.Rows.Count ; + for ( int f = 0 ; f < listaTasksCount ; f++) { + int nCut = (int) dTab.Rows[f]["cutId"] ; + if ( ! ListaCutId.Contains( nCut)) + ListaCutId.Add( nCut) ; } return ListaCutId ; } // Recupera la lunghezza della barra nel caso Produzione (colonna "l") - private static double getBarLengthP( int patternId, int productionId) + private static double GetBarLengthP( int patternId, int productionId) { double barLength = 0 ; - string sqlBarLength = "SELECT l FROM dbo.vw_Pattern WHERE patternId = @firstId " + + string sqlBarLength = "SELECT l " + + "FROM dbo.vw_Pattern " + + "WHERE patternId = @firstId " + "AND productionId = @secondId" ; // Connessione al DB ed esecuzione query - using ( SqlConnection cn = new SqlConnection( Constants.ConnectionString)) { + using ( SqlConnection cn = new SqlConnection( SqlConnectionStr)) { cn.Open() ; using ( SqlCommand sqlCommand = new SqlCommand( sqlBarLength, cn)) { sqlCommand.Parameters.Add( "@firstId", SqlDbType.Int) ; @@ -516,29 +477,16 @@ namespace ib.essetre.integration.egaltech // Recupera 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 double getBarLengthO( int elementId, int projectId) + private static double GetBarLengthO( int elementId, int projectId) { double barLength = 0 ; - string sqlBarLength = "SELECT length FROM dbo.vw_Element WHERE elementId = @firstId " + - "AND projectId = @secondId"; + DataTable dTab = ds.Tables[0] ; + int listaProcessesCount = dTab.Rows.Count ; + if ( listaProcessesCount > 0) + barLength = Convert.ToDouble( dTab.Rows[0]["length"]) + Constants.BarAddLen ; - // Connessione al DB ed esecuzione query - using ( SqlConnection cn = new SqlConnection( Constants.ConnectionString)) { - cn.Open() ; - using ( SqlCommand sqlCommand = new SqlCommand( sqlBarLength, cn)) { - sqlCommand.Parameters.Add( "@firstId", SqlDbType.Int) ; - sqlCommand.Parameters.Add( "@secondId", SqlDbType.Int) ; - sqlCommand.Parameters["@firstId"].Value = elementId ; - sqlCommand.Parameters["@secondId"].Value = projectId ; - SqlDataReader reader = sqlCommand.ExecuteReader() ; - while ( reader.Read()) { - barLength = Convert.ToDouble( reader["length"]) ; - } - } - } - - return ( barLength + 2000) ; + return barLength ; } }