private void mysqlBackgroundWorker_DoWork(object sender, DoWorkEventArgs e) { try { MySqlConnection mConnection = mysql.NewMySQLConnection(Settings.Default.WorldDB); string qry = String.Format("SELECT * FROM creature_template WHERE name LIKE '%{0}%' LIMIT 200", npcSearchTextBoxX.Text); mConnection.Open(); MySqlCommand cmd = new MySqlCommand(qry, mConnection); MySqlDataReader Reader = cmd.ExecuteReader(); while (Reader.Read()) { npcSearchListBox.Items.Add(Reader.GetString("name")); displayids.Add(Reader.GetInt32("modelid1")); entryids.Add(Reader.GetInt32("entry")); } mConnection.Close(); mConnection.Dispose(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void searchButtonX_Click(object sender, EventArgs e) { if (itemsListBox.Items.Count != 0) { itemsListBox.Items.Clear(); } if (entryids.Count != 0) { entryids.Clear(); } if (displayids.Count != 0) { displayids.Clear(); } if (itemNameTextBoxX.Text != String.Empty) { try { this.Cursor = Cursors.WaitCursor; circularProgress.Visible = true; circularProgress.IsRunning = true; MySqlConnection conn = mysql.NewMySQLConnection(Settings.Default.WorldDB); conn.Open(); string qry = String.Empty; if (searchType == SearchType.Item) { qry = String.Format("SELECT * FROM item_template WHERE name LIKE '%{0}%' LIMIT 200", itemNameTextBoxX.Text); } else if (searchType == SearchType.Weapon) { qry = String.Format("SELECT * FROM item_template WHERE name LIKE '%{0}%' AND class='2' LIMIT 200", itemNameTextBoxX.Text); } else if (searchType == SearchType.Armor) { qry = String.Format("SELECT * FROM item_template WHERE name LIKE '%{0}%' AND class='4' LIMIT 200", itemNameTextBoxX.Text); } MySqlCommand cmd = new MySqlCommand(qry, conn); MySqlDataReader Reader = cmd.ExecuteReader(); while (Reader.Read()) { itemsListBox.Items.Add(Reader.GetString("name")); displayids.Add(Reader.GetString("displayid")); entryids.Add(Reader.GetString("entry")); } conn.Close(); this.Cursor = Cursors.Default; circularProgress.IsRunning = false; circularProgress.Visible = false; if (itemsListBox.Items.Count != 0) { itemsListBox.SelectedIndex = 0; } itemsListBox.Focus(); } catch (Exception ex) { TaskDialog.Show(new TaskDialogInfo("Error", eTaskDialogIcon.Stop, "Error!", ex.Message, eTaskDialogButton.Ok)); } } }