// ////////////////////////////////////////////////////////////////////////
        //  STEP5 - BONDING COMPANIES COST BY CLIENT AND PROJECT - PUBLIC METHODS
        //
        public ActualCostsAddTDS.BondingCompaniesCostsDataTable GetBondingCompaniesDetailBondingCompaniesByClientProject()
        {
            bondingCompaniesCosts = (ActualCostsAddTDS.BondingCompaniesCostsDataTable)Session["bondingCompaniesCostsByClientProjectDummy"];
            if (bondingCompaniesCosts == null)
            {
                bondingCompaniesCosts = ((ActualCostsAddTDS.BondingCompaniesCostsDataTable)Session["bondingCompaniesCosts"]);
            }

            return bondingCompaniesCosts;
        }
        protected void grdBondingCompaniesCostsByClientProject_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            Page.Validate("DataEditBondingCompaniesByClientProject");
            if (Page.IsValid)
            {
                int companyId = Int32.Parse(hdfCompanyId.Value);
                int refId = Int32.Parse(((Label)grdBondingCompaniesCostsByClientProject.Rows[e.RowIndex].FindControl("lblRefIdEditBondingCompaniesByClientProject")).Text);
                DateTime date = (DateTime)((RadDatePicker)grdBondingCompaniesCostsByClientProject.Rows[e.RowIndex].FindControl("tkrdpDateEditBondingCompaniesByClientProject")).SelectedDate;

                int bondingCompanyId = Int32.Parse(((DropDownList)grdBondingCompaniesCostsByClientProject.Rows[e.RowIndex].FindControl("ddlBondingCompaniesEditBondingCompaniesByClientProject")).Text);
                string name = ((DropDownList)grdBondingCompaniesCostsByClientProject.Rows[e.RowIndex].FindControl("ddlBondingCompaniesEditBondingCompaniesByClientProject")).SelectedItem.Text;

                int projectId = Int32.Parse(((Label)grdBondingCompaniesCostsByClientProject.Rows[e.RowIndex].FindControl("lblProjectIdEditBondingCompaniesByClientProject")).Text);

                decimal rate = decimal.Round(decimal.Parse(((TextBox)grdBondingCompaniesCostsByClientProject.Rows[e.RowIndex].FindControl("tbxRateEditBondingCompaniesByClientProject")).Text), 2);
                decimal rateCad = 0;
                decimal rateUsd = 0;

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

                if (projectGateway.GetCountryID(projectId) == 1) //Canada
                {
                    rateCad = rate;
                }
                else
                {
                    rateUsd = rate;
                }

                string comment = ((TextBox)grdBondingCompaniesCostsByClientProject.Rows[e.RowIndex].FindControl("tbxCommentEditBondingCompaniesByClientProject")).Text;
                bool deleted = false;

                // Update Data
                ActualCostsAddBondingCompaniesCosts actualCostsAddBondingCompaniesCosts = new ActualCostsAddBondingCompaniesCosts(actualCostsAddTDS);
                actualCostsAddBondingCompaniesCosts.Update(projectId, refId, bondingCompanyId, date, rateCad, rateUsd, comment, deleted, companyId, name);

                // Store dataset
                Session.Remove("subcontractorCostsBySubcontractorDummy");
                Session.Remove("bondingCompaniesCostsByClientProjectDummy");

                Session["actualCostsAddTDS"] = actualCostsAddTDS;
                Session["bondingCompaniesCosts"] = actualCostsAddTDS.BondingCompaniesCosts;

                bondingCompaniesCosts = actualCostsAddTDS.BondingCompaniesCosts;
            }
            else
            {
                e.Cancel = true;
            }
        }
        private void grdBondingCompaniesCostsByClientProjectDetailAdd()
        {
            if (FooterValidateBondingCompaniesByClientProject())
            {
                Page.Validate("DataNewBondingCompaniesByClientProject");
                if (Page.IsValid)
                {
                    int companyId = Int32.Parse(hdfCompanyId.Value);
                    DateTime date = (DateTime)((RadDatePicker)grdBondingCompaniesCostsByClientProject.FooterRow.FindControl("tkrdpDateFooterBondingCompaniesByClientProject")).SelectedDate;

                    int bondingCompanyId = Int32.Parse(((DropDownList)grdBondingCompaniesCostsByClientProject.FooterRow.FindControl("ddlBondingCompaniesFooterBondingCompaniesByClientProject")).Text);
                    string name = ((DropDownList)grdBondingCompaniesCostsByClientProject.FooterRow.FindControl("ddlBondingCompaniesFooterBondingCompaniesByClientProject")).SelectedItem.Text;

                    int clientId = Int32.Parse(((DropDownList)grdBondingCompaniesCostsByClientProject.FooterRow.FindControl("ddlClientFooterBondingCompaniesByClientProject")).SelectedValue);
                    string client = ((DropDownList)grdBondingCompaniesCostsByClientProject.FooterRow.FindControl("ddlClientFooterBondingCompaniesByClientProject")).SelectedItem.Text;

                    int projectId = Int32.Parse(((DropDownList)grdBondingCompaniesCostsByClientProject.FooterRow.FindControl("ddlProjectFooterBondingCompaniesByClientProject")).SelectedValue);
                    string project = ((DropDownList)grdBondingCompaniesCostsByClientProject.FooterRow.FindControl("ddlProjectFooterBondingCompaniesByClientProject")).SelectedItem.Text;

                    decimal rate = decimal.Round(decimal.Parse(((TextBox)grdBondingCompaniesCostsByClientProject.FooterRow.FindControl("tbxRateFooterBondingCompaniesByClientProject")).Text), 2);
                    string comment = ((TextBox)grdBondingCompaniesCostsByClientProject.FooterRow.FindControl("tbxCommentFooterBondingCompaniesByClientProject")).Text;
                    bool deleted = false;
                    bool inDatabase = false;
                    decimal rateCad = 0;
                    decimal rateUsd = 0;
                    ProjectGateway projectGateway = new ProjectGateway();
                    projectGateway.LoadByProjectId(projectId);

                    if (projectGateway.GetCountryID(projectId) == 1) //Canada
                    {
                        rateCad = rate;
                        rateUsd = rate;
                    }
                    else
                    {
                        rateCad = rate;
                        rateUsd = rate;
                    }

                    // Insert Data
                    ActualCostsAddBondingCompaniesCosts actualCostsAddBondingCompaniesCosts = new ActualCostsAddBondingCompaniesCosts(actualCostsAddTDS);
                    actualCostsAddBondingCompaniesCosts.Insert(projectId, bondingCompanyId, date, rateCad, rateUsd, comment, deleted, companyId, inDatabase, name, client, project, clientId);

                    // Store dataset
                    Session.Remove("subcontractorCostsBySubcontractorDummy");
                    Session.Remove("bondingCompaniesCostsByClientProjectDummy");

                    Session["actualCostsAddTDS"] = actualCostsAddTDS;
                    Session["bondingCompaniesCosts"] = actualCostsAddTDS.BondingCompaniesCosts;

                    bondingCompaniesCosts = actualCostsAddTDS.BondingCompaniesCosts;

                    grdBondingCompaniesCostsByClientProject.DataBind();
                    grdBondingCompaniesCostsByClientProject.PageIndex = grdBondingCompaniesCostsByClientProject.PageCount - 1;
                }
            }
        }
        protected void grdBondingCompaniesCostsByClientProject_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            // BondingCompanies Gridview, if the gridview is edition mode
            if (grdBondingCompaniesCostsByClientProject.EditIndex >= 0)
            {
                grdBondingCompaniesCostsByClientProject.UpdateRow(grdBondingCompaniesCostsByClientProject.EditIndex, true);
            }

            // Delete BondingCompanies
            int projectId = (int)e.Keys["ProjectID"];
            int refId = (int)e.Keys["RefID"];

            // Delete costs details
            ActualCostsAddBondingCompaniesCosts actualCostsAddBondingCompaniesCosts = new ActualCostsAddBondingCompaniesCosts(actualCostsAddTDS);
            actualCostsAddBondingCompaniesCosts.Delete(projectId, refId);

            // Store dataset
            Session.Remove("subcontractorCostsBySubcontractorDummy");
            Session.Remove("bondingCompaniesCostsByClientProjectDummy");

            Session["actualCostsAddTDS"] = actualCostsAddTDS;
            Session["bondingCompaniesCosts"] = actualCostsAddTDS.BondingCompaniesCosts;

            bondingCompaniesCosts = actualCostsAddTDS.BondingCompaniesCosts;
        }
        protected void AddBondingCompaniesCostsNewEmptyFix(GridView grdBondingCompaniesCostsByClientProject)
        {
            if (grdBondingCompaniesCostsByClientProject.Rows.Count == 0)
            {
                int companyId = Int32.Parse(hdfCompanyId.Value);
                ActualCostsAddTDS.BondingCompaniesCostsDataTable dt = new ActualCostsAddTDS.BondingCompaniesCostsDataTable();
                dt.AddBondingCompaniesCostsRow(-1, -1, DateTime.Now, -1, -1, "", false, companyId, false, "", 0, "", "", 1);
                Session["bondingCompaniesCostsByClientProjectDummy"] = dt;

                grdBondingCompaniesCostsByClientProject.DataBind();
            }

            // normally executes at all postbacks
            if (grdBondingCompaniesCostsByClientProject.Rows.Count == 1)
            {
                ActualCostsAddTDS.BondingCompaniesCostsDataTable dt = (ActualCostsAddTDS.BondingCompaniesCostsDataTable)Session["bondingCompaniesCostsByClientProjectDummy"];
                if (dt != null)
                {
                    grdBondingCompaniesCostsByClientProject.Rows[0].Visible = false;
                    grdBondingCompaniesCostsByClientProject.Rows[0].Controls.Clear();
                }
            }
        }