private void Save()
        {
            // Validate data
            bool validData = false;

            Page.Validate("Data");
            if (Page.IsValid)
            {
                validData = true;
            }

            if (validData)
            {
                // Save data
                int companyId = Int32.Parse(hdfCompanyId.Value);
                int projectId = Int32.Parse(hdfProjectId.Value);
                int refId = Int32.Parse(hdfRefId.Value);
                Int64 countryId = Int64.Parse(hdfCountryId.Value);

                // ... Get subcontractor hors data
                DateTime? newDate = tkrdpDate_.SelectedDate;
                double newQuantity = double.Parse(tbxQuantity.Text.Trim());

                decimal newRateCad = 0;
                decimal newTotalCad = 0;
                decimal newRateUsd = 0;
                decimal newTotalUsd = 0;
                if (countryId == 1) // Canada
                {
                    newRateCad = decimal.Parse(tbxRate.Text.Trim());
                    newTotalCad = decimal.Parse(tbxTotal.Text.Trim());
                }
                else
                {
                    newRateUsd = decimal.Parse(tbxRate.Text.Trim());
                    newTotalUsd = decimal.Parse(tbxTotal.Text.Trim());
                }
                decimal newRate = decimal.Parse(tbxRate.Text.Trim());
                decimal newTotal = decimal.Parse(tbxTotal.Text.Trim());
                string newComment = tbxComments.Text.Trim();

                // Update basic information data
                SubcontractorHoursInformationBasicInformation subcontractorHoursInformationBasicInformation = new SubcontractorHoursInformationBasicInformation(subcontractorHoursInformationTDS);
                subcontractorHoursInformationBasicInformation.Update(projectId, refId, (DateTime)newDate, newQuantity, newRateCad, newTotalCad, newRateUsd, newTotalUsd, newComment);

                // Store datasets
                Session["subcontractorHoursInformationTDS"] = subcontractorHoursInformationTDS;

                // Update database
                UpdateDatabase();

                ViewState["update"] = "yes";

                // Redirect
                string url = "";
                if (Request.QueryString["source_page"] == "subcontractor_hours_navigator2.aspx" )
                {
                    url = "./subcontractor_hours_navigator2.aspx?source_page=subcontractor_hours_edit.aspx&project_id=" + hdfProjectId.Value + "&ref_id=" + hdfRefId.Value + GetNavigatorState() + "&update=yes";
                }

                if (Request.QueryString["source_page"] == "subcontractor_hours_summary.aspx")
                {
                    url = "./subcontractor_hours_summary.aspx?source_page=subcontractor_hours_edit.aspx&project_id=" + hdfProjectId.Value + "&ref_id=" + hdfRefId.Value + GetNavigatorState() + "&update=yes";
                }

                Response.Redirect(url);
            }
        }
        private void UpdateDatabase()
        {
            int companyId = Int32.Parse(hdfCompanyId.Value);

            DB.Open();
            DB.BeginTransaction();
            try
            {
                SubcontractorHoursInformationBasicInformation subcontractorHoursInformationBasicInformation = new SubcontractorHoursInformationBasicInformation(subcontractorHoursInformationTDS);
                subcontractorHoursInformationBasicInformation.Save(companyId);

                DB.CommitTransaction();

                // Store datasets
                subcontractorHoursInformationTDS.AcceptChanges();
                Session["subcontractorHoursInformationTDS"] = subcontractorHoursInformationTDS;
            }
            catch (Exception ex)
            {
                DB.RollbackTransaction();

                string url = string.Format("./../../error_page.aspx?error={0}", ex.Message.Replace('\n', ' '));
                Response.Redirect(url);
            }
        }
        private void Apply()
        {
            // Validate data
            bool validData = false;

            Page.Validate("Data");
            if (Page.IsValid)
            {
                validData = true;
            }

            if (validData)
            {
                // Save data
                int companyId = Int32.Parse(hdfCompanyId.Value);
                int projectId = Int32.Parse(hdfProjectId.Value);
                int refId = Int32.Parse(hdfRefId.Value);
                Int64 countryId = Int64.Parse(hdfCountryId.Value);

                // ... Get subcontractor hors data
                DateTime? newDate = tkrdpDate_.SelectedDate;
                double newQuantity = double.Parse(tbxQuantity.Text.Trim());

                decimal newRateCad = 0;
                decimal newTotalCad = 0;
                decimal newRateUsd = 0;
                decimal newTotalUsd = 0;
                if (countryId == 1) // Canada
                {
                    newRateCad = decimal.Parse(tbxRate.Text.Trim());
                    newTotalCad = decimal.Parse(tbxTotal.Text.Trim());
                }
                else
                {
                    newRateUsd = decimal.Parse(tbxRate.Text.Trim());
                    newTotalUsd = decimal.Parse(tbxTotal.Text.Trim());
                }
                decimal newRate = decimal.Parse(tbxRate.Text.Trim());
                decimal newTotal = decimal.Parse(tbxTotal.Text.Trim());
                string newComment = tbxComments.Text.Trim();

                // Update basic information data
                SubcontractorHoursInformationBasicInformation subcontractorHoursInformationBasicInformation = new SubcontractorHoursInformationBasicInformation(subcontractorHoursInformationTDS);
                subcontractorHoursInformationBasicInformation.Update(projectId, refId, (DateTime)newDate, newQuantity, newRateCad, newTotalCad, newRateUsd, newTotalUsd, newComment);

                // Store datasets
                Session["subcontractorHoursInformationTDS"] = subcontractorHoursInformationTDS;

                // Update database
                UpdateDatabase();

                ViewState["update"] = "yes";
            }
        }