コード例 #1
0
        /// <summary>
        /// Saves the input back into the dataset. </summary>
        /// <returns> true if the data was saved successfuly.  False if not. </returns>
        private bool saveData()
        {
            string routine = "StateMod_Diversion_Right_JFrame.saveData";

            if (!__worksheet.stopEditing())
            {
                // don't save if there are errors.
                Message.printWarning(1, routine, "There are errors in the data " + "that must be corrected before data can be saved.", this);
                return(false);
            }

            if (checkInput() > 0)
            {
                return(false);
            }

            // now only save data if any are different.
            bool needToSave = false;

            // if the Vectors are differently-sized, they're different
            System.Collections.IList wv = __worksheet.getAllData();     // w for worksheet
            System.Collections.IList dv = __currentDiv.getRights();     // d for diversion

            needToSave = !(StateMod_DiversionRight.Equals(wv, dv));

            Message.printStatus(1, routine, "Saving? .........[" + needToSave + "]");

            if (!needToSave)
            {
                // there's nothing different -- users may even have deleted
                // some rights and added back in identical values
                return(true);
            }

            // at this point, remove the old diversion rights from the original
            // component Vector
            System.Collections.IList diversionRights = (System.Collections.IList)(__dataset.getComponentForComponentType(StateMod_DataSet.COMP_DIVERSION_RIGHTS)).getData();
            int size = dv.Count;
            StateMod_DiversionRight dr;

            for (int i = 0; i < size; i++)
            {
                dr = (StateMod_DiversionRight)dv[i];
                StateMod_Util.removeFromVector(diversionRights, dr);
            }

            // now add the elements from the new Vector to the diversionRights
            // Vector.
            size = wv.Count;
            StateMod_DiversionRight cdr = null;

            for (int i = 0; i < size; i++)
            {
                dr           = (StateMod_DiversionRight)wv[i];
                cdr          = (StateMod_DiversionRight)dr.clone();
                cdr._isClone = false;
                diversionRights.Add(cdr);
            }

            // sort the diversionRights Vector
            // REVISIT (JTS - 2003-10-10)
            // here we are sorting the full data array -- may be a performance
            // issue
            System.Collections.IList sorted = StateMod_Util.sortStateMod_DataVector(diversionRights);
            __dataset.getComponentForComponentType(StateMod_DataSet.COMP_DIVERSION_RIGHTS).setData(sorted);
            __currentDiv.disconnectRights();
            __currentDiv.connectRights(sorted);
            __dataset.setDirty(StateMod_DataSet.COMP_DIVERSION_RIGHTS, true);
            return(true);
        }