Esempio n. 1
0
        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            this.Width  = 800;
            this.Height = 300;

            var senderGrid = (DataGridView)sender;

            if (senderGrid.Columns[e.ColumnIndex] is DataGridViewButtonColumn &&
                e.RowIndex >= 0)
            {
                String  item  = (String)dataGridView1[e.ColumnIndex - 3, e.RowIndex].Value;
                decimal price = Convert.ToDecimal(dataGridView1[e.ColumnIndex - 2, e.RowIndex].Value);
                int     upc   = (int)dataGridView1[e.ColumnIndex - 4, e.RowIndex].Value;

                int quantity = 0;
                if (dataGridView1[e.ColumnIndex - 1, e.RowIndex].Value != null)
                {
                    quantity = Convert.ToInt32(dataGridView1[e.ColumnIndex - 1, e.RowIndex].Value);

                    using (MyStoreDataDataContext db = new MyStoreDataDataContext())
                    {
                        int creditLimit = 10000;
                        var userBalance = db.USERs.Where(p => p.userID == id).Select(p => p.user_balance).First();
                        if (quantity * price > creditLimit - userBalance)
                        {
                            MessageBox.Show("That amount is over your credit limit!");
                        }
                        else
                        {
                            var date = Convert.ToDateTime(DateTime.Now.Date.ToString("MM/dd/yyyy"));

                            ORDER_DETAIL o = new ORDER_DETAIL();
                            o.order_date     = date;
                            o.custID         = id;
                            o.item_upc       = upc;
                            o.order_quantity = quantity;
                            o.order_price    = price * quantity;
                            //MessageBox.Show(date + " " + id + " " + upc + " " + quantity + " " + price * quantity);

                            db.ORDER_DETAILs.InsertOnSubmit(o);
                            db.SubmitChanges();

                            MessageBox.Show("You just bought " + quantity + " " + item + " for $" + price * quantity);
                        }
                    }
                }
                else
                {
                    MessageBox.Show("Please choose an amount greater than 0");
                }
            }
        }
Esempio n. 2
0
 private void detach_ORDER_DETAILs(ORDER_DETAIL entity)
 {
     this.SendPropertyChanging();
     entity.ITEM = null;
 }
Esempio n. 3
0
 partial void DeleteORDER_DETAIL(ORDER_DETAIL instance);
Esempio n. 4
0
 partial void UpdateORDER_DETAIL(ORDER_DETAIL instance);
Esempio n. 5
0
 partial void InsertORDER_DETAIL(ORDER_DETAIL instance);
Esempio n. 6
0
 private void attach_ORDER_DETAILs(ORDER_DETAIL entity)
 {
     this.SendPropertyChanging();
     entity.USER = this;
 }