Hi
I just made a small code pice to put in a row in a report. Just put the code in your report file and call it from your construter.
Sample 1: eks. "addEndRow("Hallo");
Sample 2. data is a array of string with lengh 6. addDataRow("1", "tekst_1", "tekst_2", new string[] { "x", "-", "-", "-", "-", "-" });
Sample 3: setData(@"c:\pic1.jpg", "This is fine"); // Put in a path for a foto.
Sample 4:
Sincerely,
Janus S. Andersen
I just made a small code pice to put in a row in a report. Just put the code in your report file and call it from your construter.
Sample 1: eks. "addEndRow("Hallo");
/// <summary> | |
/// Tilføjer den sidste række data til denne siden | |
/// </summary> | |
/// <param name="tekst">Den tekst der skal stå i rækken</param> | |
public void addEndRow(string tekst) | |
{ | |
if (tekst == null) // Undersøger om tekst er null hvis dette sættes tekst til en tom string | |
{ | |
tekst = ""; // Sætter tekst til en tom string | |
} | |
// Oprettelse af panel til indhold af tekstboks | |
var panel_1 = new Panel | |
{ | |
Size = | |
new SizeU( | |
new Unit(10.45, | |
((UnitType.Cm))), | |
new Unit(1, | |
((UnitType.Cm)))), | |
Dock = DockStyle.Left, | |
Style = { BorderStyle = { Default = BorderType.Solid } } | |
}; | |
// Oprettelse af tekstboks til indhold af tekst | |
var textBox_1 = new TextBox | |
{ | |
Value = tekst, | |
Dock = DockStyle.Top, | |
Style = | |
{ | |
TextAlign = HorizontalAlign.Left, | |
VerticalAlignVerticalAlign = VerticalAlign.Top | |
}, | |
Height = new Unit(1.5, UnitType.Cm), | |
Width = new Unit(1, UnitType.Cm), | |
}; | |
panel_1.Items.AddRange(new ReportItemBase[] { textBox_1 }); | |
panel_1.Dock = DockStyle.Top; | |
//Tilføjer panel til detail delen i rapporten | |
detail.Items.Add(panel_1); | |
} |
Sample 2. data is a array of string with lengh 6. addDataRow("1", "tekst_1", "tekst_2", new string[] { "x", "-", "-", "-", "-", "-" });
/// <summary> | |
/// Opretter en række til at indsætte data i | |
/// </summary> | |
/// <param name="nr">det nummer der skal stå i det første felt</param> | |
/// <param name="tekst_1">Den tekst der skal stå i den første række</param> | |
/// <param name="tekst_2">Den tekst der skal stå i den anden række</param> | |
/// <param name="data">Dette er et array med "X" eller " ". De tjekmark som skal anvendes</param> | |
public void addDataRow(string nr, string tekst_1, string tekst_2, string[] data) | |
{ | |
// Undersøger paremere for null | |
if (nr == null) | |
{ | |
nr = "<n/a>"; | |
} | |
if (tekst_1 == null) | |
{ | |
tekst_1 = "<n/a>"; | |
} | |
if (tekst_2 == null) | |
{ | |
tekst_2 = "<n/a>"; | |
} | |
if (data != null) | |
{ | |
if (data.Length != 6) | |
throw new Exception("Data længde på rapport forkert. Længde = " + data.Length + | |
", men skulle være 6. "); | |
} | |
else | |
{ | |
throw new Exception("data = null: fejl"); | |
} | |
// Oprettelse af paneler | |
var panel_1 = new Panel | |
{ | |
Size = | |
new SizeU( | |
new Unit(10.45, | |
((UnitType.Cm))), | |
new Unit(1, | |
((UnitType.Cm)))), | |
Dock = DockStyle.Left, | |
Style = { BorderStyle = { Default = BorderType.Solid } } | |
}; | |
var panel_2 = new Panel | |
{ | |
Dock = DockStyle.Left, | |
Style = { BorderStyle = { Left = BorderType.Solid } }, | |
Size = | |
new SizeU( | |
new Unit(10.446890830993652, | |
((UnitType.Cm))), | |
new Unit(1.5, | |
((UnitType.Cm)))) | |
}; | |
var panel_3 = new Panel | |
{ | |
Width = new Unit(3.5, UnitType.Cm), | |
Height = new Unit(1.5, UnitType.Cm), | |
Style = { BorderStyle = { Left = BorderType.Solid } }, | |
Dock = DockStyle.Right | |
}; | |
var panel_4 = new Panel { Dock = DockStyle.Right }; | |
// Oprettelse af tekstbokse | |
var textBox_1 = new TextBox | |
{ | |
Value = nr, | |
Dock = DockStyle.Left, | |
Style = | |
{ | |
TextAlign = HorizontalAlign.Center, | |
VerticalAlignVerticalAlign = VerticalAlign.Middle, | |
}, | |
Height = new Unit(1.5, UnitType.Cm), | |
Width = new Unit(1, UnitType.Cm) | |
}; | |
var textBox_2 = new TextBox | |
{ | |
Value = tekst_1, | |
Height = new Unit(0.5, UnitType.Cm), | |
Dock = DockStyle.Top, | |
Style = { BorderStyle = { Bottom = BorderType.Solid } } | |
}; | |
var textBox_3 = new TextBox | |
{ | |
Dock = DockStyle.Top, | |
Value = tekst_2, | |
Height = new Unit(0.5, UnitType.Cm) | |
}; | |
var textBox_4 = new TextBox | |
{ | |
Size = | |
new SizeU( | |
new Unit(0.5, | |
((UnitType.Cm))), | |
new Unit(1.5, | |
((UnitType.Cm)))), | |
Style = | |
{ | |
TextAlign = HorizontalAlign.Center, | |
VerticalAlignVerticalAlign = VerticalAlign.Middle, | |
BorderStyle = | |
{ | |
Left = BorderType.Solid, | |
Right = BorderType.Solid | |
} | |
}, | |
Value = data[2], | |
Dock = DockStyle.Right | |
}; | |
var textBox_5 = new TextBox | |
{ | |
Size = | |
new SizeU( | |
new Unit(0.5, | |
((UnitType.Cm))), | |
new Unit(1.5, | |
((UnitType.Cm)))), | |
Style = | |
{ | |
TextAlign = HorizontalAlign.Center, | |
VerticalAlignVerticalAlign = VerticalAlign.Middle, | |
BorderStyle = { Left = BorderType.Solid } | |
}, | |
Value = data[1], | |
Dock = DockStyle.Right | |
}; | |
var textBox_6 = new TextBox | |
{ | |
Size = | |
new SizeU( | |
new Unit(0.5, | |
((UnitType.Cm))), | |
new Unit(1.5, | |
((UnitType.Cm)))), | |
Style = | |
{ | |
TextAlign = HorizontalAlign.Center, | |
VerticalAlignVerticalAlign = VerticalAlign.Middle | |
}, | |
Value = data[0], | |
Dock = DockStyle.Right | |
}; | |
var textBox_7 = new TextBox | |
{ | |
Size = | |
new SizeU( | |
new Unit(0.5, | |
((UnitType.Cm))), | |
new Unit(1.5, | |
((UnitType.Cm)))), | |
Style = | |
{ | |
TextAlign = HorizontalAlign.Center, | |
VerticalAlignVerticalAlign = VerticalAlign.Middle, | |
BorderStyle = { Left = BorderType.Solid } | |
}, | |
Value = data[5], | |
Dock = DockStyle.Right | |
}; | |
var textBox_8 = new TextBox | |
{ | |
Size = | |
new SizeU( | |
new Unit(0.5, | |
((UnitType.Cm))), | |
new Unit(1.5, | |
((UnitType.Cm)))), | |
Style = | |
{ | |
TextAlign = HorizontalAlign.Center, | |
VerticalAlignVerticalAlign = VerticalAlign.Middle, | |
BorderStyle = { Left = BorderType.Solid } | |
}, | |
Value = data[4], | |
Dock = DockStyle.Right | |
}; | |
var textBox_9 = new TextBox | |
{ | |
Size = | |
new SizeU( | |
new Unit(0.5, | |
((UnitType.Cm))), | |
new Unit(1.5, | |
((UnitType.Cm)))), | |
Style = | |
{ | |
TextAlign = HorizontalAlign.Center, | |
VerticalAlignVerticalAlign = VerticalAlign.Middle, | |
BorderStyle = { Left = BorderType.Solid } | |
}, | |
Value = data[3], | |
Dock = DockStyle.Right | |
}; | |
panel_2.Items.AddRange(new ReportItemBase[] { textBox_2, textBox_3 }); // Indsætter tekstboks 1 og 2 i panel 2 | |
panel_4.Width = new Unit(0.5, UnitType.Cm); // Sætter bredden på panel 4 til 0.5 cm | |
panel_4.Height = new Unit(1, UnitType.Cm); // Sætter højden på panel 4 til 1 cm | |
panel_3.Items.AddRange(new ReportItemBase[] { textBox_7, textBox_8, textBox_9, panel_4, textBox_4, textBox_5, textBox_6 }); // Indsætter tekstbokse og panler i panel 3 | |
panel_1.Items.AddRange(new ReportItemBase[] { textBox_1, panel_2, panel_3 }); // Indsætter tekstbokse og paneler i panel1 | |
panel_1.Dock = DockStyle.Top; // Dockter panel 1 til top | |
if (detail != null) // Underøsger om detail sektionens objekt er null | |
{ | |
detail.Items.Add(panel_1); // Indsætter panel 1 i detail sektoinen som er det område som indeholder hoved- data i rapporten | |
} | |
} |
Sample 3: setData(@"c:\pic1.jpg", "This is fine"); // Put in a path for a foto.
/// <summary> | |
/// Sætter billed ind på siden | |
/// </summary> | |
/// <param name="filename">Sti til der hvor der ligger en billed fil</param> | |
/// <param name="text">Den firgur tekst der står under billedet</param> | |
/// <param name="s">Størrelse på billed</param> | |
public void setData(string filename, string text, params SizeU[] s) | |
{ | |
try | |
{ | |
if (!File.Exists(filename)) | |
{ | |
text += Environment.NewLine + "Filen blev ikke fundet (" + filename + ")"; | |
} | |
//Opretter tekstboks til at indeholde tekst der skal stå under hver billed | |
using (var textBox_1 = new TextBox | |
{ | |
Size = new SizeU(new Unit(2, UnitType.Cm), | |
new Unit(0.6, UnitType.Cm)), | |
Value = ("Figur " + figur_nr + ": " + text), | |
Dock = DockStyle.Top, | |
Multiline = true, | |
Style = {TextAlign = HorizontalAlign.Center} | |
}) | |
{ | |
using (var pictureBox_1 = new PictureBox | |
{ | |
Dock = DockStyle.Top, | |
Value = new Bitmap(filename), | |
Sizing = ImageSizeMode.ScaleProportional, | |
Size = new SizeU(Unit.Cm(10), Unit.Cm(10)) | |
}) | |
{ | |
detail.Items.Add(pictureBox_1); // Indsætter billed objekt | |
} | |
detail.Items.Add(textBox_1); // Indsætter tekst der står under billedet | |
} | |
figur_nr++; // Forøger figur_nr med en | |
} | |
catch (Exception ex) | |
{ | |
//Opretter tekstboks med fejlbesked i | |
var textBox_1 = new TextBox | |
{ | |
Size = | |
new SizeU( | |
new Unit(2.0000002384185791, UnitType.Cm), | |
new Unit(0.60000020265579224, UnitType.Cm)), | |
Value = | |
("Der opstod en fejl i indsættelse af billeder i PDF. Fejl:" + ex.Message), | |
Dock = DockStyle.Top, | |
Multiline = true, | |
Style = {TextAlign = HorizontalAlign.Center} | |
}; | |
detail.Items.Add(textBox_1); // Indsætter tekst fejlbeskrivelse | |
} | |
} |
Sample 4:
AddRow(
"Type", "Name", "Adress", "Phone number.:"); // Put in a Row. Call this metode to build op a page of rows with stuff
/// <summary> | |
/// Opretter en række med de personer som har medvirket til dette eftersyn | |
/// </summary> | |
/// <param name="str1">Faggruppebeskrivelse (type)</param> | |
/// <param name="str2">JuridiskNavn (navn mm.)</param> | |
/// <param name="str3">Adresse (Består af adr1 og adr2)</param> | |
/// <param name="str4">Telefonnummer. Det telefon nummer som anvendes til at kontakte denne person</param> | |
public void AddRow(string str1, string str2, string str3, string str4) | |
{ | |
if (str1 == null) | |
{ | |
str1 = ""; | |
} | |
if (str2 == null) | |
{ | |
str2 = ""; | |
} | |
if (str3 == null) | |
{ | |
str3 = ""; | |
} | |
if (str4 == null) | |
{ | |
str4 = ""; | |
} | |
// Oprettelse af paneler | |
var panel_1 = new Panel | |
{ | |
Size = | |
new SizeU( | |
new Unit(15, | |
((UnitType.Cm))), | |
new Unit(0.5, | |
((UnitType.Cm)))), | |
Dock = DockStyle.Right, | |
Style = { BorderStyle = { Default = BorderType.Solid } } | |
}; | |
var panel_3 = new Panel | |
{ | |
Width = new Unit(15, UnitType.Cm), | |
Height = new Unit(0.5, UnitType.Cm), | |
Style = { BorderStyle = { Left = BorderType.None } }, | |
Dock = DockStyle.Left | |
}; | |
var panel_4 = new Panel { Dock = DockStyle.Right }; | |
// Oprettelse af tekstbokse | |
var textBox_7 = new TextBox | |
{ | |
Size = | |
new SizeU( | |
new Unit(3.5, | |
((UnitType.Cm))), | |
new Unit(0.5, | |
((UnitType.Cm)))), | |
Style = | |
{ | |
TextAlign = HorizontalAlign.Left, | |
VerticalAlign = VerticalAlign.Middle, | |
BorderStyle = { Left = BorderType.Solid } | |
}, | |
Value = str1, | |
Dock = DockStyle.Left | |
}; | |
var textBox_8 = new TextBox | |
{ | |
Size = | |
new SizeU( | |
new Unit(3.5, | |
((UnitType.Cm))), | |
new Unit(0.5, | |
((UnitType.Cm)))), | |
Style = | |
{ | |
TextAlign = HorizontalAlign.Left, | |
VerticalAlign = VerticalAlign.Middle, | |
BorderStyle = { Left = BorderType.Solid } | |
}, | |
Value = str2, | |
Dock = DockStyle.Left | |
}; | |
var textBox_9 = new TextBox | |
{ | |
Size = | |
new SizeU( | |
new Unit(3.5, | |
((UnitType.Cm))), | |
new Unit(0.5, | |
((UnitType.Cm)))), | |
Style = | |
{ | |
TextAlign = HorizontalAlign.Left, | |
VerticalAlign = VerticalAlign.Middle, | |
BorderStyle = { Left = BorderType.Solid } | |
}, | |
Value = str3, | |
Dock = DockStyle.Left | |
}; | |
var textBox_10 = new TextBox | |
{ | |
Size = | |
new SizeU( | |
new Unit(3.5, | |
((UnitType.Cm))), | |
new Unit(0.5, | |
((UnitType.Cm)))), | |
Style = | |
{ | |
TextAlign = HorizontalAlign.Left, | |
VerticalAlign = VerticalAlign.Middle, | |
BorderStyle = { Left = BorderType.Solid } | |
}, | |
Value = str4, | |
Dock = DockStyle.Right | |
}; | |
panel_3.Items.AddRange(new ReportItemBase[] { textBox_7, textBox_9, textBox_8, textBox_10 }); | |
panel_1.Items.AddRange(new ReportItemBase[] { panel_3 }); | |
panel_1.Dock = DockStyle.Top; | |
if (str2.Length < 2 && str3.Length < 2 && str4.Length < 2) | |
{ | |
panel_1.Style.BorderStyle.Default = BorderType.None; | |
panel_3.Style.BorderStyle.Left = BorderType.None; | |
textBox_9.Style.BorderStyle.Left = BorderType.None; | |
textBox_8.Style.BorderStyle.Left = BorderType.None; | |
// textBox_7.Style.BorderStyle.Left = BorderType.None; | |
textBox_10.Style.BorderStyle.Left = BorderType.None; | |
//textBox_10.Style.BorderStyle.Right = BorderType.Solid; | |
panel_1.Style.BorderStyle.Right = BorderType.Solid; | |
textBox_7.Style.Font.Bold = true; | |
} | |
if (detail != null) | |
detail.Items.Add(panel_1); | |
} | |
Sincerely,
Janus S. Andersen