Example #1
0
 public void SelectSearchedValue(a7SearchedValue selected)
 {
     SelectedSearchedValue = selected;
     OnPropertyChanged("SelectedSearchedValue");
 }
Example #2
0
        private void SearchValues(object values)
        {
            IsSearching = true;
            var 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);
            }

            var dictValueFoundCount = new Dictionary <string, int>();

            SearchedValues = new Dictionary <string, a7SearchedValue>();
            var tablesAnalyzed      = 0;
            var selectedTablesCount = 0;

            foreach (var kv in DictTables)
            {
                if (kv.Value.IsSelected)
                {
                    selectedTablesCount++;
                }
            }
            foreach (var kv in dictTable_ColumnNames)
            {
                if (!DictTables[kv.Key].IsSelected)
                {
                    continue;
                }
                var valuesAnalyzed = 0;
                foreach (var value in asValues)
                {
                    a7SearchedValue searchedValue;
                    if (SearchedValues.ContainsKey(value))
                    {
                        searchedValue = SearchedValues[value];
                    }
                    else
                    {
                        searchedValue         = new a7SearchedValue(value);
                        SearchedValues[value] = searchedValue;
                    }
                    var sql = "SELECT * FROM " + kv.Key + " WHERE ";
                    var stringColumnFound = false;
                    if (AndSeperator == "")
                    {
                        var firstWhere = true;
                        foreach (var tc in kv.Value)
                        {
                            if (tc.IsStringColumn)
                            {
                                stringColumnFound = true;
                                if (firstWhere)
                                {
                                    firstWhere = false;
                                }
                                else
                                {
                                    sql += " OR ";
                                }
                                sql += tc.ColumnName + " LIKE ('%" + value.Trim() + "%')";
                            }
                        }
                    }
                    else
                    {
                        var andValues = value.Split(new string[] { AndSeperator }, StringSplitOptions.RemoveEmptyEntries);
                        var firstAnd  = true;
                        foreach (var singleAndValue in andValues)
                        {
                            if (firstAnd)
                            {
                                firstAnd = false;
                            }
                            else
                            {
                                sql += " AND ";
                            }
                            sql += " ( ";
                            var firstWhere = true;
                            foreach (var 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;
                    }
                    var comm    = new SqlCommand(sql, SqlConnection);
                    var adapter = new SqlDataAdapter(comm);
                    try
                    { //TODO - sypie sie brzydkie to jest :)
                        var sqlBuilder = new SqlCommandBuilder(adapter);
                        adapter.UpdateCommand = sqlBuilder.GetUpdateCommand();
                        adapter.InsertCommand = sqlBuilder.GetInsertCommand();
                        adapter.DeleteCommand = sqlBuilder.GetDeleteCommand();
                    }
                    catch
                    {
                    }
                    var 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 (var kv in dictValueFoundCount)
            {
                if (kv.Value == 0)
                {
                    sRet += "'" + kv.Key + "',";
                }
            }
            IsResultsView = true;
            IsSearching   = false;
            ActualizedWork?.Invoke(this, null);
            OnPropertyChanged(nameof(SearchedValues));
        }