protected void cvValidTimesFooter_ServerValidate(object source, ServerValidateEventArgs args)
        {
            args.IsValid = false;

            ProjectTimeGateway projectTimeGatewayForVerify = new ProjectTimeGateway();
            int employeeId = Int32.Parse(hdfEmployeeID.Value);
            int companyId = Int32.Parse(hdfCompanyId.Value);
            DateTime date_ = tkrdpStartDate.SelectedDate.Value;
            string startTimeFooter = "";
            string startHoursFooter = ""; if (((DropDownList)grdProjectTime.FooterRow.FindControl("ddlStartTimeHourFooter")).SelectedValue != "") startHoursFooter = ((DropDownList)grdProjectTime.FooterRow.FindControl("ddlStartTimeHourFooter")).SelectedValue.Trim();
            string startMinutesFooter = ""; if (((DropDownList)grdProjectTime.FooterRow.FindControl("ddlStartTimeMinuteFooter")).SelectedValue != "") startMinutesFooter = ((DropDownList)grdProjectTime.FooterRow.FindControl("ddlStartTimeMinuteFooter")).SelectedValue.Trim();

            string endTimeFooter = "";
            string endHoursFooter = ""; if (((DropDownList)grdProjectTime.FooterRow.FindControl("ddlEndTimeHourFooter")).SelectedValue != "") endHoursFooter = ((DropDownList)grdProjectTime.FooterRow.FindControl("ddlEndTimeHourFooter")).SelectedValue.Trim();
            string endMinutesFooter = ""; if (((DropDownList)grdProjectTime.FooterRow.FindControl("ddlEndTimeMinuteFooter")).SelectedValue != "") endMinutesFooter = ((DropDownList)grdProjectTime.FooterRow.FindControl("ddlEndTimeMinuteFooter")).SelectedValue.Trim();

            if ((startHoursFooter != "") && (startMinutesFooter != "") && (endHoursFooter != "") && (endMinutesFooter != ""))
            {
                startTimeFooter = startHoursFooter + ":" + startMinutesFooter;
                endTimeFooter = endHoursFooter + ":" + endMinutesFooter;

                // Verify if the time already exists at DB
                if (projectTimeGatewayForVerify.NotExistsByEmployeIdDate_StartTimeEndTime(employeeId, date_, startTimeFooter, endTimeFooter, companyId))
                {
                    args.IsValid = true;
                }

                if (args.IsValid)
                {
                    // Verify if it exist at last entered rows
                    ProjectTimeTemp modelForReview = new ProjectTimeTemp(projectTimeTDS);
                    if (modelForReview.NotExistsByEmployeIdDate_StartTimeEndTime(employeeId, date_, startTimeFooter, endTimeFooter))
                    {
                        args.IsValid = true;
                    }
                    else
                    {
                        args.IsValid = false;
                    }
                }
            }
        }
        private bool StepEndFinish()
        {
            lblError.Visible = false;
            lblError2.Visible = false;
            int companyId = Int32.Parse(hdfCompanyId.Value);

            if (ValidateStepEnd())
            {
                if (cbxEndConfirm.Checked)
                {
                    // Review all times
                    if (rbtnBeginTemplate.Checked)
                    {
                        if (grdProjectTime.Rows.Count > 0)
                        {
                            foreach (GridViewRow row in grdProjectTime.Rows)
                            {
                                if ((row.RowType == DataControlRowType.DataRow) && ((row.RowState == DataControlRowState.Normal) || (row.RowState == (DataControlRowState.Normal | DataControlRowState.Alternate))))
                                {
                                    ProjectTimeGateway projectTimeGatewayForVerify = new ProjectTimeGateway();
                                    int employeeId = 0; if (((HiddenField)row.FindControl("hdfEmployeeId")).Value.Trim() != "") employeeId = Int32.Parse(((HiddenField)row.FindControl("hdfEmployeeId")).Value.Trim());

                                    DateTime date_ = DateTime.Parse(tbxDate.Text);
                                    string startTime = ""; if (((TextBox)row.FindControl("tbxStartTime")).Text.Trim() != "") startTime = ((TextBox)row.FindControl("tbxStartTime")).Text.Trim();

                                    string endTime = ""; if (((TextBox)row.FindControl("tbxEndTime")).Text.Trim() != "") endTime = ((TextBox)row.FindControl("tbxEndTime")).Text.Trim();

                                    // Verify if the time not exists at DB
                                    if (projectTimeGatewayForVerify.NotExistsByEmployeIdDate_StartTimeEndTime(employeeId, date_, startTime, endTime, companyId))
                                    {
                                        // Verify Job Class
                                        EmployeeGateway employee = new EmployeeGateway();
                                        employee.LoadByEmployeeId(employeeId);
                                        string jobClass = employee.GetJobClassType(employeeId);

                                        if (jobClass == "")
                                        {
                                            lblError2.Visible = true;
                                            lblError2.Text = lblError2.Text + ((TextBox)row.FindControl("tbxTeamMember")).Text.Trim() + ", ";
                                        }
                                    }
                                    else
                                    {
                                        lblError.Visible = true;
                                        lblError.Text = lblError.Text + ((TextBox)row.FindControl("tbxTeamMember")).Text.Trim() + ", ";
                                    }
                                }
                            }
                        }
                    }
                }

                if ((lblError.Visible)||(lblError2.Visible))
                {
                    return false;
                }
                else
                {
                    if (PostStepEndChanges(companyId))
                    {
                        UpdateDatabase();
                        return true;
                    }
                    else
                    {
                       return false;
                    }
                }
            }
            else
            {
                return false;
            }
        }
        protected void cvValidTimesEdit_ServerValidate(object source, ServerValidateEventArgs args)
        {
            args.IsValid = false;

            if (grdProjectTime.Rows.Count > 0)
            {
                foreach (GridViewRow row in grdProjectTime.Rows)
                {
                    if ((row.RowType == DataControlRowType.DataRow) && ((row.RowState == DataControlRowState.Edit) || (row.RowState == (DataControlRowState.Edit | DataControlRowState.Alternate))))
                    {
                        ProjectTimeGateway projectTimeGatewayForVerify = new ProjectTimeGateway();
                        int employeeId = Int32.Parse(hdfEmployeeID.Value);
                        int companyId = Int32.Parse(hdfCompanyId.Value);
                        DateTime date_ = tkrdpStartDate.SelectedDate.Value;
                        string startTime = "";
                        string startHoursEdit = ""; if (((DropDownList)row.FindControl("ddlStartTimeHourEdit")).SelectedValue.Trim() != "") startHoursEdit = ((DropDownList)row.FindControl("ddlStartTimeHourEdit")).SelectedValue.Trim();
                        string startMinutesEdit = ""; if (((DropDownList)row.FindControl("ddlStartTimeMinuteEdit")).SelectedValue.Trim() != "") startMinutesEdit = ((DropDownList)row.FindControl("ddlStartTimeMinuteEdit")).SelectedValue.Trim();

                        if ((startHoursEdit != "") && (startMinutesEdit != ""))
                        {
                            startTime = startHoursEdit + ":" + startMinutesEdit;
                        }

                        string endTime = "";
                        string endHoursEdit = ""; if (((DropDownList)row.FindControl("ddlEndTimeHourEdit")).SelectedValue.Trim() != "") endHoursEdit = ((DropDownList)row.FindControl("ddlEndTimeHourEdit")).SelectedValue.Trim();
                        string endMinutesEdit = ""; if (((DropDownList)row.FindControl("ddlEndTimeMinuteEdit")).SelectedValue.Trim() != "") endMinutesEdit = ((DropDownList)row.FindControl("ddlEndTimeMinuteEdit")).SelectedValue.Trim();

                        if ((endHoursEdit != "") && (endMinutesEdit != ""))
                        {
                            endTime = endHoursEdit + ":" + endMinutesEdit;
                        }

                        // Verify if the time already exists at DB
                        if (projectTimeGatewayForVerify.NotExistsByEmployeIdDate_StartTimeEndTime(employeeId, date_, startTime, endTime, companyId))
                        {
                            args.IsValid = true;
                        }

                        int cant = 0;
                        if (args.IsValid)
                        {
                            // Verify if it exist at last entered rows
                            if (grdProjectTime.Rows.Count > 0)
                            {
                                foreach (GridViewRow rowTemp in grdProjectTime.Rows)
                                {
                                    if ((rowTemp.RowType == DataControlRowType.DataRow) && ((rowTemp.RowState == DataControlRowState.Normal) || (rowTemp.RowState == (DataControlRowState.Normal | DataControlRowState.Alternate))))
                                    {
                                        TimeSpan spanGridStartTime = TimeSpan.Parse(((TextBox)rowTemp.FindControl("tbxStartTime")).Text.Trim());
                                        TimeSpan spanGridEndTime = TimeSpan.Parse(((TextBox)rowTemp.FindControl("tbxEndTime")).Text.Trim());
                                        TimeSpan spanStartTime = TimeSpan.Parse(startTime);
                                        TimeSpan spanEndTime = TimeSpan.Parse(endTime);
                                        string twentyForHours = "23:59";
                                        TimeSpan midNight = TimeSpan.Parse(twentyForHours);

                                        if ((Int32.Parse(hdfEmployeeID.Value) == employeeId) && (tkrdpStartDate.SelectedDate.Value == date_))
                                        {
                                            // When End Time < StartTime   (when they finish work the next day)
                                            if ((spanGridEndTime < spanGridStartTime) && (spanEndTime > spanStartTime))
                                            {
                                                if (((spanStartTime >= spanGridStartTime) && (spanStartTime <= midNight)) || ((spanEndTime >= spanGridStartTime) && (spanEndTime <= midNight)))
                                                {
                                                    cant++;
                                                }
                                            }
                                            else
                                            {
                                                if ((spanEndTime < spanStartTime) && (spanGridEndTime > spanGridStartTime))
                                                {
                                                    if (((spanGridStartTime >= spanStartTime) && (midNight <= spanStartTime)) || ((spanGridStartTime >= spanEndTime) && (midNight <= spanEndTime)))
                                                    {
                                                        cant++;
                                                    }
                                                }
                                                else
                                                {
                                                    if (((spanGridEndTime < spanGridStartTime) && (spanEndTime < spanStartTime)))
                                                    {
                                                        cant++;
                                                    }
                                                    else
                                                    {
                                                        // When End Time > Start Time.  (times in the same day)
                                                        // ... If it's a valid entry
                                                        if (((spanStartTime < spanGridStartTime) && (spanEndTime <= spanGridStartTime)) || (spanStartTime >= spanGridEndTime) && (spanEndTime > spanGridEndTime))
                                                        {

                                                        }
                                                        else
                                                        {
                                                            // If the range exists
                                                            cant++;
                                                        }

                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }

                            if (cant == 0)
                            {
                                args.IsValid = true;
                            }
                            else
                            {
                                args.IsValid = false;
                            }
                        }
                    }
                }
            }
        }
        protected void cvValidTimesFooter_ServerValidate(object source, ServerValidateEventArgs args)
        {
            if (hdfBtnNext.Value == "True")
            {
                args.IsValid = true;
            }
            else
            {
                args.IsValid = false;

                ProjectTimeGateway projectTimeGatewayForVerify = new ProjectTimeGateway();
                int employeeId = 0; if (((DropDownList)grdProjectTime.FooterRow.FindControl("ddlEmployeesFooter")).SelectedValue.Trim() != "") employeeId = Int32.Parse(((DropDownList)grdProjectTime.FooterRow.FindControl("ddlEmployeesFooter")).SelectedValue.Trim());
                int companyId = Int32.Parse(hdfCompanyId.Value);
                DateTime date_ = DateTime.Parse(tbxDate.Text);
                string startTimeFooter = "";
                string startHoursFooter = ""; if (((DropDownList)grdProjectTime.FooterRow.FindControl("ddlStartTimeHourFooter")).SelectedValue != "") startHoursFooter = ((DropDownList)grdProjectTime.FooterRow.FindControl("ddlStartTimeHourFooter")).SelectedValue.Trim();
                string startMinutesFooter = ""; if (((DropDownList)grdProjectTime.FooterRow.FindControl("ddlStartTimeMinuteFooter")).SelectedValue != "") startMinutesFooter = ((DropDownList)grdProjectTime.FooterRow.FindControl("ddlStartTimeMinuteFooter")).SelectedValue.Trim();

                string endTimeFooter = "";
                string endHoursFooter = ""; if (((DropDownList)grdProjectTime.FooterRow.FindControl("ddlEndTimeHourFooter")).SelectedValue != "") endHoursFooter = ((DropDownList)grdProjectTime.FooterRow.FindControl("ddlEndTimeHourFooter")).SelectedValue.Trim();
                string endMinutesFooter = ""; if (((DropDownList)grdProjectTime.FooterRow.FindControl("ddlEndTimeMinuteFooter")).SelectedValue != "") endMinutesFooter = ((DropDownList)grdProjectTime.FooterRow.FindControl("ddlEndTimeMinuteFooter")).SelectedValue.Trim();

                if ((startHoursFooter != "") && (startMinutesFooter != "") && (endHoursFooter != "") && (endMinutesFooter != ""))
                {
                    startTimeFooter = startHoursFooter + ":" + startMinutesFooter;
                    endTimeFooter = endHoursFooter + ":" + endMinutesFooter;

                    // Verify if the time not exists at DB
                    if (projectTimeGatewayForVerify.NotExistsByEmployeIdDate_StartTimeEndTime(employeeId, date_, startTimeFooter, endTimeFooter, companyId))
                    {
                        args.IsValid = true;
                    }

                    if (args.IsValid)
                    {
                        // Verify if it exist at last entered rows
                        TeamProjectTime2DetailTemp teamProjectTime2DetailTemp = new TeamProjectTime2DetailTemp(teamProjectTime2TDS);
                        if (teamProjectTime2DetailTemp.NotExistsByEmployeIdDate_StartTime(employeeId, date_, startTimeFooter, endTimeFooter))
                        {
                            args.IsValid = true;
                        }
                        else
                        {
                            args.IsValid = false;
                        }
                    }
                }
            }
        }