/// <summary> /// UpdateRuleCategoryUnits /// </summary> /// <param name="ruleId">ruleId</param> /// <param name="companyId">companyId</param> /// <param name="categoriesSelected">categoriesSelected</param> /// <param name="companyLevelsSelected">companyLevelsSelected</param> /// <param name="unitsSelected">unitsSelected</param> private void UpdateRuleCategoryUnits(int ruleId, int companyId, ArrayList categoriesSelected, ArrayList companyLevelsSelected, ArrayList unitsSelected) { // At each category CategoryGateway categoryGateway = new CategoryGateway(); categoryGateway.Load(companyId); foreach (CategoriesTDS.LFS_FM_CATEGORYRow row in (CategoriesTDS.LFS_FM_CATEGORYDataTable)categoryGateway.Table) { int categoryId = row.CategoryID; // At each unit UnitsCategoryGateway unitsCategoryGateway = new UnitsCategoryGateway(); unitsCategoryGateway.LoadByCategoryId(categoryId, companyId); foreach (UnitsTDS.LFS_FM_UNIT_CATEGORYRow rowUnitCategory in (UnitsTDS.LFS_FM_UNIT_CATEGORYDataTable)unitsCategoryGateway.Table) { int unitId = rowUnitCategory.UnitID; RuleCategoryUnitsGateway ruleCategoryUnitsGateway = new RuleCategoryUnitsGateway(null); // If it already exists and it's not deleted if (ruleCategoryUnitsGateway.IsUsedInRuleCategoryUnits(ruleId, categoryId, unitId)) { // Verify if it's at the current selection if ((!categoriesSelected.Contains(categoryId)) || (categoriesSelected.Contains(categoryId) && (!unitsSelected.Contains(unitId)))) { // Delete RuleCategoryUnits ruleCategoryUnits = new RuleCategoryUnits(null); ruleCategoryUnits.DeleteDirect(ruleId, categoryId, unitId, companyId); } else { RuleCategoryUnits ruleCategoryUnits = new RuleCategoryUnits(null); ruleCategoryUnits.UnDeleteDirect(ruleId, categoryId, unitId, companyId); // Insert checklist foreach (int companyLevelId in companyLevelsSelected) { UnitsGateway unitsGateway = new UnitsGateway(null); if (unitsGateway.IsUsedInUnitsAndNotIsDisposed(unitId, companyLevelId)) { ChecklistGateway checklistGateway = new ChecklistGateway(null); if (checklistGateway.IsUsedInChecklist(unitId, ruleId, true)) { Checklist checklist = new Checklist(null); checklist.UnDeleteDirect(ruleId, unitId, companyId); } else { Checklist checklist = new Checklist(null); checklist.InsertDirect(unitId, ruleId, null, null, false, "Unknown", false, companyId); } } } } } else { // If it already exists and it's deleted if (ruleCategoryUnitsGateway.IsUsedInRuleCategoryUnitsAsDeleted(ruleId, categoryId, unitId)) { // Verify if it's at the current selection if (categoriesSelected.Contains(categoryId) && (unitsSelected.Contains(unitId))) { // UnDelete RuleCategoryUnits ruleCategoryUnits = new RuleCategoryUnits(null); ruleCategoryUnits.UnDeleteDirect(ruleId, categoryId, unitId, companyId); // Insert checklist foreach (int companyLevelId in companyLevelsSelected) { UnitsGateway unitsGateway = new UnitsGateway(null); if (unitsGateway.IsUsedInUnitsAndNotIsDisposed(unitId, companyLevelId)) { ChecklistGateway checklistGateway = new ChecklistGateway(null); if (checklistGateway.IsUsedInChecklist(unitId, ruleId, true)) { Checklist checklist = new Checklist(null); checklist.UnDeleteDirect(ruleId, unitId, companyId); } else { Checklist checklist = new Checklist(null); checklist.InsertDirect(unitId, ruleId, null, null, false, "Unknown", false, companyId); } } } } } // If it's not at bd else { // Verify if it's at the current selection if (categoriesSelected.Contains(categoryId) && (unitsSelected.Contains(unitId))) { // Insert rule category units RuleCategoryUnits ruleCategoryUnits = new RuleCategoryUnits(null); ruleCategoryUnits.InsertDirect(ruleId, categoryId, unitId, false, companyId); // Insert checklist foreach (int companyLevelId in companyLevelsSelected) { UnitsGateway unitsGateway = new UnitsGateway(null); if (unitsGateway.IsUsedInUnitsAndNotIsDisposed(unitId, companyLevelId)) { ChecklistGateway checklistGateway = new ChecklistGateway(null); if (checklistGateway.IsUsedInChecklist(unitId, ruleId, true)) { Checklist checklist = new Checklist(null); checklist.UnDeleteDirect(ruleId, unitId, companyId); } else { Checklist checklist = new Checklist(null); checklist.InsertDirect(unitId, ruleId, null, null, false, "Unknown", false, companyId); } } } } } } } } }