using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Text.RegularExpressions; namespace SHNDecrypt { public partial class searchFind : Form { frmMain frmParent; Dictionary originIndex = new Dictionary(); //this, other public searchFind(frmMain Handle) { frmParent = Handle; InitializeComponent(); dataGrid.DoubleBuffered(true); } protected override CreateParams CreateParams { get { CreateParams cp = base.CreateParams; cp.ExStyle |= 0x02000000; // Turn on WS_EX_COMPOSITED return cp; } } private void loadSettings() { if (frmParent.file == null) return; cmbIn.Items.Clear(); originIndex.Clear(); radioContains.Checked = true; for (int i = 0; i < frmParent.file.table.Columns.Count; i++) { DataColumn lol = frmParent.file.table.Columns[i]; cmbIn.Items.Add(i.ToString("00") + ": " + lol.ToString()); } cmbIn.SelectedIndex = 0; bindingSource1.DataSource = frmParent.file.table.DefaultView; dataGrid.DataSource = bindingSource1; frmParent.dataGrid.DataSource = frmParent.file.table.Copy(); } private void resetRadioChecks(bool checkToF = false) { Program.radioContains = checkToF; Program.radioEndsWith = checkToF; Program.radioEquals = checkToF; Program.radioStartsWith = checkToF; } private void searchFind_Shown(Object Sender, EventArgs Args) { int previouslySelectedRow = frmParent.dataGrid.CurrentCell.RowIndex; int previouslySelectedColumn = frmParent.dataGrid.CurrentCell.ColumnIndex; loadSettings(); if (frmParent.FileTab.SelectedTab.Text == Program.searchFile) { if (Program.searchParam0 != null) { txtFor.Text = Program.searchParam0; cmbIn.SelectedIndex = Program.searchParam1; if (Program.radioEndsWith == true) { radioEndsWith.Checked = true; } else if (Program.radioEquals == true) { radioEquals.Checked = true; } else if (Program.radioStartsWith == true) { radioStartsWith.Checked = true; } else { radioContains.Checked = true; } btnSearch.PerformClick(); txtFor.Select(txtFor.Text.Length, 0); } } frmParent.dataGrid.CurrentCell = frmParent.dataGrid.Rows[previouslySelectedRow].Cells[previouslySelectedColumn]; } private void searchFind_Closing(Object Sender, FormClosingEventArgs e) { try { if (dataGrid.DataSource != null) { int previouslySelectedRow = frmParent.dataGrid.CurrentCell.RowIndex; int previouslySelectedColumn = frmParent.dataGrid.CurrentCell.ColumnIndex; frmParent.file.table.DefaultView.RowFilter = null; frmParent.dataGrid.DataSource = frmParent.file.table; frmParent.dataGrid.CurrentCell = frmParent.dataGrid.Rows[previouslySelectedRow].Cells[previouslySelectedColumn]; } e.Cancel = true; this.Hide(); } catch { DialogResult result = MessageBox.Show("Error saving edits, would you still like to close the form?", "SHN", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation); if (result == DialogResult.Yes) e.Cancel = true; this.Hide(); frmParent.SQLStatus.Text = "Error saving search form edits."; } } private void btnSearch_Click(Object Sender, EventArgs Args) { Program.searchParam0 = txtFor.Text; Program.searchParam1 = cmbIn.SelectedIndex; Program.searchFile = frmParent.FileTab.SelectedTab.Text; string[] comboText = cmbIn.Text.Split(':'); try { bindingSource1.RaiseListChangedEvents = true; bindingSource1.ResetBindings(false); if (String.IsNullOrEmpty(txtFor.Text)) { frmParent.file.table.DefaultView.RowFilter = null; } else { if (radioContains.Checked) { frmParent.file.table.DefaultView.RowFilter = String.Format("Convert({0}, 'System.String') LIKE '%{1}%'", comboText[1], txtFor.Text); resetRadioChecks(); Program.radioContains = true; } else if (radioEquals.Checked) { frmParent.file.table.DefaultView.RowFilter = String.Format("Convert({0}, 'System.String') = '{1}'", comboText[1], txtFor.Text); resetRadioChecks(); Program.radioEquals = true; } else if (radioStartsWith.Checked) { frmParent.file.table.DefaultView.RowFilter = String.Format("Convert({0}, 'System.String') LIKE '{1}*'", comboText[1], txtFor.Text); resetRadioChecks(); Program.radioStartsWith = true; } else if (radioEndsWith.Checked) { frmParent.file.table.DefaultView.RowFilter = String.Format("Convert({0}, 'System.String') LIKE '*{1}'", comboText[1], txtFor.Text); resetRadioChecks(); Program.radioEndsWith = true; } } bindingSource1.RaiseListChangedEvents = false; tStatus.Text = "Found " + (dataGrid.Rows.Count - 1).ToString() + " Rows."; } catch (Exception ex) { MessageBox.Show(ex.Message); } } private void btnEnter_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { btnSearch.PerformClick(); e.SuppressKeyPress = true; } if (e.KeyCode == Keys.Escape) { e.SuppressKeyPress = true; this.Hide(); } } private void dataGrid_SelectionChanged(object sender, EventArgs e) { //frmParent.dataGrid.CurrentCell = frmParent.dataGrid.Rows[dataGrid.CurrentCell.RowIndex].Cells[dataGrid.CurrentCell.ColumnIndex]; } } }