using System.Collections.Generic;
namespace SteamWare
{
///
/// classe di wrap verso i TableAdapter impiegati
///
public class DataWrap
{
#region area protected
///
/// metodo protected di avvio della classe
///
protected DataWrap()
{
// inizializzo i table adapters
avvioTableAdaptersBase();
setupConnectionStringBase();
avvioTableAdaptersSpec();
setupConnectionStringSpec();
setupVocabolario();
}
///
/// procedura di avvio dei tableAdapter
///
protected virtual void avvioTableAdaptersBase()
{
taLingue = new SteamWare.DataLayer_genericTableAdapters.LingueTableAdapter();
taVocabolario = new SteamWare.DataLayer_genericTableAdapters.VocabolarioTableAdapter();
taLogVoc = new SteamWare.DataLayer_genericTableAdapters.LogUpdateDbTableAdapter();
}
///
/// procedura di avvio dei tableAdapter
///
protected virtual void avvioTableAdaptersSpec()
{
taCdc = new SteamWare.DataLayer_AnagGenTableAdapters.CDCTableAdapter();
taDiritti = new SteamWare.DataLayer_AnagGenTableAdapters.DIRITTITableAdapter();
taPermessi = new SteamWare.DataLayer_AnagGenTableAdapters.PermessiTableAdapter();
taFunzione = new SteamWare.DataLayer_AnagGenTableAdapters.FUNZIONETableAdapter();
taPermessi2Funzione = new SteamWare.DataLayer_AnagGenTableAdapters.Permessi2FunzioneTableAdapter();
taUtente = new SteamWare.DataLayer_AnagGenTableAdapters.UTENTETableAdapter();
taUserData = new SteamWare.DataLayer_AnagGenTableAdapters.UserDataTableAdapter();
taUserDataExt = new SteamWare.DataLayer_AnagGenTableAdapters.UserDataExtTableAdapter();
taLogAna = new SteamWare.DataLayer_AnagGenTableAdapters.LogUpdateDbTableAdapter();
taAnagDev = new DS_devicesTableAdapters.AnagDevicesTableAdapter();
}
///
/// effettua setup dei connection strings da web.config delal singola applicazione
///
protected virtual void setupConnectionStringBase()
{
string connStr = memLayer.ML.confReadString("VocabolarioConnectionString");
// connections del db vocabolario
taLingue.Connection.ConnectionString = connStr;
taVocabolario.Connection.ConnectionString = connStr;
taLogVoc.Connection.ConnectionString = connStr;
}
///
/// effettua setup dei connection strings da web.config della singola applicazione
///
protected virtual void setupConnectionStringSpec()
{
string connStrUt = memLayer.ML.confReadString("UtenteCdcConnectionString");
string connStrPerm = memLayer.ML.confReadString("PermessiConnectionString");
// cambio le connString - db anagrafica principale
taCdc.Connection.ConnectionString = connStrUt;
taDiritti.Connection.ConnectionString = connStrUt;
taFunzione.Connection.ConnectionString = connStrUt;
taUtente.Connection.ConnectionString = connStrUt;
taUserData.Connection.ConnectionString = connStrUt;
taUserDataExt.Connection.ConnectionString = connStrUt;
taLogAna.Connection.ConnectionString = connStrUt;
taAnagDev.Connection.ConnectionString = connStrUt;
// connections del db dell'applicazione
taPermessi.Connection.ConnectionString = connStrPerm;
taPermessi2Funzione.Connection.ConnectionString = connStrPerm;
}
///
/// setup delle tabelle vocabolario
///
protected void setupVocabolario()
{
if (memLayer.ML.isInCacheObject("dictVocabolario"))
{
dictVocabolario = (Dictionary)memLayer.ML.objCacheObj("dictVocabolario");
}
else
{
dictVocabolario = ricaricaDictVocabolario();
memLayer.ML.setCacheVal("dictVocabolario", dictVocabolario, true);
}
// scrivo quanti lemmi ha caricato!
logger.lg.scriviLog(string.Format("Caricati {0} lemmi!", dictVocabolario.Count));
}
///
/// prende l'oggetto tabVocabolario in ram e lo trasforma in dictionary
///
///
protected Dictionary ricaricaDictVocabolario()
{
// continuo
Dictionary answ = new Dictionary();
if (taVocabolario == null)
{
foreach (DataLayer_generic.VocabolarioRow riga in DW.taVocabolario.GetData())
{
answ.Add(riga.Lingua.ToUpper() + "#" + riga.Lemma.ToUpper(), riga.Traduzione);
}
}
else
{
foreach (DataLayer_generic.VocabolarioRow riga in taVocabolario.GetData())
{
answ.Add(riga.Lingua.ToUpper() + "#" + riga.Lemma.ToUpper(), riga.Traduzione);
}
}
return answ;
}
#endregion
#region area public
///
/// tableAdapter diritti
///
public DataLayer_AnagGenTableAdapters.DIRITTITableAdapter taDiritti;
///
/// tableAdapter permessi
///
public DataLayer_AnagGenTableAdapters.PermessiTableAdapter taPermessi;
///
/// tableAdapter funzione
///
public DataLayer_AnagGenTableAdapters.FUNZIONETableAdapter taFunzione;
///
/// tableAdapter permessi2funzione
///
public DataLayer_AnagGenTableAdapters.Permessi2FunzioneTableAdapter taPermessi2Funzione;
///
/// tableAdapter CdC
///
public DataLayer_AnagGenTableAdapters.CDCTableAdapter taCdc;
///
/// tableAdapter utenti
///
public DataLayer_AnagGenTableAdapters.UTENTETableAdapter taUtente;
///
/// tableAdapter userData (user/pwd)
///
public DataLayer_AnagGenTableAdapters.UserDataTableAdapter taUserData;
///
/// tableAdapter userDataExt (user/pwd)
///
public DataLayer_AnagGenTableAdapters.UserDataExtTableAdapter taUserDataExt;
///
/// table adapter lingue
///
public DataLayer_genericTableAdapters.LingueTableAdapter taLingue;
///
/// table adapter vocabolario
///
public DataLayer_genericTableAdapters.VocabolarioTableAdapter taVocabolario;
///
/// table adapter versione vocabolario
///
public DataLayer_genericTableAdapters.LogUpdateDbTableAdapter taLogVoc;
///
/// table adapter versione anagrafica
///
public DataLayer_AnagGenTableAdapters.LogUpdateDbTableAdapter taLogAna;
///
/// table adapter Devices utente
///
public DS_devicesTableAdapters.AnagDevicesTableAdapter taAnagDev;
///
/// oggetto vocabolario organizzato come dizionario con chiave lang#lemma e valore la traduzione
///
public Dictionary dictVocabolario;
///
/// resetta il vocabolario rileggendo i dati...
///
public void resetVocabolario()
{
memLayer.ML.emptyCacheVal("dictVocabolario");
setupVocabolario();
}
///
/// Verifica se il vocabolario sia ok...
///
public bool vocabolarioOk
{
get
{
bool answ = false;
try
{
answ = (dictVocabolario != null);
if(answ)
{
answ = dictVocabolario.Count > 0;
}
}
catch
{ }
return answ;
}
}
///
/// crea nel db corrente il lemma richiesto e lo valorizza come "--{0}--"
///
///
///
public void creaNuovoLemmaVoc(string lemma)
{
foreach (DataLayer_generic.LingueRow rigaLingua in taLingue.GetData())
{
taVocabolario.Insert(rigaLingua.Lingua, lemma, string.Format("--{0}--", lemma));
}
}
///
/// restituisce conteggio numero record dell'oggetto vocabolario
///
public int numRecVoc
{
get
{
int answ = 0;
try
{
answ = dictVocabolario.Count;
}
catch
{ }
return answ;
}
}
///
/// elenco lingue ammesse da vocabolario...
///
public DataLayer_generic.LingueDataTable lingue
{
get
{
return taLingue.GetData();
}
}
///
/// classe singleton x la gestione dei tableadapters
///
public static DataWrap DW = new DataWrap();
#endregion
}
}