/// <summary> /// UpdateUnitsAndRulesCategories /// </summary> /// <param name="originalCategoryId">originalCategoryId</param> /// <param name="newCategoryId">newCategoryId</param> /// <param name="companyId">companyId</param> private void UpdateUnitsAndRulesCategories(int originalCategoryId, int? newCategoryId, int companyId) { // Update rules categories LiquiForce.LFSLive.DA.FleetManagement.ChecklistRules.RuleGateway ruleGateway = new RuleGateway(); ruleGateway.Load(companyId); if (ruleGateway.Table.Rows.Count > 0) { foreach (RuleTDS.LFS_FM_RULERow row in (RuleTDS.LFS_FM_RULEDataTable)ruleGateway.Table) { int ruleId = row.RuleID; RuleCategoryGateway ruleCategoryGateway = new RuleCategoryGateway(null); if ((ruleCategoryGateway.IsUsedInRuleCategory(ruleId, originalCategoryId)) && (newCategoryId.HasValue)) { if (!ruleCategoryGateway.IsUsedInRuleCategory(ruleId, (int)newCategoryId, true)) { RuleCategory ruleCategory = new RuleCategory(null); // Insert new rule category ruleCategory.InsertDirect(ruleId, (int)newCategoryId, false, companyId); // Delete old rule category ruleCategory.DeleteDirect(ruleId, originalCategoryId, companyId); } else { RuleCategory ruleCategory = new RuleCategory(null); // Undelete nee rule category ruleCategory.UnDeleteDirect(ruleId, (int)newCategoryId, companyId); // Delete old rule category ruleCategory.DeleteDirect(ruleId, originalCategoryId, companyId); } } } } // Update units categories UnitsGateway unitsGateway = new UnitsGateway(); unitsGateway.Load(companyId); if (unitsGateway.Table.Rows.Count > 0) { foreach (UnitsTDS.LFS_FM_UNITRow row in (UnitsTDS.LFS_FM_UNITDataTable)unitsGateway.Table) { int unitId = row.UnitID; int companyLevelId = row.CompanyLevelID; UnitsCategoryGateway unitsCategoryGateway = new UnitsCategoryGateway(null); if ((unitsCategoryGateway.IsUsedInUnitCategory(unitId, originalCategoryId)) && (newCategoryId.HasValue) ) { if (!unitsCategoryGateway.IsUsedInUnitCategory(unitId, (int)newCategoryId, true)) { UnitsCategory unitsCategory = new UnitsCategory(null); // Insert new unit category unitsCategory.InsertDirect(unitId, (int)newCategoryId, false, companyId); // Delete old unit category unitsCategory.DeleteDirect(unitId, originalCategoryId, companyId); // Delete all checklist for unitId DeleteChecklists(unitId, companyId); // Update checklist UpdateUnitChecklists(unitId, row.CompanyLevelID, companyId); } else { UnitsCategory unitsCategory = new UnitsCategory(null); // Undelete new category unitsCategory.UnDeleteDirect(unitId, (int)newCategoryId, companyId); // Delete old category unitsCategory.DeleteDirect(unitId, originalCategoryId, companyId); // Delete all checklist for unitId DeleteChecklists(unitId, companyId); // Update checklist UpdateUnitChecklists(unitId, row.CompanyLevelID, companyId); } } } } }
/// <summary> /// UpdateRuleCategory /// </summary> /// <param name="ruleId">ruleId</param> /// <param name="companyId">companyId</param> /// <param name="categoriesSelected">categoriesSelected</param> /// <param name="companyLevelsSelected">companyLevelsSelected</param> private void UpdateRuleCategory(int ruleId, int companyId, ArrayList categoriesSelected, ArrayList companyLevelsSelected) { CategoryGateway categoryGateway = new CategoryGateway(); categoryGateway.Load(companyId); foreach (CategoriesTDS.LFS_FM_CATEGORYRow row in (CategoriesTDS.LFS_FM_CATEGORYDataTable)categoryGateway.Table) { int categoryId = row.CategoryID; RuleCategoryGateway ruleCategoryGateway = new RuleCategoryGateway(null); if (ruleCategoryGateway.IsUsedInRuleCategory(ruleId, categoryId, true)) { // Delete if (!categoriesSelected.Contains(categoryId)) { RuleCategory ruleCategory = new RuleCategory(null); ruleCategory.DeleteDirect(ruleId, categoryId, companyId); } else // Undelete { RuleCategory ruleCategory = new RuleCategory(null); ruleCategory.UnDeleteDirect(ruleId, categoryId, companyId); } } else { if (categoriesSelected.Contains(categoryId)) { RuleCategory ruleCategory = new RuleCategory(null); ruleCategory.InsertDirect(ruleId, categoryId, false, companyId); } } } }