Exemple #1
0
        private void btnSubmit_Click(object sender, EventArgs e)
        {
            if(IsValid())
            {
                Transaction transaction = new Transaction();
                transaction.CustomerID = _customer.CustomerID;
                if (chkPaid.Checked)
                {
                    transaction.PaymentRecieved = DateTime.Today;
                }
                else
                {
                    transaction.PaymentRecieved = null;
                }
                transaction.ResponsiblePartyID = _customer.ResponsiblePartyID;
                transaction.TransactionDate = DateTime.Today;
                transaction.TotalPrice = long.Parse(txtTotal.Text);

                TransactionProduct transactionProduct = new TransactionProduct();
                transactionProduct.ProductID = _product.ProductID;
                transactionProduct.Quantity = (int)numQuantity.Value;

                transaction.AddTransactionProduct(transactionProduct);

                TransactionDB.AddTransaction(transaction);
                MessageBox.Show("Transaction Added");
                this.Close();
            }
        }
Exemple #2
0
        internal static void AddTransaction(Transaction transaction)
        {
            string paymentRecieved = "";
            if(transaction.PaymentRecieved != null)
            {
                paymentRecieved = transaction.PaymentRecieved.ToString();
            }
            string _query = string.Format("INSERT INTO [Transaction] (CustomerID, ResponsiblePartyID, TransactionDate, PaymentRecieved, TotalPrice) " +
                "VALUES({0}, {1}, '{2}', '{3}', {4})", transaction.CustomerID,
                transaction.ResponsiblePartyID == null ? 0 : transaction.ResponsiblePartyID,
                transaction.TransactionDate, paymentRecieved, transaction.TotalPrice);

            long? transactionID = CaseStudyDB.ExecuteNonQuery(_query);
            if(transactionID != null)
            {
                foreach(TransactionProduct product in transaction.TransactionProducts)
                {
                    _query = string.Format("INSERT INTO TransactionProducts (TransactionID, ProductID, Quantity) " +
                        "VALUES({0},{1},{2})", transactionID, product.ProductID, product.Quantity);
                    CaseStudyDB.ExecuteNonQuery(_query);
                }
            }
            else
            {
                MessageBox.Show("Couldn't save transaction");
            }
        }
Exemple #3
0
 public static bool AddTransaction(Transaction transaction)
 {
     return true;
 }
Exemple #4
0
        private static Transaction GetTransactionFromReader(SqlCeDataReader reader)
        {
            if(reader != null)
            {
                Transaction transaction = new Transaction();
                transaction.TransactionID = (long)reader["TransactionID"];
                transaction.CustomerID = (long)reader["CustomerID"];
                if (!reader.IsDBNull(reader.GetOrdinal("ResponsiblePartyID")))
                {
                    transaction.ResponsiblePartyID = (long)reader["ResponsiblePartyID"];
                }
                transaction.TransactionDate = DateTime.Parse(reader["TransactionDate"].ToString());
                transaction.PaymentRecieved = DateTime.Parse(reader["PaymentRecieved"].ToString());
                transaction.TotalPrice = (int)reader["TotalPrice"];

                return transaction;
            }
            return null;
        }