//*******************************************************
        //
        // The Page_Load server event handler on this page is used
        // to populate information fields on this page
        //
        //*******************************************************

        protected void Page_Load(object sender, System.EventArgs e)
        {
            _user = new ITUser(
                ITSecurity.GetUserID(),
                User.Identity.Name,
                ITSecurity.GetName(),
                ITSecurity.GetUserRole(),
                "",
                ""
                );

            if (!Page.IsPostBack)
            {
                // If page is loaded for the first time, select the current week.
                BusinessLogicLayer.TimeEntry.FillCorrectStartEndDates(DateTime.Today,
                                                                      ref _weekStartingDate, ref _weekEndingDate);
                WeekEnding.Text = _weekEndingDate.ToShortDateString();

                BindUserList();
                BindEntryFields();
                BindTimeSheet(_user.UserID, _weekStartingDate, _weekEndingDate);
            }
            else
            {
                // Selects the weekending date, corresponding to week user selected.
                BusinessLogicLayer.TimeEntry.FillCorrectStartEndDates(Convert.ToDateTime(WeekEnding.Text),
                                                                      ref _weekStartingDate, ref _weekEndingDate);
                _dayListTable = BusinessLogicLayer.TimeEntry.GetWeek(Convert.ToDateTime(WeekEnding.Text));
            }
        }
        private void AddEntryActivity(int userId, int projectId, int categoryId, DateTime date, string description, decimal hours)
        {
            BusinessLogicLayer.TimeEntry te = new BusinessLogicLayer.TimeEntry(0,
                                                                               userId,
                                                                               projectId,
                                                                               categoryId,
                                                                               date,
                                                                               ITSecurity.CleanStringRegex(description),
                                                                               hours
                                                                               );

            te.Save();
        }
        //*******************************************************
        //
        // TimeEntryGrid_OnUpdate server event handler on this page is used to
        // update the changes made from in-line-editing.
        //
        //*******************************************************

        protected void TimeEntryGrid_OnUpdate(Object sender, DataGridCommandEventArgs e)
        {
            DataGridItem item = TimeEntryGrid.Items[TimeEntryGrid.EditItemIndex];

            RequiredFieldValidator required = (RequiredFieldValidator)item.FindControl("RequiredFieldValidatorGridHours");
            CompareValidator       comparer = (CompareValidator)item.FindControl("CompareValidatorGridHours");

            required.Validate();
            comparer.Validate();

            // Check for validation, if all valid, update the object to data entered and save it.
            if (required.IsValid && comparer.IsValid)
            {
                int      entryLogID;
                int      userID;
                int      projectID;
                int      categoryID;
                DateTime taskDate;
                string   description;
                decimal  duration;
                BusinessLogicLayer.TimeEntry te = null;

                // Fill in properties for TimeEntry object.
                entryLogID  = Convert.ToInt32(TimeEntryGrid.DataKeys[(int)e.Item.ItemIndex]);
                userID      = Convert.ToInt32(UserList.SelectedItem.Value);
                projectID   = Convert.ToInt32(((DropDownList)e.Item.FindControl("EntryProjects")).SelectedItem.Value);
                categoryID  = Convert.ToInt32(((DropDownList)e.Item.FindControl("EntryCategories")).SelectedItem.Value);
                taskDate    = Convert.ToDateTime(((DropDownList)e.Item.FindControl("EntryDays")).SelectedItem.Value);
                description = ITSecurity.CleanStringRegex(((TextBox)e.Item.FindControl("EntryDescription")).Text);
                duration    = Convert.ToDecimal(((TextBox)e.Item.FindControl("EntryHours")).Text);

                // Save the TimeEntry object.
                te = new BusinessLogicLayer.TimeEntry(entryLogID, userID, projectID, categoryID, taskDate, description, duration);
                te.Save();

                // Quit in-line-editing mode.
                TimeEntryGrid.EditItemIndex = -1;
                BindTimeSheet(_user.UserID, Convert.ToInt32(UserList.SelectedItem.Value), _weekStartingDate, _weekEndingDate);
            }
        }
        //*******************************************************
        //
        // AddEntry_Click server event handler on this page is used to
        // saves a time entry and adds it to the system.
        //
        //*******************************************************

        protected void AddEntry_Click(object sender, System.EventArgs e)
        {
            // check validation.
            Requiredfieldvalidator1.Validate();
            RequiredFieldValidator2.Validate();
            RangeValidator1.Validate();
            CompareValidator1.Validate();

            // proceeds if data is valid then create an obejct and save it.
            if (Requiredfieldvalidator1.IsValid && RequiredFieldValidator2.IsValid && CompareValidator1.IsValid && RangeValidator1.IsValid)
            {
                BusinessLogicLayer.TimeEntry te = new BusinessLogicLayer.TimeEntry(0,
                                                                                   Convert.ToInt32(UserList.SelectedItem.Value),
                                                                                   Convert.ToInt32(ProjectList.SelectedItem.Value),
                                                                                   Convert.ToInt32(CategoryList.SelectedItem.Value),
                                                                                   Convert.ToDateTime(Days.SelectedItem.Value),
                                                                                   ITSecurity.CleanStringRegex(Description.Text), Convert.ToDecimal(Hours.Text));
                te.Save();

                ClearEntryFields();
            }
        }