namespace SHNDecryptHK { using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Runtime.InteropServices; using System.Windows.Forms; public class searchFind : Form { private BindingSource bindingSource1; private Button btnSearch; private ComboBox cmbIn; private IContainer components; private DataGridView dataGrid; private frmMain frmParent; private GroupBox groupBox1; private Label label1; private Label label2; private Dictionary originIndex = new Dictionary(); private RadioButton radioContains; private RadioButton radioEndsWith; private RadioButton radioEquals; private RadioButton radioStartsWith; private StatusStrip statusStrip1; private ToolStripStatusLabel tStatus; private TextBox txtFor; public searchFind(frmMain Handle) { this.frmParent = Handle; this.InitializeComponent(); this.dataGrid.DoubleBuffered(true); } private void btnEnter_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { this.btnSearch.PerformClick(); e.SuppressKeyPress = true; } if (e.KeyCode == Keys.Escape) { e.SuppressKeyPress = true; base.Hide(); } } private void btnSearch_Click(object Sender, EventArgs Args) { Program.searchParam0 = this.txtFor.Text; Program.searchParam1 = this.cmbIn.SelectedIndex; Program.searchFile = this.frmParent.FileTab.SelectedTab.Text; string[] strArray = this.cmbIn.Text.Split(new char[] { ':' }); try { this.bindingSource1.RaiseListChangedEvents = true; this.bindingSource1.ResetBindings(false); if (string.IsNullOrEmpty(this.txtFor.Text)) { this.frmParent.file.table.DefaultView.RowFilter = null; } else if (this.radioContains.Checked) { this.frmParent.file.table.DefaultView.RowFilter = string.Format("Convert({0}, 'System.String') LIKE '%{1}%'", strArray[1], this.txtFor.Text); this.resetRadioChecks(false); Program.radioContains = true; } else if (this.radioEquals.Checked) { this.frmParent.file.table.DefaultView.RowFilter = string.Format("Convert({0}, 'System.String') = '{1}'", strArray[1], this.txtFor.Text); this.resetRadioChecks(false); Program.radioEquals = true; } else if (this.radioStartsWith.Checked) { this.frmParent.file.table.DefaultView.RowFilter = string.Format("Convert({0}, 'System.String') LIKE '{1}*'", strArray[1], this.txtFor.Text); this.resetRadioChecks(false); Program.radioStartsWith = true; } else if (this.radioEndsWith.Checked) { this.frmParent.file.table.DefaultView.RowFilter = string.Format("Convert({0}, 'System.String') LIKE '*{1}'", strArray[1], this.txtFor.Text); this.resetRadioChecks(false); Program.radioEndsWith = true; } this.bindingSource1.RaiseListChangedEvents = false; this.tStatus.Text = "Found " + ((this.dataGrid.Rows.Count - 1)).ToString() + " Rows."; } catch (Exception exception) { MessageBox.Show(exception.Message); } } private void dataGrid_SelectionChanged(object sender, EventArgs e) { } protected override void Dispose(bool disposing) { if (disposing && (this.components != null)) { this.components.Dispose(); } base.Dispose(disposing); } private void InitializeComponent() { this.components = new Container(); ComponentResourceManager manager = new ComponentResourceManager(typeof(searchFind)); this.groupBox1 = new GroupBox(); this.radioEndsWith = new RadioButton(); this.radioStartsWith = new RadioButton(); this.radioEquals = new RadioButton(); this.radioContains = new RadioButton(); this.btnSearch = new Button(); this.cmbIn = new ComboBox(); this.label2 = new Label(); this.label1 = new Label(); this.txtFor = new TextBox(); this.bindingSource1 = new BindingSource(this.components); this.statusStrip1 = new StatusStrip(); this.tStatus = new ToolStripStatusLabel(); this.dataGrid = new DataGridView(); this.groupBox1.SuspendLayout(); ((ISupportInitialize) this.bindingSource1).BeginInit(); this.statusStrip1.SuspendLayout(); ((ISupportInitialize) this.dataGrid).BeginInit(); base.SuspendLayout(); this.groupBox1.Controls.Add(this.radioEndsWith); this.groupBox1.Controls.Add(this.radioStartsWith); this.groupBox1.Controls.Add(this.radioEquals); this.groupBox1.Controls.Add(this.radioContains); this.groupBox1.Controls.Add(this.btnSearch); this.groupBox1.Controls.Add(this.cmbIn); this.groupBox1.Controls.Add(this.label2); this.groupBox1.Controls.Add(this.label1); this.groupBox1.Controls.Add(this.txtFor); this.groupBox1.Dock = DockStyle.Top; this.groupBox1.Location = new Point(0, 0); this.groupBox1.Name = "groupBox1"; this.groupBox1.Size = new Size(0x2e7, 100); this.groupBox1.TabIndex = 0; this.groupBox1.TabStop = false; this.radioEndsWith.AutoSize = true; this.radioEndsWith.Location = new Point(0x119, 70); this.radioEndsWith.Name = "radioEndsWith"; this.radioEndsWith.Size = new Size(0x4a, 0x11); this.radioEndsWith.TabIndex = 6; this.radioEndsWith.TabStop = true; this.radioEndsWith.Text = "Ends With"; this.radioEndsWith.UseVisualStyleBackColor = true; this.radioEndsWith.KeyDown += new KeyEventHandler(this.btnEnter_KeyDown); this.radioStartsWith.AutoSize = true; this.radioStartsWith.Location = new Point(0x119, 0x35); this.radioStartsWith.Name = "radioStartsWith"; this.radioStartsWith.Size = new Size(0x4d, 0x11); this.radioStartsWith.TabIndex = 5; this.radioStartsWith.TabStop = true; this.radioStartsWith.Text = "Starts With"; this.radioStartsWith.UseVisualStyleBackColor = true; this.radioStartsWith.KeyDown += new KeyEventHandler(this.btnEnter_KeyDown); this.radioEquals.AutoSize = true; this.radioEquals.Location = new Point(0x119, 0x24); this.radioEquals.Name = "radioEquals"; this.radioEquals.Size = new Size(0x39, 0x11); this.radioEquals.TabIndex = 4; this.radioEquals.TabStop = true; this.radioEquals.Text = "Equals"; this.radioEquals.UseVisualStyleBackColor = true; this.radioEquals.KeyDown += new KeyEventHandler(this.btnEnter_KeyDown); this.radioContains.AutoSize = true; this.radioContains.Location = new Point(0x119, 0x13); this.radioContains.Name = "radioContains"; this.radioContains.Size = new Size(0x42, 0x11); this.radioContains.TabIndex = 3; this.radioContains.TabStop = true; this.radioContains.Text = "Contains"; this.radioContains.UseVisualStyleBackColor = true; this.radioContains.KeyDown += new KeyEventHandler(this.btnEnter_KeyDown); this.btnSearch.Location = new Point(80, 0x44); this.btnSearch.Name = "btnSearch"; this.btnSearch.Size = new Size(0xc2, 0x18); this.btnSearch.TabIndex = 2; this.btnSearch.Text = "Search"; this.btnSearch.UseVisualStyleBackColor = true; this.btnSearch.Click += new EventHandler(this.btnSearch_Click); this.btnSearch.KeyDown += new KeyEventHandler(this.btnEnter_KeyDown); this.cmbIn.DropDownStyle = ComboBoxStyle.DropDownList; this.cmbIn.FormattingEnabled = true; this.cmbIn.Location = new Point(80, 0x2a); this.cmbIn.Name = "cmbIn"; this.cmbIn.Size = new Size(0xc2, 0x15); this.cmbIn.TabIndex = 1; this.cmbIn.KeyDown += new KeyEventHandler(this.btnEnter_KeyDown); this.label2.AutoSize = true; this.label2.Location = new Point(15, 0x2d); this.label2.Name = "label2"; this.label2.Size = new Size(0x37, 13); this.label2.TabIndex = 2; this.label2.Text = "Search in:"; this.label1.AutoSize = true; this.label1.Location = new Point(15, 0x13); this.label1.Name = "label1"; this.label1.Size = new Size(0x3b, 13); this.label1.TabIndex = 1; this.label1.Text = "Search for:"; this.txtFor.Location = new Point(80, 0x10); this.txtFor.Name = "txtFor"; this.txtFor.Size = new Size(0xc2, 20); this.txtFor.TabIndex = 0; this.txtFor.KeyDown += new KeyEventHandler(this.btnEnter_KeyDown); this.statusStrip1.Items.AddRange(new ToolStripItem[] { this.tStatus }); this.statusStrip1.Location = new Point(0, 0x219); this.statusStrip1.Name = "statusStrip1"; this.statusStrip1.Size = new Size(0x2e7, 0x16); this.statusStrip1.TabIndex = 8; this.statusStrip1.Text = "statusStrip1"; this.tStatus.Name = "tStatus"; this.tStatus.Size = new Size(0x2a, 0x11); this.tStatus.Text = "Ready."; this.dataGrid.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; this.dataGrid.Dock = DockStyle.Fill; this.dataGrid.Location = new Point(0, 100); this.dataGrid.Name = "dataGrid"; this.dataGrid.Size = new Size(0x2e7, 0x1b5); this.dataGrid.TabIndex = 9; this.dataGrid.TabStop = false; base.AutoScaleDimensions = new SizeF(6f, 13f); base.AutoScaleMode = AutoScaleMode.Font; base.ClientSize = new Size(0x2e7, 0x22f); base.Controls.Add(this.dataGrid); base.Controls.Add(this.statusStrip1); base.Controls.Add(this.groupBox1); base.Icon = (Icon) manager.GetObject("$this.Icon"); base.MinimizeBox = false; this.MinimumSize = new Size(500, 300); base.Name = "searchFind"; base.StartPosition = FormStartPosition.CenterScreen; this.Text = "Search"; base.FormClosing += new FormClosingEventHandler(this.searchFind_Closing); base.Shown += new EventHandler(this.searchFind_Shown); base.KeyDown += new KeyEventHandler(this.btnEnter_KeyDown); this.groupBox1.ResumeLayout(false); this.groupBox1.PerformLayout(); ((ISupportInitialize) this.bindingSource1).EndInit(); this.statusStrip1.ResumeLayout(false); this.statusStrip1.PerformLayout(); ((ISupportInitialize) this.dataGrid).EndInit(); base.ResumeLayout(false); base.PerformLayout(); } private void loadSettings() { if (this.frmParent.file != null) { this.cmbIn.Items.Clear(); this.originIndex.Clear(); this.radioContains.Checked = true; for (int i = 0; i < this.frmParent.file.table.Columns.Count; i++) { DataColumn column = this.frmParent.file.table.Columns[i]; this.cmbIn.Items.Add(i.ToString("00") + ": " + column.ToString()); } this.cmbIn.SelectedIndex = 0; this.bindingSource1.DataSource = this.frmParent.file.table.DefaultView; this.dataGrid.DataSource = this.bindingSource1; this.frmParent.dataGrid.DataSource = this.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_Closing(object Sender, FormClosingEventArgs e) { try { if (this.dataGrid.DataSource != null) { int rowIndex = this.frmParent.dataGrid.CurrentCell.RowIndex; int columnIndex = this.frmParent.dataGrid.CurrentCell.ColumnIndex; this.frmParent.file.table.DefaultView.RowFilter = null; this.frmParent.dataGrid.DataSource = this.frmParent.file.table; this.frmParent.dataGrid.CurrentCell = this.frmParent.dataGrid.Rows[rowIndex].Cells[columnIndex]; } e.Cancel = true; base.Hide(); } catch { if (MessageBox.Show("Error saving edits, would you still like to close the form?", "SHN", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == DialogResult.Yes) { e.Cancel = true; } base.Hide(); this.frmParent.SQLStatus.Text = "Error saving search form edits."; } } private void searchFind_Shown(object Sender, EventArgs Args) { int rowIndex = this.frmParent.dataGrid.CurrentCell.RowIndex; int columnIndex = this.frmParent.dataGrid.CurrentCell.ColumnIndex; this.loadSettings(); if ((this.frmParent.FileTab.SelectedTab.Text == Program.searchFile) && (Program.searchParam0 != null)) { this.txtFor.Text = Program.searchParam0; this.cmbIn.SelectedIndex = Program.searchParam1; if (Program.radioEndsWith) { this.radioEndsWith.Checked = true; } else if (Program.radioEquals) { this.radioEquals.Checked = true; } else if (Program.radioStartsWith) { this.radioStartsWith.Checked = true; } else { this.radioContains.Checked = true; } this.btnSearch.PerformClick(); this.txtFor.Select(this.txtFor.Text.Length, 0); } this.frmParent.dataGrid.CurrentCell = this.frmParent.dataGrid.Rows[rowIndex].Cells[columnIndex]; } protected override System.Windows.Forms.CreateParams CreateParams { get { System.Windows.Forms.CreateParams createParams = base.CreateParams; createParams.ExStyle |= 0x2000000; return createParams; } } } }