using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Windows.Forms;
using System.Drawing;
using System.Data;
using FastReport;
using FastReport.Data;
using FastReport.Dialog;
using FastReport.Barcode;
using FastReport.Table;
using FastReport.Utils;
namespace FastReport
{
public class ReportScript
{
private string[] hetek;
private int bontas;
private Dictionary<string, int> groupCounts = new Dictionary<string, int>();
int groupId = 0;
int oldalId = 0;
private void NemKotott(object sender, EventArgs e)
{
bontas = int.Parse(Report.Parameters.FindByName("bontas").Value.ToString());
if (bontas == 0)
{
Page1.Landscape = true;
}
DataSourceBase pedagogusAlapadatok = Report.GetDataSource("Fejlec");
Data1.DataSource = pedagogusAlapadatok;
pedagogusAlapadatok.Init();
if (bontas != 2)
{
DataSourceBase hetekDS = Report.GetDataSource("Hetek");
hetekDS.Init();
hetek = new string[hetekDS.RowCount];
int i = 0;
while(hetekDS.HasMoreRows)
{
hetek[i] = string.Format("{0} - {1}", ((DateTime)((DataRow)hetekDS.CurrentRow)["KezdoNap"]).ToString("dd"), ((DateTime)((DataRow)hetekDS.CurrentRow)["UtolsoNap"]).ToString("dd"));
i++;
hetekDS.Next();
}
}
else
{
DataSourceBase hetekDS = Report.GetDataSource("EvHonapok");
hetekDS.Init();
hetek = new string[hetekDS.RowCount];
int i = 0;
while(hetekDS.HasMoreRows)
{
hetek[i] = ((DataRow)hetekDS.CurrentRow)[0].ToString().Substring(5);
i++;
hetekDS.Next();
}
Cell769.Text = "<b><!Fejlec.TanarNev!></b> - <!Fejlec.Tanev!>. tanév";
Cell1192.Text = "<b><!Fejlec.TanarNev!></b> - <!Fejlec.Tanev!>. tanév";
}
DataSourceBase mindenDS = Report.GetDataSource("Minden");
Data5.DataSource = mindenDS;
Relation rel200 = new Relation();
rel200.Name = "mindenPedagogusRel";
rel200.ParentDataSource = pedagogusAlapadatok;
rel200.ChildDataSource = mindenDS;
rel200.ParentColumns = new string[] { "pedagogusId" };
rel200.ChildColumns = new string[] { "pedagogusId" };
Report.Dictionary.Relations.Add(rel200);
mindenDS.Init(pedagogusAlapadatok);
DataSourceBase tuloraDS = Report.GetDataSource("Tulora");
Data2.DataSource = tuloraDS;
Relation rel201 = new Relation();
rel201.Name = "TuloraPedagogusRel";
rel201.ParentDataSource = pedagogusAlapadatok;
rel201.ChildDataSource = tuloraDS;
rel201.ParentColumns = new string[] { "pedagogusId" };
rel201.ChildColumns = new string[] { "pedagogusId" };
Report.Dictionary.Relations.Add(rel201);
tuloraDS.Init(pedagogusAlapadatok);
DataSourceBase parhuzamosoraDS = Report.GetDataSource("Parhuzamosorak");
DataParhuzamosOrak.DataSource = parhuzamosoraDS;
Relation rel202 = new Relation();
rel202.Name = "ParhuzamosoraPedagogusRel";
rel202.ParentDataSource = pedagogusAlapadatok;
rel202.ChildDataSource = parhuzamosoraDS;
rel202.ParentColumns = new string[] { "pedagogusId" };
rel202.ChildColumns = new string[] { "pedagogusId" };
Report.Dictionary.Relations.Add(rel202);
parhuzamosoraDS.Init(pedagogusAlapadatok);
DataSourceBase KumulaltHelyettesitesDS = Report.GetDataSource("KumulaltHelyettesites");
DataKumulaltHelyettesites.DataSource = KumulaltHelyettesitesDS;
Relation reltkh = new Relation();
reltkh.Name = "KumulativHelyettesitesRel";
reltkh.ParentDataSource = pedagogusAlapadatok;
reltkh.ChildDataSource = KumulaltHelyettesitesDS;
reltkh.ParentColumns = new string[] { "pedagogusId" };
reltkh.ChildColumns = new string[] { "pedagogusId" };
Report.Dictionary.Relations.Add(reltkh);
KumulaltHelyettesitesDS.Init(pedagogusAlapadatok);
}
private void GroupHeader1_BeforePrint(object sender, EventArgs e)
{
if(Engine.FinalPass)
{
oldalId++;
Cell1191.Text = oldalId.ToString() + "/[TotalPages#]. oldal";
if (oldalId == 1) {
Cell1192.TextColor = Color.Transparent;
}
else {
Cell1192.TextColor = Color.Black;
}
}
}
private void OsszesitoTabla_BeforePrint(object sender, EventArgs e)
{
if (Engine.FinalPass)
{
TableObject table = sender as TableObject;
float pageWidth = Engine.PageWidth;
switch (bontas)
{
case 1:
case 2:
if (table.Name.Contains("KumulaltHelyettesites"))
{
return;
}
int maxOszlop = table.ColumnCount - 2;
for (int i = hetek.Length; i < maxOszlop; i++)
{
table.Columns.RemoveAt(hetek.Length + 1);
}
float tableWidth = table.Width;
table.Columns[0].Width *= 4;
float minus = table.Columns[0].Width + table.Columns[table.ColumnCount - 1].Width;
float colWidth = (pageWidth - minus) / hetek.Length;
for (int i = 1; i < table.ColumnCount - 1; i++)
{
table.Columns[i].AutoSize = false;
table.Columns[i].Width = colWidth;
}
break;
default:
if (!table.Name.Contains("KumulaltHelyettesites"))
{
table.Columns[0].AutoSize = false;
table.Columns[0].Width += (Engine.PageWidth - table.Width)-1;
}
else
{
table.Columns[0].Width *= 2;
minus = table.Columns[0].Width + table.Columns[table.ColumnCount - 1].Width;
colWidth = (pageWidth - minus) / 12;
for (int i = 1; i < table.ColumnCount - 1; i++)
{
table.Columns[i].AutoSize = false;
table.Columns[i].Width = colWidth;
}
}
return;
}
ObjectCollection cells = table.Rows[0].ChildObjects;
if (table.RowCount > 1)
{
cells = table.Rows[1].ChildObjects;
}
for (int i = 0; i < hetek.Length; i++)
{
TableCell cell = (TableCell)cells[i + 1];
if ((table == TableTevekenysegHeader)
|| (table == TableJogviszonyHeader)
|| (table == TableTuloraHeader)
|| (table == TableParhuzamosOrakHeader))
{
cell.Text = hetek[i];
cell.HorzAlign = HorzAlign.Center;
}
cell.Angle = 0;
}
}
}
private void HeaderTable_BeforePrint(object sender, EventArgs e)
{
if (Engine.FinalPass)
{
TableObject table = sender as TableObject;
switch (bontas)
{
case 0:
float szum = 0f;
float tableWidth = table.Width;
float novekmeny = (Engine.PageWidth - tableWidth);
for (int i = 0; i < table.ColumnCount; i++)
{
table.Columns[i].AutoSize = false;
if (i < table.ColumnCount -1)
{
table.Columns[i].Width += ((table.Columns[i].Width / tableWidth) * novekmeny);
szum += table.Columns[i].Width;
}
else
{
table.Columns[i].Width = (Engine.PageWidth - szum);
}
}
break;
default:
break;
}
}
}
private string GetKey()
{
return string.Format("{0}{1}", Report.GetColumnValue("Minden.pedagogusId"), Report.GetColumnValue("Minden.IsFelnottoktatas"));
}
private void GroupFooter6_BeforePrint(object sender, EventArgs e)
{
if (Engine.FinalPass)
{
string key = GetKey();
if (groupCounts[key] == 1)
{
((GroupFooterBand)sender).Bounds = new Rectangle(-10000, -10000, 0, 0);
}
}
}
private void GroupHeader11_BeforePrint(object sender, EventArgs e)
{
string key = GetKey();
if (Engine.FirstPass)
{
groupCounts.Add(key, 0);
}
if (Engine.FinalPass)
{
if (groupCounts[key] == 1)
{
((GroupHeaderBand)sender).Bounds = new Rectangle(-10000, -10000, 0, 0);
}
}
}
private void GroupHeader12_BeforePrint(object sender, EventArgs e)
{
if (Engine.FirstPass)
{
string key = GetKey();
groupCounts[key] = groupCounts[key] + 1;
}
}
private void Data4_AfterPrint(object sender, EventArgs e)
{
if(Engine.FinalPass)
{
groupId++;
}
}
}
}