571 lines
26 KiB
C#

using System;
using System.Collections.Generic;
using System.Web;
using System.Web.Services;
using Consulenza.Immobiliare.Business;
using System.Data;
using System.Xml;
using System.Linq;
using Consulenza.ReportCommon;
using Consulenza.WebTemplateModeler.Entity;
using Consulenza.Unica.Business;
using System.IO;
using Consulenza.PDFLettera;
using ceTe.DynamicPDF.Merger;
namespace Consulenza.Immobiliare.Services
{
/// <summary>
/// Summary description for WSImmobiliare
/// </summary>
[WebService(Namespace = "http://it.bancafideuram.report.immobiliareservice/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
// [System.Web.Script.Services.ScriptService]
public class WSImmobiliare : System.Web.Services.WebService
{
/// <summary>
/// Ottiene un array binario del PDF del report di Diagnosi Immobiliare di ConsulenzaEvoluta.
/// </summary>
/// <param name="chiaveCliente">Chiave del cliente</param>
/// <param name="idImmobileCatasto">lista di id immobile al catasto. Corrisponde al campo chiaveProdottoTerzi della tabella ConsulenzaEvoluta.PatrimonioTerzi</param>
/// <param name="idSezione">lista delle sezioni. Campo:IdSezione, tabella:Sezioni, database:ReportModeler2</param>
/// <returns></returns>
[WebMethod(MessageName = "CreaReport_Immobiliare")]
public byte[] CreaReport_Immobiliare(long chiaveCliente, List<string> idImmobileCatasto, List<Int32> idSezione)
{
return new Consulenza.Immobiliare.Business.GeneratorService().CreaReport_ImmobiliareDiagnosi(chiaveCliente, idImmobileCatasto, idSezione, false);
}
[WebMethod(MessageName = "CreaReport_ImmobiliareCU")]
public byte[] CreaReport_ImmobiliareCU(long chiaveCliente, List<string> idImmobileCatasto, List<Int32> idSezione)
{
return new Consulenza.Immobiliare.Business.GeneratorService().CreaReport_ImmobiliareDiagnosi(chiaveCliente, idImmobileCatasto, idSezione, true);
}
[WebMethod(MessageName = "CreaReport_MonitoraggioImmobiliareCU")]
public byte[] CreaReport_MonitoraggioImmobiliareCU(long chiaveCliente, List<string> idImmobileCatasto, Template template)
{
//FCToDo
#region Modifiche da portare su monitoraggioImmobiliareSolution
Consulenza.Immobiliare.Business.GeneratorService generatorService = null;
Consulenza.DataServices.DatiSeiUnico datiSeiUnico = null;
ReportStruct strutturaReport = null;
Modello modello = null;
string metodo = "";
var mt = new WebTemplateModelerService();
// lettura dati cliente
Cliente cliente = DataService.ClienteManager.RecuperaCliente(chiaveCliente, true);
PrivateBanker privatePB = DataService.PrivateBankerManager.RecuperaPrivateBanker(chiaveCliente,true);
try
{
metodo += " codiceAgente=" + privatePB.Codice + " codiceFiscale=" + cliente.CodiceFiscale+ " codiceMandato=" + " " + " codiceRete=" + privatePB.CodiceRete + " chiave=" + cliente.Chiave;
template = mt.TestTemplate(template, metodo);
modello = mt.GetModello(template.IdModello);
}
catch (Exception ex)
{
mt.insertLog("", "", "", "", "Caricamento Modello/Template " + metodo, ex);
throw new Exception("Caricamento Modello/Template " + metodo + " " + ex.Message);
}
try
{
strutturaReport = new ReportStruct
{
Opzioni = template.Options.Distinct().ToDictionary(x => x.Key, x => x.Value),
Schede = (from schede in template.Schede
join modelli in modello.Schede
on schede.Id equals modelli.Id
where modelli.Sezioni != "0"
select new ReportCommon.Scheda
{
Id = Convert.ToInt32(modelli.Sezioni),
Opzioni = schede.Options.Distinct().ToDictionary(x => x.Key, x => x.Value)
}).ToList()
};
//var Opzione10 = (from o in template.Options where o.Key == "Opzione10" select o.Value).LastOrDefault();
//if (Opzione10 != null)
//{
// foreach (int s in JsonConvert.DeserializeObject<Opzione10>(Opzione10).idSchede)
// {
// strutturaReport.Schede.Add(new ReportCommon.Scheda
// {
// Id = s,
// Opzioni = new Dictionary<string, string>()
// });
// }
//}
//foreach (var scheda in strutturaReport.Schede)
//{
// if (strutturaReport.Opzioni.ContainsKey("Opzione1"))
// scheda.Opzioni.Add("Opzione1", strutturaReport.Opzioni["Opzione1"]);
// if (strutturaReport.Opzioni.ContainsKey("Opzione2"))
// scheda.Opzioni.Add("Opzione2", strutturaReport.Opzioni["Opzione2"]);
// foreach (var opzione in scheda.Opzioni)
// {
// if (opzione.Key == "Opzione5_3")
// {
// codiceFiscaleDelegato = JsonConvert.DeserializeObject<Opzione5_3>(opzione.Value).Valore;
// }
// }
//}
}
catch (Exception ex)
{
mt.insertLog(modello.Id.ToString(), template.CodicePb, template.Id.ToString(), template.IsDefault, "strutturaReport " + metodo, ex);
throw new Exception("strutturaReport " + metodo + " " + ex.Message);
}
try
{
datiSeiUnico = new Consulenza.DataServices.DatiSeiUnico(
privatePB.Codice,
cliente.CodiceFiscale,
"", //todo verifica mandato
privatePB.CodiceRete,
!modello.Nome.ToLower().Equals("proposta") ? 0 : cliente.Chiave,
!modello.Nome.ToLower().Equals("nucleo") ? 0 : cliente.Chiave,
(from s in template.Schede select s.Id).ToList<int>()
);
datiSeiUnico.Execute();
generatorService = new Consulenza.Immobiliare.Business.GeneratorService(datiSeiUnico);
}
catch (Exception ex)
{
//mt.insertLog(modello.Id.ToString(), template.CodicePb, template.Id.ToString(), template.IsDefault, datiSeiUnico.UrlFideuramDati + " " + metodo, ex);
//throw new Exception(datiSeiUnico.UrlFideuramDati + " " + metodo + " " + ex.Message);
}
#endregion
return generatorService.CreaReport_MonitoraggioImmobiliareCU(chiaveCliente, idImmobileCatasto, strutturaReport);
//return new Consulenza.Immobiliare.Business.GeneratorService().CreaReport_MonitoraggioImmobiliareCU(chiaveCliente, idImmobileCatasto, strutturaReport);
}
[WebMethod(MessageName = "CreaReport_MonitoraggioImmobiliareCUTest")]
public byte[] CreaReport_MonitoraggioImmobiliareCUTest(long chiaveCliente, List<string> idImmobileCatasto, List<Int32> idSezione)
{
Consulenza.Immobiliare.Business.GeneratorService generatorService = null;
Consulenza.DataServices.DatiSeiUnico datiSeiUnico = null;
// lettura dati cliente
var mt = new WebTemplateModelerService();
Cliente cliente = DataService.ClienteManager.RecuperaCliente(chiaveCliente, true);
PrivateBanker privatePB = DataService.PrivateBankerManager.RecuperaPrivateBanker(chiaveCliente, true);
try
{
datiSeiUnico = new Consulenza.DataServices.DatiSeiUnico(
privatePB.Codice,
cliente.CodiceFiscale,
"", //todo verifica mandato
privatePB.CodiceRete,
0,
0,
idSezione
);
datiSeiUnico.Execute();
generatorService = new Consulenza.Immobiliare.Business.GeneratorService(datiSeiUnico);
}
catch (Exception ex)
{
throw new Exception(datiSeiUnico.UrlFideuramDati + " " + ex.Message);
}
return generatorService.CreaReport_MonitoraggioImmobiliare(chiaveCliente, idImmobileCatasto, idSezione);
}
[WebMethod(MessageName = "CreaReport_MonitoraggioImmobiliareBatchCUTest")]
public byte[] CreaReport_MonitoraggioImmobiliareBatchCUTest(long chiaveCliente, List<string> idImmobileCatasto, List<Int32> idSezione)
{
Consulenza.Immobiliare.Business.GeneratorService generatorService = null;
//Consulenza.DataServices.DatiSeiUnico datiSeiUnico = null;
// lettura dati cliente
var mt = new WebTemplateModelerService();
Cliente cliente = DataService.ClienteManager.RecuperaCliente(chiaveCliente, true);
PrivateBanker privatePB = DataService.PrivateBankerManager.RecuperaPrivateBanker(chiaveCliente, true);
int nModello = 0;
if (privatePB.CodiceRete == "F")
nModello = 13;
else
nModello = 12;
try
{
#region Carica Modello - Sezioni e Vincoli
if (idSezione.Count() == 0)
{
Modello modelloBatch = mt.GetModello(nModello);
List<Vincolo> vincoloBatch = mt.GetVincoli(chiaveCliente, 0, "ReportImmobiliareMonitoraggio").ToList();
//foreach (var v in reportManager.GetVincoli(ccpb, 0, "Monitoragio").ToList())
//{
// if (!vinc.Exists(o => o.Key == v.Key))
// {
// vinc.Add(v);
// }
//}
foreach (var scheda in modelloBatch.Schede)
{
switch (scheda.Sezioni)
{
case "226":
// flagfinalitaimmobiliUS 3
if (vincoloBatch[3].Value == "1")
idSezione.Add(Convert.ToInt32(scheda.Sezioni));
break;
case "227":
//flagfinalitaimmobiliI 4
if (vincoloBatch[4].Value == "1")
idSezione.Add(Convert.ToInt32(scheda.Sezioni));
break;
case "228":
////flagfinalitaimmobiliNS 2
if (vincoloBatch[2].Value == "1")
idSezione.Add(Convert.ToInt32(scheda.Sezioni));
break;
case "229":
////flagdirittiimmobili 5
if (vincoloBatch[5].Value == "1")
idSezione.Add(Convert.ToInt32(scheda.Sezioni));
break;
case "230":
//flaganomaliaimmobili 0
if (vincoloBatch[0].Value == "1")
idSezione.Add(Convert.ToInt32(scheda.Sezioni));
break;
case "234":
//flagimmobiliestero 6
if (vincoloBatch[6].Value == "1")
idSezione.Add(Convert.ToInt32(scheda.Sezioni));
break;
case "XXX":
//flagfabricaticatasto 1
break;
default:
idSezione.Add(Convert.ToInt32(scheda.Sezioni));
break;
}
}
}
#endregion
generatorService = new Consulenza.Immobiliare.Business.GeneratorService(cliente, privatePB);
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
byte[] myPdfReport = null;
myPdfReport = generatorService.CreaReport_MonitoraggioImmobiliare(chiaveCliente, idImmobileCatasto, idSezione, bBatch:true);
//return myPdfReport;
// NEWS
// Create two PDF document objects
GestoreLettera.RestGestoreLettera();
PdfDocument pdfA = new PdfDocument(GestoreLettera.componiLetteraAccompagnamento(cliente.CodiceFiscale, privatePB.CodiceRete));
PdfDocument pdfB = new PdfDocument(myPdfReport);
//// Merge the two documents
MergeDocument _documentoFinale = MergeDocument.Merge(pdfA, pdfB);
//// Save the PDF
byte[] _data = _documentoFinale.Draw();
// FINE NEWS
return _data;
//byte[] pdf = this.getData();
//// Create two PDF document objects
//PdfDocument pdfA;
//GestoreLettera.RestGestoreLettera();
//if (UtilityManager.getAppSetting("Periodico") != "1")
//{
// if (_dataThread.AdesioneSuccessivaAvanzato || _dataThread.ContrattoOld)
// pdfA = new PdfDocument(GestoreLettera.componiLetteraBenvenuto(_dataThread.CodiceFiscale, _dataThread.Rete, TipoLettera.LetteraAccettazioneAttivazioneSeiPosticipata, _dataThread.TipoContratto, LetteraAccompagnamento.TipoReport.Diagnosi));
// else
// pdfA = new PdfDocument(GestoreLettera.componiLetteraBenvenuto(_dataThread.CodiceFiscale, _dataThread.Rete, TipoLettera.LetteraAccettazioneConAttivazioneSei, _dataThread.TipoContratto, LetteraAccompagnamento.TipoReport.Diagnosi));
//}
//else
//{
// if (_dataThread.TipoReport.ToUpper().Trim() == "DIAGNOSI")
// pdfA = new PdfDocument(GestoreLettera.componiLetteraAccompagnamento(_dataThread.CodiceFiscale, _dataThread.Rete, _dataThread.TipoContratto, LetteraAccompagnamento.TipoReport.Diagnosi));
// else
// pdfA = new PdfDocument(GestoreLettera.componiLetteraAccompagnamento(_dataThread.CodiceFiscale, _dataThread.Rete, _dataThread.TipoContratto, LetteraAccompagnamento.TipoReport.Monitoraggio));
//}
//PdfDocument pdfB = new PdfDocument(pdf);
////pdfA = new PdfDocument(LetteraBA.GetLetteraBA(_dataThread));
//// Merge the two documents
//_documentoFinale = MergeDocument.Merge(pdfA, pdfB);
//// Save the PDF
//_data = _documentoFinale.Draw();
}
[WebMethod(MessageName = "CreaReport_MonitoraggioImmobiliareNucleiCU")]
public byte[] CreaReport_MonitoraggioImmobiliareNucleiCU(long chiaveNucleo, List<string> idImmobileCatasto, Template template)
{
// (long chiaveNucleo, List<Int64> chiaviClientiPB, List<string> idImmobileCatasto, List<Int32> idSezione)
//FCToDo
#region Modifiche da portare su monitoraggioImmobiliareSolution
Consulenza.Immobiliare.Business.GeneratorService generatorService = null;
Consulenza.DataServices.DatiSeiUnico datiSeiUnico = null;
ReportStruct strutturaReport = null;
Modello modello = null;
string metodo = "";
var mt = new WebTemplateModelerService();
var nucleo = DataService.NucleoManager.RecuperaNucleo(chiaveNucleo, true);
long chiavePbPrincipale = nucleo.ChiaveClientePBPrincipale;
var privateBanker = DataService.PrivateBankerManager.RecuperaPrivateBanker(chiavePbPrincipale, true);
try
{
metodo += " codiceAgente=" + privateBanker.Codice + " codiceMandato=" + " " + " codiceRete=" + privateBanker.CodiceRete + " chiave=" + chiaveNucleo;
template = mt.TestTemplate(template, metodo);
modello = mt.GetModello(template.IdModello);
}
catch (Exception ex)
{
mt.insertLog("", "", "", "", "Caricamento Modello/Template " + metodo, ex);
throw new Exception("Caricamento Modello/Template " + metodo + " " + ex.Message);
}
try
{
strutturaReport = new ReportStruct
{
Opzioni = template.Options.Distinct().ToDictionary(x => x.Key, x => x.Value),
Schede = (from schede in template.Schede
join modelli in modello.Schede
on schede.Id equals modelli.Id
where modelli.Sezioni != "0"
select new ReportCommon.Scheda
{
Id = Convert.ToInt32(modelli.Sezioni),
Opzioni = schede.Options.Distinct().ToDictionary(x => x.Key, x => x.Value)
}).ToList()
};
}
catch (Exception ex)
{
mt.insertLog(modello.Id.ToString(), template.CodicePb, template.Id.ToString(), template.IsDefault, "strutturaReport " + metodo, ex);
throw new Exception("strutturaReport " + metodo + " " + ex.Message);
}
try
{
datiSeiUnico = new Consulenza.DataServices.DatiSeiUnico(
nucleo.AgenteNucleo,
"",
"", //todo verifica mandato
nucleo.ReteNucleo,
0,
chiaveNucleo,
(from s in template.Schede select s.Id).ToList<int>()
);
try
{
datiSeiUnico.Execute();
}
catch (Exception e)
{
string err = e.Message.ToString();
}
generatorService = new Consulenza.Immobiliare.Business.GeneratorService(datiSeiUnico);
}
catch (Exception ex)
{
//mt.insertLog(modello.Id.ToString(), template.CodicePb, template.Id.ToString(), template.IsDefault, datiSeiUnico.UrlFideuramDati + " " + metodo, ex);
//throw new Exception(datiSeiUnico.UrlFideuramDati + " " + metodo + " " + ex.Message);
}
#endregion
return generatorService.CreaReport_MonitoraggioImmobiliareNucleiCU(chiaveNucleo, idImmobileCatasto, strutturaReport);
}
[WebMethod(MessageName = "CreaReport_MonitoraggioImmobiliareNucleiCUTest")]
public byte[] CreaReport_MonitoraggioImmobiliareNucleiCUTest(long chiaveNucleo, List<Int64> chiaviClientiPB, List<string> idImmobileCatasto, List<Int32> idSezione)
{
Consulenza.Immobiliare.Business.GeneratorService generatorService = null;
var nucleo = DataService.NucleoManager.RecuperaNucleo(chiaveNucleo, true);
long chiavePbPrincipale = nucleo.ChiaveClientePBPrincipale;
// var privateBanker = DataService.PrivateBankerManager.RecuperaPrivateBanker(chiavePbPrincipale, true);
#region lettura dati Unica
Consulenza.DataServices.DatiSeiUnico datiSeiUnico = null;
// lettura dati cliente
try
{
datiSeiUnico = new Consulenza.DataServices.DatiSeiUnico(
nucleo.AgenteNucleo,
"",
"", //todo verifica mandato
nucleo.ReteNucleo,
0,
chiaveNucleo,
idSezione
);
try {
datiSeiUnico.Execute();
}
catch ( Exception e )
{
string err = e.Message.ToString();
}
generatorService = new Consulenza.Immobiliare.Business.GeneratorService(datiSeiUnico);
}
catch (Exception ex)
{
//mt.insertLog(modello.Id.ToString(), template.CodicePb, template.Id.ToString(), template.IsDefault, datiSeiUnico.UrlFideuramDati + " " + metodo, ex);
throw new Exception(datiSeiUnico.UrlFideuramDati + " " + ex.Message);
}
#endregion
return generatorService.CreaReport_MonitoraggioImmobiliareNuclei(chiaveNucleo, chiaviClientiPB, idImmobileCatasto, idSezione);
}
/// <summary>
/// Ottiene un array binario del PDF del report di Diagnosi Immobiliare di ConsulenzaEvoluta per un nucleo familiare.
/// </summary>
/// <param name="chiaveNucleo">Chiave del nucleo familiare</param>
/// <param name="idImmobileCatasto">lista di id immobile al catasto. Corrisponde al campo chiaveProdottoTerzi della tabella ConsulenzaEvoluta.PatrimonioTerzi</param>
/// <param name="chiaviClientiPB">lista di chiaveclientepb dei componenti del nucleo.</param>
/// <param name="idSezione">lista delle sezioni. Campo:IdSezione, tabella:Sezioni, database:ReportModeler2</param>
/// <returns></returns>
[WebMethod(MessageName = "CreaReport_NucleiImmobiliare")]
public byte[] CreaReport_NucleiImmobiliare(long chiaveNucleo, List<string> idImmobileCatasto, List<Int64> chiaviClientiPB, List<Int32> idSezione)
{
return new Consulenza.Immobiliare.Business.GeneratorService().CreaReport_ImmobiliareDiagnosi_Nucleo(chiaveNucleo, idImmobileCatasto, chiaviClientiPB, idSezione, false);
}
[WebMethod(MessageName = "CreaReport_NucleiImmobiliareCU")]
public byte[] CreaReport_NucleiImmobiliareCU(long chiaveNucleo, List<string> idImmobileCatasto, List<Int64> chiaviClientiPB, List<Int32> idSezione)
{
try
{
return new Consulenza.Immobiliare.Business.GeneratorService().CreaReport_ImmobiliareDiagnosi_Nucleo(chiaveNucleo, idImmobileCatasto, chiaviClientiPB, idSezione, true);
}
catch (Exception ex)
{
using (StreamWriter outputFile = new StreamWriter(@"D:\SEIReportConsulenzaEvoluta\logs\logFile.txt"))
{
outputFile.WriteLine(System.DateTime.Now + " WSImmobiliare.CreaReport_NucleiImmobiliareCU - " + ex.ToString());
}
return null;
};
}
/// <summary>
/// Ottiene un array binario del PDF del report di Mappatura Preliminare Immobiliare.
/// </summary>
/// <param name="chiaveCliente">Chiave del cliente</param>
/// <param name="idImmobileCatasto">lista di id immobile al catasto. Corrisponde al campo chiaveProdottoTerzi della tabella ConsulenzaEvoluta.PatrimonioTerzi</param>
/// <param name="idSezione">lista delle sezioni. Campo:IdSezione, tabella:Sezioni, database:ReportModeler2</param>
/// <returns></returns>
[WebMethod(MessageName = "CreaReport_MappaturaPreliminare")]
public byte[] CreaReport_MappaturaPreliminare(long chiaveCliente, List<string> idImmobileCatasto, List<Int32> idSezione)
{
return new Consulenza.Immobiliare.Business.GeneratorService().CreaReport_MappaturaPreliminare(chiaveCliente, idImmobileCatasto, idSezione, false);
}
[WebMethod(MessageName = "CreaReport_MappaturaPreliminareCU")]
public byte[] CreaReport_MappaturaPreliminareCU(long chiaveCliente, List<string> idImmobileCatasto, List<Int32> idSezione)
{
return new Consulenza.Immobiliare.Business.GeneratorService().CreaReport_MappaturaPreliminare(chiaveCliente, idImmobileCatasto, idSezione, true);
}
/// <summary>
/// Ottiene un array binario del PDF del report di Diagnosi di Finalità Immobiliare di ConsulenzaEvoluta. (08/02/2016)
/// </summary>
/// <param name="chiaveCliente">Chiave del cliente</param>
/// <param name="idImmobileCatasto">lista di id immobile al catasto. Corrisponde al campo chiaveProdottoTerzi della tabella ConsulenzaEvoluta.PatrimonioTerzi</param>
/// <param name="idSezione">lista delle sezioni. Campo:IdSezione, tabella:Sezioni, database:ReportModeler2</param>
/// <returns></returns>
[WebMethod(MessageName = "CreaReport_FinalitaImmobiliare")]
public byte[] CreaReport_FinalitaImmobiliare(long chiaveCliente, List<string> idImmobileCatasto, List<Int32> idSezione)
{
return new Consulenza.Immobiliare.Business.GeneratorService().CreaReport_FinalitaImmobiliare(chiaveCliente, idImmobileCatasto, idSezione, false);
}
[WebMethod(MessageName = "CreaReport_FinalitaImmobiliareCU")]
public byte[] CreaReport_FinalitaImmobiliareCU(long chiaveCliente, List<string> idImmobileCatasto, List<Int32> idSezione)
{
return new Consulenza.Immobiliare.Business.GeneratorService().CreaReport_FinalitaImmobiliare(chiaveCliente, idImmobileCatasto, idSezione, true);
}
[WebMethod(MessageName = "CreaReport_MonitoraggioImmobiliare")]
public byte[] CreaReport_MonitoraggioImmobiliare(long chiaveCliente, List<string> idImmobileCatasto, List<Int32> idSezione)
{
return new Consulenza.Immobiliare.Business.GeneratorService().CreaReport_FinalitaImmobiliare(chiaveCliente, idImmobileCatasto, idSezione, true);
}
public Modello GetModello(int idModello, string codicePb)
{
return new WebTemplateModelerService().GetModello(idModello, codicePb);
}
}
}