private void Save()
        {
            // Validate page
            hdfCheckUnitsFlag.Value = "Yes";
            Page.Validate();
            if (Page.IsValid)
            {
                string url = "";

                // Save data
                int companyId = Int32.Parse(hdfCompanyId.Value);
                int ruleId = Int32.Parse(hdfRuleId.Value);

                // Get parameters
                string name = ""; if (tbxName.Text != "") name = tbxName.Text;
                bool mto = false; if (cbxMtoDot.Checked) mto = true;
                string description = ""; if (tbxDescription.Text != "") description = tbxDescription.Text;
                string frequency = tbxFrecuency.Text;
                bool alarm = false;
                int? alarmDaysBefore = null;
                bool serviceRequest = true;
                int? serviceRequestDaysBefore = null; if (tbxServicesRequestDaysBefore.Text != "") serviceRequestDaysBefore = Convert.ToInt32(tbxServicesRequestDaysBefore.Text);

                // Save last unitsSelected
                arrayUnitsSelectedForEdit.Clear();
                if (cbxlUnitsSelected.Items.Count > 0)
                {
                    foreach (ListItem lst in cbxlUnitsSelected.Items)
                    {
                        if (lst.Selected) arrayUnitsSelectedForEdit.Add(Int32.Parse(lst.Value));
                    }

                    Session["arrayUnitsSelectedForEdit"] = arrayUnitsSelectedForEdit;
                }

                // Save to database
                DB.Open();
                DB.BeginTransaction();
                try
                {
                    // Save Data
                    ChecklistRulesDetails checklistRulesDetails = new ChecklistRulesDetails(ruleTDS);
                    checklistRulesDetails.Save(ruleId, name, description, mto, frequency, alarm, alarmDaysBefore, serviceRequest, serviceRequestDaysBefore, false, companyId, arrayCategoriesSelectedForEdit, arrayCompanyLevelsSelectedForEdit, arrayUnitsSelectedForEdit);

                    DB.CommitTransaction();

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

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

                // Redirect
                if (Request.QueryString["source_page"] == "checklist_rules_navigator.aspx" || Request.QueryString["source_page"] == "checklist_rules_add.aspx")
                {
                    url = "./checklist_rules_navigator.aspx?source_page=checklist_rules_edit.aspx&rule_id=" + hdfRuleId.Value + "&update=yes";
                    Response.Redirect(url);
                }

                if (Request.QueryString["source_page"] == "checklist_rules_summary.aspx")
                {
                    url = "./checklist_rules_summary.aspx?source_page=checklist_rules_edit.aspx&rule_id=" + hdfRuleId.Value + "&update=yes";
                    Response.Redirect(url);
                }
            }
        }
        private void UpdateDatabase()
        {
            // Delete
            int ruleId = Int32.Parse(hdfRuleId.Value);
            int companyId = Int32.Parse(hdfCompanyId.Value);

            // Delete
            DB.Open();
            DB.BeginTransaction();
            try
            {
                ChecklistRulesDetails checklistRulesDetails = new ChecklistRulesDetails(ruleTDS);
                checklistRulesDetails.Delete(ruleId, companyId);

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

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