469 lines
16 KiB
C#
469 lines
16 KiB
C#
using GPW_data;
|
|
using SteamWare;
|
|
using System;
|
|
using System.Web.UI;
|
|
|
|
namespace GPW.WebUserControls
|
|
{
|
|
public partial class mod_bCodeTimb : System.Web.UI.UserControl
|
|
{
|
|
/// <summary>
|
|
/// salva il dato se il prox sia entrata...
|
|
/// </summary>
|
|
protected bool nextIsEntrata
|
|
{
|
|
get
|
|
{
|
|
return memLayer.ML.BoolSessionObj("nextIsEntrata");
|
|
}
|
|
set
|
|
{
|
|
memLayer.ML.setSessionVal("nextIsEntrata", value);
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// dataora associata all'evento scansioen BCode
|
|
/// </summary>
|
|
protected DateTime orarioBCode
|
|
{
|
|
get
|
|
{
|
|
return (DateTime)memLayer.ML.objSessionObj("dataOraBCode");
|
|
}
|
|
set
|
|
{
|
|
memLayer.ML.setSessionVal("dataOraBCode", value);
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// indica i secondi di countdown rimasti x auto-commit
|
|
/// </summary>
|
|
protected int countDown
|
|
{
|
|
get
|
|
{
|
|
return memLayer.ML.IntSessionObj("countDownBCode");
|
|
}
|
|
set
|
|
{
|
|
memLayer.ML.setSessionVal("countDownBCode", value);
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// pagina corrente
|
|
/// </summary>
|
|
protected string paginaCorrente
|
|
{
|
|
get
|
|
{
|
|
string answ = "";
|
|
Uri MyUrl = Request.Url;
|
|
string delimStr = "/";
|
|
char[] delimiter = delimStr.ToCharArray();
|
|
string[] finalUrl = MyUrl.LocalPath.ToString().Split(delimiter);
|
|
int n = finalUrl.Length;
|
|
answ = finalUrl[n - 1].ToString();
|
|
return answ;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// prox messaggio utente (da mostrare)
|
|
/// </summary>
|
|
protected string nextUsrMsg
|
|
{
|
|
get
|
|
{
|
|
string answ = "";
|
|
try
|
|
{
|
|
answ = memLayer.ML.StringSessionObj("nextUsrMsg");
|
|
}
|
|
catch
|
|
{ }
|
|
if (string.IsNullOrEmpty(answ))
|
|
{
|
|
answ = "...waiting...";
|
|
}
|
|
return answ;
|
|
}
|
|
set
|
|
{
|
|
memLayer.ML.setSessionVal("nextUsrMsg", value);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// caricamento pagina
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void Page_Load(object sender, EventArgs e)
|
|
{
|
|
chekIpPostazione();
|
|
if (!Page.IsPostBack)
|
|
{
|
|
DataProxy.idxDipendente = -1;
|
|
bool visibile = false;
|
|
setCtrlState(visibile);
|
|
checkBarcode();
|
|
}
|
|
timerConf.Tick += new EventHandler<EventArgs>(timerConf_Tick);
|
|
lblDipendenteAttivo.Text = nextUsrMsg;
|
|
txtBarcode.Focus();
|
|
}
|
|
/// <summary>
|
|
/// verifica IP della postazione chiamante, se non è tra quelli permessi (o non è indicato "*") rimanda a pagina precedente...
|
|
/// </summary>
|
|
private void chekIpPostazione()
|
|
{
|
|
// recupero IP
|
|
string IPv4 = Request.UserHostName;
|
|
// controllo se IP locale = approvata...
|
|
if (!memLayer.ML.confReadString("ipv4StazBCode").Contains(IPv4) && memLayer.ML.confReadString("ipv4StazBCode") != "*")
|
|
{
|
|
Response.Redirect("~/Default.aspx");
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// allo scadere del timer controllo countdown!
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
void timerConf_Tick(object sender, EventArgs e)
|
|
{
|
|
contatorePag = 0;
|
|
if (countDown > 1)
|
|
{
|
|
countDown = countDown - 1;
|
|
lblCountDown.Text = countDown.ToString();
|
|
txtBarcode.Focus();
|
|
}
|
|
else
|
|
{
|
|
// salvo operazione di default!
|
|
registraTimbratura(nextIsEntrata);
|
|
// reset visualizzazione
|
|
setCtrlState(false);
|
|
timerConf.Enabled = false;
|
|
// reset valori
|
|
Response.Redirect(paginaCorrente);
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// imposta lo stato visibile dei controlli
|
|
/// </summary>
|
|
/// <param name="visibile"></param>
|
|
private void setCtrlState(bool visibile)
|
|
{
|
|
pnlTimer.Visible = visibile;
|
|
//imgRun.Visible = visibile;
|
|
if (DataProxy.idxDipendente > 0)
|
|
{
|
|
grView.Visible = true;
|
|
}
|
|
else
|
|
{
|
|
grView.Visible = visibile;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// verifica in che stato debbano essere i buttons (se barcode utente valido)
|
|
/// </summary>
|
|
private void checkButtons()
|
|
{
|
|
// controllo se il prox comando DOVREBBE essere entrata o uscita
|
|
nextIsEntrata = true;
|
|
// controllo dipendente
|
|
if (DataProxy.idxDipendente > 0)
|
|
{
|
|
// ricavo ultima timbratura..
|
|
nextIsEntrata = timbratrice.nextIsEntrata(DataProxy.idxDipendente);
|
|
string tipoTimb = "uscita";
|
|
// di conseguenza cambio abilitazione ad un buttons
|
|
if (nextIsEntrata)
|
|
{
|
|
btnEntrata.CssClass = "btnPreferred";
|
|
btnUscita.CssClass = "btnStd";
|
|
tipoTimb = "ENTRATA";
|
|
}
|
|
else
|
|
{
|
|
btnEntrata.CssClass = "btnStd";
|
|
btnUscita.CssClass = "btnPreferred";
|
|
tipoTimb = "USCITA";
|
|
}
|
|
lblNextTimbr.Text = string.Format("Allo scadere del timer verrà registrata una timbratura di <b>{0}</b>", tipoTimb);
|
|
|
|
}
|
|
else
|
|
{
|
|
btnEntrata.CssClass = "btnStd";
|
|
btnUscita.CssClass = "btnStd";
|
|
lblNextTimbr.Text = "";
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// controlla se ci sia un barcode valido, tra:
|
|
/// - idxDipendente (INT, eventuale padding di zero...)
|
|
/// - matr dipendente
|
|
/// - cf dipendente
|
|
/// </summary>
|
|
private void checkBarcode()
|
|
{
|
|
if (!string.IsNullOrEmpty(barcodeIn))
|
|
{
|
|
// mostro i buttons enabled
|
|
btnEntrata.Enabled = true;
|
|
btnUscita.Enabled = true;
|
|
lblMessaggi.Text = "Barcode";
|
|
|
|
switch (tipoBCode)
|
|
{
|
|
case tipoCodiceBarcode.idxDipendente:
|
|
// calcolo idxOperatore...
|
|
int idxOper = 0;
|
|
try
|
|
{
|
|
idxOper = Convert.ToInt32(barcodeIn.ToLowerInvariant().Replace("idx", ""));
|
|
}
|
|
catch
|
|
{ }
|
|
// controllo esista il codice idxDipendente scansionato
|
|
if (DataProxy.DP.taDipendenti.getByIdx(idxOper).Rows.Count == 0)
|
|
{
|
|
setCtrlState(false);
|
|
DataProxy.idxDipendente = 0;
|
|
orarioBCode = DateTime.Now;
|
|
timerConf.Enabled = false;
|
|
nextUsrMsg = "...waiting...";
|
|
lblMessaggi.Text += " - codice non valido / non trovato.";
|
|
pnlAll.CssClass = "stileComandoKo";
|
|
}
|
|
else
|
|
{
|
|
setCtrlState(true);
|
|
DataProxy.idxDipendente = idxOper;
|
|
orarioBCode = DateTime.Now;
|
|
DS_Applicazione.DipendentiRow rigaDip = DataProxy.DP.taDipendenti.getByIdx(idxOper)[0];
|
|
nextUsrMsg = string.Format("{0} {1} - {2: HH:mm:ss}", rigaDip.Cognome, rigaDip.Nome, orarioBCode);
|
|
lblMessaggi.Text += " - impostato dipendente!";
|
|
pnlAll.CssClass = "stileComandoOk";
|
|
// faccio partire countdown
|
|
countDown = SteamWare.memLayer.ML.confReadInt("secTimeoutBCode");
|
|
lblCountDown.Text = countDown.ToString();
|
|
timerConf.Enabled = true;
|
|
}
|
|
txtBarcode.Focus();
|
|
break;
|
|
case tipoCodiceBarcode.matrDipendente:
|
|
// fare!!!
|
|
txtBarcode.Focus();
|
|
break;
|
|
case tipoCodiceBarcode.cfDipendente:
|
|
// fare!!!
|
|
txtBarcode.Focus();
|
|
break;
|
|
case tipoCodiceBarcode.Comando:
|
|
// procedo SOLO se ho cod dipendente
|
|
if (DataProxy.DP.taDipendenti.getByIdx(DataProxy.idxDipendente).Rows.Count > 0)
|
|
{
|
|
timerConf.Enabled = false;
|
|
setCtrlState(false);
|
|
}
|
|
nextUsrMsg = "...waiting...";
|
|
// controlla se sia entra/esci (IN/OUT)
|
|
if (barcodeIn.ToUpperInvariant() == "CMDIN")
|
|
{
|
|
// registro ingresso!
|
|
registraTimbratura(true);
|
|
Response.Redirect(paginaCorrente);
|
|
}
|
|
else if (barcodeIn.ToUpperInvariant() == "CMDOUT")
|
|
{
|
|
// registro uscita!
|
|
registraTimbratura(false);
|
|
Response.Redirect(paginaCorrente);
|
|
}
|
|
//else if (barcodeIn.ToUpperInvariant() == "CMD")
|
|
//{
|
|
// Response.Redirect(paginaCorrente);
|
|
//}
|
|
//DataProxy.idxDipendente = -1;
|
|
txtBarcode.Focus();
|
|
break;
|
|
default:
|
|
txtBarcode.Focus();
|
|
break;
|
|
}
|
|
barcodeIn = "";
|
|
}
|
|
else
|
|
{
|
|
lblMessaggi.Text = "...attesa barcode...";
|
|
}
|
|
grView.DataBind();
|
|
checkButtons();
|
|
txtBarcode.Focus();
|
|
}
|
|
|
|
/// <summary>
|
|
/// valore barcode
|
|
/// </summary>
|
|
public string barcodeIn
|
|
{
|
|
get
|
|
{
|
|
return txtBarcode.Text.Trim();
|
|
}
|
|
set
|
|
{
|
|
txtBarcode.Text = value;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// salvo entrata
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void btnEntrata_Click(object sender, EventArgs e)
|
|
{
|
|
// salvo entrata...
|
|
registraTimbratura(true);
|
|
Response.Redirect(paginaCorrente);
|
|
}
|
|
/// <summary>
|
|
/// salvo uscita
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void btnUscita_Click(object sender, EventArgs e)
|
|
{
|
|
// salvo uscita
|
|
registraTimbratura(false);
|
|
Response.Redirect(paginaCorrente);
|
|
}
|
|
/// <summary>
|
|
/// registro timbratura
|
|
/// </summary>
|
|
/// <param name="isEntrata"></param>
|
|
/// <returns></returns>
|
|
private void registraTimbratura(bool isEntrata)
|
|
{
|
|
// salvo evento entrata...
|
|
string IPv4 = Request.UserHostName;
|
|
// auto-approvazione da web.config
|
|
bool approvata = memLayer.ML.confReadBool("barcodeAutoApprove");
|
|
if (DataProxy.idxDipendente > 0)
|
|
{
|
|
string CognomeNome = "";
|
|
if (memLayer.ML.confReadBool("showNameAfterCmd"))
|
|
{
|
|
CognomeNome = DataProxy.DP.cognomeNomeByIdx(DataProxy.idxDipendente);
|
|
}
|
|
if (nextIsEntrata)
|
|
{
|
|
nextUsrMsg = string.Format("{1} ENTRATA {0:HH:mm:ss}", orarioBCode, CognomeNome);
|
|
}
|
|
else
|
|
{
|
|
nextUsrMsg = string.Format("{1} USCITA {0:HH:mm:ss}", orarioBCode, CognomeNome);
|
|
}
|
|
timbratrice.registraTimbratura(DataProxy.idxDipendente, orarioBCode, isEntrata, IPv4, "Web", approvata);
|
|
//aggiorno timbrature visualizzate
|
|
setButtons();
|
|
grView.DataBind();
|
|
}
|
|
else
|
|
{
|
|
lblMessaggi.Text = "IdxDipendente non trovato! timbratura impossibile";
|
|
pnlAll.CssClass = "stileComandoND";
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// imposta i buttons secondo i valori in sessione...
|
|
/// </summary>
|
|
private void setButtons()
|
|
{
|
|
// mostrare e abilitare secondo condizioni al contorno
|
|
}
|
|
/// <summary>
|
|
/// decodifica il tipo barcode acquisito
|
|
/// </summary>
|
|
public tipoCodiceBarcode tipoBCode
|
|
{
|
|
get
|
|
{
|
|
tipoCodiceBarcode answ = tipoCodiceBarcode.ND;
|
|
// controllo non si tratti di un comando...
|
|
string preCmd = memLayer.ML.confReadString("prefComandi");
|
|
if (barcodeIn.StartsWith(preCmd, StringComparison.InvariantCultureIgnoreCase))
|
|
{
|
|
answ = tipoCodiceBarcode.Comando;
|
|
}
|
|
// controllo se sia un codice "idx"
|
|
else if (barcodeIn.StartsWith("idx", StringComparison.InvariantCultureIgnoreCase))
|
|
{
|
|
answ = tipoCodiceBarcode.idxDipendente;
|
|
}
|
|
// controllo se sia un codice "matr"
|
|
else if (barcodeIn.StartsWith("matr", StringComparison.InvariantCultureIgnoreCase))
|
|
{
|
|
answ = tipoCodiceBarcode.matrDipendente;
|
|
}
|
|
// controllo se sia un codice "cf"
|
|
else if (barcodeIn.StartsWith("cf", StringComparison.InvariantCultureIgnoreCase))
|
|
{
|
|
answ = tipoCodiceBarcode.cfDipendente;
|
|
}
|
|
return answ;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// inverte valore booleano
|
|
/// </summary>
|
|
/// <param name="isEnt"></param>
|
|
/// <returns></returns>
|
|
public bool invBool(object valore)
|
|
{
|
|
bool answ = true;
|
|
try
|
|
{
|
|
answ = !Convert.ToBoolean(valore);
|
|
}
|
|
catch
|
|
{ }
|
|
return answ;
|
|
}
|
|
/// <summary>
|
|
/// evento cambio testo
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void txtBarcode_TextChanged(object sender, EventArgs e)
|
|
{
|
|
// solo se ho ALMENO 3 char...
|
|
if (barcodeIn.Length >= 3)
|
|
{
|
|
contatorePag = 0;
|
|
checkBarcode();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// variabile che conta numero di refresh parziali prima di fare reload completo
|
|
/// </summary>
|
|
protected int contatorePag
|
|
{
|
|
get
|
|
{
|
|
return memLayer.ML.IntSessionObj("numChiamatePaginaBCode");
|
|
}
|
|
set
|
|
{
|
|
memLayer.ML.setSessionVal("numChiamatePaginaBCode", value);
|
|
}
|
|
}
|
|
|
|
}
|
|
} |