392 lines
17 KiB
C#
392 lines
17 KiB
C#
using System;
|
|
using System.Data;
|
|
using System.Configuration;
|
|
using System.Drawing;
|
|
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 Dundas.Charting.WebControl;
|
|
using Font = System.Drawing.Font;
|
|
using PDFGenerator.BusinessLayer;
|
|
using PDFGenerator;
|
|
using PDFGenerator.BusinessLayer.DataSection;
|
|
using PDFGenerator.Presentation.Section.Tables;
|
|
using PDFGenerator.Presentation.Section.Charts;
|
|
using PDFGenerator.Presentation.Section;
|
|
using ContrattoSei.Utilities;
|
|
|
|
|
|
public class S84 : ISezione
|
|
{
|
|
|
|
#region ISezione Members
|
|
|
|
string Titolo = " ";
|
|
int Resolution = 300;
|
|
private string _testointroduttivo = "";
|
|
|
|
public string TestoIntroduttivo
|
|
{
|
|
get
|
|
{
|
|
return _testointroduttivo;
|
|
}
|
|
set
|
|
{
|
|
_testointroduttivo = value;
|
|
}
|
|
}
|
|
|
|
public void setTitolo (string label)
|
|
{
|
|
Titolo = label;
|
|
}
|
|
|
|
public void writeSezione (DataThread dataThread)
|
|
{
|
|
DocumentPDF document = dataThread.DocumentPDF;
|
|
DataSetS84 set = (DataSetS84)dataThread.Data.DatiSezione;
|
|
DatiTabella datitab = new DatiTabella();
|
|
CombinationChart graficoCombinato = new CombinationChart(500, 200, Resolution);
|
|
|
|
//setta la datatable che contiene i Dati per disegnare la tabella
|
|
datitab.table = set.Tables["DatiGrafico"];
|
|
|
|
DateTime inizio = Convert.ToDateTime(datitab.table.Rows[0]["Data"]);
|
|
DateTime fine = Convert.ToDateTime(datitab.table.Rows[datitab.table.Rows.Count - 1]["Data"]); ;
|
|
TimeSpan differenza = fine.Subtract(inizio);
|
|
|
|
//calcola se entra nella pagina altrimenti aggiunge una nuova pagina. In questa sezione il # di righe è fissato
|
|
//if (document.checkMargin((float)(graficoCombinato.Height.Value + 50)))
|
|
if (document.checkMargin((float)(graficoCombinato.Height.Value - 100)))
|
|
document.addPage();
|
|
|
|
double totaleGiorni = fine.Subtract(inizio).TotalDays;
|
|
document.setTitolo(Titolo);
|
|
document.setChapterHeader(_testointroduttivo);
|
|
|
|
// associo il documento pdf corrente al grafico
|
|
graficoCombinato.DocumentPDF = document;
|
|
graficoCombinato.PositionX = (int)document.getMargineLeft();
|
|
//V Sforamento del footer nel caso di nota sulla S83
|
|
//graficoCombinato.PositionY = (int)(document.getLastPos());
|
|
graficoCombinato.PositionY = (int)(document.getLastPos()) - 15;
|
|
|
|
graficoCombinato.TabIndex = 10;
|
|
graficoCombinato.BorderLineWidth = 0;
|
|
|
|
#region Settaggio della ChartArea
|
|
//imposto la chart area
|
|
ChartArea ChartArea = new ChartArea();
|
|
// Settaggi dell'area del grafico
|
|
|
|
#region Generale
|
|
ChartArea.Name = "Default";
|
|
ChartArea.Area3DStyle.WallWidth = 0;
|
|
ChartArea.BackColor = System.Drawing.Color.FromArgb(255, 255, 255);
|
|
ChartArea.BorderColor = System.Drawing.Color.Empty;
|
|
ChartArea.BorderWidth = 0;
|
|
|
|
#endregion
|
|
|
|
#region AsseX
|
|
ChartArea.AxisX.LabelsAutoFit = false;
|
|
ChartArea.AxisX.Margin = false;
|
|
ChartArea.AxisX.MinorGrid.Enabled = false;
|
|
ChartArea.AxisX.MajorGrid.Enabled = false;
|
|
ChartArea.AxisX.MinorTickMark.Enabled = false;
|
|
//ChartArea.AxisX.MinorTickMark.Size = 2F;
|
|
ChartArea.AxisX.LabelStyle.Enabled = true;
|
|
//ChartArea.AxisX.LabelStyle.FontAngle = 90;
|
|
//ChartArea.AxisX.LabelStyle.ShowEndLabels = false; // mostra le label per il primo e per l'ultimo valore sull'asse X
|
|
ChartArea.AxisX.LabelStyle.Font = new Font("verdana", 5);
|
|
ChartArea.AxisX.IntervalType = DateTimeIntervalType.Days;
|
|
ChartArea.AxisX.LabelStyle.Format = "d";
|
|
ChartArea.AxisX.Minimum = inizio.AddDays(-differenza.TotalDays / 200).ToOADate();
|
|
ChartArea.AxisX.Maximum = fine.AddDays(differenza.TotalDays / 100).ToOADate();
|
|
|
|
|
|
if (totaleGiorni < 10)
|
|
ChartArea.AxisX.Interval = 1;
|
|
else
|
|
ChartArea.AxisX.Interval = differenza.TotalDays / 6;
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
#region AsseY
|
|
ChartArea.AxisY.Margin = false;
|
|
ChartArea.AxisY.LabelsAutoFit = false;
|
|
ChartArea.AxisY.MinorGrid.Enabled = false;//
|
|
ChartArea.AxisY.MajorGrid.LineColor = System.Drawing.Color.Gray;
|
|
ChartArea.AxisY.MajorGrid.LineStyle = ChartDashStyle.Dash;
|
|
ChartArea.AxisY.MajorGrid.Enabled = true;
|
|
ChartArea.AxisY.MinorTickMark.Size = 2F;
|
|
ChartArea.AxisY.LabelStyle.Format = "C";
|
|
ChartArea.AxisY.LabelStyle.Font = new Font("verdana", 6F);
|
|
|
|
//imposto i valori massimi dell'asse Y a seconda del controvalore massimo + 10%
|
|
|
|
//recupero il controvalore massimo che è il massimo tra il campo "Controvalore" e "RisorseAssociate"
|
|
decimal valMAxControvalore;
|
|
decimal maxControvalore = Convert.ToDecimal(datitab.table.Compute("Max(Controvalore)", string.Empty));
|
|
decimal maxRisorseAssociate = Convert.ToDecimal(datitab.table.Compute("Max(RisorseAssociate)", string.Empty));
|
|
|
|
if (maxControvalore < maxRisorseAssociate)
|
|
valMAxControvalore = maxRisorseAssociate;
|
|
else
|
|
valMAxControvalore = maxControvalore;
|
|
|
|
|
|
//recupero il controvalore minimo che è il minimo tra il campo "Controvalore" e "RisorseAssociate"
|
|
decimal valMinControvalore;
|
|
decimal minControvalore = Convert.ToDecimal(datitab.table.Compute("Min(Controvalore)", string.Empty));
|
|
decimal minRisorseAssociate = Convert.ToDecimal(datitab.table.Compute("Min(RisorseAssociate)", string.Empty));
|
|
|
|
if (minControvalore < minRisorseAssociate)
|
|
valMinControvalore = minControvalore;
|
|
else
|
|
valMinControvalore = minRisorseAssociate;
|
|
|
|
valMAxControvalore = Math.Ceiling(valMAxControvalore);
|
|
valMinControvalore = Math.Ceiling(valMinControvalore);
|
|
//aggiungo 10%
|
|
decimal valorepercentuale;
|
|
valorepercentuale = (valMAxControvalore/100)*10;
|
|
|
|
double valMaxAsseY = (double)valMAxControvalore + (double)valorepercentuale;
|
|
|
|
if (valMaxAsseY <= 0)
|
|
valMaxAsseY = 10;
|
|
else
|
|
valMaxAsseY = LibFunction.ArrotondaAxis(valMaxAsseY, LibFunction.tipoArrotondamento.eccesso);
|
|
|
|
double valMinAsseY;
|
|
|
|
if (((double)valMinControvalore - (double)valorepercentuale) < 0)
|
|
{
|
|
valMinAsseY = 0;
|
|
}
|
|
else
|
|
{
|
|
valMinAsseY = LibFunction.ArrotondaAxis((double)valMinControvalore - (double)valorepercentuale, LibFunction.tipoArrotondamento.difetto);
|
|
// dato che non può essere negativa viene arrotondata per difetto altrimenti si sarebbe dovuto arrotondare per eccesso
|
|
//ChartArea.AxisY.Minimum = LibFunction.ArrotondaAxis(valMinAsseY, LibFunction.tipoArrotondamento.eccesso);
|
|
}
|
|
|
|
|
|
int numeroIntervalli = 6;
|
|
|
|
// Imposto l'intervallo sull'asse Y
|
|
double intervallo = LibFunction.ArrotondaAxis((valMaxAsseY - valMinAsseY) / numeroIntervalli, LibFunction.tipoArrotondamento.eccesso);
|
|
|
|
if (intervallo == 0)
|
|
{
|
|
valMaxAsseY = valMaxAsseY * 1.1;
|
|
intervallo = LibFunction.ArrotondaAxis((valMaxAsseY - valMinAsseY) / numeroIntervalli, LibFunction.tipoArrotondamento.eccesso);
|
|
}
|
|
|
|
|
|
ChartArea.AxisY.Maximum = valMinAsseY + (intervallo * numeroIntervalli);
|
|
ChartArea.AxisY.Minimum = valMinAsseY;
|
|
ChartArea.AxisY.Interval = intervallo;
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
// associazione della ChartArea
|
|
graficoCombinato.Area = ChartArea;
|
|
|
|
#region Settaggio delle Series
|
|
|
|
#region Settaggio dei dati asse X
|
|
|
|
|
|
|
|
// imposto i dati
|
|
// override dei dati...
|
|
|
|
DataTable dtDati = datitab.table.Clone();
|
|
dtDati.TableName = "DatiGrafico";
|
|
dtDati.Columns.Add("RilevazioneEffettiva", typeof (Int16));
|
|
|
|
|
|
|
|
|
|
DateTime data= inizio;
|
|
//double intevalloData= differenza.TotalDays / 10;
|
|
double intevalloData= 1;
|
|
DataRow drUltima = null;
|
|
for (int i = 0; i <= totaleGiorni; i++)
|
|
{
|
|
|
|
string strData = data.ToShortDateString();
|
|
// controllo se la data è presente nel datatable di origine
|
|
DataRow[] drResult= datitab.table.Select(" data = '" + strData.Replace("'", "''") + "'");
|
|
|
|
if (drResult.Length > 0)
|
|
{
|
|
drUltima = drResult[0];
|
|
DataRow newRow = dtDati.NewRow();
|
|
newRow["Controvalore"] = drResult[0]["Controvalore"];
|
|
newRow["RisorseAssociate"] = drResult[0]["RisorseAssociate"];
|
|
newRow["Data"] = drResult[0]["Data"];
|
|
newRow["Need_Area"] = drResult[0]["Need_Area"];
|
|
newRow["NomeProgetto"] = drResult[0]["NomeProgetto"];
|
|
newRow["RilevazioneEffettiva"] = 1;
|
|
dtDati.Rows.Add(newRow);
|
|
}
|
|
else
|
|
{
|
|
DataRow newRow = dtDati.NewRow();
|
|
newRow["Controvalore"] = drUltima["Controvalore"];
|
|
newRow["RisorseAssociate"] = drUltima["RisorseAssociate"];
|
|
newRow["Data"] = Convert.ToDateTime(strData);
|
|
newRow["Need_Area"] = drUltima["Need_Area"];
|
|
newRow["NomeProgetto"] = drUltima["NomeProgetto"];
|
|
newRow["RilevazioneEffettiva"] = 0;
|
|
dtDati.Rows.Add(newRow);
|
|
}
|
|
data = data.AddDays(intevalloData);
|
|
}
|
|
|
|
//setFattoreMoltiplicativo(dtDati); // Con la versione di grafico "StepLine" la funzione non dev piu esser richiamata.
|
|
|
|
graficoCombinato.Datasource = dtDati;
|
|
|
|
|
|
#endregion
|
|
|
|
ArrayList objSeries = new ArrayList(); // arraylist contenitore Series
|
|
|
|
//aggiungo la serie Risorse Apportate
|
|
Series sRisorseApportate = new Series("Risorse apportate");
|
|
sRisorseApportate.Color = System.Drawing.Color.Aquamarine;
|
|
sRisorseApportate.Type = SeriesChartType.StackedColumn;
|
|
sRisorseApportate.SetAttribute("AxisXColumnName", "Data");
|
|
sRisorseApportate.SetAttribute("AxisYColumnName", "RisorseAssociate");
|
|
objSeries.Add(sRisorseApportate);
|
|
|
|
//aggiungo la serie ControvaloreMonitorato
|
|
Series sControvaloreMonitorato = new Series("Controvalore monitorato");
|
|
sControvaloreMonitorato.Color = System.Drawing.Color.Blue;
|
|
sControvaloreMonitorato.Type = SeriesChartType.StepLine;
|
|
sControvaloreMonitorato.SetAttribute("AxisXColumnName", "Data");
|
|
sControvaloreMonitorato.SetAttribute("AxisYColumnName", "Controvalore");
|
|
//V
|
|
sControvaloreMonitorato.BorderWidth = 3;
|
|
|
|
//sControvaloreMonitorato.MarkerBorderWidth = 100;
|
|
//sControvaloreMonitorato.MarkerStep = 100;
|
|
|
|
|
|
objSeries.Add(sControvaloreMonitorato);
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
// Aggiungo tutte le serie alla proprietà esposta dal grafico
|
|
graficoCombinato.ChartSeries = objSeries;
|
|
|
|
//graficoCombinato.ColumnWidth = 1;
|
|
graficoCombinato.ShowValueInChart = false;
|
|
|
|
//Khorne (added)
|
|
//disabilito la legenda generata dal grafico, per riscriverla manualmente.
|
|
graficoCombinato.ChartLegend.Enabled = false;
|
|
//Khorne end
|
|
|
|
//Commented By Bido 8 March 2011
|
|
////Imposto la Leggenda
|
|
//graficoCombinato.ChartLegend.LegendStyle = LegendStyle.Row;
|
|
//graficoCombinato.ChartLegend.Docking = LegendDocking.Bottom;
|
|
//graficoCombinato.ChartLegend.Alignment = StringAlignment.Center;
|
|
|
|
// Disegno
|
|
graficoCombinato.Draw();
|
|
|
|
//New Bido Work 9 March 2011
|
|
System.Reflection.Assembly thisExe;
|
|
thisExe = System.Reflection.Assembly.GetExecutingAssembly();
|
|
System.IO.Stream fileImmagineA = thisExe.GetManifestResourceStream(UtilityManager.getAppSetting("ImmagineA_S83"));
|
|
System.IO.Stream fileImmagineB = thisExe.GetManifestResourceStream(UtilityManager.getAppSetting("ImmagineB_S83"));
|
|
System.IO.Stream fileImmagineC = thisExe.GetManifestResourceStream(UtilityManager.getAppSetting("ImmagineC_S83"));
|
|
|
|
ceTe.DynamicPDF.Merger.ImportedPage page = document.getCurrentPage();
|
|
int deltaY = -3;
|
|
//Khorne (added)
|
|
page.Elements.Add(new ceTe.DynamicPDF.PageElements.Rectangle(document.getMargineLeft() + 95, document.getLastPos() + 185 + deltaY, 15, 1
|
|
, new ceTe.DynamicPDF.RgbColor(System.Drawing.Color.Blue.R, System.Drawing.Color.Blue.G, System.Drawing.Color.Blue.B)
|
|
, new ceTe.DynamicPDF.RgbColor(System.Drawing.Color.Blue.R, System.Drawing.Color.Blue.G, System.Drawing.Color.Blue.B)));
|
|
|
|
page.Elements.Add(new ceTe.DynamicPDF.PageElements.Label("Controvalore monitorato", document.getMargineLeft() + 115, document.getLastPos() + 180 + deltaY, 512, 12, Globals.OpenTypeFontVerdana, 9));
|
|
|
|
page.Elements.Add(new ceTe.DynamicPDF.PageElements.Image(fileImmagineA, document.getMargineLeft() + 230, document.getLastPos() + 180 + deltaY, 0.15F));
|
|
|
|
page.Elements.Add(new ceTe.DynamicPDF.PageElements.Rectangle(document.getMargineLeft() + 270, document.getLastPos() + 185 + deltaY, 15, 1
|
|
, new ceTe.DynamicPDF.RgbColor(System.Drawing.Color.Aquamarine.R, System.Drawing.Color.Aquamarine.G, System.Drawing.Color.Aquamarine.B)
|
|
, new ceTe.DynamicPDF.RgbColor(System.Drawing.Color.Aquamarine.R, System.Drawing.Color.Aquamarine.G, System.Drawing.Color.Aquamarine.B)));
|
|
|
|
page.Elements.Add(new ceTe.DynamicPDF.PageElements.Label("Risorse apportate", document.getMargineLeft() + 290, document.getLastPos() + 180 + deltaY, 512, 12, Globals.OpenTypeFontVerdana, 9));
|
|
|
|
page.Elements.Add(new ceTe.DynamicPDF.PageElements.Image(fileImmagineB, document.getMargineLeft() + 380, document.getLastPos() + 180 + deltaY, 0.15F));
|
|
page.Elements.Add(new ceTe.DynamicPDF.PageElements.Rectangle(document.getMargineLeft() + 396, document.getLastPos() + 185, 5, 1, ceTe.DynamicPDF.CmykColor.Black, ceTe.DynamicPDF.CmykColor.Black));
|
|
page.Elements.Add(new ceTe.DynamicPDF.PageElements.Image(fileImmagineC, document.getMargineLeft() + 407, document.getLastPos() + 180 + deltaY, 0.15F));
|
|
//Khorne end
|
|
|
|
//End Of Bido Work 9 March 2011
|
|
|
|
////aggiorno il puntatore alla posizione da cui si può scrivere
|
|
float heightChart = (float)graficoCombinato.Height.Value;
|
|
document.setLastPos(heightChart);
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Funzione utilizzata per la vecchia versione del grafico che prevedeva una tipo di grafico "Line" anziché "StepLine".
|
|
/// Con la nuova versione "StepLine" la funzione non serve più.
|
|
/// Mantengo in cao di cambio specifiche.
|
|
/// </summary>
|
|
/// <param name="dataTable"></param>
|
|
private void setFattoreMoltiplicativo(DataTable dataTable)
|
|
{
|
|
DataRow[] righeIndici = dataTable.Select(" RilevazioneEffettiva = 1");
|
|
int indiceInizio = 0;
|
|
int indiceFine = 0;
|
|
int numIntervalli = 0;
|
|
decimal ctvInizio = 0;
|
|
decimal ctvFine = 0;
|
|
decimal fattoreMoltiplicativo = 0;
|
|
for (int i = 0; i < righeIndici.Length; i++)
|
|
{
|
|
if ((i + 1) < righeIndici.Length)
|
|
{
|
|
indiceInizio = (int) dataTable.Rows.IndexOf((DataRow) righeIndici[i]);
|
|
indiceFine = (int) dataTable.Rows.IndexOf((DataRow) righeIndici[i + 1]);
|
|
if (indiceInizio + 1 < indiceFine)
|
|
{
|
|
ctvInizio = (decimal) dataTable.Rows[indiceInizio]["Controvalore"];
|
|
ctvFine = (decimal) dataTable.Rows[indiceFine]["Controvalore"];
|
|
numIntervalli = indiceFine - indiceInizio;
|
|
fattoreMoltiplicativo = (ctvFine - ctvInizio)/numIntervalli;
|
|
for (int j = indiceInizio + 1; j < indiceFine; j++)
|
|
{
|
|
//ctv per ogni riga
|
|
dataTable.Rows[j]["Controvalore"] = (decimal) dataTable.Rows[j - 1]["Controvalore"] + fattoreMoltiplicativo;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
}
|