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

Report printing 01/01/1899 for date

Last post 10-19-2009, 2:16 PM by Dan Suceava. 7 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
  •  10-13-2009, 1:58 PM 19583 in reply to 12848

    • deanl is not online. Last active: 05-11-2010, 12:07 PM deanl
    • Not Ranked
      Male
    • Joined on 03-27-2009
    • Moorestown, NJ
    • Posts 4
    • Points 68
    Re: Report printing 01/01/1899 for date

    Sadly enough, I am now having this issue.  Below is my code for GroupHeader1.  The problem occurs only for custom fields...for the OnTime default date fields, it works fine.

     Thanks,

     

    public void ignoreGroupHeader1_Format()
    {
        System.DateTime dt;
       
        if (rpt.Fields.Contains("ReportedDate") && rpt.Fields["ReportedDate"].Value != null)
        {
            dt = (System.DateTime)rpt.Fields["ReportedDate"].Value;       
            if (dt.Year < 1910)
            {
                ((TextBox)rpt.Sections["ignoreGroupHeader1"].Controls["txtReportedDate"]).Text = " ";
            }
        }
       
        if (rpt.Fields.Contains("StartDate") && rpt.Fields["StartDate"].Value != null)
        {
            dt = (System.DateTime)rpt.Fields["StartDate"].Value;       
            if (dt.Year < 1910)
            {
                ((TextBox)rpt.Sections["ignoreGroupHeader1"].Controls["txtStartDate"]).Text = " ";
            }
        }
       
        if (rpt.Fields.Contains("CompletionDate") && rpt.Fields["CompletionDate"].Value != null)
        {
            dt = (System.DateTime)rpt.Fields["CompletionDate"].Value;       
            if (dt.Year < 1910)
            {
                ((TextBox)rpt.Sections["ignoreGroupHeader1"].Controls["txtCompletionDate"]).Text = " ";
            }
        }

        if (rpt.Fields.Contains("Custom_157") && rpt.Fields["Custom_157"].Value != null)
        {
            dt = (System.DateTime)rpt.Fields["Custom_157"].Value;       
            if (dt.Year < 1910)
            {
                ((TextBox)rpt.Sections["ignoreGroupHeader1"].Controls["txtClosedDate"]).Text = "   ";
            }
        }
       
        if (rpt.Fields.Contains("Custom_156") && rpt.Fields["Custom_156"].Value != null)
        {
            dt = (System.DateTime)rpt.Fields["Custom_156"].Value;       
            if (dt.Year < 1910)
            {
                ((TextBox)rpt.Sections["ignoreGroupHeader1"].Controls["ResolvedDate"]).Text = "    ";
            }
        }       

        ((TextBox)rpt.Sections["ignoreGroupHeader1"].Controls["txtCustomerName"]).Text = string.Format("{0}", rpt.Fields["CustomerName"].Value);
       
        // append ":" to field name labels if necessary
        foreach (ARControl c in rpt.Sections["ignoreGroupHeader1"].Controls)
        {
            if (c is Label)
            {
                if (!((Label)c).Text.EndsWith(":"))
                {
                    ((Label)c).Text += ":";
                }
            }
        }
    }

    Filed under:
  •  10-14-2009, 10:31 AM 19591 in reply to 19583

    Re: Report printing 01/01/1899 for date
    The custom fields are the 2 fields you already check for (Custom_156 and Custom_157)?  Double-check that those are the right fields.

    Dan Suceava
    http://www.axosoft.com
  •  10-14-2009, 10:41 AM 19592 in reply to 19591

    • deanl is not online. Last active: 05-11-2010, 12:07 PM deanl
    • Not Ranked
      Male
    • Joined on 03-27-2009
    • Moorestown, NJ
    • Posts 4
    • Points 68
    Re: Report printing 01/01/1899 for date
    Yes those fields I check for.  If I go ahead and put the date into the fields, it is reported correctly on the report.  So, the fields are correct.
  •  10-19-2009, 2:16 PM 19630 in reply to 19592

    Re: Report printing 01/01/1899 for date
    The code looks ok, so the only thing I can suggest is that you try some old-school debugging and print out the dt.Year to see why it's failing that check (or the check before it).

    Dan Suceava
    http://www.axosoft.com
View as RSS news feed in XML

© 2002 - 2011, Axosoft, LLC. All Rights Reserved. | Privacy
Scrum Project Management Software | Scrum Master