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

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

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

                // Update data
                ProjectCostingSheetInformationHotelsInformation model = new ProjectCostingSheetInformationHotelsInformation(projectCostingSheetInformationTDS);
                model.Update(costingSheetId, hotelId, refId, rate, false, companyId, startDate, endDate);

                // Store dataset
                hotelsInformation = (ProjectCostingSheetInformationTDS.HotelsInformationDataTable)model.Table;
                Session["hotelsInformation"] = hotelsInformation;
                Session["projectCostingSheetInformationTDS"] = projectCostingSheetInformationTDS;

                StepHotelsInformationProcessGrid();
            }
            else
            {
                e.Cancel = true;
            }
        }
        ///////////////////////////////
        protected void grdHotels_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            switch (e.CommandName)
            {
                case "Add":
                    // Hotels Gridview, if the gridview is edition mode
                    if (grdHotels.EditIndex >= 0)
                    {
                        grdHotels.UpdateRow(grdHotels.EditIndex, true);
                    }

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

                    if (Page.IsValid)
                    {
                        int companyId = Int32.Parse(hdfCompanyId.Value);
                        int hotelId = Int32.Parse(((DropDownList)grdHotels.FooterRow.FindControl("ddlHotelNew")).SelectedValue);
                        string hotel = ((DropDownList)grdHotels.FooterRow.FindControl("ddlHotelNew")).SelectedItem.Text;
                        decimal rate = Decimal.Parse(((TextBox)grdHotels.FooterRow.FindControl("tbxRateNew")).Text.Trim());

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

                        ProjectCostingSheetInformationHotelsInformation model = new ProjectCostingSheetInformationHotelsInformation(projectCostingSheetInformationTDS);
                        model.Insert(0, hotelId, rate, false, companyId, hotel, startDate, endDate);

                        Session.Remove("hotelsInformationDummy");
                        hotelsInformation = (ProjectCostingSheetInformationTDS.HotelsInformationDataTable)model.Table;
                        Session["hotelsInformation"] = hotelsInformation;
                        Session["projectCostingSheetInformationTDS"] = projectCostingSheetInformationTDS;

                        grdHotels.DataBind();

                        StepHotelsInformationProcessGrid();
                    }
                    break;
            }
        }
        protected void grdHotels_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            // Hotels Gridview, if the gridview is edition mode
            if (grdHotels.EditIndex >= 0)
            {
                grdHotels.UpdateRow(grdHotels.EditIndex, true);
            }

            // Delete hotel
            int costingSheetId = (int)e.Keys["CostingSheetID"];
            int hotelId = (int)e.Keys["HotelID"];
            int refId = (int)e.Keys["RefID"];

            ProjectCostingSheetInformationHotelsInformation model = new ProjectCostingSheetInformationHotelsInformation(projectCostingSheetInformationTDS);
            model.Delete(costingSheetId, hotelId, refId);

            // Store dataset
            hotelsInformation = (ProjectCostingSheetInformationTDS.HotelsInformationDataTable)model.Table;
            Session["hotelsInformation"] = hotelsInformation;
            Session["projectCostingSheetInformationTDS"] = projectCostingSheetInformationTDS;

            StepHotelsInformationProcessGrid();
        }
        private void UpdateDatabase()
        {
            int companyId = Int32.Parse(hdfCompanyId.Value);
            int costingSheetId = Int32.Parse(hdfCostingSheetId.Value);

            DB.Open();
            DB.BeginTransaction();
            try
            {
                ProjectCostingSheetInformationBasicInformation projectCostingSheetInformationBasicInformation = new ProjectCostingSheetInformationBasicInformation(projectCostingSheetInformationTDS);
                projectCostingSheetInformationBasicInformation.Save(companyId);

                // Save costs information
                ProjectCostingSheetInformationLabourHoursInformation projectCostingSheetInformationLabourHoursInformation = new ProjectCostingSheetInformationLabourHoursInformation(projectCostingSheetInformationTDS);
                projectCostingSheetInformationLabourHoursInformation.Save(companyId, costingSheetId);

                ProjectCostingSheetInformationUnitsInformation projectCostingSheetInformationUnitsInformation = new ProjectCostingSheetInformationUnitsInformation(projectCostingSheetInformationTDS);
                projectCostingSheetInformationUnitsInformation.Save(companyId, costingSheetId);

                ProjectCostingSheetInformationMaterialsInformation projectCostingSheetInformationMaterialsInformation = new ProjectCostingSheetInformationMaterialsInformation(projectCostingSheetInformationTDS);
                projectCostingSheetInformationMaterialsInformation.Save(companyId, costingSheetId);

                ProjectCostingSheetInformationOtherCostsInformation projectCostingSheetInformationOtherCostsInformation = new ProjectCostingSheetInformationOtherCostsInformation(projectCostingSheetInformationTDS);
                projectCostingSheetInformationOtherCostsInformation.Save(companyId, costingSheetId);

                ProjectCostingSheetInformationSubcontractorsInformation projectCostingSheetInformationSubcontractorsInformation = new ProjectCostingSheetInformationSubcontractorsInformation(projectCostingSheetInformationTDS);
                projectCostingSheetInformationSubcontractorsInformation.Save(companyId, costingSheetId);

                ProjectCostingSheetInformationHotelsInformation projectCostingSheetInformationHotelsInformation = new ProjectCostingSheetInformationHotelsInformation(projectCostingSheetInformationTDS);
                projectCostingSheetInformationHotelsInformation.Save(companyId, costingSheetId);

                ProjectCostingSheetInformationBondingsInformation projectCostingSheetInformationBondingsInformation = new ProjectCostingSheetInformationBondingsInformation(projectCostingSheetInformationTDS);
                projectCostingSheetInformationBondingsInformation.Save(companyId, costingSheetId);

                ProjectCostingSheetInformationInsurancesInformation projectCostingSheetInformationInsurancesInformation = new ProjectCostingSheetInformationInsurancesInformation(projectCostingSheetInformationTDS);
                projectCostingSheetInformationInsurancesInformation.Save(companyId, costingSheetId);

                ProjectCostingSheetInformationOtherCategoryInformation projectCostingSheetInformationOtherCategoryInformation = new ProjectCostingSheetInformationOtherCategoryInformation(projectCostingSheetInformationTDS);
                projectCostingSheetInformationOtherCategoryInformation.Save(companyId, costingSheetId);

                DB.CommitTransaction();

                // Store datasets
                projectCostingSheetInformationTDS.AcceptChanges();
                Session["lfsProjectTDS"] = projectTDS;
                Session["projectCostingSheetInformationTDS"] = projectCostingSheetInformationTDS;
                Session["labourHoursInformation"] = projectCostingSheetInformationTDS.LabourHoursInformation;
                Session["unitsInformation"] = projectCostingSheetInformationTDS.UnitsInformation;
                Session["subcontractorsInformation"] = projectCostingSheetInformationTDS.SubcontractorsInformation;
                Session["materialsInformation"] = projectCostingSheetInformationTDS.MaterialsInformation;
                Session["otherCostsInformation"] = projectCostingSheetInformationTDS.OtherCostsInformation;

                Session["hotelssInformation"] = projectCostingSheetInformationTDS.HotelsInformation;
                Session["bondingsInformation"] = projectCostingSheetInformationTDS.BondingsInformation;
                Session["insurancesInformation"] = projectCostingSheetInformationTDS.InsurancesInformation;
                Session["otherCategoryInformation"] = projectCostingSheetInformationTDS.OtherCategoryInformation;
            }
            catch (Exception ex)
            {
                DB.RollbackTransaction();

                string url = string.Format("./../../error_page.aspx?error={0}", ex.Message.Replace('\n', ' '));
                Response.Redirect(url);
            }
        }