using MapoDb;
using SteamWare;
using System;
using System.Web.UI;
namespace MoonProTablet.WebUserControls
{
public partial class mod_dettMacchina : System.Web.UI.UserControl
{
///
/// fatto refresh --> chiedo remove modal (se c'è)
///
public event EventHandler eh_reqRemoveModal;
///
/// idx macchina selezionata
///
public string idxMacchina
{
get
{
return memLayer.ML.StringSessionObj("IdxMacchina");
}
set
{
memLayer.ML.setSessionVal("IdxMacchina", value);
}
}
///
/// caricamento pagina
///
///
///
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
dmTimer.Interval = memLayer.ML.CRI("dtTimerInt");
}
// controllo se ho dett macchina altrimenti ritorno a pagina generale...
if (idxMacchina == "")
{
Response.Redirect("~/MappaStato.aspx");
}
//hlFermate.Visible = showInsFermata;
}
///
/// url completo immagine
///
///
///
public string ImgUrl(object url)
{
if (url.ToString() == "")
{
url = "empty.png";
}
return string.Format("./images/macchine/{0}", url);
}
///
/// fomratta durata in minuti/ore/gg a seconda del totale...
///
///
///
public string formatDurata(object min)
{
return utility.formatDurata(min);
}
///
/// fa update del controllo
///
public void doUpdate()
{
ods.DataBind();
repLI.DataBind();
}
///
/// timeout scaduto
///
///
///
protected void Timer1_Tick(object sender, EventArgs e)
{
// sollevo evento!
if (eh_reqRemoveModal != null)
{
eh_reqRemoveModal(this, new EventArgs());
}
// update
doUpdate();
//ScriptManager.RegisterStartupScript(Page, GetType(), "temp", "", false);
ScriptManager.RegisterStartupScript(Page, GetType(), "temp", "", false);
}
///
/// Determina se il refresh (via timer) sia o meno abilitato
///
public bool refreshEnabled
{
get
{
return dmTimer.Enabled;
}
set
{
dmTimer.Enabled = value;
}
}
///
/// Determina se dato lo stato dell'impianto si debba mostrare btn fermata perché
/// - fermo > xx min (da web.config, es 20')
/// - impianto fermo (controllando idxStato: priorità > 1)
///
public bool showInsFermata(object _idxStato, object _durata)
{
int idxStato = 0;
int durata = 0;
int durMinWarning = memLayer.ML.CRI("durMinWarning");
int.TryParse(_idxStato.ToString(), out idxStato);
int.TryParse(_durata.ToString(), out durata);
bool answ = false;
if (durata >= durMinWarning)
{
try
{
// in questo caso controllo idxStato... e recupero priorità se > 1 --> richiesta qualifica
answ = (DataLayer.obj.taAnagStati.GetByIdx(idxStato)[0].Priorita > 1);
}
catch
{ }
}
return answ;
}
public string urlDisegno(object _codArticolo)
{
// default è ND...
string outVal = "~/Files/Disegni/ND.pdf";
// recupero da anagrafica articoli...
try
{
DS_ProdTempi.AnagArticoliRow riga = DataLayer.obj.taAnagArt.getByCod(_codArticolo.ToString())[0];
// se disegno presente...
if (docPresente(riga.Disegno))
{
outVal = string.Format("~/Files/Disegni/{0}.pdf", riga.Disegno);
}
else
{
logger.lg.scriviLog(string.Format("Errore Articolo {0}: NON ho trovato il disegno {1} con URL {2}", riga.CodArticolo, riga.Disegno, outVal), tipoLog.INFO);
}
}
catch (Exception exc)
{
logger.lg.scriviLog(string.Format("Errore in ricostruzione URL disegno:{0}{1}", Environment.NewLine, exc), tipoLog.EXCEPTION);
}
return outVal;
}
///
/// path completo documento su filesystem
///
/// Nome disegno
///
protected string docFilePath(string Disegno)
{
string answ = "";
answ = string.Format(memLayer.ML.confReadString("urlDisegni"), Disegno);
// rimetto ".pdf" finale se non ci fosse...
if (answ.IndexOf(".pdf") < 0) Disegno += ".pdf";
return answ;
}
///
/// verifica se il documento sia presente
///
public bool docPresente(string Disegno)
{
bool answ = false;
try
{
fileMover.obj.setDirectory("");
string filePath = docFilePath(Disegno);
answ = fileMover.obj.fileExist(filePath);
// se non trova provo a sostituire "~/" con "./"
if (!answ)
{
answ = fileMover.obj.fileExist(filePath.Replace("~/", "./"));
logger.lg.scriviLog("Test 1");
}
// ultima prova...
if (!answ)
{
answ = fileMover.obj.fileExist(filePath.Replace("~/", ""));
logger.lg.scriviLog("Test 2");
}
}
catch (Exception exc)
{
logger.lg.scriviLog(string.Format("Errore in verifica docPresente:{0}{1}", Environment.NewLine, exc), tipoLog.EXCEPTION);
}
return answ;
}
}
}