/// <summary>
        /// Sets up the data to be displayed in the table. </summary>
        /// <param name="data"> a Vector of StateMod_DelayTable objects from which the data to b
        /// be displayed in the table will be gathered. </param>

        /*
         * private void setupData(List data) {
         *      int num = 0;
         *      int size = data.size();
         *      StateMod_DelayTable dt = null;
         *      String id = null;
         *      __data = new List[__COLUMNS];
         *      for (int i = 0; i < __COLUMNS; i++) {
         *              __data[i] = new Vector();
         *      }
         *
         *      __rowMap = new Vector();
         *
         *      double total = 0;
         *      int rowCount = 0;
         *      for (int i = 0; i < size; i++) {
         *              total = 0;
         *              dt = (StateMod_DelayTable)data.get(i);
         *              id = dt.getID();
         *              num = dt.getNdly();
         *              for (int j = 0; j < num; j++) {
         *                      __data[COL_PLAN_ID].add(id);
         *                      __data[COL_RIVER_NODE_ID].add(new Integer(j + 1));
         *                      __data[COL_PERCENT_RETURN].add( new Double(dt.getRet_val(j)));
         *                      total += dt.getRet_val(j);
         *                      __rowMap.add(new Integer(rowCount));
         *                      rowCount++;
         *              }
         *
         *              __data[COL_PLAN_ID].add("TOTAL " + id);
         *              __data[COL_RIVER_NODE_ID].add(new Integer(-999));
         *              __data[COL_PERCENT_RETURN].add(new Double(total));
         *
         *              rowCount++;
         *      }
         *      _rows = rowCount;
         * }
         */

        /// <summary>
        /// Sets the value at the specified position to the specified value. </summary>
        /// <param name="value"> the value to set the cell to. </param>
        /// <param name="row"> the row of the cell for which to set the value. </param>
        /// <param name="col"> the col of the cell for which to set the value. </param>
        public virtual void setValueAt(object value, int row, int col)
        {
            if (_sortOrder != null)
            {
                row = _sortOrder[row];
            }

            StateMod_ReturnFlow rf = (StateMod_ReturnFlow)_data.get(row);

            switch (col)
            {
            case COL_PLAN_ID:
                rf.setID((string)value);
                break;

            case COL_RIVER_NODE_ID:
                rf.setCrtnid((string)value);
                break;

            case COL_PERCENT_RETURN:
                rf.setPcttot((double?)value);
                break;

            case COL_DELAY_TABLE_ID:
                rf.setIrtndl((string)value);
                break;

            case COL_COMMENT:
                rf.setComment((string)value);
                break;
            }
            base.setValueAt(value, row, col);
        }
        /// <summary>
        /// Checks the data to make sure that all the data are valid. </summary>
        /// <returns> 0 if the data are valid, 1 if errors exist and -1 if non-fatal errors
        /// exist. </returns>
        private int checkInput()
        {
            string routine = "StateMod_Well_ReturnFlow_JFrame.checkInput";
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @SuppressWarnings("unchecked") java.util.List<StateMod_ReturnFlow> v = (java.util.List<StateMod_ReturnFlow>)__worksheet.getAllData();
            IList <StateMod_ReturnFlow> v = (IList <StateMod_ReturnFlow>)__worksheet.getAllData();

            int size = v.Count;
            StateMod_ReturnFlow rf = null;
            string warning         = "";
            string riverNode;
            int    fatalCount = 0;

            for (int i = 0; i < size; i++)
            {
                rf        = v[i];
                riverNode = rf.getCrtnid();
                riverNode = StringUtil.getToken(riverNode, " ", StringUtil.DELIM_SKIP_BLANKS, 0);
                if (string.ReferenceEquals(riverNode, null))
                {
                    riverNode = "";
                    warning  += "\nMust specify a River Node ID.";
                    fatalCount++;
                }
                if (riverNode.Length > 12)
                {
                    warning += "\nRiver Node ID (" + riverNode + ") is "
                               + "longer than 12 characters.";
                    fatalCount++;
                }

                if (riverNode.IndexOf(" ", StringComparison.Ordinal) > -1 || riverNode.IndexOf("-", StringComparison.Ordinal) > -1)
                {
                    warning += "\nRiver Node ID (" + riverNode + ") cannot contain spaces or dashes.";
                    fatalCount++;
                }
            }
            if (warning.Length > 0)
            {
                warning += "\nCorrect or Cancel.";
                Message.printWarning(1, routine, warning, this);
                if (fatalCount > 0)
                {
                    // Fatal errors...
                    Message.printStatus(1, routine, "Returning 1 from checkInput()");
                    return(1);
                }
                else
                {         // Nonfatal errors...
                    Message.printStatus(1, routine, "Returning -1 from checkInput()");
                    return(-1);
                }
            }
            else
            {     // No errors...
                Message.printStatus(1, routine, "Returning 0 from checkInput()");
                return(0);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Clones the data object. </summary>
        /// <returns> a cloned object. </returns>
        public override object clone()
        {
            StateMod_ReturnFlow rf = (StateMod_ReturnFlow)base.clone();

            rf._isClone = true;

            return(rf);
        }
        /// <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_ReturnFlow_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 lists are differently-sized, they're different
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @SuppressWarnings("unchecked") java.util.List<StateMod_ReturnFlow> wv = (java.util.List<StateMod_ReturnFlow>)__worksheet.getAllData();
            IList <StateMod_ReturnFlow> wv = (IList <StateMod_ReturnFlow>)__worksheet.getAllData(); // w for worksheet

            System.Collections.IList dv = __currentDiv.getReturnFlows();                            // d for diversion

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

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

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

            // clone the objects from the worksheet vector and assign them
            // to the diversion object as its new return flows.
            int size = wv.Count;
            IList <StateMod_ReturnFlow> clone = new List <StateMod_ReturnFlow>();
            StateMod_ReturnFlow         rf    = null;
            StateMod_ReturnFlow         crf   = null;

            for (int i = 0; i < size; i++)
            {
                rf  = wv[i];
                crf = (StateMod_ReturnFlow)rf.clone();
                rf.setCrtnid(StringUtil.getToken(rf.getCrtnid(), " ", StringUtil.DELIM_SKIP_BLANKS, 0));
                crf._isClone = false;
                clone.Add(crf);
            }

            __currentDiv.setReturnFlow(clone);
            __dataset.setDirty(StateMod_DataSet.COMP_DIVERSION_STATIONS, true);

            return(true);
        }
        /// <summary>
        /// Checks the data to make sure that all the data are valid. </summary>
        /// <returns> 0 if the data are valid, 1 if errors exist and -1 if non-fatal errors
        /// exist. </returns>
        private int checkInput()
        {
            string routine = "StateMod_Well_ReturnFlow_JFrame.checkInput";

            System.Collections.IList v = __worksheet.getAllData();

            int size = v.Count;
            StateMod_ReturnFlow rf = null;
            string warning         = "";
            string riverNode;
            int    fatalCount = 0;

            for (int i = 0; i < size; i++)
            {
                rf        = (StateMod_ReturnFlow)(v[i]);
                riverNode = rf.getCrtnid();
                riverNode = StringUtil.getToken(riverNode, " ", StringUtil.DELIM_SKIP_BLANKS, 0);
                if (string.ReferenceEquals(riverNode, null))
                {
                    riverNode = "";
                    warning  += "\nMust specify a River Node ID.";
                    fatalCount++;
                }
                if (riverNode.Length > 12)
                {
                    warning += "\nRiver Node ID (" + riverNode + ") is "
                               + "longer than 12 characters.";
                    fatalCount++;
                }

                if (riverNode.IndexOf(" ", StringComparison.Ordinal) > -1 || riverNode.IndexOf("-", StringComparison.Ordinal) > -1)
                {
                    warning += "\nRiver Node ID (" + riverNode + ") cannot contain spaces or dashes.";
                    fatalCount++;
                }
            }
            if (warning.Length > 0)
            {
                warning += "\nCorrect or Cancel.";
                Message.printWarning(1, routine, warning, this);
                if (fatalCount > 0)
                {
                    // Fatal errors...
                    Message.printStatus(1, routine, "Returning 1 from checkInput()");
                    return(1);
                }
                else
                {         // Nonfatal errors...
                    Message.printStatus(1, routine, "Returning -1 from checkInput()");
                    return(-1);
                }
            }
            else
            {     // No errors...
                Message.printStatus(1, routine, "Returning 0 from checkInput()");
                return(0);
            }
        }
        /// <summary>
        /// Sets up the data to be displayed in the table.
        /// </summary>
        private void setupData()
        {
            int           num      = 0;
            int           size     = _data.size();
            StateMod_Well well     = null;
            string        id       = null;
            double        total    = 0;
            int           rowCount = 0;

            __data = new System.Collections.IList[__COLUMNS];
            for (int i = 0; i < __COLUMNS; i++)
            {
                __data[i] = new List <object>();
            }

            __rowMap = new List <object>();

            StateMod_ReturnFlow rf = null;

            System.Collections.IList returnFlows = null;
            for (int i = 0; i < size; i++)
            {
                total = 0;
                well  = (StateMod_Well)_data.get(i);
                id    = well.getID();

                if (__isDepletion)
                {
                    num         = well.getNrtnw2();
                    returnFlows = well.getDepletions();
                }
                else
                {
                    num         = well.getNrtnw();
                    returnFlows = well.getReturnFlows();
                }
                for (int j = 0; j < num; j++)
                {
                    rf = (StateMod_ReturnFlow)returnFlows[j];
                    __data[__COL_ID].Add(id);
                    __data[__COL_NODE_ID].Add(rf.getCrtnid());
                    __data[__COL_PERCENT].Add(new double?(rf.getPcttot()));
                    __data[__COL_DELAY_ID].Add("" + rf.getIrtndl());
                    total += rf.getPcttot();
                    __rowMap.Add(new int?(rowCount));
                    rowCount++;
                }

                __data[__COL_ID].Add(id);
                __data[__COL_NODE_ID].Add("TOTAL");
                __data[__COL_PERCENT].Add(new double?(total));
                __data[__COL_DELAY_ID].Add("");

                rowCount++;
            }
            _rows = rowCount;
        }
        /// <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_Well_ReturnFlow_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 lv = __currentWell.getReturnFlows(); // l for welL

            needToSave = !(StateMod_ReturnFlow.Equals(wv, lv));

            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);
            }

            // clone the objects from the worksheet vector and assign them
            // to the well object as its new return flows.
            int size = wv.Count;

            System.Collections.IList clone = new List <object>();
            StateMod_ReturnFlow      rf;
            StateMod_ReturnFlow      crf = null;

            for (int i = 0; i < size; i++)
            {
                rf  = (StateMod_ReturnFlow)wv[i];
                crf = (StateMod_ReturnFlow)rf.clone();
                crf.setCrtnid(StringUtil.getToken(rf.getCrtnid(), " ", StringUtil.DELIM_SKIP_BLANKS, 0));
                crf._isClone = false;
                clone.Add(crf);
            }

            __currentWell.setReturnFlows(clone);
            __dataset.setDirty(StateMod_DataSet.COMP_WELL_STATIONS, true);

            return(true);
        }
        /// <summary>
        /// Inserts the specified value into the table at the given position. </summary>
        /// <param name="value"> the object to store in the table cell. </param>
        /// <param name="row"> the row of the cell in which to place the object. </param>
        /// <param name="col"> the column of the cell in which to place the object. </param>
        public virtual void setValueAt(object value, int row, int col)
        {
            if (_sortOrder != null)
            {
                row = _sortOrder[row];
            }
            double dval;
            int    ival;
            int    index;
            string s;

            StateMod_ReturnFlow rf = (StateMod_ReturnFlow)_data.get(row);

            switch (col)
            {
            case COL_RIVER_NODE:
                rf.setCrtnid((string)value);
                break;

            case COL_RETURN_PCT:
                dval = ((double?)value).Value;
                rf.setPcttot(dval);
                break;

            case COL_RETURN_ID:
                if (value is string)
                {
                    index = ((string)value).IndexOf(" -", StringComparison.Ordinal);
                    s     = null;
                    if (index > -1)
                    {
                        s = ((string)value).Substring(0, index);
                    }
                    else
                    {
                        s = (string)value;
                    }
                    rf.setIrtndl(s);
                }
                else
                {
                    if (value == null)
                    {
                        // user input a blank value -- just keep what was originally in the table
                        return;
                    }
                    ival = ((int?)value).Value;
                    rf.setIrtndl(ival);
                }
                break;
            }

            base.setValueAt(value, row, col);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Called when the Apply button is pressed. This commits any changes to the data objects.
        /// </summary>
        protected internal override void apply()
        {
            StateMod_ReturnFlow rf = null;
            int size = _data.Count;

            for (int i = 0; i < size; i++)
            {
                rf = (StateMod_ReturnFlow)_data[i];
                rf.createBackup();
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Called when the cancel button is pressed.  This discards any changes made to the data objects.
        /// </summary>
        protected internal override void cancel()
        {
            StateMod_ReturnFlow rf = null;
            int size = _data.Count;

            for (int i = 0; i < size; i++)
            {
                rf = (StateMod_ReturnFlow)_data[i];
                rf.restoreOriginal();
            }
        }
Ejemplo n.º 11
0
 /// <summary>
 /// Tests to see if two return flows are equal.  Strings are compared with case sensitivity. </summary>
 /// <param name="rf"> the return flow to compare. </param>
 /// <returns> true if they are equal, false otherwise. </returns>
 public virtual bool Equals(StateMod_ReturnFlow rf)
 {
     if (!base.Equals(rf))
     {
         return(false);
     }
     if (rf.__crtnid.Equals(__crtnid) && rf.__pcttot == __pcttot && rf.__irtndl == __irtndl && rf.__isMonthlyData == __isMonthlyData)
     {
         return(true);
     }
     return(false);
 }
Ejemplo n.º 12
0
        /// <summary>
        /// Cancels any changes made to this object within a GUI since createBackup()
        /// was called and sets _original to null.
        /// </summary>
        public override void restoreOriginal()
        {
            StateMod_ReturnFlow rf = (StateMod_ReturnFlow)_original;

            base.restoreOriginal();

            __crtnid  = rf.__crtnid;
            __pcttot  = rf.__pcttot;
            __irtndl  = rf.__irtndl;
            _isClone  = false;
            _original = null;
        }
 /// <summary>
 /// Add return flow node to the vector of return flow nodes. </summary>
 /// <param name="rivret"> return flow </param>
 public virtual void addReturnFlow(StateMod_ReturnFlow rivret)
 {
     if (rivret == null)
     {
         return;
     }
     _rivret.Add(rivret);
     setDirty(true);
     if (!_isClone && _dataset != null)
     {
         _dataset.setDirty(StateMod_DataSet.COMP_DIVERSION_STATIONS, true);
     }
 }
Ejemplo n.º 14
0
 /// <summary>
 /// Add depletion node to the vector of depletion nodes.  Updates the variable
 /// which tracks the number of depletion nodes for this well. </summary>
 /// <param name="depl"> depletion data object </param>
 public virtual void addDepletion(StateMod_ReturnFlow depl)
 {
     if (depl == null)
     {
         return;
     }
     _depl.Add(depl);
     setDirty(true);
     if (!_isClone && _dataset != null)
     {
         _dataset.setDirty(StateMod_DataSet.COMP_WELL_STATIONS, true);
     }
 }
        /// <summary>
        /// Responds to action performed events. </summary>
        /// <param name="e"> the ActionEvent that happened. </param>
        public virtual void actionPerformed(ActionEvent e)
        {
            string action = e.getActionCommand();

            if (action.Equals(__BUTTON_ADD_DEPLETION))
            {
                StateMod_ReturnFlow aReturnFlow = new StateMod_ReturnFlow(StateMod_DataSet.COMP_WELL_STATIONS);
                aReturnFlow._isClone = true;
                __worksheet.addRow(aReturnFlow);
                __worksheet.scrollToLastRow();
                __worksheet.selectLastRow();
                __deleteDepletion.setEnabled(true);
            }
            else if (action.Equals(__BUTTON_DELETE_DEPLETION))
            {
                int row = __worksheet.getSelectedRow();
                if (row != -1)
                {
                    int x = (new ResponseJDialog(this, "Delete Depletion", "Delete depletion?", ResponseJDialog.YES | ResponseJDialog.NO)).response();
                    if (x == ResponseJDialog.NO)
                    {
                        return;
                    }
                    __worksheet.cancelEditing();
                    __worksheet.deleteRow(row);
                    __deleteDepletion.setEnabled(false);
                }
            }
            else if (action.Equals(__BUTTON_CLOSE))
            {
                if (saveData())
                {
                    setVisible(false);
                    dispose();
                }
            }
            else if (action.Equals(__BUTTON_APPLY))
            {
                saveData();
            }
            else if (action.Equals(__BUTTON_CANCEL))
            {
                setVisible(false);
                dispose();
            }
            else if (action.Equals(__BUTTON_HELP))
            {
                // REVISIT HELP (JTS - 2003-06-24)
            }
        }
        /// <summary>
        /// Returns the data that should be placed in the JTable at the given row and column. </summary>
        /// <param name="row"> the row for which to return data. </param>
        /// <param name="col"> the column for which to return data. </param>
        /// <returns> the data that should be placed in the JTable at the given row and col. </returns>
        public virtual object getValueAt(int row, int col)
        {
            if (_sortOrder != null)
            {
                row = _sortOrder[row];
            }

            StateMod_ReturnFlow rf = (StateMod_ReturnFlow)_data.get(row);

            switch (col)
            {
            case COL_PLAN_ID:
                return(rf.getID());

            case COL_RIVER_NODE_ID:
                return(rf.getCrtnid());

            case COL_PERCENT_RETURN:
                return(rf.getPcttot());

            case COL_DELAY_TABLE_ID:
                return(rf.getIrtndl());

            case COL_COMMENT:
                return(rf.getComment());

            default:
                return("");
            }

            /*
             * if (!__showTotals) {
             *      row = ((Integer)__rowMap.get(row)).intValue();
             * }
             * return __data[col].get(row);
             */
        }
        /// <summary>
        /// Returns the data that should be placed in the JTable at the given row and column. </summary>
        /// <param name="row"> the row for which to return data. </param>
        /// <param name="col"> the column for which to return data. </param>
        /// <returns> the data that should be placed in the JTable at the given row and col. </returns>
        public virtual object getValueAt(int row, int col)
        {
            if (_sortOrder != null)
            {
                row = _sortOrder[row];
            }

            StateMod_ReturnFlow rf = (StateMod_ReturnFlow)_data.get(row);

            switch (col)
            {
            case COL_RIVER_NODE:
                return(rf.getCrtnid());

            case COL_RETURN_PCT:
                return(new double?(rf.getPcttot()));

            case COL_RETURN_ID:
                return(new int?(rf.getIrtndl()));

            default:
                return("");
            }
        }
        /// <summary>
        /// Read diversion information in and store in a java vector.
        /// The new diversions are added to the end of the previously stored diversions. </summary>
        /// <param name="filename"> filename containing diversion information </param>
        /// <exception cref="Exception"> if an error occurs </exception>
        //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
        //ORIGINAL LINE: public static java.util.List<StateMod_Diversion> readStateModFile(String filename) throws Exception
        public static IList <StateMod_Diversion> readStateModFile(string filename)
        {
            string                     routine       = "StateMod_Diversion.readStateModFile";
            string                     iline         = null;
            IList <object>             v             = new List <object>(9);
            IList <StateMod_Diversion> theDiversions = new List <StateMod_Diversion>();
            int    i;
            int    linecount = 0;
            string s         = null;

            int[] format_0  = new int[] { StringUtil.TYPE_STRING, StringUtil.TYPE_STRING, StringUtil.TYPE_STRING, StringUtil.TYPE_INTEGER, StringUtil.TYPE_DOUBLE, StringUtil.TYPE_INTEGER, StringUtil.TYPE_INTEGER, StringUtil.TYPE_STRING, StringUtil.TYPE_STRING };
            int[] format_0w = new int[] { 12, 24, 12, 8, 8, 8, 8, 1, 12 };
            int[] format_1  = new int[] { StringUtil.TYPE_STRING, StringUtil.TYPE_STRING, StringUtil.TYPE_STRING, StringUtil.TYPE_INTEGER, StringUtil.TYPE_INTEGER, StringUtil.TYPE_DOUBLE, StringUtil.TYPE_DOUBLE, StringUtil.TYPE_INTEGER, StringUtil.TYPE_INTEGER };
            int[] format_1w = new int[] { 12, 24, 12, 8, 8, 8, 8, 8, 8 };
            int[] format_2  = new int[] { StringUtil.TYPE_STRING, StringUtil.TYPE_STRING, StringUtil.TYPE_DOUBLE, StringUtil.TYPE_INTEGER };
            int[] format_2w = new int[] { 36, 12, 8, 8 };

            StateMod_Diversion  aDiversion  = null;
            StateMod_ReturnFlow aReturnNode = null;
            StreamReader        @in         = null;

            Message.printStatus(1, routine, "Reading diversion file: " + filename);
            try
            {
                @in = new StreamReader(IOUtil.getPathUsingWorkingDir(filename));
                while (!string.ReferenceEquals((iline = @in.ReadLine()), null))
                {
                    ++linecount;
                    // check for comments
                    if (iline.StartsWith("#", StringComparison.Ordinal) || iline.Trim().Length == 0)
                    {
                        continue;
                    }

                    // allocate new diversion node
                    aDiversion = new StateMod_Diversion();

                    // line 1
                    if (Message.isDebugOn)
                    {
                        Message.printDebug(50, routine, "line 1: " + iline);
                    }
                    StringUtil.fixedRead(iline, format_0, format_0w, v);
                    aDiversion.setID(((string)v[0]).Trim());
                    aDiversion.setName(((string)v[1]).Trim());
                    aDiversion.setCgoto(((string)v[2]).Trim());
                    aDiversion.setSwitch((int?)v[3]);
                    aDiversion.setDivcap((double?)v[4]);
                    aDiversion.setIreptype(((int?)v[6]));
                    aDiversion.setCdividy(((string)v[8]).Trim());

                    // line 2
                    iline = @in.ReadLine();
                    ++linecount;
                    if (Message.isDebugOn)
                    {
                        Message.printDebug(50, routine, "line 2: " + iline);
                    }
                    StringUtil.fixedRead(iline, format_1, format_1w, v);
                    aDiversion.setUsername(((string)v[1]).Trim());
                    aDiversion.setIdvcom(((int?)v[3]));
                    int nrtn = ((int?)v[4]).Value;
                    aDiversion.setDivefc(((double?)v[5]));
                    aDiversion.setArea(((double?)v[6]));
                    aDiversion.setIrturn(((int?)v[7]));
                    aDiversion.setDemsrc(((int?)v[8]));

                    // get the efficiency information
                    if (aDiversion.getDivefc() < 0)
                    {
                        // Negative value indicates monthly efficiencies will follow...
                        iline = @in.ReadLine();
                        ++linecount;
                        // Free format...
                        char[]   seps  = { ' ', '\t', '\n', '\r', '\f' };
                        string[] split = iline.Split(seps);
                        if (split != null && split.Length == 12)
                        {
                            for (i = 0; i < 12; i++)
                            {
                                aDiversion.setDiveff(i, split[0]);
                            }
                        }
                    }
                    else
                    {
                        // Annual efficiency so set monthly efficiencies to the annual...
                        aDiversion.setDiveff(0, aDiversion.getDivefc());
                        aDiversion.setDiveff(1, aDiversion.getDivefc());
                        aDiversion.setDiveff(2, aDiversion.getDivefc());
                        aDiversion.setDiveff(3, aDiversion.getDivefc());
                        aDiversion.setDiveff(4, aDiversion.getDivefc());
                        aDiversion.setDiveff(5, aDiversion.getDivefc());
                        aDiversion.setDiveff(6, aDiversion.getDivefc());
                        aDiversion.setDiveff(7, aDiversion.getDivefc());
                        aDiversion.setDiveff(8, aDiversion.getDivefc());
                        aDiversion.setDiveff(9, aDiversion.getDivefc());
                        aDiversion.setDiveff(10, aDiversion.getDivefc());
                        aDiversion.setDiveff(11, aDiversion.getDivefc());
                    }

                    // get the return information
                    for (i = 0; i < nrtn; i++)
                    {
                        iline = @in.ReadLine();
                        ++linecount;
                        StringUtil.fixedRead(iline, format_2, format_2w, v);
                        aReturnNode = new StateMod_ReturnFlow(StateMod_DataSet.COMP_DIVERSION_STATIONS);
                        s           = ((string)v[1]).Trim();
                        if (s.Length <= 0)
                        {
                            aReturnNode.setCrtnid(((string)v[0]).Trim());
                            Message.printWarning(3, routine, "Return node for structure \"" + aDiversion.getID() + "\" is blank. ");
                        }
                        else
                        {
                            aReturnNode.setCrtnid(s);
                        }

                        aReturnNode.setPcttot(((double?)v[2]));
                        aReturnNode.setIrtndl(((int?)v[3]));
                        aDiversion.addReturnFlow(aReturnNode);
                    }

                    // Set the diversion to not dirty because it was just initialized...

                    aDiversion.setDirty(false);

                    // add the diversion to the vector of diversions
                    theDiversions.Add(aDiversion);
                }
            }
            catch (Exception e)
            {
                Message.printWarning(3, routine, "Error reading line " + linecount + " \"" + iline + "\"");
                Message.printWarning(3, routine, e);
                throw e;
            }
            finally
            {
                if (@in != null)
                {
                    @in.Close();
                }
            }
            return(theDiversions);
        }
Ejemplo n.º 19
0
        /// <summary>
        /// Read a well input file. </summary>
        /// <param name="filename"> name of file containing well information </param>
        /// <returns> status(always 0 since exception handling is now used) </returns>
        //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
        //ORIGINAL LINE: public static java.util.List<StateMod_Well> readStateModFile(String filename) throws Exception
        public static IList <StateMod_Well> readStateModFile(string filename)
        {
            string routine = "StateMod_Well.readStateModFile";
            IList <StateMod_Well> theWellStations = new List <StateMod_Well>();

            int[]               format_1 = new int[] { StringUtil.TYPE_STRING, StringUtil.TYPE_STRING, StringUtil.TYPE_STRING, StringUtil.TYPE_INTEGER, StringUtil.TYPE_DOUBLE, StringUtil.TYPE_SPACE, StringUtil.TYPE_STRING, StringUtil.TYPE_SPACE, StringUtil.TYPE_DOUBLE };
            int[]               format_1w = new int[] { 12, 24, 12, 8, 8, 1, 12, 1, 12 };
            int[]               format_2 = new int[] { StringUtil.TYPE_SPACE, StringUtil.TYPE_STRING, StringUtil.TYPE_INTEGER, StringUtil.TYPE_INTEGER, StringUtil.TYPE_INTEGER, StringUtil.TYPE_DOUBLE, StringUtil.TYPE_DOUBLE, StringUtil.TYPE_INTEGER, StringUtil.TYPE_INTEGER };
            int[]               format_2w = new int[] { 36, 12, 8, 8, 8, 8, 8, 8, 8 };
            int[]               format_4 = new int[] { StringUtil.TYPE_SPACE, StringUtil.TYPE_STRING, StringUtil.TYPE_DOUBLE, StringUtil.TYPE_INTEGER };
            int[]               format_4w = new int[] { 36, 12, 8, 8 };
            string              iline = null;
            string              s = null;
            IList <object>      v = new List <object>(9);
            StreamReader        @in = null;
            StateMod_Well       aWell = null;
            StateMod_ReturnFlow aReturnNode = null;
            IList <string>      effv = null;
            int nrtn, ndepl;

            Message.printStatus(1, routine, "Reading well file: " + filename);

            try
            {
                @in = new StreamReader(IOUtil.getPathUsingWorkingDir(filename));
                while (!string.ReferenceEquals((iline = @in.ReadLine()), null))
                {
                    if (iline.StartsWith("#", StringComparison.Ordinal) || iline.Trim().Length == 0)
                    {
                        continue;
                    }

                    aWell = new StateMod_Well();

                    StringUtil.fixedRead(iline, format_1, format_1w, v);
                    if (Message.isDebugOn)
                    {
                        Message.printDebug(50, routine, "iline: " + iline);
                    }
                    aWell.setID(((string)v[0]).Trim());
                    aWell.setName(((string)v[1]).Trim());
                    aWell.setCgoto(((string)v[2]).Trim());
                    aWell.setSwitch((int?)v[3]);
                    aWell.setDivcapw((double?)v[4]);
                    aWell.setCdividyw(((string)v[5]).Trim());
                    aWell.setPrimary((double?)v[6]);

                    // user data

                    iline = @in.ReadLine();
                    StringUtil.fixedRead(iline, format_2, format_2w, v);
                    if (Message.isDebugOn)
                    {
                        Message.printDebug(50, routine, "iline: " + iline);
                    }
                    aWell.setIdvcow2(((string)v[0]).Trim());
                    aWell.setIdvcomw((int?)v[1]);
                    // Don't set the number of return flow data get(2) or depletion data get(3) because
                    // those will be calculated
                    nrtn  = ((int?)v[2]).Value;
                    ndepl = ((int?)v[3]).Value;
                    aWell.setDivefcw((double?)v[4]);
                    aWell.setAreaw((double?)v[5]);
                    aWell.setIrturnw((int?)v[6]);
                    aWell.setDemsrcw((int?)v[7]);
                    if (aWell.getDivefcw() >= 0)
                    {
                        // Efficiency line won't be included - set each value to the average
                        for (int i = 0; i < 12; i++)
                        {
                            aWell.setDiveff(i, aWell.getDivefcw());
                        }
                    }
                    else
                    {
                        // 12 efficiency values
                        iline = @in.ReadLine();
                        effv  = StringUtil.breakStringList(iline, " ", StringUtil.DELIM_SKIP_BLANKS);
                        for (int i = 0; i < 12; i++)
                        {
                            aWell.setDiveff(i, (string)effv[i]);
                        }
                    }

                    // return flow data

                    if (Message.isDebugOn)
                    {
                        Message.printDebug(50, routine, "Number of return flows: " + nrtn);
                    }
                    for (int i = 0; i < nrtn; i++)
                    {
                        iline = @in.ReadLine();
                        StringUtil.fixedRead(iline, format_4, format_4w, v);
                        if (Message.isDebugOn)
                        {
                            Message.printDebug(50, routine, "Fixed read returned " + v.Count + " elements");
                        }

                        aReturnNode = new StateMod_ReturnFlow(StateMod_DataSet.COMP_WELL_STATIONS);
                        s           = ((string)v[0]).Trim();
                        if (s.Length <= 0)
                        {
                            aReturnNode.setCrtnid(s);
                            Message.printWarning(2, routine, "Return node for structure \"" + aWell.getID() + "\" is blank. ");
                        }
                        else
                        {
                            aReturnNode.setCrtnid(s);
                        }

                        aReturnNode.setPcttot(((double?)v[1]));
                        aReturnNode.setIrtndl(((int?)v[2]));
                        aWell.addReturnFlow(aReturnNode);
                    }

                    // depletion data

                    for (int i = 0; i < ndepl; i++)
                    {
                        iline = @in.ReadLine();
                        StringUtil.fixedRead(iline, format_4, format_4w, v);

                        aReturnNode = new StateMod_ReturnFlow(StateMod_DataSet.COMP_WELL_STATIONS);
                        s           = ((string)v[0]).Trim();
                        if (s.Length <= 0)
                        {
                            aReturnNode.setCrtnid(s);
                            Message.printWarning(2, routine, "Return node for structure \"" + aWell.getID() + "\" is blank. ");
                        }
                        else
                        {
                            aReturnNode.setCrtnid(s);
                        }

                        aReturnNode.setPcttot(((double?)v[1]));
                        aReturnNode.setIrtndl(((int?)v[2]));
                        aWell.addDepletion(aReturnNode);
                    }

                    theWellStations.Add(aWell);
                }
            }
            catch (Exception e)
            {
                routine   = null;
                format_1  = null;
                format_1w = null;
                format_2  = null;
                format_2w = null;
                format_4  = null;
                format_4w = null;
                s         = null;
                v         = null;
                if (@in != null)
                {
                    @in.Close();
                }
                @in         = null;
                aWell       = null;
                aReturnNode = null;
                effv        = null;
                Message.printWarning(2, routine, e);
                throw e;
            }
            routine   = null;
            format_1  = null;
            format_1w = null;
            format_2  = null;
            format_2w = null;
            format_4  = null;
            format_4w = null;
            iline     = null;
            s         = null;
            v         = null;
            if (@in != null)
            {
                @in.Close();
            }
            @in         = null;
            aWell       = null;
            aReturnNode = null;
            effv        = null;
            return(theWellStations);
        }
        /// <summary>
        /// Responds to action performed events. </summary>
        /// <param name="e"> the ActionEvent that happened. </param>
        public virtual void actionPerformed(ActionEvent e)
        {
            string routine = "StateMod_Reservoir_Return_JFrame::actionPerformed";

            string action = e.getActionCommand();

            if (action.Equals(__BUTTON_ADD_RETURN))
            {
                StateMod_ReturnFlow aReturn = new StateMod_ReturnFlow(StateMod_DataSet.COMP_RESERVOIR_RETURN);
                aReturn._isClone = true;
                StateMod_ReturnFlow last = (StateMod_ReturnFlow)__worksheet.getLastRowData();

                if (last == null)
                {
                    aReturn.setID(StateMod_Util.createNewID(__currentRes.getID()));
                    aReturn.setCgoto(__currentRes.getID());
                }
                else
                {
                    aReturn.setID(StateMod_Util.createNewID(last.getID()));
                    aReturn.setCgoto(last.getCgoto());
                }
                __worksheet.scrollToLastRow();
                __worksheet.addRow(aReturn);
                __worksheet.selectLastRow();
                __deleteReturn_JButton.setEnabled(true);
            }
            else if (action.Equals(__BUTTON_DEL_RETURN))
            {
                int row = __worksheet.getSelectedRow();
                if (row != -1)
                {
                    int x = (new ResponseJDialog(this, "Delete return", "Delete reservoir return?", ResponseJDialog.YES | ResponseJDialog.NO)).response();
                    if (x == ResponseJDialog.NO)
                    {
                        return;
                    }

                    __worksheet.cancelEditing();
                    __worksheet.deleteRow(row);
                    __deleteReturn_JButton.setEnabled(false);
                }
                else
                {
                    Message.printWarning(1, routine, "Must select desired return to delete.");
                }
            }
            else if (action.Equals(__BUTTON_CLOSE))
            {
                if (saveData())
                {
                    setVisible(false);
                    dispose();
                }
            }
            else if (action.Equals(__BUTTON_APPLY))
            {
                saveData();
            }
            else if (action.Equals(__BUTTON_CANCEL))
            {
                setVisible(false);
                dispose();
            }
            else if (e.getSource() == __help_JButton)
            {
                // TODO HELP (JTS - 2003-06-09)
            }
        }
Ejemplo n.º 21
0
        /// <summary>
        /// Writes a list of StateMod_ReturnFlow objects to a list file.  A header is
        /// printed to the top of the file, containing the commands used to generate the
        /// file.  Any strings in the body of the file that contain the field delimiter will be wrapped in "...". </summary>
        /// <param name="filename"> the name of the file to which the data will be written. </param>
        /// <param name="delimiter"> the delimiter to use for separating field values. </param>
        /// <param name="update"> whether to update an existing file, retaining the current
        /// header (true) or to create a new file with a new header. </param>
        /// <param name="data"> the list of objects to write. </param>
        /// <param name="newComments"> new comments to add to the header (e.g., command file, HydroBase version). </param>
        /// <exception cref="Exception"> if an error occurs. </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public static void writeListFile(String filename, String delimiter, boolean update, java.util.List<StateMod_ReturnFlow> data, int componentType, java.util.List<String> newComments) throws Exception
        public static void writeListFile(string filename, string delimiter, bool update, IList <StateMod_ReturnFlow> data, int componentType, IList <string> newComments)
        {
            int size = 0;

            if (data != null)
            {
                size = data.Count;
            }

            IList <string> fields = new List <string>();

            fields.Add("ID");
            fields.Add("RiverNodeID");
            if (componentType == StateMod_DataSet.COMP_WELL_STATION_DEPLETION_TABLES)
            {
                fields.Add("DepletionPercent");
            }
            else
            {
                fields.Add("ReturnPercent");
            }
            fields.Add("DelayTableID");
            fields.Add("Comment");
            int fieldCount = fields.Count;

            string[] names   = new string[fieldCount];
            string[] formats = new string[fieldCount];
            int      comp    = componentType;
            string   s       = null;

            for (int i = 0; i < fieldCount; i++)
            {
                s          = fields[i];
                names[i]   = StateMod_Util.lookupPropValue(comp, "FieldName", s);
                formats[i] = StateMod_Util.lookupPropValue(comp, "Format", s);
            }

            string oldFile = null;

            if (update)
            {
                oldFile = IOUtil.getPathUsingWorkingDir(filename);
            }

            int                 j    = 0;
            PrintWriter         @out = null;
            StateMod_ReturnFlow rf   = null;
            IList <string>      commentIndicators = new List <string>(1);

            commentIndicators.Add("#");
            IList <string> ignoredCommentIndicators = new List <string>(1);

            ignoredCommentIndicators.Add("#>");
            string[]      line   = new string[fieldCount];
            StringBuilder buffer = new StringBuilder();

            try
            {
                // Add some basic comments at the top of the file.  However, do this to a copy of the
                // incoming comments so that they are not modified in the calling code.
                IList <string> newComments2 = null;
                if (newComments == null)
                {
                    newComments2 = new List <string>();
                }
                else
                {
                    newComments2 = new List <string>(newComments);
                }
                newComments2.Insert(0, "");
                if (componentType == StateMod_DataSet.COMP_DIVERSION_STATION_DELAY_TABLES)
                {
                    newComments2.Insert(1, "StateMod diversion delay (return) file.");
                    newComments2.Insert(2, "See also the associated diversion station file.");
                }
                else if (componentType == StateMod_DataSet.COMP_WELL_STATION_DEPLETION_TABLES)
                {
                    newComments2.Insert(1, "StateMod well depletion file.");
                    newComments2.Insert(2, "See also the associated well station and return files.");
                }
                else if (componentType == StateMod_DataSet.COMP_WELL_STATION_DELAY_TABLES)
                {
                    newComments2.Insert(1, "StateMod well delay (return) file.");
                    newComments2.Insert(2, "See also the associated well station and depletion files.");
                }
                newComments2.Insert(3, "");
                @out = IOUtil.processFileHeaders(oldFile, IOUtil.getPathUsingWorkingDir(filename), newComments2, commentIndicators, ignoredCommentIndicators, 0);

                for (int i = 0; i < fieldCount; i++)
                {
                    buffer.Append("\"" + names[i] + "\"");
                    if (i < (fieldCount - 1))
                    {
                        buffer.Append(delimiter);
                    }
                }

                @out.println(buffer.ToString());

                for (int i = 0; i < size; i++)
                {
                    rf = data[i];

                    line[0] = StringUtil.formatString(rf.getID(), formats[0]).Trim();
                    line[1] = StringUtil.formatString(rf.getCrtnid(), formats[1]).Trim();
                    line[2] = StringUtil.formatString(rf.getPcttot(), formats[2]).Trim();
                    line[3] = StringUtil.formatString(rf.getIrtndl(), formats[3]).Trim();
                    line[4] = StringUtil.formatString(rf.getComment(), formats[4]).Trim();

                    buffer = new StringBuilder();
                    for (j = 0; j < fieldCount; j++)
                    {
                        if (line[j].IndexOf(delimiter, StringComparison.Ordinal) > -1)
                        {
                            line[j] = "\"" + line[j] + "\"";
                        }
                        buffer.Append(line[j]);
                        if (j < (fieldCount - 1))
                        {
                            buffer.Append(delimiter);
                        }
                    }

                    @out.println(buffer.ToString());
                }
            }
            finally
            {
                if (@out != null)
                {
                    @out.flush();
                    @out.close();
                }
            }
        }
Ejemplo n.º 22
0
        /// <summary>
        /// Read return information in and store in a list. </summary>
        /// <param name="filename"> filename containing return flow information </param>
        /// <param name="smdataCompType"> the StateMod_DataSet component type, passed to the constructor of StateMod_ReturnFlow
        /// objects. </param>
        /// <exception cref="Exception"> if an error occurs </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public static java.util.List<StateMod_ReturnFlow> readStateModFile(String filename, int smdataCompType) throws Exception
        public static IList <StateMod_ReturnFlow> readStateModFile(string filename, int smdataCompType)
        {
            string         routine = "StateMod_ReturnFlow.readStateModFile";
            string         iline   = null;
            IList <string> v;
            IList <StateMod_ReturnFlow> theReturns = new List <StateMod_ReturnFlow>();
            int linecount = 0;

            StateMod_ReturnFlow aReturn = null;
            StreamReader        @in     = null;

            Message.printStatus(2, routine, "Reading return file: " + filename);
            int size       = 0;
            int errorCount = 0;

            try
            {
                @in = new StreamReader(IOUtil.getPathUsingWorkingDir(filename));
                while (!string.ReferenceEquals((iline = @in.ReadLine()), null))
                {
                    ++linecount;
                    // check for comments
                    if (iline.StartsWith("#", StringComparison.Ordinal) || (iline.Trim().Length == 0))
                    {
                        // Special dynamic header comments written by software and blank lines - no need to keep
                        continue;
                    }
                    if (Message.isDebugOn)
                    {
                        Message.printDebug(50, routine, "line: " + iline);
                    }
                    // Break the line using whitespace, while allowing for quoted strings...
                    v    = StringUtil.breakStringList(iline, " \t", StringUtil.DELIM_ALLOW_STRINGS | StringUtil.DELIM_SKIP_BLANKS);
                    size = 0;
                    if (v != null)
                    {
                        size = v.Count;
                    }
                    if (size < 4)
                    {
                        Message.printStatus(2, routine, "Ignoring line " + linecount + " not enough data values.  Have " + size + " expecting 4+");
                        ++errorCount;
                        continue;
                    }
                    // Uncomment if testing...
                    //Message.printStatus ( 2, routine, "" + v );

                    // Allocate new plan node and set the values
                    aReturn = new StateMod_ReturnFlow(smdataCompType);
                    aReturn.setID(v[0].Trim());
                    aReturn.setName(v[0].Trim());             // Same as ID
                    aReturn.setCrtnid(v[1].Trim());
                    aReturn.setCgoto(v[1].Trim());            // Redundant
                    aReturn.setPcttot(v[2].Trim());
                    aReturn.setIrtndl(v[3].Trim());
                    if (v.Count > 4)
                    {
                        aReturn.setComment(v[4].Trim());
                    }

                    // Set the return to not dirty because it was just initialized...

                    aReturn.setDirty(false);

                    // Add the return to the list of returns
                    theReturns.Add(aReturn);
                }
            }
            catch (Exception e)
            {
                Message.printWarning(3, routine, "Error reading line " + linecount + " \"" + iline + "\" uniquetempvar.");
                Message.printWarning(3, routine, e);
                throw e;
            }
            finally
            {
                if (@in != null)
                {
                    @in.Close();
                }
            }
            if (errorCount > 0)
            {
                throw new Exception("There were " + errorCount + " errors processing the data - refer to log file.");
            }
            return(theReturns);
        }
Ejemplo n.º 23
0
        /// <summary>
        /// Write return flow information to a StateMod file.  History header information
        /// is also maintained by calling this routine. </summary>
        /// <param name="instrfile"> input file from which previous history should be taken </param>
        /// <param name="outstrfile"> output file to which to write </param>
        /// <param name="stationType"> the station type, for the file header (e.g., "Plan", "Reservoir"). </param>
        /// <param name="theReturns"> list of plans to write. </param>
        /// <param name="newComments"> addition comments which should be included in history </param>
        /// <exception cref="Exception"> if an error occurs. </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public static void writeStateModFile(String instrfile, String outstrfile, String stationType, java.util.List<StateMod_ReturnFlow> theReturns, java.util.List<String> newComments) throws Exception
        public static void writeStateModFile(string instrfile, string outstrfile, string stationType, IList <StateMod_ReturnFlow> theReturns, IList <string> newComments)
        {
            string         routine           = "StateMod_ReturnFlow.writeStateModFile";
            IList <string> commentIndicators = new List <string>(1);

            commentIndicators.Add("#");
            IList <string> ignoredCommentIndicators = new List <string>(1);

            ignoredCommentIndicators.Add("#>");
            PrintWriter @out = null;
            string      comment;

            try
            {
                @out = IOUtil.processFileHeaders(IOUtil.getPathUsingWorkingDir(instrfile), IOUtil.getPathUsingWorkingDir(outstrfile), newComments, commentIndicators, ignoredCommentIndicators, 0);

                int    i;
                string iline;
                string cmnt = "#>";
                // This format follows historical conventions found in example files, limited by StateMod ID lengths
                string formatLine1     = "%-12.12s %-12.12s %8.2f %-12.12s"; // Comment only written if not blank
                StateMod_ReturnFlow rf = null;
                IList <object>      v  = new List <object>(11);              // Reuse for all output lines.

                @out.println(cmnt);
                @out.println(cmnt + "*************************************************");
                @out.println(cmnt + "  StateMod " + stationType + " Return Flows");
                @out.println(cmnt);
                @out.println(cmnt + "  Free format; however historical format based on StateMod");
                @out.println(cmnt + "               identifier string lengths is used for consistency.");
                @out.println(cmnt);
                @out.println(cmnt + "  ID                   :  " + stationType + " ID");
                @out.println(cmnt + "  River Node     crtnid:  River node identifier receiving return flow");
                @out.println(cmnt + "  Ret %         pcttot*:  Percent of return flow the the river node");
                @out.println(cmnt + "  Table ID      irtndl*:  Delay (return flow) table identifier for return");
                @out.println(cmnt + "  Comment              :  Optional (e.g., return type, name)");
                @out.println(cmnt + "                          Double quote to faciliate free-format processing.");
                @out.println(cmnt);
                @out.println(cmnt + " ID         River Node    Ret %    Table ID       Comment");
                @out.println(cmnt + "---------exb----------exb------exb----------exb-------------------------------e");
                @out.println(cmnt + "EndHeader");

                int num = 0;
                if (theReturns != null)
                {
                    num = theReturns.Count;
                }
                for (i = 0; i < num; i++)
                {
                    rf = theReturns[i];
                    if (rf == null)
                    {
                        continue;
                    }

                    // line 1
                    v.Clear();
                    v.Add(rf.getID());
                    v.Add(rf.getCrtnid());
                    v.Add(rf.getPcttot());
                    v.Add("" + rf.getIrtndl());             // Format as string
                    comment = rf.getComment().Trim();
                    if (comment.Length > 0)
                    {
                        comment = " \"" + comment + "\"";
                    }
                    iline = StringUtil.formatString(v, formatLine1) + comment;
                    @out.println(iline);
                }
            }
            catch (Exception e)
            {
                Message.printWarning(3, routine, e);
                throw e;
            }
            finally
            {
                if (@out != null)
                {
                    @out.flush();
                    @out.close();
                }
            }
        }
Ejemplo n.º 24
0
        /// <summary>
        /// Compares this object to another StateMod_ReturnFlow object based on the sorted
        /// order from the StateMod_ReturnFlow variables, and then by crtnid, pcttot, and irtndl, in that order. </summary>
        /// <param name="data"> the object to compare against. </param>
        /// <returns> 0 if they are the same, 1 if this object is greater than the other object, or -1 if it is less. </returns>
        public virtual int CompareTo(StateMod_Data data)
        {
            int res = base.CompareTo(data);

            if (res != 0)
            {
                return(res);
            }

            StateMod_ReturnFlow rf = (StateMod_ReturnFlow)data;

            int    index   = -1;
            string crtnid1 = __crtnid;

            index = crtnid1.IndexOf(" - ", StringComparison.Ordinal);
            if (index > 0)
            {
                crtnid1 = crtnid1.Substring(0, index).Trim();
            }

            string crtnid2 = rf.__crtnid;

            index = crtnid2.IndexOf(" - ", StringComparison.Ordinal);
            if (index > 0)
            {
                crtnid2 = crtnid2.Substring(0, index).Trim();
            }

            res = crtnid1.CompareTo(crtnid2);
            if (res != 0)
            {
                return(res);
            }

            if (__pcttot < rf.__pcttot)
            {
                return(-1);
            }
            else if (__pcttot > rf.__pcttot)
            {
                return(1);
            }

            if (__irtndl < rf.__irtndl)
            {
                return(-1);
            }
            else if (__irtndl > rf.__irtndl)
            {
                return(1);
            }

            // sort false before true
            if (__isMonthlyData == false)
            {
                if (rf.__isMonthlyData == true)
                {
                    return(-1);
                }
                return(0);
            }
            else
            {
                if (rf.__isMonthlyData == true)
                {
                    return(0);
                }
                return(1);
            }
        }
        /// <summary>
        /// Checks the data to make sure that all the data are valid. </summary>
        /// <returns> 0 if the data are valid, 1 if errors exist and -1 if non-fatal errors exist. </returns>
        private int checkInput()
        {
            string routine = "StateMod_Reservoir_Return_JFrame.checkInput";
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @SuppressWarnings("unchecked") java.util.List<StateMod_ReturnFlow> v = (java.util.List<StateMod_ReturnFlow>)__worksheet.getAllData();
            IList <StateMod_ReturnFlow> v = (IList <StateMod_ReturnFlow>)__worksheet.getAllData();

            int size = v.Count;
            StateMod_ReturnFlow aReturn = null;
            string warning = "";
            string id;
            string riverNodeID;
            //double percent;
            //String tableID;
            int fatalCount = 0;

            //String comment;
            for (int i = 0; i < size; i++)
            {
                aReturn = v[i];

                id          = aReturn.getID();
                riverNodeID = aReturn.getCrtnid();
                //percent = aReturn.getPcttot();
                //tableID = "" + aReturn.getIrtndl();
                //comment = aReturn.getComment();

                // TODO SAM 2011-01-02 Need to implement validators
                if (id.Length > 12)
                {
                    warning += "\nReservoir ID (" + id + ") is longer than 12 characters.";
                    fatalCount++;
                }

                if (id.IndexOf(" ", StringComparison.Ordinal) > -1 || id.IndexOf("-", StringComparison.Ordinal) > -1)
                {
                    warning += "\nReservoir ID (" + id + ") cannot contain spaces or dashes.";
                    fatalCount++;
                }

                if (riverNodeID.Length > 12)
                {
                    warning += "River node ID (" + riverNodeID + ") is longer than 12 characters.";
                }
            }

            if (warning.Length > 0)
            {
                warning += "\nCorrect or Cancel.";
                Message.printWarning(1, routine, warning, this);
                if (fatalCount > 0)
                {
                    // Fatal errors...
                    Message.printStatus(1, routine, "Returning 1 from checkInput()");
                    return(1);
                }
                else
                {
                    // Nonfatal errors...
                    Message.printStatus(1, routine, "Returning -1 from checkInput()");
                    return(-1);
                }
            }
            else
            {
                // No errors...
                Message.printStatus(2, routine, "Returning 0 from checkInput()");
                return(0);
            }
        }
        /// <summary>
        /// Checks the data to make sure that all the data are valid. </summary>
        /// <returns> 0 if the data are valid, 1 if errors exist and -1 if non-fatal errors exist. </returns>
        private int checkInput()
        {
            string routine = "StateMod_Plan_Return_JFrame.checkInput";

            System.Collections.IList v = __worksheet.getAllData();

            int size = v.Count;
            StateMod_ReturnFlow aReturn = null;
            string warning = "";
            string id;
            string riverNodeID;
            double percent;
            string tableID;
            int    fatalCount = 0;
            string comment;

            for (int i = 0; i < size; i++)
            {
                aReturn = (StateMod_ReturnFlow)(v[i]);

                id          = aReturn.getID();
                riverNodeID = aReturn.getCrtnid();
                percent     = aReturn.getPcttot();
                tableID     = "" + aReturn.getIrtndl();
                comment     = aReturn.getComment();

                // TODO SAM 2011-01-02 Need to implement validators
                if (id.Length > 12)
                {
                    warning += "\nPlan ID (" + id + ") is longer than 12 characters.";
                    fatalCount++;
                }

                if (id.IndexOf(" ", StringComparison.Ordinal) > -1 || id.IndexOf("-", StringComparison.Ordinal) > -1)
                {
                    warning += "\nPlan ID (" + id + ") cannot contain spaces or dashes.";
                    fatalCount++;
                }

                if (riverNodeID.Length > 12)
                {
                    warning += "River node ID (" + riverNodeID + ") is longer than 12 characters.";
                }
            }

            if (warning.Length > 0)
            {
                warning += "\nCorrect or Cancel.";
                Message.printWarning(1, routine, warning, this);
                if (fatalCount > 0)
                {
                    // Fatal errors...
                    Message.printStatus(1, routine, "Returning 1 from checkInput()");
                    return(1);
                }
                else
                {
                    // Nonfatal errors...
                    Message.printStatus(1, routine, "Returning -1 from checkInput()");
                    return(-1);
                }
            }
            else
            {
                // No errors...
                Message.printStatus(2, routine, "Returning 0 from checkInput()");
                return(0);
            }
        }