Example #1
0
        /// <summary>
        /// DeleteDirectByUnitId
        /// </summary>
        /// <param name="unitId">unitId</param>
        /// <param name="companyId">companyId</param>
        public bool DeleteDirectByUnitId(int unitId, int companyId)
        {
            ChecklistGateway checklistGateway = new ChecklistGateway(null);
            checklistGateway.DeleteByUnitId(unitId, companyId);

            return true;
        }
        /// <summary>
        /// DeleteChecklists
        /// </summary>
        /// <param name="unitId">unitId</param>
        /// <param name="companyId">companyId</param>
        private void DeleteChecklists(int unitId, int companyId)
        {
            ChecklistGateway checklistGateway = new ChecklistGateway(null);

            if (checklistGateway.IsUnitUsedInChecklist(unitId))
            {
                // Delete all checklists for unitId
                Checklist checklist = new Checklist(null);
                checklist.DeleteDirectByUnitId(unitId, companyId);
            }
        }
        /// <summary>
        /// Save services
        /// </summary>
        /// <param name="dateTime_">dateTime_</param>
        /// <param name="employeeId">employeeId</param>
        /// <param name="companyId">companyId</param>
        /// <param name="checklistState">checklistState</param>
        public int? Save(DateTime dateTime_, int employeeId, int companyId)
        {
            int? newServiceId = null;

            ServicesAddRequestTDS servicesAddRequestSelfAsignedChanges = (ServicesAddRequestTDS)Data.GetChanges();
            if (servicesAddRequestSelfAsignedChanges.BasicInformation.Rows.Count > 0)
            {
                ServicesGateway servicesGateway = new ServicesGateway(servicesAddRequestSelfAsignedChanges);

                foreach (ServicesAddRequestTDS.BasicInformationRow row in (ServicesAddRequestTDS.BasicInformationDataTable)servicesAddRequestSelfAsignedChanges.BasicInformation)
                {
                    DateTime? assignmentDeadlineDate = null; if (!row.IsAssignedDeadlineDateNull()) assignmentDeadlineDate = row.AssignedDeadlineDate;
                    DateTime? assignDateTime = null; if(row.IsAssignDateTimeNull()) row.AssignDateTime = DateTime.Now;
                    DateTime? acceptDatetime = null; if (!row.IsAcceptDatetimeNull()) acceptDatetime = row.AcceptDatetime;
                    DateTime? unitOutOfServiceDate = null; if (!row.IsUnitOutOfServiceDateNull()) unitOutOfServiceDate = row.UnitOutOfServiceDate;
                    string unitOutOfServiceTime = ""; if (!row.IsUnitOutOfServiceTimeNull()) unitOutOfServiceTime = row.UnitOutOfServiceTime;
                    DateTime? completeWorkDateTime = null; if (!row.IsCompleteWorkDateTimeNull()) completeWorkDateTime = row.CompleteWorkDateTime;
                    DateTime? unitBackInServiceDate = null; if (!row.IsUnitBackInServiceDateNull()) unitBackInServiceDate = row.UnitBackInServiceDate;
                    string unitBackInServiceTime = ""; if (!row.IsUnitBackInServiceTimeNull()) unitBackInServiceTime = row.UnitBackInServiceTime;
                    string completeWorkDetailDescription = ""; if (!row.IsCompleteWorkDetailDescriptionNull()) completeWorkDetailDescription = row.CompleteWorkDetailDescription;
                    bool completeWorkDetailPreventable = row.CompleteWorkDetailPreventable;
                    Decimal? completeWorkDetailTMLabourHours = null; if (!row.IsCompleteWorkDetailTMLabourHoursNull()) completeWorkDetailTMLabourHours = row.CompleteWorkDetailTMLabourHours;
                    Decimal? completeWorkDetailTMCost = null; if (!row.IsCompleteWorkDetailTMCostNull()) completeWorkDetailTMCost = row.CompleteWorkDetailTMCost;
                    string completeWorkDetaildTPVInvoiceNumber = ""; if (!row.IsCompleteWorkInvoiceNumberNull()) completeWorkDetaildTPVInvoiceNumber = row.CompleteWorkInvoiceNumber;
                    Decimal? completeWorkDetaildTPVInvoiceAmount = null; if (!row.IsCompleteWorkInvoiceAmountNull()) completeWorkDetaildTPVInvoiceAmount = row.CompleteWorkInvoiceAmount;
                    string mileage = ""; if (!row.IsMileageNull()) mileage = row.Mileage;
                    string startWorkMileage = ""; if (!row.IsStartWorkMileageNull()) startWorkMileage = row.StartWorkMileage;
                    string completeWorkMileage = ""; if (!row.IsCompleteWorkMileageNull()) completeWorkMileage = row.CompleteWorkMileage;
                    bool assignTeamMember = row.AssignTeamMember;
                    int? assignTeamMemberId = null; if (!row.IsAssignTeamMemberIdNull()) assignTeamMemberId = row.AssignTeamMemberId;
                    string assignThirdPartyVendor = ""; if (!row.IsAssignThirdPartyVendorNull()) assignThirdPartyVendor = row.AssignThirdPartyVendor;
                    DateTime? startWorkDateTime = null; if (!row.IsUnitOutOfServiceDateNull()) startWorkDateTime =  DateTime.Now;
                    int? ruleId = null; if (!row.IsRuleIDNull()) ruleId = row.RuleID;
                    string type = ""; if (ruleId.HasValue) type = "Checklist"; else type = "Normal";
                    int? libraryCategoriesId = 3736;//Fleet Maintence Invoices folder

                    Services services = new Services(null);
                    newServiceId = services.InsertDirect(dateTime_, row.MtoDot, row.ServiceDescription, row.UnitID, type, row.ServiceState, employeeId, assignDateTime, assignmentDeadlineDate, assignTeamMember, assignTeamMemberId, assignThirdPartyVendor, acceptDatetime, null, "", startWorkDateTime, unitOutOfServiceDate, unitOutOfServiceTime, completeWorkDateTime, unitBackInServiceDate, unitBackInServiceTime, completeWorkDetailDescription, completeWorkDetailPreventable, completeWorkDetailTMLabourHours, completeWorkDetailTMCost, completeWorkDetaildTPVInvoiceNumber, completeWorkDetaildTPVInvoiceAmount, "", ruleId, mileage, startWorkMileage, completeWorkMileage, row.Deleted, row.COMPANY_ID, libraryCategoriesId);

                    // modify checklist state
                    if (ruleId.HasValue)
                    {
                        string newChecklistState = "In Progress";

                        if (row.ServiceState == "Completed")
                        {
                            RuleGateway ruleGateway = new RuleGateway();
                            ruleGateway.LoadAllByRuleId(row.RuleID, row.COMPANY_ID);

                            DateTime? newLastService = null; newLastService = DateTime.Now;
                            DateTime? newNextDue = null;
                            bool newDone = true;
                            newChecklistState = "Healthy";

                            if (newLastService.HasValue)
                            {
                                ChecklistGateway checklistGateway = new ChecklistGateway();
                                checklistGateway.LoadByUnitIdRuleId(row.UnitID, row.RuleID, companyId);

                                // ... Original values
                                DateTime? originalLastService = checklistGateway.GetLastService(row.UnitID, row.RuleID);
                                DateTime? originalNextDue = checklistGateway.GetNextDue(row.UnitID, row.RuleID);
                                bool originalDone = checklistGateway.GetDone(row.UnitID, row.RuleID);
                                string originalState = checklistGateway.GetState(row.UnitID, row.RuleID);

                                string frecuency = ruleGateway.GetFrequency(row.RuleID);

                                if (frecuency != "Only once")
                                {
                                    // Get next due
                                    DateTime timeToAdded = new DateTime(((DateTime)newLastService).Year, ((DateTime)newLastService).Month, ((DateTime)newLastService).Day);

                                    if (frecuency == "Monthly") newNextDue = timeToAdded.AddMonths(1);
                                    if (frecuency == "Every 2 months") newNextDue = timeToAdded.AddMonths(2);
                                    if (frecuency == "Every 3 months") newNextDue = timeToAdded.AddMonths(3);
                                    if (frecuency == "Every 4 months") newNextDue = timeToAdded.AddMonths(4);
                                    if (frecuency == "Every 6 months") newNextDue = timeToAdded.AddMonths(6);
                                    if (frecuency == "Yearly") newNextDue = timeToAdded.AddYears(1);

                                    newDone = false;
                                }

                                Checklist checklist = new Checklist();
                                checklist.UpdateDirect(row.UnitID, row.RuleID, originalLastService, originalNextDue, originalDone, originalState, false, companyId, row.UnitID, row.RuleID, newLastService, newNextDue, newDone, newChecklistState, false, companyId);
                            }
                        }
                        else
                        {
                            Checklist checklist = new Checklist(null);
                            checklist.UpdateStateDirect(ruleId.Value, row.UnitID, companyId, newChecklistState);
                        }
                    }
                }
            }

            return newServiceId;
        }
        // ////////////////////////////////////////////////////////////////////////
        // PRIVATE METHODS
        //
        /// <summary>
        /// UpdateForReport
        /// </summary>
        /// <param name="mtoDotRules">mtoDotRules</param>
        /// <param name="frequency">frequency</param>
        /// <param name="state">state</param>
        /// <param name="allUnits">allUnits</param>
        private void UpdateForReport(string mtoDotRules, string frequency, string state, bool allUnits)
        {
            UnitChecklistsReportChecklistDetailsGateway unitChecklistsReportChecklistDetailsGateway = new UnitChecklistsReportChecklistDetailsGateway(Data);
            unitChecklistsReportChecklistDetailsGateway.ClearBeforeFill = false;
            UnitChecklistsReportChecklistDetails unitChecklistsReportChecklistDetails = new UnitChecklistsReportChecklistDetails(Data);

            foreach (UnitChecklistsReportTDS.UnitChecklistsReportUnitDetailsRow row in (UnitChecklistsReportTDS.UnitChecklistsReportUnitDetailsDataTable)Table)
            {
                ChecklistGateway  checklistGateway = new ChecklistGateway();

                // Not show units witho no rules
                if ((!allUnits) && (!checklistGateway.IsUnitUsedInChecklist(row.UnitID)))
                {
                    row.Delete();
                }
                else
                {
                    // Load data for all units
                    if (mtoDotRules == "All")
                    {
                        if (frequency == "(All)")
                        {
                            if (state == "All")
                            {
                                // ... Load All
                                unitChecklistsReportChecklistDetailsGateway.LoadByUnitId(row.UnitID, row.COMPANY_ID);
                            }
                            else
                            {
                                unitChecklistsReportChecklistDetailsGateway.LoadByUnitIdState(row.UnitID, state, row.COMPANY_ID);
                            }
                        }
                        else
                        {
                            if (state == "All")
                            {
                                unitChecklistsReportChecklistDetailsGateway.LoadByUnitIdFrequency(row.UnitID, frequency, row.COMPANY_ID);
                            }
                            else
                            {
                                unitChecklistsReportChecklistDetailsGateway.LoadByUnitIdFrequencyState(row.UnitID, frequency, state, row.COMPANY_ID);
                            }
                        }
                    }
                    else
                    {
                        if (frequency == "(All)")
                        {
                            if (state == "All")
                            {
                                unitChecklistsReportChecklistDetailsGateway.LoadByUnitIdMtoDotRules(row.UnitID, mtoDotRules, row.COMPANY_ID);
                            }
                            else
                            {
                                unitChecklistsReportChecklistDetailsGateway.LoadByUnitIdMtoDotRulesState(row.UnitID, mtoDotRules, state, row.COMPANY_ID);
                            }
                        }
                        else
                        {
                            if (state == "All")
                            {
                                unitChecklistsReportChecklistDetailsGateway.LoadByUnitIdMtoDotRulesFrequency(row.UnitID, mtoDotRules, frequency, row.COMPANY_ID);
                            }
                            else
                            {
                                unitChecklistsReportChecklistDetailsGateway.LoadByUnitIdMtoDotRulesFrequencyState(row.UnitID, mtoDotRules, frequency, state, row.COMPANY_ID);
                            }
                        }
                    }
                }

            }
        }
        /// <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);
                            }
                        }
                    }
                }
            }
        }
        /// <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);
                        }
                    }
                }
            }
        }
