コード例 #1
0
        /// <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);
                        }
                    }
                }
            }
        }
コード例 #2
0
        /// <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);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
コード例 #3
0
        /// <summary>
        /// UpdateRuleCategory
        /// </summary>
        /// <param name="ruleId">ruleId</param>
        /// <param name="companyId">companyId</param>
        /// <param name="companyLevelsSelected">companyLevelsSelected</param>
        /// <param name="categoriesSelected">categoriesSelected</param>
        /// <param name="unitsSelected">unitsSelected</param>
        private void UpdateRuleCategory(int ruleId, int companyId, ArrayList companyLevelsSelected, ArrayList categoriesSelected, ArrayList unitsSelected)
        {
            // Insert into checklist only selected units
            foreach (int categoryId in categoriesSelected)
            {
                RuleCategory ruleCategory = new RuleCategory(null);
                ruleCategory.InsertDirect(ruleId, categoryId, false, companyId);

                foreach (int unitId in unitsSelected)
                {
                    //int unitId = row.UnitID;

                    // Save categories and selected units
                    UnitsCategoryGateway unitsCategoryGatewayExist = new UnitsCategoryGateway(null);
                    if (unitsCategoryGatewayExist.IsUsedInUnitCategory(unitId, categoryId, false))
                    {
                        RuleCategoryUnits ruleCategoryUnits = new RuleCategoryUnits(null);
                        ruleCategoryUnits.InsertDirect(ruleId, categoryId, unitId, false, companyId);
                    }

                    // Save Chechklists for selected units
                    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))
                            {
                                Checklist checklist = new Checklist(null);
                                checklist.InsertDirect(unitId, ruleId, null, null, false, "Unknown", false, companyId);
                            }
                        }
                    }
                }
            }
        }
コード例 #4
0
        /// <summary>
        /// DeleteRuleCategory
        /// </summary>
        /// <param name="ruleId">ruleId</param>
        /// <param name="companyId">companyId</param>
        private void DeleteRuleCategory(int ruleId, int companyId)
        {
            // Delete RuleCategoryUnits
            RuleCategoryUnits ruleCategoryUnits = new RuleCategoryUnits(null);
            RuleCategoryUnitsGateway ruleCategoryUnitsGateway = new RuleCategoryUnitsGateway(null);

            if (ruleCategoryUnitsGateway.IsRuleUsed(ruleId))
            {
                ruleCategoryUnits.DeleteDirectByRuleId(ruleId, companyId);
            }

            // Load all categories
            CategoryGateway categoryGateway = new CategoryGateway();
            categoryGateway.Load(companyId);

            // Delete rule categories
            if (categoryGateway.Table.Rows.Count > 0)
            {
                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))
                    {
                        RuleCategory ruleCategory = new RuleCategory(null);
                        ruleCategory.DeleteDirect(ruleId, categoryId, companyId);
                    }
                }
            }
        }