using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.Collections; using ceTe.DynamicPDF; using ceTe.DynamicPDF.Text; using PDFGenerator; using PDFGenerator.BusinessLayer; using PDFGenerator.BusinessLayer.DataSection; using PDFGenerator.Presentation.Section.Charts; using PDFGenerator.Presentation.Section; public class S85 : ISezione { string Titolo = " "; int Resolution = 300; private bool _IncludiScenarioMedio; private string _testointroduttivo = ""; public string TestoIntroduttivo { get { return _testointroduttivo; } set { _testointroduttivo = value; } } public S85() { // // TODO: Add constructor logic here // } #region ISezione Members /// /// Recupera il massimo valore dell'arraylist /// /// /// public static object GetMaxValue(ArrayList arrList) { ArrayList sortArrayList = arrList; sortArrayList.Sort(); sortArrayList.Reverse(); return sortArrayList[0]; } /// /// Recupera il minimo valore dell'arraylist /// /// /// public static object GetMinValue(ArrayList arrList) { ArrayList sortArrayList = arrList; sortArrayList.Sort(); return sortArrayList[0]; } public void writeSezione(DataThread dataThread) { DocumentPDF document = dataThread.DocumentPDF; DataSetS85 set = (DataSetS85)dataThread.Data.DatiSezione; int ChartHeigth = 200; //eventuali operazioni sul dataset //calcola se entra nella pagina altrimenti aggiunge una nuova pagina. In questa sezione il # di righe è fissato //if (document.checkMargin(ChartHeigth + 50)) // //if (document.checkMargin(ChartHeigth + 100)) // document.addPage(); document.setLastPos((document.getLastPos()*-1)+410); ceTe.DynamicPDF.Merger.ImportedPage page = document.getCurrentPage(); //page.Elements.Add(new ceTe.DynamicPDF.PageElements.Label("Possibile evoluzione del rendimento", document.getMargineLeft(), document.getLastPos() - 30, 500, 12, Globals.OpenTypeFontVerdanaB, 12, ceTe.DynamicPDF.CmykColor.Black)); document.setTitolo(Titolo); document.setHeaderSpace(5); //document.setChapterHeader(_testointroduttivo); document.setChapterHeader(_testointroduttivo, 0, 520, 8); #region Valori Asse Y //Impostare l’asse delle ordinate in funzione del valore massimo e minimo // rappresentati nel grafico (tra i valori del cono e il valore del rendimento) DataTable dtDati = new DataTable(); DataTable dtGrafico = new DataTable(); DataTable dtRendimento = new DataTable(); dtGrafico = set.Tables["DatiGrafico"].Copy(); dtRendimento = set.Tables["Rendimento"]; dtGrafico.Merge(dtRendimento, true); DataView dwValoriY = new DataView(dtGrafico); dtDati = dwValoriY.ToTable(false, "Ottimistico", "Pessimistico", "Valore"); // in un arraylist che poi andrò ad ordinare per recuperare massimo e minimo inserisco tutti valore delle 3 colonne // "Ottimistico", "Pessimistico", "Valore" ArrayList al = new ArrayList(); // MODIFICA TORRESI /* foreach (DataRow r in dtDati.Rows) foreach (DataColumn c in dtDati.Columns) { if (r[c].ToString() != string.Empty) al.Add(Convert.ToDouble(r[c].ToString())); } */ foreach (DataColumn c in dtDati.Columns) { foreach (DataRow r in dtDati.Rows) if ((r[c].ToString() != string.Empty) && (r[c].ToString() != "")) al.Add(Convert.ToDouble(r[c].ToString())); } //FINE MODIFICA TORRESI #endregion DatiGrafico dati = new DatiGrafico(); dati.dataTab = set.Tables["DatiGrafico"]; dati.setHeight(ChartHeigth); dati.setWidth(440); LineeRendimentoCumulato grafico = new LineeRendimentoCumulato(); grafico.MaximumY = Convert.ToDouble(GetMaxValue(al)); grafico.MinimumY = Convert.ToDouble(GetMinValue(al)); if (set.Tables["Rendimento"].Rows.Count > 0) { if (set.Tables["Rendimento"].Rows[0]["Data"] != DBNull.Value) grafico.DataRendimento = (DateTime)set.Tables["Rendimento"].Rows[0]["Data"]; if (set.Tables["Rendimento"].Rows[0]["Valore"] != DBNull.Value) grafico.Rendimento = Convert.ToDouble(set.Tables["Rendimento"].Rows[0]["Valore"]); } grafico.IncludiScenarioMedio = false; document.InsertGrafico(grafico.getGrafico(dati), 70, document.getLastPos(), Resolution); // Disegno il rettangolo grigio( footer del grafico) page.Elements.Add(new ceTe.DynamicPDF.PageElements.Rectangle(100, document.getLastPos() - 2 + ChartHeigth, 410, 23, 0, new RgbColor(232, 236, 237))); FormatNum format = new FormatNum(); DataTable datiAsse = set.Tables["DatiAsse"]; if (datiAsse.Rows.Count > 0) { ArrayList labels = format.CreaCustomDataTime(Convert.ToDateTime(datiAsse.Rows[0]["DataInizio"]), Convert.ToInt32(datiAsse.Rows[0]["IntervalloMesi"])); float startX = getX(Convert.ToInt32(datiAsse.Rows[0]["IntervalloMesi"])) - 15; float endX = 489; // punto fisso 489. float intervallo = (endX - startX) / (labels.Count - 1); int indiceLabel = 0; foreach (string label in labels) { page.Elements.Add(new ceTe.DynamicPDF.PageElements.Label(labels[indiceLabel].ToString(), startX, document.getLastPos() + ChartHeigth, 420, 10, Globals.OpenTypeFontVerdana, 7, ceTe.DynamicPDF.TextAlign.Left, ceTe.DynamicPDF.CmykColor.Black)); startX += intervallo; indiceLabel += 1; } } ceTe.DynamicPDF.PageElements.Rectangle rect = new ceTe.DynamicPDF.PageElements.Rectangle(document.getMargineLeft() + 95, document.getLastPos() + ChartHeigth + 13, 10, 2, 0, new RgbColor(0, 0, 255)); page.Elements.Add(rect); page.Elements.Add(new ceTe.DynamicPDF.PageElements.Label("Scenario ottimistico", document.getMargineLeft() + 110, document.getLastPos() + ChartHeigth + 8, 120, 10, Globals.OpenTypeFontVerdana, 9)); rect = new ceTe.DynamicPDF.PageElements.Rectangle(document.getMargineLeft() + 225, document.getLastPos() + ChartHeigth + 10, 5, 5, 0, new RgbColor(0, 0, 0)); rect.CornerRadius = 2.5F; page.Elements.Add(rect); //to tutaj page.Elements.Add(new ceTe.DynamicPDF.PageElements.Label("Rendimento cumulato", document.getMargineLeft() + 235, document.getLastPos() + ChartHeigth + 8, 120, 10, Globals.OpenTypeFontVerdana, 9)); rect = new ceTe.DynamicPDF.PageElements.Rectangle(document.getMargineLeft() + 345, document.getLastPos() + ChartHeigth + 13, 10, 2, 0, new RgbColor(239, 65, 53)); page.Elements.Add(rect); page.Elements.Add(new ceTe.DynamicPDF.PageElements.Label("Scenario pessimistico", document.getMargineLeft() + 360, document.getLastPos() + ChartHeigth + 8, 120, 10, Globals.OpenTypeFontVerdana, 9)); document.setLastPos(ChartHeigth + 40); dataThread.UltimaSezioneStampata = "S85"; } /// /// Ritorna la x su cui scrivere la prima etichetta dell'asse x. /// /// /// /// private float getX(int intervallomesi) { decimal massimo = 360; decimal xPartenza = 133; decimal xFine = xPartenza + 23; decimal intervallo = xFine - xPartenza; decimal rapporto = intervallo / massimo; return Convert.ToSingle(xFine - (rapporto * intervallomesi)); } public void setTitolo(string label) { Titolo = label; } public bool IncludiScenarioMedio { get { return _IncludiScenarioMedio; } set { _IncludiScenarioMedio = value; } } #endregion }