Exemplo n.º 1
0
        public void SetOrder(Order order)
        {
            DataRow row = _db._ds.Tables["Order"].Rows.Find(order.Id);

              if (row == null)
              {
            row = _db._ds.Tables["Order"].NewRow();

            row["Id"] = order.Id;
            row["Category"] = order.Category;
            row["ClientId"] = order.ClientId;
            row["DeliveryAdress"] = order.DeliveryAdress;
            row["DeliveryDate"] = order.DeliveryDate;
            row["EmployeeId"] = order.EmployeeId;
            row["OrderDate"] = order.OrderDate;
            row["Sum"] = order.Sum;

            _db._ds.Tables["Order"].Rows.Add(row);

            _db._adapterOrder.Update(_db._ds.Tables["Order"]);

            foreach (var pair in order.Products)
            {
              DataRow dr = _db._ds.Tables["Products_in_Order"].NewRow();
              dr["Id"] = pair.Value.Id;
              dr["OrderId"] = pair.Value.OrderId;
              dr["ProductId"] = pair.Value.ProductId;
              dr["Quantity"] = pair.Value.Quantity;
              dr["FinalPrice"] = pair.Value.FinalPrice;
              dr["Sum"] = pair.Value.Sum;

              _db._ds.Tables["Products_in_Order"].Rows.Add(dr);

              _db._adapterProducts_in_Order.Update(_db._ds.Tables["Products_in_Order"]);
            }
              }
              else
              {
            row["Id"] = order.Id;
            row["Category"] = order.Category;
            row["ClientId"] = order.ClientId;
            row["DeliveryAdress"] = order.DeliveryAdress;
            row["DeliveryDate"] = order.DeliveryDate;
            row["EmployeeId"] = order.EmployeeId;
            row["OrderDate"] = order.OrderDate;
            row["Sum"] = order.Sum;

            _db._adapterOrder.Update(_db._ds.Tables["Order"]);

            DataRow[] pios = _db._ds.Tables["Products_in_Order"].Select("OrderId = " + order.Id).ToArray();

            foreach (DataRow r in pios)
            {
              r.Delete();
            }

            _db._adapterProducts_in_Order.Update(_db._ds.Tables["Products_in_Order"]);

            foreach (var pair in order.Products)
            {
              DataRow dr = _db._ds.Tables["Products_in_Order"].Rows.Find(pair.Value.Id);
              dr["Id"] = pair.Value.Id;
              dr["OrderId"] = pair.Value.OrderId;
              dr["ProductId"] = pair.Value.ProductId;
              dr["Quantity"] = pair.Value.Quantity;
              dr["FinalPrice"] = pair.Value.FinalPrice;
              dr["Sum"] = pair.Value.Sum;

              _db._ds.Tables["Products_in_Order"].Rows.Add(dr);
            }

            _db._adapterProducts_in_Order.Update(_db._ds.Tables["Products_in_Order"]);
              }

              _db._adapterProduct.Fill(_db._ds.Tables["Product"]);
              _db._adapterEmployee.Fill(_db._ds.Tables["Employee"]);
              _db._adapterClient.Fill(_db._ds.Tables["Client"]);

              OnDBChanged(_db);
        }
Exemplo n.º 2
0
        public void RemoveOrder(Order order)
        {
            DataRow[] rows = _db._ds.Tables["Products_in_Order"].Select("OrderId = " + order.Id).ToArray();

              foreach (DataRow row in rows)
              {
            row.Delete();
              }

              _db._adapterProducts_in_Order.Update(_db._ds.Tables["Products_in_Order"]);

              DataRow rowInOrder = _db._ds.Tables["Order"].Rows.Find(order.Id);

              rowInOrder.Delete();

              _db._adapterOrder.Update(_db._ds.Tables["Order"]);

              _db._adapterProduct.Fill(_db._ds.Tables["Product"]);
              _db._adapterEmployee.Fill(_db._ds.Tables["Employee"]);
              _db._adapterClient.Fill(_db._ds.Tables["Client"]);

              OnDBChanged(_db);
        }