Printing labels and price tags for .net online store

    Why for an online store, you ask? Of course, for the online store and not only I answer. Typically, large trading companies do not write software for themselves, they order it on the side. And no matter how strange it may seem, very often the hands do not reach the price tag, and this document plays a significant role in trade. I remember the times when the completion of the price tag was 150 euros and then, this task did not seem trivial at all. At the end of the article, the working draft c #, #core, # .net #MVC is attached. Try to experiment with your trading system, thank you in advance for positive feedback.

    So, the owner of an online store (a regular store) decided to modify his boring black and white price tags. And what is in our assortment, you ask?



    In my previousarticle , a sea of ​​complaints raised an xml data source. It seemed obvious to me that experienced programmers could easily adapt the considered example to other sources, but as the comments showed, this turned out to be wrong. Therefore, we will pay a little attention to the data set. We will use the universal component DataSet, I hope that the reader can fill it in a similar way or replace it with another source.

    Let's consider the controller

    public class HomeController : MyController 
        { 
            private IHostingEnvironment _env; 
            public HomeController(IHostingEnvironment env) 
            { 
                _env = env; 
            } 
            public IActionResult Index() 
            { 
                ViewBag.Items = InitData().Tables["Items"].Rows; 
                return View(); 
            } 
            public IActionResult PrintTags() 
            { 
                WebReport webReport = new WebReport(); 
                webReport.Width = "100%"; 
                DataSet d = InitData(); 
                webReport.Report.Load(System.IO.Path.Combine(_env.WebRootPath + "/reports", "tags.frx")); 
                webReport.Report.RegisterData(d, "ItemsDataSet"); 
                webReport.Report.GetDataSource("Items").Enabled = true; 
                (webReport.Report.FindObject("Data1") as DataBand).DataSource = webReport.Report.GetDataSource("Items"); 
                webReport.Report.Prepare(); 
                ViewBag.WebReport = webReport; 
                return View(); 
            } 
        } 
    

    It is the descendant of the MyController class in which the data set is initialized. This is done solely in order not to overload the code of the main controller. The Index page displays a storefront. The PrintTags page provides price tags.

    So, after the data for the output to the price tag has been prepared, we will load the FastReport demo version and develop the price tag



    design. The design is completely spontaneous, you can type any components for your tasks, whether it be barcodes or even pictures. The template file is located in the project at wwwroot / reports / tags.frx, you can fix it or create your own price tag or label depending on where the print will be displayed. Perhaps even this will be an adhesive tape and printed on a thermal label.

    When creating a project, be sure to add links to packages





    In Setup.cs add

    app.UseFastReport(); 
    

    In controllers

    using FastReport; 
    using FastReport.Web; 
    

    All this can be seen in the project.

    Printing of price tags is started by the button Print Tags.

    public IActionResult PrintTags() 
            { 
                WebReport webReport = new WebReport();//создание компонента 
                webReport.Width = "100%";//ширина на всю страницу 
                DataSet d = InitData(); //создаем демо данные  
                webReport.Report.Load(System.IO.Path.Combine(_env.WebRootPath + "/reports", "tags.frx"));//загружаем шаблон отчета 
                webReport.Report.RegisterData(d, "ItemsDataSet");//регистрируем источник данных 
                webReport.Report.GetDataSource("Items").Enabled = true;//выбираем таблицу (их может быть много в наборе данных) 
                (webReport.Report.FindObject("Data1") as DataBand).DataSource = webReport.Report.GetDataSource("Items");//устанавливаем бенду в отчете привязку к данным (бендов и страниц может быть много в отчете) 
                webReport.Report.Prepare();//формируем отчет 
                ViewBag.WebReport = webReport;//выводим на форму 
                return View(); 
            } 
    

    Go to the page on the button Print Tags



    You can then immediately print or download a PDF file



    We print



    or download and send mail.

    Conclusion


    No doubt specialized tools can work wonders. A component that is capable of creating such reports will be useful to any company working with information systems of the ERP class. I saw on a tube companies that work in programs where all reports are made outside the main system in order to reduce the costs of their production. I would be grateful for constructive feedback, all success in building reports.

    Also popular now: