208 lines
5.5 KiB
C#
208 lines
5.5 KiB
C#
using SteamWare;
|
|
using System;
|
|
using System.Threading;
|
|
using System.Timers;
|
|
using System.Web.UI;
|
|
|
|
namespace NKC_WF.WebUserControls
|
|
{
|
|
public partial class cmp_barcode : BaseUserControl, IDisposable
|
|
{
|
|
#region Public Properties
|
|
|
|
/// <summary>
|
|
/// Comando acquisito da Barcode
|
|
/// </summary>
|
|
public string inputAcquired
|
|
{
|
|
get
|
|
{
|
|
return hfLastCmd.Value;
|
|
}
|
|
set
|
|
{
|
|
hfLastCmd.Value = value;
|
|
}
|
|
}
|
|
|
|
#endregion Public Properties
|
|
|
|
#region Public Methods
|
|
|
|
public override void Dispose()
|
|
{
|
|
UiTimer.Tick -= UiTimer_Tick;
|
|
UiTimer.Dispose();
|
|
base.Dispose();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Reset input del barcode SENZA generare evento...
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public void resetInput()
|
|
{
|
|
valueRead = "";
|
|
txtBarcode.Focus();
|
|
}
|
|
|
|
/// <summary>
|
|
/// reset messaggio
|
|
/// </summary>
|
|
public void resetMessage()
|
|
{
|
|
lbtReset.Visible = false;
|
|
lblOutput.Text = "";
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gestione output da mostrare (opzionale
|
|
/// </summary>
|
|
/// <param name="cssClass">Enum delle classi permesse</param>
|
|
/// <param name="messaggio"></param>
|
|
public void showOutput(AppData.cssClass cssClass, string messaggio)
|
|
{
|
|
// In primis: mostro qualcosa SOLO SE ho del testo
|
|
lbtReset.Visible = !string.IsNullOrEmpty(messaggio);
|
|
lblOutput.Text = messaggio;
|
|
lbtReset.CssClass = $"btn btn-sm btn-block py-0 btn-{cssClass}";
|
|
}
|
|
|
|
#endregion Public Methods
|
|
|
|
#region Protected Properties
|
|
|
|
/// <summary>
|
|
/// Ultima esecuzione comando (x forzare reset)
|
|
/// </summary>
|
|
protected DateTime lastDtInput
|
|
{
|
|
get
|
|
{
|
|
DateTime answ = DateTime.Now;
|
|
if (!string.IsNullOrEmpty(hfLastDtInput.Value))
|
|
{
|
|
answ = DateTime.Parse(hfLastDtInput.Value);
|
|
}
|
|
return answ;
|
|
}
|
|
set
|
|
{
|
|
hfLastDtInput.Value = $"{value:yyyy-MM-dd HH:mm:ss}";
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Valore acquisito in lettura barcode
|
|
/// </summary>
|
|
protected string valueRead
|
|
{
|
|
get
|
|
{
|
|
return txtBarcode.Text.Trim();
|
|
}
|
|
set
|
|
{
|
|
txtBarcode.Text = value;
|
|
}
|
|
}
|
|
|
|
#endregion Protected Properties
|
|
|
|
#region Protected Methods
|
|
|
|
/// <summary>
|
|
/// reset lettura
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void lbtReset_Click(object sender, EventArgs e)
|
|
{
|
|
Response.Redirect(Request.RawUrl);
|
|
}
|
|
|
|
protected void Page_Load(object sender, EventArgs e)
|
|
{
|
|
if (!Page.IsPostBack)
|
|
{
|
|
resetInput();
|
|
resetMessage();
|
|
setTimer();
|
|
test4reload();
|
|
}
|
|
else if (string.IsNullOrEmpty(inputAcquired))
|
|
{
|
|
checkRaiseEv();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// evento modifica testo
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void txtBarcode_TextChanged(object sender, EventArgs e)
|
|
{
|
|
lastDtInput = DateTime.Now;
|
|
checkRaiseEv();
|
|
}
|
|
|
|
protected void UiTimer_Tick(object sender, EventArgs e)
|
|
{
|
|
test4reload();
|
|
}
|
|
|
|
#endregion Protected Methods
|
|
|
|
#region Private Methods
|
|
|
|
/// <summary>
|
|
/// Verifica se inviare evento
|
|
/// </summary>
|
|
private void checkRaiseEv()
|
|
{
|
|
if (valueRead != inputAcquired)
|
|
{
|
|
// registro NUOVO cmd
|
|
inputAcquired = valueRead;
|
|
// alzo evento SOLO SE il nuovo valore è diverso da null...
|
|
if (!string.IsNullOrEmpty(inputAcquired))
|
|
{
|
|
raiseEvent();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (string.IsNullOrEmpty(inputAcquired))
|
|
{
|
|
resetInput();
|
|
}
|
|
}
|
|
resetInput();
|
|
}
|
|
|
|
/// <summary>
|
|
/// imposta il tempo di scadenza del timer x il refresh del componente
|
|
/// </summary>
|
|
private void setTimer()
|
|
{
|
|
int timer = memLayer.ML.CRI("timerBarcode");
|
|
timer = timer > 0 ? timer : 10000;
|
|
UiTimer.Interval = timer;
|
|
}
|
|
|
|
private void test4reload()
|
|
{
|
|
// controllo, se ultima operazione > smartForceReloadPagina_ms --> reload!
|
|
var tsLastUpdate = DateTime.Now.Subtract(lastDtInput);
|
|
if (tsLastUpdate.TotalMilliseconds > memLayer.ML.CRI("smartForceReloadPagina_ms"))
|
|
{
|
|
lgInfo($"cmp_barcode | Reload page for timeout: {tsLastUpdate.TotalSeconds} sec from last update");
|
|
inputAcquired = "##";
|
|
Response.Redirect(Request.RawUrl);
|
|
}
|
|
}
|
|
|
|
#endregion Private Methods
|
|
}
|
|
} |