Example #7
0
 // ////////////////////////////////////////////////////////////////////////
 // PUBLIC METHODS
 //
 /// <summary>
 /// InsertDirect
 /// </summary>
 /// <param name="unitId">unitId</param>
 /// <param name="ruleId">ruleId</param>
 /// <param name="lastService">lastService</param>
 /// <param name="nextDue">nextDue</param>
 /// <param name="done">done</param>
 /// <param name="state">state</param>
 /// <param name="deleted">deleted</param>
 /// <param name="companyId">companyId</param>
 public void InsertDirect(int unitId, int ruleId, DateTime? lastService, DateTime? nextDue, bool done, string state, bool deleted, int companyId)
 {
     ChecklistGateway checklistGateway = new ChecklistGateway(null);
     checklistGateway.Insert(unitId, ruleId, lastService, nextDue, done, state, deleted, companyId);
 }
Example #8
0
 /// <summary>
 /// UpdateStateDirect
 /// </summary>
 /// <param name="ruleId">ruleId</param>
 /// <param name="unitId">unitId</param>
 /// <param name="companyId">companyId</param>
 /// <param name="newState">newState</param>
 public void UpdateStateDirect(int ruleId, int unitId, int companyId, string newState)
 {
     ChecklistGateway checklistGateway = new ChecklistGateway(null);
     checklistGateway.UpdateState(ruleId, unitId, companyId, newState);
 }
