using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using SteamWare; using GPW_data; namespace GPW.WebUserControls { public partial class mod_timbrature : System.Web.UI.UserControl { protected bool forceButtons = true; protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { // verifico se ci sia un numero di righe selezionate altrimenti lo imposto... if (!memLayer.ML.isInSessionObject("numColEU")) numColEU = 2; if (!memLayer.ML.isInSessionObject("numRowTimb")) numRowTimb = 10; memLayer.ML.setSessionVal("dataRif", DateTime.Today); } setButtons(); } public int numColEU { get { int answ = 2; try { answ = memLayer.ML.IntSessionObj("numColEU"); } catch { } if (answ <= 0) answ = 2; return answ; } set { memLayer.ML.setSessionVal("numColEU", value); } } public int numRowTimb { get { return memLayer.ML.IntSessionObj("numRowTimb"); } set { memLayer.ML.setSessionVal("numRowTimb", value); } } /// /// imposto highlight di un area intorno al button /// private void setButtons() { // controllo SE voglio inibire i buttons... if (forceButtons) { // controllo se il prox comando DOVREBBE essere entrata o uscita bool nextIsEntrata = true; // controllo dipendente if (IdxDipendente > 0) { // ricavo ultima timbratura.. nextIsEntrata = timbratrice.nextIsEntrata(IdxDipendente); // di conseguenza cambio abilitazione ad un buttons if (nextIsEntrata) { btnEntrata.Enabled = true; btnUscita.Enabled = false; } else { btnEntrata.Enabled = false; btnUscita.Enabled = true; } } else { btnEntrata.Enabled = false; btnUscita.Enabled = false; } } else { btnEntrata.Enabled = true; btnUscita.Enabled = true; } } /// /// timbro entrata... /// /// /// protected void btnEntrata_Click(object sender, EventArgs e) { bool isEntrata = true; registraTimbratura(isEntrata); } /// /// uscita... /// /// /// protected void btnUscita_Click(object sender, EventArgs e) { bool isEntrata = false; registraTimbratura(isEntrata); } /// /// Abilita tutti i buttons /// public void abilitaAll() { forceButtons = false; } /// /// Aggiorno visualizzazione /// public void doUpdate() { setButtons(); grView.DataBind(); } /// /// update elenco ultime timbrature /// private void updateTimbrature() { // aggiorno datagrid } /// /// registro timbratura /// /// /// private int registraTimbratura(bool isEntrata) { // salvo evento entrata... string IPv4 = ""; bool approvata = false; if (IdxDipendente > 0) { // recupero IP IPv4 = Request.UserHostName; // controllo se IP locale = approvata... if (IPv4.Contains(memLayer.ML.confReadString("localNet"))) { approvata = true; } timbratrice.registraTimbratura(IdxDipendente, DateTime.Now, isEntrata, IPv4, "Web", approvata); lblWarning.Visible = false; //aggiorno timbrature visualizzate setButtons(); updateTimbrature(); grView.DataBind(); } else { lblWarning.Text = "IdxDipendente non trovato! timbratura impossibile"; lblWarning.Visible = true; } return IdxDipendente; } /// /// idx dipendente loggato /// protected int IdxDipendente { get { int idx = 0; try { idx = memLayer.ML.IntSessionObj("IdxDipendente"); } catch { } return idx; } } /// /// inverte valore booleano /// /// /// public bool invBool(object valore) { bool answ = true; try { answ = !Convert.ToBoolean(valore); } catch { } return answ; } protected void grView_RowCreated(object sender, GridViewRowEventArgs e) { int maxNum = e.Row.Cells.Count - 2; for (int i = numColEU * 2 + 1; i < maxNum; i++) { e.Row.Cells[i].Visible = false; } } protected void grView_SelectedIndexChanged(object sender, EventArgs e) { // rimando ai progetti sulla data indicata... DateTime dataRif = DateTime.Today; try { dataRif = Convert.ToDateTime(grView.SelectedDataKey["dataLav"]); } catch { } // salvo in sessione... memLayer.ML.setSessionVal("dataRif", dataRif); // reinvio Response.Redirect(string.Format("Progetti?dataRif={0:yyyy-MM-dd}", dataRif)); } } }