Bài 08: Chọn nhiều hàng vào đơn hàng
Nội dung:- Tạo OrderItemViewController
- Tạo PopupWindowShowAction để chọn Products_ListView
- Thêm hàng hóa đã chọn vào đơn hàng
- Hiển thị Products_ListView dưới dạng chọn CheckBox
- Chạy thử với phiên bản web, blazor
1. Tạo ViewController cho OrderItem
using App.Module.Modules.Inventory.Entities;
using DevExpress.ExpressApp;
using DevExpress.ExpressApp.Actions;
using System;
using System.Linq;
using YouSoft.Vn.XAFCustom.Supports.Extensions;
namespace App.Module.Modules.Sales
{
public class OrderItemViewController : ViewController<ListView>
{
PopupWindowShowAction selectProductsAction;
public OrderItemViewController()
{
TargetObjectType = typeof(OrderItem);
TargetViewNesting = Nesting.Nested;
selectProductsAction = new PopupWindowShowAction()
{
Id = nameof(selectProductsAction),
Caption = "Chọn hàng",
TargetObjectType = typeof(OrderItem),
TargetViewNesting = Nesting.Nested,
SelectionDependencyType=SelectionDependencyType.Independent
};
Actions.Add(selectProductsAction);
selectProductsAction.CustomizePopupWindowParams += SelectProductsAction_CustomizePopupWindowParams;
selectProductsAction.Execute += SelectProductsAction_Execute;
}
private void SelectProductsAction_Execute(object sender, PopupWindowShowActionExecuteEventArgs e)
{
if (View.GetRawMasterObject() is SalesOrder order)
{
var products = e.PopupWindowViewSelectedObjects
.Cast<Product>()
.ToList();
foreach(var product in products)
{
order.Add(product);
}
}
}
private void SelectProductsAction_CustomizePopupWindowParams(object sender, CustomizePopupWindowParamsEventArgs e)
{
e.SetListView<Product>("", false, false);
}
}
}
Kiểm tra kết quả2. Thêm hàm Add product vào lớp SalesOrder
public void Add(Product product, double quantity = 1) { var item =OrderItems.FirstOrDefault(i => i.Product == product); if (item == null) { item = new OrderItem(Session) { Product = Session.CloneObject(product) }; OrderItems.Add(item); } item.Quantity += quantity; }
3. Trong windows, hiển thị list view với checkbox cho user chọn
3.1 Clone Product_ListView
Sửa các thuộc tính như trong hình
3.2 Đăng ký trong App.Module.cs
protected override void Register(ICheckboxListViewService service)
{
base.Register(service);
service.Register("Product_ListView_Popup");
}





































