From 55310be90157ff4a74d0102e515ff321ea5c6f4e Mon Sep 17 00:00:00 2001 From: Dario Sassi Date: Fri, 8 Feb 2019 19:46:52 +0000 Subject: [PATCH] Integration 2.1b5 : - diverse semplificazioni e ottimizzazioni. --- IntegrationEgaltech/Generator.cs | 1025 ++++++++--------- .../IntegrationEgaltech.csproj | 1 + .../Properties/AssemblyInfo.cs | 4 +- 3 files changed, 495 insertions(+), 535 deletions(-) diff --git a/IntegrationEgaltech/Generator.cs b/IntegrationEgaltech/Generator.cs index 4d6c0c3..f8891a2 100644 --- a/IntegrationEgaltech/Generator.cs +++ b/IntegrationEgaltech/Generator.cs @@ -13,574 +13,533 @@ 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(InOutParameters parameters, ICallBack callback) - { - _thread = new Thread(() => DoJob(parameters, callback)); + public void Run(InOutParameters parameters, ICallBack callback) + { + _thread = new Thread(() => DoJob(parameters, callback)); - _thread.Start(); - } + _thread.Start(); + } - private delegate void dDoJob(InOutParameters parameters, ICallBack callback); + private delegate void dDoJob( InOutParameters parameters, ICallBack callback) ; - // campo data ultima modifica nel DATABASE [lastModified] - private static void DoJob(InOutParameters parameters, ICallBack callback) - { - callback.Progress(0, "Init"); + // campo data ultima modifica nel DATABASE [lastModified] + private static void DoJob( InOutParameters parameters, ICallBack callback) + { + callback.Progress( 0, "Init") ; - String ExePath = parameters.Read("EGALTECH", "PATH_EXE", ""); - String BtlDir = parameters.Read("EGALTECH", "DIR_BTL", ""); + String ExePath = parameters.Read( "EGALTECH", "PATH_EXE", "") ; + String BtlDir = parameters.Read( "EGALTECH", "DIR_BTL", "") ; - int numBars = parameters.Patterns.Length; + int numBars = parameters.Patterns.Length ; - for (int i = 0; i < numBars; i++) - { + for ( int i = 0; i < numBars; i++) { - BTL btlObject = new BTL(); + BTL btlObject = new BTL() ; - 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 = @firstId" + - " and vw_Task.productionId = @secondId"; - - String sqlProject = - "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, " + - "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"; - - string sql = null; - - // 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; - - // Connessione al DB ed esecuzione query - var cn = new SqlConnection(Constants.ConnectionString); - 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; - } - else - { - cmd.Parameters["@firstId"].Value = (Int32)parameters.Patterns[i].PatternId; - cmd.Parameters["@secondId"].Value = (Int32)parameters.Patterns[i].ProductionId; - } - 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()); - - } - cn.Close(); - - // 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); - - // 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); - - // 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; - Process process = Process.Start(ExePath, path); - - // Attendo il termine del processo - while (!process.HasExited) - { - process.Refresh(); - System.Threading.Thread.Sleep(50); - } - - // 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; - } - } - parameters.Patterns[i].SetTaskState(cutId, taskId, resExe, textErr); - - PatternInfo.Results res; - string msg; - parameters.Patterns[i].GetTaskState(cutId, taskId, out res, out msg); - System.Windows.Forms.MessageBox.Show(msg, res.ToString()); - - // Lettura OutputFilename e scrittura nel parametro stringa Iso (solo nel caso UIModes.HIDDEN) - if (parameters.UIMode == InOutParameters.UIModes.HIDDEN) - { - - 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; - } - else - { - parameters.Patterns[i].Iso = ""; - parameters.Patterns[i].Result = PatternInfo.Results.ERROR; - parameters.Patterns[i].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(); - //} - } + // 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) { + 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, " + + "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"; + } + 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.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"; } - callback.Progress(1, "End"); + // Connessione al DB ed esecuzione query + using ( SqlConnection cn = new SqlConnection( parameters.ConnectionString)) { + 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 ; + } + else { + cmd.Parameters["@firstId"].Value = (Int32)parameters.Patterns[i].PatternId ; + cmd.Parameters["@secondId"].Value = (Int32)parameters.Patterns[i].ProductionId ; + } + var dataAdapter = new SqlDataAdapter( cmd) ; - callback.Done(parameters); //fine - } + // Lettura DB e riempimento DataSet + ds.Clear() ; + dataAdapter.Fill( ds) ; + } + } - 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; + // 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 - return nVal; - } + getListaTasks( btlObject, 0) ; - public void Abort() - { - //non implementata al momento - } + // 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); - // 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; + // 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 ; + Process process = Process.Start( ExePath, path) ; - 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]["cutId"].ToString(); - readPart.count = Convert.ToString(1); - 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; - if (listaProcessesCount == 0) - return; - - 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(1); - ListaCutParts.Add((int)ds.Tables[i].Rows[0]["elementId"]); - - 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]["elementId"] == ListaCutParts[c]) - { - readPart.singleMemberNumber = ds.Tables[i].Rows[ltc]["elementId"].ToString(); - readPart.count = Convert.ToString(1); - 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.elementId = (int)ds.Tables[i].Rows[ltc]["elementId"]; - } - - readPart.features = new List(); - - for (int f = 0; f < listaProcessesCount; f++) - { - if ((int)ds.Tables[i].Rows[f]["elementId"] == 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(); + //parameters.Patterns[i].GetTaskState( cutId, taskId, out PatternInfo.Results res, out string msg) ; + //System.Windows.Forms.MessageBox.Show( msg, res.ToString()) ; - string sqlCutId = "SELECT cutId FROM dbo.vw_Cut WHERE patternId = @firstId " + - "AND productionId = @secondId"; + // Lettura OutputFilename e scrittura nel parametro stringa Iso (solo nel caso UIModes.HIDDEN) + if ( parameters.UIMode == InOutParameters.UIModes.HIDDEN) { - // Connessione al DB ed esecuzione query - var cn = new SqlConnection(Constants.ConnectionString); - 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; - cn.Open(); - SqlDataReader reader = sqlCommand.ExecuteReader(); - while (reader.Read()) - { - ListaCutId.Add((int)reader["cutId"]); - } + 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 ; + } + else { + parameters.Patterns[i].Iso = "" ; + parameters.Patterns[i].Result = PatternInfo.Results.ERROR ; + parameters.Patterns[i].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(); + //} } - cn.Close(); + } - return ListaCutId; - } + callback.Progress( 1, "End") ; - //Ottiene la lunghezza della barra nel caso Produzione (colonna "l") - private static int getBarLengthP(int patternId, int productionId) - { - int barLength = 0; + callback.Done( parameters) ; //fine + } - string sqlBarLength = "SELECT l FROM dbo.vw_Pattern WHERE patternId = @firstId " + - "AND productionId = @secondId"; + private static int? GetVal( string sText, string sKey) + { + string[] sParts = sText.Split( new Char[] { '=' }) ; + if ( string.Compare( sParts[0], sKey) != 0) + return null ; + if ( ! int.TryParse( sParts[1], out int nVal)) + return null ; + else + return nVal ; + } - // Connessione al DB ed esecuzione query - var cn = new SqlConnection(Constants.ConnectionString); - using (SqlCommand sqlCommand = new SqlCommand(sqlBarLength, cn)) - { - sqlCommand.Parameters.Add("@firstId", SqlDbType.Int); - sqlCommand.Parameters.Add("@secondId", SqlDbType.Int); - sqlCommand.Parameters["@firstId"].Value = patternId; - sqlCommand.Parameters["@secondId"].Value = productionId; - cn.Open(); - SqlDataReader reader = sqlCommand.ExecuteReader(); - while (reader.Read()) - { - barLength = Convert.ToInt16(reader["l"]); - } + 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) + { + DataTable dTab = ds.Tables[i] ; + Int32 listaTasksCount = dTab.Rows.Count ; + if ( listaTasksCount == 0) + return ; + + 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.productionId = (int)dRow0["productionId"] ; + btlObject.patternId = (int)dRow0["patternId"] ; + btlObject.parts = new List() ; + + List ListaCutParts = getListaCutIdP( (int)dRow0["patternId"], (int)dTab.Rows[i]["productionId"]) ; + + for ( int c = 0 ; c < ListaCutParts.Count ; c++) { + + BTL.Part readPart = new BTL.Part() ; + + bool bFirst = true ; + for ( int f = 0; f < listaTasksCount; f++) { + + DataRow dRowF = dTab.Rows[f] ; + if ( (int)dRowF["cutId"] != ListaCutParts[c]) + continue ; + + if ( bFirst) { + readPart.singleMemberNumber = dRowF["cutId"].ToString() ; + readPart.count = "1" ; + readPart.length = dRowF["length"].ToString() ; + readPart.height = dRowF["height"].ToString() ; + readPart.width = dRowF["width"].ToString() ; + readPart.x = (double)dRowF["x"] ; + readPart.inverted = dRowF["inverted"].ToString() ; + readPart.rotated = dRowF["rotated"].ToString() ; + readPart.cutId = (int)dRowF["cutId"] ; + bFirst = false ; + 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()) ; + + readPart.features.Add( readFeature) ; } - cn.Close(); + 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)) ; + } - return barLength; - } + // 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) + { + DataTable dTab = ds.Tables[i] ; + Int32 listaProcessesCount = dTab.Rows.Count ; + if ( listaProcessesCount == 0) + return ; - //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; + 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.projectId = (int)dRow0["projectId"] ; + btlObject.elementId = (int)dRow0["elementId"] ; + btlObject.parts = new List() ; - string sqlBarLength = "SELECT length FROM dbo.vw_Element WHERE elementId = @firstId " + - "AND projectId = @secondId"; + List ListaCutParts = new List( 1) ; + ListaCutParts.Add( (int)dRow0["elementId"]) ; - // Connessione al DB ed esecuzione query - var cn = new SqlConnection(Constants.ConnectionString); - 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; - cn.Open(); - SqlDataReader reader = sqlCommand.ExecuteReader(); - while (reader.Read()) - { - barLength = Convert.ToInt16(reader["length"]); - } + for ( int c = 0 ; c < ListaCutParts.Count ; c++) { + + BTL.Part readPart = new BTL.Part() ; + + bool bFirst = true ; + for ( int f = 0 ; f < listaProcessesCount ; f++) { + + DataRow dRowF = dTab.Rows[f] ; + if ( (int)dRowF["elementId"] != ListaCutParts[c]) + continue ; + + if ( bFirst) { + readPart.singleMemberNumber = dRowF["elementId"].ToString() ; + readPart.count = "1" ; + readPart.length = dRowF["length"].ToString() ; + readPart.height = dRowF["height"].ToString() ; + readPart.width = dRowF["width"].ToString() ; + readPart.x = (double)dRowF["x"] ; + readPart.inverted = dRowF["inverted"].ToString() ; + readPart.rotated = dRowF["rotated"].ToString() ; + readPart.elementId = (int)dRowF["elementId"] ; + bFirst = false ; + 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()) ; + + readPart.features.Add( readFeature) ; } - cn.Close(); + 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)) ; + } - return barLength + 2000; - } + // 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 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"]) ; + } + } + } + + return ListaCutId ; + } + + // Recupera la lunghezza della barra nel caso Produzione (colonna "l") + private static double getBarLengthP( int patternId, int productionId) + { + double barLength = 0 ; + + 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)) { + 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 = patternId ; + sqlCommand.Parameters["@secondId"].Value = productionId ; + SqlDataReader reader = sqlCommand.ExecuteReader() ; + while ( reader.Read()) { + barLength = Convert.ToDouble( reader["l"]) ; + } + } + } + + return barLength ; + } + + // 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) + { + double barLength = 0 ; + + string sqlBarLength = "SELECT length FROM dbo.vw_Element WHERE elementId = @firstId " + + "AND projectId = @secondId"; + + // 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) ; + } + + } } diff --git a/IntegrationEgaltech/IntegrationEgaltech.csproj b/IntegrationEgaltech/IntegrationEgaltech.csproj index fda1a5f..3f1bb81 100644 --- a/IntegrationEgaltech/IntegrationEgaltech.csproj +++ b/IntegrationEgaltech/IntegrationEgaltech.csproj @@ -32,6 +32,7 @@ prompt 4 + false diff --git a/IntegrationEgaltech/Properties/AssemblyInfo.cs b/IntegrationEgaltech/Properties/AssemblyInfo.cs index 48ee175..0c87896 100644 --- a/IntegrationEgaltech/Properties/AssemblyInfo.cs +++ b/IntegrationEgaltech/Properties/AssemblyInfo.cs @@ -36,5 +36,5 @@ using System.Runtime.InteropServices; // È possibile specificare tutti i valori oppure impostare valori predefiniti per i numeri relativi alla revisione e alla build // usando l'asterisco '*' come illustrato di seguito: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("2.1.2.4")] -[assembly: AssemblyFileVersion("2.1.2.4")] +[assembly: AssemblyVersion("2.1.2.5")] +[assembly: AssemblyFileVersion("2.1.2.5")]