Translate

Thứ Năm, 25 tháng 3, 2021

Bài 4: In phiếu bán hàng

 Bài 4: In phiếu bán hàng

Chào các bạn!
Ở bài trước, chúng ta tạo ra phiếu bán hàng (SalesOrder), hôm nay chúng ta tiếp tục in phiếu bán hàng nhé. Chi tiết các bạn tham khảo ở video này

1. Thêm report vào dự án

Bấm chuột phải lên thư mục Sales, chọn Add Devexpress Item>>New Item





Trong cửa sổ Devexpress Template Gallery, Reporting chọn report



Chọn Blank Report. 




2. Design report


Thêm CollectionDataSource vào report


Chỉ định kiểu datasource


3. Đăng ký report

Mở file App.Module.cs
Thêm đoạn code sau để đăng ký:



protected override void Register(IXtraReportService service)
        {
            base.Register(service);
            service.Register<SalesReport>("Phiếu bán hàng",typeof(SalesOrder),true);
        }

4.a Tạo View controller in report

using DevExpress.ExpressApp;
using DevExpress.ExpressApp.Actions;
using System;
using System.Collections.Generic;
using YouSoft.Vn.XAFCustom.Supports.Extensions;
using System.Text;

namespace App.Module.Modules.Sales
{
    public class SalesOrderViewController:ViewController
    {
        SimpleAction printReport;
        public SalesOrderViewController()
        {
            TargetObjectType = typeof(SalesOrder);
            printReport = new SimpleAction() { 
                Id=nameof(printReport),
                Caption="In phiếu",
                TargetObjectType=typeof(SalesOrder)
            };
            Actions.Add(printReport);
            printReport.Execute += PrintReport_Execute;
        }

        private void PrintReport_Execute(object sender, SimpleActionExecuteEventArgs e)
        {
            this.ShowReportForCurrentObject<SalesReport>();
        }
    }
}

Đăng ký Controller

protected override void Register(ModuleControllerService service)
        {
            base.Register(service);
            service.Register<ProductViewController>()
                .Register < SalesOrderViewController>();
        }

Chạy chương trình



4.b Tạo View controller in report

Tới đây bạn đã biết cách hiển thị report từ action như thế nào. Thật tuyệt vời phải không?
Tuy nhiên còn một cách tuyệt vời hơn, bạn không cần phải tạo controller action.
Mở lớp SalesOrder chỉ cần implement interface IReportPrintable như bên dưới là chạy được




using App.Module.Modules.Sales;
using DevExpress.ExpressApp.DC;
using DevExpress.ExpressApp.Model;
using DevExpress.Persistent.Base;
using DevExpress.Xpo;
using ModuleBase.Entities;
using System;
using System.ComponentModel;
using System.Linq;
using YouSoft.Vn.Framework.Core.Utilities;
using YouSoft.Vn.XAFCustom.Core.Entities;
using YouSoft.Vn.XAFCustom.Supports;
using YouSoft.Vn.XAFCustom.Supports.Attributes.Validation;
using YouSoft.Vn.XAFCustom.Supports.Interfaces;

namespace App.Module.Modules.Sales
{
    [XafDisplayName("Đơn hàng")]
    [ImageName("BO_SalesOrder")]
    [VisibleInDashboards]
    [VisibleInReports]
    [LookupEditorMode(LookupEditorMode.AllItemsWithSearch)]
    public partial class SalesOrder : YsvObject,IReportPrintable
    {

        //..............
        [Browsable(false)]
        public bool Printable => true;
        [Browsable(false)]
        public Type ReportType => typeof(SalesReport);
    }
}
Chúc các bạn thành công.

Không có nhận xét nào:

Đăng nhận xét