Files
MoonPro.net/MP-MON/Controllers/HomeController.cs
T
2018-12-19 16:47:53 +01:00

143 lines
3.9 KiB
C#

using MP_MON.Models;
using SteamWare;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
namespace MP_MON.Controllers
{
public class HomeController : Controller
{
private MoonProEntities db = new MoonProEntities();
public ActionResult Index()
{
// ricarico ogni minuto COMUNQUE tutto...
string pageRefreshSec = "60";
// refresh std ogni sec
int pageRefreshMs = 1000;
ViewBag.cssSemBase = "sem";
try
{
pageRefreshSec = memLayer.ML.CRS("pageRefreshSec");
}
catch
{ }
if (pageRefreshSec == "")
{
pageRefreshSec = "60";
}
ViewBag.pageRefreshMs = pageRefreshMs;
Response.AddHeader("Refresh", pageRefreshSec);
// aggiungo il controllo del NUM MAX col x singola riga
int maxCol = 6;
try
{
maxCol = memLayer.ML.cdvi("MON_maxCol");
}
catch
{ }
ViewBag.maxCol = maxCol;
// ritorno la view!
return View();
}
public ActionResult Blink()
{
// ricarico ogni minuto COMUNQUE tutto...
string pageRefreshSec = "60";
// se ho animazione refresh è ogni 2 sec...
int pageRefreshMs = 2000;
ViewBag.cssSemBase = "semBlink";
try
{
pageRefreshSec = memLayer.ML.CRS("pageRefreshSec");
}
catch
{ }
if (pageRefreshSec == "")
{
pageRefreshSec = "60";
}
ViewBag.pageRefreshMs = pageRefreshMs;
Response.AddHeader("Refresh", pageRefreshSec);
return View("Index");
}
public ActionResult Fix()
{
// ricarico ogni minuto COMUNQUE tutto...
string pageRefreshSec = "60";
// refresh std ogni sec
int pageRefreshMs = 1000;
ViewBag.cssSemBase = "semFix";
try
{
pageRefreshSec = memLayer.ML.CRS("pageRefreshSec");
}
catch
{ }
if (pageRefreshSec == "")
{
pageRefreshSec = "60";
}
ViewBag.pageRefreshMs = pageRefreshMs;
Response.AddHeader("Refresh", pageRefreshSec);
return View("Index");
}
public ActionResult GetClock()
{
return PartialView("_mmClock");
}
public ActionResult checkIOB()
{
string esito = "ND";
// verifico TUTTE le macchine x il keepAlive e se almeno 1 è offline da oltre "keepAliveMin" minuti --> invio email!!!
int keepAliveMin = 1;
try
{
keepAliveMin = memLayer.ML.CRI("keepAliveMin");
}
catch
{ }
// recupero elenco macchine offline e mostro!
var MappaStato = db.stp_MSE_getOffline(keepAliveMin);
List<MappaStatoExpl> risultato = MappaStato.ToList();
int numKO = risultato.Count;
if (numKO > 0)
{
// scrivo esito
esito = string.Format("Trovate {0} schede offline", numKO);
// invio email...
string from = memLayer.ML.CRS("_fromEmail");
string to = memLayer.ML.CRS("_checkIobEmail");
string subject = "MapoIOB - ciclo di controllo schede MapoIOB";
string body = string.Format("<h2>Attenzione!</h2> durante l'ultimo ciclo di controllo sono state {1}{0}", Environment.NewLine, esito);
foreach (MappaStatoExpl item in risultato)
{
body += string.Format("{2}<b>{0}</b> \t\t | Art: {1}", item.Nome, item.CodArticolo, Environment.NewLine);
}
// se ho una pwd/user utilizzo smtp auth, altrimenti base...
if ((memLayer.ML.CRS("_emailUser") != "") && (memLayer.ML.CRS("_emailPwd") != ""))
{
SteamWare.gestEmail.geAuth.mandaEmail(from, to, subject, body);
}
else
{
SteamWare.gestEmail.ge.mandaEmail(from, to, subject, body);
}
}
else
{
esito = "OK";
}
ViewBag.EsitoVerifica = esito;
// inserisco elenco macchine offline x rendering in partialView
return PartialView("_checkIOB", risultato);
}
}
}