private void ButtonDonate_Click(object sender, RoutedEventArgs e) { WindowDonate window = new WindowDonate(Id.ToString()); if (window.ShowDialog() == true) { Mon.Content = window.Money; } oper(); }
private void ButtonBuyDota_Click(object sender, RoutedEventArgs e) { if (MessageBox.Show("You really want to buy it ?", "Tresu Store", MessageBoxButton.OKCancel) == MessageBoxResult.OK) { int id_skin = listViewDota.SelectedIndex + 1; string Name = "Usp-s Kill Confirmed", ImgName = "CS_GO/usp_s/kill_confirmed.png", Price = "125.78"; int price_skin = 0; double num; string connString = ConfigurationManager.ConnectionStrings["BConnection"].ConnectionString; try { using (SQLiteConnection conn = new SQLiteConnection(connString)) { conn.Open(); ImageBrush image = new ImageBrush(); string command = "SELECT * FROM SkinsDota"; using (SQLiteCommand cmd = new SQLiteCommand(command, conn)) { using (SQLiteDataReader reader = cmd.ExecuteReader()) { while (reader.Read()) { if (reader["Id"].ToString() == id_skin.ToString()) { if (double.Parse(Mone) < double.Parse(reader["Price"].ToString())) { MessageBox.Show("You haven`t got so much money to buy this skin"); WindowDonate window = new WindowDonate(Id.ToString()); window.ShowDialog(); return; } Name = reader["Name"].ToString(); ImgName = reader["ImgName"].ToString(); Price = reader["Price"].ToString(); num = Math.Round(double.Parse(reader["Price"].ToString())); //MessageBox.Show(num.ToString()); price_skin = int.Parse(num.ToString()); } //cmd.ExecuteNonQuery(); } } } } } catch (SQLiteException ex) { MessageBox.Show(ex.Message); } int money = int.Parse(Mon.Content.ToString()) - price_skin; connString = ConfigurationManager.ConnectionStrings["DbConnection"].ConnectionString; try { using (SQLiteConnection conn = new SQLiteConnection(connString)) { conn.Open(); string command = "UPDATE Users SET Money = @Money WHERE Id = @Id"; using (SQLiteCommand cmd = new SQLiteCommand(command, conn)) { cmd.Parameters.AddWithValue("@Money", money); cmd.Parameters.AddWithValue("@Id", Id); cmd.Prepare(); cmd.ExecuteNonQuery(); } } } catch (Exception ex) { } connString = ConfigurationManager.ConnectionStrings["DbConnection"].ConnectionString; try { using (SQLiteConnection conn = new SQLiteConnection(connString)) { conn.Open(); string command = "INSERT INTO Skins (Name,ImgName,Price,user_id) VALUES(@Name,@ImgName,@Price,@user_id)"; using (SQLiteCommand cmd = new SQLiteCommand(command, conn)) { cmd.Prepare(); cmd.Parameters.AddWithValue("@Name", Name); cmd.Parameters.AddWithValue("@ImgName", ImgName); cmd.Parameters.AddWithValue("@Price", Price); cmd.Parameters.AddWithValue("@user_id", Id); cmd.ExecuteNonQuery(); } } } catch (Exception ex) { MessageBox.Show(ex.Message); } } }