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

            if (Page.IsValid)
            {
                int costingSheetId = (int)e.Keys["CostingSheetID"];
                string category = (string)e.Keys["Category"];
                int refId = (int)e.Keys["RefID"];

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

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

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

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

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

                    if (Page.IsValid)
                    {
                        int companyId = Int32.Parse(hdfCompanyId.Value);
                        string category = ((DropDownList)grdOtherCategory.FooterRow.FindControl("ddlCategoryNew")).SelectedValue;
                        decimal rate = Decimal.Parse(((TextBox)grdOtherCategory.FooterRow.FindControl("tbxRateNew")).Text.Trim());

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

                        ProjectCostingSheetInformationOtherCategoryInformation model = new ProjectCostingSheetInformationOtherCategoryInformation(projectCostingSheetInformationTDS);
                        model.Insert(0, category, rate, false, companyId, startDate, endDate);

                        Session.Remove("otherCategoryInformationDummy");
                        otherCategoryInformation = (ProjectCostingSheetInformationTDS.OtherCategoryInformationDataTable)model.Table;
                        Session["otherCategoryInformation"] = otherCategoryInformation;
                        Session["projectCostingSheetInformationTDS"] = projectCostingSheetInformationTDS;

                        grdOtherCategory.DataBind();

                        StepOtherCategoryInformationProcessGrid();
                    }
                    break;
            }
        }
        protected void grdOtherCategory_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            // OtherCategory Gridview, if the gridview is edition mode
            if (grdOtherCategory.EditIndex >= 0)
            {
                grdOtherCategory.UpdateRow(grdOtherCategory.EditIndex, true);
            }

            // Delete otherCategory
            int costingSheetId = (int)e.Keys["CostingSheetID"];
            string category = (string)e.Keys["Category"];
            int refId = (int)e.Keys["RefID"];

            ProjectCostingSheetInformationOtherCategoryInformation model = new ProjectCostingSheetInformationOtherCategoryInformation(projectCostingSheetInformationTDS);
            model.Delete(costingSheetId, category, refId);

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

            StepOtherCategoryInformationProcessGrid();
        }
        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);
            }
        }