C-sharp winform ADO.NET

时间:2017-12-12 07:49:22

标签: c#

 我正在尝试使用c#开发一个可以在我的药房管理系统中称为交易的模块,但我想做的是我想要一个情况,即每个项目销售的小计我们将存储在mysql数据库中,总金额将是一次存储,也将在mysql数据库中为每个事务累积。

private void TransactionSave()
{
    try
    {
        if (RxtTransact_Id.Text == "" || QuantitySold_Transaction.Text == "" || RxtUnit_Price.Text == "" ||
            RxtProduct_Name.Text == "" || cmbTransaction_SalesMan.Text == "" ||
            RxtCustomer_transaction.Text == "")
        {
            MessageBox.Show("The required field(s) can not be left empty", "Transaction erreor", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }
        else
        {
            conn.Open();
            commandd = new MySqlCommand("insert into transaction( Transaction_id, quantity_sold, unit_price, product_name, salesman, customer_name, date_time, sub_total, total_amount) values (@Transaction_id, @quantity_sold, @unit_price, @product_name, @salesman, @customer_name, @date_time, @sub_total, @total_amount)", conn);
            commandd.Parameters.AddWithValue("Transaction_id", RxtTransact_Id.Text);
            commandd.Parameters.AddWithValue("quantity_sold", QuantitySold_Transaction.Text);
            commandd.Parameters.AddWithValue("unit_price", RxtUnit_Price.Text);
            commandd.Parameters.AddWithValue("product_name", RxtProduct_Name.Text);
            commandd.Parameters.AddWithValue("salesman", cmbTransaction_SalesMan.Text);
            commandd.Parameters.AddWithValue("customer_name", RxtCustomer_transaction.Text);
            DateTime dt = Convert.ToDateTime(dateTimePicker1.Value);
            dateTimePicker1.Value = DateTime.Parse(dt.ToShortDateString());
            commandd.Parameters.AddWithValue("date_time", dateTimePicker1.Value);
            commandd.Parameters.AddWithValue("sub_total", RxtSubTotal_transaction.Text);
            commandd.Parameters.AddWithValue("total_amount", RxtTotal_Transaction.Text);
            commandd.ExecuteNonQuery();
        }
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.ToString());
    }

    conn.Close();
}

GUI Snapshot

每次点击addtocart时,我都希望立即保存总金额,并继续为每笔交易累计。

0 个答案:

没有答案