Exemplo n.º 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_InstreamFlow_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 iv = __currentInstreamFlow.getRights(); // i for instream flow

            needToSave = !(StateMod_InstreamFlowRight.Equals(wv, iv));

            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 instreamFlowRights = (System.Collections.IList)(__dataset.getComponentForComponentType(StateMod_DataSet.COMP_INSTREAM_RIGHTS)).getData();
            int size = iv.Count;
            StateMod_InstreamFlowRight ir;

            for (int i = 0; i < size; i++)
            {
                ir = (StateMod_InstreamFlowRight)iv[i];
                StateMod_Util.removeFromVector(instreamFlowRights, ir);
            }

            // now add the elements from the new Vector to the instreamFlowRights
            // Vector.
            size = wv.Count;
            StateMod_InstreamFlowRight cir = null;

            for (int i = 0; i < size; i++)
            {
                ir           = (StateMod_InstreamFlowRight)wv[i];
                cir          = (StateMod_InstreamFlowRight)(ir.clone());
                cir._isClone = false;
                instreamFlowRights.Add(cir);
            }

            // sort the instreamFlowRights 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(instreamFlowRights);
            __dataset.getComponentForComponentType(StateMod_DataSet.COMP_INSTREAM_RIGHTS).setData(sorted);
            __currentInstreamFlow.disconnectRights();
            __currentInstreamFlow.connectRights(sorted);
            __dataset.setDirty(StateMod_DataSet.COMP_INSTREAM_RIGHTS, true);
            return(true);
        }