private void orderIDComboBox_SelectedIndexChanged(object sender, EventArgs e) { int selectedID = (int)orderIDComboBox.SelectedValue; try { current = OrderDB.GetOrderByID(selectedID); DisplayCurrentCustomerData(); ordDetails = OrderDetailsDB.GetOrderDetailIDs(selectedID); orderDetailDataGridView.DataSource = ordDetails; //ordDetails //Calculating order total float total = 0; foreach (OrderDetail order in ordDetails) { total += order.OrderTotal; } string Total = total.ToString(); textOrderTotal.Text = total.ToString("c2"); } catch (Exception ex) { MessageBox.Show("Error while retrieving customer with selected ID: " + ex.Message, ex.GetType().ToString()); } }
//called to refresh all the fields and datagridview private void populateFields(Button disableButton, Button enableButton, int index) { orders = OrderDB.GetOrders(); txtOrderID.Text = orders[index].OrderID.ToString(); txtCustomerID.Text = orders[index].CustomerID; dtpOrderDate.Value = (DateTime)orders[index].OrderDate; dtpRequiredDate.Value = (DateTime)orders[index].RequiredDate; if (orders[index].ShippedDate != null) // if the shippeddate is not null { dtpShippedDate.Format = DateTimePickerFormat.Long; dtpShippedDate.Value = (DateTime)orders[index].ShippedDate; isNull = false; } else //shipped date is null { dtpShippedDate.CustomFormat = " "; dtpShippedDate.Format = DateTimePickerFormat.Custom; isNull = true; } List <OrderDetails> orderDetails_List = OrderDetailsDB.GetOrdersDetails(orders[index].OrderID); dgvOrderDetails.DataSource = orderDetails_List; txtTotalCharges.Text = CalculateCharges(orderDetails_List).ToString("c"); Disablebuttion(disableButton, enableButton, index); }