226 lines
5.1 KiB
C#
226 lines
5.1 KiB
C#
using Data;
|
|
using SteamWare;
|
|
using System;
|
|
using System.Text.RegularExpressions;
|
|
|
|
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;
|
|
// esempio da https://www.regextester.com/19
|
|
// altri esempi: http://regexlib.com/Search.aspx?k=email&AspxAutoDetectCookieSupport=1
|
|
Match match = Regex.Match(email, @"^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$");
|
|
if (match.Success)
|
|
{
|
|
answ = true;
|
|
}
|
|
return answ;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// email inserita
|
|
/// </summary>
|
|
protected string email
|
|
{
|
|
get
|
|
{
|
|
return txtEmail.Text.Trim();
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// email inserita
|
|
/// </summary>
|
|
protected string cognome
|
|
{
|
|
get
|
|
{
|
|
return txtCognome.Text.Trim();
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// email inserita
|
|
/// </summary>
|
|
protected string nome
|
|
{
|
|
get
|
|
{
|
|
return txtNome.Text.Trim();
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// Verifica utente sia ATTIVO
|
|
/// </summary>
|
|
protected bool userIsActive
|
|
{
|
|
get
|
|
{
|
|
bool answ = false;
|
|
var tabUtenti = DtProxy.man.taUsr.getByEmail(email);
|
|
if (tabUtenti.Rows.Count > 0)
|
|
{
|
|
var rigaUt = tabUtenti[0];
|
|
answ = rigaUt.attivo;
|
|
}
|
|
return answ;
|
|
}
|
|
}
|
|
/// <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)
|
|
{
|
|
if (userIsActive)
|
|
{
|
|
lblCheckEmail.Text = "Utente trovato!";
|
|
}
|
|
else
|
|
{
|
|
lblCheckEmail.Text = "Utente bloccato, RIATTIVARE con link.";
|
|
}
|
|
}
|
|
else
|
|
{
|
|
lblCheckEmail.Text = "Utente non trovato, prego completare dati";
|
|
}
|
|
divAddUser.Visible = emailValid && !userExist;
|
|
divAssignUser.Visible = emailValid && userExist;
|
|
lbtAssign.Visible = emailValid && userExist && userIsFree && userIsActive;
|
|
lblUserAssigned.Visible = emailValid && userExist && !userIsFree;
|
|
}
|
|
|
|
protected void lbtAdd_Click(object sender, EventArgs e)
|
|
{
|
|
// creo nuovo utente SENZA assegnare alcun permesso...
|
|
DtProxy.man.taUsr.insertQuery(email, cognome, nome, SteamwareStrings.pseudoRandomString(20), 1000, memLayer.ML.CRS("CodModulo"));
|
|
checkVisibility();
|
|
}
|
|
|
|
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);
|
|
}
|
|
}
|
|
}
|
|
} |