private void DataBind() { try { dgvOrdersList.SelectionChanged -= dgvOrdersList_SelectionChanged; var searchCriteria = string.Empty; var criteriaList = new Collection <string>(); if (!string.IsNullOrEmpty(OrderSearchCriteria)) { criteriaList.Add(OrderSearchCriteria); } if (!string.IsNullOrEmpty(CustomerSearchCriteria)) { var commaSeparatedCustomerIDs = string.Empty; var customerIDs = new Collection <string>(); var customerSearchResults = _customerBusiness.Search(CustomerSearchCriteria).ToList(); if (customerSearchResults.Count > 0) { foreach (var customer in customerSearchResults) { customerIDs.Add(string.Format("'{0}'", customer.id)); } commaSeparatedCustomerIDs = string.Join(",", customerIDs); criteriaList.Add(string.Format("it.recipient_id IN {{{0}}}", commaSeparatedCustomerIDs)); } else { criteriaList.Add("it.recipient_id = ''"); } } searchCriteria = string.Join(" AND ", criteriaList); BindingSource bindingSource = new BindingSource(); bindingSource.DataSource = _business.Search(searchCriteria).ToList(); bindingSource.ResetBindings(false); this.dgvOrdersList.AutoGenerateColumns = false; this.dgvOrdersList.DataSource = bindingSource; this.dgvOrdersList.ClearSelection(); } catch (Exception ex) { AppLogger.logError(this.ToString(), "Error occurs while binding source to orders list data grid view.", ex); } }
private void dgvCustomersList_SelectionChanged(object sender, EventArgs e) { try { if (!string.IsNullOrEmpty(SelectedCustomerID)) { var customer = _business.Get(SelectedCustomerID); PopulateCustomerInfo(customer); string query = string.Format("it.recipient_id = '{0}'", SelectedCustomerID); List <RegularOrder> orders = _regularOrderBusiness.Search(query).ToList(); Collection <RegularOrder> openOrders = new Collection <RegularOrder>(); Collection <RegularOrder> closedOrders = new Collection <RegularOrder>(); foreach (RegularOrder order in orders) { if (order.order_status.Equals(Constants.DeliveryStatus.Closed.ToString())) { closedOrders.Add(order); } else { openOrders.Add(order); } } tbOrdersCount.Text = openOrders.Count.ToString(); tbTotalPayment.Text = CurrencyUtil.ToString(openOrders.Sum(o => o.total_cost)); btnCloseOrders.Enabled = openOrders.Count > 0; OpenOrders = openOrders; ClosedOrders = closedOrders; } } catch (Exception ex) { MessageBox.Show("Có lỗi xảy ra.", Constants.Messages.ERROR_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Error); AppLogger.logError(this.ToString(), ex); } }