private void buyWorker_DoWork(object sender, DoWorkEventArgs e) { if (activeList == Active_List.None) return; string unitName = string.Empty; int unitCost = 0; int listId = 0; int listIndex = 0; List<CustomizableUnit> boughtUnitList = null; switch (activeList) { case Active_List.Mech: { unitName = MechsPriceList.Type.PriceLists[mechListIndex].Name; unitCost = MechsPriceList.Type.PriceLists[mechListIndex].Price; listId = 1; listIndex = mechListIndex; boughtUnitList = MechDBUnits; } break; case Active_List.AirUnit: { unitName = AunitPriceList.Type.PriceLists[airUnitListIndex].Name; unitCost = AunitPriceList.Type.PriceLists[airUnitListIndex].Price; listId = 2; listIndex = airUnitListIndex; boughtUnitList = ADBUnits; } break; case Active_List.GroundUnit: { unitName = GunitPriceList.Type.PriceLists[groundUnitListIndex].Name; unitCost = GunitPriceList.Type.PriceLists[groundUnitListIndex].Price; listId = 3; listIndex = groundUnitListIndex; boughtUnitList = GDBUnits; } break; case Active_List.Jet: { unitName = JunitPriceList.Type.PriceLists[jetUnitListIndex].Name; unitCost = JunitPriceList.Type.PriceLists[jetUnitListIndex].Price; listId = 4; listIndex = jetUnitListIndex; boughtUnitList = JDBUnits; } break; } try { //Decreasing Credit string sql = "UPDATE phpap_AKusers SET money = @DeductedCash WHERE Username=@User"; MySqlCommand cmd = new MySqlCommand(sql, Program.AKsqlcon); MySqlParameter DeductedCashP = new MySqlParameter(); DeductedCashP.ParameterName = "@DeductedCash"; DeductedCashP.Value = cash - unitCost; cmd.Parameters.Add(DeductedCashP); MySqlParameter EmailP = new MySqlParameter(); EmailP.ParameterName = "@User"; EmailP.Value = Program.username; cmd.Parameters.Add(EmailP); cmd.ExecuteNonQuery(); } catch (Exception ex) { if (ex != null) { OnBuyGuiUpdate update = new OnBuyGuiUpdate(SetInfo); update.Invoke(ex.Message, true); } } try { string sql = "INSERT INTO phpap_AKunits (UnitName, Username, UnitGameID, ListID) VALUES (@Unitname, @Username, @Unitgameid, @Listid)"; MySqlCommand cmd = new MySqlCommand(sql, Program.AKsqlcon); MySqlParameter Unitname = new MySqlParameter(); MySqlParameter Username = new MySqlParameter(); MySqlParameter Unitgameid = new MySqlParameter(); MySqlParameter Listid = new MySqlParameter(); Unitname.ParameterName = "@Unitname"; Username.ParameterName = "@Username"; Unitgameid.ParameterName = "@Unitgameid"; Listid.ParameterName = "@Listid"; Unitname.Value = unitName; Username.Value = Program.username; Unitgameid.Value = listIndex; Listid.Value = listId; //cmd.Connection.Open(); cmd.Parameters.Add(Unitname); cmd.Parameters.Add(Username); cmd.Parameters.Add(Unitgameid); cmd.Parameters.Add(Listid); cmd.ExecuteNonQuery(); cash -= unitCost; txtCash.Text = "Cash: " + cash.ToString(); boughtUnitList.Add(new CustomizableUnit(listId, unitName)); btnBuy.Enable = false; } catch (Exception ex) { if (ex != null) { OnBuyGuiUpdate update = new OnBuyGuiUpdate(SetInfo); update.Invoke(ex.Message, true); } } }
private void buyWorker_DoWork(object sender, DoWorkEventArgs e) { if (activeList == Active_List.None) { return; } string unitName = string.Empty; int unitCost = 0; int listId = 0; int listIndex = 0; List <CustomizableUnit> boughtUnitList = null; switch (activeList) { case Active_List.Mech: { unitName = MechsPriceList.Type.PriceLists[mechListIndex].Name; unitCost = MechsPriceList.Type.PriceLists[mechListIndex].Price; listId = 1; listIndex = mechListIndex; boughtUnitList = MechDBUnits; } break; case Active_List.AirUnit: { unitName = AunitPriceList.Type.PriceLists[airUnitListIndex].Name; unitCost = AunitPriceList.Type.PriceLists[airUnitListIndex].Price; listId = 2; listIndex = airUnitListIndex; boughtUnitList = ADBUnits; } break; case Active_List.GroundUnit: { unitName = GunitPriceList.Type.PriceLists[groundUnitListIndex].Name; unitCost = GunitPriceList.Type.PriceLists[groundUnitListIndex].Price; listId = 3; listIndex = groundUnitListIndex; boughtUnitList = GDBUnits; } break; case Active_List.Jet: { unitName = JunitPriceList.Type.PriceLists[jetUnitListIndex].Name; unitCost = JunitPriceList.Type.PriceLists[jetUnitListIndex].Price; listId = 4; listIndex = jetUnitListIndex; boughtUnitList = JDBUnits; } break; } try { //Decreasing Credit string sql = "UPDATE phpap_AKusers SET money = @DeductedCash WHERE Username=@User"; MySqlCommand cmd = new MySqlCommand(sql, Program.AKsqlcon); MySqlParameter DeductedCashP = new MySqlParameter(); DeductedCashP.ParameterName = "@DeductedCash"; DeductedCashP.Value = cash - unitCost; cmd.Parameters.Add(DeductedCashP); MySqlParameter EmailP = new MySqlParameter(); EmailP.ParameterName = "@User"; EmailP.Value = Program.username; cmd.Parameters.Add(EmailP); cmd.ExecuteNonQuery(); } catch (Exception ex) { if (ex != null) { OnBuyGuiUpdate update = new OnBuyGuiUpdate(SetInfo); update.Invoke(ex.Message, true); } } try { string sql = "INSERT INTO phpap_AKunits (UnitName, Username, UnitGameID, ListID) VALUES (@Unitname, @Username, @Unitgameid, @Listid)"; MySqlCommand cmd = new MySqlCommand(sql, Program.AKsqlcon); MySqlParameter Unitname = new MySqlParameter(); MySqlParameter Username = new MySqlParameter(); MySqlParameter Unitgameid = new MySqlParameter(); MySqlParameter Listid = new MySqlParameter(); Unitname.ParameterName = "@Unitname"; Username.ParameterName = "@Username"; Unitgameid.ParameterName = "@Unitgameid"; Listid.ParameterName = "@Listid"; Unitname.Value = unitName; Username.Value = Program.username; Unitgameid.Value = listIndex; Listid.Value = listId; //cmd.Connection.Open(); cmd.Parameters.Add(Unitname); cmd.Parameters.Add(Username); cmd.Parameters.Add(Unitgameid); cmd.Parameters.Add(Listid); cmd.ExecuteNonQuery(); cash -= unitCost; txtCash.Text = "Cash: " + cash.ToString(); boughtUnitList.Add(new CustomizableUnit(listId, unitName)); btnBuy.Enable = false; } catch (Exception ex) { if (ex != null) { OnBuyGuiUpdate update = new OnBuyGuiUpdate(SetInfo); update.Invoke(ex.Message, true); } } }