using System.Collections.Generic; using System.Web.Services; using Consulenza.Unica.Business; using Consulenza.WebTemplateModeler.Entity; using Consulenza.ReportArchive.Entity; using Consulenza.ReportWriter.Manager.Section.Entity; using Consulenza.ReportWriter.Business.Entity; using System; using Consulenza.ReportCommon; using System.Linq; using Newtonsoft.Json; namespace Consulenza.Unica.Services { /// /// Summary description for ReportManager /// [WebService(Namespace = "http://tempuri.org/")] [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 ReportManager : WebService { //test prova git [WebMethod(MessageName = "CreaReportPO")] public byte[] CreaReportPO(string codiceAgente, string codiceFiscale, string codiceMandato, string codiceRete, long chiaveProposta) { var mt = new WebTemplateModelerService(); Template template = mt.GetTemplate(codiceRete.Equals("S") ? 10000 :9000, "S"); return CreaReport(codiceAgente, codiceFiscale, codiceMandato, codiceRete, chiaveProposta, template,new List()); } [WebMethod(MessageName = "CreaReportNoChiave")] public byte[] CreaReportNoChiave(string codiceAgente, string codiceFiscale, string codiceMandato, string codiceRete, Template template, List parametri) { List dateTime = new List(); dateTime.Add(DateTime.Now); var mt = new WebTemplateModelerService(); byte[] reportByte= new byte[0]; Consulenza.DataServices.DatiSeiUnico datiSeiUnico = null; ReportStruct strutturaReport = null; Modello modello = null; GeneratorService generatorService = null; string metodo = ""; try { metodo += " codiceAgente=" + codiceAgente + " codiceFiscale=" + codiceFiscale + " codiceMandato=" + codiceMandato + " codiceRete=" + codiceRete; 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).idSchede) { strutturaReport.Schede.Add(new ReportCommon.Scheda { Id = s, Opzioni = new Dictionary() }); } } 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"]); } } 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( codiceAgente, codiceFiscale, codiceMandato, codiceRete, 0, 0, (from s in template.Schede select s.Id).ToList() ); dateTime.Add(DateTime.Now); datiSeiUnico.Execute(); dateTime.Add(DateTime.Now); generatorService = new 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); } try { switch (modello.Nome.ToLower()) { case "diagnosi": reportByte = generatorService.CreaReport_Diagnosi(strutturaReport); break; case "monitoraggio": reportByte = generatorService.CreaReport_Monitoraggio(strutturaReport); break; case "proposta": reportByte = generatorService.CreaReport_Proposta(strutturaReport); break; case "nucleo": reportByte = generatorService.CreaReport_Nucleo(strutturaReport); break; default: throw new Exception("CreaReport_" + modello.Nome.ToLower() + " non esistente"); } } catch (Exception ex) { mt.insertLog(modello.Id.ToString(), template.CodicePb, template.Id.ToString(), template.IsDefault, "CreaReport_" + modello.Nome + " " + metodo, ex); throw new Exception("CreaReport_" + modello.Nome + " " + metodo + " " + ex.Message + " " + ex.StackTrace); } dateTime.Add(DateTime.Now); mt.insertLog(modello.Id.ToString(), template.CodicePb, template.Id.ToString(), template.IsDefault, "LogDate", metodo, dateTime); return reportByte; } [WebMethod(MessageName = "CreaReport")] public byte[] CreaReport(string codiceAgente, string codiceFiscale, string codiceMandato, string codiceRete, long chiave, Template template, List parametri) { List dateTime = new List(); dateTime.Add(DateTime.Now); var mt = new WebTemplateModelerService(); byte[] reportByte = new byte[0]; Consulenza.DataServices.DatiSeiUnico datiSeiUnico = null; ReportStruct strutturaReport = null; Modello modello = null; GeneratorService generatorService = null; string metodo = ""; string codiceFiscaleDelegato=""; bool dettaglioProdotti = false; bool dettaglioProdottiCointestati = false; bool dettaglioProdottiTCM = false; VisualizzazioneProdotti visualizzazioneScelta =VisualizzazioneProdotti.PosizioniAttive; try { metodo += " codiceAgente=" + codiceAgente + " codiceFiscale=" + codiceFiscale + " codiceMandato=" + codiceMandato + " codiceRete=" + codiceRete + " chiave=" + chiave.ToString(); 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).idSchede) { strutturaReport.Schede.Add(new ReportCommon.Scheda { Id = s, Opzioni = new Dictionary() }); } } 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(opzione.Value).Valore; } // isSezione 55 equivale alla scheda 12 -- arriva dal DB if (scheda.Id == 55) { if (opzione.Key == "Opzione4_1") { if (JsonConvert.DeserializeObject(opzione.Value).Valore) { dettaglioProdotti = true; } } if (opzione.Key == "Opzione4_2") { if (JsonConvert.DeserializeObject(opzione.Value).Valore) { dettaglioProdottiCointestati = true; } } if (opzione.Key == "Opzione4_3") { if (JsonConvert.DeserializeObject(opzione.Value).Valore) { dettaglioProdottiTCM = true; } } if (opzione.Key == "Opzione12") { var paramList = JsonConvert.DeserializeObject(opzione.Value).Valore.Split(','); string paramVisualizzazione = paramList[paramList.Length-1]; switch (paramVisualizzazione) { case "A": visualizzazioneScelta= VisualizzazioneProdotti.PosizioniAttive; break; case "SL": visualizzazioneScelta = VisualizzazioneProdotti.PosizioniLiquidate; break; case "CL": visualizzazioneScelta = VisualizzazioneProdotti.ContrattiLiquidati; break; default: visualizzazioneScelta = VisualizzazioneProdotti.All; break; } } } } } } 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( codiceAgente, codiceFiscale, codiceMandato, codiceRete, !modello.Nome.ToLower().Equals("proposta") ? 0 : chiave, !modello.Nome.ToLower().Equals("nucleo") ? 0 : chiave, (from s in template.Schede select s.Id).ToList(), codiceFiscaleDelegato, dettaglioProdotti, dettaglioProdottiCointestati, visualizzazioneScelta, dettaglioProdottiTCM ); dateTime.Add(DateTime.Now); datiSeiUnico.Execute(); dateTime.Add(DateTime.Now); generatorService = new 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); } try { switch (modello.Nome.ToLower()) { case "diagnosi": reportByte = generatorService.CreaReport_Diagnosi(strutturaReport); break; case "monitoraggio": reportByte = generatorService.CreaReport_Monitoraggio(strutturaReport); break; case "proposta": reportByte = generatorService.CreaReport_Proposta(strutturaReport); break; case "nucleo": reportByte = generatorService.CreaReport_Nucleo(strutturaReport); break; default: throw new Exception("CreaReport_" + modello.Nome.ToLower() + " non esistente"); } } catch (Exception ex) { mt.insertLog(modello.Id.ToString(), template.CodicePb, template.Id.ToString(), template.IsDefault, "CreaReport_" + modello.Nome + " " + metodo, ex); throw new Exception("CreaReport_" + modello.Nome + " " + metodo + " " + ex.Message + " " + ex.StackTrace); } dateTime.Add(DateTime.Now); mt.insertLog(modello.Id.ToString(), template.CodicePb, template.Id.ToString(), template.IsDefault, "LogDate", metodo, dateTime); return reportByte; } [WebMethod(MessageName = "CreaReportOld")] public byte[] CreaReportOld(long chiave, Template template, List parametri) { //((Opzione2)JsonConvert.DeserializeObject((from o in template.Options where o.Key == "Opzione2" select o.Value).LastOrDefault(), typeof(Opzione2))).ChiaveProposta // Modello var mt = new WebTemplateModelerService(); template = mt.TestTemplate(template, "CreaReportOld"); var modello = mt.GetModello(template.IdModello); //****** string Opzione2 = (from o in template.Options where o.Key == "Opzione2" select o.Value).LastOrDefault(); var cliente = Consulenza.DataServices.DatiSeiUnico.GetMokCliente(chiave); Consulenza.DataServices.DatiSeiUnico datiSeiUnico = new Consulenza.DataServices.DatiSeiUnico( cliente.codiceAgente, cliente.codiceFiscale, cliente.codiceMandato, cliente.codiceRete, Opzione2 != null ? ((Opzione2)JsonConvert.DeserializeObject(Opzione2, typeof(Opzione2))).ChiaveProposta : 0, !modello.Nome.ToLower().Equals("nucleo") ? 0 : chiave, (from s in template.Schede select s.Id).ToList() ); datiSeiUnico.Execute(); //******** // Struttura del report var 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 select new ReportCommon.Scheda { Id = Convert.ToInt32(modelli.Sezioni), Opzioni = schede.Options.Distinct().ToDictionary(x => x.Key, x => x.Value) }).ToList() }; //Propago le Opzioni a livello Report (per ora solo Opzione1 e Opzione2) a tutte le schede foreach (var scheda in strutturaReport.Schede) { if (strutturaReport.Opzioni.ContainsKey("Opzione1")) scheda.Opzioni.Add("Opzione1", strutturaReport.Opzioni["Opzione1"]); // Report anonimo o nominativo if (strutturaReport.Opzioni.ContainsKey("Opzione2")) scheda.Opzioni.Add("Opzione2", strutturaReport.Opzioni["Opzione2"]); // ChiaveProposta } //Switch per report switch (modello.Nome.ToLower()) { case "diagnosi": return new GeneratorService(chiave).CreaReport_Diagnosi(strutturaReport); case "monitoraggio": return new GeneratorService(chiave).CreaReport_Monitoraggio(strutturaReport); case "proposta": return new GeneratorService(datiSeiUnico).CreaReport_Proposta(strutturaReport); case "nucleo": return new GeneratorService(datiSeiUnico).CreaReport_Nucleo(strutturaReport); default: throw new Exception("Report non esistente"); } } /// /// metodo da cancellare usato per gestire sviluppo separato da webtemplatemodeler db: le schede S74 S75 non sono incluse...tanto funzionano /// /// /// private List getModelloMoKKato(string nomemodello) { var lista = new List(); int idscheda = 785; int idsezione = 44; for (int i = 1; i <= 16; i++) { var scheda = new WebTemplateModeler.Entity.Scheda { Id = idscheda, Options = new List