private void LoadNotes(int unitId, int companyId)
        {
            UnitInformationUnitDetailsGateway unitInformationUnitDetailsGateway = new UnitInformationUnitDetailsGateway(unitInformationTDS);

            int? libraryCategoriesId = null; if (unitInformationUnitDetailsGateway.GetLibraryCategoriesId(unitId).HasValue) libraryCategoriesId = (int)unitInformationUnitDetailsGateway.GetLibraryCategoriesId(unitId);

            if (libraryCategoriesId.HasValue)
            {
                tbxCategoryAssocited.Text = GetFullCategoryName((int)libraryCategoriesId, companyId);
            }
            else
            {
                tbxCategoryAssocited.Text = "";
            }
        }
        private void Save2()
        {
            // Validate data
            bool validData = true;

            // For valid data
            if (validData)
            {
                // Validate Ryder Specied
                if (ddlInsuranceClass.SelectedValue == "Ryder Specified")
                {
                    Page.Validate("generalSpecial");
                }

                // Notes Gridview, if the gridview is edition mode
                if (grdNotes.EditIndex >= 0)
                {
                    grdNotes.UpdateRow(grdNotes.EditIndex, true);
                }

                // Inspections Gridview, if the gridview is edition mode
                if (grdInspections.EditIndex >= 0)
                {
                    grdInspections.UpdateRow(grdInspections.EditIndex, true);
                }

                // Costs Gridview, if the gridview is edition mode
                if (grdCosts.EditIndex >= 0)
                {
                    grdCosts.UpdateRow(grdCosts.EditIndex, true);
                }

                // Costs Exceptions Gridview, if the gridview is edition mode
                if (grdCostsExceptions.EditIndex >= 0)
                {
                    grdCostsExceptions.UpdateRow(grdCostsExceptions.EditIndex, true);
                }

                // If there is data at the footers
                GrdNotesAdd();
                InspectionsAddNew();
                GrdCostsAdd();
                GrdCostsExceptionsAdd();

                // Basic
                int companyId = Int32.Parse(hdfCompanyId.Value);
                int unitId = Int32.Parse(hdfUnitId.Value);

                // General
                string code = tbxCode.Text;
                string description = ""; if (tbxDescription.Text != "") description = tbxDescription.Text;
                string vin = ""; if (tbxVinSn.Text != "") vin = tbxVinSn.Text;
                string manufacturer = ""; if (tbxManufacturer.Text != "") manufacturer = tbxManufacturer.Text;
                string model = ""; if (tbxModel.Text != "") model = tbxModel.Text;
                string year = ""; if (tbxYear.Text != "") year = tbxYear.Text;
                bool isTowable = (cbxIsTowable.Checked) ? isTowable = true : isTowable = false;
                int companyLevelIdSelected = 0;
                arrayCompanyLevelsSelectedForEdit.Clear();
                foreach (TreeNode nodes in tvCompanyLevelsRoot.Nodes)
                {
                    GetCompanyLevelsSelected(nodes);
                }
                DateTime? acquisitionDate = null; if (tkrdpAcquisitionDate.SelectedDate.HasValue) acquisitionDate = tkrdpAcquisitionDate.SelectedDate.Value;
                DateTime? dispositionDate = null; if (tkrdpDispositionDate.SelectedDate.HasValue) dispositionDate = tkrdpDispositionDate.SelectedDate.Value;
                string dispositionReason = ""; if (tbxDispositionReason.Text != "") dispositionReason = tbxDispositionReason.Text;

                foreach (int companyLevelId in arrayCompanyLevelsSelectedForEdit)
                {
                    companyLevelIdSelected = companyLevelId;
                }

                // Plate
                Int64? licenseCountry = null;
                Int64? licenceState = null;
                string licensePlateNumber = ""; if (tbxLicensePlateNumber.Text != "") licensePlateNumber = tbxLicensePlateNumber.Text;
                string apportionedTagNumber = ""; // This field will not be shown

                // Technical
                string actualWeight = "";
                string registeredWeight = "";
                string tireSizeFront = "";
                string tireSizeBack = "";
                string numberOfAxes = "";
                string fuelType = "";
                string beginningOdometer = ""; if (tbxBeginningOdometer.Text != "") beginningOdometer = tbxBeginningOdometer.Text;
                bool isRefeerEquipped = cbxIsReeferEquipped.Checked;
                bool isPtoEquipped = cbxIsPtoEquipped.Checked;

                if (hdfUnitType.Value == "Vehicle")
                {
                    if (ddlLicenseCountry.SelectedValue != "-1")
                    {
                        licenseCountry = Int64.Parse(ddlLicenseCountry.SelectedValue);

                        if (licenseCountry.ToString() == "1")
                        {
                            // Ontario
                            hdfLicenseStateId.Value = "12435";
                            licenceState = Int64.Parse(hdfLicenseStateId.Value);
                        }
                        else
                        {
                            if (licenseCountry.ToString() == "2")
                            {
                                // Michigan
                                hdfLicenseStateId.Value = "84026";
                                licenceState = Int64.Parse(hdfLicenseStateId.Value);
                            }
                        }
                    }

                    actualWeight = tbxActualWeight.Text;
                    registeredWeight = tbxRegisteredWeight.Text;
                    tireSizeFront = tbxTireSizeFront.Text;
                    tireSizeBack = tbxTireSizeBack.Text;
                    numberOfAxes = ddlNumberOfAxes.SelectedValue;
                    fuelType = ddlFuelType.SelectedValue;
                }

                // Ownership
                string ownerType = ddlOwnerType.SelectedValue;
                Int64? ownerCountry = null;
                Int64? ownerState = null;
                string ownerName = ""; if (tbxOwnerName.Text != "") ownerName = tbxOwnerName.Text;
                string ownerContact = ""; if (tbxOwnerContact.Text != "") ownerContact = tbxOwnerContact.Text;

                if (ddlOwnerCountry.SelectedValue != "-1")
                {
                    ownerCountry = Int64.Parse(ddlOwnerCountry.SelectedValue);

                    if (ddlOwnerState.SelectedValue != "-1")
                    {
                        ownerState = Int64.Parse(ddlOwnerState.SelectedValue);
                    }
                }

                // Qualification Details
                DateTime? qualifiedDate = null; if (tkrdpQualifiedDate.SelectedDate.HasValue) qualifiedDate = tkrdpQualifiedDate.SelectedDate.Value;
                DateTime? notQualifiedDate = null; if (tkrdpNotQualifiedDate.SelectedDate.HasValue) notQualifiedDate = tkrdpNotQualifiedDate.SelectedDate.Value;
                string notQualifiedExplain = ""; if (tbxIfNotQualifiedExplain.Text != "") notQualifiedExplain = tbxIfNotQualifiedExplain.Text;

                string insuranceClass = ddlInsuranceClass.SelectedValue;
                string insuranceClassRyderSpecified = "";
                if (ddlInsuranceClass.SelectedValue == "Ryder Specified")
                {
                    insuranceClassRyderSpecified = tbxRyderSpecified.Text;
                }
                decimal? purchasePrice = null; if (tbxPurchasePrice.Text != "") purchasePrice = Convert.ToDecimal(tbxPurchasePrice.Text);
                DateTime? scrapDate = null; if (tkrdpScrapDate.SelectedDate.HasValue) scrapDate = tkrdpScrapDate.SelectedDate.Value;
                decimal? saleProceeds = null; if (tbxSaleProceeds.Text != "") saleProceeds = Convert.ToDecimal(tbxSaleProceeds.Text);

                UnitInformationUnitDetailsGateway UnitInformationUnitDetailsGateway = new UnitInformationUnitDetailsGateway(unitInformationTDS);
                int? libraryCategoriesId = null; if (UnitInformationUnitDetailsGateway.GetLibraryCategoriesId(int.Parse(hdfUnitId.Value)).HasValue) libraryCategoriesId = (int)UnitInformationUnitDetailsGateway.GetLibraryCategoriesId(int.Parse(hdfUnitId.Value));

                // Update unit data
                UnitInformationUnitDetails unitInformationUnitDetails = new UnitInformationUnitDetails(unitInformationTDS);
                unitInformationUnitDetails.Update(unitId, code, description, vin, manufacturer, model, year, isTowable, companyLevelIdSelected, acquisitionDate, dispositionDate, dispositionReason, licenseCountry, licenceState, licensePlateNumber, apportionedTagNumber, actualWeight, registeredWeight, tireSizeFront, tireSizeBack, numberOfAxes, fuelType, beginningOdometer, isRefeerEquipped, isPtoEquipped, ownerType, ownerCountry, ownerState, ownerName, ownerContact, qualifiedDate, notQualifiedDate, notQualifiedExplain, insuranceClass, insuranceClassRyderSpecified, purchasePrice, scrapDate, saleProceeds, libraryCategoriesId);

                Session["arrayCategoriesSelectedForEdit"] = arrayCategoriesSelectedForEdit;
                Session["arrayCompanyLevelsSelectedForEdit"] = arrayCompanyLevelsSelectedForEdit;

                // Store dataset
                Session["unitInformationTDS"] = unitInformationTDS;
                Session["categoriesTDSForUnits"] = categoriesTDS;
                Session["companyLevelsTDS"] = companyLevelsTDS;

                ViewState["update"] = "no";
            }
        }
        protected void grdNotes_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            // Edit items
            if ((e.Row.RowType == DataControlRowType.DataRow) && ((e.Row.RowState == DataControlRowState.Edit) || (e.Row.RowState == (DataControlRowState.Edit | DataControlRowState.Alternate))))
            {
                string originalFileNameEdit = ((TextBox)e.Row.FindControl("tbxNoteAttachmentEdit")).Text;
                string fileName = ((Label)e.Row.FindControl("lblFileNameEdit")).Text;
                int libraryFileId = 0; if (((Label)e.Row.FindControl("lblLibraryFileIdEdit")).Text != "") libraryFileId = Int32.Parse(((Label)e.Row.FindControl("lblLibraryFileIdEdit")).Text);

                // Button visibility
                if (originalFileNameEdit == "")
                {
                    ((Button)e.Row.FindControl("btnNoteDeleteEdit")).Visible = false;

                    UnitInformationUnitDetailsGateway unitInformationUnitDetailsGateway = new UnitInformationUnitDetailsGateway(unitInformationTDS);
                    int? libraryCategoriesId = null; if (unitInformationUnitDetailsGateway.GetLibraryCategoriesId(int.Parse(hdfUnitId.Value)).HasValue) libraryCategoriesId = (int)unitInformationUnitDetailsGateway.GetLibraryCategoriesId(int.Parse(hdfUnitId.Value));

                    if (libraryCategoriesId.HasValue)
                    {
                        ((Button)e.Row.FindControl("btnNoteAddEdit")).Visible = true;
                    }
                    else
                    {
                        ((Button)e.Row.FindControl("btnNoteAddEdit")).Visible = false;
                    }
                }
                else
                {
                    ((Button)e.Row.FindControl("btnNoteDeleteEdit")).Visible = true;
                    ((Button)e.Row.FindControl("btnNoteAddEdit")).Visible = false;
                }
            }

            // Normal items
            if ((e.Row.RowType == DataControlRowType.DataRow) && ((e.Row.RowState == DataControlRowState.Normal) || (e.Row.RowState == (DataControlRowState.Normal | DataControlRowState.Alternate))))
            {
                string originalFileName = ((TextBox)e.Row.FindControl("tbxNoteAttachment")).Text;
                string fileName = ((Label)e.Row.FindControl("lblFileName")).Text;
                int libraryFileId = 0; if (((Label)e.Row.FindControl("lblLibraryFileId")).Text != "") libraryFileId = Int32.Parse(((Label)e.Row.FindControl("lblLibraryFileId")).Text);

                // Button visibility
                if (originalFileName == "")
                {
                    ((Button)e.Row.FindControl("btnNoteDownload")).Visible = false;
                }
                else
                {
                    ((Button)e.Row.FindControl("btnNoteDownload")).Visible = true;
                }
            }

            // Footer item
            if (e.Row.RowType == DataControlRowType.Footer)
            {
                UnitInformationUnitDetailsGateway unitInformationUnitDetailsGateway = new UnitInformationUnitDetailsGateway(unitInformationTDS);
                int? libraryCategoriesId = null; if (unitInformationUnitDetailsGateway.GetLibraryCategoriesId(int.Parse(hdfUnitId.Value)).HasValue) libraryCategoriesId = (int)unitInformationUnitDetailsGateway.GetLibraryCategoriesId(int.Parse(hdfUnitId.Value));

                if (libraryCategoriesId.HasValue)
                {
                    ((Button)e.Row.FindControl("btnAddFooter")).Visible = true;
                }
                else
                {
                    ((Button)e.Row.FindControl("btnAddFooter")).Visible = false;
                }
            }
        }
        private void LoadNotes()
        {
            UnitInformationUnitDetailsGateway unitInformationUnitDetailsGateway = new UnitInformationUnitDetailsGateway(unitInformationTDS);

            int? libraryCategoriesId = null; if (unitInformationUnitDetailsGateway.GetLibraryCategoriesId(int.Parse(hdfUnitId.Value)).HasValue) libraryCategoriesId = (int)unitInformationUnitDetailsGateway.GetLibraryCategoriesId(int.Parse(hdfUnitId.Value));

            if (libraryCategoriesId.HasValue)
            {
                ViewState["libraryCategoriesId"] = (int)libraryCategoriesId;
                tbxCategoryAssocited.Text = GetFullCategoryName((int)libraryCategoriesId);
                btnAssociate.Visible = false;
                btnUnassociate.Visible = true;
            }
            else
            {
                tbxCategoryAssocited.Text = "";
                btnAssociate.Visible = true;
                btnUnassociate.Visible = false;
            }
        }
        /// <summary>
        /// Save
        /// </summary>
        /// <param name="categoriesSelected">categoriesSelected</param>
        /// <param name="companyId">companyId</param>
        public void Save(ArrayList categoriesSelected, int companyId)
        {
            UnitInformationTDS unitsInformationChanges = (UnitInformationTDS)Data.GetChanges();

            if (unitsInformationChanges.UnitDetails.Rows.Count > 0)
            {
                UnitInformationUnitDetailsGateway unitInformationUnitDetailsGateway = new UnitInformationUnitDetailsGateway(unitsInformationChanges);

                // Update unit
                foreach (UnitInformationTDS.UnitDetailsRow unitDetailsRow in (UnitInformationTDS.UnitDetailsDataTable)unitsInformationChanges.UnitDetails)
                {
                    // Unchanged values
                    int unitId = unitDetailsRow.UnitID;
                    string state = unitInformationUnitDetailsGateway.GetState(unitId);
                    string type = unitInformationUnitDetailsGateway.GetType(unitId);
                    bool deleted = false;
                    string notes = ""; if (!unitDetailsRow.IsNotesNull()) notes = unitDetailsRow.Notes;
                    string originalCategories = ""; if (!unitDetailsRow.IsCategoriesNull()) originalCategories = unitDetailsRow.Categories;

                    // Original Unit values
                    string originalUnitCode = unitInformationUnitDetailsGateway.GetUnitCodeOriginal(unitId);
                    string originalDescription = unitInformationUnitDetailsGateway.GetDescriptionOriginal(unitId);
                    string originalVin = unitInformationUnitDetailsGateway.GetVinOriginal(unitId);
                    string originalManufacturer = unitInformationUnitDetailsGateway.GetManufacturerOriginal(unitId);
                    string originalModel = unitInformationUnitDetailsGateway.GetModelOriginal(unitId);
                    string originalYear_ = unitInformationUnitDetailsGateway.GetYear_Original(unitId);
                    bool originalIsTowable = unitInformationUnitDetailsGateway.GetIsTowableOriginal(unitId);
                    int originalCompanyLevelId = unitInformationUnitDetailsGateway.GetCompanyLevelIdOriginal(unitId);
                    DateTime? originalAcquisitionDate = null; if (unitInformationUnitDetailsGateway.GetAcquisitionDateOriginal(unitId).HasValue) originalAcquisitionDate = (DateTime)unitInformationUnitDetailsGateway.GetAcquisitionDateOriginal(unitId);
                    DateTime? originalDispositionDate = null; if (unitInformationUnitDetailsGateway.GetDispositionDateOriginal(unitId).HasValue) originalDispositionDate = (DateTime)unitInformationUnitDetailsGateway.GetDispositionDateOriginal(unitId);
                    string originalDispositionReason = unitInformationUnitDetailsGateway.GetDispositionReasonOriginal(unitId);
                    string originalOwnerType = unitInformationUnitDetailsGateway.GetOwnerTypeOriginal(unitId);
                    Int64? originalOwnerCountry = null; if (unitInformationUnitDetailsGateway.GetOwnerCountryOriginal(unitId).HasValue) originalOwnerCountry = (Int64)unitInformationUnitDetailsGateway.GetOwnerCountryOriginal(unitId);
                    Int64? originalOwnerState = null; if (unitInformationUnitDetailsGateway.GetOwnerStateOriginal(unitId).HasValue) originalOwnerState = (Int64)unitInformationUnitDetailsGateway.GetOwnerStateOriginal(unitId);
                    string originalOwnerName = unitInformationUnitDetailsGateway.GetOwnerNameOriginal(unitId);
                    string originalOwnerContact = unitInformationUnitDetailsGateway.GetOwnerContactOriginal(unitId);
                    DateTime? originalQualifiedDate = null; if (unitInformationUnitDetailsGateway.GetQualifiedDateOriginal(unitId).HasValue) originalQualifiedDate = (DateTime)unitInformationUnitDetailsGateway.GetQualifiedDateOriginal(unitId);
                    DateTime? originalNotQualifiedDate = null; if (unitInformationUnitDetailsGateway.GetNotQualifiedDateOriginal(unitId).HasValue) originalNotQualifiedDate = (DateTime)unitInformationUnitDetailsGateway.GetNotQualifiedDateOriginal(unitId);
                    string originalNotQualifiedExplain = unitInformationUnitDetailsGateway.GetNotQualifiedExplainOriginal(unitId);
                    string originalInsuranceClass = unitInformationUnitDetailsGateway.GetInsuranceClassOriginal(unitId);
                    string originalInsuranceClassRyderSpecified = unitInformationUnitDetailsGateway.GetInsuranceClassRyderSpecifiedOriginal(unitId);
                    decimal? originalPurchasePrice = null; if (unitInformationUnitDetailsGateway.GetPurchasePriceOriginal(unitId).HasValue) originalPurchasePrice = unitInformationUnitDetailsGateway.GetPurchasePriceOriginal(unitId).Value;
                    DateTime? originalScrapDate = null; if (unitInformationUnitDetailsGateway.GetScrapDateOriginal(unitId).HasValue) originalScrapDate = (DateTime)unitInformationUnitDetailsGateway.GetScrapDateOriginal(unitId);
                    decimal? originalSaleProceeds = null; if (unitInformationUnitDetailsGateway.GetSaleProceedsOriginal(unitId).HasValue) originalSaleProceeds = unitInformationUnitDetailsGateway.GetSaleProceedsOriginal(unitId).Value;
                    int? originalLibraryCategoriesId = null; if (unitInformationUnitDetailsGateway.GetLibraryCategoriesIdOriginal(unitId).HasValue) originalLibraryCategoriesId = unitInformationUnitDetailsGateway.GetLibraryCategoriesIdOriginal(unitId).Value;

                    // New Unit values
                    string newUnitCode = unitInformationUnitDetailsGateway.GetUnitCode(unitId);
                    string newDescription = unitInformationUnitDetailsGateway.GetDescription(unitId);
                    string newVin = unitInformationUnitDetailsGateway.GetVin(unitId);
                    string newManufacturer = unitInformationUnitDetailsGateway.GetManufacturer(unitId);
                    string newModel = unitInformationUnitDetailsGateway.GetModel(unitId);
                    string newYear_ = unitInformationUnitDetailsGateway.GetYear_(unitId);
                    bool newIsTowable = unitInformationUnitDetailsGateway.GetIsTowable(unitId);
                    int newCompanyLevelId = unitInformationUnitDetailsGateway.GetCompanyLevelId(unitId);
                    DateTime? newAcquisitionDate = null; if (unitInformationUnitDetailsGateway.GetAcquisitionDate(unitId).HasValue) newAcquisitionDate = (DateTime)unitInformationUnitDetailsGateway.GetAcquisitionDate(unitId);
                    DateTime? newDispositionDate = null; if (unitInformationUnitDetailsGateway.GetDispositionDate(unitId).HasValue) newDispositionDate = (DateTime)unitInformationUnitDetailsGateway.GetDispositionDate(unitId);
                    string newDispositionReason = unitInformationUnitDetailsGateway.GetDispositionReason(unitId);
                    string newOwnerType = unitInformationUnitDetailsGateway.GetOwnerType(unitId);
                    Int64? newOwnerCountry = null; if (unitInformationUnitDetailsGateway.GetOwnerCountry(unitId).HasValue) newOwnerCountry = (Int64)unitInformationUnitDetailsGateway.GetOwnerCountry(unitId);
                    Int64? newOwnerState = null; if (unitInformationUnitDetailsGateway.GetOwnerState(unitId).HasValue) newOwnerState = (Int64)unitInformationUnitDetailsGateway.GetOwnerState(unitId);
                    string newOwnerName = unitInformationUnitDetailsGateway.GetOwnerName(unitId);
                    string newOwnerContact = unitInformationUnitDetailsGateway.GetOwnerContact(unitId);
                    DateTime? newQualifiedDate = null; if (unitInformationUnitDetailsGateway.GetQualifiedDate(unitId).HasValue) newQualifiedDate = (DateTime)unitInformationUnitDetailsGateway.GetQualifiedDate(unitId);
                    DateTime? newNotQualifiedDate = null; if (unitInformationUnitDetailsGateway.GetNotQualifiedDate(unitId).HasValue) newNotQualifiedDate = (DateTime)unitInformationUnitDetailsGateway.GetNotQualifiedDate(unitId);
                    string newNotQualifiedExplain = unitInformationUnitDetailsGateway.GetNotQualifiedExplain(unitId);

                    string newCategories = "";

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

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

                    string newInsuranceClass = unitInformationUnitDetailsGateway.GetInsuranceClass(unitId);
                    string newInsuranceClassRyderSpecified = unitInformationUnitDetailsGateway.GetInsuranceClassRyderSpecified(unitId);
                    decimal? newPurchasePrice = null; if (unitInformationUnitDetailsGateway.GetPurchasePrice(unitId).HasValue) newPurchasePrice = unitInformationUnitDetailsGateway.GetPurchasePrice(unitId).Value;
                    DateTime? newScrapDate = null; if (unitInformationUnitDetailsGateway.GetScrapDate(unitId).HasValue) newScrapDate = (DateTime)unitInformationUnitDetailsGateway.GetScrapDate(unitId);
                    decimal? newSaleProceeds = null; if (unitInformationUnitDetailsGateway.GetSaleProceeds(unitId).HasValue) newSaleProceeds = unitInformationUnitDetailsGateway.GetSaleProceeds(unitId).Value;
                    int? newLibraryCategoriesId = null; if (unitInformationUnitDetailsGateway.GetLibraryCategoriesId(unitId).HasValue) newLibraryCategoriesId = unitInformationUnitDetailsGateway.GetLibraryCategoriesId(unitId).Value;

                    // Update unit
                    UpdateUnit(unitId, originalUnitCode, originalDescription, originalVin, originalManufacturer, originalModel, originalYear_, originalIsTowable, originalCompanyLevelId, originalAcquisitionDate, originalDispositionDate, originalDispositionReason,  originalOwnerType, originalOwnerCountry, originalOwnerState, originalOwnerName, originalOwnerContact, originalQualifiedDate, originalNotQualifiedDate, originalNotQualifiedExplain, state, type, deleted, companyId, notes, originalCategories, originalInsuranceClass, originalInsuranceClassRyderSpecified, originalPurchasePrice, originalScrapDate, originalSaleProceeds, originalLibraryCategoriesId, unitId, newUnitCode, newDescription, newVin, newManufacturer, newModel, newYear_, newIsTowable, newCompanyLevelId, newAcquisitionDate, newDispositionDate, newDispositionReason,  newOwnerType, newOwnerCountry, newOwnerState, newOwnerName, newOwnerContact, newQualifiedDate, newNotQualifiedDate, newNotQualifiedExplain, state, type, deleted, companyId, notes, newCategories, newInsuranceClass, newInsuranceClassRyderSpecified, newPurchasePrice, newScrapDate, newSaleProceeds, newLibraryCategoriesId);
                    UpdateUnitCategory(unitId, companyId, categoriesSelected, newCompanyLevelId);

                    if (type == "Vehicle")
                    {
                        // Original Unit Vehicle values
                        Int64? originalLicenseCountry = null; if (unitInformationUnitDetailsGateway.GetLicenseCountryOriginal(unitId).HasValue) originalLicenseCountry = (Int64)unitInformationUnitDetailsGateway.GetLicenseCountryOriginal(unitId);
                        Int64? originalLicenseState = null; if (unitInformationUnitDetailsGateway.GetLicenseStateOriginal(unitId).HasValue) originalLicenseState = (Int64)unitInformationUnitDetailsGateway.GetLicenseStateOriginal(unitId);
                        string originalLicensePlateNumber = unitInformationUnitDetailsGateway.GetLicensePlateNumbverOriginal(unitId);
                        string originalAportionedTagNumber = unitInformationUnitDetailsGateway.GetAportionedTagNumberOriginal(unitId);
                        string originalActualWeight = unitInformationUnitDetailsGateway.GetActualWeightOriginal(unitId);
                        string originalRegisteredWeight = unitInformationUnitDetailsGateway.GetRegisteredWeightOriginal(unitId);
                        string originalTireSizeFront = unitInformationUnitDetailsGateway.GetTireSizeFrontOriginal(unitId);
                        string originalTireSizeBack = unitInformationUnitDetailsGateway.GetTireSizeBackOriginal(unitId);
                        string originalNumberOfAxes = unitInformationUnitDetailsGateway.GetNumberOfAxesOriginal(unitId);
                        string originalFuelType = unitInformationUnitDetailsGateway.GetFuelTypeOriginal(unitId);
                        string originalBeginningOdometer = unitInformationUnitDetailsGateway.GetBeginningOdometerOriginal(unitId);
                        bool originalIsReeferEquipped = unitInformationUnitDetailsGateway.GetIsReeferEquippedOriginal(unitId);
                        bool originalIsPtoEquipped = unitInformationUnitDetailsGateway.GetIsPTOEquippedOriginal(unitId);

                        // New Unit Vehicle values
                        Int64? newLicenseCountry = null; if (unitInformationUnitDetailsGateway.GetLicenseCountry(unitId).HasValue) newLicenseCountry = (Int64)unitInformationUnitDetailsGateway.GetLicenseCountry(unitId);
                        Int64? newLicenseState = null; if (unitInformationUnitDetailsGateway.GetLicenseState(unitId).HasValue) newLicenseState = (Int64)unitInformationUnitDetailsGateway.GetLicenseState(unitId);
                        string newLicensePlateNumber = unitInformationUnitDetailsGateway.GetLicensePlateNumbver(unitId);
                        string newAportionedTagNumber = unitInformationUnitDetailsGateway.GetAportionedTagNumber(unitId);
                        string newActualWeight = unitInformationUnitDetailsGateway.GetActualWeight(unitId);
                        string newRegisteredWeight = unitInformationUnitDetailsGateway.GetRegisteredWeight(unitId);
                        string newTireSizeFront = unitInformationUnitDetailsGateway.GetTireSizeFront(unitId);
                        string newTireSizeBack = unitInformationUnitDetailsGateway.GetTireSizeBack(unitId);
                        string newNumberOfAxes = unitInformationUnitDetailsGateway.GetNumberOfAxes(unitId);
                        string newFuelType = unitInformationUnitDetailsGateway.GetFuelType(unitId);
                        string newBeginningOdometer = unitInformationUnitDetailsGateway.GetBeginningOdometer(unitId);
                        bool newIsReeferEquipped = unitInformationUnitDetailsGateway.GetIsReeferEquipped(unitId);
                        bool newIsPtoEquipped = unitInformationUnitDetailsGateway.GetIsPTOEquipped(unitId);

                        UpdateUnitVehicle(unitId, originalLicenseCountry, originalLicenseState, originalLicensePlateNumber, originalAportionedTagNumber, originalActualWeight, originalRegisteredWeight, originalTireSizeFront, originalTireSizeBack, originalNumberOfAxes, originalFuelType, originalBeginningOdometer, originalIsReeferEquipped, originalIsPtoEquipped, deleted, companyId, unitId, newLicenseCountry, newLicenseState, newLicensePlateNumber, newAportionedTagNumber, newActualWeight, newRegisteredWeight, newTireSizeFront, newTireSizeBack, newNumberOfAxes, newFuelType, newBeginningOdometer, newIsReeferEquipped, newIsPtoEquipped, deleted, companyId);
                    }
                }
            }
        }