Files
b2bcondomini.it/PUB/WebUserContols/mod_userAdd.ascx.cs
T
2018-09-28 23:40:14 +02:00

169 lines
3.6 KiB
C#

using Data;
using SteamWare;
using System;
namespace PUB.WebUserContols
{
public partial class mod_userAdd : System.Web.UI.UserControl
{
/// <summary>
/// indicato richiesta refresh
/// </summary>
public event EventHandler eh_refresh;
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
checkVisibility();
}
}
/// <summary>
/// Fornitore selezionato
/// </summary>
public int idxForn
{
get
{
int answ = 0;
int.TryParse(hfIdxForn.Value, out answ);
return answ;
}
set
{
hfIdxForn.Value = value.ToString();
}
}
/// <summary>
/// Amministratore selezionato
/// </summary>
public int idxAmm
{
get
{
int answ = 0;
int.TryParse(hfIdxAmm.Value, out answ);
return answ;
}
set
{
hfIdxAmm.Value = value.ToString();
}
}
protected void txtEmail_TextChanged(object sender, EventArgs e)
{
checkVisibility();
}
/// <summary>
/// Verifica validità email inserita
/// </summary>
protected bool emailValid
{
get
{
bool answ = false;
answ = email != "" && email.IndexOf("@") > 0;
return answ;
}
}
protected string email
{
get
{
return txtEmail.Text.Trim();
}
}
/// <summary>
/// Verifica esistenza utente
/// </summary>
protected bool userExist
{
get
{
bool answ = false;
answ = DtProxy.man.taUsr.getByEmail(email).Rows.Count > 0;
return answ && emailValid;
}
}
/// <summary>
/// Verifica utente sia LIBERO da assegnazioni (Amministratori o Fornitori)
/// </summary>
protected bool userIsFree
{
get
{
bool answ = false;
answ = DtProxy.man.taUsr.getUnassByEmail(email).Rows.Count > 0;
return answ && emailValid;
}
}
private void checkVisibility()
{
// verifico email
lblCheckEmail.Visible = emailValid;
if (userExist)
{
lblCheckEmail.Text = "Utente trovato!";
}
else
{
lblCheckEmail.Text = "Utente non trovato, prego completare dati";
}
divAddUser.Visible = emailValid && !userExist;
divAssignUser.Visible = emailValid && userExist;
lbtAssign.Visible = emailValid && userExist && userIsFree;
lblUserAssigned.Visible = emailValid && userExist && !userIsFree;
}
protected void lbtAdd_Click(object sender, EventArgs e)
{
// creo nuovo utente SENZA assegnare alcun permesso...
}
protected void lbtAssign_Click(object sender, EventArgs e)
{
// inizializzo utente, a seconda della modalità come AMM o come FORN...
if (idxAmm > 0)
{
DtProxy.man.taUsr.initUserAmm(email, idxAmm);
}
else if (idxForn > 0)
{
DtProxy.man.taUsr.initUserForn(email, idxForn);
}
// reset valori
doReset();
// sollevo evento nuovo valore...
if (eh_refresh != null)
{
eh_refresh(this, new EventArgs());
}
}
/// <summary>
/// reset controllo
/// </summary>
private void doReset()
{
txtEmail.Text = "";
checkVisibility();
}
protected void lbtShowUser_Click(object sender, EventArgs e)
{
searchVal = email;
Response.Redirect("AnagUtenti");
}
public string searchVal
{
get
{
return memLayer.ML.StringSessionObj("siteSearchVal");
}
set
{
memLayer.ML.setSessionVal("siteSearchVal", value);
}
}
}
}