/// <summary>
        /// Save
        /// </summary>
        public void Save()
        {
            UnitsOfMeasurementNavigatorTDS unitOfMeasurementAddChanges = (UnitsOfMeasurementNavigatorTDS)Data.GetChanges();

            if (unitOfMeasurementAddChanges != null)
            {
                if (unitOfMeasurementAddChanges.UnitsOfMeasurementNavigator.Rows.Count > 0)
                {
                    UnitsOfMeasurementNavigatorGateway unitsOfMeasurementNavigatorGateway = new UnitsOfMeasurementNavigatorGateway(unitOfMeasurementAddChanges);

                    // Update unit of measurement
                    foreach (UnitsOfMeasurementNavigatorTDS.UnitsOfMeasurementNavigatorRow row in (UnitsOfMeasurementNavigatorTDS.UnitsOfMeasurementNavigatorDataTable)unitOfMeasurementAddChanges.UnitsOfMeasurementNavigator)
                    {
                        int companyId = row.COMPANY_ID;

                        // Insert new unit of measurement
                        if ((!row.Deleted) && (!row.InDataBase))
                        {
                            int unitOfMeasurementId = row.UnitOfMeasurementID;
                            string description = row.Description;
                            string abreviation = row.Abbreviation;
                            bool deleted = row.Deleted;

                            UnitsOfMeasurement unitsOfMeasurement = new UnitsOfMeasurement(null);
                            unitsOfMeasurement.InsertDirect(unitOfMeasurementId, description, abreviation, deleted, companyId);
                        }

                        // Update unit of measurement
                        if ((!row.Deleted) && (row.InDataBase))
                        {
                            int unitOfMeasurementId = row.UnitOfMeasurementID;
                            bool originalDeleted = false;
                            int originalCompanyId = companyId;

                            // Original values
                            string originalDescription = unitsOfMeasurementNavigatorGateway.GetDescriptionOriginal(unitOfMeasurementId);
                            string originalAbbreviation = unitsOfMeasurementNavigatorGateway.GetAbbreviationOriginal(unitOfMeasurementId);

                            // New values
                            string newDescription = unitsOfMeasurementNavigatorGateway.GetDescription(unitOfMeasurementId);
                            string newAbbreviation = unitsOfMeasurementNavigatorGateway.GetAbbreviation(unitOfMeasurementId);

                            UnitsOfMeasurement unitsOfMeasurement = new UnitsOfMeasurement(null);
                            unitsOfMeasurement.UpdateDirect(unitOfMeasurementId, originalDescription, originalAbbreviation, originalDeleted, originalCompanyId, unitOfMeasurementId, newDescription, newAbbreviation, originalDeleted, originalCompanyId);
                        }

                        // Delete unit of measurement
                        if ((row.Deleted) && (row.InDataBase))
                        {
                            UnitsOfMeasurement unitsOfMeasurement = new UnitsOfMeasurement(null);
                            unitsOfMeasurement.DeleteDirect(row.UnitOfMeasurementID, row.COMPANY_ID);
                        }

                    }
                }
            }
        }
        // ////////////////////////////////////////////////////////////////////////
        // INITIAL EVENTS
        //
        protected void Page_Load(object sender, EventArgs e)
        {
            // Register client scripts
            this.RegisterClientScripts();

            if (!IsPostBack)
            {
                // Security check
                if ((!Convert.ToBoolean(Session["sgLFS_RESOURCES_UNITSOFMEASUREMENT_VIEW"])) && (!Convert.ToBoolean(Session["sgLFS_RESOURCES_UNITSOFMEASUREMENT_ADD"])) && (!Convert.ToBoolean(Session["sgLFS_RESOURCES_UNITSOFMEASUREMENT_EDIT"])) && (!Convert.ToBoolean(Session["sgLFS_RESOURCES_UNITSOFMEASUREMENT_DELETE"])) )
                {
                    Response.Redirect("./../../error_page.aspx?error=" + "You are not authorized to view this page. Contact your system administrator.");
                }

                // Validate query string
                if ((string)Request.QueryString["source_page"] == null)
                {
                    Response.Redirect("./../../error_page.aspx?error=" + "Invalid query string in unitsOfMeasurement_navigator.aspx");
                }

                // Tag Page
                Session.Remove("unitOfMeasurementDummy");
                hdfCompanyId.Value = Session["companyID"].ToString();

                // If coming from out
                if (((string)Request.QueryString["source_page"] == "out") || ((string)Request.QueryString["source_page"] == "unitsOfMeasurement_navigator.aspx"))
                {
                    unitsOfMeasurementNavigatorTDS = new UnitsOfMeasurementNavigatorTDS();

                    // Get unitsOfMeasurement records
                    int companyId = Int32.Parse(hdfCompanyId.Value);
                    UnitsOfMeasurementNavigatorGateway unitsOfMeasurementNavigatorGateway = new UnitsOfMeasurementNavigatorGateway(unitsOfMeasurementNavigatorTDS);
                    unitsOfMeasurementNavigatorGateway.LoadAll(companyId);

                    // Store dataset
                    Session["unitsOfMeasurementNavigatorTDS"] = unitsOfMeasurementNavigatorTDS;
                    Session["unitsOfMeasurementNavigator"] = unitsOfMeasurementNavigatorTDS.UnitsOfMeasurementNavigator;
                    unitsOfMeasurementNavigator = unitsOfMeasurementNavigatorTDS.UnitsOfMeasurementNavigator;
                }

                // Databind
                Page.DataBind();
            }
            else
            {
                // Restore dataset
                unitsOfMeasurementNavigatorTDS = (UnitsOfMeasurementNavigatorTDS)Session["unitsOfMeasurementNavigatorTDS"];
                unitsOfMeasurementNavigator = unitsOfMeasurementNavigatorTDS.UnitsOfMeasurementNavigator;
            }
        }
 // ////////////////////////////////////////////////////////////////////////
 // PUBLIC METHODS
 //
 /// <summary>
 /// LoadAll
 /// </summary>
 /// <param name="companyId">companyId</param>        
 public void LoadAll(int companyId)
 {
     UnitsOfMeasurementNavigatorGateway unitsOfMeasurementNavigatorGateway = new UnitsOfMeasurementNavigatorGateway(Data);
     unitsOfMeasurementNavigatorGateway.LoadAll(companyId);
 }