private void TsbRuleAddClick(object sender, EventArgs e)
        {
            var rls    = _dsSecurity.Tables["Rule"].AsEnumerable();
            var rlgrps = _dsSecurity.Tables["GrpRl"].AsEnumerable();

            //
            // Reserva o grupo atual
            //
            DataRowView currentGroup = _bsGroup.Current as DataRowView;

            var groupRules =
                from rl in rls
                join rlgrp in rlgrps
                on rl["Name"]
                equals rlgrp["RuleName"] into joinedGroup
                from jndGrp in joinedGroup
                where (string)jndGrp["GroupName"] == (string)currentGroup["Name"]
                select new
            {
                RuleName    = rl["Name"],
                Description = rl["Description"]
            };

            var allRules =
                from rl in rls
                select new
            {
                RuleName    = rl["Name"],
                Description = rl["Description"]
            };

            var working = allRules.Except(groupRules);

            DataTable avlRls = _dsSecurity.Tables["Rule"].Clone();

            avlRls.Clear();
            foreach (var record in working)
            {
                DataRow nRow = avlRls.NewRow();

                nRow["Name"]        = record.RuleName.ToString();
                nRow["Description"] = record.Description.ToString();

                avlRls.Rows.Add(nRow);

                avlRls.AcceptChanges();
            }

            using (RuleListForm ruleListForm = new RuleListForm(avlRls))
            {
                if (ruleListForm.ShowDialog() == DialogResult.OK)
                {
                    DataRowView newRule = _bsRule.AddNew() as DataRowView;

                    DataRowView selectedRule = ruleListForm.listBox1.SelectedItem as DataRowView;

                    newRule["GroupName"] = currentGroup["Name"];
                    newRule["Name"]      = selectedRule["Name"];

                    newRule["Description"] = selectedRule["Description"];

                    _bsRule.EndEdit();
                    _bsRule.ResetCurrentItem();

                    DataTable dtGrpRl  = _dsSecurity.Tables["GrpRl"];
                    DataRow   newGrpRl = dtGrpRl.NewRow();

                    newGrpRl["RuleName"]  = newRule["Name"];
                    newGrpRl["GroupName"] = newRule["GroupName"];

                    dtGrpRl.Rows.Add(newGrpRl);
                }
            }
        }
		private void TsbRuleAddClick(object sender, EventArgs e)
		{
			var rls = _dsSecurity.Tables["Rule"].AsEnumerable();
			var rlgrps = _dsSecurity.Tables["GrpRl"].AsEnumerable();
			
			//
			// Reserva o grupo atual
			//
			DataRowView currentGroup = _bsGroup.Current as DataRowView;
			
			var groupRules =
				from rl in rls
				join rlgrp in rlgrps
				on rl["Name"]
				equals rlgrp["RuleName"] into joinedGroup
				from jndGrp in joinedGroup
				where (string)jndGrp["GroupName"] == (string)currentGroup["Name"]
				select new
			{
				RuleName = rl["Name"],
				Description = rl["Description"]
			};
			
			var allRules =
				from rl in rls
				select new
			{
				RuleName = rl["Name"],
				Description = rl["Description"]
			};
			
			var working = allRules.Except(groupRules);
			
			DataTable avlRls = _dsSecurity.Tables["Rule"].Clone();
			avlRls.Clear();
			foreach(var record in working)
			{
				DataRow nRow = avlRls.NewRow();
				
				nRow["Name"] = record.RuleName.ToString();
				nRow["Description"] = record.Description.ToString();
				
				avlRls.Rows.Add(nRow);
				
				avlRls.AcceptChanges();
			}
			
			using (RuleListForm ruleListForm = new RuleListForm(avlRls))
			{
				if (ruleListForm.ShowDialog() == DialogResult.OK)
				{
					DataRowView newRule = _bsRule.AddNew() as DataRowView;
					
					DataRowView selectedRule = ruleListForm.listBox1.SelectedItem as DataRowView;
					
					newRule["GroupName"] = currentGroup["Name"];
					newRule["Name"] = selectedRule["Name"];
					
					newRule["Description"] = selectedRule["Description"];
					
					_bsRule.EndEdit();
					_bsRule.ResetCurrentItem();
					
					DataTable dtGrpRl = _dsSecurity.Tables["GrpRl"];
					DataRow newGrpRl = dtGrpRl.NewRow();
					
					newGrpRl["RuleName"] = newRule["Name"];
					newGrpRl["GroupName"] = newRule["GroupName"];
					
					dtGrpRl.Rows.Add(newGrpRl);
				}
			}
		}