/// <summary> /// Đổ dữ liệu vào Thông tin Mặt hàng khi click vào bảng Hóa đơn /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void gridControlOrders_MouseDown(object sender, MouseButtonEventArgs e) { try { OrderTableModel model = gridControlOrders.SelectedItem as OrderTableModel; Models.Order order = App.orderController.getById(model.Id); List <OrderLineTableModel> orderLines = OrderLineTableModel.ToListByListOrderLine(order.OrderLines.ToList()); gridControlOrderLines.ItemsSource = orderLines; txtOrderId.Text = order.Id.ToString(); txtOrderCreateTime.Text = order.CreateTime.ToString("dd/MM/yyyy HH:mm:ss"); txtOrderCreatedBy.Text = order.Account?.Name ?? ""; txtOrderDetail.Text = order.Detail; txtOrderGuestName.Text = order.GuessName; txtOrderGuestEmail.Text = order.GuessEmail; txtOrderGuestPhone.Text = order.GuessPhone; txtOrderGuestAddress.Text = order.GuessAddress; txtOrderTotalPrice.Text = Helpers.MoneyHelper.PriceToVND(order.TotalPrice); txtOrderPaidPrice.Text = Helpers.MoneyHelper.PriceToVND(order.PaidPrice); txtOrderVATPrice.Text = Helpers.MoneyHelper.PriceToVND(order.VATPrice); txtOrderDiscountPrice.Text = Helpers.MoneyHelper.PriceToVND(order.Discount); btnPrint.Visibility = Visibility.Visible; } catch (Exception) { } }
/// <summary> /// Đổ dữ liệu vào khung Thông tin Mặt hàng khi click chuột vào bảng Dòng Hóa đơn /// </summary> private void gridControlOrderLines_MouseDown(object sender, MouseButtonEventArgs e) { try { OrderLineTableModel item = gridControlOrderLines.SelectedItem as OrderLineTableModel; Models.Product product = App.productController.GetById(item.ProductId); txtProductId.Text = product.Id.ToString(); txtProductBarCode.Text = product.BarCode; txtProductName.Text = product.Name; txtProductPrice.Text = product.Price.ToString(); txtProductQuantity.Text = item.Quantity.ToString(); txtProductTotalPrice.Text = item.TotalPrice; try { imageProductPicture.EditValue = System.IO.File.ReadAllBytes(App.BaseImageDirectory + "Product\\" + product.Picture); } catch (Exception ex) { imageProductPicture.EditValue = System.IO.File.ReadAllBytes(App.DefaultProductImagePath); } btnAddProduct.Visibility = Visibility.Hidden; btnRemoveProduct.Visibility = Visibility.Visible; btnSaveChangeOrderLineProduct.Visibility = Visibility.Visible; } catch (Exception) { } }
/// <summary> /// Xóa Mặt hàng khỏi Hóa đơn /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnRemoveProduct_Click(object sender, RoutedEventArgs e) { try { Convert.ToInt32(txtProductId.Text); } catch (Exception) { MessageBox.Show( "Mã số sản phẩm không hợp lệ", "Cập nhật Hóa đơn", MessageBoxButton.OK, MessageBoxImage.Warning); return; } List <OrderLineTableModel> orderLines = gridControlOrderLines.ItemsSource as List <OrderLineTableModel>; if (orderLines == null) { MessageBox.Show( "Hóa đơn rỗng", "Cập nhật Hóa đơn", MessageBoxButton.OK, MessageBoxImage.Warning); return; } Models.Product product = App.productController.GetById(Convert.ToInt32(txtProductId.Text)); OrderLineTableModel orderLine = null; try { orderLine = orderLines.Single(m => m.ProductId == product.Id); } catch (Exception) { orderLines = null; } if (orderLine != null) { orderLines.Remove(orderLine); gridControlOrderLines.ItemsSource = orderLines; gridControlOrderLines.RefreshData(); ClearProductInformations(); } ReLoadOrderDetail(); }
private void gridControlOrdersToday_MouseDown(object sender, MouseButtonEventArgs e) { try { OrderTableModel model = gridControlOrdersToday.SelectedItem as OrderTableModel; Models.Order order = App.orderController.getById(model.Id); List <OrderLineTableModel> orderLines = OrderLineTableModel.ToListByListOrderLine(order.OrderLines.ToList()); gridControlOrderLinesToday.ItemsSource = orderLines; ((TableView)gridControlOrderLinesToday.View).BestFitColumns(); } catch (Exception ex) { } }
/// <summary> /// Cập nhật dòng hóa đơn /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnSaveChangeOrderLineProduct_Click(object sender, RoutedEventArgs e) { if (String.IsNullOrWhiteSpace(txtProductQuantity.Text)) { MessageBox.Show( "Vui lòng nhập Số lượng", "Cập nhật Hóa đơn", MessageBoxButton.OK, MessageBoxImage.Warning); txtProductQuantity.Focus(); return; } try { if (Convert.ToInt32(txtProductQuantity.Text) <= 0) { MessageBox.Show( "Vui lòng nhập Số lượng là một số lớn hơn 0", "Cập nhật Hóa đơn", MessageBoxButton.OK, MessageBoxImage.Warning); txtProductQuantity.Focus(); return; } } catch (Exception) { MessageBox.Show( "Vui lòng nhập Số lượng là một số lớn hơn 0", "Cập nhật Hóa đơn", MessageBoxButton.OK, MessageBoxImage.Warning); txtProductQuantity.Focus(); return; } try { List <OrderLineTableModel> orderLines = gridControlOrderLines.ItemsSource as List <OrderLineTableModel>; if (orderLines == null) { orderLines = new List <OrderLineTableModel>(); } Models.Product product = App.productController.GetById(Convert.ToInt32(txtProductId.Text)); int quantity = Convert.ToInt32(txtProductQuantity.Text); OrderLineTableModel orderLine = null; try { orderLine = orderLines.Single(m => m.ProductId == product.Id); } catch (Exception) { orderLine = null; } if (product.Status == 1) { MessageBox.Show( "Mặt hàng hiện tạm ngưng, không bán.", "Thêm Mặt hàng vào Hóa đơn", MessageBoxButton.OK, MessageBoxImage.Warning); return; } if (!product.Quantity.HasValue || (orderLine == null && quantity > product.Quantity.Value) || (orderLine != null && quantity > product.Quantity.Value) ) { MessageBox.Show( "Số lượng vượt quá tồn kho", "Cập nhật dòng Hóa đơn", MessageBoxButton.OK, MessageBoxImage.Warning); txtProductQuantity.Focus(); return; } if (orderLine == null) { orderLines.Add( new OrderLineTableModel( orderLines.Count + 1, product, quantity ) ); } else { orderLine.Quantity = quantity; orderLine.TotalPrice = Helpers.MoneyHelper.PriceToVND((long)(product.Price * orderLine.Quantity + ((product.Price * orderLine.Quantity) / 10))); } gridControlOrderLines.ItemsSource = orderLines; gridControlOrderLines.RefreshData(); ((TableView)gridControlOrderLines.View).BestFitColumns(); ReLoadOrderDetail(); } catch (Exception) { MessageBox.Show( "Cập nhật Hóa đơn thất bại", "Cập nhật Hóa đơn", MessageBoxButton.OK, MessageBoxImage.Warning); } }