/// <summary> /// CompanyLevelIsUsed /// </summary> /// <param name="companyLevelId">companyLevelId</param> /// <param name="companyId">companyId</param> /// <returns>True or False</returns> public bool CompanyLevelIsUsed(int companyLevelId, int companyId) { UnitsGateway unitsGateway = new UnitsGateway(); unitsGateway.Load(companyId); LiquiForce.LFSLive.DA.FleetManagement.ChecklistRules.RuleGateway ruleGateway = new RuleGateway(); ruleGateway.Load(companyId); bool inUse = false; foreach (UnitsTDS.LFS_FM_UNITRow row in (UnitsTDS.LFS_FM_UNITDataTable)unitsGateway.Table) { int unitId = row.UnitID; if (companyLevelId == row.CompanyLevelID) { inUse = true; } } 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, companyLevelId)) { inUse = true; } } return inUse; }
/// <summary> /// UnDeleteDirect /// </summary> /// <param name="ruleId">ruleId</param> /// <param name="companyLevelId">companyLevelId</param> /// <param name="companyId">companyId</param> /// <returns>true</returns> public bool UnDeleteDirect(int ruleId, int companyLevelId, int companyId) { RuleCompanyLevelGateway ruleCompanyLevelGateway = new RuleCompanyLevelGateway(Data); ruleCompanyLevelGateway.UnDelete(ruleId, companyLevelId, companyId); return true; }
private void GetNodeForCompanyLevels(TreeNodeCollection nodes, int parentId) { Int32 thisId; string thisName; RuleCompanyLevelGateway ruleCompanyLevelGateway = new RuleCompanyLevelGateway(null); DataRow[] children = companyLevelsTDS.Tables["LFS_FM_COMPANYLEVEL"].Select("ParentID='" + parentId + "'"); // No child nodes, exit function if (children.Length == 0) return; foreach (DataRow child in children) { // Step 1 thisId = Convert.ToInt32(child.ItemArray[0]); // Step 2 thisName = Convert.ToString(child.ItemArray[1]); // Step 3 TreeNode newNode = new TreeNode(thisName, thisId.ToString()); newNode.ShowCheckBox = true; newNode.SelectAction = TreeNodeSelectAction.None; // Step 4 if (ruleCompanyLevelGateway.IsUsedInRuleCompanyLevel(Int32.Parse(hdfRuleId.Value), thisId)) { newNode.Checked = true; arrayCompanyLevelsSelected.Add(int.Parse(newNode.Value)); } // Step 5 nodes.Add(newNode); newNode.ToggleExpandState(); // Step 6 GetNodeForCompanyLevels(newNode.ChildNodes, thisId); } }
// //////////////////////////////////////////////////////////////////////// // PUBLIC METHODS // /// <summary> /// InsertDirect /// </summary> /// <param name="ruleId">ruleId</param> /// <param name="companyLevelId">companyLevelId</param> /// <param name="deleted">deleted</param> /// <param name="companyId">companyId</param> public void InsertDirect(int ruleId, int companyLevelId, bool deleted, int companyId) { RuleCompanyLevelGateway ruleCompanyLevelGateway = new RuleCompanyLevelGateway(null); ruleCompanyLevelGateway.Insert(ruleId, companyLevelId, deleted, companyId); }
/// <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); } } } } }
/// <summary> /// UpdateUnitChecklists /// </summary> /// <param name="unitId">unitId</param> /// <param name="companyLevelId">companyLevelId</param> /// <param name="companyId">companyId</param> private void UpdateUnitChecklists(int unitId, int companyLevelId, int companyId) { UnitsCategoryGateway unitsCategoryGateway = new UnitsCategoryGateway(); unitsCategoryGateway.LoadByUnitId(unitId, companyId); foreach (UnitsTDS.LFS_FM_UNIT_CATEGORYRow row in (UnitsTDS.LFS_FM_UNIT_CATEGORYDataTable)unitsCategoryGateway.Table) { int categoryId = row.CategoryID; RuleCategoryGateway ruleCategoryGateway = new RuleCategoryGateway(); ruleCategoryGateway.LoadByCategoryId(categoryId, companyId); foreach (RuleTDS.LFS_FM_RULE_CATEGORYRow rowRuleCategory in (RuleTDS.LFS_FM_RULE_CATEGORYDataTable)ruleCategoryGateway.Table) { int ruleId = rowRuleCategory.RuleID; RuleCompanyLevelGateway ruleCompanyLevelGateway = new RuleCompanyLevelGateway(null); if (ruleCompanyLevelGateway.IsUsedInRuleCompanyLevel(ruleId, 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); } } } } }
/// <summary> /// UpdateRuleCompanyLevel /// </summary> /// <param name="ruleId">ruleId</param> /// <param name="companyId">companyId</param> /// <param name="companyLevelsSected">companyLevelsSected</param> private void UpdateRuleCompanyLevel(int ruleId, int companyId, ArrayList companyLevelsSelected) { CompanyLevelGateway companyLevelGateway = new CompanyLevelGateway(); companyLevelGateway.Load(companyId); if (companyLevelGateway.Table.Rows.Count > 0) { foreach (CompanyLevelsTDS.LFS_FM_COMPANYLEVELRow row in (CompanyLevelsTDS.LFS_FM_COMPANYLEVELDataTable)companyLevelGateway.Table) { int companyLevelId = row.CompanyLevelID; RuleCompanyLevelGateway ruleCompanyLevelGateway = new RuleCompanyLevelGateway(null); if (ruleCompanyLevelGateway.IsUsedInRuleCompanyLevel(ruleId, companyLevelId, true)) { if (!companyLevelsSelected.Contains(companyLevelId)) { RuleCompanyLevel ruleCompanyLevel = new RuleCompanyLevel(null); ruleCompanyLevel.DeleteDirect(ruleId, companyLevelId, companyId); } else { RuleCompanyLevel ruleCompanyLevel = new RuleCompanyLevel(null); ruleCompanyLevel.UnDeleteDirect(ruleId, companyLevelId, companyId); } } else { if (companyLevelsSelected.Contains(companyLevelId)) { RuleCompanyLevel ruleCompanyLevel = new RuleCompanyLevel(null); ruleCompanyLevel.InsertDirect(ruleId, companyLevelId, false, companyId); } } } } }
/// <summary> /// DeleteRuleCompanyLevel /// </summary> /// <param name="ruleId">ruleId</param> /// <param name="companyId">companyId</param> private void DeleteRuleCompanyLevel(int ruleId, int companyId) { CompanyLevelGateway companyLevelGateway = new CompanyLevelGateway(); companyLevelGateway.Load(companyId); if (companyLevelGateway.Table.Rows.Count > 0) { foreach (CompanyLevelsTDS.LFS_FM_COMPANYLEVELRow row in (CompanyLevelsTDS.LFS_FM_COMPANYLEVELDataTable)companyLevelGateway.Table) { int companyLevelId = row.CompanyLevelID; RuleCompanyLevelGateway ruleCompanyLevelGateway = new RuleCompanyLevelGateway(null); if (ruleCompanyLevelGateway.IsUsedInRuleCompanyLevel(ruleId, companyLevelId)) { RuleCompanyLevel ruleCompanyLevel = new RuleCompanyLevel(null); ruleCompanyLevel.DeleteDirect(ruleId, companyLevelId, companyId); } } } }