2025-04-15 12:10:19 +02:00

509 lines
21 KiB
C#

using System;
using System.Collections.Generic;
using System.Web.UI;
using System.Data;
using System.Web;
using ConsulenzaEvoluta;
//ISPB >>>>
using ClassLibraryWS.bancafideuram.nac.token;
//ISPB <<<<
public partial class reportNucleiFamiliari : System.Web.UI.Page
{
public string codCliente;
public string tipoRete;
public string codPB;
public string codAs;
public string codiceUtenteQueryString;
public string token;
public string userName = string.Empty;
public string codiceApplicazione = string.Empty;
public string checkPrivacy;
private Nucleo _nucleo;
public string pathNav;
public int idReport; //indica il modello (fixed) COMPLETO di QUESTO report da cui costruire la treeview iniziale
private string sUtente;
public int chiaveNucleo;
public static int tpReport = 8; //valore proprietario (fixed) di QUESTO report //DA VALUTARE!!
public static int idReportAlbero = 16; //valore proprietario (fixed) di QUESTO report //DA VALUTARE!!
public static int idReportBase = 16;
public static int idReportCompleto = 16;
public string codiceRete;
public string codicePB;
public string ambiente;
public int lastSavedReportId;
public static string nomeReport = "NUCLEO"; //valore proprietario (fixed) di QUESTO report
public static string nomeReportCompleto = "Nucleo completo"; //valore proprietario (fixed) di QUESTO report
public static string nomeReportRischio = "NUCLEO"; //valore proprietario (fixed) di QUESTO report
public static string nomeReportBaseRischio = "Nucleo base"; //valore proprietario (fixed) di QUESTO report
public static string nomeReportCompletoRischio = "Nucleo completo"; //valore proprietario (fixed) di QUESTO report
string nomeReportPerLabel;
string descrizioneReportPerLabel;
public int reportIdToLoadBack = -1;
public string endOfjob = "0";
//private bool reportNominativo = false;
int IDReportToLoad = -1;
public string baseCompleto;
public string reportName;
private int IdModello;
private GestReport m = new GestReport();
private bool mioblocco = false;
protected void Page_Load(object sender, EventArgs e)
{
if (ClassLibraryWS.Debug.iSDebug && Request.QueryString.Get("tipoRete") == null)
{
Response.Redirect("reportNucleiFamiliari.aspx?codPB=" + ClassLibraryWS.Debug.Agente + "&chiaveNucleo=" + ClassLibraryWS.Debug.ChiaveNucleo + "&token=&tipoRete=" + ClassLibraryWS.Debug.Rete);
return;
}
SessionNucleo sessionNucleo = new SessionNucleo();
sessionNucleo.ClearSession();
token = Request.QueryString.Get("token");
codiceRete = Request.QueryString.Get("tipoRete");
tipoRete = Request.QueryString.Get("tiporete").ToUpper();
codicePB = Request.QueryString.Get("codPB");
codPB = Request.QueryString.Get("codpb").ToUpper();
codAs = Request.QueryString.Get("codas") != null ? Request.QueryString.Get("codas").ToUpper() : string.Empty;
codiceUtenteQueryString = tipoRete.Trim() + codicePB.Trim();
chiaveNucleo = Convert.ToInt32(Request.QueryString["chiaveNucleo"]);
IdModello = codiceRete.Equals("S") ? 4 : 3;
_nucleo = Nucleo.getNucleo(chiaveNucleo);
if (!Page.IsPostBack)
{
#region From Gestione Modelli
string loadingReport = Request.QueryString.Get("idReportToLoad");
nomeReportPerLabel = Request.QueryString.Get("nomeInizialeReport");
descrizioneReportPerLabel = Request.QueryString.Get("descrizioneInizialeReport");
#endregion
if (HFERRORMSG.Value.Equals(""))
{
if (Session["daSalvaPdf"] == null) Session.Add("daSalvaPdf", false);
m.TipoRete = codiceRete.Equals("F") ? "Banca Fideuram" : "SanPaolo Invest";
if (!bool.Parse(Session["daSalvaPdf"].ToString()) || Session["DatiHidden"] == null)
{
m.AcquisisciModello(IdModello);
Session["DatiHidden"] = null;
Session["HFNomeTemplate"] = null;
CaricaTemplate(null, false);
}
else
{
m.SetHtmlClient(Session["DatiHidden"].ToString());
DatiHidden.Value = m.GetHtmlClient();
HFNomeTemplate.Value = Session["HFNomeTemplate"].ToString();
Session["DatiHidden"] = null;
Session["HFNomeTemplate"] = null;
CaricaTemplate(HFNomeTemplate.Value, false);
}
Session["daSalvaPdf"] = false;
List<string> vincoli = m.GetVincoliSchedeNucleo(chiaveNucleo);
m.SetEnableSchede(vincoli);
//m.SetEnableSchedeNucleo(codiceRete, codicePB, chiaveNucleo);
DatiHidden.Value = m.GetHtmlClient();
}
if (ClassLibraryWS.Debug.iSDebug)
{
ClassLibraryWS.Debug.LogFunzionalita("iSDebug", "return forzato");
return;
}
#region Recupero token da AnagraficaWS.GetVersion
if (string.IsNullOrEmpty(token))
{
string codPortal = WebConfigParameter.getParameter("CODICEPORTALEPERVERSIONESIMPB");
InfoClient infoCliente = new InfoClient();
infoCliente.codiceApplicazione = WebConfigParameter.getParameter("CODICEAPPLICAZIONE").ToString();
infoCliente.codiceRete = codiceRete;
infoCliente.versioneDatabaseSIMPB = 0;
AnagraficaWS wsana = new AnagraficaWS();
//ISPB >>>>
TokenRes risposta = wsana.GetVersion(infoCliente, codPortal);
token = risposta.info.versioneDatabaseSIMPB.ToString();
//ISPB <<<<
}
#endregion
#region InfoClient e ChiaveCliente di GlobalPosition e Anagrafica
// Global Position
ClassLibraryWS.bancafideuram.nac.globalposition.InfoClient _infoCliente_GlobalPosition = new ClassLibraryWS.bancafideuram.nac.globalposition.InfoClient();
_infoCliente_GlobalPosition.codiceApplicazione = WebConfigParameter.getParameter("CODICEAPPLICAZIONE").ToString();
_infoCliente_GlobalPosition.versioneDatabaseSIMPB = int.Parse(token);
ClassLibraryWS.bancafideuram.nac.globalposition.ChiaveCliente _chiaveCliente_GlobalPosition = new ClassLibraryWS.bancafideuram.nac.globalposition.ChiaveCliente();
//ISPB _chiaveCliente_GlobalPosition.potenzialeClienteNAC = true;
#endregion
#region Caricamento tabella Dettaglio_Asul
DataTable dtDettaglioAsul = new DataTable();
DataTable dtContrattoSintesiNucleo = BusinessManager.GetDataTableFromStoredProcedure_ConsulenzaEvoluta("REP_NUCLEO_CONTRATTOSINTESI", -1, -1, _nucleo.ChiaveNucleo);
DataRow[] rowsProdottiAsul = dtContrattoSintesiNucleo.Select("tipoProdotto='ASUL'");
foreach (DataRow itemClientePB in dtContrattoSintesiNucleo.DefaultView.ToTable(true, "chiaveClientePB").Rows)
{
// elimino i dati dalla dettaglio_asul per ogni chiaveClientePB
BusinessManager.DeleteData_Into_DettaglioAsul(Convert.ToInt32(itemClientePB["chiaveClientePB"]));
}
// Richiamo il dettaglio asul per ogni asul trovato nel portafoglio del cliente.
foreach (DataRow itemProdottoAsul in rowsProdottiAsul)
{
#region Recupero il dettaglio asul per ogni chiaveClientePB
// infoCliente
_infoCliente_GlobalPosition.codiceRete = itemProdottoAsul["codiceRete"].ToString();
// chiaveCliente
_chiaveCliente_GlobalPosition.codiceAgente = itemProdottoAsul["codiceAgente"].ToString();
//ISPB >>>
_chiaveCliente_GlobalPosition.NSG = itemProdottoAsul["codNsg"].ToString();
//ISPB <<<<
_chiaveCliente_GlobalPosition.codiceRete = itemProdottoAsul["codiceRete"].ToString();
dtDettaglioAsul = Prometeia.GetContrattoUnitLinkedSaldo(
_chiaveCliente_GlobalPosition,
itemProdottoAsul["CODICECONTRATTO"].ToString(),
_infoCliente_GlobalPosition,
Convert.ToInt32(itemProdottoAsul["chiaveClientePB"]));
#endregion
// Insert sulla DETTAGLIO_ASUL di ConsulenzaEvoluta
if (dtDettaglioAsul.Rows.Count > 0)
BusinessManager.InsertData_Into_DettaglioAsul(Convert.ToInt32(itemProdottoAsul["chiaveClientePB"]), dtDettaglioAsul);
}
#endregion
#region Gestione Autorizzazione
if (WebConfigParameter.getParameter("Ambiente") == "esterno")
userName = User.Identity.Name;
else
userName = WebConfigParameter.getParameter("UtenzaWindowsAccessoHP");
//1) utente loggato (VINCENZO UT.PROVA 2 MAGRI)
//2) utente impersonificato (VIOTTI GIANCARLO)
string AbilitazionePrimaria = string.Empty;
codiceApplicazione = WebConfigParameter.getParameter("CodiceApplicazione");
//ISPB string codiceUtente = tipoRete + Utente.GetCodiceUtente(userName); // è il codiceutente con cui andrò a interrogare la ConsulenzaBase.dbo.PromotoreBancario per recuperare le informazioni dell'utente loggato
string codiceUtente = tipoRete + codicePB; // è il codiceutente con cui andrò a interrogare la ConsulenzaBase.dbo.PromotoreBancario per recuperare le informazioni dell'utente loggato
Utente utenteLoggato_WS = Utente.GetAutorizzazioniAccessoGestioneControlli(userName, codiceApplicazione); // utente loggato (VINCENZO UT.PROVA 2 MAGRI), informazioni prese dai WS
Utente utenteLoggato = Utente.GetProfiloUtente(codiceUtente, utenteLoggato_WS.ProfiloUtenteLoggato); // utente loggato (VINCENZO UT.PROVA 2 MAGRI) , informazioni prese da DB
utenteLoggato.ProfiloUtenteLoggato = utenteLoggato_WS.ProfiloUtenteLoggato;
utenteLoggato.AbilitazionePrimaria = utenteLoggato_WS.AbilitazionePrimaria;
utenteLoggato.IsUtenteImpersonificato = utenteLoggato_WS.IsUtenteImpersonificato;
utenteLoggato.UtenteAutorizzatoApplicazione = utenteLoggato_WS.UtenteAutorizzatoApplicazione;
Utente utenteImpersonificato = Utente.GetProfiloUtente(codiceUtenteQueryString, null); // utente impersonificato (VIOTTI GIANCARLO)
utenteImpersonificato.AbilitazionePrimaria = utenteLoggato.AbilitazionePrimaria;
utenteImpersonificato.IsUtenteImpersonificato = utenteLoggato.IsUtenteImpersonificato;
utenteImpersonificato.UtenteAutorizzatoApplicazione = utenteLoggato.UtenteAutorizzatoApplicazione;
// FIX da valutare per TK T-300675-L4Y3
if (!codAs.Equals(codPB))
codiceUtenteQueryString = codiceUtente;
Utente utenteSoloPerAutorizzazione = Utente.GetAutorizzazioni(userName, codiceApplicazione, tipoRete, codiceUtenteQueryString, Convert.ToInt32(token));
if (utenteSoloPerAutorizzazione.UtenteAutorizzatoApplicazione)
{
if (Request.Browser.Cookies)
{
#region utente Loggato (UtenteLoggatoDiSessione)
string utenteLoggatoString = Utente.SerializeMessage(utenteLoggato);
utenteLoggatoString = HttpUtility.UrlDecode(utenteLoggatoString.TrimStart().TrimEnd());
Session.Add("UtenteLoggatoDiSessione", utenteLoggatoString);
#endregion
#region utente Impersonificato (UtenteImpersonificatoDiSessione)
string utenteImpersonificatoString = Utente.SerializeMessage(utenteImpersonificato);
utenteImpersonificatoString = HttpUtility.UrlDecode(utenteImpersonificatoString.TrimStart().TrimEnd());
Session.Add("UtenteImpersonificatoDiSessione", utenteImpersonificatoString);
#endregion
}
else
{
AbilitazionePrimaria = string.Empty;
if (utenteLoggato != null)
if (utenteLoggato.AbilitazionePrimaria != null)
AbilitazionePrimaria = utenteLoggato.AbilitazionePrimaria;
Response.Redirect("error.aspx?UtenteWindows=" + userName + "&UtentePB=" + codiceUtenteQueryString + "&CodiceApplicazione=" + WebConfigParameter.getParameter("CODICEAPPLICAZIONE") + "&VersioneSIMPB=" + token.ToString() + "&AbilitazionePrimaria=" + AbilitazionePrimaria);
}
}
else
{
AbilitazionePrimaria = string.Empty;
if (utenteLoggato != null)
if (utenteLoggato.AbilitazionePrimaria != null)
AbilitazionePrimaria = utenteLoggato.AbilitazionePrimaria;
Response.Redirect("error.aspx?UtenteWindows=" + userName + "&UtentePB=" + codiceUtenteQueryString + "&CodiceApplicazione=" + WebConfigParameter.getParameter("CODICEAPPLICAZIONE") + "&VersioneSIMPB=" + token.ToString() + "&AbilitazionePrimaria=" + AbilitazionePrimaria + "&UtenteAutorizzato=" + utenteLoggato_WS.UtenteAutorizzatoApplicazione.ToString());
}
#endregion
}
}
private int scriviNuovoModelloReportIntoDB(string reportName, int idCliente)
{
int rc = -1;
List<Parametro> parametri = new List<Parametro>();
Parametro parametro = new Parametro();
parametro.DbType = DbType.String;
parametro.Value = reportName;
parametro.ParameterName = "nome";
parametri.Add(parametro);
parametro = new Parametro();
parametro.DbType = DbType.String;
parametro.Value = string.Empty;
parametro.ParameterName = "descrizione";
parametri.Add(parametro);
parametro = new Parametro();
parametro.DbType = DbType.Boolean;
parametro.Value = false;
parametro.ParameterName = "flgModello";
parametri.Add(parametro);
parametro = new Parametro();
parametro.DbType = DbType.Int16;
parametro.Value = idReportAlbero;
parametro.ParameterName = "idReportModello";
parametri.Add(parametro);
parametro = new Parametro();
parametro.DbType = DbType.Int16;
parametro.Value = tpReport;
parametro.ParameterName = "tpReport";
parametri.Add(parametro);
parametro = new Parametro();
parametro.DbType = DbType.String;
parametro.Value = sUtente;
parametro.ParameterName = "utente";
parametri.Add(parametro);
parametro = new Parametro();
parametro.DbType = DbType.Int32;
parametro.Value = idCliente;
parametro.ParameterName = "idCliente";
parametri.Add(parametro);
parametro = new Parametro();
parametro.DbType = DbType.Int16;
//parametro.Value = rbl_Privacy.Items[0].Selected ? 0 : 1;
parametro.ParameterName = "Privacy";
parametri.Add(parametro);
rc = DataAccess.ExecuteNonQueryStoredProcedure(DBProvider.SqlServer, "sp_insertNewReportModelNew", parametri);
return rc;
}
private int InsertDatiInReportSezioniPers(int idReport, string delimiter, string hiddensezioniselezionate, string utente)
{
#region Salvataggio Modello
SezioneVincolo vincoli = (SezioneVincolo)Session["VINCOLIRISCHIO"];
int rc = 0;
List<Parametro> parametri = new List<Parametro>();
Parametro parametro = new Parametro();
parametro.DbType = DbType.Int32;
parametro.Value = idReport;
parametro.ParameterName = "pIdReport";
parametri.Add(parametro);
parametro = new Parametro();
parametro.DbType = DbType.String;
parametro.Value = delimiter;
parametro.ParameterName = "delimiter";
parametri.Add(parametro);
parametro = new Parametro();
parametro.DbType = DbType.String;
parametro.Value = hiddensezioniselezionate;
parametro.ParameterName = "splitstring";
parametri.Add(parametro);
parametro = new Parametro();
parametro.DbType = DbType.String;
parametro.Value = utente;
parametro.ParameterName = "utente";
parametri.Add(parametro);
rc = DataAccess.ExecuteNonQueryStoredProcedure(DBProvider.SqlServer, "sp_InsertIdSezioniIntoReportSezioniPers", parametri);
return rc;
#endregion
}
protected void ButCarica_Click(object sender, EventArgs e)
{
try
{
if (!DDLTemplate.Text.Equals("Seleziona"))
{
m.SetHtmlClient(DatiHidden.Value);
CaricaTemplate(DDLTemplate.SelectedItem.Text, true);
}
}
catch { }
finally
{
DatiHidden.Value = m.GetHtmlClient();
}
}
protected void ButElimina_Click(object sender, EventArgs e)
{
string alertMsg = "1";
try
{
if (!DDLTemplate.Text.Equals("Seleziona"))
{
m.SetHtmlClient(DatiHidden.Value);
m.CancellaTemplate(int.Parse(DDLTemplate.Text));
CaricaTemplate(null, false);
}
else
{
alertMsg = "2";
}
}
catch { alertMsg = "3"; }
finally
{
DatiHidden.Value = m.GetHtmlClient();
}
HFERRORMSG.Value = alertMsg;
}
protected void ButSalva_Click(object sender, EventArgs e)
{
string alertMsg = "4";
try
{
m.SetHtmlClient(DatiHidden.Value);
int[] idSez = new int[m.Template.Length];
for (int i = 0; i < m.Template.Length; i++)
idSez[i] = m.Template[i].Id;
foreach (DataRow dr in m.AcquisisciTemplate(codicePB, codiceRete, IdModello).Rows)
{
if (dr["NOMETEMPLATE"].ToString().Equals(HFNomeTemplate.Value) &&
dr["DEFAULT"].ToString().Equals("N") &&
!dr["codicePB"].ToString().Equals(""))
{
m.CancellaTemplate(int.Parse(dr["IDTEMPLATE"].ToString()));
m.SetHtmlClient(DatiHidden.Value);
alertMsg = "5";
break;
}
}
m.SalvaTemplate(HFNomeTemplate.Value, codicePB, codiceRete, IdModello, idSez, false, false);
CaricaTemplate(HFNomeTemplate.Value, true);
}
catch { alertMsg = "6"; }
finally
{
DatiHidden.Value = m.GetHtmlClient();
}
HFERRORMSG.Value = alertMsg;
}
protected void ButStampa_Click(object sender, EventArgs e)
{
m.SetHtmlClient(DatiHidden.Value);
#region Generator.aspx
int rc = 0;
//inizializzo il cookie che segnala la possibilita' di mostrare la pagina di inserimento note (reportStampa.aspx)
HttpCookie ck_endOfJob = new HttpCookie("endOfJob");
ck_endOfJob.Value = "0";
Response.Cookies.Add(ck_endOfJob);
idReport = scriviNuovoModelloReportIntoDB("LAST USED CONFIG" + "_" + _nucleo.IdCliente_SEIReport.ToString(), _nucleo.IdCliente_SEIReport);
// il modello è prefissato
rc = InsertDatiInReportSezioniPers(idReport, "|", m.GetSchedeReport(), codiceRete + codicePB);
if (rc > 0)
{
Session["DatiHidden"] = DatiHidden.Value;
Session["HFNomeTemplate"] = HFNomeTemplate.Value;
Session["HIDDENFIELD"] = HiddenFieldStampa.Value;
HFRETURN.Value = Request.QueryString.ToString();
HFGENERAPDF.Value = "tipoReport=NUCLEO&action=createNucleo&codicePB=" + codicePB + "&codiceFiscale=" + "&token=" + token + "&codiceRete=" + codiceRete + "&idReport=" + idReport.ToString() + "&chiaveNucleo=" + chiaveNucleo.ToString() + "&ambiente=" + ambiente + "&nomeInizialeReport=" + nomeReport + "&descrizioneInizialeReport=" + nomeReportCompleto + "&baseCompleto=" + baseCompleto + "&checkPrivacy=true";
}
#endregion
}
private void CaricaTemplate(string nometemplate, bool aggiorna)
{
DataTable dt = m.AcquisisciTemplate(codicePB, codiceRete, IdModello);
DDLTemplate.DataSource = dt;
DDLTemplate.DataTextField = "NOMETEMPLATE";
DDLTemplate.DataValueField = "IDTEMPLATE";
DDLTemplate.DataBind();
for (int r = 0; r < dt.Rows.Count; r++)
{
if (dt.Rows[r]["default"].ToString().Equals("S"))
{
DDLTemplate.Items[r].Text = "* - " + dt.Rows[r]["NOMETEMPLATE"];
}
if (nometemplate != null && nometemplate.Equals(DDLTemplate.Items[r].Text))
{
DDLTemplate.Items[r].Selected = true;
if (aggiorna)
{
m.SetTamplate(int.Parse(dt.Rows[r]["IDTEMPLATE"].ToString()), dt.Rows[r]["default"].ToString());
}
}
}
DDLTemplate.Items.Insert(0, "Seleziona");
}
}