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

            if (Page.IsValid)
            {
                int costingSheetId = (int)e.Keys["CostingSheetID"];
                int refIdRevenue = (int)e.Keys["RefIDRevenue"];

                int companyId = Int32.Parse(hdfCompanyId.Value);
                string comment = ((TextBox)grdRevenue.Rows[e.RowIndex].Cells[0].FindControl("tbxCommentEdit")).Text;

                decimal revenue = 0.0M;
                revenue = Decimal.Parse(((TextBox)grdRevenue.Rows[e.RowIndex].Cells[0].FindControl("tbxRevenueEdit")).Text.Trim());
                revenue = Decimal.Round(revenue, 2);

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

                // Update data
                ProjectCombinedCostingSheetAddRevenueInformation model = new ProjectCombinedCostingSheetAddRevenueInformation(projectCostingSheetAddTDS);
                model.Update(costingSheetId, refIdRevenue, revenue, false, companyId, startDate, endDate, comment);

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

                StepRevenueInformationProcessGrid();
            }
            else
            {
                e.Cancel = true;
            }
        }
        protected void grdRevenue_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            // Revenue Gridview, if the gridview is edition mode
            if (grdRevenue.EditIndex >= 0)
            {
                grdRevenue.UpdateRow(grdRevenue.EditIndex, true);
            }

            // Delete revenue
            int costingSheetId = (int)e.Keys["CostingSheetID"];
            int refIdRevenue = (int)e.Keys["RefIDRevenue"];

            ProjectCombinedCostingSheetAddRevenueInformation model = new ProjectCombinedCostingSheetAddRevenueInformation(projectCostingSheetAddTDS);
            model.Delete(costingSheetId, refIdRevenue);

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

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

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

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

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

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

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

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

                    ProjectCombinedCostingSheetAddRevenueInformation projectCostingSheetAddRevenueInformation = new ProjectCombinedCostingSheetAddRevenueInformation(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);
            }
        }
        // /////////////////////////////////////////////////////////////////////////////////////////////////////
        //
        // STEP9 - REVENUE INFORMATION
        //
        // ////////////////////////////////////////////////////////////////////////
        // STEP9 - REVENUE INFORMATION - EVENTS
        //
        protected void grdRevenue_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            switch (e.CommandName)
            {
                case "Add":
                    // Revenue Gridview, if the gridview is edition mode
                    if (grdRevenue.EditIndex >= 0)
                    {
                        grdRevenue.UpdateRow(grdRevenue.EditIndex, true);
                    }

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

                    if (Page.IsValid)
                    {
                        int companyId = Int32.Parse(hdfCompanyId.Value);
                        string comment = ""; if (((TextBox)grdRevenue.FooterRow.FindControl("tbxCommentNew")).Text.Trim() != "") comment = ((TextBox)grdRevenue.FooterRow.FindControl("tbxCommentNew")).Text.Trim();

                        decimal revenue = 0.0M;
                        revenue = Decimal.Parse(((TextBox)grdRevenue.FooterRow.FindControl("tbxRevenueNew")).Text.Trim());
                        revenue = Decimal.Round(revenue, 2);

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

                        ProjectCombinedCostingSheetAddRevenueInformation model = new ProjectCombinedCostingSheetAddRevenueInformation(projectCostingSheetAddTDS);
                        model.Insert(0, revenue, false, companyId, startDate, endDate, comment, 1);

                        Session.Remove("revenueInformationDummy");
                        revenueInformation = (ProjectCostingSheetAddTDS.CombinedRevenueInformationDataTable)model.Table;
                        Session["revenueInformation"] = revenueInformation;
                        Session["projectCostingSheetAddTDS"] = projectCostingSheetAddTDS;

                        grdRevenue.DataBind();

                        StepRevenueInformationProcessGrid();
                    }
                    break;
            }
        }
        // ////////////////////////////////////////////////////////////////////////
        // STEP9 - REVENUE INFORMATION - METHODS
        //
        private void StepRevenueInformationIn()
        {
            // Set instruction
            Label instruction = (Label)this.Master.FindControl("lblInstruction");
            instruction.Text = "Please verify Revenue information";

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

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

            // Store tables
            Session.Remove("revenueInformationDummy");
            revenueInformation = (ProjectCostingSheetAddTDS.CombinedRevenueInformationDataTable)model.Table;
            Session["revenueInformation"] = revenueInformation;
            Session["projectCostingSheetAddTDS"] = projectCostingSheetAddTDS;

            grdRevenue.DataBind();
            StepRevenueInformationProcessGrid();

            GetRevenueSummary();
        }