/// <summary> /// Perform the query. Currently only diversion stations are supported. /// </summary> private void doQuery() { string routine = "StateMod_QueryTool_JFrame.doQuery", message; InputFilter_JPanel ifp = __input_filter_diversion_JPanel; InputFilter filter = null; int size; // Size of data Vector int i; // Loop for data items. DataSetComponent comp = null; string where, @operator, input; int where_length = 0; // Length of "where", to optimize code. bool do_int, do_double, do_string; string input_string; // Data parameters to check, as int input_int; // transferred from the data objects. double input_double; bool do_ID, do_Name, do_RiverNodeID, do_OnOff, do_Capacity, do_ReplaceResOption, do_DailyID, do_UserName, do_DemandType, do_EffAnnual, do_Area, do_UseType, do_DemandSource; bool[] matches = null; // Indicates if a data item matches all // the filter criteria. bool item_matches; // Indicates whether the itme matches a // single filter criteria. bool[] @checked = null; // Indicates whether a data item has // already been checked for a criteria. // If checked and false, then a "true" // should not reset the false. int nfg = 0; // Number of filter groups. do_int = false; // Whether the data item is an integer. do_double = false; // Whether the data item is a double. do_string = false; // Whether the data item is a string. StateMod_Diversion dds = null; __status_JTextField.setText(__Wait); JGUIUtil.setWaitCursor(this, true); if (ifp is StateMod_Diversion_InputFilter_JPanel) { input_int = StateMod_Util.MISSING_INT; input_double = StateMod_Util.MISSING_DOUBLE; input_string = StateMod_Util.MISSING_STRING; comp = __dataset.getComponentForComponentType(StateMod_DataSet.COMP_DIVERSION_STATIONS); //JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @SuppressWarnings("unchecked") java.util.List<StateMod_Diversion> dds_Vector = (java.util.List<StateMod_Diversion>)comp.getData(); IList <StateMod_Diversion> dds_Vector = (IList <StateMod_Diversion>)comp.getData(); size = 0; if (dds_Vector != null) { size = dds_Vector.Count; } // REVISIT SAM 2004-10-27 Remove when debugging is complete //Message.printStatus ( 2, routine, //"Searching " + size + " diversion stations." ); // Initialize the arrays indicating if data objects have been // checked and whether they matched the filter(s)... if (size > 0) { matches = new bool[size]; @checked = new bool[size]; } for (i = 0; i < size; i++) { matches[i] = false; @checked[i] = false; } // Loop through the where clauses... nfg = ifp.getNumFilterGroups(); for (int ifg = 0; ifg < nfg; ifg++) { // Get the filter information... filter = ifp.getInputFilter(ifg); where = filter.getWhereInternal(); where_length = where.Length; @operator = ifp.getOperator(ifg); input = filter.getInput(false); // REVISIT SAM 2004-10-27 Remove when debugging is // complete //Message.printStatus ( 2, routine, //"where=" + where + " operator=" + operator + //" input=" + input ); // Initialize flags to indicate what data will be // checked... do_int = false; do_double = false; do_string = false; do_ID = false; do_Name = false; do_RiverNodeID = false; do_OnOff = false; do_Capacity = false; do_ReplaceResOption = false; do_DailyID = false; do_UserName = false; do_DemandType = false; do_EffAnnual = false; do_Area = false; do_UseType = false; do_DemandSource = false; // The following checks on "where" need to match the // input filter internal where labels assigned in // StateMod_Diversion_InputFilter_JPanel. // List in the order of the StateMod documentation... if (where.Equals("ID", StringComparison.OrdinalIgnoreCase)) { do_string = true; do_ID = true; } else if (where.Equals("Name", StringComparison.OrdinalIgnoreCase)) { do_string = true; do_Name = true; } else if (where.Equals("RiverNodeID", StringComparison.OrdinalIgnoreCase)) { do_string = true; do_RiverNodeID = true; } else if (where.Equals("OnOff", StringComparison.OrdinalIgnoreCase) && StringUtil.isInteger(input)) { do_int = true; do_OnOff = true; } else if (where.Equals("Capacity", StringComparison.OrdinalIgnoreCase) && StringUtil.isDouble(input)) { do_double = true; do_Capacity = true; } else if (where.Equals("ReplaceResOption", StringComparison.OrdinalIgnoreCase) && StringUtil.isInteger(input)) { do_int = true; do_ReplaceResOption = true; } else if (where.Equals("DailyID", StringComparison.OrdinalIgnoreCase)) { do_string = true; do_DailyID = true; } else if (where.Equals("UserName", StringComparison.OrdinalIgnoreCase)) { do_string = true; do_UserName = true; } else if (where.Equals("DemandType", StringComparison.OrdinalIgnoreCase)) { do_int = true; do_DemandType = true; } else if (where.Equals("EffAnnual", StringComparison.OrdinalIgnoreCase) && StringUtil.isDouble(input)) { do_double = true; do_EffAnnual = true; } else if (where.Equals("Area", StringComparison.OrdinalIgnoreCase) && StringUtil.isDouble(input)) { do_double = true; do_Area = true; } else if (where.Equals("UseType", StringComparison.OrdinalIgnoreCase) && StringUtil.isInteger(input)) { do_int = true; do_UseType = true; } else if (where.Equals("DemandSource", StringComparison.OrdinalIgnoreCase) && StringUtil.isInteger(input)) { do_int = true; do_DemandSource = true; } else if (where_length == 0) { // WIll match anything. } else { // Unrecognized where... continue; } // REVISIT SAM 2004-10-27 Remove when debugging is // complete /* * Message.printStatus ( 2, routine, * "do_string=" + do_string + " do_int=" + do_int + * "do_double=" + do_double + * " " + do_ID + * " " + do_Name + * " " + do_RiverNodeID + * " " + do_OnOff + * " " + do_Capacity + * " " + do_ReplaceResOption + * " " + do_DailyID + * " " + do_UserName + * " " + do_DemandType + * " " + do_EffAnnual + * " " + do_Area + * " " + do_UseType + * " " + do_DemandSource ); */ for (i = 0; i < size; i++) { dds = (StateMod_Diversion)dds_Vector[i]; // Get the specific data to compare... if (do_ID) { input_string = dds.getID(); } else if (do_Name) { input_string = dds.getName(); } else if (do_RiverNodeID) { input_string = dds.getCgoto(); } else if (do_OnOff) { input_int = dds.getSwitch(); } else if (do_Capacity) { input_double = dds.getDivcap(); } else if (do_ReplaceResOption) { input_int = dds.getIreptype(); } else if (do_DailyID) { input_string = dds.getCdividy(); } else if (do_UserName) { input_string = dds.getUsername(); } else if (do_DemandType) { input_int = dds.getIdvcom(); } else if (do_EffAnnual) { input_double = dds.getDivefc(); } else if (do_Area) { input_double = dds.getArea(); } else if (do_UseType) { input_int = dds.getIrturn(); } else if (do_DemandSource) { input_int = dds.getDemsrc(); } else { // Unrecognized... continue; } // Compare the data with the input filter... item_matches = false; if (do_string) { item_matches = filter.matches(input_string, @operator, true); } else if (do_int) { item_matches = filter.matches(input_int, @operator); } else if (do_double) { item_matches = filter.matches(input_double, @operator); } if (where_length == 0) { // Always consider a match... item_matches = true; } if (item_matches && (!@checked[i] || (@checked[i] && matches[i]))) { // So far the item matches all // filters... matches[i] = true; } else if (@checked[i] && !item_matches) { // Does not match this filter to reset // result to false... matches[i] = false; } // Indicate that we have checked the item // against at least one filter... @checked[i] = true; } } // Get a count so the Vector can be sized appropriately (this // should be fast)... int match_count = 0; for (i = 0; i < size; i++) { if (matches[i]) { ++match_count; } } // Loop through and set up the matches_Vector... __matches_Vector = null; if (match_count > 0) { __matches_Vector = new List <StateMod_Diversion> (match_count); for (i = 0; i < size; i++) { if (matches[i]) { // The diversion station matches so add // to the list... __matches_Vector.Add(dds_Vector[i]); } } } message = "Matched " + match_count + " diversion stations (from original " + size + ")."; Message.printStatus(2, routine, message); __message_JTextField.setText(message); __status_JTextField.setText(__Ready); JGUIUtil.setWaitCursor(this, false); } if (__matches_Vector == null) { __display_JButton.setEnabled(false); } else { __display_JButton.setEnabled(true); } }