54249c1766
- primo rilascio.
614 lines
35 KiB
C#
614 lines
35 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Data.SqlClient;
|
|
using System.Diagnostics;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using ib.essetre.integration;
|
|
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 Generator()
|
|
{
|
|
Console.WriteLine("Inizializzato");
|
|
}
|
|
|
|
//public void Run(BTL btlObject, ICallBack callback)
|
|
//{
|
|
// _thread = new Thread(() => DoJob(btlObject, callback));
|
|
// _thread.Start();
|
|
//}
|
|
|
|
//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);
|
|
// }
|
|
//}
|
|
|
|
public void Run(InOutParameters parameters, ICallBack callback)
|
|
{
|
|
_thread = new Thread(() => DoJob(parameters, callback));
|
|
|
|
_thread.Start();
|
|
}
|
|
|
|
private delegate void dDoJob(InOutParameters parameters, ICallBack callback);
|
|
|
|
//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);
|
|
|
|
callback.Progress(0, "Init");
|
|
|
|
//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
|
|
|
|
//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 percorsoExe = parameters.Read("EGTCAM5", "PATH_EXE", ""); //Config.ini
|
|
//String connectionString = parameters.ConnectionString;
|
|
//parameters.Patterns(0).OutputFilename
|
|
|
|
// 2 PARAMETRI AGGIUNTI DA NOI
|
|
//parameters.Flag;
|
|
//parameters.Modifiable;
|
|
|
|
//using (System.Data.SqlClient.SqlConnection cn = new System.Data.SqlClient.SqlConnection(connectionString))
|
|
//{
|
|
//cn.Open();
|
|
|
|
//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";
|
|
|
|
int numBars = parameters.Patterns.Length;
|
|
|
|
for (int i = 0; i < numBars; i++)
|
|
{
|
|
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 = " + (Int32)parameters.Patterns[i].PatternId +
|
|
" and vw_Task.productionId = " + (Int32)parameters.Patterns[i].ProductionId;
|
|
|
|
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;
|
|
|
|
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;
|
|
|
|
var cn = new SqlConnection(Constants.ConnectionString);
|
|
SqlCommand cmd = new SqlCommand(sql, cn);
|
|
cn.Open();
|
|
var dataAdapter = new SqlDataAdapter(cmd);
|
|
|
|
//var commandBuilder = new SqlCommandBuilder(dataAdapter);
|
|
var tempDs = new DataSet();
|
|
dataAdapter.Fill(tempDs);
|
|
//ds = tempDs;
|
|
|
|
//for(int iTable = 0; iTable < ds.Tables.Count; iTable++)
|
|
//{
|
|
// if (AreTablesTheSame(ds.Tables[iTable], tempDs.Tables[0]))
|
|
// ds.Tables.Remove(ds.Tables[iTable]);
|
|
|
|
//}
|
|
|
|
//tempDs.Tables[0].TableName = "Table" + ds.Tables.Count;
|
|
//ds.Tables.Add(tempDs.Tables[0].Copy());
|
|
|
|
if(ds.Tables.Count != 0)
|
|
ds.Tables.Remove(ds.Tables[0]);
|
|
|
|
ds.Tables.Add(tempDs.Tables[0].Copy());
|
|
|
|
//tempDs.Tables[0].TableName = "Table1";
|
|
//ds.Tables.Add(tempDs.Tables[0].Copy());
|
|
//tempDs.Tables[0].TableName = "Table2";
|
|
//ds.Tables.Add(tempDs.Tables[0].Copy());
|
|
//string prova = ds.Tables[0].TableName;
|
|
//string prova2 = ds.Tables[1].TableName;
|
|
|
|
if (parameters.Patterns[i].IsFromProject)
|
|
getListaProcesses(btlObject, i);
|
|
else
|
|
getListaTasks(btlObject, i);
|
|
|
|
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);
|
|
|
|
string filePath = btlObject.writeIntoFile(parameters.Patterns[i].IsFromProject); // Constants.fullPath);
|
|
//System.Windows.Forms.MessageBox.Show("File scritto!");
|
|
//ErrorManager.writeErrorToFile(ErrorManager.ErrorType.NONE, btlObject.fileName);
|
|
|
|
//System.Diagnostics.Process.Start(filePath);
|
|
string path = "\"" + filePath + "\" " + parameters.MachineName + " " + (int)parameters.UIMode + " " + parameters.Patterns[i].OutputFilename;
|
|
Process process = Process.Start("C:\\EgtProg\\EgtCAM5\\EgtCAM5R32.exe", path); // "\"" + filePath + "\" "
|
|
//+ parameters.MachineName + " " + parameters.UIMode + " " + parameters.Patterns[0].OutputFilename);
|
|
|
|
// 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);
|
|
}
|
|
string text = System.IO.File.ReadAllText(filePath.Replace(".btl", ".txt"));
|
|
//parameters.Patterns[i].SetTaskState(btlObject.cutId, parameters.Patterns[i]. btlObject.features., PatternInfo.Results.ERROR, text);
|
|
//parameters.Patterns[i].GetTaskState(cutId, taskId, PatternInfo.Results, text);
|
|
System.Windows.Forms.MessageBox.Show(text, "Error");
|
|
|
|
////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
|
|
}
|
|
|
|
// DA SISTEMARE: i vari ds.Tables[0] (e forse anche i Rows[0]) probabilmente han bisogno dell'indice i
|
|
// in conseguenza al vettore di travi in input (al posto del vettore singolo)
|
|
|
|
// Il seguente metodo prende i record visualizzati in ds (Caso: Produzione) e li carica in un oggetto BTL
|
|
public static void getListaTasks(BTL btlObject, int i)
|
|
{
|
|
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[i]["productionId"]));
|
|
btlObject.parts = new List<BTL.Part>();
|
|
|
|
btlObject.productionId = (int)ds.Tables[i].Rows[0]["productionId"];
|
|
btlObject.patternId = (int)ds.Tables[i].Rows[0]["patternId"];
|
|
|
|
List<int> ListaCutParts = new List<int>();
|
|
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.features = new List<BTL.Feature>();
|
|
|
|
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<string>();
|
|
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);
|
|
}
|
|
}
|
|
// 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[0].Rows[0]["elementId"],
|
|
// (int)ds.Tables[0].Rows[0]["projectId"]));
|
|
btlObject.parts = new List<BTL.Part>();
|
|
|
|
btlObject.projectId = (int)ds.Tables[i].Rows[0]["projectId"];
|
|
btlObject.elementId = (int)ds.Tables[i].Rows[0]["elementId"];
|
|
|
|
List<int> ListaCutParts = new List<int>();
|
|
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.features = new List<BTL.Feature>();
|
|
|
|
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.taskId = ds.Tables[0].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<string>();
|
|
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);
|
|
}
|
|
}
|
|
// 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 si connette al Database 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<int> getListaCutIdP(int patternId, int productionId)
|
|
{
|
|
List<int> ListaCutId = new List<int>();
|
|
|
|
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(sqlCutId, cn);
|
|
SqlDataReader reader = sqlCommand.ExecuteReader();
|
|
while (reader.Read())
|
|
{
|
|
ListaCutId.Add((int)reader["cutId"]);
|
|
}
|
|
cn.Close();
|
|
}
|
|
return ListaCutId;
|
|
}
|
|
|
|
// Il seguente metodo si connette al Database 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<int> getListaCutIdO(int elementId, int projectId)
|
|
{
|
|
List<int> ListaCutId = new List<int>();
|
|
|
|
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 ed è usato solo nel caso Produzione perché nelle tabelle
|
|
//del caso Ordine non c'è la 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;
|
|
}
|
|
|
|
//private static int getBarLengthO(int elementId, int projectId)
|
|
//{
|
|
// int barLength = 0;
|
|
|
|
// // SISTEMARE: vw_Element non ha l come vW_Pattern
|
|
// string sqlBarLength = "SELECT l FROM dbo.vw_Element WHERE elementId = " + elementId +
|
|
// "AND projectId = " + projectId;
|
|
|
|
// using (SqlConnection cn = new SqlConnection(Constants.ConnectionString))
|
|
// {
|
|
// cn.Open();
|
|
// SqlCommand sqlCommand = new SqlCommand(sqlBarLength, cn);
|
|
// SqlDataReader reader = sqlCommand.ExecuteReader();
|
|
// while (reader.Read())
|
|
// {
|
|
// barLength = Convert.ToInt16(reader["l"]);
|
|
// }
|
|
// cn.Close();
|
|
// }
|
|
// return barLength;
|
|
//}
|
|
|
|
public static bool AreTablesTheSame(DataTable tbl1, DataTable tbl2)
|
|
{
|
|
if (tbl1.Rows.Count != tbl2.Rows.Count || tbl1.Columns.Count != tbl2.Columns.Count)
|
|
return false;
|
|
|
|
for (int i = 0; i < tbl1.Rows.Count; i++)
|
|
{
|
|
for (int c = 0; c < tbl1.Columns.Count; c++)
|
|
{
|
|
if (!Equals(tbl1.Rows[i][c], tbl2.Rows[i][c]))
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
}
|
|
}
|