895 lines
26 KiB
C#
895 lines
26 KiB
C#
using Newtonsoft.Json;
|
|
using Newtonsoft.Json.Converters;
|
|
using NKC_SDK;
|
|
using SteamWare;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
|
|
namespace AppData
|
|
{
|
|
/// <summary>
|
|
/// Classe con metodi di supporto per COMUNICAZIONE
|
|
/// </summary>
|
|
public class ComLib
|
|
{
|
|
|
|
/// <summary>
|
|
/// Wrapper traduzione termini
|
|
/// </summary>
|
|
/// <param name="lemma"></param>
|
|
/// <returns></returns>
|
|
public static string traduci(string lemma)
|
|
{
|
|
return user_std.UtSn.Traduci(lemma);
|
|
}
|
|
#region conf posizioni redis
|
|
|
|
protected static string redOutPath = "NKC:SERV:BREQ";
|
|
protected static string redMsgCount = "NKC:SERV:BREQ:MCount";
|
|
protected static string redMsgList = "NKC:SERV:BREQ:MList";
|
|
protected static string redMLCurrStack = "NKC:SERV:TAKT:CurrStack";
|
|
|
|
protected static string redNestAnsw = "NKC:NEST:BANSW";
|
|
|
|
protected static string redProdReq = "NKC:SERV:BUNKS";
|
|
protected static string redProdAnsw = "NKC:PROD:BUNKS";
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
#region definizione classi impiegate con PROD
|
|
|
|
|
|
|
|
public static string PositionStatusDescr(object value)
|
|
{
|
|
string answ = "";
|
|
try
|
|
{
|
|
BatchPosition pStatus = (BatchPosition)Enum.Parse(typeof(BatchPosition), value.ToString());
|
|
switch (pStatus)
|
|
{
|
|
case BatchPosition.NotStarted:
|
|
answ = traduci("NotStarted");
|
|
break;
|
|
case BatchPosition.StackStarted:
|
|
answ = traduci("Stacking");
|
|
break;
|
|
case BatchPosition.StackDone:
|
|
answ = traduci("StackDone");
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
catch
|
|
{ }
|
|
return answ;
|
|
}
|
|
public static string BatchStatusDescr(object value)
|
|
{
|
|
string answ = "";
|
|
try
|
|
{
|
|
BatchStatus bStatus = (BatchStatus)Enum.Parse(typeof(BatchStatus), value.ToString());
|
|
switch (bStatus)
|
|
{
|
|
case BatchStatus.Imported:
|
|
answ = "Imported";
|
|
break;
|
|
case BatchStatus.EstimationRequested:
|
|
answ = "Estimation Requested";
|
|
break;
|
|
case BatchStatus.EstimationDone:
|
|
answ = "Estimation Completed";
|
|
break;
|
|
case BatchStatus.NestRequested:
|
|
answ = "Nesting Requested";
|
|
break;
|
|
case BatchStatus.NestDone:
|
|
answ = "Nesting Completed";
|
|
break;
|
|
case BatchStatus.Approved:
|
|
answ = "Nesting Approved";
|
|
break;
|
|
case BatchStatus.Discarded:
|
|
answ = "Nesting Discarded";
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
catch
|
|
{ }
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Oggetto globale TAKT
|
|
/// </summary>
|
|
public class Takt
|
|
{
|
|
/// <summary>
|
|
/// Codice univoco oggetto TAKT (data.num)
|
|
/// </summary>
|
|
public string TaktId { get; set; }
|
|
/// <summary>
|
|
/// Stato del TAKT
|
|
/// </summary>
|
|
public CStatus Status { get; set; }
|
|
/// <summary>
|
|
/// Elenco degli Stack da lavorare
|
|
/// </summary>
|
|
public List<ProdBunk> StackList { get; set; }
|
|
/// <summary>
|
|
/// Numero di Stack da lavorare
|
|
/// </summary>
|
|
public int NumStack
|
|
{
|
|
get
|
|
{
|
|
int answ = 0;
|
|
try
|
|
{
|
|
answ = StackList.Count;
|
|
}
|
|
catch
|
|
{ }
|
|
return answ;
|
|
}
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region definizione classi impiegate con NEST
|
|
|
|
|
|
public class Parte
|
|
{
|
|
public int PartId { get; set; }
|
|
public string DataMatrix { get; set; }
|
|
public string ExtCode { get; set; }
|
|
public string Description { get; set; }
|
|
public int MatId { get; set; }
|
|
public string PostProc { get; set; }
|
|
public string ProcessReq { get; set; }
|
|
public string CadFilePath { get; set; }
|
|
public int Qty { get; set; }
|
|
}
|
|
|
|
public class Batch
|
|
{
|
|
/// <summary>
|
|
/// ID del batch in esecuzione
|
|
/// </summary>
|
|
public int BatchId { get; set; }
|
|
/// <summary>
|
|
/// tempo amssimo eprmesso x nesting (minuti)
|
|
/// </summary>
|
|
public int maxTime { get; set; }
|
|
/// <summary>
|
|
/// Tipo di processing richeisto
|
|
/// </summary>
|
|
public int procType { get; set; }
|
|
/// <summary>
|
|
/// Codice della amcchina x cui si effettua richeista
|
|
/// </summary>
|
|
[JsonConverter(typeof(StringEnumConverter))]
|
|
public mType machineType { get; set; }
|
|
/// <summary>
|
|
/// Tipo di ordine richeisto
|
|
/// </summary>
|
|
[JsonConverter(typeof(StringEnumConverter))]
|
|
public oType orderType { get; set; }
|
|
}
|
|
/// <summary>
|
|
/// Salva su redis l'oggetto dei materiali serializzato
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public static bool sendMaterials()
|
|
{
|
|
bool answ = false;
|
|
// leggo tab MNATERIALS da DB
|
|
var table = DataLayer.man.taMat.GetData();
|
|
// serializzo
|
|
string redVal = JsonConvert.SerializeObject(table);
|
|
// salvo
|
|
string redKey = $"NKC:SERV:CONF:MATERIALS";
|
|
// scrivo per ora solo su REDIS
|
|
memLayer.ML.setRSV(redKey, redVal);
|
|
return answ;
|
|
}
|
|
/// <summary>
|
|
/// Restituisce il prossimo codice di envelope per comunicare con sistemi esterni
|
|
/// </summary>
|
|
/// <param name="BatchID">Batch contenuto nell'envelope</param>
|
|
/// <param name="note">note opzionali (motivo envelope)</param>
|
|
/// <returns></returns>
|
|
public static string getNextEnv(int BatchID, string note)
|
|
{
|
|
// incremento counter
|
|
long nextIndex = memLayer.ML.setRCntI(redMsgCount);
|
|
// salvo contenuto della busta
|
|
string answ = $"Z{nextIndex:000000000000}";
|
|
Dictionary<string, string> lista = new Dictionary<string, string>();
|
|
lista.Add(answ, $"{BatchID}|{note}");
|
|
memLayer.ML.redSaveHashDict(redMsgList, lista);
|
|
// ritorno
|
|
return answ;
|
|
}
|
|
/// <summary>
|
|
/// Restituisce elenco KVP delle buste ancora "pending" (quando processate le elimina da elenco...)
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public static KeyValuePair<string, string>[] getEnvList()
|
|
{
|
|
KeyValuePair<string, string>[] answ = memLayer.ML.redGetHash(redMsgList);
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Invia una richiesta di esecuzione di Nesting x un Batch
|
|
/// </summary>
|
|
/// <param name="BatchID">Batch di cui si chiede processing</param>
|
|
/// <param name="note">note opzionali</param>
|
|
/// <returns></returns>
|
|
public static bool sendBatchReq(int BatchID, string note)
|
|
{
|
|
bool answ = false;
|
|
// per prima cosa mi serve una "nuova busta" per inviare i messaggi
|
|
string nextEnv = getNextEnv(BatchID, note);
|
|
// preparo il contenuto della busta ed invio i messaggi...
|
|
try
|
|
{
|
|
// in base allo stato del BATCH corrente determino il tempo e le opzioni da inviare...
|
|
var batch = DataLayer.man.taBL.getByKey(BatchID);
|
|
int mTime = 1;
|
|
int pType = 1;
|
|
if (batch[0].STATUS < (int)BatchStatus.EstimationDone)
|
|
{
|
|
mTime = memLayer.ML.cdvi("estimMaxTime");
|
|
}
|
|
else
|
|
{
|
|
mTime = memLayer.ML.cdvi("nestMaxTime");
|
|
pType = 2;
|
|
}
|
|
// leggo tab ORDINI da DB
|
|
var tblOrd = DataLayer.man.taOL.getByBatch(BatchID);
|
|
// serializzo
|
|
string redVal = JsonConvert.SerializeObject(tblOrd);
|
|
// salvo
|
|
string redKey = $"{redOutPath}:{nextEnv}:ORDERS";
|
|
// scrivo su REDIS
|
|
memLayer.ML.setRSV(redKey, redVal);
|
|
|
|
var tblItm = DataLayer.man.taIL.getByBatch(BatchID);
|
|
// serializzo
|
|
redVal = JsonConvert.SerializeObject(tblItm);
|
|
// salvo
|
|
redKey = $"{redOutPath}:{nextEnv}:ITEMS";
|
|
// scrivo su REDIS
|
|
memLayer.ML.setRSV(redKey, redVal);
|
|
// ora versione gerarchica
|
|
var currBatch = new Batch()
|
|
{
|
|
BatchId = BatchID,
|
|
maxTime = mTime,
|
|
procType = pType,
|
|
machineType = mType.Multiax,
|
|
orderType = oType.BatchRequest
|
|
};
|
|
// serializzo
|
|
redVal = JsonConvert.SerializeObject(currBatch);
|
|
// salvo
|
|
redKey = $"{redOutPath}:{nextEnv}:DATA";
|
|
// scrivo su REDIS
|
|
memLayer.ML.setRSV(redKey, redVal);
|
|
|
|
// invio notifica che c'è una busta da processare
|
|
redKey = $"{redOutPath}:CURR";
|
|
// scrivo su REDIS
|
|
memLayer.ML.setRSV(redKey, nextEnv);
|
|
answ = true;
|
|
}
|
|
catch
|
|
{ }
|
|
// restituisco ok
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Invia una richiesta di esecuzione di CAM x un ordine offline
|
|
/// </summary>
|
|
/// <param name="OffOrderID">OfflineOrder di cui si chiede processing</param>
|
|
/// <param name="note">note opzionali</param>
|
|
/// <returns></returns>
|
|
public static bool sendOfflineOrderReq(int OffOrderID, string note)
|
|
{
|
|
bool answ = false;
|
|
// per prima cosa mi serve una "nuova busta" per inviare i messaggi
|
|
string nextEnv = getNextEnv(OffOrderID, note);
|
|
// preparo il contenuto della busta ed invio i messaggi...
|
|
try
|
|
{
|
|
int mTime = 5;
|
|
int pType = 1;
|
|
// serializzo ordini come ARRAY VUOTO
|
|
string redVal = "[]";
|
|
// salvo
|
|
string redKey = $"{redOutPath}:{nextEnv}:ORDERS";
|
|
// scrivo su REDIS
|
|
memLayer.ML.setRSV(redKey, redVal);
|
|
// ora ITEMS
|
|
var tblItm = DataLayer.man.taIL.getByOfflineOrder(OffOrderID);
|
|
// serializzo
|
|
redVal = JsonConvert.SerializeObject(tblItm);
|
|
// salvo
|
|
redKey = $"{redOutPath}:{nextEnv}:ITEMS";
|
|
// scrivo su REDIS
|
|
memLayer.ML.setRSV(redKey, redVal);
|
|
// ora versione gerarchica
|
|
var currBatch = new Batch()
|
|
{
|
|
BatchId = OffOrderID,
|
|
maxTime = mTime,
|
|
procType = pType,
|
|
machineType = mType.Offline,
|
|
orderType = oType.OfflineOrder
|
|
};
|
|
// serializzo
|
|
redVal = JsonConvert.SerializeObject(currBatch);
|
|
// salvo
|
|
redKey = $"{redOutPath}:{nextEnv}:DATA";
|
|
// scrivo su REDIS
|
|
memLayer.ML.setRSV(redKey, redVal);
|
|
|
|
// invio notifica che c'è una busta da processare
|
|
redKey = $"{redOutPath}:CURR";
|
|
// scrivo su REDIS
|
|
memLayer.ML.setRSV(redKey, nextEnv);
|
|
answ = true;
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
logger.lg.scriviLog($"Eccezione in sendOfflineOrderReq:{Environment.NewLine}{exc}");
|
|
}
|
|
// restituisco ok
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Verifica lo stato di una richiesta di esecuzione
|
|
/// </summary>
|
|
/// <param name="OffOrderID">OfflineOrder di cui si chiede processing</param>
|
|
/// <param name="note">note opzionali</param>
|
|
/// <returns></returns>
|
|
public static bool checkOfflineOrderReq(int OffOrderID)
|
|
{
|
|
bool answ = false;
|
|
string typeSearch = "OffOrdCalculation";
|
|
string keyEnv = "";
|
|
// recupero lista dei vari task APERTI...
|
|
KeyValuePair<string, string>[] comAperte = getEnvList();
|
|
// processo x cercare ordine...
|
|
foreach (var item in comAperte)
|
|
{
|
|
// cerco dove sia quello richiesto
|
|
if (item.Value.Contains(typeSearch))
|
|
{
|
|
// controllo SE sia quello richiesto
|
|
if (item.Value == $"{OffOrderID}|{typeSearch}")
|
|
{
|
|
keyEnv = item.Key;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
// controllo e se c'è risposta --> update DB
|
|
string redKey = $"{redNestAnsw}:FULL:{keyEnv}";
|
|
string rawAnsw = memLayer.ML.getRSV(redKey);
|
|
if (rawAnsw != "")
|
|
{
|
|
// cerco risposta come stack --> disegno...
|
|
var offOrder = deserializeOfflineOrder(rawAnsw);
|
|
// se ho in risposta 1 stack...
|
|
if (offOrder.Stacks.Count == 1)
|
|
{
|
|
// se ho 1 solo sheet
|
|
var sheets = offOrder.Stacks[0].SheetList;
|
|
if (sheets.Count == 1)
|
|
{
|
|
// controllo se ho CNC prog
|
|
answ = sheets[0].MachiningProgram != "";
|
|
if (answ)
|
|
{
|
|
// aggiorno su DB il disegno...
|
|
string disegno = sheets[0].Drawing;
|
|
DataLayer.man.taOffOL.updateDrawing(OffOrderID, disegno);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
// restituisco ok
|
|
return answ;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region metodi helper di conversione
|
|
|
|
/// <summary>
|
|
/// Helper x serializzare l'oggetto
|
|
/// </summary>
|
|
/// <param name="currData"></param>
|
|
/// <returns></returns>
|
|
public static string serializeTakt(Takt currData)
|
|
{
|
|
string answ = JsonConvert.SerializeObject(currData);
|
|
return answ;
|
|
}
|
|
/// <summary>
|
|
/// Helper x deserializzare l'oggetto
|
|
/// </summary>
|
|
/// <param name="rawData"></param>
|
|
/// <returns></returns>
|
|
public static Takt deserializeTakt(string rawData)
|
|
{
|
|
Takt answ = JsonConvert.DeserializeObject<Takt>(rawData);
|
|
return answ;
|
|
}
|
|
/// <summary>
|
|
/// Deserializza un ordine offline
|
|
/// </summary>
|
|
/// <param name="rawData"></param>
|
|
/// <returns></returns>
|
|
public static nestReplyOffOrd deserializeOfflineOrder(string rawData)
|
|
{
|
|
nestReplyOffOrd answ = null;
|
|
try
|
|
{
|
|
answ = JsonConvert.DeserializeObject<nestReplyOffOrd>(rawData);
|
|
}
|
|
catch
|
|
{ }
|
|
return answ;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region metodi x data persistence
|
|
|
|
/// <summary>
|
|
/// Salvo il Takt inviato
|
|
/// </summary>
|
|
/// <param name="origin">Origine del dato: SERV / PROD / NEST</param>
|
|
/// <param name="currData"></param>
|
|
/// <returns></returns>
|
|
public static bool saveTakt(string origin, Takt currData)
|
|
{
|
|
bool answ = false;
|
|
try
|
|
{
|
|
// calcolo valori redis
|
|
string redKey = $"NKC:{origin.ToUpper()}:TAKT:{currData.TaktId}";
|
|
string redVal = serializeTakt(currData);
|
|
// scrivo per ora solo su REDIS
|
|
memLayer.ML.setRSV(redKey, redVal);
|
|
answ = true;
|
|
}
|
|
catch
|
|
{ }
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Leggo il Takt inviato
|
|
/// </summary>
|
|
/// <param name="origin">Origine del dato: SERV / PROD / NEST</param>
|
|
/// <param name="currData"></param>
|
|
/// <returns></returns>
|
|
public static Takt readTakt(string origin, string TaktId)
|
|
{
|
|
Takt answ = null;
|
|
try
|
|
{
|
|
string redKey = $"NKC:{origin.ToUpper()}:TAKT:{TaktId}";
|
|
string redVal = memLayer.ML.getRSV(redKey);
|
|
answ = deserializeTakt(redVal);
|
|
}
|
|
catch
|
|
{ }
|
|
return answ;
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
#region metodi per PROD
|
|
|
|
/// <summary>
|
|
/// Esegue richieste lettura da PROD
|
|
/// </summary>
|
|
public static void procProdReadReq()
|
|
{
|
|
// !!!FIXME!!!
|
|
}
|
|
/// <summary>
|
|
/// Esegue richieste lettura da PROD
|
|
/// </summary>
|
|
public static void procProdWriteReq()
|
|
{
|
|
// !!!FIXME!!!
|
|
}
|
|
|
|
/// <summary>
|
|
/// Fornisce il prossimo TAKT da elaborare oppure null se non ce ne fossero altri da elaborare per la data CORRENTE
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public Takt prodGetNextTakt()
|
|
{
|
|
return null;
|
|
}
|
|
/// <summary>
|
|
/// Chiave primo bunk su redis
|
|
/// </summary>
|
|
protected static string redFirstBunkKey = $"{redProdReq}:FirstBunk";
|
|
/// <summary>
|
|
/// Chiave primo bunk su redis
|
|
/// </summary>
|
|
protected static string redAllNextBunkKey = $"{redProdReq}:NextBunk";
|
|
/// <summary>
|
|
/// TTL standard x dati da scambiare con PROD (30 gg)
|
|
/// </summary>
|
|
protected static int ttlProdData = 3600 * 24 * 30;
|
|
/// <summary>
|
|
/// Chiave primo bunk su redis
|
|
/// </summary>
|
|
protected static string redNextBunkKey(int BunkID)
|
|
{
|
|
return $"{redProdReq}:NextBunk:{BunkID}";
|
|
}
|
|
/// <summary>
|
|
/// Resetto in REDIS i dati di bunk (corrente e successivi)
|
|
/// </summary>
|
|
public static void resetRedisBunkData()
|
|
{
|
|
redisFirstBunk = null;
|
|
}
|
|
/// <summary>
|
|
/// Cache redis del PRIMO bunk da lavorare
|
|
/// </summary>
|
|
private static ProdBunk redisFirstBunk
|
|
{
|
|
get
|
|
{
|
|
ProdBunk answ = null;
|
|
string rawData = memLayer.ML.getRSV(redFirstBunkKey);
|
|
if (rawData != "")
|
|
{
|
|
// provo a deserializzare
|
|
try
|
|
{
|
|
answ = JsonConvert.DeserializeObject<ProdBunk>(rawData);
|
|
}
|
|
catch
|
|
{ }
|
|
}
|
|
return answ;
|
|
}
|
|
set
|
|
{
|
|
if (value != null)
|
|
{
|
|
string redVal = JsonConvert.SerializeObject(value);
|
|
// default lascio x 5 minuti...
|
|
memLayer.ML.setRSV(redFirstBunkKey, redVal, ttlProdData);
|
|
}
|
|
else
|
|
// se null elimino da redis
|
|
{
|
|
memLayer.ML.setRSV(redFirstBunkKey, "");
|
|
// elimino TUTTI i next...
|
|
memLayer.ML.redFlushKey(redAllNextBunkKey);
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Recupero da Redis del SUCCESSIVO bunk da lavorare
|
|
/// </summary>
|
|
/// <param name="currBunkId"></param>
|
|
/// <returns></returns>
|
|
private static ProdBunk getRedisNextBunk(int currBunkId)
|
|
{
|
|
ProdBunk answ = null;
|
|
string rawData = memLayer.ML.getRSV(redNextBunkKey(currBunkId));
|
|
if (rawData != "")
|
|
{
|
|
// provo a deserializzare
|
|
try
|
|
{
|
|
answ = JsonConvert.DeserializeObject<ProdBunk>(rawData);
|
|
}
|
|
catch
|
|
{ }
|
|
}
|
|
return answ;
|
|
}
|
|
/// <summary>
|
|
/// Salvo in Redis il SUCCESSIVO bunk da lavorare
|
|
/// </summary>
|
|
/// <param name="currBunkId"></param>
|
|
/// <param name="value"></param>
|
|
private static void setRedisNextBunk(int currBunkId, ProdBunk value)
|
|
{
|
|
if (value != null)
|
|
{
|
|
string redVal = JsonConvert.SerializeObject(value);
|
|
// default lascio x 5 minuti...
|
|
memLayer.ML.setRSV(redNextBunkKey(currBunkId), redVal, ttlProdData);
|
|
}
|
|
else
|
|
// se null elimino da redis
|
|
{
|
|
memLayer.ML.setRSV(redNextBunkKey(currBunkId), "");
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Restituisce il PRIMO bunk secondo criterio:
|
|
/// - posizione = 5 (ho letto da webApp il BUNK e preso in carico)
|
|
/// - NumSheet > NumSheetUnload
|
|
/// - Ordinato per StackIndex (crescente) x avere il più VECCHIO
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public static ProdBunk prodGetFirstBunk()
|
|
{
|
|
// cerco prima su REDIS...
|
|
ProdBunk answ = redisFirstBunk;
|
|
if (answ == null)
|
|
{
|
|
// vado sul DB e leggo ...
|
|
DS_App.StackListDataTable tabBunks = DataLayer.man.taSTL.getLoaded();
|
|
// controllo di averne almeno 1...
|
|
if (tabBunks.Count > 0)
|
|
{
|
|
DS_App.StackListRow currBunk = tabBunks[0];
|
|
answ = getBunkFromDb(currBunk);
|
|
// se ho qualcosa salvo su REDIS
|
|
redisFirstBunk = answ;
|
|
}
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Restituisce il PROSSIMO bunk secondo criterio:
|
|
/// - posizione = 5 (ho letto da webApp il BUNK e preso in carico)
|
|
/// - NumSheet > NumSheetUnload
|
|
/// - Ordinato per StackIndex (crescente) x avere il più VECCHIO
|
|
/// - SUCCESSIVO al BunkID(=StackID) ricevuto
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public static ProdBunk prodGetNextBunk(int BunkID)
|
|
{
|
|
ProdBunk answ = getRedisNextBunk(BunkID);
|
|
if (answ == null)
|
|
{
|
|
// vado sul DB e leggo ...
|
|
DS_App.StackListDataTable tabBunks = DataLayer.man.taSTL.getLoaded();
|
|
// controllo di averne almeno 1...
|
|
if (tabBunks.Count > 0)
|
|
{
|
|
DS_App.StackListRow currBunk = null;
|
|
bool trovato = false;
|
|
// ciclo
|
|
foreach (var item in tabBunks)
|
|
{
|
|
if (trovato)
|
|
{
|
|
currBunk = item;
|
|
break;
|
|
}
|
|
// controllo se sia quello richiesto
|
|
if (item.StackID == BunkID)
|
|
{
|
|
trovato = true;
|
|
}
|
|
}
|
|
// se c'è un bunk trovato --> carico
|
|
if (currBunk != null)
|
|
{
|
|
answ = getBunkFromDb(currBunk);
|
|
// salvo su redis
|
|
setRedisNextBunk(BunkID, answ);
|
|
}
|
|
}
|
|
}
|
|
return answ;
|
|
}
|
|
/// <summary>
|
|
/// Recupera e transcodifica DA DB i dati di UN SINGOLO bunk
|
|
/// </summary>
|
|
/// <param name="currBunk"></param>
|
|
/// <returns></returns>
|
|
private static ProdBunk getBunkFromDb(DS_App.StackListRow currBunk)
|
|
{
|
|
ProdBunk answ;
|
|
// calcolo attributi oggetti
|
|
CStatus currSt = CStatus.Programmed;
|
|
if (currBunk.Position == 5)
|
|
{
|
|
currSt = CStatus.Running;
|
|
}
|
|
else
|
|
{
|
|
currSt = CStatus.Done;
|
|
}
|
|
List<ProdSheet> elSheet = new List<ProdSheet>();
|
|
// recupero gli sheets di questo stack...
|
|
DS_App.SheetListDataTable tabSheets = DataLayer.man.taSHL.getByStack(currBunk.StackID);
|
|
DateTime dataStart = DateTime.Now;
|
|
ProdSheet currPanel;
|
|
foreach (var item in tabSheets)
|
|
{
|
|
// converto i workData
|
|
WorkData wdPrint = new WorkData()
|
|
{
|
|
DtStart = item.IsPrntStartNull() ? null : (DateTime?)item.PrntStart,
|
|
DtEnd = item.IsPrntEndNull() ? null : (DateTime?)item.PrntEnd,
|
|
ProgramPath = item.PrintFilePath
|
|
};
|
|
WorkData wdMachining = new WorkData()
|
|
{
|
|
DtStart = item.IsWrkStartNull() ? null : (DateTime?)item.WrkStart,
|
|
DtEnd = item.IsWrkEndNull() ? null : (DateTime?)item.WrkEnd,
|
|
ProgramPath = item.CncFilePath
|
|
};
|
|
WorkData wdUnload = new WorkData()
|
|
{
|
|
DtStart = item.IsUnlStartNull() ? null : (DateTime?)item.UnlStart,
|
|
DtEnd = item.IsUnlEndNull() ? null : (DateTime?)item.UnlEnd
|
|
};
|
|
MaterialData material = new MaterialData()
|
|
{
|
|
MaterialId = item.MatID,
|
|
MaterialDescription = item.MatDesc,
|
|
MaterialPN = item.MatExtCode.ToString()
|
|
};
|
|
PStatus currPnlStatus = PStatus.Programmed;
|
|
Enum.TryParse(item.ShStatus.ToString(), out currPnlStatus);
|
|
currPanel = new ProdSheet()
|
|
{
|
|
Printing = wdPrint,
|
|
Machining = wdMachining,
|
|
Unloading = wdUnload,
|
|
Material = material,
|
|
SheetId = item.SheetID,
|
|
Status = currPnlStatus
|
|
};
|
|
elSheet.Add(currPanel);
|
|
if (!item.IsPrntStartNull())
|
|
{
|
|
dataStart = item.PrntStart < dataStart ? item.PrntStart : dataStart;
|
|
}
|
|
}
|
|
// compongo il bunk...
|
|
answ = new ProdBunk()
|
|
{
|
|
BunkId = currBunk.StackID,
|
|
Status = currSt,
|
|
DataMatrix = currBunk.StackDtmx,
|
|
SheetList = elSheet,
|
|
DtStart = dataStart
|
|
};
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Recupera e transcodifica DA DB i dati di UN SINGOLO bunk
|
|
/// </summary>
|
|
/// <param name="currBunk"></param>
|
|
/// <returns></returns>
|
|
public static ProdBunk prodGetBunk(int StackID)
|
|
{
|
|
ProdBunk answ = null;
|
|
List<ProdSheet> elSheet = new List<ProdSheet>();
|
|
var tabBunks = DataLayer.man.taSTL.getByKey(StackID);
|
|
if (tabBunks.Count == 1)
|
|
{
|
|
DS_App.StackListRow currBunk = tabBunks[0];
|
|
// calcolo attributi oggetti
|
|
CStatus currSt = CStatus.Programmed;
|
|
if (currBunk.Position == 5)
|
|
{
|
|
currSt = CStatus.Running;
|
|
}
|
|
else
|
|
{
|
|
currSt = CStatus.Done;
|
|
}
|
|
// recupero gli sheets di questo stack...
|
|
DS_App.SheetListDataTable tabSheets = DataLayer.man.taSHL.getByStack(StackID);
|
|
DateTime dataStart = DateTime.Now;
|
|
ProdSheet currPanel;
|
|
foreach (var item in tabSheets)
|
|
{
|
|
// converto i workData
|
|
WorkData wdPrint = new WorkData()
|
|
{
|
|
DtStart = item.IsPrntStartNull() ? null : (DateTime?)item.PrntStart,
|
|
DtEnd = item.IsPrntEndNull() ? null : (DateTime?)item.PrntEnd,
|
|
ProgramPath = item.PrintFilePath
|
|
};
|
|
WorkData wdMachining = new WorkData()
|
|
{
|
|
DtStart = item.IsWrkStartNull() ? null : (DateTime?)item.WrkStart,
|
|
DtEnd = item.IsWrkEndNull() ? null : (DateTime?)item.WrkEnd,
|
|
ProgramPath = item.CncFilePath
|
|
};
|
|
WorkData wdUnload = new WorkData()
|
|
{
|
|
DtStart = item.IsUnlStartNull() ? null : (DateTime?)item.UnlStart,
|
|
DtEnd = item.IsUnlEndNull() ? null : (DateTime?)item.UnlEnd
|
|
};
|
|
MaterialData material = new MaterialData()
|
|
{
|
|
MaterialId = item.MatID,
|
|
MaterialDescription = item.MatDesc,
|
|
MaterialPN = item.MatExtCode.ToString()
|
|
};
|
|
PStatus currPnlStatus = PStatus.Programmed;
|
|
Enum.TryParse(item.ShStatus.ToString(), out currPnlStatus);
|
|
currPanel = new ProdSheet()
|
|
{
|
|
Printing = wdPrint,
|
|
Machining = wdMachining,
|
|
Unloading = wdUnload,
|
|
Material = material,
|
|
SheetId = item.StackID,
|
|
Status = currPnlStatus
|
|
};
|
|
elSheet.Add(currPanel);
|
|
if (!item.IsPrntStartNull())
|
|
{
|
|
dataStart = item.PrntStart < dataStart ? item.PrntStart : dataStart;
|
|
}
|
|
}
|
|
// compongo il bunk...
|
|
answ = new ProdBunk()
|
|
{
|
|
BunkId = currBunk.StackID,
|
|
Status = currSt,
|
|
DataMatrix = currBunk.StackDtmx,
|
|
SheetList = elSheet,
|
|
DtStart = dataStart
|
|
};
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Valore dello Stack correntemente in processing per ML (MachineLoad)
|
|
/// </summary>
|
|
public static string taktMLCurrStack
|
|
{
|
|
get
|
|
{
|
|
return memLayer.ML.getRSV(redMLCurrStack);
|
|
}
|
|
set
|
|
{
|
|
memLayer.ML.setRSV(redMLCurrStack, value);
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
}
|
|
}
|