コード例 #1
0
        public void TransactionCompletedMethod(object sebder, EventArgs e)
        {
            this.Refresh();
            lblTotal.Text = String.Format("Total to Pay: {0:C}", totalToPay);

            using (Coffee_ProjectEntities cpe = new Coffee_ProjectEntities())
            {
                if (ChosenProductsList.Count > 0)
                {
                    TblTransaction transaction = new TblTransaction();
                    transaction.TransactionDate = DateTime.Now;
                    foreach (var item in ChosenProductsList)
                    {
                        transaction.TblTransactionItems.Add(new TblTransactionItem()
                        {
                            ProductID = item.ProductID
                        });
                    }

                    cpe.TblTransactions.Add(transaction);
                    try
                    {
                        cpe.SaveChanges();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, ex.Source, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }

            PrintReciept();
        }
        private void btnSave_Click(object sender, EventArgs e)
        {
            using (Coffee_ProjectEntities cpe = new Coffee_ProjectEntities())
            {
                TblProduct newProduct = new TblProduct()
                {
                    Description = txtDescription.Text,
                    Price       = Convert.ToDecimal(txtPrice.Text),
                    Image       = imageBytes,
                    ProductType = (int)cmbCategory.SelectedValue
                };

                cpe.TblProducts.Add(newProduct);
                cpe.SaveChanges();
                lblSaving.Visible = false;
                MessageBox.Show("Item Saved Successfully", "Item Saved", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }