Example #1
0
        public void saveInvoice(Invoice invoice)
        {
            try{
                DateTime dt = DateTime.Parse(invoice.getDate());

                string sql = "INSERT INTO Invoice (CarId, AccountId, Duration, PreCharge, Date) values(@carId, @accountId, @duration, @preCharge, @date)";
                conn = new MySql.Data.MySqlClient.MySqlConnection(myConnectionString);

                MySqlCommand command = new MySqlCommand(sql,conn);
                command.Parameters.AddWithValue("carId", invoice.getCarID());
                command.Parameters.AddWithValue("accountId", invoice.getAccountID());
                command.Parameters.AddWithValue("duration", invoice.getDuration());
                command.Parameters.AddWithValue("preCharge", invoice.getPreCharge());
                command.Parameters.AddWithValue("date", dt.ToString("yyyy-MM-dd"));
                conn.Open();

                command.ExecuteNonQuery();

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                conn.Close();
            }
        }