Welcome to the Axosoft Community, Sign in | Register | Help
in Search

Report printing 01/01/1899 for date

Last post 08-14-2007, 9:27 AM by Dan Suceava. 3 replies.
Sort Posts: Previous Next
  •  08-08-2007, 1:22 PM 12740

    Report printing 01/01/1899 for date

    I saw several posts about this but I have been unable to get any of the suggestions to work. I have the completion date field on a custom report and where there is no completion date filled in for a task it prints 01/01/1899.

     

    I have some code in the detail format event handler:

     

            dt = (System.DateTime)rpt.Fields["CompletionDate"].Value;
            if (dt.Year < 1910)
            {
                ((TextBox)rpt.Sections["Detail"].Controls["txtCompletionDate"]).Text = "";
            }

    Which works fine for other fields but not for this field. Any ideas? 

    Filed under:
  •  08-13-2007, 8:25 AM 12820 in reply to 12740

    Re: Report printing 01/01/1899 for date
    That code should work fine, I've just tried it in a report.  What other code do you have in the detail format handler?
    Dan Suceava
    http://www.axosoft.com
  •  08-13-2007, 8:56 AM 12821 in reply to 12820

    Re: Report printing 01/01/1899 for date

    Here's the entire code listing for the report:

     

    private bool _oddRow = false;

    private string[] _labels = new string[1];


    public void Detail_Format()
    {
            if (_oddRow)
            {
                rpt.Sections["Detail"].BackColor = System.Drawing.Color.FromArgb(224, 224, 224);
            }
            else
            {
                rpt.Sections["Detail"].BackColor = System.Drawing.Color.White;
            }
            _oddRow = !_oddRow;

       
        if (rpt.Fields.Contains("StartDate") && rpt.Fields["StartDate"].Value != null)
        {
            System.DateTime dt = (System.DateTime)rpt.Fields["StartDate"].Value;
            if (dt.Year < 1910)
            {
                ((TextBox)rpt.Sections["Detail"].Controls["txtStartDate"]).Text = "";
            }
            dt = (System.DateTime)rpt.Fields["DueDate"].Value;
            if (dt.Year < 1910)
            {
                ((TextBox)rpt.Sections["Detail"].Controls["txtDueDate"]).Text = "";
            }
            dt = (System.DateTime)rpt.Fields["CompletionDate"].Value;
            if (dt.Year < 1910)
            {
                ((TextBox)rpt.Sections["Detail"].Controls["txtCompletionDate"]).Text = "";
            }
        }
       
    }

    public void PageHeader_Format()
    {
        ((Label)rpt.Sections["PageHeader"].Controls["labelTitle"]).Text = rptTitle;
    }

    public void PageFooter_Format()
    {
        ((Label)rpt.Sections["PageFooter"].Controls["labelPrintedOn"]).Text = string.Format(((Label)rpt.Sections["PageFooter"].Controls["labelPrintedOn"]).Text, System.DateTime.Now.ToShortDateString());
        ((Label)rpt.Sections["PageFooter"].Controls["labelPage"]).Text = string.Format(_labels[0], rpt.PageNumber.ToString());
    }

    public void autoGroupHeader1_Format()
    {
        if (rptSelectedGroupHeaderField.Length > 0 && rpt.Fields.Contains(rptSelectedGroupHeaderField) && rpt.Fields[rptSelectedGroupHeaderField].Value != null)
        {
            if (rpt.Fields[rptSelectedGroupHeaderField].Value.ToString().Length > 0)
            {
                ((Label)rpt.Sections["autoGroupHeader1"].Controls["labelGroupHeader"]).Text = rpt.Fields[rptSelectedGroupHeaderField].Value.ToString();
            }
            else
            {
                ((Label)rpt.Sections["autoGroupHeader1"].Controls["labelGroupHeader"]).Text = rpt_NONE_TEXT;
            }
        }
    }

    public void ActiveReport_ReportStart()
    {
        _labels[0] = ((Label)rpt.Sections["PageFooter"].Controls["labelPage"]).Text;

        if (rptSelectedGroupField.Length > 0)
        {
            ((GroupHeader)rpt.Sections["autoGroupHeader1"]).DataField = rptSelectedGroupField;
            rpt.Sections["autoGroupHeader1"].Visible = true;
            rpt.Sections["GroupFooter1"].Visible = true;
        }
        else
        {
            rpt.Sections["autoGroupHeader1"].Visible = false;
            rpt.Sections["GroupFooter1"].Visible = false;
        }
    }
     

  •  08-14-2007, 9:27 AM 12848 in reply to 12821

    Re: Report printing 01/01/1899 for date
    Try moving the 'CompletionDate' code outside the 'StartDate' if statement, it currently only gets executed if the StartDate is not null.
    Dan Suceava
    http://www.axosoft.com
View as RSS news feed in XML

© 2002 - 2007, Axosoft, LLC. All Rights Reserved. | Privacy
Bug Tracking | Defect Tracking Videos | Help Desk Software