/// <summary>
        /// Save
        /// </summary>
        /// <param name="categoriesSelected">categoriesSelected</param>
        /// <param name="companyId">companyId</param>
        public void Save(ArrayList categoriesSelected, int companyId)
        {
            UnitsAddTDS unitsAddChanges = (UnitsAddTDS)Data.GetChanges();

            if (unitsAddChanges.UnitsAddNew.Rows.Count > 0)
            {
                foreach (UnitsAddTDS.UnitsAddNewRow row in (UnitsAddTDS.UnitsAddNewDataTable)unitsAddChanges.UnitsAddNew)
                {
                    string type = ""; if (!row.IsTypeNull()) type = row.Type;
                    string code = row.Code;
                    string description = ""; if (!row.IsDescriptionNull()) description = row.Description;
                    string vin = ""; if (!row.IsVINNull()) vin = row.VIN;
                    string manufacturer = ""; if (!row.IsManufacturerNull()) manufacturer = row.Manufacturer;
                    string model = ""; if (!row.IsModelNull()) model = row.Model;
                    string year_ = ""; if (!row.IsYear_Null()) year_ = row.Year_;
                    bool isTowable = row.IsTowable;
                    Int64? licenseCountry = null; if (!row.IsLicenseCountryNull()) licenseCountry = row.LicenseCountry;
                    Int64? licenseState = null; if (!row.IsLicenseStateNull()) licenseState = row.LicenseState;
                    string licensePlateNumber = ""; if (!row.IsLicensePlateNumberNull()) licensePlateNumber = row.LicensePlateNumber;
                    int companyLevelId = row.CompanyLevelID;
                    string apportionedTagNumber = ""; if (!row.IsApportionedTagNumberNull()) apportionedTagNumber = row.ApportionedTagNumber;

                    string categories = "";

                    if (categoriesSelected.Count > 0)
                    {
                        foreach (int categoryId in categoriesSelected)
                        {
                            CategoryGateway categoryGateway = new CategoryGateway();
                            categoryGateway.LoadByCategoryId(categoryId, companyId);
                            categories = categories + categoryGateway.GetName(categoryId) + ", ";
                        }

                        if (categories.Length > 2)
                        {
                            categories = categories.Substring(0, categories.Length - 2);
                        }
                    }

                    Units units = new Units(null);
                    int unitId = units.InsertDirect(code, description, vin, manufacturer, model, year_, isTowable, companyLevelId, null, null, "", "", null, null, "", "", null, null, "", "Active", type, false, companyId, "", categories, "", "", null, null, null, null);

                    // ... Insert vehicle info
                    if (type == "Vehicle")
                    {
                        new UnitsVehicle(null).InsertDirect(unitId, licenseCountry, licenseState, licensePlateNumber, apportionedTagNumber, "", "", "", "", "", "", "", false, false, false, companyId);
                    }

                    // Save UnitCategory
                    UpdateUnitCategory(unitId, companyId, categoriesSelected);

                    // Save Checklist
                    UnitsChecklistRulesTemp unitChecklistRulesTemp = new UnitsChecklistRulesTemp(Data);
                    unitChecklistRulesTemp.Save(unitId, companyId);
                }
            }
        }
        private bool Delete(int unitId, int companyId)
        {
            LiquiForce.LFSLive.BL.FleetManagement.Units.Units units = new LiquiForce.LFSLive.BL.FleetManagement.Units.Units(null);

            int result = units.IsInUse(unitId, companyId);

            if (result != 0)
            {
                return false;
            }
            else
            {
                return true;
            }
        }
 /// <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)
 {
     Units units = new Units(null);
     units.DeleteDirect(unitId, unitType, companyId);
 }
 /// <summary>
 /// UpdateUnitState
 /// </summary>
 /// <param name="unitId">unitId</param>
 /// <param name="companyId">companyId</param>
 /// <param name="state">state</param>
 private void UpdateUnitState(int unitId, int companyId, string state)
 {
     Units units = new Units(null);
     units.UpdateStateDirect(unitId, companyId, state);
 }
 // ////////////////////////////////////////////////////////////////////////
 // PRIVATE METHODS
 //
 /// <summary>
 /// UpdateUnit
 /// </summary>
 /// <param name="originalUnitId">originalUnitId</param>
 /// <param name="originalUnitCode"originalUnitCode></param>
 /// <param name="originalDescription">originalDescription</param>
 /// <param name="originalVin">originalVin</param>
 /// <param name="originalManufacturer">originalManufacturer</param>
 /// <param name="originalModel">originalModel</param>
 /// <param name="originalYear_">originalYear_</param>
 /// <param name="originalIsTowable">originalIsTowable</param>
 /// <param name="originalCompanyLevelId">originalCompanyLevelId</param>
 /// <param name="originalAcquisitionDate">originalAcquisitionDate</param>
 /// <param name="originalDispositionDate">originalDispositionDate</param>
 /// <param name="originalDispositionReason">originalDispositionReason</param>        
 /// <param name="originalOwnerType">originalOwnerType</param>
 /// <param name="originalOwnerCountry">originalOwnerCountry</param>
 /// <param name="originalOwnerState">originalOwnerState</param>
 /// <param name="originalOwnerName">originalOwnerName</param>
 /// <param name="originalOwnerContact">originalOwnerContact</param>
 /// <param name="originalQualifiedDate">originalQualifiedDate</param>
 /// <param name="originalNotQualifiedDate">originalNotQualifiedDate</param>
 /// <param name="originalNotQualifiedExplain">originalNotQualifiedExplain</param>
 /// <param name="originalState">originalState</param>
 /// <param name="originalType">originalType</param>
 /// <param name="originalDeleted">originalDeleted</param>
 /// <param name="originalCompanyId">originalCompanyId</param>
 /// <param name="originalNotes">originalNotes</param>
 /// <param name="originalCategories">originalCategories</param>
 /// <param name="originalInsuranceClass">originalInsuranceClass</param>
 /// <param name="originalInsuranceClassRyderSpecified">originalInsuranceClassRyderSpecified</param>
 /// <param name="originalPurchasePrice">originalPurchasePrice</param>
 /// <param name="originalSaleProceeds">originalSaleProceeds</param>
 /// <param name="originalScrapDate">originalScrapDate</param>
 /// <param name="originalLibraryCategoriesId">originalLibraryCategoriesId</param>
 /// 
 /// <param name="newUnitId">newUnitId</param>
 /// <param name="newUnitCode">newUnitCode</param>
 /// <param name="newDescription">newDescription</param>
 /// <param name="newVin">newVin</param>
 /// <param name="newManufacturer">newManufacturer</param>
 /// <param name="newModel">newModel</param>
 /// <param name="newYear_">newYear_</param>
 /// <param name="newIsTowable">newIsTowable</param>
 /// <param name="newCompanyLevelId">newCompanyLevelId</param>
 /// <param name="newAcquisitionDate">newAcquisitionDate</param>
 /// <param name="newDispositionDate">newDispositionDate</param>
 /// <param name="newDispositionReason">newDispositionReason</param>        
 /// <param name="newOwnerType">newOwnerType</param>
 /// <param name="newOwnerCountry">newOwnerCountry</param>
 /// <param name="newOwnerState">newOwnerState</param>
 /// <param name="newOwnerName">newOwnerName</param>
 /// <param name="newOwnerContact">newOwnerContact</param>
 /// <param name="newQualifiedDate">newQualifiedDate</param>
 /// <param name="newNotQualifiedDate">newNotQualifiedDate</param>
 /// <param name="newNotQualifiedExplain">newNotQualifiedExplain</param>
 /// <param name="newState">newState</param>
 /// <param name="newType">newType</param>
 /// <param name="newDeleted">newDeleted</param>
 /// <param name="newCompanyId">newCompanyId</param>
 /// <param name="newNotes">newNotes</param>
 /// <param name="newCategories">newCategories</param>
 /// <param name="newInsuranceClass">newInsuranceClass</param>
 /// <param name="newInsuranceClassRyderSpecified">newInsuranceClassRyderSpecified</param>
 /// <param name="newPurchasePrice">newPurchasePrice</param>
 /// <param name="newSaleProceeds">newSaleProceeds</param>
 /// <param name="newScrapDate">newScrapDate</param>
 /// <param name="newLibraryCategoriesId">newLibraryCategoriesId</param>
 private void UpdateUnit(int originalUnitId, string originalUnitCode, string originalDescription, string originalVin, string originalManufacturer, string originalModel, string originalYear_, bool originalIsTowable, int originalCompanyLevelId, DateTime? originalAcquisitionDate, DateTime? originalDispositionDate, string originalDispositionReason, string originalOwnerType, Int64? originalOwnerCountry, Int64? originalOwnerState, string originalOwnerName, string originalOwnerContact, DateTime? originalQualifiedDate, DateTime? originalNotQualifiedDate, string originalNotQualifiedExplain, string originalState, string originalType, bool originalDeleted, int originalCompanyId, string originalNotes, string originalCategories, string originalInsuranceClass, string originalInsuranceClassRyderSpecified, decimal? originalPurchasePrice, DateTime? originalScrapDate, decimal? originalSaleProceeds, int? originalLibraryCategoriesId, int newUnitId, string newUnitCode, string newDescription, string newVin, string newManufacturer, string newModel, string newYear_, bool newIsTowable, int newCompanyLevelId, DateTime? newAcquisitionDate, DateTime? newDispositionDate, string newDispositionReason, string newOwnerType, Int64? newOwnerCountry, Int64? newOwnerState, string newOwnerName, string newOwnerContact, DateTime? newQualifiedDate, DateTime? newNotQualifiedDate, string newNotQualifiedExplain, string newState, string newType, bool newDeleted, int newCompanyId, string newNotes, string newCategories, string newInsuranceClass, string newInsuranceClassRyderSpecified, decimal? newPurchasePrice, DateTime? newScrapDate, decimal? newSaleProceeds, int? newLibraryCategoriesId)
 {
     Units units = new Units(null);
     units.UpdateDirect(originalUnitId, originalUnitCode, originalDescription, originalVin, originalManufacturer, originalModel, originalYear_, originalIsTowable, originalCompanyLevelId, originalAcquisitionDate, originalDispositionDate, originalDispositionReason,  originalOwnerType, originalOwnerCountry, originalOwnerState, originalOwnerName, originalOwnerContact, originalQualifiedDate, originalNotQualifiedDate, originalNotQualifiedExplain, originalState, originalType, originalDeleted, originalCompanyId, originalNotes, originalCategories, originalInsuranceClass, originalInsuranceClassRyderSpecified, originalPurchasePrice, originalScrapDate, originalSaleProceeds, originalLibraryCategoriesId, newUnitId, newUnitCode, newDescription, newVin, newManufacturer, newModel, newYear_, newIsTowable, newCompanyLevelId, newAcquisitionDate, newDispositionDate, newDispositionReason, newOwnerType, newOwnerCountry, newOwnerState, newOwnerName, newOwnerContact, newQualifiedDate, newNotQualifiedDate, newNotQualifiedExplain, newState, newType, newDeleted, newCompanyId, newNotes, newCategories, newInsuranceClass, newInsuranceClassRyderSpecified, newPurchasePrice, newScrapDate, newSaleProceeds, newLibraryCategoriesId);
 }
        /// <summary>
        /// UpdateUnitState
        /// </summary>
        /// <param name="unitId">unitId</param>
        /// <param name="state">state</param>
        /// <param name="companyId">companyId</param>
        private void UpdateUnitState(int unitId, string state, int companyId)
        {
            ServiceInformationBasicInformation serviceInformationBasicInformation = new ServiceInformationBasicInformation();
            serviceInformationBasicInformation.LoadInProgressByUnitId(unitId, companyId);

            if (serviceInformationBasicInformation.Table.Rows.Count == 0)
            {
                LiquiForce.LFSLive.BL.FleetManagement.Units.Units units = new LiquiForce.LFSLive.BL.FleetManagement.Units.Units(null);
                units.UpdateStateDirect(unitId, companyId, state);
            }
        }
        private int Delete(int unitId, int companyId)
        {
            LiquiForce.LFSLive.BL.FleetManagement.Units.Units units = new LiquiForce.LFSLive.BL.FleetManagement.Units.Units(null);

            int result = units.IsInUse(unitId, companyId);

            return result;
        }