Example #9
0
 /// <summary>
 /// UpdateDirect
 /// </summary>
 /// <param name="originalUnitId">originalUnitId</param>
 /// <param name="originalRuleId">originalRuleId</param>
 /// <param name="originalLastService">originalLastService</param>
 /// <param name="originalNextDue">originalNextDue</param>
 /// <param name="originalDone">originalDone</param>
 /// <param name="originalState">originalState</param>
 /// <param name="originalDeleted">originalDeleted</param>
 /// <param name="originalCompanyId">originalCompanyId</param>
 /// <param name="newUnitId">newUnitId</param>
 /// <param name="newRuleId">newRuleId</param>
 /// <param name="newLastService">newLastService</param>
 /// <param name="newNextDue">newNextDue</param>
 /// <param name="newDone">newDone</param>
 /// <param name="newState">newState</param>
 /// <param name="newDeleted">newDeleted</param>
 /// <param name="newCompanyId">newCompanyId</param>
 public void UpdateDirect(int originalUnitId, int originalRuleId, DateTime? originalLastService, DateTime? originalNextDue, bool originalDone, string originalState, bool originalDeleted, int originalCompanyId, int newUnitId, int newRuleId, DateTime? newLastService, DateTime? newNextDue, bool newDone, string newState, bool newDeleted, int newCompanyId)
 {
     ChecklistGateway checklistGateway = new ChecklistGateway(null);
     checklistGateway.Update(originalUnitId, originalRuleId, originalLastService, originalNextDue, originalDone, originalState, originalDeleted, originalCompanyId, newUnitId, newRuleId, newLastService, newNextDue, newDone, newState, newDeleted, newCompanyId);
 }
Example #10
0
        /// <summary>
        /// UnDeleteDirect
        /// </summary>
        /// <param name="ruleId">ruleId</param>
        /// <param name="unitId">unitId</param>
        /// <param name="companyId">companyId</param>
        public bool UnDeleteDirect(int ruleId, int unitId, int companyId)
        {
            ChecklistGateway checklistGateway = new ChecklistGateway(null);
            checklistGateway.UnDelete(ruleId, unitId, companyId);

            return true;
        }
        /// <summary>
        /// DeleteChecklists
        /// </summary>
        /// <param name="ruleId">ruleId</param>
        /// <param name="companyId">companyId</param>
        private void DeleteChecklists(int ruleId, int companyId)
        {
            ChecklistGateway checklistGateway = new ChecklistGateway(null);

            if (checklistGateway.IsRuleUsedInChecklist(ruleId))
            {
                // Delete all checklists for ruleId
                Checklist checklist = new Checklist(null);
                checklist.DeleteDirectByRuleId(ruleId, companyId);
            }
        }
        /// <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);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }