コード例 #1
0
 partial void DeleteTransactionBuy(TransactionBuy instance);
コード例 #2
0
 partial void InsertTransactionBuy(TransactionBuy instance);
コード例 #3
0
 partial void UpdateTransactionBuy(TransactionBuy instance);
コード例 #4
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            String unit = txUnit.Text;
            String color = txColor.Text;
            decimal price = checkNumeric(txPrice.Text);
            int amount = (int)checkNumeric(txAmount.Text);

            if (color.Equals(""))
                MessageBox.Show("Color must be filled.");
            else if (price < 1)
                MessageBox.Show("Price must be more than 0.");
            else if (amount < 1)
                MessageBox.Show("Amount must be more than 0.");
            else if (unit.Equals(""))
                MessageBox.Show("Unit must be filled.");
            else
            {
                if (!checkExisted(itemId,color, price, unit))
                {
                    ItemInventory item = new ItemInventory();
                    item.Color = color;
                    item.ItemId = itemId;
                    item.Price = price;
                    item.Quantity = 0;
                    item.Unit = unit;

                    db.ItemInventories.InsertOnSubmit(item);
                    db.SubmitChanges();
                }

                ItemInventory temp = (from x in db.ItemInventories
                                      where
                                         x.ItemId == itemId &&
                                         x.Color.Equals(color) &&
                                         x.Price == price &&
                                         x.Unit.Equals(unit)
                                      select x).First();

                temp.Quantity += amount;

                db.SubmitChanges();

                TransactionBuy buy = new TransactionBuy();
                buy.Amount = amount;
                buy.BuyDate = dateTimePicker1.Value;
                buy.InventoryId = temp.Id;
                buy.Price = price;

                db.TransactionBuys.InsertOnSubmit(buy);
                db.SubmitChanges();

                MessageBox.Show("Inventory is added successfully.");
                dataGridView1.ClearSelection();
                items = (from x in db.ItemInventories where x.ItemId == itemId select x).ToArray();
                dataGridView1.DataSource = items;
                dataGridView1.Columns[0].Visible = false;
                dataGridView1.Columns[1].Visible = false;
                txColor.Text = "";
                txAmount.Text = "";
                txPrice.Text = "";
                txUnit.Text = "";
            }
        }