public void SelectSearchedValue(a7SearchedValue selected) { SelectedSearchedValue = selected; OnPropertyChanged("SelectedSearchedValue"); }
private void SearchValues(object values) { string sRet = ""; values = values.ToString().Replace("'", ""); string[] asValues; if (string.IsNullOrEmpty(Seperator)) { asValues = new string[] { values.ToString() } } ; else { string seperator; if (Seperator.ToLower() == "[enter]") { seperator = "\r\n"; } else { seperator = Seperator; } asValues = values.ToString().Split(new string[] { seperator }, StringSplitOptions.RemoveEmptyEntries); } Dictionary <string, int> dictValueFoundCount = new Dictionary <string, int>(); SearchedValues = new Dictionary <string, a7SearchedValue>(); int tablesAnalyzed = 0; int selectedTablesCount = 0; foreach (KeyValuePair <string, a7TableSelection> kv in DictTables) { if (kv.Value.IsSelected) { selectedTablesCount++; } } foreach (KeyValuePair <string, List <a7TableColumn> > kv in dictTable_ColumnNames) { if (!DictTables[kv.Key].IsSelected) { continue; } int valuesAnalyzed = 0; foreach (string value in asValues) { a7SearchedValue searchedValue; if (SearchedValues.ContainsKey(value)) { searchedValue = SearchedValues[value]; } else { searchedValue = new a7SearchedValue(value); SearchedValues[value] = searchedValue; } string sql = "SELECT * FROM " + kv.Key + " WHERE "; bool stringColumnFound = false; if (AndSeperator == "") { bool firstWhere = true; foreach (a7TableColumn tc in kv.Value) { if (tc.IsStringColumn) { stringColumnFound = true; if (firstWhere) { firstWhere = false; } else { sql += " OR "; } sql += tc.ColumnName + " LIKE ('%" + value.Trim() + "%')"; } } } else { string[] andValues = value.Split(new string[] { AndSeperator }, StringSplitOptions.RemoveEmptyEntries); bool firstAnd = true; foreach (string singleAndValue in andValues) { if (firstAnd) { firstAnd = false; } else { sql += " AND "; } sql += " ( "; bool firstWhere = true; foreach (a7TableColumn tc in kv.Value) { if (tc.IsStringColumn) { stringColumnFound = true; if (firstWhere) { firstWhere = false; } else { sql += " OR "; } sql += "[" + tc.ColumnName + "]" + " LIKE ('%" + singleAndValue.Trim() + "%')"; } } sql += " ) "; } } if (abortSearch) { return; } if (!stringColumnFound) { continue; } SqlCommand comm = new SqlCommand(sql, ExportConfiguration.SqlConnection); SqlDataAdapter adapter = new SqlDataAdapter(comm); try { //TODO - sypie sie brzydkie to jest :) SqlCommandBuilder sqlBuilder = new SqlCommandBuilder(adapter); adapter.UpdateCommand = sqlBuilder.GetUpdateCommand(); adapter.InsertCommand = sqlBuilder.GetInsertCommand(); adapter.DeleteCommand = sqlBuilder.GetDeleteCommand(); } catch { } DataTable dt = new DataTable(kv.Key); adapter.Fill(dt); searchedValue.AddDataTable(dt, adapter); if (!dictValueFoundCount.ContainsKey(value)) { dictValueFoundCount[value] = int.Parse(dt.Rows.Count.ToString()); } else { dictValueFoundCount[value] += int.Parse(dt.Rows.Count.ToString()); } valuesAnalyzed++; OnActualizedWork(kv.Key, value, tablesAnalyzed, selectedTablesCount, valuesAnalyzed, asValues.Length); } tablesAnalyzed++; } foreach (KeyValuePair <string, int> kv in dictValueFoundCount) { if (kv.Value == 0) { sRet += "'" + kv.Key + "',"; } } if (FinishedSearch != null) { FinishedSearch(this, new DBSearchFinishedEventArgs(sRet)); } OnPropertyChanged("SearchedValues"); }