private void button1_Click(object sender, EventArgs e) { if (this.listBox1.Items.Count != 0) { int iD = ExChangeList[ExChangeList.Count - 1].IndexID + 1; t_EXChange temp = new t_EXChange(); temp.IndexID = iD; ExChangeList.Add(temp); this.listBox1.Items.Clear(); int num = ExChangeList.Count <t_EXChange>(); for (int i = 0; i < num; i++) { int iD2 = ExChangeList[i].IndexID; int npcid = ExChangeList[i].NpcIndex; this.listBox1.Items.Add(iD2 + " - " + npcid); } if (this.checkBox1.Checked) { //Mysql Insert MySqlConnection mySqlConnection = new MySqlConnection("datasource=" + Host + ";port=3306;username="******";password="******";database=" + Database); mySqlConnection.Open(); MySqlCommand mySqlCommand3 = new MySqlCommand(string.Concat(new object[] { "INSERT INTO t_item_exchange (a_index,a_enable)VALUES('", iD, "','1", "');" }), mySqlConnection); mySqlCommand3.ExecuteNonQuery(); mySqlConnection.Close(); } } }
private void LoadListBox() { MySqlConnection mysqlCon = new MySqlConnection("datasource=" + Host + ";port=3306;username="******";password="******";database=" + Database); mysqlCon.Open(); MySqlCommand Command = new MySqlCommand("SELECT * FROM t_item_exchange ORDER BY a_index ASC;", mysqlCon); Command.ExecuteNonQuery(); MySqlDataReader Reader = Command.ExecuteReader(); while (Reader.Read()) { t_EXChange temp = new t_EXChange(); temp.IndexID = (int)Reader["a_index"]; temp.Enable = (int)Reader["a_enable"]; temp.NpcIndex = (int)Reader["a_npc_index"]; temp.ResultItemIdx = (int)Reader["result_itemIndex"]; temp.ResultItemCount = (int)Reader["result_itemCount"]; temp.SourceItemIndex0 = (int)Reader["source_itemIndex0"]; temp.SourceItemIndex1 = (int)Reader["source_itemIndex1"]; temp.SourceItemIndex2 = (int)Reader["source_itemIndex2"]; temp.SourceItemIndex3 = (int)Reader["source_itemIndex3"]; temp.SourceItemIndex4 = (int)Reader["source_itemIndex4"]; temp.SourceItemCount0 = (int)Reader["source_itemCount0"]; temp.SourceItemCount1 = (int)Reader["source_itemCount1"]; temp.SourceItemCount2 = (int)Reader["source_itemCount2"]; temp.SourceItemCount3 = (int)Reader["source_itemCount3"]; temp.SourceItemCount4 = (int)Reader["source_itemCount4"]; ExChangeList.Add(temp); } listBox1.Items.Clear(); int sk = ExChangeList.Count(); for (int i = 0; i < sk; i++) { int ID = ExChangeList[i].IndexID; int npcid = ExChangeList[i].NpcIndex; listBox1.Items.Add(ID + " - " + "NPC ID " + " - " + npcid); } mysqlCon.Close(); }