Beispiel #1
0
        /// <summary>
        /// Generate Project Number for new Project
        /// </summary>
        /// <param name="countryId">CountryId</param>
        /// <param name="officeId">OfficeId</param>
        /// <param name="salesmanId">SalesmanId - EmployeeId</param>
        /// <param name="date">Date to generate</param>
        /// <param name="companyId">companyId</param>
        /// <returns>Project Number generated</returns>
        public string GenerateProjectNumber(Int64 countryId, int officeId, int salesmanId, DateTime date, int companyId)
        {
            CountryGateway countryGateway = new CountryGateway(new DataSet());
            countryGateway.LoadByCountryId(countryId);
            string pnCountryId = countryGateway.GetIdForProjects(countryId);

            OfficeGateway officeGateway = new OfficeGateway(new DataSet());
            officeGateway.LoadByOfficeId(officeId);
            string pnOfficeId = officeGateway.GetIdForProjects(officeId);

            SalesmanGateway salesmanGateway = new SalesmanGateway(new DataSet());
            salesmanGateway.LoadBySalesmanId(salesmanId);
            string pnSalesmanId = salesmanGateway.GetIdForProjects(salesmanId);

            ProjectNumberGateway projectNumberGateway = new ProjectNumberGateway(Data);
            projectNumberGateway.Load();
            ProjectNumber projectNumber = new ProjectNumber(Data);
            string pnYearCode = projectNumber.GetYearCode(date.Year);
            string pnProjectIncrement = projectNumber.GetProjectIncrement(date.Year, companyId);

            string newProjectNumber = pnCountryId + pnOfficeId + pnSalesmanId + pnYearCode + pnProjectIncrement;

            return newProjectNumber;
        }
        private void LoadDetailedData(int unitId)
        {
            UnitInformationUnitDetailsGateway unitInformationUnitDetailsGateway = new UnitInformationUnitDetailsGateway(unitInformationTDS);
            if (unitInformationUnitDetailsGateway.Table.Rows.Count > 0)
            {
                // Load for General Tab
                if (unitInformationUnitDetailsGateway.GetAcquisitionDate(unitId).HasValue) tbxAcquisitionDate.Text = ((DateTime)unitInformationUnitDetailsGateway.GetAcquisitionDate(unitId)).ToShortDateString();
                if (unitInformationUnitDetailsGateway.GetDispositionDate(unitId).HasValue) tbxDispositionDate.Text = ((DateTime)unitInformationUnitDetailsGateway.GetDispositionDate(unitId)).ToShortDateString();
                tbxDispositionReason.Text = unitInformationUnitDetailsGateway.GetDispositionReason(unitId);
                int companyLevelId = unitInformationUnitDetailsGateway.GetCompanyLevelId(unitId);

                GetNodeForCategory(tvCategoriesRoot.Nodes, 0);
                GetNodeForCompanyLevels(tvCompanyLevelsRoot.Nodes, 0, companyLevelId);

                foreach (TreeNode nodes in tvCategoriesRoot.Nodes)
                {
                    GetCategoriesParent(nodes);
                }

                foreach (TreeNode nodes in tvCompanyLevelsRoot.Nodes)
                {
                    GetCompanyLevelsParent(nodes);
                }

                // Load for Plate and Technical Tabs
                if (unitInformationUnitDetailsGateway.GetType(unitId) == "Vehicle")
                {
                    if (unitInformationUnitDetailsGateway.GetLicenseCountry(unitId).HasValue)
                    {
                        Int64 countryId = (Int64)unitInformationUnitDetailsGateway.GetLicenseCountry(unitId);
                        CountryGateway countryGateway = new CountryGateway();
                        countryGateway.LoadByCountryId(countryId);
                        tbxLicenseCountry.Text = countryGateway.GetName(countryId);
                    }

                    if (unitInformationUnitDetailsGateway.GetLicenseState(unitId).HasValue)
                    {
                        Int64 stateId = (Int64)unitInformationUnitDetailsGateway.GetLicenseState(unitId);
                        ProvinceGateway provinceGateway = new ProvinceGateway();
                        provinceGateway.LoadByProvinceId(stateId);
                        tbxLicenseState.Text = provinceGateway.GetName(stateId);
                    }

                    tbxLicensePlateNumber.Text = unitInformationUnitDetailsGateway.GetLicensePlateNumbver(unitId);
                    tbxActualWeight.Text = unitInformationUnitDetailsGateway.GetActualWeight(unitId);
                    tbxRegisteredWeight.Text = unitInformationUnitDetailsGateway.GetRegisteredWeight(unitId);
                    tbxTireSizeFront.Text = unitInformationUnitDetailsGateway.GetTireSizeFront(unitId);
                    tbxTireSizeBack.Text = unitInformationUnitDetailsGateway.GetTireSizeBack(unitId);
                    tbxNumberOfAxes.Text = unitInformationUnitDetailsGateway.GetNumberOfAxes(unitId);
                    tbxFuelType.Text = unitInformationUnitDetailsGateway.GetFuelType(unitId);
                    tbxBeginningOdometer.Text = unitInformationUnitDetailsGateway.GetBeginningOdometer(unitId);
                    cbxIsReeferEquipped.Checked = unitInformationUnitDetailsGateway.GetIsReeferEquipped(unitId);
                    cbxIsPtoEquipped.Checked = unitInformationUnitDetailsGateway.GetIsPTOEquipped(unitId);

                }

                // Load for Ownership tab
                tbxOwnerType.Text = unitInformationUnitDetailsGateway.GetOwnerType(unitId);
                tbxOwnerName.Text = unitInformationUnitDetailsGateway.GetOwnerName(unitId);
                tbxOwnerContact.Text = unitInformationUnitDetailsGateway.GetOwnerContact(unitId);

                if (unitInformationUnitDetailsGateway.GetOwnerCountry(unitId).HasValue)
                {
                    Int64 countryId = (Int64)unitInformationUnitDetailsGateway.GetOwnerCountry(unitId);
                    CountryGateway countryGateway = new CountryGateway();
                    countryGateway.LoadByCountryId(countryId);
                    tbxOwnerCountry.Text = countryGateway.GetName(countryId);

                    if (unitInformationUnitDetailsGateway.GetOwnerState(unitId).HasValue)
                    {
                        Int64 stateId = (Int64)unitInformationUnitDetailsGateway.GetOwnerState(unitId);
                        ProvinceGateway provinceGateway = new ProvinceGateway();
                        provinceGateway.LoadByProvinceId(stateId);
                        tbxOwnerState.Text = provinceGateway.GetName(stateId);
                    }
                }

                // Load for Inspection Tab (Qualification data)
                if (unitInformationUnitDetailsGateway.GetQualifiedDate(unitId).HasValue) tbxQualifiedDate.Text = ((DateTime)unitInformationUnitDetailsGateway.GetQualifiedDate(unitId)).ToShortDateString();
                if (unitInformationUnitDetailsGateway.GetNotQualifiedDate(unitId).HasValue) tbxNotQualifiedDate.Text = ((DateTime)unitInformationUnitDetailsGateway.GetNotQualifiedDate(unitId)).ToShortDateString();
                tbxIfNotQualifiedExplain.Text = unitInformationUnitDetailsGateway.GetNotQualifiedExplain(unitId);
            }
        }
        private void LoadDetailedData(int unitId)
        {
            UnitInformationUnitDetailsGateway unitInformationUnitDetailsGateway = new UnitInformationUnitDetailsGateway(unitInformationTDS);
            if (unitInformationUnitDetailsGateway.Table.Rows.Count > 0)
            {
                // Load for General Tab
                if (upnlGeneralDataEdit.Visible)
                {
                    if (unitInformationUnitDetailsGateway.GetAcquisitionDate(unitId).HasValue)
                    {
                        tkrdpAcquisitionDate.SelectedDate = unitInformationUnitDetailsGateway.GetAcquisitionDate(unitId);
                    }

                    if (unitInformationUnitDetailsGateway.GetDispositionDate(unitId).HasValue)
                    {
                        tkrdpDispositionDate.SelectedDate = unitInformationUnitDetailsGateway.GetDispositionDate(unitId);
                    }

                    tbxDispositionReason.Text = unitInformationUnitDetailsGateway.GetDispositionReason(unitId);
                    int companyLevelId = unitInformationUnitDetailsGateway.GetCompanyLevelId(unitId);

                    GetNodeForCategory(tvCategoriesRoot.Nodes, 0);
                    GetNodeForCompanyLevels(tvCompanyLevelsRoot.Nodes, 0, companyLevelId);

                    foreach (TreeNode nodes in tvCategoriesRoot.Nodes)
                    {
                        GetCategoriesParent(nodes);
                    }

                    foreach (TreeNode nodes in tvCompanyLevelsRoot.Nodes)
                    {
                        GetCompanyLevelsParent(nodes);
                    }
                }
                else
                {
                    if (unitInformationUnitDetailsGateway.GetAcquisitionDate(unitId).HasValue) tbxAcquisitionDateSummary.Text = ((DateTime)unitInformationUnitDetailsGateway.GetAcquisitionDate(unitId)).ToShortDateString();
                    if (unitInformationUnitDetailsGateway.GetDispositionDate(unitId).HasValue) tbxDispositionDateSummary.Text = ((DateTime)unitInformationUnitDetailsGateway.GetDispositionDate(unitId)).ToShortDateString();
                    tbxDispositionReasonSummary.Text = unitInformationUnitDetailsGateway.GetDispositionReason(unitId);
                    int companyLevelId = unitInformationUnitDetailsGateway.GetCompanyLevelId(unitId);

                    GetNodeForCategory(tvCategoriesRootSummary.Nodes, 0);
                    GetNodeForCompanyLevels(tvCompanyLevelsRootSummary.Nodes, 0, companyLevelId);

                    foreach (TreeNode nodes in tvCategoriesRootSummary.Nodes)
                    {
                        GetCategoriesParent(nodes);
                    }

                    foreach (TreeNode nodes in tvCompanyLevelsRootSummary.Nodes)
                    {
                        GetCompanyLevelsParent(nodes);
                    }
                }

                // Load for Plate and Technical Tabs
                if (unitInformationUnitDetailsGateway.GetType(unitId) == "Vehicle")
                {
                    if (upnlPlateDataEdit.Visible)
                    {
                        if (unitInformationUnitDetailsGateway.GetLicenseCountry(unitId).HasValue)
                        {
                            Int64 countryId = (Int64)unitInformationUnitDetailsGateway.GetLicenseCountry(unitId);
                            ddlLicenseCountry.SelectedValue = countryId.ToString();

                            if (unitInformationUnitDetailsGateway.GetLicenseState(unitId).HasValue)
                            {
                                Int64? stateId = null;

                                stateId = unitInformationUnitDetailsGateway.GetLicenseState(unitId);

                                if (stateId.HasValue)
                                {
                                    tbxLicenseState.Text = "";
                                    hdfLicenseStateId.Value = "";

                                    if (stateId.ToString() == "12435")
                                    {
                                        tbxLicenseState.Text = "Ontario";
                                        hdfLicenseStateId.Value = "12435";
                                    }
                                    else
                                    {
                                        if (ddlLicenseCountry.SelectedValue == "2")
                                        {
                                            tbxLicenseState.Text = "Michigan";
                                            hdfLicenseStateId.Value = "84026";
                                        }
                                    }
                                }
                            }
                        }

                        tbxLicensePlateNumber.Text = unitInformationUnitDetailsGateway.GetLicensePlateNumbver(unitId);
                    }
                    else
                    {
                        if (unitInformationUnitDetailsGateway.GetLicenseCountry(unitId).HasValue)
                        {
                            Int64 countryId = (Int64)unitInformationUnitDetailsGateway.GetLicenseCountry(unitId);
                            CountryGateway countryGateway = new CountryGateway();
                            countryGateway.LoadByCountryId(countryId);
                            tbxLicenseCountrySummary.Text = countryGateway.GetName(countryId);
                        }

                        if (unitInformationUnitDetailsGateway.GetLicenseState(unitId).HasValue)
                        {
                            Int64 stateId = (Int64)unitInformationUnitDetailsGateway.GetLicenseState(unitId);
                            ProvinceGateway provinceGateway = new ProvinceGateway();
                            provinceGateway.LoadByProvinceId(stateId);
                            tbxLicenseStateSummary.Text = provinceGateway.GetName(stateId);
                        }

                        tbxLicensePlateNumberSummary.Text = unitInformationUnitDetailsGateway.GetLicensePlateNumbver(unitId);
                    }

                    if (upnlTechnicalEdit.Visible)
                    {
                        tbxActualWeight.Text = unitInformationUnitDetailsGateway.GetActualWeight(unitId);
                        tbxRegisteredWeight.Text = unitInformationUnitDetailsGateway.GetRegisteredWeight(unitId);
                        tbxTireSizeFront.Text = unitInformationUnitDetailsGateway.GetTireSizeFront(unitId);
                        tbxTireSizeBack.Text = unitInformationUnitDetailsGateway.GetTireSizeBack(unitId);
                        ddlNumberOfAxes.SelectedValue = unitInformationUnitDetailsGateway.GetNumberOfAxes(unitId);
                        ddlFuelType.SelectedValue = unitInformationUnitDetailsGateway.GetFuelType(unitId);
                        tbxBeginningOdometer.Text = unitInformationUnitDetailsGateway.GetBeginningOdometer(unitId);
                        cbxIsReeferEquipped.Checked = unitInformationUnitDetailsGateway.GetIsReeferEquipped(unitId);
                        cbxIsPtoEquipped.Checked = unitInformationUnitDetailsGateway.GetIsPTOEquipped(unitId);
                    }
                    else
                    {
                        tbxActualWeightSummary.Text = unitInformationUnitDetailsGateway.GetActualWeight(unitId);
                        tbxRegisteredWeightSummary.Text = unitInformationUnitDetailsGateway.GetRegisteredWeight(unitId);
                        tbxTireSizeFrontSummary.Text = unitInformationUnitDetailsGateway.GetTireSizeFront(unitId);
                        tbxTireSizeBackSummary.Text = unitInformationUnitDetailsGateway.GetTireSizeBack(unitId);
                        tbxNumberOfAxesSummary.Text = unitInformationUnitDetailsGateway.GetNumberOfAxes(unitId);
                        tbxFuelTypeSummary.Text = unitInformationUnitDetailsGateway.GetFuelType(unitId);
                        tbxBeginningOdometerSummary.Text = unitInformationUnitDetailsGateway.GetBeginningOdometer(unitId);
                        cbxIsReeferEquippedSummary.Checked = unitInformationUnitDetailsGateway.GetIsReeferEquipped(unitId);
                        cbxIsPtoEquippedSummary.Checked = unitInformationUnitDetailsGateway.GetIsPTOEquipped(unitId);
                    }
                }

                // Load for Ownership tab
                if (upnlOwnershipEdit.Visible)
                {
                    ddlOwnerType.SelectedValue = unitInformationUnitDetailsGateway.GetOwnerType(unitId);
                    tbxOwnerName.Text = unitInformationUnitDetailsGateway.GetOwnerName(unitId);
                    tbxOwnerContact.Text = unitInformationUnitDetailsGateway.GetOwnerContact(unitId);

                    if (unitInformationUnitDetailsGateway.GetOwnerCountry(unitId).HasValue)
                    {
                        Int64 countryId = (Int64)unitInformationUnitDetailsGateway.GetOwnerCountry(unitId);
                        ddlOwnerCountry.SelectedValue = countryId.ToString();

                        ProvinceList provinceList = new ProvinceList();
                        provinceList.LoadByCountryIdAndAddItem(-1, "(Select a state)", countryId);
                        ddlOwnerState.DataSource = provinceList.Table;
                        ddlOwnerState.DataValueField = "ProvinceID";
                        ddlOwnerState.DataTextField = "Name";
                        ddlOwnerState.DataBind();

                        if (unitInformationUnitDetailsGateway.GetOwnerState(unitId).HasValue)
                        {
                            Int64 stateId = (Int64)unitInformationUnitDetailsGateway.GetOwnerState(unitId);
                            ddlOwnerState.SelectedValue = stateId.ToString();
                        }
                    }
                }
                else
                {
                    tbxOwnerTypeSummary.Text = unitInformationUnitDetailsGateway.GetOwnerType(unitId);
                    tbxOwnerNameSummary.Text = unitInformationUnitDetailsGateway.GetOwnerName(unitId);
                    tbxContactInfoSummary.Text = unitInformationUnitDetailsGateway.GetOwnerContact(unitId);

                    if (unitInformationUnitDetailsGateway.GetOwnerCountry(unitId).HasValue)
                    {
                        Int64 countryId = (Int64)unitInformationUnitDetailsGateway.GetOwnerCountry(unitId);
                        CountryGateway countryGateway = new CountryGateway();
                        countryGateway.LoadByCountryId(countryId);
                        tbxOwnerCountrySummary.Text = countryGateway.GetName(countryId);

                        if (unitInformationUnitDetailsGateway.GetOwnerState(unitId).HasValue)
                        {
                            Int64 stateId = (Int64)unitInformationUnitDetailsGateway.GetOwnerState(unitId);
                            ProvinceGateway provinceGateway = new ProvinceGateway();
                            provinceGateway.LoadByProvinceId(stateId);
                            tbxOwnerStateSummary.Text = provinceGateway.GetName(stateId);
                        }
                    }
                }

                // Load for Inspection Tab (Qualification data)
                if (upnlInspectionEdit.Visible)
                {
                    if (unitInformationUnitDetailsGateway.GetQualifiedDate(unitId).HasValue)
                    {
                        tkrdpQualifiedDate.SelectedDate = unitInformationUnitDetailsGateway.GetQualifiedDate(unitId);
                    }

                    if (unitInformationUnitDetailsGateway.GetNotQualifiedDate(unitId).HasValue)
                    {
                        tkrdpNotQualifiedDate.SelectedDate = (DateTime)unitInformationUnitDetailsGateway.GetNotQualifiedDate(unitId);
                    }

                    tbxIfNotQualifiedExplain.Text = unitInformationUnitDetailsGateway.GetNotQualifiedExplain(unitId);
                }
                else
                {
                    if (unitInformationUnitDetailsGateway.GetQualifiedDate(unitId).HasValue) tbxQualifiedDateSummary.Text = ((DateTime)unitInformationUnitDetailsGateway.GetQualifiedDate(unitId)).ToShortDateString();
                    if (unitInformationUnitDetailsGateway.GetNotQualifiedDate(unitId).HasValue) tbxNotQualifiedDateSummary.Text = ((DateTime)unitInformationUnitDetailsGateway.GetNotQualifiedDate(unitId)).ToShortDateString();
                    tbxIfNotQualifiedExplainSummary.Text = unitInformationUnitDetailsGateway.GetNotQualifiedExplain(unitId);
                }
            }
        }
        // ////////////////////////////////////////////////////////////////////////
        // EVENTS
        //
        protected void Page_Load(object sender, EventArgs e)
        {
            // Register client scripts
            this.RegisterClientScripts();

            if (!IsPostBack)
            {
                // Validate query string
                if (((string)Request.QueryString["source_page"] == null) && ((string)Request.QueryString["others"] == null) && ((string)Request.QueryString["employee_id"] == null) && ((string)Request.QueryString["period_id"] == null) && ((string)Request.QueryString["projecttime_id"] == null))
                {
                    Response.Redirect("./../../error_page.aspx?error=" + "Invalid query string in timesheet_summary.aspx");
                }

                // Security check
                if (!Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_FULL_EDITING"]))
                {
                    if (Request.QueryString["others"] == "no")
                    {
                        if (!Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_MY_TIMESHEETS_VIEW"]))
                        {
                            if (!Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_MY_TIMESHEETS_MANAGEMENT"]))
                            {
                                if (!Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_MY_TIMESHEETS_MANAGEMENT_WED"]))
                                {
                                    Response.Redirect("./../../error_page.aspx?error=" + "You are not authorized to view this page. Contact your system administrator.");
                                }
                            }
                        }
                    }
                    else
                    {
                        if (!Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_MY_TIMESHEETS_VIEW"]))
                        {
                            if (!Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_MY_TIMESHEETS_MANAGEMENT"]))
                            {
                                if (!Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_MY_TIMESHEETS_MANAGEMENT_WED"]))
                                {
                                    if (!Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_OTHERS_TIMESHEETS_VIEW"]))
                                    {
                                        if (!Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_OTHERS_TIMESHEETS_MANAGEMENT"]))
                                        {
                                            if (!Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_OTHERS_TIMESHEETS_MANAGEMENT_WED"]))
                                            {
                                                Response.Redirect("./../../error_page.aspx?error=" + "You are not authorized to view this page. Contact your system administrator.");
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                // Initialize viewstate's variables
                ViewState["others"] = Request.QueryString["others"];
                ViewState["employee_id"] = int.Parse(Request.QueryString["employee_id"]);
                ViewState["period_id"] = int.Parse(Request.QueryString["period_id"]);
                ViewState["projecttime_id"] = int.Parse(Request.QueryString["projecttime_id"]);
                System.Configuration.AppSettingsReader appSettingReader = new System.Configuration.AppSettingsReader();
                ViewState["LHMode"] = appSettingReader.GetValue("LABOUR_HOURS_OPERATION_MODE", typeof(System.String)).ToString();

                // Get ProjectTime record
                projectTimeTDS =  new ProjectTimeTDS();

                ProjectTimeGateway projectTimeGateway = new ProjectTimeGateway(projectTimeTDS);
                projectTimeGateway.LoadByProjectTimeId((int)ViewState["projecttime_id"]);

                // Store datasets
                Session["projectTimeTDS"] = projectTimeTDS;

                // Databind
                tbxDate.DataBind();
                tbxWorkingDetails.DataBind();
                tbxStartTime.DataBind();
                tbxEndTime.DataBind();
                tbxLunch.DataBind();
                tbxComments.DataBind();
                tbxState.DataBind();

                // Prepare initial data for client
                StoreNavigatorState();

                EmployeeGateway employeeGateway = new EmployeeGateway(new DataSet());
                employeeGateway.LoadByEmployeeId((int)ViewState["employee_id"]);
                tbxEmployee.Text = employeeGateway.GetFullName((int)ViewState["employee_id"]);

                int companyId = Int32.Parse(Session["companyID"].ToString());

                CompaniesGateway companiesGateway = new CompaniesGateway(new DataSet());
                companiesGateway.LoadAllByCompaniesId(projectTimeGateway.GetCompaniesId((int)ViewState["projecttime_id"]), companyId);
                tbxClient.Text = companiesGateway.GetName(projectTimeGateway.GetCompaniesId((int)ViewState["projecttime_id"]));

                ProjectGateway projectGateway = new ProjectGateway(new DataSet());
                projectGateway.LoadByProjectId(projectTimeGateway.GetProjectId((int)ViewState["projecttime_id"]));
                tbxProject.Text = projectGateway.GetName(projectTimeGateway.GetProjectId((int)ViewState["projecttime_id"])) + "(" + projectGateway.GetProjectNumber(projectTimeGateway.GetProjectId((int)ViewState["projecttime_id"])) + ")";

                if (projectGateway.GetFairWageApplies(projectTimeGateway.GetProjectId((int)ViewState["projecttime_id"])))
                {
                    tbxJobClassType.Visible = true;
                    lblJobClassType.Visible = true;
                    tbxJobClassType.Text = projectTimeGateway.GetJobClassType((int)ViewState["projecttime_id"]);
                }
                else
                {
                    tbxJobClassType.Visible = false;
                    lblJobClassType.Visible = false;
                }

                if (projectTimeGateway.GetMealsCountry((int)ViewState["projecttime_id"]).HasValue)
                {
                    CountryGateway countryGateway = new CountryGateway(new DataSet());
                    countryGateway.LoadByCountryId((Int64)projectTimeGateway.GetMealsCountry((int)ViewState["projecttime_id"]));
                    tbxMealsCountry.Text = countryGateway.GetName((Int64)projectTimeGateway.GetMealsCountry((int)ViewState["projecttime_id"]));
                }

                //if (projectTimeGateway.GetMealsAllowance((int)ViewState["projecttime_id"]) > 0)
                //{
                //    cbxMealsAllowance.Checked = true;
                //}

                //if (projectTimeGateway.GetFairWage((int)ViewState["projecttime_id"]))
                //{
                //    cbxFairWage.Checked = true;
                //}

                if (projectTimeGateway.GetUnitId((int)ViewState["projecttime_id"]).HasValue)
                {
                    UnitsGateway unitGateway = new UnitsGateway(new DataSet());
                    unitGateway.LoadByUnitId((int)projectTimeGateway.GetUnitId((int)ViewState["projecttime_id"]), Convert.ToInt32(Session["companyID"]));
                    tbxUnit.Text = unitGateway.GetUnitCode((int)projectTimeGateway.GetUnitId((int)ViewState["projecttime_id"]));
                }

                if (projectTimeGateway.GetTowedUnitId((int)ViewState["projecttime_id"]).HasValue)
                {
                    UnitsGateway unitGateway = new UnitsGateway(new DataSet());
                    unitGateway.LoadByUnitId((int)projectTimeGateway.GetTowedUnitId((int)ViewState["projecttime_id"]), Convert.ToInt32(Session["companyID"]));
                    tbxTowed.Text = unitGateway.GetUnitCode((int)projectTimeGateway.GetTowedUnitId((int)ViewState["projecttime_id"]));
                }

                tbxTypeOfWork.Text = "";
                if (projectTimeGateway.GetWork((int)ViewState["projecttime_id"]) != "")
                {
                    tbxTypeOfWork.Text = projectTimeGateway.GetWork((int)ViewState["projecttime_id"]);
                }

                tbxFunction.Text = "";
                if (projectTimeGateway.GetFunction((int)ViewState["projecttime_id"]) != "")
                {
                    tbxFunction.Text = projectTimeGateway.GetFunction((int)ViewState["projecttime_id"]);
                }
            }
            else
            {
                // Restore datasets
                projectTimeTDS = (ProjectTimeTDS)Session["projectTimeTDS"];
            }
        }
        private void LoadGeneralData()
        {
            // ... for geographical location
            hdfCountryId.DataBind();
            if (hdfCountryId.Value != "")
            {
                CountryGateway countryGateway = new CountryGateway();
                countryGateway.LoadByCountryId(Int64.Parse(hdfCountryId.Value));
                tbxCountry.Text = countryGateway.GetName(Int64.Parse(hdfCountryId.Value));
            }
            else
            {
                tbxCountry.Text = "";
            }

            hdfProvinceStateId.DataBind();
            if (hdfProvinceStateId.Value != "")
            {
                ProvinceGateway provinceGateway = new ProvinceGateway();
                provinceGateway.LoadByProvinceId(Int64.Parse(hdfProvinceStateId.Value));
                tbxProvinceState.Text = provinceGateway.GetName(Int64.Parse(hdfProvinceStateId.Value));
            }
            else
            {
                tbxProvinceState.Text = "";
            }

            hdfCountyId.DataBind();
            if (hdfCountyId.Value != "")
            {
                CountyGateway countyGateway = new CountyGateway();
                countyGateway.LoadByCountyId(Int64.Parse(hdfCountyId.Value));
                tbxCounty.Text = countyGateway.GetName(Int64.Parse(hdfCountyId.Value));
            }
            else
            {
                tbxCounty.Text = "";
            }

            hdfCityId.DataBind();
            if (hdfCityId.Value != "")
            {
                CityGateway cityGateway = new CityGateway();
                cityGateway.LoadByCityId(Int64.Parse(hdfCityId.Value));
                tbxCity.Text = cityGateway.GetName(Int64.Parse(hdfCityId.Value));
            }
            else
            {
                tbxCity.Text = "";
            }

            // ... for project
            ProjectGateway projectGateway = new ProjectGateway(projectTDS);
            int currentCompanyId = projectGateway.GetClientID(Int32.Parse(hdfProjectId.Value.ToString()));
            hdfClientId.Value = projectGateway.GetClientID(Int32.Parse(hdfProjectId.Value)).ToString();

            // ... for client
            int companyId = Int32.Parse(hdfCompanyId.Value);
            CompaniesGateway companiesGateway = new CompaniesGateway();
            companiesGateway.LoadAllByCompaniesId(currentCompanyId, companyId);

            if (projectTDS.LFS_PROJECT.Rows.Count > 0)
            {
                tkrdpStartDate.DataBind();
                tkrdpEndDate.DataBind();
                tkrdpProposalDate.DataBind();
                tbxProjectNumber.DataBind();
                tbxName.DataBind();
                tbxDescription.DataBind();
                tbxClientName.Text = companiesGateway.GetName(projectGateway.GetClientID(int.Parse(hdfProjectId.Value)));
                tbxClientProjectNumber.DataBind();

                // ... ... for primary contact
                ContactsList contactList = new ContactsList();
                contactList.LoadAllAndAddItemByCompaniesId(-1, " ", projectGateway.GetClientID(int.Parse(hdfProjectId.Value)), companyId);
                ddlClientPrimaryContactId.DataSource = contactList.Table;
                ddlClientPrimaryContactId.DataValueField = "CONTACTS_ID";
                ddlClientPrimaryContactId.DataTextField = "Name";

                if (projectGateway.GetClientPrimaryContactID(int.Parse(hdfProjectId.Value)).HasValue)
                {
                    ddlClientPrimaryContactId.SelectedValue = projectGateway.GetClientPrimaryContactID(int.Parse(hdfProjectId.Value)).ToString();
                }
                else
                {
                    ddlClientPrimaryContactId.SelectedValue = "-1";
                }

                ddlClientPrimaryContactId.DataBind();

                // ... ... for secondary contact
                ddlClientSecondaryContactId.DataSource = contactList.Table;
                ddlClientSecondaryContactId.DataValueField = "CONTACTS_ID";
                ddlClientSecondaryContactId.DataTextField = "Name";

                if (projectGateway.GetClientSecondaryContactID(int.Parse(hdfProjectId.Value)).HasValue)
                {
                    ddlClientSecondaryContactId.SelectedValue = projectGateway.GetClientSecondaryContactID(int.Parse(hdfProjectId.Value)).ToString();
                }
                else
                {
                    ddlClientSecondaryContactId.SelectedValue = "-1";
                }

                ddlClientSecondaryContactId.DataBind();

                // ... for resources
                // ...  ... for project lead
                EmployeeList employeeList = new EmployeeList();
                employeeList.LoadAndAddItem(-1, " ");
                ddlProjectLeadId.DataSource = employeeList.Table;
                ddlProjectLeadId.DataValueField = "EmployeeID";
                ddlProjectLeadId.DataTextField = "FullName";
                ddlProjectLeadId.SelectedValue = (projectGateway.GetProjectLeadID(int.Parse(hdfProjectId.Value)).HasValue) ? ((int)projectGateway.GetProjectLeadID(int.Parse(hdfProjectId.Value))).ToString() : "-1";
                ddlProjectLeadId.DataBind();

                // ... ... for salesman
                SalesmanListGateway salesmanListGateway = new SalesmanListGateway(new DataSet());
                salesmanListGateway.Load();
                ddlSalesmanId.DataSource = salesmanListGateway.Table;
                ddlSalesmanId.DataValueField = "SalesmanID";
                ddlSalesmanId.DataTextField = "FullName";
                ddlSalesmanId.SelectedValue = ((int)projectGateway.GetSalesmanID(int.Parse(hdfProjectId.Value))).ToString();
                ddlSalesmanId.DataBind();

                // ... ... for Pricing
                if (projectGateway.GetProjectType(int.Parse(hdfProjectId.Value)) == "Ballpark")
                {
                    ProjectSaleBillingPricingGateway projectSaleBillingPricingGateway = new ProjectSaleBillingPricingGateway(projectTDS);

                    if (projectSaleBillingPricingGateway.Table.Rows.Count > 0)
                    {
                        tbxBillPrice.DataBind();
                        ddlBillMoney.DataBind();
                    }
                    else
                    {
                        if (projectGateway.GetCountryID(int.Parse(hdfProjectId.Value)) == 1)
                        {
                            ddlBillMoney.SelectedValue = "CAD";
                        }
                        else
                        {
                            ddlBillMoney.SelectedValue = "USD";
                        }
                    }
                }
            }

            cbxFairWageApplies.DataBind();

            // Data for unit budget tab
            ProjectNavigatorProjectUnitsBudgetGateway projectNavigatorProjectUnitsBudgetGateway = new ProjectNavigatorProjectUnitsBudgetGateway(projectNavigatorTDS);

            if (projectNavigatorProjectUnitsBudgetGateway.Table.Rows.Count > 0)
            {
                tbxUnitsBudget.Text = projectNavigatorProjectUnitsBudgetGateway.GetBudget(int.Parse(hdfProjectId.Value)).ToString("n2");
            }

            // Data for materials budget tab
            ProjectNavigatorProjectMaterialsBudgetGateway projectNavigatorProjectMaterialsBudgetGateway = new ProjectNavigatorProjectMaterialsBudgetGateway(projectNavigatorTDS);

            if (projectNavigatorProjectMaterialsBudgetGateway.Table.Rows.Count > 0)
            {
                tbxMaterialsBudget.Text = projectNavigatorProjectMaterialsBudgetGateway.GetBudget(int.Parse(hdfProjectId.Value)).ToString("n2");
            }

            // Data for subcontractors budget tab
            ProjectNavigatorProjectSubcontractorsBudgetGateway projectNavigatorProjectSubcontractorsBudgetGateway = new ProjectNavigatorProjectSubcontractorsBudgetGateway(projectNavigatorTDS);

            if (projectNavigatorProjectSubcontractorsBudgetGateway.Table.Rows.Count > 0)
            {
                tbxSubcontractorsBudget.Text = projectNavigatorProjectSubcontractorsBudgetGateway.GetBudget(int.Parse(hdfProjectId.Value), 1, 1).ToString("n2");
            }

            // Data for hotels budget tab
            ProjectNavigatorProjectHotelsBudgetGateway projectNavigatorProjectHotelsBudgetGateway = new ProjectNavigatorProjectHotelsBudgetGateway(projectNavigatorTDS);

            if (projectNavigatorProjectHotelsBudgetGateway.Table.Rows.Count > 0)
            {
                tbxHotelsBudget.Text = projectNavigatorProjectHotelsBudgetGateway.GetBudget(int.Parse(hdfProjectId.Value), 1, 1).ToString("n2");
            }

            // Data for bondings budget tab
            ProjectNavigatorProjectBondingsBudgetGateway projectNavigatorProjectBondingsBudgetGateway = new ProjectNavigatorProjectBondingsBudgetGateway(projectNavigatorTDS);

            if (projectNavigatorProjectBondingsBudgetGateway.Table.Rows.Count > 0)
            {
                tbxBondingsBudget.Text = projectNavigatorProjectBondingsBudgetGateway.GetBudget(int.Parse(hdfProjectId.Value), 1, 1).ToString("n2");
            }

            // Data for insurances budget tab
            ProjectNavigatorProjectInsurancesBudgetGateway projectNavigatorProjectInsurancesBudgetGateway = new ProjectNavigatorProjectInsurancesBudgetGateway(projectNavigatorTDS);

            if (projectNavigatorProjectInsurancesBudgetGateway.Table.Rows.Count > 0)
            {
                tbxInsurancesBudget.Text = projectNavigatorProjectInsurancesBudgetGateway.GetBudget(int.Parse(hdfProjectId.Value), 1, 1).ToString("n2");
            }

            CalculateTotalBudget();
        }
        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 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;
            }
        }
        private void GrdTeamProjectTimeDetailAdd()
        {
            Page.Validate();
            if (Page.IsValid)
            {
                Page.Validate("footerValidData");
                if (Page.IsValid)
                {
                    Page.Validate("footerData");
                    if (Page.IsValid)
                    {
                        int teamProjectTimeId = Int32.Parse(hdfTeamProjectTimeID.Value);
                        int employeeId = Int32.Parse(((DropDownList)grdProjectTime.FooterRow.FindControl("ddlEmployeesFooter")).SelectedValue);
                        int companiesId = int.Parse(ddlClient.SelectedValue);
                        int projectId = int.Parse(ddlProject.SelectedValue);
                        DateTime date_ = tkrdpDate_.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 = tbxWorkingDetails.Text;
                        bool isMealsAllowanceFooter = false;// ((CheckBox)grdProjectTime.FooterRow.FindControl("ckbxMealsAllowanceFooter")).Checked;
                        string commentsFooter = ((TextBox)grdProjectTime.FooterRow.FindControl("tbxCommentsFooter")).Text;
                        int companyId = Int32.Parse(hdfCompanyId.Value);
                        bool fairWageFooter = false; if (hdfFairWage.Value == "True") fairWageFooter = true;

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

                        string projectTimeState = "For Approval"; if ((string)ViewState["LHMode"] == "Partial") projectTimeState = "Approved";

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

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

                        // Insert Data
                        TeamProjectTime2DetailTemp teamProjectTime2DetailTemp = new TeamProjectTime2DetailTemp(teamProjectTime2TDS);
                        teamProjectTime2DetailTemp.Insert(teamProjectTimeId, employeeId, companiesId, projectId, date_, startTimeFooter, endTimeFooter, offsetFooterFinal, workingDetailsFooter, location, mealsCountry, isMealsAllowanceFooter, unitIdFooter, towedIdFooter, projectTimeState, commentsFooter, work_, function_, typeOfWorkFooter, fairWageFooter, jobClassTypeFooter);

                        // Store Dataset
                        Session.Remove("teamProjectTimeDetailTempDummy");
                        Session["teamProjectTime2TDS"] = teamProjectTime2TDS;
                        teamProjectTimeDetailTemp = teamProjectTime2TDS.LFS_TEAM_PROJECT_TIME_DETAIL_TEMP;
                        Session["teamProjectTimeDetailTemp"] = teamProjectTime2TDS.LFS_TEAM_PROJECT_TIME_DETAIL_TEMP; ;

                        grdProjectTime.DataBind();
                        grdProjectTime.PageIndex = grdProjectTime.PageCount - 1;
                    }
                }
            }
        }
        private void PostPageChanges()
        {
            int projectTimeId = (int)ViewState["projecttime_id"];
            int companiesId = int.Parse(ddlClient.SelectedValue);
            int projectId = int.Parse(ddlProject.SelectedValue);
            DateTime date_ = tkrdpDate_.SelectedDate.Value;
            string workingDetails = ""; if (ddlWorkingDetails.SelectedValue != "(Select)") workingDetails = ddlWorkingDetails.SelectedValue;

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

            DateTime? startTime = null;
            if ((ddlStartTimeHour.SelectedValue.Trim() != "") && (ddlStartTimeMinute.SelectedValue.Trim() != "") )
            {
                startTime = new DateTime(date_.Year, date_.Month, date_.Day, Int32.Parse(ddlStartTimeHour.SelectedValue), Int32.Parse(ddlStartTimeMinute.SelectedValue), 0);
            }

            DateTime? endTime = null;
            if ((ddlEndTimeHour.SelectedValue.Trim() != "") && (ddlEndTimeMinute.SelectedValue.Trim() != "") )
            {
                endTime = new DateTime(date_.Year, date_.Month, date_.Day, Int32.Parse(ddlEndTimeHour.SelectedValue), Int32.Parse(ddlEndTimeMinute.SelectedValue), 0);
            }

            string work_ = ""; if (ddlTypeOfWork.SelectedValue != "(Select a Type)") work_ = ddlTypeOfWork.SelectedValue;
            string function_ = ""; if (ddlFunction.SelectedValue != "(Select a Function)") function_ = ddlFunction.SelectedValue;

            double? offset = 0; if (ddlLunch.SelectedValue != "0") offset = double.Parse(ddlLunch.SelectedValue);
            Int64? mealsCountry = null; if (ddlMealsCountry.SelectedValue != "-1") mealsCountry = Int64.Parse(ddlMealsCountry.SelectedValue);
            string mealsAllowanceType = ""; //if (cbxMealsAllowance.Checked) mealsAllowanceType = "Full Day";

            decimal mealsAllowance = MealsAllowance.GetMealsAllowance(mealsCountry, false, "Full Day");

            int? unitId = null; if (ddlUnit.SelectedValue != "-1") unitId = int.Parse(ddlUnit.SelectedValue);
            int? towedUnitId = null; if (ddlTowed.SelectedValue != "-1") towedUnitId = int.Parse(ddlTowed.SelectedValue);

            string comments = tbxComments.Text.Trim();
            bool fairWage = projectGateway.GetFairWageApplies(projectId);

            string jobClassType = ""; if (ddlJobClassType.SelectedValue != "(Select a Job Class Type)") jobClassType = ddlJobClassType.SelectedValue;

            EmployeeGateway employeeGateway = new EmployeeGateway(new DataSet());
            int employeeId = employeeGateway.GetEmployeIdByLoginId(Convert.ToInt32(Session["loginID"]));

            LiquiForce.LFSLive.BL.LabourHours.ProjectTime.ProjectTime projectTime = new LiquiForce.LFSLive.BL.LabourHours.ProjectTime.ProjectTime(projectTimeTDS);
            projectTime.Update(projectTimeId, companiesId, projectId, date_, startTime, endTime, offset, workingDetails, location, mealsCountry, mealsAllowanceType, mealsAllowance, unitId, towedUnitId, comments, work_, function_, fairWage, jobClassType, employeeId);
        }
        protected void ddlProject_SelectedIndexChanged(object sender, EventArgs e)
        {
            if ((ddlProject.SelectedValue != null) && (ddlProject.SelectedValue != "-1"))
            {
                int companiesId = int.Parse(ddlClient.SelectedValue);
                int projectId = int.Parse(ddlProject.SelectedValue);

                ProjectGateway projectGateway = new ProjectGateway(new DataSet());
                projectGateway.LoadByProjectId(projectId);

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

                if (projectGateway.GetFairWageApplies(projectId))
                {
                    if (projectGateway.GetCountryID(Int32.Parse(ddlProject.SelectedValue)) == 1) //Canada
                    {
                        odsJobClassType.SelectParameters.Clear();
                        odsJobClassType.SelectParameters.Add("countryId", "1");
                        odsJobClassType.SelectParameters.Add("jobClassType", "(Select a Job Class Type)");
                        odsJobClassType.SelectParameters.Add("companyId", "3");
                        odsJobClassType.Select();
                    }
                    else
                    {
                        odsJobClassType.SelectParameters.Clear();
                        odsJobClassType.SelectParameters.Add("countryId", "2");
                        odsJobClassType.SelectParameters.Add("jobClassType", "(Select a Job Class Type)");
                        odsJobClassType.SelectParameters.Add("companyId", "3");
                        odsJobClassType.Select();
                    }
                }
                else
                {
                    odsJobClassType.SelectParameters.Clear();
                    odsJobClassType.SelectParameters.Add("countryId", "-1");
                    odsJobClassType.SelectParameters.Add("jobClassType", "");
                    odsJobClassType.SelectParameters.Add("companyId", "3");
                    odsJobClassType.Select();
                }

                if (projectId != 35 && projectId != 39 && projectId != 716)
                {
                    switch (projectGateway.GetCountryID(projectId))
                    {
                        case 1:
                            ddlMealsCountry.SelectedValue = "1";
                            hdfWorkingDetails.Value = "Canada";
                            break;
                        case 2:
                            ddlMealsCountry.SelectedValue = "2";
                            hdfWorkingDetails.Value = "USA";
                            break;
                    }

                    if (tkrdpEndDate.Visible)
                    {
                        lblStartDate.Text = "Date";
                        lblLastDate.Visible = false;
                        tkrdpEndDate.Visible = false;
                    }

                    odsWorkingDetails.SelectParameters.RemoveAt(0);
                    odsWorkingDetails.SelectParameters.Add("workingDetails", "");
                    odsWorkingDetails.Select();
                    ddlWorkingDetails.DataBind();
                    ddlWorkingDetails.SelectedIndex = 0;
                    lblWorkingDetails.Visible = false;
                    ddlWorkingDetails.Visible = false;
                    lblMealsCountry.Visible = true;
                    ddlMealsCountry.Visible = true;
                    grdProjectTime.Visible = true;
                    lblCommentsVacation.Visible = false;
                    tbxCommentsVacation.Visible = false;

                    odsWorkFunctionConcat.SelectParameters.RemoveAt(0);
                    odsWorkFunctionConcat.SelectParameters.Add("workFunctionConcat", "(Select)");
                    odsWorkFunctionConcat.Select();
                }
                else
                {
                    ddlMealsCountry.SelectedIndex = 0;
                    if (!tkrdpEndDate.Visible)
                    {
                        lblStartDate.Text = "Start Date";
                        lblLastDate.Visible = true;
                        tkrdpEndDate.Visible = true;
                    }

                    odsWorkingDetails.SelectParameters.RemoveAt(0);
                    odsWorkingDetails.SelectParameters.Add("workingDetails", "(Select)");
                    odsWorkingDetails.Select();
                    ddlWorkingDetails.DataBind();
                    ddlWorkingDetails.SelectedIndex = 0;
                    lblWorkingDetails.Visible = true;
                    ddlWorkingDetails.Visible = true;
                    lblMealsCountry.Visible = false;
                    ddlMealsCountry.Visible = false;
                    grdProjectTime.Visible = false;
                    lblCommentsVacation.Visible = true;
                    tbxCommentsVacation.Visible = true;

                    odsWorkFunctionConcat.SelectParameters.RemoveAt(0);
                    odsWorkFunctionConcat.SelectParameters.Add("workFunctionConcat", "");
                    odsWorkFunctionConcat.Select();
                }
            }

            grdProjectTime.DataBind();
        }
        private void LoadGeneralData()
        {
            // Data for General Data
            tbxProjectNumber.DataBind();
            tbxName.DataBind();
            tbxProposalDate.DataBind();
            tbxStartDate.DataBind();
            tbxEndDate.DataBind();
            tbxDescription.DataBind();
            cbxFairWageApplies.DataBind();

            // ... for geographical location
            hdfCountryId.DataBind();
            if (hdfCountryId.Value != "")
            {
                CountryGateway countryGateway = new CountryGateway();
                countryGateway.LoadByCountryId(Int64.Parse(hdfCountryId.Value));
                tbxCountry.Text = countryGateway.GetName(Int64.Parse(hdfCountryId.Value));
            }
            else
            {
                tbxCountry.Text = "";
            }

            hdfProvinceStateId.DataBind();
            if (hdfProvinceStateId.Value != "")
            {
                ProvinceGateway provinceGateway = new ProvinceGateway();
                provinceGateway.LoadByProvinceId(Int64.Parse(hdfProvinceStateId.Value));
                tbxProvinceState.Text = provinceGateway.GetName(Int64.Parse(hdfProvinceStateId.Value));
            }
            else
            {
                tbxProvinceState.Text = "";
            }

            hdfCountyId.DataBind();
            if (hdfCountyId.Value != "")
            {
                CountyGateway countyGateway = new CountyGateway();
                countyGateway.LoadByCountyId(Int64.Parse(hdfCountyId.Value));
                tbxCounty.Text = countyGateway.GetName(Int64.Parse(hdfCountyId.Value));
            }
            else
            {
                tbxCounty.Text = "";
            }

            hdfCityId.DataBind();
            if (hdfCityId.Value != "")
            {
                CityGateway cityGateway = new CityGateway();
                cityGateway.LoadByCityId(Int64.Parse(hdfCityId.Value));
                tbxCity.Text = cityGateway.GetName(Int64.Parse(hdfCityId.Value));
            }
            else
            {
                tbxCity.Text = "";
            }

            // ... for project
            ProjectGateway projectGateway = new ProjectGateway(projectTDS);
            int currentCompanyId = projectGateway.GetClientID(Int32.Parse(hdfProjectId.Value.ToString()));

            // ... for client
            int companyId = Int32.Parse(hdfCompanyId.Value);
            CompaniesGateway companiesGateway = new CompaniesGateway();
            companiesGateway.LoadAllByCompaniesId(currentCompanyId, companyId);

            tbxClientName.Text = companiesGateway.GetName(currentCompanyId);
            hdfClientId.Value = projectGateway.GetClientID(int.Parse(hdfProjectId.Value)).ToString();
            tbxClientProjectNumber.DataBind();

            // ... ... for primary contact
            if (projectGateway.GetClientPrimaryContactID(int.Parse(hdfProjectId.Value)).HasValue)
            {
                hdfClientPrimaryContactID.Value = ((int)projectGateway.GetClientPrimaryContactID(int.Parse(hdfProjectId.Value))).ToString();
                ContactsGateway contactsGatewayForPrimaryContact = new ContactsGateway();
                contactsGatewayForPrimaryContact.LoadAllByContactId(int.Parse(hdfClientPrimaryContactID.Value), companyId);
                tbxClientPrimaryContact.Text = contactsGatewayForPrimaryContact.GetCompleteName(int.Parse(hdfClientPrimaryContactID.Value));
            }

            // ... ... for secondary contact
            if (projectGateway.GetClientSecondaryContactID(int.Parse(hdfProjectId.Value)).HasValue)
            {
                hdfClientSecondaryContactID.Value = ((int)projectGateway.GetClientSecondaryContactID(int.Parse(hdfProjectId.Value))).ToString();
                ContactsGateway contactsGatewayForSecondaryContact = new ContactsGateway();
                contactsGatewayForSecondaryContact.LoadAllByContactId(int.Parse(hdfClientSecondaryContactID.Value), companyId);
                tbxClientSecondaryContact.Text = contactsGatewayForSecondaryContact.GetCompleteName(int.Parse(hdfClientSecondaryContactID.Value));
            }

            // ... for resources
            // ... ... for project lead
            if (projectGateway.GetProjectLeadID(int.Parse(hdfProjectId.Value)).HasValue)
            {
                EmployeeGateway employeeGateway = new EmployeeGateway();
                employeeGateway.LoadByEmployeeId((int)projectGateway.GetProjectLeadID(int.Parse(hdfProjectId.Value)));
                tbxProjectLead.Text = employeeGateway.GetFullName((int)projectGateway.GetProjectLeadID(int.Parse(hdfProjectId.Value)));
            }

            // ... ... for salesman
            SalesmanGateway salesmanGateway = new SalesmanGateway();
            salesmanGateway.LoadExpandedBySalesmanId(projectGateway.GetSalesmanID(int.Parse(hdfProjectId.Value)));
            tbxSalesman.Text = salesmanGateway.GetFullName(projectGateway.GetSalesmanID(int.Parse(hdfProjectId.Value)));

            // ... ... for Pricing
            if (projectGateway.GetProjectType(int.Parse(hdfProjectId.Value)) == "Ballpark")
            {
                ProjectSaleBillingPricingGateway projectSaleBillingPricingGateway = new ProjectSaleBillingPricingGateway(projectTDS);

                if (projectSaleBillingPricingGateway.Table.Rows.Count > 0)
                {
                    if (projectSaleBillingPricingGateway.GetBillPrice(int.Parse(hdfProjectId.Value)).HasValue) tbxBillPrice.Text = ((decimal)projectSaleBillingPricingGateway.GetBillPrice(int.Parse(hdfProjectId.Value))).ToString("n2");
                    tbxBillMoney.Text = projectSaleBillingPricingGateway.GetBillMoney(int.Parse(hdfProjectId.Value));
                }
                else
                {
                    if (projectGateway.GetCountryID(int.Parse(hdfProjectId.Value)) == 1)
                    {
                        tbxBillMoney.Text = "CAD";
                    }
                    else
                    {
                        tbxBillMoney.Text = "USD";
                    }
                }
            }

            // Data for unit budget tab
            ProjectNavigatorProjectUnitsBudgetGateway projectNavigatorProjectUnitsBudgetGateway = new ProjectNavigatorProjectUnitsBudgetGateway(projectNavigatorTDS);

            if (projectNavigatorProjectUnitsBudgetGateway.Table.Rows.Count > 0)
            {
                tbxUnitsBudget.Text = projectNavigatorProjectUnitsBudgetGateway.GetBudget(int.Parse(hdfProjectId.Value)).ToString("n2");
            }

            // Data for materials budget tab
            ProjectNavigatorProjectMaterialsBudgetGateway projectNavigatorProjectMaterialsBudgetGateway = new ProjectNavigatorProjectMaterialsBudgetGateway(projectNavigatorTDS);

            if (projectNavigatorProjectMaterialsBudgetGateway.Table.Rows.Count > 0)
            {
                tbxMaterialsBudget.Text = projectNavigatorProjectMaterialsBudgetGateway.GetBudget(int.Parse(hdfProjectId.Value)).ToString("n2");
            }

            // Data for subcontractors budget tab
            ProjectNavigatorProjectSubcontractorsBudgetGateway projectNavigatorProjectSubcontractorsBudgetGateway = new ProjectNavigatorProjectSubcontractorsBudgetGateway(projectNavigatorTDS);

            if (projectNavigatorProjectSubcontractorsBudgetGateway.Table.Rows.Count > 0)
            {
                tbxSubcontractorsBudget.Text = projectNavigatorProjectSubcontractorsBudgetGateway.GetBudget(int.Parse(hdfProjectId.Value), 1, 1).ToString("n2");
            }

            // Data for hotels budget tab
            ProjectNavigatorProjectHotelsBudgetGateway projectNavigatorProjectHotelsBudgetGateway = new ProjectNavigatorProjectHotelsBudgetGateway(projectNavigatorTDS);

            if (projectNavigatorProjectHotelsBudgetGateway.Table.Rows.Count > 0)
            {
                tbxHotelsBudget.Text = projectNavigatorProjectHotelsBudgetGateway.GetBudget(int.Parse(hdfProjectId.Value), 1, 1).ToString("n2");
            }

            // Data for bondings budget tab
            ProjectNavigatorProjectBondingsBudgetGateway projectNavigatorProjectBondingsBudgetGateway = new ProjectNavigatorProjectBondingsBudgetGateway(projectNavigatorTDS);

            if (projectNavigatorProjectBondingsBudgetGateway.Table.Rows.Count > 0)
            {
                tbxBondingsBudget.Text = projectNavigatorProjectBondingsBudgetGateway.GetBudget(int.Parse(hdfProjectId.Value), 1, 1).ToString("n2");
            }

            // Data for insurances budget tab
            ProjectNavigatorProjectInsurancesBudgetGateway projectNavigatorProjectInsurancesBudgetGateway = new ProjectNavigatorProjectInsurancesBudgetGateway(projectNavigatorTDS);

            if (projectNavigatorProjectInsurancesBudgetGateway.Table.Rows.Count > 0)
            {
                tbxInsurancesBudget.Text = projectNavigatorProjectInsurancesBudgetGateway.GetBudget(int.Parse(hdfProjectId.Value), 1, 1).ToString("n2");
            }

            CalculateTotalBudget();
        }
        /// <summary>
        /// GetProjectNumber
        /// </summary>
        /// <param name="row">row</param>
        /// <param name="companyId">companyId</param>
        /// <returns></returns>
        private string GetProjectNumber(DataMigrationTDS.DataMigrationProjectRow row, int companyId)
        {
            DateTime date = DateTime.Now;

            CountryGateway countryGateway = new CountryGateway(new DataSet());
            countryGateway.LoadByCountryId(row.CountryID);
            string pnCountryId = countryGateway.GetIdForProjects(row.CountryID);

            OfficeGateway officeGateway = new OfficeGateway(new DataSet());
            officeGateway.LoadByOfficeId(row.OfficeID);
            string pnOfficeId = officeGateway.GetIdForProjects(row.OfficeID);

            SalesmanGateway salesmanGateway = new SalesmanGateway(new DataSet());
            salesmanGateway.LoadBySalesmanId(row.SalesmanID);
            string pnSalesmanId = salesmanGateway.GetIdForProjects(row.SalesmanID);

            ProjectNumberGateway projectNumberGateway = new ProjectNumberGateway();
            projectNumberGateway.Load();
            ProjectNumber projectNumber = new ProjectNumber(projectNumberGateway.Data);
            string pnYearCode = projectNumber.GetYearCode(date.Year);
            string pnProjectIncrement = projectNumber.GetProjectIncrement(date.Year, companyId);

            string newProjectNumber = pnCountryId + pnOfficeId + pnSalesmanId + pnYearCode + pnProjectIncrement;

            return newProjectNumber;
        }
        private void PostStepDataChanges()
        {
            int teamProjectTimeId = (int)ViewState["teamProjectTimeId"];
            string templateName = "";
            int companiesId = int.Parse(ddlClient.SelectedValue);
            int projectId = int.Parse(ddlProject.SelectedValue);
            DateTime date_ = tkrdpDate_.SelectedDate.Value;
            string workingDetails = ""; if (tbxWorkingDetails.Text != "(Select)") workingDetails = tbxWorkingDetails.Text;
            string work_ = ddlTypeOfWork.SelectedValue;
            string function_ = ddlFunction.SelectedValue;

            ProjectGateway projectGateway = new ProjectGateway(new DataSet());
            projectGateway.LoadByProjectId(projectId);

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

            string location = countryGateway.GetName(projectGateway.GetCountryID(projectId));

            DateTime? startTime = null;
            if ((ddlStartTimeHour.SelectedValue.Trim() != "") && (ddlStartTimeMinute.SelectedValue.Trim() != "") )
            {
                startTime = new DateTime(date_.Year, date_.Month, date_.Day, Int32.Parse(ddlStartTimeHour.SelectedValue), Int32.Parse(ddlStartTimeMinute.SelectedValue), 0);
            }

            DateTime? endTime = null;
            if ((ddlEndTimeHour.SelectedValue.Trim() != "") && (ddlEndTimeMinute.SelectedValue.Trim() != "") )
            {
                endTime = new DateTime(date_.Year, date_.Month, date_.Day, Int32.Parse(ddlEndTimeHour.SelectedValue), Int32.Parse(ddlEndTimeMinute.SelectedValue), 0);
            }

            double? offset = 0; if (ddlLunch.SelectedValue != "0") offset = double.Parse(ddlLunch.SelectedValue);
            Int64? mealsCountry = null; if (ddlMealsCountry.SelectedValue != "-1") mealsCountry = Int64.Parse(ddlMealsCountry.SelectedValue);
            string mealsAllowanceType = ""; //if (cbxMealsAllowance.Checked) mealsAllowanceType = "Full Day";
            decimal mealsAllowance = MealsAllowance.GetMealsAllowance(mealsCountry, false, "Full Day");
            string comments = "";
            string type = "Template";
            string state = "Done";
            int loginId = Convert.ToInt32(Session["loginID"]);
            bool deleted = false;
            int? unitId = null;
            int? towedUnitId = null;
            bool fairWage = false; if (hdfFairWage.Value == "True") fairWage = true;

            // New template check
            TeamProjectTime2 teamProjectTime2 = new TeamProjectTime2(teamProjectTime2TDS);
            if (((int)ViewState["teamProjectTimeId"] == 0) && ((string)ViewState["StepFrom"] != "Employees"))
            {
                // ... Insert team project time
                teamProjectTime2.Insert(teamProjectTimeId, templateName, companiesId, projectId, date_, startTime, endTime, offset, workingDetails, location, mealsCountry, mealsAllowanceType, mealsAllowance, unitId, towedUnitId, comments, type, state, loginId, deleted, work_, function_, fairWage);
            }
            else
            {
                // ... Update team project time
                teamProjectTime2.Update(teamProjectTimeId, templateName, companiesId, projectId, date_, startTime, endTime, offset, workingDetails, location, mealsCountry, mealsAllowanceType, mealsAllowance, unitId, towedUnitId, comments, type, state, loginId, deleted, work_, function_, fairWage);
            }

            // Store date in date edit for employees step
            tbxDate.Text = tkrdpDate_.SelectedDate.Value.ToString();
            hdfDate.Value = tkrdpDate_.SelectedDate.Value.ToString();

            // Store data in hidden components for employees step
            hdfTeamProjectTimeID.Value = teamProjectTimeId.ToString();
            hdfCompaniesID.Value = companiesId.ToString();
            hdfProjectID.Value = projectId.ToString();

            string startTimeForNextStep = "";
            if ((ddlStartTimeHour.SelectedValue.Trim() != "") && (ddlStartTimeMinute.SelectedValue.Trim() != ""))
            {
                startTimeForNextStep = ddlStartTimeHour.SelectedValue.Trim() + ":" + ddlStartTimeMinute.SelectedValue.Trim();
            }
            hdfStartTime.Value = startTimeForNextStep;

            string endTimeForNextStep = "";
            if ((ddlEndTimeHour.SelectedValue.Trim() != "") && (ddlEndTimeMinute.SelectedValue.Trim() != ""))
            {
                endTimeForNextStep = ddlEndTimeHour.SelectedValue.Trim() + ":" + ddlEndTimeMinute.SelectedValue.Trim();
            }

            hdfEndTime.Value = endTimeForNextStep;
            if (offset != null) hdfOffset.Value = offset.ToString(); else hdfOffset.Value = "";
            hdfWorkingDetails.Value = workingDetails.ToString();
            hdfLocation.Value = location.ToString();
            hdfMealsCountry.Value = ddlMealsCountry.SelectedValue;
            hdfIsMealsAllowance.Value = "false";// cbxMealsAllowance.Checked.ToString();
            hdfMealsAllowance.Value = mealsAllowance.ToString();
            hdfProjectTimeState.Value = "For Approval"; if ((string)ViewState["LHMode"] == "Partial") hdfProjectTimeState.Value = "Approved";
            //if (cbxClearUnitAssigment.Checked)
            hdfClearUnitAssigment.Value = "false";

            // ... For work and function string
            hdfWork_.Value = work_;
            hdfFunction_.Value = function_;
            hdfWorkFunctionConcat.Value = work_ + " . " + function_;

            // Clear Unit Assigment validation
            //if (cbxClearUnitAssigment.Checked)
            //{
            //    // ... Update detail
            //    TeamProjectTime2DetailTemp teamProjectTime2DetailTemp = new TeamProjectTime2DetailTemp(teamProjectTime2TDS);
            //    teamProjectTime2DetailTemp.UpdateAll(teamProjectTimeId);
            //}
            //else
            //{
                // ... Update detail
                TeamProjectTime2DetailTemp teamProjectTime2DetailTemp = new TeamProjectTime2DetailTemp(teamProjectTime2TDS);
                teamProjectTime2DetailTemp.UpdateAll(teamProjectTimeId, false);
            //}

            // Store datasets
            Session["teamProjectTime2TDS"] = teamProjectTime2TDS;
            teamProjectTimeDetailTemp = teamProjectTime2TDS.LFS_TEAM_PROJECT_TIME_DETAIL_TEMP;
            Session["teamProjectTimeDetailTemp"] = teamProjectTime2TDS.LFS_TEAM_PROJECT_TIME_DETAIL_TEMP;
        }
        protected string GetCountry(object country)
        {
            if (country == DBNull.Value)
            {
                return "";
            }
            else
            {
                Int64 countryId = Int64.Parse(country.ToString());

                if (countryId > 0)
                {
                    CountryGateway countryGateway = new CountryGateway();
                    countryGateway.LoadByCountryId(countryId);
                    return countryGateway.GetName(countryId);
                }
                else
                {
                    return "";
                }
            }
        }
        // ////////////////////////////////////////////////////////////////////////
        // 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;
            }
        }
        private void TagPage()
        {
            hdfWorkType.Value = Request.QueryString["work_type"].ToString();
            hdfCompanyId.Value = Session["companyID"].ToString();
            hdfProjectId.Value = Request.QueryString["project_id"].ToString();

            // Get ids & location
            int projectId = Int32.Parse(hdfProjectId.Value.Trim());
            ProjectGateway projectGateway = new ProjectGateway();
            projectGateway.LoadByProjectId(projectId);

            // ... Get ids
            Int64 currentCountry = projectGateway.GetCountryID(projectId);
            Int64? currentProvince = null; if (projectGateway.GetProvinceID(projectId).HasValue) currentProvince = (Int64)projectGateway.GetProvinceID(projectId);
            Int64? currentCounty = null; if (projectGateway.GetCountyID(projectId).HasValue) currentCounty = (Int64)projectGateway.GetCountyID(projectId);
            Int64? currentCity = null; if (projectGateway.GetCityID(projectId).HasValue) currentCity = (Int64)projectGateway.GetCityID(projectId);

            hdfCountryId.Value = currentCountry.ToString();
            hdfProvinceId.Value = currentProvince.ToString();
            hdfCountyId.Value = currentCounty.ToString();
            hdfCityId.Value = currentCity.ToString();

            // .. Get location
            string projectLocation = "";

            CountryGateway countryGateway = new CountryGateway();
            countryGateway.LoadByCountryId(currentCountry);
            projectLocation = projectLocation + countryGateway.GetName(currentCountry);

            if (currentProvince.HasValue)
            {
                ProvinceGateway provinceGateway = new ProvinceGateway();
                provinceGateway.LoadByProvinceId((Int64)currentProvince);
                projectLocation = projectLocation + ", " + provinceGateway.GetName((Int64)currentProvince);
            }

            if (currentCounty.HasValue)
            {
                CountyGateway countyGateway = new CountyGateway();
                countyGateway.LoadByCountyId((Int64)currentCounty);
                projectLocation = projectLocation + ", " + countyGateway.GetName((Int64)currentCounty);
            }

            if (currentCity.HasValue)
            {
                CityGateway cityGateway = new CityGateway();
                cityGateway.LoadByCityId((Int64)currentCity);
                projectLocation = projectLocation + ", " + cityGateway.GetName((Int64)currentCity);
            }

            hdfSearchTitle.Value = projectLocation;
        }
        protected void grdProjectTime_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            Page.Validate("editValidData");
            if (Page.IsValid)
            {
                Page.Validate("editData");
                if (Page.IsValid)
                {
                    int teamProjectTimeId = (int)e.Keys["TeamProjectTimeID"];
                    int detailId = (int)e.Keys["DetailID"];
                    DateTime date_ = DateTime.Parse(hdfDate.Value);

                    int employeeId = Int32.Parse(((DropDownList)grdProjectTime.Rows[e.RowIndex].Cells[3].FindControl("ddlEmployeesEdit")).SelectedValue);
                    int companiesId = int.Parse(ddlClient.SelectedValue);
                    int projectId = int.Parse(ddlProject.SelectedValue);
                    Int64? mealsCountry = null; if (ddlMealsCountry.SelectedValue != "-1") mealsCountry = Int64.Parse(ddlMealsCountry.SelectedValue);
                    string startTime = "";
                    string startHoursEdit = ((DropDownList)grdProjectTime.Rows[e.RowIndex].Cells[3].FindControl("ddlStartTimeHourEdit")).SelectedValue.Trim();
                    string startMinutesEdit = ((DropDownList)grdProjectTime.Rows[e.RowIndex].Cells[3].FindControl("ddlStartTimeMinuteEdit")).SelectedValue.Trim();

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

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

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

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

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

                    bool fairWage = false; if (hdfFairWage.Value == "True") fairWage = true;
                    string jobClassType = ((DropDownList)grdProjectTime.Rows[e.RowIndex].Cells[3].FindControl("ddlJobClassTypeEdit")).SelectedValue;

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

                    // Update data
                    TeamProjectTime2DetailTemp teamProjectTime2DetailTemp = new TeamProjectTime2DetailTemp(teamProjectTime2TDS);
                    teamProjectTime2DetailTemp.Update(teamProjectTimeId, detailId, employeeId, date_, startTime, endTime, offsetFinal, workingDetails, location, mealsCountry, isMealsAllowance, unitId, towedUnitId, comments, work_, function_, workFunctionConcat, fairWage, jobClassType);

                    // Store dataset
                    Session.Remove("teamProjectTimeDetailTempDummy");
                    Session["teamProjectTime2TDS"] = teamProjectTime2TDS;
                    Session["teamProjectTimeDetailTemp"] = teamProjectTime2TDS.LFS_TEAM_PROJECT_TIME_DETAIL_TEMP;
                    teamProjectTimeDetailTemp = teamProjectTime2TDS.LFS_TEAM_PROJECT_TIME_DETAIL_TEMP;
                }
                else
                {
                    e.Cancel = true;
                }
            }
            else
            {
                e.Cancel = true;
            }
        }