private void GrdProjectTimeAdd()
        {
            Page.Validate("generalData");

            int projectId = int.Parse(ddlProject.SelectedValue);

            if (Page.IsValid)
            {
                Page.Validate("footerValidData");
                if (Page.IsValid)
                {
                    Page.Validate("footerData");
                    if (Page.IsValid)
                    {
                        // Validate project times
                        if (FooterValidate())
                        {
                            // Save data
                            int employeeId = Int32.Parse(hdfEmployeeID.Value);
                            int companiesId = int.Parse(ddlClient.SelectedValue);

                            if (projectId != 35 && projectId != 39 && projectId != 716)
                            {
                                DateTime date_ = tkrdpStartDate.SelectedDate.Value;
                                Int64? mealsCountry = null; if (ddlMealsCountry.SelectedValue != "-1") mealsCountry = Int64.Parse(ddlMealsCountry.SelectedValue);

                                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();

                                if ((startHoursFooter != "") && (startMinutesFooter != ""))
                                {
                                    startTimeFooter = startHoursFooter + ":" + startMinutesFooter;
                                }

                                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 ((endHoursFooter != "") && (endMinutesFooter != ""))
                                {
                                    endTimeFooter = endHoursFooter + ":" + endMinutesFooter;
                                }

                                decimal? offsetFooter = 0; if (((DropDownList)grdProjectTime.FooterRow.FindControl("ddlLunchFooter")).SelectedValue != "0") offsetFooter = Decimal.Round(decimal.Parse(((DropDownList)grdProjectTime.FooterRow.FindControl("ddlLunchFooter")).SelectedValue), 2);
                                double? offsetFooterFinal = null; if (offsetFooter.HasValue) offsetFooterFinal = double.Parse(((decimal)offsetFooter).ToString());
                                string typeOfWorkFooter = ((DropDownList)grdProjectTime.FooterRow.FindControl("ddlTypeOfWorkFooter")).SelectedValue;
                                int? unitIdFooter = null; if (((DropDownList)grdProjectTime.FooterRow.FindControl("ddlUnitFooter")).SelectedValue != "-1") unitIdFooter = Int32.Parse(((DropDownList)grdProjectTime.FooterRow.FindControl("ddlUnitFooter")).SelectedValue);
                                int? towedIdFooter = null; if (((DropDownList)grdProjectTime.FooterRow.FindControl("ddlTowedFooter")).SelectedValue != "-1") towedIdFooter = Int32.Parse(((DropDownList)grdProjectTime.FooterRow.FindControl("ddlTowedFooter")).SelectedValue);
                                string workingDetailsFooter = "Canada";
                                workingDetailsFooter = hdfWorkingDetails.Value;
                                bool isMealsAllowanceFooter = false;// ((CheckBox)grdProjectTime.FooterRow.FindControl("ckbxMealsAllowanceFooter")).Checked;
                                string commentsFooter = ((TextBox)grdProjectTime.FooterRow.FindControl("tbxCommentsFooter")).Text;
                                int companyId = Int32.Parse(hdfCompanyId.Value);

                                ProjectGateway projectGateway = new ProjectGateway(new DataSet());
                                projectGateway.LoadByProjectId(projectId);
                                bool fairWage = projectGateway.GetFairWageApplies(projectId);
                                string projectTimeState = "For Approval"; if ((string)ViewState["LHMode"] == "Partial") projectTimeState = "Approved";

                                string work_ = "";
                                string function_ = "";
                                if (typeOfWorkFooter != "(Select)" && typeOfWorkFooter != "")
                                {
                                    string[] workFunction = typeOfWorkFooter.ToString().Trim().Split('.');
                                    work_ = workFunction[0].Trim();
                                    function_ = workFunction[1].Trim();
                                }

                                CountryGateway countryGateway = new CountryGateway(new DataSet());
                                countryGateway.LoadByCountryId(projectGateway.GetCountryID(projectId));

                                string location = "";
                                if (countryGateway.Table.Rows.Count > 0)
                                {
                                    location = countryGateway.GetName(projectGateway.GetCountryID(projectId));
                                }

                                string mealsAllowanceType = ""; if (isMealsAllowanceFooter) mealsAllowanceType = "Full Day";
                                decimal mealsAllowance = MealsAllowance.GetMealsAllowance(mealsCountry, isMealsAllowanceFooter, "Full Day");

                                string jobClassType = ((DropDownList)grdProjectTime.FooterRow.FindControl("ddlJobClassTypeFooter")).SelectedValue;

                                // Insert Data
                                ProjectTimeTemp model = new ProjectTimeTemp(projectTimeTDS);
                                model.Insert(employeeId, companiesId, projectId, date_, startTimeFooter, endTimeFooter, offsetFooterFinal, workingDetailsFooter, location, mealsCountry, mealsAllowanceType, isMealsAllowanceFooter, mealsAllowance, unitIdFooter, towedIdFooter, projectTimeState, commentsFooter, work_, function_, typeOfWorkFooter, fairWage, jobClassType);

                                // Store Dataset
                                Session.Remove("projectTimeTempNewDummy");
                                Session["projectTimeTDS"] = projectTimeTDS;
                                Session["projectTimeTemp"] = projectTimeTDS.LFS_PROJECT_TIME_TEMP;

                                grdProjectTime.DataBind();
                                grdProjectTime.PageIndex = grdProjectTime.PageCount - 1;
                            }
                        }
                    }
                }

                hdfIsMoreThan15.Value = "false";
                upIsMoreThan15.Update();
            }
        }
        protected void cvAlreadyRegisteredMealsAllowanceEdit_ServerValidate(object source, ServerValidateEventArgs args)
        {
            args.IsValid = true;

            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))))
                    {
                        int companyId = Int32.Parse(hdfCompanyId.Value);
                        int employeeId = Int32.Parse(hdfEmployeeID.Value);
                        DateTime startDate = tkrdpStartDate.SelectedDate.Value;
                        DateTime lastDate = tkrdpEndDate.SelectedDate.Value;
                        bool isMealsAllowance = false;// ((CheckBox)row.FindControl("ckbxMealsAllowanceEdit")).Checked;
                        int projectTimeId2 = Int32.Parse(((Label)row.FindControl("lblProjectTimeIdEdit")).Text);
                        int projectId = int.Parse(ddlProject.SelectedValue);

                        if (projectId == 35 || projectId == 39 || projectId == 716)
                        {
                            if (isMealsAllowance)
                            {
                                args.IsValid = false;
                            }
                        }
                        else
                        {
                            string mealsCountry = ddlMealsCountry.SelectedValue;
                            int projectTimeId = -1;
                            args.IsValid = true;

                            ProjectTimeTemp projectTimeTemp = new ProjectTimeTemp(projectTimeTDS);
                            bool validMealsAllowance1 = projectTimeTemp.ValidateMealsAllowanceEdit(employeeId, isMealsAllowance, projectTimeId2);
                            if (validMealsAllowance1)
                            {
                                if ((mealsCountry != "-1") && (isMealsAllowance))
                                {
                                    ProjectTimeGateway projectTimeGateway = new ProjectTimeGateway();
                                    if (projectTimeId == -1)
                                    {
                                        if (projectTimeGateway.ExistsMealsAllowanceByEmployeIdDate(employeeId, startDate, companyId))
                                        {
                                            args.IsValid = false;
                                        }
                                    }
                                    else
                                    {
                                        if (projectTimeGateway.ExistsMealsAllowanceByProjectTimeIdEmployeIdDate(projectTimeId, employeeId, startDate, companyId))
                                        {
                                            args.IsValid = false;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        // ////////////////////////////////////////////////////////////////////////
        // NAVIGATION EVENTS
        //
        protected void tkrmTop_ItemClick(object sender, RadMenuEventArgs e)
        {
            DropDownList ddlOthersFor = (DropDownList)tkrpbLeftMenuOthersTimesheets.FindItemByValue("nbOthersTimesheetsDDL").FindControl("ddlOthersFor");
            Session["ddlOthersForSelectedValue"] = ddlOthersFor.SelectedValue;

            int employeeId = Int32.Parse(hdfEmployeeID.Value);
            int periodId = Int32.Parse(hdfPeriodId.Value);

            switch (e.Item.Value)
            {
                case "mSave":
                    if (ValidatePage())
                    {
                        int companiesId = int.Parse(ddlClient.SelectedValue);
                        int projectId = int.Parse(ddlProject.SelectedValue);

                        if (projectId == 35 || projectId == 39 || projectId == 716)
                        {
                            Page.Validate("specialData");

                            if (Page.IsValid)
                            {
                                DateTime startDate = tkrdpStartDate.SelectedDate.Value;
                                DateTime lastDate = tkrdpEndDate.SelectedDate.Value;
                                DateTime date_ = startDate;

                                while (date_ <= lastDate)
                                {
                                    Int64? mealsCountry = null;
                                    string startTimeFooter = "";
                                    string endTimeFooter = "";
                                    double? offsetFooterFinal = 0;
                                    string typeOfWorkFooter = "";
                                    int? unitIdFooter = null;
                                    int? towedIdFooter = null;
                                    string workingDetailsFooter = ddlWorkingDetails.SelectedValue;
                                    bool isMealsAllowanceFooter = false;
                                    string commentsFooter = tbxCommentsVacation.Text;
                                    int companyId = Int32.Parse(hdfCompanyId.Value);
                                    bool fairWage = false;
                                    string projectTimeState = "For Approval"; if ((string)ViewState["LHMode"] == "Partial") projectTimeState = "Approved";
                                    string work_ = "";
                                    string function_ = "";

                                    ProjectGateway projectGateway = new ProjectGateway(new DataSet());
                                    projectGateway.LoadByProjectId(projectId);
                                    CountryGateway countryGateway = new CountryGateway(new DataSet());
                                    countryGateway.LoadByCountryId(projectGateway.GetCountryID(projectId));

                                    string location = "";
                                    if (countryGateway.Table.Rows.Count > 0)
                                    {
                                        location = countryGateway.GetName(projectGateway.GetCountryID(projectId));
                                    }

                                    string mealsAllowanceType = "";
                                    decimal mealsAllowance = MealsAllowance.GetMealsAllowance(mealsCountry, isMealsAllowanceFooter, "Full Day");

                                    string jobClassType = ((DropDownList)grdProjectTime.FooterRow.FindControl("ddlJobClassTypeFooter")).SelectedValue;

                                    // Insert Data
                                    ProjectTimeTemp model = new ProjectTimeTemp(projectTimeTDS);
                                    model.Insert(employeeId, companiesId, projectId, date_, startTimeFooter, endTimeFooter, offsetFooterFinal, workingDetailsFooter, location, mealsCountry, mealsAllowanceType, isMealsAllowanceFooter, mealsAllowance, unitIdFooter, towedIdFooter, projectTimeState, commentsFooter, work_, function_, typeOfWorkFooter, fairWage, jobClassType);

                                    date_ = date_.AddDays(1);

                                    // ... ... Store Dataset
                                    Session.Remove("projectTimeTempNewDummy");
                                    Session["projectTimeTDS"] = projectTimeTDS;
                                    Session["projectTimeTemp"] = projectTimeTDS.LFS_PROJECT_TIME_TEMP;
                                }

                                PostPageChanges();
                                UpdateDatabase();

                                Response.Redirect("./../timesheet/timesheet.aspx?source_page=timesheet_add.aspx&others=" + ViewState["others"] + "&employee_id=" + employeeId.ToString() + "&period_id=" + periodId.ToString() + "&projecttime_id=" + DB.GetIdentCurrent("LFS_PROJECT_TIME").ToString());
                            }
                        }
                        else
                        {
                            // Project time Gridview, if the gridview is edition mode
                            if (grdProjectTime.EditIndex >= 0)
                            {
                                grdProjectTime.UpdateRow(grdProjectTime.EditIndex, true);
                            }

                            // Insert Data
                            GrdProjectTimeAdd();

                            PostPageChanges();
                            UpdateDatabase();

                            Response.Redirect("./../timesheet/timesheet.aspx?source_page=timesheet_add.aspx&others=" + ViewState["others"] + "&employee_id=" + employeeId.ToString() + "&period_id=" + periodId.ToString() + "&projecttime_id=" + DB.GetIdentCurrent("LFS_PROJECT_TIME").ToString());
                        }
                    }
                    break;

                case "mCancel":
                    if (Request.QueryString["source_page"] == "timesheet.aspx")
                    {
                        Response.Redirect("./../timesheet/timesheet.aspx?source_page=timesheet_add.aspx&others=" + ViewState["others"] + "&employee_id=" + employeeId.ToString() + "&period_id=" + periodId.ToString());
                    }
                    else
                    {
                        if (Request.QueryString["source_page"] == "timesheet_summary_from_approve_project_times.aspx")
                        {
                            Response.Redirect("./timesheet_summary.aspx?source_page=timesheet_approve.aspx&others=" + ViewState["others"] + "&employee_id=" + employeeId.ToString() + "&period_id=" + periodId.ToString() + "&projecttime_id=" + ViewState["projecttime_id"]);
                        }
                        else
                        {
                            Response.Redirect("./timesheet_summary.aspx?source_page=timesheet_add.aspx&others=" + ViewState["others"] + "&employee_id=" + employeeId.ToString() + "&period_id=" + periodId.ToString() + "&projecttime_id=" + ViewState["projecttime_id"]);
                        }
                    }
                    break;
            }
        }
        protected void cvDuplicateMealsAllowanceFooter_ServerValidate(object source, ServerValidateEventArgs args)
        {
            int employeeId = Int32.Parse(hdfEmployeeID.Value);
            bool isMealsAllowance = false;// ((CheckBox)grdProjectTime.FooterRow.FindControl("ckbxMealsAllowanceFooter")).Checked;

            ProjectTimeTemp projectTimeTemp = new ProjectTimeTemp(projectTimeTDS);
            bool validMealsAllowance1 = projectTimeTemp.ValidateMealsAllowance(employeeId, isMealsAllowance);

            args.IsValid = true;

            int projectId = int.Parse(ddlProject.SelectedValue);

            if (projectId == 35 || projectId == 39 || projectId == 716)
            {
                if (isMealsAllowance)
                {
                    args.IsValid = false;
                    CustomValidator cvAlreadyRegisterdMealsAllowanceEdit = (CustomValidator)source;
                    cvAlreadyRegisterdMealsAllowanceEdit.ErrorMessage = "Please don't select meals allowance.";
                }
            }
            else
            {
                if (!validMealsAllowance1)
                {
                    args.IsValid = false;
                }
            }
        }
        protected void grdProjectTime_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            Page.Validate("generalData");
            if (Page.IsValid)
            {
                Page.Validate("editValidData");
                if (Page.IsValid)
                {
                    Page.Validate("editData");
                    if (Page.IsValid)
                    {
                        int projectTimeId = (int)e.Keys["ProjectTimeID"];
                        int employeeId = Int32.Parse(hdfEmployeeID.Value);
                        int companiesId = int.Parse(ddlClient.SelectedValue);
                        int projectId = int.Parse(ddlProject.SelectedValue);
                        DateTime date_ = tkrdpStartDate.SelectedDate.Value;
                        string workingDetails = hdfWorkingDetails.Value;
                        if (projectId == 35 || projectId == 39 || projectId == 716)
                        {
                            Page.Validate("specialData");
                        }

                        if (Page.IsValid)
                        {
                            if (projectId == 35 || projectId == 39 || projectId == 716)
                            {
                                date_ = Convert.ToDateTime(((HiddenField)grdProjectTime.Rows[e.RowIndex].Cells[1].FindControl("hdfDateEdit")).Value);
                                workingDetails = ddlWorkingDetails.SelectedValue;
                            }
                            Int64? mealsCountry = null; if (ddlMealsCountry.SelectedValue != "-1") mealsCountry = Int64.Parse(ddlMealsCountry.SelectedValue);

                            string startTime = "";
                            string startHoursEdit = ((DropDownList)grdProjectTime.Rows[e.RowIndex].Cells[1].FindControl("ddlStartTimeHourEdit")).SelectedValue.Trim();
                            string startMinutesEdit = ((DropDownList)grdProjectTime.Rows[e.RowIndex].Cells[1].FindControl("ddlStartTimeMinuteEdit")).SelectedValue.Trim();

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

                            string endTime = "";
                            string endHoursEdit = ((DropDownList)grdProjectTime.Rows[e.RowIndex].Cells[1].FindControl("ddlEndTimeHourEdit")).SelectedValue.Trim();
                            string endMinutesEdit = ((DropDownList)grdProjectTime.Rows[e.RowIndex].Cells[1].FindControl("ddlEndTimeMinuteEdit")).SelectedValue.Trim();

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

                            decimal? offset = 0; if (((DropDownList)grdProjectTime.Rows[e.RowIndex].Cells[1].FindControl("ddlLunchEdit")).SelectedValue != "0") offset = decimal.Round(Decimal.Parse(((DropDownList)grdProjectTime.Rows[e.RowIndex].Cells[1].FindControl("ddlLunchEdit")).SelectedValue), 2);
                            double? offsetFinal = null; if (offset.HasValue) offsetFinal = double.Parse(((decimal)offset).ToString());
                            bool isMealsAllowance = false;// ((CheckBox)grdProjectTime.Rows[e.RowIndex].Cells[1].FindControl("ckbxMealsAllowanceEdit")).Checked;
                            int? unitId = null; if (((DropDownList)grdProjectTime.Rows[e.RowIndex].Cells[1].FindControl("ddlUnitEdit")).SelectedValue != "-1") unitId = Int32.Parse(((DropDownList)grdProjectTime.Rows[e.RowIndex].Cells[1].FindControl("ddlUnitEdit")).SelectedValue);
                            int? towedUnitId = null; if (((DropDownList)grdProjectTime.Rows[e.RowIndex].Cells[1].FindControl("ddlTowedEdit")).SelectedValue != "-1") towedUnitId = Int32.Parse(((DropDownList)grdProjectTime.Rows[e.RowIndex].Cells[1].FindControl("ddlTowedEdit")).SelectedValue);
                            string comments = ((TextBox)grdProjectTime.Rows[e.RowIndex].Cells[1].FindControl("tbxCommentsEdit")).Text;
                            string workFunctionConcat = ((DropDownList)grdProjectTime.Rows[e.RowIndex].Cells[1].FindControl("ddlTypeOfWorkFunctionEdit")).SelectedValue;

                            ProjectGateway projectGateway = new ProjectGateway(new DataSet());
                            projectGateway.LoadByProjectId(projectId);
                            bool fairWage = projectGateway.GetFairWageApplies(projectId);

                            string work_ = "";
                            string function_ = "";
                            if (workFunctionConcat != "(Select)" && workFunctionConcat != "")
                            {
                                string[] workFunction = workFunctionConcat.ToString().Trim().Split('.');
                                work_ = workFunction[0].Trim();
                                function_ = workFunction[1].Trim();
                            }

                            CountryGateway countryGateway = new CountryGateway(new DataSet());
                            countryGateway.LoadByCountryId(projectGateway.GetCountryID(projectId));
                            string location = countryGateway.GetName(projectGateway.GetCountryID(projectId));

                            string mealsAllowanceType = ""; if (isMealsAllowance) mealsAllowanceType = "Full Day";
                            decimal mealsAllowance = MealsAllowance.GetMealsAllowance(mealsCountry, isMealsAllowance, "Full Day");

                            string jobClassType = ((DropDownList)grdProjectTime.Rows[e.RowIndex].Cells[1].FindControl("ddlJobClassTypeEdit")).SelectedValue;

                            // Update data
                            ProjectTimeTemp model = new ProjectTimeTemp(projectTimeTDS);
                            model.Update(projectTimeId, companiesId, projectId, date_, startTime, endTime, offsetFinal, workingDetails, location, mealsCountry, mealsAllowanceType, isMealsAllowance, mealsAllowance, unitId, towedUnitId, comments, work_, function_, workFunctionConcat, fairWage, jobClassType);

                            // Store dataset
                            Session.Remove("projectTimeTempNewDummy");
                            Session["projectTimeTDS"] = projectTimeTDS;
                            Session["projectTimeTemp"] = projectTimeTDS.LFS_PROJECT_TIME_TEMP;
                        }
                        else
                        {
                            e.Cancel = true;
                        }
                    }
                    else
                    {
                        e.Cancel = true;
                    }
                }
                else
                {
                    e.Cancel = true;
                }
            }
            else
            {
                e.Cancel = true;
            }
        }
        protected void grdProjectTime_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            // Project Time Gridview, if the gridview is edition mode
            if (grdProjectTime.EditIndex >= 0)
            {
                grdProjectTime.UpdateRow(grdProjectTime.EditIndex, true);
            }

            // Delete project time
            int projectTimeId = (int)e.Keys["ProjectTimeID"];

            ProjectTimeTemp model = new ProjectTimeTemp(projectTimeTDS);
            model.Delete(projectTimeId);

            // Store dataset
            Session["projectTimeTDS"] = projectTimeTDS;
            Session["projectTimeTemp"] = projectTimeTDS.LFS_PROJECT_TIME_TEMP;
        }
        protected void cvDuplicateMealsAllowanceEdit_ServerValidate(object source, ServerValidateEventArgs args)
        {
            args.IsValid = true;

            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))))
                    {
                        int employeeId = Int32.Parse(hdfEmployeeID.Value);
                        bool isMealsAllowance = false;// ((CheckBox)row.FindControl("ckbxMealsAllowanceEdit")).Checked;
                        int projectTimeId = Int32.Parse(((Label)row.FindControl("lblProjectTimeIdEdit")).Text);
                        int projectId = int.Parse(ddlProject.SelectedValue);

                        if (projectId == 35 || projectId == 39 || projectId == 716)
                        {
                            if (isMealsAllowance)
                            {
                                args.IsValid = false;
                                CustomValidator cvAlreadyRegisterdMealsAllowanceEdit = (CustomValidator)source;
                                cvAlreadyRegisterdMealsAllowanceEdit.ErrorMessage = "Please don't select meals allowance.";
                            }
                        }
                        else
                        {
                            ProjectTimeTemp projectTimeTemp = new ProjectTimeTemp(projectTimeTDS);
                            bool validMealsAllowance1 = projectTimeTemp.ValidateMealsAllowanceEdit(employeeId, isMealsAllowance, projectTimeId);

                            args.IsValid = true;
                            if (!validMealsAllowance1)
                            {
                                args.IsValid = false;
                            }
                        }
                    }
                }
            }
        }
        protected void cvAlreadyRegisteredMealsAllowanceFooter_ServerValidate(object source, ServerValidateEventArgs args)
        {
            int companyId = Int32.Parse(hdfCompanyId.Value);
            int employeeId = Int32.Parse(hdfEmployeeID.Value);
            DateTime startDate = tkrdpStartDate.SelectedDate.Value;
            DateTime lastDate = tkrdpEndDate.SelectedDate.Value;
            bool isMealsAllowance = false;// ((CheckBox)grdProjectTime.FooterRow.FindControl("ckbxMealsAllowanceFooter")).Checked;
            string mealsCountry = ddlMealsCountry.SelectedValue;
            int projectTimeId = -1;
            args.IsValid = true;

            int projectId = int.Parse(ddlProject.SelectedValue);

            if (projectId == 35 || projectId == 39 || projectId == 716)
            {
                if (isMealsAllowance)
                {
                    args.IsValid = false;
                }
            }
            else
            {
                ProjectTimeTemp projectTimeTemp = new ProjectTimeTemp(projectTimeTDS);
                bool validMealsAllowance1 = projectTimeTemp.ValidateMealsAllowance(employeeId, isMealsAllowance);
                if (validMealsAllowance1)
                {
                    if ((mealsCountry != "-1") && (isMealsAllowance))
                    {
                        ProjectTimeGateway projectTimeGateway = new ProjectTimeGateway();
                        if (projectTimeId == -1)
                        {
                            if (projectTimeGateway.ExistsMealsAllowanceByEmployeIdDate(employeeId, startDate, companyId))
                            {
                                args.IsValid = false;
                            }
                        }
                        else
                        {
                            if (projectTimeGateway.ExistsMealsAllowanceByProjectTimeIdEmployeIdDate(projectTimeId, employeeId, startDate, companyId))
                            {
                                args.IsValid = false;
                            }
                        }
                    }
                }
            }
        }
        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;
                    }
                }
            }
        }