Ejemplo n.º 1
0
        } //FormatDateDiffResults()

        // Format the text to display on live tile
        public void FormatLiveTileText(DateTime dtFromDate, DateTime dtToDate, out string strResultsText)
        {
            CalculateDateDifference dateDiff = new CalculateDateDifference(dtFromDate, dtToDate);

            // Total days
            TimeSpan tsDaysSince = dtToDate - dtFromDate;
            int      nTotalDays  = (int)tsDaysSince.TotalDays;

            int nTotalMonths = dateDiff.Months;
            int nDays        = dateDiff.Days;
            int nTotalYears  = dateDiff.Years;

            // truth table for formatting the string output
            string        strDay;
            string        strMonth;
            string        strYear;
            StringBuilder sbBeginning   = new StringBuilder("");
            StringBuilder sbResultsText = new StringBuilder("");

            /*
             * Backtile output
             *
             * <date>
             * xxxxx days
             * xxx years, xx months, xxx days
             *
             * // Days Since page output
             * Number of Days Since <date> is:
             * xxxxx days
             * xxx years, xx months, xxx days
             */

            sbBeginning.Append("      " + dtFromDate.ToShortDateString() + "\r\n\r\n");
            if (1 == nTotalMonths)
            {
                strMonth = DaysSinceClassLibAppResources.txtSpaceMonthCommaSpace; //" month, ";
            }
            else
            {
                strMonth = DaysSinceClassLibAppResources.txtSpaceMonthsCommaSpace; // " months, ";
            }
            if (1 == nDays)
            {
                strDay = DaysSinceClassLibAppResources.txtSpaceDay; // " day";
            }
            else
            {
                strDay = DaysSinceClassLibAppResources.txtSpaceDays; // " days";
            }
            if (1 == nTotalYears)
            {
                strYear = DaysSinceClassLibAppResources.txtSpaceYearCommaSpace; // " year, ";
            }
            else
            {
                strYear = DaysSinceClassLibAppResources.txtYearsCommaSpace; // " years, ";
            }
            //strResultsText = "";
            string strFromDate = dtFromDate.ToShortDateString();
            string strToDate   = dtToDate.ToShortDateString();

            if (strFromDate == strToDate) // Dates are equal.
            {
                strResultsText = sbBeginning + nDays.ToString() + strDay.ToString();;
                return;
            }

            if ((0 == nTotalYears) && (0 == nTotalMonths) && (nDays > 0))
            {
                // 0 years, 0 months, x days
                //strResultsText = sbBeginning + nDays.ToString() + strDay.ToString(); ;
                sbResultsText.Append(sbBeginning + nDays.ToString() + strDay.ToString());
            }

            // 0 years, x months, 0 days
            if ((0 == nTotalYears) && (nTotalMonths > 0) && (0 == nDays))
            {
                //strResultsText = sbBeginning + nTotalDays.ToString() + DaysSinceClassLibAppResources.txtSpaceDaysSpace + "\r\n" + nTotalMonths + strMonth.ToString() + nDays + strDay.ToString();
                sbResultsText.Append(sbBeginning + nTotalDays.ToString() + DaysSinceClassLibAppResources.txtSpaceDaysSpace + "\r\n" + nTotalMonths + strMonth.ToString() + nDays + strDay.ToString());
            }

            // 0 years, x months, x days
            if ((0 == nTotalYears) && (nTotalMonths > 0) && (nDays > 0))
            {
                //strResultsText = sbBeginning + nTotalDays.ToString() + DaysSinceClassLibAppResources.txtSpaceDaysSpace + "\r\n" + nTotalMonths + strMonth + nDays + strDay.ToString();
                sbResultsText.Append(sbBeginning + nTotalDays.ToString() + DaysSinceClassLibAppResources.txtSpaceDaysSpace + "\r\n" + nTotalMonths + strMonth + nDays + strDay.ToString());
            }

            // x years, 0 months, 0 days
            if ((nTotalYears > 0) && (0 == nTotalMonths) && (0 == nDays))
            {
                //strResultsText = sbBeginning + nTotalDays.ToString() + DaysSinceClassLibAppResources.txtSpaceDaysSpace + "\r\n" + nTotalYears + strYear.ToString() + nTotalMonths + strMonth.ToString() + nDays + strDay.ToString();
                sbResultsText.Append(sbBeginning + nTotalDays.ToString() + DaysSinceClassLibAppResources.txtSpaceDaysSpace + "\r\n" + nTotalYears + strYear.ToString() + nTotalMonths + strMonth.ToString() + nDays + strDay.ToString());
            }

            if ((nTotalYears > 0) && (0 == nTotalMonths) && (nDays > 0))
            {
                // x years, 0 months, x days
                //strResultsText = sbBeginning + nTotalDays.ToString() + DaysSinceClassLibAppResources.txtSpaceDaysSpace + "\r\n" + nTotalYears + strYear.ToString() + nTotalMonths + strMonth.ToString() + nDays + strDay.ToString();
                sbResultsText.Append(sbBeginning + nTotalDays.ToString() + DaysSinceClassLibAppResources.txtSpaceDaysSpace + "\r\n" + nTotalYears + strYear.ToString() + nTotalMonths + strMonth.ToString() + nDays + strDay.ToString());
            }

            if ((nTotalYears > 0) && (nTotalMonths > 0) && (0 == nDays))
            {
                // x years, x months, 0 days
                //strResultsText = sbBeginning + nTotalDays.ToString() + DaysSinceClassLibAppResources.txtSpaceDaysSpace + "\r\n" + nTotalYears + strYear.ToString() + nTotalMonths + strMonth.ToString() + nDays + strDay.ToString();
                sbResultsText.Append(sbBeginning + nTotalDays.ToString() + DaysSinceClassLibAppResources.txtSpaceDaysSpace + "\r\n" + nTotalYears + strYear.ToString() + nTotalMonths + strMonth.ToString() + nDays + strDay.ToString());
            }

            if ((nTotalYears > 0) && (nTotalMonths > 0) && (nDays > 0))
            {
                // x years, x months, x days
                //strResultsText = sbBeginning + nTotalDays.ToString() + DaysSinceClassLibAppResources.txtSpaceDaysSpace + "\r\n" + nTotalYears + strYear.ToString() + nTotalMonths + strMonth.ToString() + nDays + strDay.ToString();
                //sbResultsText.Append( sbBeginning + nTotalDays.ToString() + DaysSinceClassLibAppResources.txtSpaceDaysSpace + "\r\n" + nTotalYears + strYear.ToString() + nTotalMonths + strMonth.ToString() + nDays + strDay.ToString() );
                sbResultsText.Append(sbBeginning + nTotalDays.ToString() + DaysSinceClassLibAppResources.txtSpaceDaysSpace + "\r\n" + nTotalYears + strYear.ToString() + nTotalMonths + strMonth.ToString() + nDays + strDay.ToString());
            }

            strResultsText = sbResultsText.ToString();// need to return as a string
        } // void FormatLiveTileText
Ejemplo n.º 2
0
        // Called on for DaysSince
        public void FormatDaysSinceResults(DateTime dtFromDate, DateTime dtToDate, out string strResultsText)
        {
            // Clear Text Block
            strResultsText = "";

            CalculateDateDifference dateDiff = new CalculateDateDifference(dtFromDate, dtToDate);

            // Total days
            TimeSpan tsDaysSince = dtToDate - dtFromDate;
            int      nTotalDays  = (int)tsDaysSince.TotalDays;

            int nTotalMonths = dateDiff.Months;
            int nDays        = dateDiff.Days;
            int nTotalYears  = dateDiff.Years;

            // truth table for formatting the string output
            string strDay;
            string strMonth;
            string strYear;
            string sRN = " \r\n";

            StringBuilder sbDays        = new StringBuilder(DaysSinceClassLibAppResources.txtDays);
            StringBuilder sbBeginning   = new StringBuilder("\r\n\r\n");
            StringBuilder sbResultsText = new StringBuilder("");

            // Days Since page output

            /*
             * Number of Days Since <date> is:
             * xxxxx days
             * xxx years, xx months, xxx days
             */

            if (1 == nTotalMonths)
            {
                strMonth = DaysSinceClassLibAppResources.txtMonthComma; //strMonth = " Month, ";
            }
            else
            {
                strMonth = DaysSinceClassLibAppResources.txtMonthsComma; //strMonth = " Months, ";
            }
            if (1 == nDays)
            {
                strDay = DaysSinceClassLibAppResources.txtDay; //strDay = " Day";
            }
            else
            {
                strDay = DaysSinceClassLibAppResources.txtDays; //strDay = " Days";
            }
            if (1 == nTotalYears)
            {
                strYear = DaysSinceClassLibAppResources.txtYearComma; //strYear = " Year, ";
            }
            else
            {
                strYear = DaysSinceClassLibAppResources.txtYearsComma; //strYear = " Years, ";
            }
            string strFromDate = dtFromDate.ToShortDateString();
            string strToDate   = dtToDate.ToShortDateString();

            if (strFromDate == strToDate)   // Dates are equal.
            {
                //strResultsText = sbBeginning + nDays.ToString() + strDay.ToString(); ;
                sbResultsText.Append(sbBeginning + nDays.ToString() + strDay.ToString());
                strResultsText += sbResultsText.ToString();
                return;
            }

            if ((0 == nTotalYears) && (0 == nTotalMonths) && (nDays > 0))
            {
                // 0 years, 0 months, x days
                //strResultsText = sbBeginning + nDays.ToString() + strDay.ToString(); ;
                sbResultsText.Append(sbBeginning.ToString() + nDays.ToString() + strDay.ToString());
            }

            // 0 years, x months, 0 days
            if ((0 == nTotalYears) && (nTotalMonths > 0) && (0 == nDays))
            {
                //strResultsText = sbBeginning + nTotalDays.ToString() + " Days \r\n" + nTotalMonths + strMonth.ToString() + nDays + strDay.ToString();
                sbResultsText.Append(sbBeginning + nTotalDays.ToString() + sbDays.ToString() + sRN + nTotalMonths + strMonth.ToString() + nDays + strDay.ToString());
            }

            // 0 years, x months, x days
            if ((0 == nTotalYears) && (nTotalMonths > 0) && (nDays > 0))
            {
                //strResultsText = sbBeginning + nTotalDays.ToString() + " Days \r\n" + nTotalMonths + strMonth + nDays + strDay.ToString();
                sbResultsText.Append(sbBeginning + nTotalDays.ToString() + sbDays.ToString() + sRN + nTotalMonths + strMonth + nDays + strDay.ToString());
            }

            // x years, 0 months, 0 days
            if ((nTotalYears > 0) && (0 == nTotalMonths) && (0 == nDays))
            {
                //strResultsText = sbBeginning + nTotalDays.ToString() + " Days \r\n" + nTotalYears + strYear.ToString() + nTotalMonths + strMonth.ToString() + nDays + strDay.ToString();
                sbResultsText.Append(sbBeginning + nTotalDays.ToString() + sbDays.ToString() + sRN + nTotalYears + strYear.ToString() + nTotalMonths + strMonth.ToString() + nDays + strDay.ToString());
            }

            if ((nTotalYears > 0) && (0 == nTotalMonths) && (nDays > 0))
            {
                // x years, 0 months, x days
                //strResultsText = sbBeginning + nTotalDays.ToString() + " Days \r\n" + nTotalYears + strYear.ToString() + nTotalMonths + strMonth.ToString() + nDays + strDay.ToString();
                sbResultsText.Append(sbBeginning + nTotalDays.ToString() + sbDays.ToString() + sRN + nTotalYears + strYear.ToString() + nTotalMonths + strMonth.ToString() + nDays + strDay.ToString());
            }

            if ((nTotalYears > 0) && (nTotalMonths > 0) && (0 == nDays))
            {
                // x years, x months, 0 days
                //strResultsText = sbBeginning + nTotalDays.ToString() + " Days \r\n" + nTotalYears + strYear.ToString() + nTotalMonths + strMonth.ToString() + nDays + strDay.ToString();
                sbResultsText.Append(sbBeginning + nTotalDays.ToString() + sbDays.ToString() + sRN + nTotalYears + strYear.ToString() + nTotalMonths + strMonth.ToString() + nDays + strDay.ToString());
            }

            if ((nTotalYears > 0) && (nTotalMonths > 0) && (nDays > 0))
            {
                // x years, x months, x days
                //strResultsText = sbBeginning + nTotalDays.ToString() + " Days \r\n" + nTotalYears + strYear.ToString() + nTotalMonths + strMonth.ToString() + nDays + strDay.ToString();
                sbResultsText.Append(sbBeginning + nTotalDays.ToString() + sbDays.ToString() + sRN + nTotalYears + strYear.ToString() + nTotalMonths + strMonth.ToString() + nDays + strDay.ToString());
            }


            strResultsText += sbResultsText.ToString();
        } //FormatDaysSinceResults()
