Ejemplo n.º 1
0
        // создание списка товаров на заказ для вывода в ShowInfoForm
        static public List <ItemOrdersEntity> LoadItemOrdersEntities(int orderID)
        {
            using (var context = new ComputerShopEntities())
            {
                // выборка всех промежуточных сущностей товаров с количеством товара, найденного по ID заказа
                List <OrderItem>        orderIts = context.OrderItems.Where(x => x.OrderID == orderID).Include(x => x.Item).Include("Order").ToList();
                List <ItemOrdersEntity> data     = new List <ItemOrdersEntity>();

                // заполнение форм сущности ItemOrdersEntity данными
                for (int i = 0; i < orderIts.Count(); i++)
                {
                    ItemOrdersEntity ord = new ItemOrdersEntity(
                        item: orderIts[i].Item.ToString(),
                        orderID: orderIts[i].OrderID,
                        quantity: orderIts[i].ItemsQuantity,
                        orderDate: orderIts[i].Order.OrderDate.ToString(),
                        sellerName: orderIts[i].Order.Seller.ToString(),
                        customer: orderIts[i].Order.Customer,
                        customerContact: orderIts[i].Order.CustomerContact,
                        category: orderIts[i].Item.Category.Name
                        );
                    data.Add(ord);
                }
                return(data);
            }
        }
Ejemplo n.º 2
0
 // удаление заказа
 static public void RemoveOrder(ItemOrdersEntity toRemove)
 {
     using (var context = new ComputerShopEntities())
     {
         var original = context.Orders.Find(toRemove.OrderID);
         context.OrderItems.RemoveRange(original.OrderItems);
         context.Entry(original).State = EntityState.Deleted;
         context.SaveChanges();
         MessageBox.Show("Заказ с ID " + toRemove.OrderID + " удален из базы данных!", "Внимание!", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
Ejemplo n.º 3
0
 // конструктор копирования
 public ItemOrdersEntity(ItemOrdersEntity obj)
 {
     this.Item            = obj.Item;
     this.OrderID         = obj.OrderID;
     this.Quantity        = obj.Quantity;
     this.OrderDate       = obj.OrderDate;
     this.SellerName      = obj.SellerName;
     this.Customer        = obj.Customer;
     this.CustomerContact = obj.CustomerContact;
     this.Category        = obj.Category;
 }
Ejemplo n.º 4
0
        // добавление нового товара в заказ
        private void button2_Click(object sender, EventArgs e)
        {
            try
            {
                // создание отдельной сущности заказа с товаром и его количеством
                MainForm.currentItemOrderEntity.SellerName      = comboBox1.SelectedItem.ToString();
                MainForm.currentItemOrderEntity.OrderDate       = dateTimePicker1.Value.ToString();
                MainForm.currentItemOrderEntity.Item            = MainForm.currentItem.Name;
                MainForm.currentItemOrderEntity.Quantity        = Convert.ToInt32(numericUpDown1.Text);
                MainForm.currentItemOrderEntity.Customer        = textBox2.Text;
                MainForm.currentItemOrderEntity.CustomerContact = textBox3.Text;

                // добавление в список товаров нового товара с помощью конструктора копирования
                ItemOrdersEntity newItem = new ItemOrdersEntity(MainForm.currentItemOrderEntity);
                // проверка дублирования добавляемого товара
                foreach (ItemOrdersEntity it in MainForm.currentItemOrdersEntities)
                {
                    if (newItem.Item == it.Item)
                    {
                        MessageBox.Show("Товар уже в заказе!", "Внимание!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                }
                MainForm.currentItemOrdersEntities.Add(newItem);

                // отображение всех товаров в заказе в DataGridView1
                dataGridView1.RowCount    = MainForm.currentItemOrdersEntities.Count;
                dataGridView1.ColumnCount = 2;

                dataGridView1.ReadOnly = true;
                for (int i = 0; i < dataGridView1.RowCount; i++)
                {
                    dataGridView1.Rows[i].Cells[0].Value = MainForm.currentItemOrdersEntities[i].Item;
                    dataGridView1.Rows[i].Cells[1].Value = MainForm.currentItemOrdersEntities[i].Quantity;
                }
            }
            catch
            {
                MessageBox.Show("Ошибка! Проверьте заполненность полей!", "Внимание!", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }