コード例 #1
0
        private void btnPurchase_Click(object sender, EventArgs e)
        {
            DateTimePicker date = new DateTimePicker();
            // DateTime date = new DateTime();
            int qty;

            //making sure the user enters an integer
            if (int.TryParse(textBox.Text, out qty))
            {
                if (qty > 0)
                {
                    if (qty <= context.ITEMs.Select(b => b.QTY_ITEM).First())
                    {
                        //check balance-if able to buy it, then change balance amount
                        if (context.USERs.Where(c => Convert.ToInt16(c.User_ID) == Login.Id)
                            .Select(c => c.Balance).First() +
                            (context.ITEMs.Where(b => b.Item_ID.Equals(ItemId))
                             .Select(b => b.Price).First() * qty) <= Payment.Credit)
                        {
                            //now need to subtract qty
                            ITEM item = context.ITEMs.Single(b => b.Item_ID == ItemId);



                            //increase the balance
                            USER user = context.USERs.Single(c => Convert.ToInt16(c.User_ID) == Login.Id);
                            user.Balance += context.ITEMs.Where(b => b.Item_ID == ItemId)
                                            .Select(b => b.Price).First() * qty;

                            //insert into the Order_Line table
                            ORDER order = new ORDER
                            {
                                ITEM_ID    = ItemId,
                                User_ID    = Convert.ToString(Login.Id),
                                Total_Cost = context.ITEMs.Where(b => b.Item_ID == ItemId)
                                             .Select(b => b.Price).First() * qty,
                                ORDER_DATE = date.Value,
                                QTY        = qty
                            };
                            context.ORDERs.InsertOnSubmit(order);
                            //submit ALL the changes...
                            context.SubmitChanges();
                            MessageBox.Show("Item is being shipped!");
                        }//end if
                        else
                        {
                            MessageBox.Show("You have gone over your Balance");
                        }
                    }//end if
                    else
                    {
                        if (context.ITEMs.Select(b => b.QTY_ITEM).First() == 0)
                        {
                            MessageBox.Show("Out of stock\nPick another book");
                        }
                        else
                        {
                            MessageBox.Show("Not enough in stock, reenter quantity");
                        }
                    }
                }//end if
                else
                {
                    MessageBox.Show("Enter quantity amount");
                }
            }//end if
        }
コード例 #2
0
 partial void UpdateITEM(ITEM instance);
コード例 #3
0
 partial void DeleteITEM(ITEM instance);
コード例 #4
0
 partial void InsertITEM(ITEM instance);