Ejemplo n.º 3
0
        // Called by both 'DaysSince()' and 'DateDiff()' to format text output to UI.
        void FormatResultsText(DateTime dtFromDate, DateTime dtToDate, out string strResultsText, eFormatType eFT)
        {
            CalculateDateDifference dateDiff = new CalculateDateDifference(dtFromDate, dtToDate);

            // Total days
            TimeSpan tsDaysSince = dtToDate - dtFromDate;
            int      nTotalDays  = (int)tsDaysSince.TotalDays;

            int totalMonths = dateDiff.Months;
            int nDays       = dateDiff.Days;
            int totalYears  = dateDiff.Years;

            // truth table for formatting the string output
            string sDay;
            string sMonth;
            string sYear;
            string sBeginning = "";

            /*
             * Backtile output
             *
             * <date>
             * xxxxx days
             * xxx years, xx months, xxx days
             *
             * // Days Since page output
             * Number of Days Since <date> is:
             * xxxxx days
             * xxx years, xx months, xxx days
             */
            if (eFormatType.DATEDIFF == eFT)
            {
                sBeginning = "Number of days between\r\n" + dtFromDate.ToShortDateString() + " and " + dtToDate.ToShortDateString() + " is:  ";
            }

            if (eFormatType.MAINPAGE == eFT)
            {
                sBeginning = "Number of days since " + dtFromDate.ToShortDateString() + " is: ";
            }

            if (eFormatType.BACKTILE == eFT)
            {
                sBeginning = dtFromDate.ToShortDateString() + "\r\n";
            }

            if (1 == totalMonths)
            {
                sMonth = " month, ";
            }
            else
            {
                sMonth = " months, ";
            }

            if (1 == nDays)
            {
                sDay = " day.";
            }
            else
            {
                sDay = " days.";
            }

            if (1 == totalYears)
            {
                sYear = " year, ";
            }
            else
            {
                sYear = " years, ";
            }

            // clear text block
            strResultsText = "";
            if ((0 == totalYears) && (0 == totalMonths) && (nDays > 0))
            {
                // 0 years, 0 months, x days
                strResultsText = sBeginning + nDays.ToString() + sDay.ToString();
            }
            ;

            // 0 years, x months, 0 days
            if ((0 == totalYears) && (totalMonths > 0) && (0 == nDays))
            {
                strResultsText = sBeginning + nTotalDays.ToString() + " days or,\r\n" + totalMonths + sMonth.ToString() + nDays + sDay.ToString();
            }

            // 0 years, x months, x days
            if ((0 == totalYears) && (totalMonths > 0) && (nDays > 0))
            {
                strResultsText = sBeginning + nTotalDays.ToString() + " days or,\r\n" + totalMonths + sMonth + nDays + sDay.ToString();
            }

            // x years, 0 months, 0 days
            if ((totalYears > 0) && (0 == totalMonths) && (0 == nDays))
            {
                strResultsText = sBeginning + nTotalDays.ToString() + " days or,\r\n" + totalYears + sYear.ToString() + totalMonths + sMonth.ToString() + nDays + sDay.ToString();
            }

            if ((totalYears > 0) && (0 == totalMonths) && (nDays > 0))
            {
                // x years, 0 months, x days
                strResultsText = sBeginning + nTotalDays.ToString() + " days or,\r\n" + totalYears + sYear.ToString() + totalMonths + sMonth.ToString() + nDays + sDay.ToString();
            }

            if ((totalYears > 0) && (totalMonths > 0) && (0 == nDays))
            {
                // x years, x months, 0 days
                strResultsText = sBeginning + nTotalDays.ToString() + " days or,\r\n" + totalYears + sYear.ToString() + totalMonths + sMonth.ToString() + nDays + sDay.ToString();
            }

            if ((totalYears > 0) && (totalMonths > 0) && (nDays > 0))
            {
                // x years, x months, x days
                strResultsText = sBeginning + nTotalDays.ToString() + " days or,\r\n" + totalYears + sYear.ToString() + totalMonths + sMonth.ToString() + nDays + sDay.ToString();
            }
        } // void FormatResultsText