// ////////////////////////////////////////////////////////////////////////
        // INITIAL EVENTS
        //
        protected void Page_Load(object sender, EventArgs e)
        {
            // Register client scripts
            this.RegisterClientScripts();

            if (!IsPostBack)
            {
                // Security check
                if (!Convert.ToBoolean(Session["sgLFS_PROJECTS_COSTINGSHEETS_ADMIN"]))
                {
                    if (!(Convert.ToBoolean(Session["sgLFS_PROJECTS_COSTINGSHEETS_VIEW"]) && Convert.ToBoolean(Session["sgLFS_PROJECTS_COSTINGSHEETS_ADD"])))
                    {
                        Response.Redirect("./../../error_page.aspx?error=" + "You are not authorized to view this page. Contact your system administrator.");
                    }
                }

                // Validate query string
                if (((string)Request.QueryString["source_page"] == null) || ((string)Request.QueryString["project_id"] == null))
                {
                    Response.Redirect("./../../error_page.aspx?error=" + "Invalid query string in project_costing_sheets_add.aspx");
                }

                // Tag Page
                TagPage();

                // Initialize viewstate variables
                ViewState["StepFrom"] = "Out";
                Session.Remove("labourHoursInformationDummy");
                Session.Remove("labourHoursInformation");
                Session.Remove("unitsInformationDummy");
                Session.Remove("unitsInformation");
                Session.Remove("subcontractorsInformationDummy");
                Session.Remove("subcontractorsInformation");
                Session.Remove("materialsInformationDummy");
                Session.Remove("materialsInformation");
                Session.Remove("otherCostsInformationDummy");
                Session.Remove("otherCostsInformation");
                Session.Remove("revenueInformationDummy");
                Session.Remove("revenueInformation");
                Session.Remove("templateInformationDummy");
                Session.Remove("templateInformation");

                Session.Remove("hotelsInformationDummy");
                Session.Remove("hotelsInformation");

                Session.Remove("bondingsInformationDummy");
                Session.Remove("bondingsInformation");

                Session.Remove("insurancesInformationDummy");
                Session.Remove("insurancesInformation");

                Session.Remove("otherCategoryInformationDummy");
                Session.Remove("otherCategoryInformation");

                // ... Initialize tables
                projectCostingSheetAddTDS = new ProjectCostingSheetAddTDS();
                labourHoursInformation = new ProjectCostingSheetAddTDS.LabourHoursInformationDataTable();
                unitsInformation = new ProjectCostingSheetAddTDS.UnitsInformationDataTable();
                subcontractorsInformation = new ProjectCostingSheetAddTDS.SubcontractorsInformationDataTable();
                materialsInformation = new ProjectCostingSheetAddTDS.MaterialsInformationDataTable();
                otherCostsInformation = new ProjectCostingSheetAddTDS.OtherCostsInformationDataTable();
                revenueInformation = new ProjectCostingSheetAddTDS.RevenueInformationDataTable();
                templateInformation = new ProjectCostingSheetAddTDS.TemplateInformationDataTable();
                hotelsInformation = new ProjectCostingSheetAddTDS.HotelsInformationDataTable();
                bondingsInformation = new ProjectCostingSheetAddTDS.BondingsInformationDataTable();
                insurancesInformation = new ProjectCostingSheetAddTDS.InsurancesInformationDataTable();
                otherCategoryInformation = new ProjectCostingSheetAddTDS.OtherCategoryInformationDataTable();

                tbxTeamMembersTotalCostCAD.Text = "0";
                tbxTeamMembersTotalCostUSD.Text = "0";
                tbxUnitsTotalCostsCAD.Text = "0";
                tbxUnitsTotalCostsUSD.Text = "0";
                tbxSubcontractorsTotalCostsCAD.Text = "0";
                tbxSubcontractorsTotalCostsUSD.Text = "0";
                tbxMaterialsTotalCostsCAD.Text = "0";
                tbxMaterialsTotalCostsUSD.Text = "0";
                tbxOtherCostsTotalCostsCAD.Text = "0";
                tbxOtherCostsTotalCostsUSD.Text = "0";
                tbxRevenueTotal.Text = "0";
                tbxGradRevenue.Text = "0";
                tbxGrandProfit.Text = "0";
                tbxGrandGrossMargin.Text = "0";

                tbxHotelsTotalCostsCAD.Text = "0";
                tbxHotelsTotalCostsUSD.Text = "0";

                tbxBondingsTotalCostsCAD.Text = "0";
                tbxBondingsTotalCostsUSD.Text = "0";

                tbxInsurancesTotalCostsCAD.Text = "0";
                tbxInsurancesTotalCostsUSD.Text = "0";

                tbxOtherCategoryTotalCostsCAD.Text = "0";
                tbxOtherCategoryTotalCostsUSD.Text = "0";

                // ... Store tables
                Session["projectCostingSheetAddTDS"] = projectCostingSheetAddTDS;
                Session["labourHoursInformation"] = labourHoursInformation;
                Session["unitsInformation"] = unitsInformation;
                Session["subcontractorsInformation"] = subcontractorsInformation;
                Session["materialsInformation"] = materialsInformation;
                Session["otherCostsInformation"] = otherCostsInformation;
                Session["revenueInformation"] = revenueInformation;
                Session["templateInformation"] = templateInformation;

                Session["hotelsInformation"] = hotelsInformation;
                Session["bondingsInformation"] = bondingsInformation;
                Session["insurancesInformation"] = insurancesInformation;
                Session["otherCategoryInformation"] = otherCategoryInformation;

                // StepGeneralInformation
                wzProjectCostinsSheetsAdd.ActiveStepIndex = 0;
            }
            else
            {
                // Restore tables
                projectCostingSheetAddTDS = (ProjectCostingSheetAddTDS)Session["projectCostingSheetAddTDS"];
                labourHoursInformation = (ProjectCostingSheetAddTDS.LabourHoursInformationDataTable)Session["labourHoursInformation"];
                unitsInformation = (ProjectCostingSheetAddTDS.UnitsInformationDataTable)Session["unitsInformation"];
                subcontractorsInformation = (ProjectCostingSheetAddTDS.SubcontractorsInformationDataTable)Session["subcontractorsInformation"];
                materialsInformation = (ProjectCostingSheetAddTDS.MaterialsInformationDataTable)Session["materialsInformation"];
                otherCostsInformation = (ProjectCostingSheetAddTDS.OtherCostsInformationDataTable)Session["otherCostsInformation"];
                revenueInformation = (ProjectCostingSheetAddTDS.RevenueInformationDataTable)Session["revenueInformation"];
                templateInformation = (ProjectCostingSheetAddTDS.TemplateInformationDataTable)Session["templateInformation"];

                hotelsInformation = (ProjectCostingSheetAddTDS.HotelsInformationDataTable)Session["hotelsInformation"];
                bondingsInformation = (ProjectCostingSheetAddTDS.BondingsInformationDataTable)Session["bondingsInformation"];
                insurancesInformation = (ProjectCostingSheetAddTDS.InsurancesInformationDataTable)Session["insurancesInformation"];
                otherCategoryInformation = (ProjectCostingSheetAddTDS.OtherCategoryInformationDataTable)Session["otherCategoryInformation"];
            }
        }
        // ////////////////////////////////////////////////////////////////////////
        // STEP4 - LABOUR HOUR INFORMATION - METHODS
        //
        private void StepLabourHourInformationIn()
        {
            // Set instruction
            Label instruction = (Label)this.Master.FindControl("lblInstruction");
            instruction.Text = "Please verify Labour Hour information";

            // Load
            ProjectCostingSheetAddLabourHoursInformation model = new ProjectCostingSheetAddLabourHoursInformation(projectCostingSheetAddTDS);
            int projectId = Int32.Parse(hdfProjectId.Value);
            ProjectGateway projectGateway = new ProjectGateway();
            projectGateway.LoadByProjectId(projectId);

            if (projectCostingSheetAddTDS.LabourHoursInformation.Rows.Count <= 0)
            {
                ArrayList works = new ArrayList();
                if (cbxRehabAssessmentData.Checked) works.Add("Rehab Assessment");
                if (cbxFullLengthLiningData.Checked) works.Add("Full Length");
                if (cbxPointRepairData.Checked) { works.Add("Point Lining"); works.Add("Grouting"); }
                if (cbxJunctionLiningData.Checked) works.Add("Junction Lining");
                if (cbxManholeRehabData.Checked) works.Add("MH Rehab");
                if (cbxMobilizationData.Checked) works.Add("Mobilization");
                if (cbxOtherData.Checked)
                {
                    works.Add("Other");
                    works.Add("Downtime");
                    works.Add("Office");
                    works.Add("Office / Shop");
                    works.Add("R & D");
                    works.Add("Special Projects");
                    works.Add("Subcontractor");
                    works.Add("Watermain Relining");
                    works.Add("SOTA");
                }

                if (!projectGateway.GetFairWageApplies(projectId))
                {
                    model.Load(works, projectId, tkrdpFrom.SelectedDate.Value, tkrdpTo.SelectedDate.Value, int.Parse(hdfCompanyId.Value), "");
                }
                else
                {
                    ArrayList jobClassType = new ArrayList();
                    jobClassType.Add("Laborer Group 2");
                    jobClassType.Add("Laborer Group 6");
                    jobClassType.Add("Operator Group 1");
                    jobClassType.Add("Operator Group 2");
                    jobClassType.Add("Regular Rate");

                    model.LoadFairWageProject(works, jobClassType, projectId, tkrdpFrom.SelectedDate.Value, tkrdpTo.SelectedDate.Value, int.Parse(hdfCompanyId.Value), "");
                }
            }

            // Store tables
            Session.Remove("labourHoursInformationDummy");
            labourHoursInformation = (ProjectCostingSheetAddTDS.LabourHoursInformationDataTable)model.Table;
            Session["labourHoursInformation"] = labourHoursInformation;
            Session["projectCostingSheetAddTDS"] = projectCostingSheetAddTDS;

            grdTeamMembers.Columns[10].Visible = false;
            grdTeamMembers.Columns[11].Visible = false;
            grdTeamMembers.Columns[12].Visible = false;
            grdTeamMembers.Columns[13].Visible = false;
            grdTeamMembers.Columns[15].Visible = false;
            grdTeamMembers.Columns[16].Visible = false;
            grdTeamMembers.Columns[19].Visible = false;
            grdTeamMembers.Columns[20].Visible = false;

            // Validate grid columns
            if (projectGateway.GetCountryID(projectId) == 1) //Canada
            {
                // Team Members Grid
                grdTeamMembers.Columns[14].Visible = true;
                grdTeamMembers.Columns[17].Visible = true;
                grdTeamMembers.Columns[18].Visible = false;
                grdTeamMembers.Columns[21].Visible = false;

                // Totals
                lblTeamMembersTotalCost.Text = "Total Cost (CAD) : ";
                tbxTeamMembersTotalCostCAD.Visible = true;
                tbxTeamMembersTotalCostUSD.Visible = false;
            }
            else
            {
                if (projectGateway.GetCountryID(projectId) == 2) //USA
                {
                    // Team Members Grid
                    grdTeamMembers.Columns[14].Visible = false;
                    grdTeamMembers.Columns[17].Visible = false;
                    grdTeamMembers.Columns[18].Visible = true;
                    grdTeamMembers.Columns[21].Visible = true;

                    // Totals
                    lblTeamMembersTotalCost.Text = "Total Cost (USD) : ";
                    tbxTeamMembersTotalCostCAD.Visible = false;
                    tbxTeamMembersTotalCostUSD.Visible = true;
                }
            }

            grdTeamMembers.DataBind();
            StepLabourHoursInformationProcessGrid();
        }
        protected void LabourHoursInformationEmptyFix(GridView grdView)
        {
            if (grdView.Rows.Count == 0)
            {
                ProjectCostingSheetAddTDS.LabourHoursInformationDataTable dt = new ProjectCostingSheetAddTDS.LabourHoursInformationDataTable();
                dt.AddLabourHoursInformationRow(0, "", 0, 0, 0, "", "", 0, "", 0, 0, 0, 0, 0, 0, 0, 0, 0, false, 3, false, "", DateTime.Now, DateTime.Now, false, "", "", "", "", "", 0, 0);
                Session["labourHoursInformationDummy"] = dt;

                grdView.DataBind();
            }

            // Normally executes at all postbacks
            if (grdView.Rows.Count == 1)
            {
                ProjectCostingSheetAddTDS.LabourHoursInformationDataTable dt = (ProjectCostingSheetAddTDS.LabourHoursInformationDataTable)Session["labourHoursInformationDummy"];
                if (dt != null)
                {
                    // Hide row
                    grdView.Rows[0].Visible = false;
                    grdView.Rows[0].Controls.Clear();
                }
            }
        }
        public ProjectCostingSheetAddTDS.LabourHoursInformationDataTable GetLabourHoursInformation()
        {
            labourHoursInformation = (ProjectCostingSheetAddTDS.LabourHoursInformationDataTable)Session["labourHoursInformationDummy"];

            if (labourHoursInformation == null)
            {
                labourHoursInformation = (ProjectCostingSheetAddTDS.LabourHoursInformationDataTable)Session["labourHoursInformation"];
            }

            return labourHoursInformation;
        }
        protected void grdTeamMembers_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            int projectId = Int32.Parse(hdfProjectId.Value);
            ProjectGateway projectGateway = new ProjectGateway();

            // Validate general data
            Page.Validate("labourHoursEdit");

            if (Page.IsValid)
            {
                projectGateway.LoadByProjectId(projectId);

                // Validate costs
                if (projectGateway.GetCountryID(projectId) == 1) //Canada
                {
                    Page.Validate("labourHoursCadEdit");
                }
                else
                {
                    Page.Validate("labourHoursUsdEdit");
                }
            }

            if (Page.IsValid)
            {
                int costingSheetId = (int)e.Keys["CostingSheetID"];
                string work_ = (string)e.Keys["Work_"];
                int employeeId = (int)e.Keys["EmployeeID"];
                int refId = (int)e.Keys["RefID"];
                int companyId = Int32.Parse(hdfCompanyId.Value);

                string name = ((TextBox)grdTeamMembers.Rows[e.RowIndex].Cells[0].FindControl("tbxTeamMemberEdit")).Text;
                string unitOfMeasurementLH = ((DropDownList)grdTeamMembers.Rows[e.RowIndex].Cells[0].FindControl("ddlUnitOfMeasurementLHEdit")).SelectedValue;
                double lHQuantity = double.Parse(((TextBox)grdTeamMembers.Rows[e.RowIndex].Cells[0].FindControl("tbxLHQtyEdit")).Text.Trim());
                string unitOfMeasurementMeals = ((DropDownList)grdTeamMembers.Rows[e.RowIndex].Cells[0].FindControl("ddlUnitsOfMeasurementLHMealsEdit")).SelectedValue;
                int? mealsQuantity = null; if (((TextBox)grdTeamMembers.Rows[e.RowIndex].Cells[0].FindControl("tbxMealsQtyEdit")).Text.Trim() != "") mealsQuantity = Int32.Parse(((TextBox)grdTeamMembers.Rows[e.RowIndex].Cells[0].FindControl("tbxMealsQtyEdit")).Text.Trim());
                string unitOfMeasurementMotel = ((DropDownList)grdTeamMembers.Rows[e.RowIndex].Cells[0].FindControl("ddlUnitsOfMeasurementLHMotelEdit")).SelectedValue;
                int? motelQuantity = null; if (((TextBox)grdTeamMembers.Rows[e.RowIndex].Cells[0].FindControl("tbxMotelQtyEdit")).Text.Trim() != "") motelQuantity = Int32.Parse(((TextBox)grdTeamMembers.Rows[e.RowIndex].Cells[0].FindControl("tbxMotelQtyEdit")).Text.Trim());

                decimal lhCostCad = 0.0M;
                decimal totalCostCad = 0.0M;
                decimal? mealsCostCad = null;
                decimal? motelCostCad = null;
                decimal lhCostUsd = 0.0M;
                decimal totalCostUsd = 0.0M;
                decimal? mealsCostUsd = null;
                decimal? motelCostUsd = null;

                if (projectGateway.GetCountryID(projectId) == 1) //Canada
                {
                    lhCostCad = Decimal.Parse(((TextBox)grdTeamMembers.Rows[e.RowIndex].Cells[0].FindControl("tbxLHCostCADEdit")).Text.Trim());
                    if (((TextBox)grdTeamMembers.Rows[e.RowIndex].Cells[0].FindControl("tbxMealsCostCADEdit")).Text.Trim() != "") mealsCostCad = Decimal.Parse(((TextBox)grdTeamMembers.Rows[e.RowIndex].Cells[0].FindControl("tbxMealsCostCADEdit")).Text.Trim());
                    if (((TextBox)grdTeamMembers.Rows[e.RowIndex].Cells[0].FindControl("tbxMotelCostCADEdit")).Text.Trim() != "") motelCostCad = Decimal.Parse(((TextBox)grdTeamMembers.Rows[e.RowIndex].Cells[0].FindControl("tbxMotelCostCADEdit")).Text.Trim());
                    totalCostCad = (lhCostCad * decimal.Parse(lHQuantity.ToString()));
                    if (mealsCostCad.HasValue && mealsQuantity.HasValue) totalCostCad = totalCostCad + (mealsCostCad.Value * decimal.Parse(mealsQuantity.Value.ToString()));
                    if (motelCostCad.HasValue && motelQuantity.HasValue) totalCostCad = totalCostCad + (motelCostCad.Value * decimal.Parse(motelQuantity.Value.ToString()));
                    totalCostCad = Decimal.Round(totalCostCad, 2);
                }
                else
                {
                    lhCostUsd = Decimal.Parse(((TextBox)grdTeamMembers.Rows[e.RowIndex].Cells[0].FindControl("tbxLHCostUSDEdit")).Text.Trim());
                    if (((TextBox)grdTeamMembers.Rows[e.RowIndex].Cells[0].FindControl("tbxMealsCostUSDEdit")).Text.Trim() != "") mealsCostUsd = Decimal.Parse(((TextBox)grdTeamMembers.Rows[e.RowIndex].Cells[0].FindControl("tbxMealsCostUSDEdit")).Text.Trim());
                    if (((TextBox)grdTeamMembers.Rows[e.RowIndex].Cells[0].FindControl("tbxMotelCostUSDEdit")).Text.Trim() != "") motelCostUsd = Decimal.Parse(((TextBox)grdTeamMembers.Rows[e.RowIndex].Cells[0].FindControl("tbxMotelCostUSDEdit")).Text.Trim());
                    totalCostUsd = (lhCostUsd * decimal.Parse(lHQuantity.ToString()));
                    if (mealsCostUsd.HasValue && mealsQuantity.HasValue) totalCostUsd = totalCostUsd + (mealsCostUsd.Value * decimal.Parse(mealsQuantity.Value.ToString()));
                    if (motelCostUsd.HasValue && motelQuantity.HasValue) totalCostUsd = totalCostUsd + (motelCostUsd.Value * decimal.Parse(motelQuantity.Value.ToString()));
                    totalCostUsd = Decimal.Round(totalCostUsd, 2);
                }

                DateTime startDate = ((RadDatePicker)grdTeamMembers.Rows[e.RowIndex].Cells[0].FindControl("tkrdpStartDateEdit")).SelectedDate.Value;
                DateTime endDate = ((RadDatePicker)grdTeamMembers.Rows[e.RowIndex].Cells[0].FindControl("tkrdpEndDateEdit")).SelectedDate.Value;

                string workFunctionConcat = "";
                string function_ = "";
                workFunctionConcat = ((DropDownList)grdTeamMembers.Rows[e.RowIndex].Cells[0].FindControl("ddlWorkFunctionEdit")).SelectedValue;
                if (workFunctionConcat != "(Select)")
                {
                    string[] workFunction = workFunctionConcat.ToString().Trim().Split('.');
                    function_ = workFunction[1].Trim();
                }

                // Update data
                ProjectCostingSheetAddLabourHoursInformation model = new ProjectCostingSheetAddLabourHoursInformation(projectCostingSheetAddTDS);
                model.Update(costingSheetId, work_, employeeId, refId, lHQuantity, unitOfMeasurementLH, unitOfMeasurementMeals, mealsQuantity, unitOfMeasurementMotel, motelQuantity, lhCostCad, mealsCostCad, motelCostCad, totalCostCad, lhCostUsd, mealsCostUsd, motelCostUsd, totalCostUsd, false, companyId, name, startDate, endDate, workFunctionConcat, function_);

                // Store dataset
                labourHoursInformation = (ProjectCostingSheetAddTDS.LabourHoursInformationDataTable)model.Table;
                Session["labourHoursInformation"] = labourHoursInformation;
                Session["projectCostingSheetAddTDS"] = projectCostingSheetAddTDS;

                StepLabourHoursInformationProcessGrid();
            }
            else
            {
                e.Cancel = true;
            }
        }
        protected void grdTeamMembers_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            // Team member Gridview, if the gridview is edition mode
            if (grdTeamMembers.EditIndex >= 0)
            {
                grdTeamMembers.UpdateRow(grdTeamMembers.EditIndex, true);
            }

            // Add New Team Member
            int costingSheetId = (int)e.Keys["CostingSheetID"];
            string work_ = (string)e.Keys["Work_"];
            int employeeId = (int)e.Keys["EmployeeID"];
            int refId = (int)e.Keys["RefID"];

            ProjectCostingSheetAddLabourHoursInformation model = new ProjectCostingSheetAddLabourHoursInformation(projectCostingSheetAddTDS);

            // Delete Team Member Cost
            model.Delete(costingSheetId, work_, employeeId, refId);

            // Store dataset
            labourHoursInformation = (ProjectCostingSheetAddTDS.LabourHoursInformationDataTable)model.Table;
            Session["labourHoursInformation"] = labourHoursInformation;
            Session["projectCostingSheetAddTDS"] = projectCostingSheetAddTDS;

            StepLabourHoursInformationProcessGrid();
        }
        // /////////////////////////////////////////////////////////////////////////////////////////////////////
        //
        // STEP4 - LABOUR HOUR INFORMATION
        //
        // ////////////////////////////////////////////////////////////////////////
        // STEP4 - LABOUR HOUR INFORMATION - EVENTS
        //
        protected void grdTeamMembers_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            switch (e.CommandName)
            {
                case "Add":
                    // Team member Gridview, if the gridview is edition mode
                    if (grdTeamMembers.EditIndex >= 0)
                    {
                        grdTeamMembers.UpdateRow(grdTeamMembers.EditIndex, true);
                    }

                    // Add New Team Member
                    int projectId = Int32.Parse(hdfProjectId.Value);
                    ProjectGateway projectGateway = new ProjectGateway();

                    // Validate general data
                    Page.Validate("labourHoursNew");

                    if (Page.IsValid)
                    {
                        projectGateway.LoadByProjectId(projectId);

                        // Validate costs
                        if (projectGateway.GetCountryID(projectId) == 1) //Canada
                        {
                            Page.Validate("labourHoursCadNew");
                        }
                        else
                        {
                            Page.Validate("labourHoursUsdNew");
                        }
                    }

                    if (Page.IsValid)
                    {
                        int companyId = Int32.Parse(hdfCompanyId.Value);
                        string typeOfWork = ((DropDownList)grdTeamMembers.FooterRow.FindControl("ddlTypeOfWork_New")).SelectedValue;
                        int employeeId = Int32.Parse(((DropDownList)grdTeamMembers.FooterRow.FindControl("ddlTeamMemberNew")).SelectedValue);
                        string name = ((DropDownList)grdTeamMembers.FooterRow.FindControl("ddlTeamMemberNew")).SelectedItem.Text;
                        string unitOfMeasurementLH = ((DropDownList)grdTeamMembers.FooterRow.FindControl("ddlUnitOfMeasurementLHNew")).SelectedValue;
                        double lHQuantity = double.Parse(((TextBox)grdTeamMembers.FooterRow.FindControl("tbxLHQtyNew")).Text.Trim());
                        string unitOfMeasurementMeals = ((DropDownList)grdTeamMembers.FooterRow.FindControl("ddlUnitsOfMeasurementLHMealsNew")).SelectedValue;
                        int? mealsQuantity = null; if (((TextBox)grdTeamMembers.FooterRow.FindControl("tbxMealsQtyNew")).Text.Trim() != "") mealsQuantity = Int32.Parse(((TextBox)grdTeamMembers.FooterRow.FindControl("tbxMealsQtyNew")).Text.Trim());
                        string unitOfMeasurementMotel = ((DropDownList)grdTeamMembers.FooterRow.FindControl("ddlUnitsOfMeasurementLHMotelNew")).SelectedValue;
                        int? motelQuantity = null; if (((TextBox)grdTeamMembers.FooterRow.FindControl("tbxMotelQtyNew")).Text.Trim() != "") motelQuantity = Int32.Parse(((TextBox)grdTeamMembers.FooterRow.FindControl("tbxMotelQtyNew")).Text.Trim());

                        decimal lhCostCad = 0.0M;
                        decimal totalCostCad = 0.0M;
                        decimal? mealsCostCad = null;
                        decimal? motelCostCad = null;
                        decimal lhCostUsd = 0.0M;
                        decimal totalCostUsd = 0.0M;
                        decimal? mealsCostUsd = null;
                        decimal? motelCostUsd = null;

                        if (projectGateway.GetCountryID(projectId) == 1) //Canada
                        {
                            lhCostCad = Decimal.Parse(((TextBox)grdTeamMembers.FooterRow.FindControl("tbxLHCostCADNew")).Text.Trim());
                            if (((TextBox)grdTeamMembers.FooterRow.FindControl("tbxMealsCostCADNew")).Text.Trim() != "") mealsCostCad = Decimal.Parse(((TextBox)grdTeamMembers.FooterRow.FindControl("tbxMealsCostCADNew")).Text.Trim());
                            if (((TextBox)grdTeamMembers.FooterRow.FindControl("tbxMotelCostCADNew")).Text.Trim() != "") motelCostCad = Decimal.Parse(((TextBox)grdTeamMembers.FooterRow.FindControl("tbxMotelCostCADNew")).Text.Trim());
                            totalCostCad = (lhCostCad * decimal.Parse(lHQuantity.ToString()));
                            if (mealsCostCad.HasValue && mealsQuantity.HasValue) totalCostCad = totalCostCad + (mealsCostCad.Value * decimal.Parse(mealsQuantity.Value.ToString()));
                            if (motelCostCad.HasValue && motelQuantity.HasValue) totalCostCad = totalCostCad + (motelCostCad.Value * decimal.Parse(motelQuantity.Value.ToString()));
                            totalCostCad = Decimal.Round(totalCostCad, 2);
                        }
                        else
                        {
                            lhCostUsd = Decimal.Parse(((TextBox)grdTeamMembers.FooterRow.FindControl("tbxLHCostUSDNew")).Text.Trim());
                            if (((TextBox)grdTeamMembers.FooterRow.FindControl("tbxMealsCostUSDNew")).Text.Trim() != "") mealsCostUsd = Decimal.Parse(((TextBox)grdTeamMembers.FooterRow.FindControl("tbxMealsCostUSDNew")).Text.Trim());
                            if (((TextBox)grdTeamMembers.FooterRow.FindControl("tbxMotelCostUSDNew")).Text.Trim() != "") motelCostUsd = Decimal.Parse(((TextBox)grdTeamMembers.FooterRow.FindControl("tbxMotelCostUSDNew")).Text.Trim());
                            totalCostUsd = (lhCostUsd * decimal.Parse(lHQuantity.ToString()));
                            if (mealsCostUsd.HasValue && mealsQuantity.HasValue) totalCostUsd = totalCostUsd + (mealsCostUsd.Value * decimal.Parse(mealsQuantity.Value.ToString()));
                            if (motelCostUsd.HasValue && motelQuantity.HasValue) totalCostUsd = totalCostUsd + (motelCostUsd.Value * decimal.Parse(motelQuantity.Value.ToString()));
                            totalCostUsd = Decimal.Round(totalCostUsd, 2);
                        }

                        DateTime startDate = ((RadDatePicker)grdTeamMembers.FooterRow.FindControl("tkrdpStartDateNew")).SelectedDate.Value;
                        DateTime endDate = ((RadDatePicker)grdTeamMembers.FooterRow.FindControl("tkrdpEndDateNew")).SelectedDate.Value;

                        string workFunctionConcat = "";
                        string function_ = "";
                        workFunctionConcat = ((DropDownList)grdTeamMembers.FooterRow.FindControl("ddlWorkFunctionNew")).SelectedValue;
                        if (workFunctionConcat != "(Select)")
                        {
                            string[] workFunction = workFunctionConcat.ToString().Trim().Split('.');
                            function_ = workFunction[1].Trim();
                        }

                        ProjectCostingSheetAddLabourHoursInformation model = new ProjectCostingSheetAddLabourHoursInformation(projectCostingSheetAddTDS);
                        model.Insert(0, typeOfWork, employeeId, lHQuantity, unitOfMeasurementLH, unitOfMeasurementMeals, mealsQuantity, unitOfMeasurementMotel, motelQuantity, lhCostCad, mealsCostCad, motelCostCad, totalCostCad, lhCostUsd, mealsCostUsd, motelCostUsd, totalCostUsd, false, companyId, name, startDate, endDate, workFunctionConcat, function_);

                        Session.Remove("labourHoursInformationDummy");
                        labourHoursInformation = (ProjectCostingSheetAddTDS.LabourHoursInformationDataTable)model.Table;
                        Session["labourHoursInformation"] = labourHoursInformation;
                        Session["projectCostingSheetAddTDS"] = projectCostingSheetAddTDS;

                        grdTeamMembers.DataBind();
                        StepLabourHoursInformationProcessGrid();
                    }
                    break;
            }
        }