protected void grdBondings_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            // Validate general data
            Page.Validate("bondingEdit");

            if (Page.IsValid)
            {
                int costingSheetId = (int)e.Keys["CostingSheetID"];
                int bondingCompanyId = (int)e.Keys["BondingCompanyID"];
                int refId = (int)e.Keys["RefID"];

                int companyId = Int32.Parse(hdfCompanyId.Value);
                decimal rate = Decimal.Parse(((TextBox)grdBondings.Rows[e.RowIndex].Cells[0].FindControl("tbxRateEdit")).Text.Trim());
                DateTime startDate = ((RadDatePicker)grdBondings.Rows[e.RowIndex].Cells[0].FindControl("tkrdpStartDateEdit")).SelectedDate.Value;
                DateTime endDate = ((RadDatePicker)grdBondings.Rows[e.RowIndex].Cells[0].FindControl("tkrdpEndDateEdit")).SelectedDate.Value;

                // Update data
                ProjectCostingSheetAddBondingsInformation model = new ProjectCostingSheetAddBondingsInformation(projectCostingSheetAddTDS);
                model.Update(costingSheetId, bondingCompanyId, refId, rate, false, companyId, startDate, endDate);

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

                StepBondingsInformationProcessGrid();
            }
            else
            {
                e.Cancel = true;
            }
        }
        protected void grdBondings_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            // Bondings Gridview, if the gridview is edition mode
            if (grdBondings.EditIndex >= 0)
            {
                grdBondings.UpdateRow(grdBondings.EditIndex, true);
            }

            // Delete bonding
            int costingSheetId = (int)e.Keys["CostingSheetID"];
            int bondingCompanyId = (int)e.Keys["BondingCompanyID"];
            int refId = (int)e.Keys["RefID"];

            ProjectCostingSheetAddBondingsInformation model = new ProjectCostingSheetAddBondingsInformation(projectCostingSheetAddTDS);
            model.Delete(costingSheetId, bondingCompanyId, refId);

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

            StepBondingsInformationProcessGrid();
        }
        // /////////////////////////////////////////////////////////////////////////////////////////////////////
        //
        // STEP7 - BONDING INFORMATION
        //
        // ////////////////////////////////////////////////////////////////////////
        // STEP7 - BONDING INFORMATION - EVENTS
        //
        protected void grdBondings_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            switch (e.CommandName)
            {
                case "Add":
                    // Bondings Gridview, if the gridview is edition mode
                    if (grdBondings.EditIndex >= 0)
                    {
                        grdBondings.UpdateRow(grdBondings.EditIndex, true);
                    }

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

                    if (Page.IsValid)
                    {
                        int companyId = Int32.Parse(hdfCompanyId.Value);
                        int bondingCompanyId = Int32.Parse(((DropDownList)grdBondings.FooterRow.FindControl("ddlBondingNew")).SelectedValue);
                        string bonding = ((DropDownList)grdBondings.FooterRow.FindControl("ddlBondingNew")).SelectedItem.Text;
                        decimal rate = Decimal.Parse(((TextBox)grdBondings.FooterRow.FindControl("tbxRateNew")).Text.Trim());

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

                        ProjectCostingSheetAddBondingsInformation model = new ProjectCostingSheetAddBondingsInformation(projectCostingSheetAddTDS);
                        model.Insert(0, bondingCompanyId, rate, false, companyId, startDate, endDate, bonding);

                        Session.Remove("bondingsInformationDummy");
                        bondingsInformation = (ProjectCostingSheetAddTDS.BondingsInformationDataTable)model.Table;
                        Session["bondingsInformation"] = bondingsInformation;
                        Session["projectCostingSheetAddTDS"] = projectCostingSheetAddTDS;

                        grdBondings.DataBind();

                        StepBondingsInformationProcessGrid();
                    }
                    break;
            }
        }
        private void UpdateDatabase()
        {
            DB.Open();
            DB.BeginTransaction();
            try
            {
                int companyId = Int32.Parse(hdfCompanyId.Value);
                int loginId = Convert.ToInt32(Session["loginID"]);

                if (cbxEndConfirm.Checked)
                {
                    ProjectCostingSheetAddBasicInformation projectCostingSheetAddBasicInformation = new ProjectCostingSheetAddBasicInformation(projectCostingSheetAddTDS);
                    int costingSheetId = projectCostingSheetAddBasicInformation.Save(companyId);
                    hdfCostingSheetId.Value = costingSheetId.ToString();

                    // Save costs information
                    ProjectCostingSheetAddLabourHoursInformation projectCostingSheetAddLabourHoursInformation = new ProjectCostingSheetAddLabourHoursInformation(projectCostingSheetAddTDS);
                    projectCostingSheetAddLabourHoursInformation.Save(companyId, costingSheetId);

                    ProjectCostingSheetAddUnitsInformation projectCostingSheetAddUnitsInformation = new ProjectCostingSheetAddUnitsInformation(projectCostingSheetAddTDS);
                    projectCostingSheetAddUnitsInformation.Save(companyId, costingSheetId);

                    ProjectCostingSheetAddMaterialsInformation projectCostingSheetAddMaterialsInformation = new ProjectCostingSheetAddMaterialsInformation(projectCostingSheetAddTDS);
                    projectCostingSheetAddMaterialsInformation.Save(companyId, costingSheetId);

                    ProjectCostingSheetAddSubcontractorsInformation projectCostingSheetAddSubcontractorsInformation = new ProjectCostingSheetAddSubcontractorsInformation(projectCostingSheetAddTDS);
                    projectCostingSheetAddSubcontractorsInformation.Save(companyId, costingSheetId);

                    ProjectCostingSheetAddOtherCostsInformation projectCostingSheetAddOtherCostsInformation = new ProjectCostingSheetAddOtherCostsInformation(projectCostingSheetAddTDS);
                    projectCostingSheetAddOtherCostsInformation.Save(companyId, costingSheetId);

                    ProjectCostingSheetAddHotelsInformation projectCostingSheetAddHotelsInformation = new ProjectCostingSheetAddHotelsInformation(projectCostingSheetAddTDS);
                    projectCostingSheetAddHotelsInformation.Save(companyId, costingSheetId);

                    ProjectCostingSheetAddBondingsInformation projectCostingSheetAddBondingsInformation = new ProjectCostingSheetAddBondingsInformation(projectCostingSheetAddTDS);
                    projectCostingSheetAddBondingsInformation.Save(companyId, costingSheetId);

                    ProjectCostingSheetAddInsurancesInformation projectCostingSheetAddInsurancesInformation = new ProjectCostingSheetAddInsurancesInformation(projectCostingSheetAddTDS);
                    projectCostingSheetAddInsurancesInformation.Save(companyId, costingSheetId);

                    ProjectCostingSheetAddOtherCategoryInformation projectCostingSheetAddOtherCategoryInformation = new ProjectCostingSheetAddOtherCategoryInformation(projectCostingSheetAddTDS);
                    projectCostingSheetAddOtherCategoryInformation.Save(companyId, costingSheetId);

                    ProjectCostingSheetAddRevenueInformation projectCostingSheetAddRevenueInformation = new ProjectCostingSheetAddRevenueInformation(projectCostingSheetAddTDS);
                    projectCostingSheetAddRevenueInformation.Save(companyId, costingSheetId);

                    if (rbtnBeginTemplate.Checked)
                    {
                        ProjectCostingSheetTemplateInformation projectCostingSheetTemplateInformation = new ProjectCostingSheetTemplateInformation(projectCostingSheetAddTDS);
                        projectCostingSheetTemplateInformation.Save(companyId);
                    }
                }
                else
                {
                    if (cbxEndSave.Checked)
                    {
                        ProjectCostingSheetTemplateInformation projectCostingSheetTemplateInformation = new ProjectCostingSheetTemplateInformation(projectCostingSheetAddTDS);
                        projectCostingSheetTemplateInformation.Save(companyId);
                    }
                    else
                    {
                        if (rbtnBeginTemplate.Checked)
                        {
                            ProjectCostingSheetTemplateInformation projectCostingSheetTemplateInformation = new ProjectCostingSheetTemplateInformation(projectCostingSheetAddTDS);
                            projectCostingSheetTemplateInformation.Save(companyId);
                        }
                    }
                }

                DB.CommitTransaction();

                // Store datasets
                projectCostingSheetAddTDS.AcceptChanges();
                Session["projectCostingSheetAddTDS"] = projectCostingSheetAddTDS;

            }
            catch (Exception ex)
            {
                DB.RollbackTransaction();

                string url = string.Format("./../../error_page.aspx?error={0}", ex.Message.Replace('\n', ' '));
                Response.Redirect(url);
            }
        }
        // ////////////////////////////////////////////////////////////////////////
        // STEP7 - BONDING INFORMATION - METHODS
        //
        private void StepBondingsInformationIn()
        {
            // Set instruction
            Label instruction = (Label)this.Master.FindControl("lblInstruction");
            instruction.Text = "Please verify Bondings information";

            // Load
            ProjectCostingSheetAddBondingsInformation model = new ProjectCostingSheetAddBondingsInformation(projectCostingSheetAddTDS);

            if (projectCostingSheetAddTDS.BondingsInformation.Rows.Count <= 0)
            {
                model.Load(int.Parse(hdfProjectId.Value), tkrdpFrom.SelectedDate.Value, tkrdpTo.SelectedDate.Value, int.Parse(hdfCompanyId.Value));
            }

            // Store tables
            Session.Remove("bondingsInformationDummy");
            bondingsInformation = (ProjectCostingSheetAddTDS.BondingsInformationDataTable)model.Table;
            Session["bondingsInformation"] = bondingsInformation;
            Session["projectCostingSheetAddTDS"] = projectCostingSheetAddTDS;

            // Validate grid columns
            int projectId = Int32.Parse(hdfProjectId.Value);
            ProjectGateway projectGateway = new ProjectGateway();
            projectGateway.LoadByProjectId(projectId);

            if (projectGateway.GetCountryID(projectId) == 1) //Canada
            {
                // Bondings Grid
                lblBondingsTotalCosts.Text = "Total Cost (CAD) : ";
                tbxBondingsTotalCostsCAD.Visible = true;
                tbxBondingsTotalCostsUSD.Visible = false;
            }
            else
            {
                // Bondings Grid
                lblBondingsTotalCosts.Text = "Total Cost (USD) : ";
                tbxBondingsTotalCostsCAD.Visible = false;
                tbxBondingsTotalCostsUSD.Visible = true;
            }

            grdBondings.DataBind();
            StepBondingsInformationProcessGrid();
        }