Different scripts in the report generator
On this page you will find various useful scripts that can be used in the report generator.How do I hide the % sign in the header if there is no discount?
Remember that the script must be selected on the "PageHeader" ribbon in Properties/Behavior/Scripts, in the "Before print" field.private void PageHeader_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e) { var colSource = GetCurrentColumnValue("DebtorInfo") as Uniconta.ClientTools.DataModel.DebtorClient; bool discountPctExist = false; if (colSource !=null) { var invLines = colSource.InventoryTransInvoice as Uniconta.ClientTools.DataModel.InvTransInvoice[]; foreach(var invLine in invLines) { if(invLine.DiscountPct !=null || invLine.DiscountPct >0) { discountPctExist = true; break; } } } if(discountPctExist) { //Label name you want to show xrLabelDiscountPct.Visible = true; } else { //Label name you want to hide xrLabelDiscountPct.Visible = false; } }
How do I hide the % sign in the header if there is neither a % discount nor an amount discount?
Remember that the script must be selected on the "PageHeader" ribbon in Properties/Behavior/Scripts, in the "Before print" field.private void PageHeader_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e) { var colSource = GetCurrentColumnValue("DebtorInfo") as Uniconta.ClientTools.DataModel.DebtorClient; bool discountPctExist = false; //xrLabelDiscountPct.Visible = false; if (colSource !=null) { var invLines = colSource.InventoryTransInvoice as Uniconta.ClientTools.DataModel.InvTransInvoice[]; foreach(var invLine in invLines) { if(invLine.DiscountPct !=null || invLine.DiscountPct >0 || invLine.Discount !=null || invLine.Discount >0) { discountPctExist = true; break; } } } if(discountPctExist) { //Label name you want to show xrLabelDiscountPct.Visible = true; } else { //Label name you want to hide xrLabelDiscountPct.Visible = false; } }
How do I hide a label for an empty field?
When you use a data field that is not always filled in, e.g. requisition number, you can hide your label by making a small entry in "Scripts" which you find in the generator's menu, top right.private void xrReqLable_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e) { // Ex. på hvordan man får fat i objektet xrReqLable, via "sender" i funktionskaldet, der derefter kan manipuleret med alverdens egenskaber XRLabel label = (XRLabel)sender; // Ex. på hvordan man kan udfylde en label via kode... // Ex. på en if sætning... // Spørger om label xrReqValue er tomt! Hvis tomt, skal tilhørende label xrReqLable ikke vises, ellers skal den vises. if (xrReqValue.Text == "") { label.Visible = false; } else { label.Visible = true; //label.ForeColor = Color.Black; //label.BackColor = Color.White; } }
How do I get decimals on my VAT amount?
If your fields don't show decimals as expected, you can write a small note in "Scripts" which you find in the generator menu, top right. Select the label in question, e.g. as below the VAT field, xrDetailInvoiceFieldSum, and click Scripts in the menu. Then select BeforePrint in the right drop-down menu at the top and the function below will appear. Insert the XRLabel.... code as shown in the function below in italics.private void xrDetailInvoiceFieldSum_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e) { XRLabel label = (XRLabel)sender; // Formatere den valgte label til at have to decimaler (N2) if(!string.IsNullOrEmpty(label.Text)) label.Text = Convert.ToDouble(label.Text).ToString("N2"); }
How to hide a label for the default DateTime value? ("01-01-0001 00:00:00:00" or "01-01-0001")
When you have a DateTime field filled with default value, you can hide its label by making a small print in "Scripts" that you can find in the generators' menu at the top rightprivate void xrReqLable_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e) { var xrLabel = sender as XRLabel; if(xrLabel != null && !string.IsNullOrEmpty(xrLabel.Text)) { DateTime dateTime; if(DateTime.TryParse(xrLabel.Text, out dateTime) && dateTime == DateTime.MinValue) xrLabel.Text = string.Empty; } }
How to use before print event for localizing labels in user reports?
Copy the below code and set it to the required XRLABEL's before print eventprivate void xrLabel_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e) { var xrLable = sender as XRLabel; var text = xrLable.Text; xrLable.Text = Uniconta.ClientTools.Util.UtilFunctions.LocalizePrompt(text); }