Files
Integration/IntegrationEgaltech/Generator.cs
T
Renzo Lanza 984e80c1bf Integration 2.1.2.4:
-Modificate le query SQL, aggiungendo SQL Parameters ed evitando SQL Injection
-Modificata la modalità di connessione al DB, ora viene fatta col costrutto "using(...)" per garantire la chiusura della connessione
-Cancellato il metodo GetListaCutO perché non più usato
2019-02-08 11:00:13 +00:00

587 lines
33 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(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)
{
callback.Progress(0, "Init");
String ExePath = parameters.Read("EGALTECH", "PATH_EXE", "");
String BtlDir = parameters.Read("EGALTECH", "DIR_BTL", "");
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 = @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();
//}
}
}
callback.Progress(1, "End");
callback.Done(parameters); //fine
}
private static int? GetVal(string sText, string sKey)
{
string[] sParts = sText.Split(new Char[] { '=' });
if (string.Compare(sParts[0], sKey) != 0)
return null;
int nVal;
if (!int.TryParse(sParts[1], out nVal))
return null;
else
return nVal;
}
public void Abort()
{
//non implementata al momento
}
// Il seguente metodo prende i record visualizzati in ds (Caso: Produzione) e li carica in un oggetto BTL
public static void getListaTasks(BTL btlObject, int i)
{
Int32 listaTasksCount = ds.Tables[i].Rows.Count;
if (listaTasksCount == 0)
return;
btlObject.projectNumber = ds.Tables[i].Rows[0]["projectId"].ToString();
btlObject.scaleUnit = Convert.ToString(2);
btlObject.barLength = Convert.ToString(getBarLengthP((int)ds.Tables[i].Rows[0]["patternId"],
(int)ds.Tables[i].Rows[0]["productionId"]));
btlObject.parts = new List<BTL.Part>();
btlObject.productionId = (int)ds.Tables[i].Rows[0]["productionId"];
btlObject.patternId = (int)ds.Tables[i].Rows[0]["patternId"];
List<int> 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<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;
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<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>(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<BTL.Feature>();
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<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 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<int> getListaCutIdP(int patternId, int productionId)
{
List<int> ListaCutId = new List<int>();
string sqlCutId = "SELECT cutId FROM dbo.vw_Cut WHERE patternId = @firstId " +
"AND productionId = @secondId";
// 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"]);
}
}
cn.Close();
return ListaCutId;
}
//Ottiene la lunghezza della barra nel caso Produzione (colonna "l")
private static int getBarLengthP(int patternId, int productionId)
{
int barLength = 0;
string sqlBarLength = "SELECT l FROM dbo.vw_Pattern WHERE patternId = @firstId " +
"AND productionId = @secondId";
// 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"]);
}
}
cn.Close();
return barLength;
}
//Ottiene la lunghezza della barra nel caso Ordine (colonna "length", ovvero la lunghezza della singola trave)
//a cui aggiungiamo un valore fisso (es. 2000)
private static int getBarLengthO(int elementId, int projectId)
{
int barLength = 0;
string sqlBarLength = "SELECT length FROM dbo.vw_Element WHERE elementId = @firstId " +
"AND projectId = @secondId";
// 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"]);
}
}
cn.Close();
return barLength + 2000;
}
}
}