Files
2021-08-31 09:29:11 +02:00

322 lines
7.7 KiB
C#

using MapoSDK;
using Newtonsoft.Json;
using SteamWare;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace MoonProTablet.WebUserControls
{
public partial class cmp_ST_objView : BaseUserControl
{
#region Protected Properties
protected bool enableForceParamSchedaTecnica
{
get
{
return memLayer.ML.cdvb("enableForceParamSchedaTecnica");
}
}
protected bool hasDeroga
{
get
{
bool answ = false;
try
{
var currDeroga = DataLayerObj.getDerogaSt(idxST);
answ = (currDeroga != null);
if (answ)
{
answ = (currDeroga.CanForce && currDeroga.Num == dataNum && currDeroga.CodGruppo == dataGroup && currDeroga.CodTipo == dataType && currDeroga.Oggetto == dataOggetto);
}
}
catch
{ }
return answ;
}
}
#endregion Protected Properties
#region Public Properties
public string dataCss
{
get
{
string answ = "";
if (required)
{
if (dataValue != extCode)
{
answ = " text-danger";
}
else
{
answ = " text-success";
}
}
return answ;
}
}
public string dataGroup
{
get
{
return hfGruppo.Value.Trim();
}
set
{
hfGruppo.Value = value.Trim();
}
}
public string dataLabel
{
get
{
return hfLabel.Value.Trim();
}
set
{
hfLabel.Value = value.Trim();
}
}
public int dataNum
{
get
{
int answ = 0;
int.TryParse(hfNum.Value, out answ);
return answ;
}
set
{
hfNum.Value = $"{value}";
}
}
public int dataOggetto
{
get
{
int answ = 0;
int.TryParse(hfOggetto.Value, out answ);
return answ;
}
set
{
hfOggetto.Value = $"{value}";
}
}
public string dataType
{
get
{
return hfType.Value.Trim();
}
set
{
hfType.Value = value.Trim();
fixDisplay();
}
}
public string dataValue
{
get
{
return hfValue.Value.Trim();
}
set
{
hfValue.Value = value.Trim();
}
}
public string dataValueRead
{
get
{
return hfValueRead.Value.Trim();
}
set
{
hfValueRead.Value = value.Trim();
lblExtCode.Visible = !string.IsNullOrEmpty(value);
}
}
public string derogaCss
{
get
{
string answ = enableForceParamSchedaTecnica && hasDeroga ? " bg-warning" : "";
return answ;
}
}
public string extCode
{
get
{
return hfExtCode.Value.Trim();
}
set
{
hfExtCode.Value = value.Trim();
fixDisplay();
}
}
public int idxST
{
get
{
int answ = 0;
int.TryParse(hfIdxST.Value, out answ);
return answ;
}
set
{
hfIdxST.Value = $"{value}";
}
}
/// <summary>
/// Url immagine SE richiesta
/// </summary>
public string imageUrl
{
get
{
string imgPath = "";
string fullPath = "";
//check type...
if (dataType == "IMG")
{
imgPath = dataValue;
if (!Path.IsPathRooted(imgPath))
{
// aggiungo base path
imgPath = $"~\\images\\ST_img\\{imgPath}";
}
fullPath = Server.MapPath(imgPath);
// verifico esistenza file...
if (!File.Exists(fullPath))
{
// metto segnaposto empty
imgPath = "~\\images\\ST_img\\Steamware.png";
}
}
return imgPath;
}
}
public bool required
{
get
{
bool answ = false;
bool.TryParse(hfRequired.Value.Trim(), out answ);
return answ;
}
set
{
hfRequired.Value = value.ToString();
fixDisplay();
}
}
public bool showCheckedData
{
get
{
bool answ = false;
if (required && (dataValue == extCode))
{
answ = true;
}
return answ;
}
}
public bool showMissingData
{
get
{
bool answ = false;
if (required && (dataValue != extCode))
{
answ = true;
}
return answ;
}
}
#endregion Public Properties
#region Private Methods
private void fixDisplay()
{
divImg.Visible = false;
divTxt.Visible = false;
switch (dataType)
{
case "IMG":
divImg.Visible = true;
break;
case "TXT":
default:
divTxt.Visible = true;
break;
}
bool doShow = showMissingData;
lblError.Visible = doShow;
lblChecked.Visible = doShow;
bool checkDeroga = hasDeroga;
lbtForce.Visible = doShow && enableForceParamSchedaTecnica && !checkDeroga;
lblDeroga.Visible = doShow && enableForceParamSchedaTecnica && checkDeroga;
}
#endregion Private Methods
#region Protected Methods
protected void lbtForce_Click(object sender, EventArgs e)
{
// registro abilitazione forzatura parametro per un periodo limitato
StCheckOverride newDeroga = new StCheckOverride()
{
CanForce = enableForceParamSchedaTecnica,
Num = dataNum,
Oggetto = dataOggetto,
CodTipo = dataType,
CodGruppo = dataGroup,
IdxST = idxST
};
// salvo
DataLayerObj.setDerogaSt(newDeroga);
Response.Redirect(Request.RawUrl);
}
protected void Page_Load(object sender, EventArgs e)
{
}
#endregion Protected Methods
}
}