/// <summary> /// UpdateUnitsAndRulesCompanyLevels /// </summary> /// <param name="originalCompanyLevelId">originalCompanyLevelId</param> /// <param name="newCompanyLevelId">newCompanyLevelId</param> /// <param name="companyId">companyId</param> private void UpdateUnitsAndRulesCompanyLevels(int originalCompanyLevelId, int? newCompanyLevelId, int companyId) { // Update units 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; if (originalCompanyLevelId == row.CompanyLevelID) { if (newCompanyLevelId.HasValue) { UnitsGateway unitsGatewayToUpdate = new UnitsGateway(null); unitsGatewayToUpdate.UpdateCompanyLevel(row.UnitID, row.Deleted, row.COMPANY_ID, (int)newCompanyLevelId); } } } } // Update rules company levels 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; RuleCompanyLevelGateway ruleCompanyLevelGateway = new RuleCompanyLevelGateway(null); if ((ruleCompanyLevelGateway.IsUsedInRuleCompanyLevel(ruleId, originalCompanyLevelId)) && (newCompanyLevelId.HasValue)) { if (!ruleCompanyLevelGateway.IsUsedInRuleCompanyLevel(ruleId, (int)newCompanyLevelId)) { RuleCompanyLevel ruleCompanyLevel = new RuleCompanyLevel(null); ruleCompanyLevel.InsertDirect(ruleId, (int)newCompanyLevelId, false, companyId); ruleCompanyLevel.DeleteDirect(ruleId, originalCompanyLevelId, companyId); } else { RuleCompanyLevel ruleCompanyLevel = new RuleCompanyLevel(null); ruleCompanyLevel.DeleteDirect(ruleId, originalCompanyLevelId, companyId); } } } } }