private void LoadData() { ClearData(); foreach (Order order in Order.GetFreeOrders()) { freeOrdersListView.Items.Add(new ListViewItem(new string[] { order.Id.ToString(), order.AddressFrom, order.AddressTo })); } if (Order.GetAcceptedOrders().Count > 0) { foreach (Order order in Order.GetAcceptedOrders()) { acceptedOrdersListView.Items.Add(new ListViewItem(new string[] { order.Id.ToString(), order.AddressFrom, order.AddressTo, order.Driver.Id.ToString() })); } } foreach (Order order in Order.GetInProgressOrders()) { executingOrdersListView.Items.Add(new ListViewItem(new string[] { order.Id.ToString(), order.AddressFrom, order.AddressTo, order.Driver.Id.ToString() })); } foreach (Driver driver in OnlineDrivers.GetOnlineDrivers()) { driversListView.Items.Add(new ListViewItem(new string[] { driver.Id.ToString(), driver.Status.ToString(), driver.Model })); } }
private void SetOrderCompleted(object sender, EventArgs e) { if (executingOrdersListView.SelectedItems.Count > 0) { Order selectedOrder = Order.GetInProgressOrders().Where(o => o.Id.ToString() == executingOrdersListView.SelectedItems[0].SubItems[0].Text).First(); selectedOrder.Status = OrderStatuses.Сompleted; selectedOrder.SaveChanges(); Driver currentDriver = OnlineDrivers.GetOnlineDrivers().Where(d => d.Id.ToString() == executingOrdersListView.SelectedItems[0].SubItems[3].Text).First(); if (currentDriver != null) { currentDriver.Status = DriverStatuses.Free; currentDriver.SaveChanges(); } } }
private void appointDriverBtn_Click(object sender, EventArgs e) { if (driverComboBox.SelectedIndex != -1) { Driver currentDriver = OnlineDrivers.GetOnlineDrivers().Where(d => d.Id.ToString() == driverComboBox.SelectedItem.ToString()).First(); currentOrder.Driver = currentDriver; currentDriver.Status = DriverStatuses.NotFree; currentDriver.SaveChanges(); currentOrder.Status = OrderStatuses.Accepted; currentOrder.SaveChanges(); currentOrder.SaveDriver(); Close(); } }