Ejemplo n.º 1
0
        private void SearchBtn_Click(object sender, RoutedEventArgs e)
        {
            var    model = new NoteViewModel();
            string query = "SELECT Id FROM Notes WHERE ";

            for (int i = 0; i < 11; i++)
            {
                if (search_checks[i].IsChecked == true)
                {
                    query += search_queries[i][search_combos[i].SelectedIndex];
                    query += " AND ";
                }
            }
            if (TextCheck.IsChecked == true)
            {
                query += $"(WeatherNote LIKE '%{TextTxt.Text}%' OR WaterNote LIKE '%{TextTxt.Text}%' OR NoteString LIKE '%{TextTxt.Text}%') AND ";
            }
            if (LocationCheck.IsChecked == true)
            {
                query += $"Location_id = {(int)LocationTb.Tag} AND ";
            }
            if (RainfallCheck.IsChecked == true)
            {
                query += "Rainfall=1 AND ";
            }
            if (SpecyCheck.IsChecked == true)
            {
                if (TrophySpecyCheck.IsChecked == true)
                {
                    query += $"(Id IN (SELECT Note_id FROM Trophies WHERE Specy_id={((Specy)SpecyCombo.SelectedItem).Id})) AND ))";
                }
                else
                {
                    query += $"(Id IN (SELECT Note_id FROM Catches WHERE Specy_id={((Specy)SpecyCombo.SelectedItem).Id}) OR "
                             + $"Id IN (SELECT Note_id FROM Trophies WHERE Specy_id={((Specy)SpecyCombo.SelectedItem).Id})) AND ";
                }
            }
            if (TackleCheck.IsChecked == true)
            {
                if (string.IsNullOrEmpty(TackleParamTxt.Text))
                {
                    query += $"Id IN (SELECT Note_id FROM NoteTackles WHERE Tackle_id={(int)TackleTb.Tag}) AND ";
                }
                else
                {
                    query += $"Id IN (SELECT Note_id FROM NoteTackles WHERE Tackle_id={(int)TackleTb.Tag} AND Parameter LIKE '%{TackleParamTxt.Text}%') AND ";
                }
            }
            if (CatchCountCheck.IsChecked == true)
            {
                query += $"CatchCount BETWEEN {(int)(FromCatchCountUpDown.Value ?? 0)} AND {(int)(ToCatchCountUpDown.Value ?? 0)} AND ";
            }

            try
            {
                query  = query.Substring(0, query.LastIndexOf(" AND"));
                query += " ORDER BY date(Date) ASC";

                NoteListBox2.DataContext = model;
                //NoteListBox2.Items.Clear();
                model.SQL(query);
                //model.Refresh();

                //notes.ForEach(v => NoteListBox2.Items.Add(model.Notes.FirstOrDefault(n => n.Id == v.Id)));
            }
            catch { MessageBox.Show("Ошибка в параметрах поиска!"); }
            if (NoteListBox2.Items.Count > 0)
            {
                SearchExcelBtn.IsEnabled = true;
            }
            else
            {
                SearchExcelBtn.IsEnabled = false;
            }
        }