![]() |
![]() |
This is an advanced technique where it is possible to add C# scripts that can adapt the output to special requirements, to any Palstat system assembly.
All examples are examples only and CANNOT be used simply CTRL+C -> CTRL+V
In order to be able to use some of the basic objects of the Palstat system in the assembly, it is necessary to start by inserting scripts.
using Palstat;
While using using there may be further catagories that need to be used in printing, these other catagories will be used in each example of the guide.
- Drag a text field into the report named "label3"
- Create a new script in the properties, by default it is placed in Before Print.
- You will automatically switch to the appropriate field in the scrip editor. The default language is C#.
Reading values is provided by the Palstat library, which allows you to load several types of variable:
The name of the variable in the DB and the name of the relevant report detail (table) in which the variable is located are used as input parameters. The name of the variable in the DB is written as the last value in the help box, which appears when hovering the mouse over the corresponding value in the "Field List", eg. see Fig. "Copy number" is "DICOPYNUMBER".
Turn on help:
Display help in the FieldList:
The name of the relevant report detail can be found by looking in the "Field List", what is the name of the table in which the item you want to load is located, then look in the report, what is the number of the table in the report detail, eg see fig. The. "Copy number" belongs to the "Table: Distribution list" and in this report this table is defined as "DetailReport2". |
Now we will show what a simple script will look like, which will load the value of the item "Copy number" from the database where the item is called "DICOPYNUMBER" into our sample field "label3". We will not modify it in any way, we will only load it into the variable cis_kopie and write it to "label3":
using Palstat;
private void label3_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e) {
string cis_kopie = PS.GetString("DICOPYNUMBER", DetailReport2);
label3.Text = cis_kopie;
}
We load the data into our own variables for futher processing.
int TEKIND = PS.GetInt("TEKIND",DetailReport1);
TEKIND = The name of the field as it is is kept in the database and can also be displayed in the editor or in the program.
DetailReport1 = From which report in the report to retrieve the data. The report with the data must always be inserted in the printout in order to be accessible by this procedure.
using Palstat;
private void OnBeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e) {
string MAKIND = PS.GetString("MAKIND", DetailReport);
string MARESULT = PS.GetString("MARESULT", DetailReport);
double STRATING = PS.GetDouble("STRATING", DetailReport1);
int TEKIND = PS.GetInt("TEKIND",DetailReport1);
DateTime? DatumPOV = PS.GetDateTimeN("MAPROTOCOLDATE",DetailReport);
}
Sometimes it is necessary to load data into a report that is not related to the current report or is not available in the report. We load data via SQL directly from the database.
KEYWORD: sql enquiry, query, database
Retrieving the data, performing the operation, and writing the output to the required field, which much be pre-inserted and named in the report. The fields we write to are named in this example "data_*".
KEYWORD: chain, switch, substring
The sample shuts down part of the print report if there is no data in a particular field.
KEYWORD: cancel, hide, byte
After evaluating and loading the data, add a frame to the object on which the function is hung.
KEYWORD: frames, frame, frame, border
using Palstat;
using System.Globalization;
public static int GetWeekNumber(DateTime dtPassed)
{
CultureInfo ciCurr = CultureInfo.CurrentCulture;
int weekNum = ciCurr.Calendar.GetWeekOfYear(dtPassed, CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Monday);
return weekNum;
}
private void tableCell3DatumPOV_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e) {
XRLabel control = (XRLabel)sender;
DateTime? DatumPOV = PS.GetDateTimeN("MAPROTOCOLDATE",DetailReport);
if (DatumPOV.HasValue){
string cislo_tydne = GetWeekNumber(DatumPOV.Value).ToString();
control.Text = String.Format("{0:yyyy} - week {1}",DatumPOV,cislo_tydne);
}
else {
control.Text = "";
}
}
If you need to change the font, size, bold colour after evaluating the data
private void tableCell_78_PrintOnPage(object sender, DevExpress.XtraReports.UI.PrintOnPageEventArgs e) {
XRControl control = (XRControl)sender;
control.cell.Font = new Font("Times New Roman", 12, FontStyle.Bold);
}
KEYWORD: resizing, element placement, rotation, image, signature
// pie chart used as a progress bar to display percent progress
// the section in the circle is enlarged, coloured according to the percentage in the fulfillment of measures
// if it is met to 100% the colourof the whole circle will change to green
// it is solved by creating a model graph, as we want it to look, so without a legend, fencing, with colours cut out, etc.
// we use fixed values for this during the debugging of the appearance and we then only dynamically change it according to the current data.
private void chart1_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e) {
int Plneni = PS.GetInt("ACRUNSTATE",DetailReport1);
chart1.Series[0].Points[0].Values = new double[1] {Plneni};
chart1.Series[0].Points[1].Values = new double[1] {100-Plneni};
}
private void chart1_CustomDrawSeriesPoint(object sender, DevExpress.XtraCharts.CustomDrawSeriesPointEventArgs e) {
if (PS.GetInt("ACRUNSTATE",DetailReport1) == 100) e.SeriesDrawOptions.Color = Color.Green;
}
// graph filled with values from the script - filter graph data
// graph is created in the beginning of detail2, no data is bound to it, data is only forwarded for the series
private void Detail2_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e) {
string KodKoty = PS.GetString("CODICODE",DetailReport2);
if(!KodKoty.Contains("AA_OHY")) {e.Cancel = true; return;}
int KrokCislo = PS.GetInt("STSTEPNUM",DetailReport1);
double X = PS.GetDouble("STAVERAGEMET",DetailReport1);
var s = chart1.Series[0];
s.Points.Add(new SeriesPoint(KrokCislo, X));
}
Searching for values with specific characters, evaluation, and passing to a report
KEYWORD: string, page, compare, search, merge
Example of comparing two date items and listing the difference.
using Palstat;
private void OnBeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e) {
XRLabel script = (XRLabel)sender;
string s1 = PS.GetString("PRPLANNEDEND",DetailReport);
string s2 = PS.GetString("PRPLANNEDSTART",DetailReport);
if (s1 == "") {script.Text = "X"; return;}
if (s2 == "") {script.Text = "X"; return;}
DateTime d1 = Convert.ToDateTime(s1);
DateTime d2 = Convert.ToDateTime(s2);
TimeSpan s = d2-d1;
script.Text = s.TotalDays.ToString();
}
Example of using Exception in case of unexpected input, the example works with the field "MEAACURACY" which is in the String program, this tries to convert it to Double, but the conversion may fail if the user does not enter the expected numerical value into the field. In this case, issue a Messagebox.
KEYWORD: message, box, exception, convert
using Palstat;
private void label15_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e) {
try {
double MEACCURACY = Convert.ToDouble(PS.GetString("MEACCURACY", DetailReport2)); /*presnost*/
double LITOLERANCE = Convert.ToDouble(PS.GetDouble("LITOLERANCE", DetailReport)); /*tolerance*/
//scr_re.Text = "MEACCURACY:"+MEACCURACY+ " LITOLERANCE:"+LITOLERANCE;
scr_re.Text = Convert.ToString(( MEACCURACY / (LITOLERANCE*100) ));
}
catch (FormatException) {
System.Windows.Forms.MessageBox.Show("PALSTAT: NO VALID DATA FOR FIELDS ACCURANCY(MEASURES) OR TOLERANCE(MSA)");
scr_re.Text = "";
}
}
![]() |
© Copyright 1992 - 2025 PALSTAT s.r.o. |
PALSTAT s.r.o. Bucharova 230 543 02 Vrchlabí CZECH REPUBLIC |
tel.: +420 499 422 044 tel.: +420 499 692 016 www.palstat.cz |
» Home Page » Training » References » News |
» Events » Partners » Support » Contact |
» Products » Customer portal » Remote support » Update |
» Terms and Conditions » Gallery » Map » Portal 3 |