/// <summary> /// Used internally to build a SQL WHERE criteria from the AFindCriteria HashTable. /// /// </summary> /// <param name="ACriteriaData">HashTable containing non-empty Partner Find parameters</param> /// <param name="AParametersArray">An array holding 1..n instantiated OdbcParameters /// (including parameter Value)</param> /// <returns>SQL WHERE criteria /// </returns> private String BuildCustomWhereCriteria(DataTable ACriteriaData, out OdbcParameter[] AParametersArray) { String CustomWhereCriteria = ""; DataTable CriteriaDataTable; DataRow CriteriaRow; ArrayList InternalParameters; OdbcParameter miParam; CriteriaDataTable = ACriteriaData; CriteriaRow = CriteriaDataTable.Rows[0]; InternalParameters = new ArrayList(); if (CriteriaRow["Addr1"].ToString().Length > 0) { new TDynamicSearchHelper(PLocationTable.TableId, PLocationTable.ColumnLocalityId, CriteriaRow, "Addr1", "Addr1Match", ref CustomWhereCriteria, ref InternalParameters); } if (CriteriaRow["Street2"].ToString().Length > 0) { new TDynamicSearchHelper(PLocationTable.TableId, PLocationTable.ColumnStreetNameId, CriteriaRow, "Street2", "Street2Match", ref CustomWhereCriteria, ref InternalParameters); } if (CriteriaRow["Addr3"].ToString().Length > 0) { new TDynamicSearchHelper(PLocationTable.TableId, PLocationTable.ColumnAddress3Id, CriteriaRow, "Addr3", "Addr3Match", ref CustomWhereCriteria, ref InternalParameters); } if (CriteriaRow["City"].ToString().Length > 0) { new TDynamicSearchHelper(PLocationTable.TableId, PLocationTable.ColumnCityId, CriteriaRow, "City", "CityMatch", ref CustomWhereCriteria, ref InternalParameters); } if (CriteriaRow["PostCode"].ToString().Length > 0) { new TDynamicSearchHelper(PLocationTable.TableId, PLocationTable.ColumnPostalCodeId, CriteriaRow, "PostCode", "PostCodeMatch", ref CustomWhereCriteria, ref InternalParameters); } if (CriteriaRow["County"].ToString().Length > 0) { new TDynamicSearchHelper(PLocationTable.TableId, PLocationTable.ColumnCountyId, CriteriaRow, "County", "CountyMatch", ref CustomWhereCriteria, ref InternalParameters); } if (CriteriaRow["Country"].ToString().Length > 0) { new TDynamicSearchHelper(PLocationTable.TableId, PLocationTable.ColumnCountryCodeId, CriteriaRow, "Country", "CountryMatch", ref CustomWhereCriteria, ref InternalParameters); } if (CriteriaRow["LocationKey"].ToString().Length > 0) { // DISREGARD ALL OTHER SEARCH CRITERIA!!! CustomWhereCriteria = ""; InternalParameters = new ArrayList(); CustomWhereCriteria = String.Format("{0} AND PUB.{1}.{2} = ?", CustomWhereCriteria, PLocationTable.GetTableDBName(), PLocationTable.GetLocationKeyDBName()); miParam = new OdbcParameter("", OdbcType.Decimal, 10); miParam.Value = (object)CriteriaRow["LocationKey"]; InternalParameters = new ArrayList(); InternalParameters.Add(miParam); } // TLogging.LogAtLevel(7, "CustomWhereCriteria: " + CustomWhereCriteria); /* Convert ArrayList to a array of ODBCParameters * seem to need to declare a type first */ AParametersArray = ((OdbcParameter[])(InternalParameters.ToArray(typeof(OdbcParameter)))); InternalParameters = null; // ensure this is GC'd return(CustomWhereCriteria); }
/// <summary> /// contructor /// </summary> /// <param name="ACriteriaData"></param> public TPartnerLocationFindUIConnector(DataTable ACriteriaData) : base() { Hashtable ColumnNameMapping; String CustomWhereCriteria; ArrayList InternalParameters; OdbcParameter miParam; DataRow CriteriaRow; FPagedDataSetObject = new TPagedDataSet(new PartnerFindTDSSearchResultTable()); ColumnNameMapping = null; // get the first and only row CriteriaRow = ACriteriaData.Rows[0]; // used to help with strong typing of columns InternalParameters = new ArrayList(); CustomWhereCriteria = ""; if (CriteriaRow["Addr1"].ToString().Length > 0) { new TDynamicSearchHelper(PLocationTable.TableId, PLocationTable.ColumnLocalityId, CriteriaRow, "Addr1", "Addr1Match", ref CustomWhereCriteria, ref InternalParameters); } if (CriteriaRow["Street2"].ToString().Length > 0) { new TDynamicSearchHelper(PLocationTable.TableId, PLocationTable.ColumnStreetNameId, CriteriaRow, "Street2", "Street2Match", ref CustomWhereCriteria, ref InternalParameters); } if (CriteriaRow["Addr3"].ToString().Length > 0) { new TDynamicSearchHelper(PLocationTable.TableId, PLocationTable.ColumnAddress3Id, CriteriaRow, "Addr3", "Addr3Match", ref CustomWhereCriteria, ref InternalParameters); } if (CriteriaRow["City"].ToString().Length > 0) { new TDynamicSearchHelper(PLocationTable.TableId, PLocationTable.ColumnCityId, CriteriaRow, "City", "CityMatch", ref CustomWhereCriteria, ref InternalParameters); } if (CriteriaRow["PostCode"].ToString().Length > 0) { new TDynamicSearchHelper(PLocationTable.TableId, PLocationTable.ColumnPostalCodeId, CriteriaRow, "PostCode", "PostCodeMatch", ref CustomWhereCriteria, ref InternalParameters); } if (CriteriaRow["County"].ToString().Length > 0) { new TDynamicSearchHelper(PLocationTable.TableId, PLocationTable.ColumnCountyId, CriteriaRow, "County", "CountyMatch", ref CustomWhereCriteria, ref InternalParameters); } if (CriteriaRow["Country"].ToString().Length > 0) { new TDynamicSearchHelper(PLocationTable.TableId, PLocationTable.ColumnCountryCodeId, CriteriaRow, "Country", "CountryMatch", ref CustomWhereCriteria, ref InternalParameters); } if (CriteriaRow["LocationKey"].ToString().Length > 0) { // DISREGARD ALL OTHER SEARCH CRITERIA!!! CustomWhereCriteria = ""; InternalParameters = new ArrayList(); CustomWhereCriteria = String.Format("{0} AND PUB.{1}.{2} = ?", CustomWhereCriteria, PLocationTable.GetTableDBName(), PLocationTable.GetLocationKeyDBName()); miParam = new OdbcParameter("", OdbcType.Decimal, 10); miParam.Value = (object)CriteriaRow["LocationKey"]; InternalParameters = new ArrayList(); InternalParameters.Add(miParam); } Console.WriteLine("WHERE CLAUSE: " + CustomWhereCriteria); FPagedDataSetObject.FindParameters = new TPagedDataSet.TAsyncFindParameters( " p_city_c, p_postal_code_c, p_locality_c, p_street_name_c, p_address_3_c, p_county_c, p_country_code_c, p_location_key_i, p_site_key_n ", "PUB_p_location ", " p_location_key_i<>-1 " + CustomWhereCriteria + ' ', "p_city_c ", ColumnNameMapping, ((OdbcParameter[])(InternalParameters.ToArray(typeof(OdbcParameter))))); // fields // table // where // order by // both empty for now string session = TSession.GetSessionID(); // // Start the Find Thread // try { ThreadStart myThreadStart = delegate { FPagedDataSetObject.ExecuteQuery(session); }; FFindThread = new Thread(myThreadStart); FFindThread.Name = "PartnerLocationFind" + Guid.NewGuid().ToString(); FFindThread.Start(); } catch (Exception) { throw; } }