Adding creation/printing date for report

Stimulsoft Ultimate discussion
Post Reply
tynar
Posts: 25
Joined: Thu Mar 17, 2011 11:54 pm
Location: Kyrgyzstan

Adding creation/printing date for report

Post by tynar »

Hello,

I've a task to place printing date with time on all kind of StimulSoft reports, and was wondering if it is already implemented in StimulSoft? If not, would much appreciate your guidance how to accomplish this task. We have a class SReport which inherits from StiReport class which is used to render all our reports. What I'm thinking at the moment is to override Load(string path) method to read 'mrt' file into MemoryStream and add TextBox with current date to the bottom of first page and load that Stream, but perhaps it is not a good idea.

Looking forward your suggestions.
Tynar.
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

Adding creation/printing date for report

Post by Alex K. »

Hello,

As a way you can try to adding in report a additional text component with expression {DateTime.Now}

Thank you.
tynar
Posts: 25
Joined: Thu Mar 17, 2011 11:54 pm
Location: Kyrgyzstan

Adding creation/printing date for report

Post by tynar »

What I've done so far:

Code: Select all

        public override void Load(string path)
        {
            var rootDirectory = HttpContext.Current.Request.MapPath("~");
            var reportFilePath = Path.Combine(rootDirectory, path);
            base.Load(reportFilePath);
            LoadDatabaseConf();
            AddPrintDate();
        }

        public void AddPrintDate()
        {
            if (Pages.Count > 0)
            {
                StiPage firstPage = Pages[0];

                StiFooterBand footerBand = new StiFooterBand(firstPage.ClientRectangle);
                StiUnit unit = new StiHundredthsOfInchUnit();
                double height = unit.ConvertFromHInches(30);
                footerBand.Height = height;
                footerBand.Name = "FooterBandReserved";

                firstPage.Components.Add(footerBand);

                //Create creation date.
                StiText printDateText = new StiText();
                printDateText.Height = unit.ConvertFromHInches(20);
                printDateText.Width = unit.ConvertFromHInches(110);
                printDateText.Text = DateTime.Now.ToString("dd.MM.yyyy hh:mm:ss");
                printDateText.Brush = new StiSolidBrush(Color.Black);
                printDateText.Name = "FooterTextReserved";
                printDateText.Font = new System.Drawing.Font("Times New Roman", 12f);

                footerBand.Components.Add(printDateText);
            }
        }
But I cannot see desired result, could you please point me what I am missing.
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

Adding creation/printing date for report

Post by Alex K. »

Hello,

Please check the following code:

Code: Select all

if (Pages.Count > 0)
{
    StiPage firstPage = Pages[0];

    StiPageFooterBand footerBand = new StiPageFooterBand();
    
    StiUnit unit = new StiHundredthsOfInchUnit();
    double height = unit.ConvertFromHInches(30);
    footerBand.Height = height;
    footerBand.Name = "FooterBandReserved";

    firstPage.Components.Add(footerBand);

    //Create creation date.
    StiText printDateText = new StiText();
    printDateText.Height = unit.ConvertFromHInches(20);
    printDateText.Width = unit.ConvertFromHInches(110);
    printDateText.Text = DateTime.Now.ToString("dd.MM.yyyy hh:mm:ss");
    printDateText.Border = new Stimulsoft.Base.Drawing.StiBorder(Stimulsoft.Base.Drawing.StiBorderSides.None, System.Drawing.Color.FromArgb(255, 193, 152, 89), 1, Stimulsoft.Base.Drawing.StiPenStyle.Solid, false, 4, new Stimulsoft.Base.Drawing.StiSolidBrush(System.Drawing.Color.Black), false);
    printDateText.Brush = new Stimulsoft.Base.Drawing.StiSolidBrush(System.Drawing.Color.Transparent);
    printDateText.Font = new System.Drawing.Font("Times New Roman", 12f);
    printDateText.TextBrush = new Stimulsoft.Base.Drawing.StiSolidBrush(System.Drawing.Color.Black);
    printDateText.Name = "FooterTextReserved";

    footerBand.Components.Add(printDateText);
}
This code work correctly.

Thank you.
tynar
Posts: 25
Joined: Thu Mar 17, 2011 11:54 pm
Location: Kyrgyzstan

Adding creation/printing date for report

Post by tynar »

Thank you, it worked. I love this forum :biggrin:
Andrew
Posts: 4109
Joined: Fri Jun 09, 2006 3:58 am

Adding creation/printing date for report

Post by Andrew »

Hello,

Great!

Post Reply