BomKhung.Com Đã Quay Trở Lại
Hoạt Động Dưới Tên Miền Hung.Pro.VN
00 Days
00 Hours
00 Minutes
00 Seconds
Hiện website đang cập nhật nội dung bài viết, nếu có lỗi gì mọi người có thể thông báo cho mình Tại đây!

[DEVEXPRESS] How to make Label Report in c# winform

Xin chào các bạn, bài viết hôm nay mình chia sẻ các bạn source code, tạo báo cáo report in tem nhãn dùng quản lý thông tin thiết bị, tài sản của công ty hoặc cá nhân.

[DEVEXPRESS] Chia sẻ source code tạo báo cáo report in tem nhãn label trên C# winform

Dưới đây là hình ảnh demo ứng dụng C#:

[DEVEXPRESS] How to make Label Report in c# winform

Source code C#:

1, Code FormMain.cs
using DevExpress.Export;
using DevExpress.XtraPrinting;
using DevExpress.XtraReports.UI;
using System;
using System.Data;
using System.Data.OleDb;
using System.Windows.Forms;
using DevExpress.XtraGrid.Views.Grid;
using DevExpress.XtraEditors;
using report;

namespace VNSoftware.frmDongThung
{
    public partial class TaoMaVachcs : DevExpress.XtraEditors.XtraForm
    {
        private DataTable yourDataTable;



        public TaoMaVachcs()
        {
            InitializeComponent();
            InitializeDataTable();
            InitDataDemo();
            dtgv.DataSource = yourDataTable;
        }

        private void InitializeDataTable()
        {           
            yourDataTable = new DataTable();
            yourDataTable.Columns.Add("MA HANG", typeof(string));
            yourDataTable.Columns.Add("VERSION", typeof(string));
            yourDataTable.Columns.Add("SO LUONG/ THUNG", typeof(string));
            yourDataTable.Columns.Add("Ma Cty", typeof(string));
            yourDataTable.Columns.Add("MA VUNG", typeof(string));
            yourDataTable.Columns.Add("LOT DH", typeof(string));
            yourDataTable.Columns.Add("SO TT THUNG", typeof(string));
            yourDataTable.Columns.Add("Ma trong", typeof(string));
            yourDataTable.Columns.Add("QRCODE", typeof(string));
        }
        public int GetRandomNumber(int min, int max)
        {
            Random random = new Random();
            return random.Next(min, max + 1);
        }
        private void InitDataDemo()
        {
            try
            {
                string mahang = "SP240116-01";
                mahang = mahang.PadRight(22);
                string ver = "0";
                ver = ver.PadRight(12);
                string soluong = GetRandomNumber(1, 1500).ToString();
                soluong = soluong.PadRight(14);
                string macty = "LAPTRINHVB2015";
                macty = macty.PadRight(16);
                string mavung = "VBNET";
                string lot = "123456";
                string matrong ="0";
                int j = 0;
                int k = 100;


              
                for (int i = j; i <= k; i++)
                {
                   string sothutu = i.ToString("0000");
                  string qrcode = $"{mahang}{ver}{soluong}{macty}{mavung}{lot}{sothutu}{matrong}";
                    DataRow newRow = yourDataTable.NewRow();
                    newRow["MA HANG"] = mahang;
                    newRow["VERSION"] = ver;
                    newRow["SO LUONG/ THUNG"] = soluong.Trim();
                    newRow["Ma Cty"] = macty;
                    newRow["MA VUNG"] = mavung;
                    newRow["LOT DH"] = lot;
                    newRow["SO TT THUNG"] = sothutu;
                    newRow["Ma trong"] = matrong;
                    newRow["QRCODE"] = qrcode;                
                    yourDataTable.Rows.Add(newRow);
                }           
                gridView1.BestFitColumns();
            }
            catch (FormatException)
            {
                MessageBox.Show("Không thể chuyển đổi chuỗi sang số nguyên.");
            }

        }

        private void btnInNhan_Click(object sender, EventArgs e)
        {
            if (yourDataTable.Rows.Count <= 0)
            {
                XtraMessageBox.Show("Chưa có dữ liệu để in nhãn");
                return;
            }
            var loaiReport = 1;
            var formPrintPreview = new FrmPrintPreview(loaiReport, yourDataTable);
            formPrintPreview.Show();
        }
    }
}

2. Source code form FrmPrintPreview.cs

amespace report
{
    public partial class FrmPrintPreview : DevExpress.XtraBars.Ribbon.RibbonForm
    {
        public int _loaiReport;
        public object _dataTable;
        public FrmPrintPreview(int loaiReport, object dataTable)
        {
            InitializeComponent();
            this._loaiReport = loaiReport;
            this._dataTable = dataTable;

        

        }

        protected override void OnShown(EventArgs e)
        {
            base.OnShown(e);
           
            switch (_loaiReport)
            {
                case 1:
                    {
                        Text = @"IN TEM NHÃN LABEL";
                        var rpt = new reportLabel1();
                        documentViewer1.PrintingSystem = rpt.PrintingSystem;
                        rpt.DataSource = _dataTable;
                        rpt.BindData();
                        rpt.CreateDocument();
                    }
                    break;
            }
        }
    }
}

3. Source code reportLabel1.cs

namespace report
{
    public partial class reportLabel1 : DevExpress.XtraReports.UI.XtraReport
    {
        public reportLabel1()
        {
            InitializeComponent();
        }

        public void BindData()
        {
            txtMaHang.DataBindings.Add("Text", DataSource, "MA HANG");
            txtSoThuTu.DataBindings.Add("Text", DataSource, "SO TT THUNG");
            txtVersion.DataBindings.Add("Text", DataSource, "VERSION");
            txtSoluong.DataBindings.Add("Text", DataSource, "SO LUONG/ THUNG").FormatString = "{0:#,###.##} Pcs";

            txtLotDH.DataBindings.Add("Text", DataSource, "LOT DH");
            txtMaVung.DataBindings.Add("Text", DataSource, "MA VUNG");
            xrBarCode1.DataBindings.Add("Text", DataSource, "QRCODE");
        }
    }
}

Chúc các bạn thành công với thủ thuật trên, để tích hợp để phù hợp với công việc của các bạn nhé

DOWNLOAD SOURCE CODE


PASSWORD UNZIP : HUNG.PRO.VN

Đăng nhận xét

Đồng ý sữ dụng cookie
Chúng tôi sử dụng cookie trên trang web này để phân tích lưu lượng truy cập, ghi nhớ tùy chọn của bạn và tối ưu hóa trải nghiệm của bạn.
Xem thêm
Oops!
Có vẻ như kết nối internet của bạn có vấn đề. Vui lòng kết nối lại và duyệt web.
AdBlock Detected!
Chúng tôi phát hiện bạn đang sử dụng plugin chặn quảng cáo trong trình duyệt của mình.
Doanh thu chúng tôi kiếm được từ quảng cáo được sử dụng để quản lý trang web này, chúng tôi yêu cầu bạn đưa trang web của chúng tôi vào danh sách trắng trong plugin chặn quảng cáo của bạn.
Site is Blocked
Sorry! This site is not available in your country.
Kỹ thuật số thế hệ tiếp theo Chào mừng bạn đến với trò chuyện WhatsApp
Xin chào! Chúng tôi có thể giúp gì cho bạn hôm nay?
Nhập vào đây...