Exemplo n.º 1
0
        /// <summary>
        /// DeleteDirect
        /// </summary>
        /// <param name="unitId">unitId</param>
        /// <param name="unitType">unitType</param>
        /// <param name="companyId">companyId</param>
        public void DeleteDirect(int unitId, string unitType, int companyId)
        {
            UnitsGateway unitsGateway = new UnitsGateway();
            unitsGateway.LoadByUnitId(unitId,  companyId);

            if (unitsGateway.Table.Rows.Count > 0)
            {
                // ... Delete unit categories
                UnitsCategory unitsCategory = new UnitsCategory(null);
                UnitsCategoryGateway unitsCategoryGateway = new UnitsCategoryGateway();
                unitsCategoryGateway.LoadByUnitId(unitId, companyId);

                foreach (UnitsTDS.LFS_FM_UNIT_CATEGORYRow rowCategories in (UnitsTDS.LFS_FM_UNIT_CATEGORYDataTable)unitsCategoryGateway.Table)
                {
                    unitsCategory.DeleteDirect(unitId, rowCategories.CategoryID, companyId);
                }

                // ... if vehicle type then delete unit
                if (unitType == "Vehicle")
                {
                    UnitsVehicle unitsVehicle = new UnitsVehicle(null);
                    unitsVehicle.DeleteDirect(unitId, companyId);
                }

                // ... Delete inspections
                UnitsInspection unitsInspection = new UnitsInspection(null);
                UnitsInspectionGateway unitsInspectionGateway = new UnitsInspectionGateway();
                unitsInspectionGateway.LoadByUnitId(unitId, companyId);

                foreach (UnitsTDS.LFS_FM_UNIT_INSPECTIONRow rowInspections in (UnitsTDS.LFS_FM_UNIT_INSPECTIONDataTable)unitsInspectionGateway.Table)
                {
                    unitsInspection.DeletedDirect(unitId, rowInspections.InspectionID, companyId);
                }

                // ... Delete unit
                unitsGateway.Delete(unitId, companyId);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// UpdateUnitCategory
        /// </summary>
        /// <param name="unitId">unitId</param>
        /// <param name="companyId">companyId</param>
        /// <param name="categoriesSelected">categoriesSelected</param>
        private void UpdateUnitCategory(int unitId, int companyId, ArrayList categoriesSelected)
        {
            CategoryGateway categoryGateway = new CategoryGateway();
            categoryGateway.Load(companyId);

            if (categoryGateway.Table.Rows.Count > 0)
            {
                foreach (CategoriesTDS.LFS_FM_CATEGORYRow row in (CategoriesTDS.LFS_FM_CATEGORYDataTable)categoryGateway.Table)
                {
                    int categoryId = row.CategoryID;

                    UnitsCategoryGateway unitsCategoryGateway = new UnitsCategoryGateway(null);

                    if (unitsCategoryGateway.IsUsedInUnitCategory(unitId, categoryId))
                    {
                        if (!categoriesSelected.Contains(categoryId))
                        {
                            UnitsCategory unitsCategory = new UnitsCategory(null);
                            unitsCategory.DeleteDirect(unitId, categoryId, companyId);
                        }
                    }
                    else
                    {
                        if (categoriesSelected.Contains(categoryId))
                        {
                            UnitsCategory unitsCategory = new UnitsCategory(null);
                            unitsCategory.InsertDirect(unitId, categoryId, false, companyId);
                        }
                    }
                }
            }
        }
        /// <summary>
        /// UpdateUnitCategory
        /// </summary>
        /// <param name="unitId">unitId</param>
        /// <param name="companyId">companyId</param>
        /// <param name="categoriesSelected">categoriesSelected</param>
        /// <param name="companyLevelId">companyLevelId</param>
        private void UpdateUnitCategory(int unitId, int companyId, ArrayList categoriesSelected, int companyLevelId)
        {
            RuleCategoryUnitsGateway ruleCategoryUnitsGateway = new RuleCategoryUnitsGateway(null);

            CategoryGateway categoryGateway = new CategoryGateway();
            categoryGateway.Load(companyId);

            if (categoryGateway.Table.Rows.Count > 0)
            {
                foreach (CategoriesTDS.LFS_FM_CATEGORYRow row in (CategoriesTDS.LFS_FM_CATEGORYDataTable)categoryGateway.Table)
                {
                    int categoryId = row.CategoryID;

                    UnitsCategoryGateway unitsCategoryGateway = new UnitsCategoryGateway(null);

                    // Exists in DB
                    if (unitsCategoryGateway.IsUsedInUnitCategory(unitId, categoryId, true))
                    {
                        if (!categoriesSelected.Contains(categoryId))
                        {
                            UnitsCategory unitsCategory = new UnitsCategory(null);
                            unitsCategory.DeleteDirect(unitId, categoryId, companyId);

                            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;

                                if (ruleCategoryUnitsGateway.IsUsedInRuleCategoryUnits(ruleId, categoryId, unitId))
                                {
                                    // Delete
                                    RuleCategoryUnits ruleCategoryUnits = new RuleCategoryUnits(null);
                                    ruleCategoryUnits.DeleteDirect(ruleId, categoryId, unitId, companyId);
                                }
                            }
                        }
                        else
                        {
                            UnitsCategory unitsCategory = new UnitsCategory(null);
                            unitsCategory.UnDeleteDirect(unitId, categoryId, companyId);
                        }
                    }
                    else
                    {
                        if (categoriesSelected.Contains(categoryId))
                        {
                            UnitsCategory unitsCategory = new UnitsCategory(null);
                            unitsCategory.InsertDirect(unitId, categoryId, false, companyId);
                        }
                    }
                }
            }
        }
Exemplo n.º 4
0
        /// <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);
                        }
                    }
                }
            }
        }