private void LoadData(int ruleId)
        {
            RuleGateway ruleGateway = new RuleGateway(ruleTDS);

            if (ruleGateway.Table.Rows.Count > 0)
            {
                tbxName.Text = ruleGateway.GetName(ruleId);
                cbxMtoDot.Checked = ruleGateway.GetMto(ruleId);
                tbxDescription.Text = ruleGateway.GetDescription(ruleId);
                tbxFrecuency.Text = ruleGateway.GetFrequency(ruleId);
                tbxServicesRequestDaysBefore.Text = ""; if (ruleGateway.GetServiceRequestDays(ruleId).HasValue) tbxServicesRequestDaysBefore.Text = ((int)(ruleGateway.GetServiceRequestDays(ruleId))).ToString();

                // Load Trees
                GetNodeForCategory(tvCategoriesRoot.Nodes, 0);
                GetNodeForCompanyLevels(tvCompanyLevelsRoot.Nodes, 0);

                // Load Units
                int companyId = Int32.Parse(hdfCompanyId.Value);
                string category = "";
                UnitsList unitsList = new UnitsList(new DataSet());

                foreach (int categoryId in arrayCategoriesSelected)
                {
                    CategoryGateway categoryGateway = new CategoryGateway();

                    //Verify the location of the unit
                    foreach (int companyLevelId in arrayCompanyLevelsSelected)
                    {
                        // Load the unit if corresponds
                        categoryGateway.LoadByCategoryId(categoryId, Int32.Parse(hdfCompanyId.Value));
                        category = categoryGateway.GetName(categoryId);

                        unitsList.LoadAndAddItemByCategoryCompanyLevelId(category, companyLevelId, companyId);
                    }
                }

                if (unitsList.Table != null)
                {
                    cbxlUnitsSelected.DataSource = RemoveDuplicateRows(unitsList.Table, "UnitID");
                    cbxlUnitsSelected.DataValueField = "UnitID";
                    cbxlUnitsSelected.DataTextField = "UnitCode";
                    cbxlUnitsSelected.DataBind();

                    // Total units
                    lblTotalUnits.Text = "Total Units: " + cbxlUnitsSelected.Items.Count;
                }
                else
                {
                    // Total units
                    lblTotalUnits.Text = "Total Units: 0";
                }
            }
        }
        // ////////////////////////////////////////////////////////////////////////
        // STEP5 - UNITS - METHODS
        //        
        private void StepUnitsIn()
        {
            // Set instruction
            Label instruction = (Label)this.Master.FindControl("lblInstruction");
            instruction.Text = "Please select the units to which the rule will be applied";

            // Load Units
            int companyId = Int32.Parse(hdfCompanyId.Value);
            string category = "";
            UnitsList unitsList = new UnitsList(new DataSet());

            foreach (int categoryId in arrayCategoriesSelected)
            {
                CategoryGateway categoryGateway = new CategoryGateway();

                //Verify the location of the unit
                foreach (int companyLevelId in arrayCompanyLevelsSelected)
                {
                    // Load the unit if corresponds
                    categoryGateway.LoadByCategoryId(categoryId, Int32.Parse(hdfCompanyId.Value));
                    category = categoryGateway.GetName(categoryId);

                    unitsList.LoadAndAddItemByCategoryCompanyLevelId(category, companyLevelId, companyId);
                }
            }

            // Select all units by default
            if (unitsList.Table != null)
            {
                cbxlUnitsSelected.DataSource = RemoveDuplicateRows(unitsList.Table, "UnitID");
                cbxlUnitsSelected.DataValueField = "UnitID";
                cbxlUnitsSelected.DataTextField = "UnitCode";
                cbxlUnitsSelected.DataBind();

                foreach (ListItem lst in cbxlUnitsSelected.Items)
                {
                    lst.Selected = true;
                }

                // Total units
                lblTotalUnits.Text = "Total Units: " + cbxlUnitsSelected.Items.Count;

                Session["arrayUnitsSelected"] = arrayUnitsSelected;
            }
            else
            {
                // Total units
                lblTotalUnits.Text = "Total Units: 0";
            }
        }
        protected void tvCategoriesRoot_TreeNodeCheckChanged(object sender, TreeNodeEventArgs e)
        {
            // Validate to load checked units
            hdfCheckUnitsFlag.Value = "No";

            // Get categories
            arrayCategoriesSelectedForEdit.Clear();
            foreach (TreeNode nodes in tvCategoriesRoot.Nodes)
            {
                GetCategoriesSelected(nodes);
            }

            // Load Units
            int companyId = Int32.Parse(hdfCompanyId.Value);
            string category = "";
            UnitsList unitsList = new UnitsList(new DataSet());

            foreach (int categoryId in arrayCategoriesSelectedForEdit)
            {
                CategoryGateway categoryGateway = new CategoryGateway();

                //Verify the location of the unit
                foreach (int companyLevelId in arrayCompanyLevelsSelectedForEdit)
                {
                    // Load the unit if corresponds
                    categoryGateway.LoadByCategoryId(categoryId, Int32.Parse(hdfCompanyId.Value));
                    category = categoryGateway.GetName(categoryId);

                    unitsList.LoadAndAddItemByCategoryCompanyLevelId(category, companyLevelId, companyId);
                }
            }

            if (unitsList.Table != null)
            {
                cbxlUnitsSelected.DataSource = RemoveDuplicateRows(unitsList.Table, "UnitID");
                cbxlUnitsSelected.DataValueField = "UnitID";
                cbxlUnitsSelected.DataTextField = "UnitCode";
                cbxlUnitsSelected.DataBind();

                // Total units
                lblTotalUnits.Text = "Total Units: " + cbxlUnitsSelected.Items.Count;
            }
            else
            {
                // Total units
                lblTotalUnits.Text = "Total Units: 0";
            }
        }