public OrdersView()
        {
            InitializeComponent();

            comboBox1.DataSource = ((NORTHWNDEntities)c1DataSource1.ClientCache.DbContext).Cities.ToList();

            // Define and bind a live view on top of the Orders EntityViewSource
            // sorted by the total cost in descending order.
            bindingSource1.DataSource = _ordersView =
                from o in c1DataSource1["Orders"].AsLive <Order>()
                // Order cost is the sum of order detail costs.
                let totalCost = o.Order_Details.Sum(od => od.Quantity * od.UnitPrice * (1m - (decimal)od.Discount))
                                orderby totalCost descending
                                select new OrderInfo()
            {
                Order        = o,
                OrderID      = o.OrderID,
                OrderDate    = o.OrderDate,
                CustomerName = o.Customer.CompanyName,
                TotalCost    = totalCost,
                OrderDetails = o.Order_Details.AsLive()
            };

            dataGridView1.DataSource = bindingSource1;
        }
예제 #2
0
        public EditOrders()
        {
            InitializeComponent();

            // Define and bind a live view on top of the Orders EntityViewSource
            // sorted by the total cost in descending order.
            dataGrid1.ItemsSource = _ordersView =
                from o in dataSource["Orders"].AsLive <Orders.Order>()
                // Order cost is the sum of order detail costs.
                let totalCost = o.Order_Details.Sum(od => od.Quantity * od.UnitPrice * (1m - (decimal)od.Discount))
                                orderby totalCost descending
                                select new OrderInfo()
            {
                Order        = o,
                OrderID      = o.OrderID,
                OrderDate    = o.OrderDate,
                Customer     = o.Customer,
                TotalCost    = totalCost,
                OrderDetails = o.Order_Details.AsLive()
            };
        }
예제 #3
0
        private void DataGrid1_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
        {
            // Rebind the data grid, display the order details of the selected order.
            // If the "checkDiscontinued" check box is checked, show only the order details for discontinued products.
            var item = dataGrid1.SelectedItem as OrderInfo;

            if (item != null)
            {
                dataGrid2.ItemsSource = _orderDetailsView =
                    from od in item.OrderDetails
                    where (!checkDiscontinued.IsChecked ?? true) || od.Product.Discontinued
                    select new OrderDetailInfo()
                {
                    ProductID = od.ProductID,
                    Product   = od.Product,
                    Quantity  = od.Quantity,
                    UnitPrice = od.UnitPrice,
                    Discount  = od.Discount,
                    TotalCost = od.Quantity * od.UnitPrice * (1m - (decimal)od.Discount)
                }
            }
            ;
        }
        private void bindingSource1_CurrentChanged(object sender, EventArgs e)
        {
            if (bindingSource1.Current == null)
            {
                return;
            }

            // Rebind the data grid, display the order details of the selected order.
            // If the "checkBox1" check box is checked, show only the order details for discontinued products.
            OrderInfo oi = (bindingSource1.Current as ViewRow).Value as OrderInfo;

            dataGridView2.DataSource = _orderDetailsView =
                from od in oi.OrderDetails
                where !checkBox1.Checked || od.Product.Discontinued
                select new OrderDetailInfo()
            {
                ProductID   = od.ProductID,
                ProductName = od.Product.ProductName,
                Quantity    = od.Quantity,
                UnitPrice   = od.UnitPrice,
                Discount    = od.Discount,
                TotalCost   = od.Quantity * od.UnitPrice * (1m - (decimal)od.Discount)
            };
        }