Esempio n. 1
0
 private void ClearItemArea()
 {
     ItemId.Clear();
     ItemTextBox.Clear();
     ItemBoxName.Clear();
     ItemQuantity.Clear();
     ItemTargetQuantity.Clear();
     ItemCanExpire.IsChecked = false;
 }
        private void Sell_Click(object sender, RoutedEventArgs e)
        {
            if (!string.IsNullOrWhiteSpace(ItemQuantity.Text) && int.Parse(ItemQuantity.Text) <= int.Parse(oldQuan.Text) && int.Parse(ItemQuantity.Text) != 0)
            {
                int newQuan = int.Parse(oldQuan.Text) - int.Parse(ItemQuantity.Text);
                try
                {
                    connection.Open();

                    MySqlCommand cmd = new MySqlCommand();
                    cmd.CommandText = "update items set ITEM_NAME=@ItemName,ITEM_QUANTATY=@ItemQuantity where ITEM_ID=@ItemId";
                    cmd.Parameters.AddWithValue("@ItemName", ItemName.Text);
                    cmd.Parameters.AddWithValue("@ItemQuantity", newQuan);
                    cmd.Parameters.AddWithValue("@ItemId", ItemId.Text);
                    cmd.Connection = connection;
                    cmd.ExecuteNonQuery();
                    MySqlCommand Com = new MySqlCommand($"Select * from items where ITEM_QUANTATY>{0}", connection);

                    MySqlDataAdapter adp = new MySqlDataAdapter(Com);
                    DataSet          ds  = new DataSet();
                    adp.Fill(ds, "LoadDataBinding");
                    GridItemSell.DataContext = ds;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
                finally
                {
                    connection.Close();
                    string sts = ItemQuantity.Text + " " + ItemName.Text + " has been sold";
                    MessageBox.Show(sts, "Success");
                    //     ItemName.Clear();
                    ItemQuantity.Clear();
                    ItemId.Clear();
                }
            }
            else
            {
                MessageBox.Show("WRONG QUANTITY", "ERROR");
            }
        }