Пример #1
0
        protected void LoadXmlDocument(string fileName)
        {
            XElement root = XElement.Load(fileName);

            // Note: No need to perform the below.  this.TimesheetMonth is
            // updated prior to calling this member.
            //int year = Convert.ToInt32(root.Attribute("timesheetYear").Value);
            //int month = Convert.ToInt32(root.Attribute("timesheetMonth").Value);
            //this.TimesheetMonth = new TimesheetMonth(year, month);
            // _PRIORITY_: This is new 2011-02-15!!!
            int invoiceNumber = Convert.ToInt32(root.Attribute("invoiceNumber").Value);

            if (invoiceNumber == 0)
            {
                // Get our invoice number to use.
                invoiceNumber = MonthlyTimesheets.GetPreviousInvoiceNumberOrDefault(new DateTime(this.TimesheetMonth.Year, this.TimesheetMonth.Month, 1).AddMonths(-1));
                ++invoiceNumber;
            }
            this.InvoiceNumber = invoiceNumber;

            foreach (XElement timesheetElement in root.XPathSelectElements("./timesheet"))
            {
                Timesheet timesheet = new Timesheet(this, timesheetElement);
                this.Add(timesheet);
            }
        }
Пример #2
0
        protected void CreateXmlDocument(string fileName)
        {
            int year  = this.TimesheetMonth.Year;
            int month = this.TimesheetMonth.Month;

            DateTime startDate = new DateTime(year, month, 1);
            DateTime endDate   = new DateTime(year, month, DateTime.DaysInMonth(year, month));

            TimesheetMonth timesheetMonth = new TimesheetMonth(startDate.Year, startDate.Month);

            // Get our invoice number to use.
            int invoiceNumber = MonthlyTimesheets.GetPreviousInvoiceNumberOrDefault(new DateTime(year, month, 1).AddMonths(-1));

            this.InvoiceNumber = ++invoiceNumber;

            // Capture the day of week...
            DayOfWeek dayOfWeek = startDate.DayOfWeek;

            // If the day of week is not a Monday, we need to calculate backwards or
            // forwards to get to the Monday we want...
            if (dayOfWeek != DayOfWeek.Monday)
            {
                double daysToAdd = 0;

                if (dayOfWeek < DayOfWeek.Monday)
                {
                    daysToAdd = Convert.ToDouble(DayOfWeek.Monday - dayOfWeek);
                }
                else if (startDate.DayOfWeek > DayOfWeek.Monday)
                {
                    daysToAdd = -Convert.ToDouble(dayOfWeek - DayOfWeek.Monday);
                }

                startDate = startDate.AddDays(daysToAdd);
            }

            DateTime monday = startDate;

            for (int i = 0; monday <= endDate; i++)
            {
                DateTime mondayPlus6 = monday.AddDays(6);

                if (!Timesheet.WouldTimesheetSplit(timesheetMonth, monday, mondayPlus6))
                {
                    this.Add(monday, mondayPlus6, i);
                }
                else
                {
                    this.Add(monday, mondayPlus6, i, 0);
                    this.Add(monday, mondayPlus6, i, 1);
                }

                monday = monday.AddDays(7);                     // see if we can get the next Monday...
            }

            // Save the changes.
            XElement root = new XElement(this.ToXml());

            root.Save(fileName);
        }
Пример #3
0
 protected virtual void AttachChangedEvent(Timesheet timesheet)
 {
     timesheet.TimesheetChangedEvent += new EventHandler <TimesheetChangedEventArgs>(
         delegate(object sender, TimesheetChangedEventArgs e) {
         // If suspend changed event is not set, notify anyone who needs to know that
         // this monthly timesheet has changed...
         if (!this.IsSuspendChangedEvent && this.MonthlyTimesheetChangedEvent != null)
         {
             this.MonthlyTimesheetChangedEvent(this, new MonthlyTimesheetChangedEventArgs(this));
         }
     });
 }
Пример #4
0
        protected virtual void Add(Timesheet timesheet)
        {
            this.Timesheets.Add(timesheet);
            this.AttachChangedEvent(timesheet);

            // If suspend changed event is not set, notify anyone who needs to know that
            // this monthly timesheet has changed...
            if (!this.IsSuspendChangedEvent && this.MonthlyTimesheetChangedEvent != null)
            {
                this.MonthlyTimesheetChangedEvent(this, new MonthlyTimesheetChangedEventArgs(this));
            }
        }
Пример #5
0
        // Static Members
        // --------------------------------------------------------------------------
        #region Static Members
        static public string GetTimesheetWeekString(Timesheet timesheet)
        {
            lock (m_syncRoot) {
                TimesheetMonth timesheetMonth = timesheet.MonthlyTimesheets.TimesheetMonth;

                string fromDate = Helpers.Dates.GetMMDDYYYY(timesheet.StartDate.Date, '-');
                string toDate   = Helpers.Dates.GetMMDDYYYY(timesheet.EndDate.Date, '-');

                const string formatString = "Week {0} ({1} Through {2})";
                return(string.Format(formatString, timesheet.WeekNumber.ToString(), fromDate, toDate));
            }
        }
