199 lines
5.7 KiB
C#
199 lines
5.7 KiB
C#
using Newtonsoft.Json;
|
|
using SteamWare;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Web;
|
|
|
|
namespace MagData
|
|
{
|
|
public class MagDataLayer
|
|
{
|
|
#region oggetti public
|
|
|
|
// reports
|
|
public DS_ReportTableAdapters.PrintJobQueueTableAdapter taPJQ;
|
|
public DS_ReportTableAdapters.stp_prt_CartellinoFinitiOdetteTableAdapter taCartFinOdette;
|
|
|
|
#endregion
|
|
|
|
#region init classe
|
|
|
|
public MagDataLayer()
|
|
{
|
|
// inizializzaizone classe
|
|
initTA();
|
|
setupConnString();
|
|
}
|
|
|
|
private void setupConnString()
|
|
{
|
|
string connString = memLayer.ML.CRS("NKC_WFConnectionString");
|
|
// reports
|
|
taPJQ.Connection.ConnectionString = connString;
|
|
taCartFinOdette.Connection.ConnectionString = connString;
|
|
}
|
|
private void initTA()
|
|
{
|
|
// reports
|
|
taPJQ = new DS_ReportTableAdapters.PrintJobQueueTableAdapter();
|
|
taCartFinOdette = new DS_ReportTableAdapters.stp_prt_CartellinoFinitiOdetteTableAdapter();
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// oggetto static/singleton per fare chiamate sul datalayer
|
|
/// </summary>
|
|
public static MagDataLayer man = new MagDataLayer();
|
|
|
|
#endregion
|
|
|
|
#region helpers e utils
|
|
|
|
public static string redQueueConf= "MP-CTRACK:MAG:queueConf";
|
|
|
|
/// <summary>
|
|
/// Restituisce un array JSon x le conf delle code di stampa leggendo dal file
|
|
/// </summary>
|
|
/// <returns>lista oggetto Json in formato SteamwareSDK.queueConf</returns>
|
|
public List<queueConf> queueConfJson
|
|
{
|
|
get
|
|
{
|
|
List<queueConf> answ = new List<queueConf>();
|
|
string dirPath = HttpContext.Current.Server.MapPath("~/Reports/");
|
|
string nomeFile = "queueConf.json";
|
|
bool fileExist = fileMover.obj.fileExist(dirPath, nomeFile);
|
|
if (fileExist)
|
|
{
|
|
string rawData = File.ReadAllText($"{dirPath}\\{nomeFile}");
|
|
if (!string.IsNullOrEmpty(rawData))
|
|
{
|
|
try
|
|
{
|
|
answ = JsonConvert.DeserializeObject<List<queueConf>>(rawData);
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Instance.Error(exc, "Eccezione in decodifica file conf printQueue");
|
|
}
|
|
}
|
|
}
|
|
return answ;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// Cache redis della conf delle code
|
|
/// </summary>
|
|
/// <returns>lista oggetto Json in formato SteamwareSDK.queueConf</returns>
|
|
public List<queueConf> queueConf
|
|
{
|
|
get
|
|
{
|
|
List<queueConf> answ = new List<queueConf>();
|
|
string redKey = memLayer.ML.redHash(redQueueConf);
|
|
string rawData = memLayer.ML.getRSV(redKey);
|
|
if(!string.IsNullOrEmpty(rawData))
|
|
{
|
|
try
|
|
{
|
|
answ = JsonConvert.DeserializeObject<List<queueConf>>(rawData);
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Instance.Error(exc, "Eccezione in recupero dati queueConf da redis");
|
|
}
|
|
}
|
|
// controllo se vuoto rileggo da file
|
|
if(answ.Count==0)
|
|
{
|
|
answ = queueConfJson;
|
|
// a quesot punto salvo in Redis
|
|
queueConf = queueConfJson;
|
|
}
|
|
return answ;
|
|
}
|
|
set
|
|
{
|
|
string redKey = memLayer.ML.redHash(redQueueConf);
|
|
string rawData = "";
|
|
// salvo inc ache per 1 h...
|
|
memLayer.ML.setRSV(redKey, rawData, 3600);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// effettua la stampa di un documento
|
|
/// </summary>
|
|
/// <param name="keyParam">Codice UNIVOCO del documento</param>
|
|
/// <param name="printQueue">stampante specifica (da postazione o std da web.config, a cura dell'utente</param>
|
|
/// <param name="clientIp">IP del chiamante</param>
|
|
/// <returns></returns>
|
|
public bool stampaDoc(string keyParam, string printQueue, string clientIp)
|
|
{
|
|
bool answ = false;
|
|
// controllo se esista UDC
|
|
if (checkDoc(printQueue, keyParam))
|
|
{
|
|
answ = reportPrinter.obj.stampaCartellino(tipoDoc, keyParam, printQueue);
|
|
if (answ)
|
|
{
|
|
logger.lg.scriviLog(string.Format(" | {0} | stampato UDC {1} | stampante {2} | tipo {3}", clientIp, keyParam, printQueue, tipoDoc), tipoLog.INFO);
|
|
}
|
|
else
|
|
{
|
|
logger.lg.scriviLog(string.Format("ERRORE | {0} | stampato UDC {1} | stampante {2} | tipo {3}", clientIp, keyParam, printQueue, tipoDoc), tipoLog.ERROR);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
logger.lg.scriviLog(string.Format(" | {0} | Richiesta stampa per DOC tipo {1} | stampante {2} | key {3}", clientIp, tipoDoc, printQueue, keyParam), tipoLog.ERROR);
|
|
}
|
|
return answ;
|
|
}
|
|
/// <summary>
|
|
/// Verifica esistenza record da NOME CODA stampa + chiave...
|
|
/// </summary>
|
|
/// <param name="printQueue"></param>
|
|
/// <param name="keyParam"></param>
|
|
/// <returns></returns>
|
|
private bool checkDoc(string printQueue, string keyParam)
|
|
{
|
|
bool answ = false;
|
|
int intIdx = 0;
|
|
//cerco in setup queueConf
|
|
|
|
|
|
switch (printQueue)
|
|
{
|
|
case tipoDocumento.docBinPre:
|
|
break;
|
|
case tipoDocumento.docBinPost:
|
|
break;
|
|
case tipoDocumento.docCart:
|
|
break;
|
|
case tipoDocumento.docPart:
|
|
int.TryParse(keyParam, out intIdx);
|
|
var tabPart = taIL.getByKey(intIdx);
|
|
answ = tabPart.Count > 0;
|
|
break;
|
|
case tipoDocumento.docStack:
|
|
int.TryParse(keyParam, out intIdx);
|
|
var tabStack = taSTL.getByKey(intIdx);
|
|
answ = tabStack.Count > 0;
|
|
break;
|
|
case tipoDocumento.docND:
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|