private void Save()
        {
            // Save to database
            DB.Open();
            DB.BeginTransaction();
            try
            {
                int newCompanyLevelIdForInsert = 0;

                // Save companyLevels
                CompanyLevelsAddNew companyLevelsAddNew = new CompanyLevelsAddNew(companyLevelsAddTDS);
                newCompanyLevelIdForInsert = companyLevelsAddNew.Save();

                // Save companyLevels managers
                int companyId = Int32.Parse(hdfCompanyId.Value);
                CompanyLevelsAddManagers companyLevelsAddManagers = new CompanyLevelsAddManagers(companyLevelsAddTDS);
                companyLevelsAddManagers.Save(newCompanyLevelIdForInsert, companyId);

                // Store datasets
                companyLevelsAddTDS.AcceptChanges();
                Session["companyLevelsAddTDS"] = companyLevelsAddTDS;

                DB.CommitTransaction();
            }
            catch (Exception ex)
            {
                DB.RollbackTransaction();

                string url = string.Format("./../../error_page.aspx?error={0}", ex.Message.Replace('\n', ' '));
                Response.Redirect(url);
            }
        }
        private bool StepSummaryFinish()
        {
            if (Page.IsValid)
            {
                int companyId = Convert.ToInt32(Session["companyID"]);
                int? companyLevelId = null;

                foreach (int companyLevelIdInArray in arrayCompanyLevelsSelected)
                {
                    companyLevelId = companyLevelIdInArray;
                }

                if (rbtnAddCompanyLevel.Checked)
                {
                    CompanyLevelsAddNew companyLevelsAddNew = new CompanyLevelsAddNew(companyLevelsAddTDS);
                    companyLevelsAddNew.Insert(null, null, tbxName.Text.Trim(), companyLevelId, false, companyId, false, tbxUnitsUnitOfMeasurement.Text.Trim());
                }

                if (rbtnEditCompanyLevel.Checked)
                {
                    CompanyLevelsAddNew companyLevelsAddNew = new CompanyLevelsAddNew(companyLevelsAddTDS);
                    companyLevelsAddNew.Insert(companyLevelId, null, tbxName.Text.Trim(), null, false, companyId, true, tbxUnitsUnitOfMeasurement.Text.Trim());
                }

                if (rbtnDeleteCompanyLevel.Checked)
                {
                    int? newCompanyLevelId = null;

                    if (arrayCompanyLevelsSelected2.Count > 0)
                    {
                        foreach (int companyLevelId2 in arrayCompanyLevelsSelected2)
                        {
                            newCompanyLevelId = companyLevelId2;
                        }
                    }

                    CompanyLevelsAddNew companyLevelsAddNew = new CompanyLevelsAddNew(companyLevelsAddTDS);
                    companyLevelsAddNew.Insert(companyLevelId, newCompanyLevelId, tbxName.Text.Trim(), null, true, companyId, true, tbxUnitsUnitOfMeasurement.Text.Trim());

                    // Delete company level managers
                    CompanyLevelsAddManagers companyLevelsAddManagers = new CompanyLevelsAddManagers(companyLevelsAddTDS);
                    companyLevelsAddManagers.DeleteAll();
                }

                // Store database
                Session["companyLevelsAddTDS"] = companyLevelsAddTDS;

                // Save
                Save();

                hdfUpdate.Value = "yes";

                return true;
            }
            else
            {
                return false;
            }
        }
        protected void Wizard_NextButtonClick(object sender, WizardNavigationEventArgs e)
        {
            switch (wzCompanyLevelsAdd.ActiveStep.Name)
            {
                case "Operation":
                    e.Cancel = !StepOperationNext();
                    if (!e.Cancel)
                    {
                        ViewState["StepFrom"] = "Operation";
                    }
                    break;

                case "Company Levels":
                    e.Cancel = !StepCompanyLevelsNext();
                    if (!e.Cancel)
                    {
                        ViewState["StepFrom"] = "Company Levels";

                        if (rbtnDeleteCompanyLevel.Checked)
                        {
                            bool inUse = false;
                            foreach (int companyLevelId in arrayCompanyLevelsSelected)
                            {
                                CompanyLevelsAddNew companyLevelsAddNew = new CompanyLevelsAddNew(null);
                                inUse = companyLevelsAddNew.CompanyLevelIsUsed(companyLevelId, Int32.Parse(hdfCompanyId.Value));
                            }

                            if (inUse)
                            {
                                wzCompanyLevelsAdd.ActiveStepIndex = wzCompanyLevelsAdd.WizardSteps.IndexOf(StepCompanyLevels2);
                            }
                            else
                            {
                                wzCompanyLevelsAdd.ActiveStepIndex = wzCompanyLevelsAdd.WizardSteps.IndexOf(StepSummary);
                            }
                        }
                        else
                        {
                            wzCompanyLevelsAdd.ActiveStepIndex = wzCompanyLevelsAdd.WizardSteps.IndexOf(StepCompanyLevelManagers);
                        }
                    }
                    break;

                case "Company Level Managers":
                    e.Cancel = !StepCompanyLevelManagersNext();
                    if (!e.Cancel)
                    {
                        ViewState["StepFrom"] = "CompanyLevelManagers";
                        wzCompanyLevelsAdd.ActiveStepIndex = wzCompanyLevelsAdd.WizardSteps.IndexOf(StepSummary);
                    }
                    break;

                case "Company level to replace":
                    e.Cancel = !StepCompanyLevels2Next();
                    if (!e.Cancel)
                    {
                        ViewState["StepFrom"] = "CompanyLevels2";
                    }
                    break;

                default:
                    throw new Exception("Not exists the option for " + wzCompanyLevelsAdd.ActiveStep.Name + " step in company_levels_edit.Wizard_NextButtonClick function");
            }
        }