Пример #6
0
        /// <summary>
        /// Returns the default billable hours for the date.
        /// </summary>
        /// <param name="timesheet">The timesheet that the date falls under.</param>
        /// <param name="date">The date whose default billable hours are to be returned.</param>
        /// <returns>The default billable hours.</returns>
        static protected decimal GetBillableHoursDefault(Timesheet timesheet, DateTime date)
        {
            lock (m_syncRoot) {
                int year  = timesheet.MonthlyTimesheets.TimesheetMonth.Year;
                int month = timesheet.MonthlyTimesheets.TimesheetMonth.Month;
                if (date.Year != year || date.Month != month)
                {
                    // If the date to check does not fall within the timesheet, do not count hours for that day.
                    return(0m);
                }
                else if (date.DayOfWeek == DayOfWeek.Saturday || date.DayOfWeek == DayOfWeek.Sunday)
                {
                    // If the date falls on a weekend, do not count hours for that day.
                    return(0m);
                }
                else
                {
                    decimal defaultWorkDayHours = Configuration.Configuration.Instance.MiscellaneousConfiguration.DefaultWorkDayHours;

                    // Do split checking...
                    if (timesheet.IsSplitTimesheet)
                    {
                        // If we are working with a split timesheet and this is the FIRST of two split timesheets,
                        // all days less than or equal to the 15th (day <= 15) is billable...
                        if (timesheet.SplitIndex == 0)
                        {
                            return((date.Day > 15) ? 0m : defaultWorkDayHours);
                        }
                        else
                        {
                            // If we are working with a split timesheet and this is the SECOND of two split timesheets,
                            // all days greater than the 15th (day > 15) is billable...
                            return((date.Day > 15) ? defaultWorkDayHours : 0m);
                        }
                    }
                    else
                    {
                        // Return the default work day hours.
                        return(defaultWorkDayHours);
                    }
                }
            }
        }
Пример #7
0
        /// <summary>
        /// Returns the default invoive amount for the date.
        /// </summary>
        /// <param name="timesheet">The timesheet that the date falls under.</param>
        /// <param name="date">The date whose default invoice amount is to be returned.</param>
        /// <returns>The default invoice anount for the date.</returns>
        //static protected decimal GetInvoiceAmountDefault(Timesheet timesheet, DateTime date) {
        //   lock (m_syncRoot) {
        //      decimal defaultWorkDayHours = Configuration.Configuration.Instance.MiscellaneousConfiguration.DefaultWorkDayHours;
        //      decimal defaultDollarsPerHour = Configuration.Configuration.Instance.InvoiceConfiguration.Rate;
        //      return Timesheet.IsBillableDate(timesheet, date) ? defaultWorkDayHours * defaultDollarsPerHour : 0m;
        //   }
        //}

        static public bool IsBillableDate(Timesheet timesheet, DateTime date)
        {
            int year  = timesheet.MonthlyTimesheets.TimesheetMonth.Year;
            int month = timesheet.MonthlyTimesheets.TimesheetMonth.Month;

            if (date.Year != year || date.Month != month)
            {
                // If the date to check does not fall within the timesheet, we cannot claim an invoice amount for that date.
                return(false);
            }
            else if (date.DayOfWeek == DayOfWeek.Saturday || date.DayOfWeek == DayOfWeek.Sunday)
            {
                // If the date falls on a weekend, we cannot claim an invoice amount for that date.
                return(false);
            }
            else
            {
                // Return the default invoice amount.
                if (!timesheet.IsSplitTimesheet)
                {
                    return(true);
                }
                else if (timesheet.SplitIndex == 0)
                {
                    return(date.Day <= 15);
                }
                else if (timesheet.SplitIndex == 1)
                {
                    return(date.Day > 15);
                }
                else
                {
                    throw new Exception(string.Format("Unhandled condition in [{0}], Date: [{1}]", timesheet.GetFileName(), date.ToShortDateString()));
                }
            }
        }
Пример #8
0
        protected virtual void InitializeTimesheetDateValues()
        {
            foreach (TimesheetDate date in this.Dates)
            {
                decimal defaultBillableHours = Timesheet.GetBillableHoursDefault(this, date.Date);
                date.BillableHours = defaultBillableHours;

                // Attach to the TimesheetDateChangedEvent for the TimesheetDate. If it changes
                // from this point on, we need to inform anyone who needs to know that this timesheet
                // has changed...
                date.TimesheetDateChangedEvent += new EventHandler <TimesheetDateChangedEventArgs>(
                    delegate(object sender, TimesheetDateChangedEventArgs e) {
                    if (this.TimesheetChangedEvent != null)
                    {
                        this.TimesheetChangedEvent(this, new TimesheetChangedEventArgs(this));
                    }
                });
            }

            if (this.TimesheetChangedEvent != null)
            {
                this.TimesheetChangedEvent(this, new TimesheetChangedEventArgs(this));
            }
        }
 public TimesheetChangedEventArgs(Timesheet timesheet)
 {
     this.Timesheet = timesheet;
 }