C#RSClientPrint非常大的假脱机

时间:2011-04-13 13:58:19

标签: c# networking .net-3.5 barcode spooler

我正在使用带有DB2后端的ASP .Net 3.5 MVC1。我的公司正在尝试从Microsoft SQL Server 2008 RSCLient打印GDI +对话框中打印条形码。我们无法将文件保存为PDF并打印本地,因为这是针对我们的物理库存应用程序,并且关联人员可能会使用本地条形码做坏事(它们是很好的检查),因此我们不得不通过HTTP打印并控制其打印。每个商店都有一台打印服务器,但Web服务器位于公司IT办公室。我相信我必须使用.jpeg,因为.gif会导致条形码中的线条模糊,扫描枪无法读取。

应用程序可以正常运行几百个标签(大约5页,大约5分钟即可完成打印假脱机),但打印2000个标签需要2个小时(接近300页大约+150 MB)。我在应用程序上运行Wireshark尝试捕获来回的数据包,并将信息传递给网络,这是他们的回应。

  

NO。时间源目标协议信息   36628 653.373235 HTTP [TCP窗口已满]延续或非HTTP流量   36630 654.245430 TCP [TCP ZeroWindowProbe] http> 35503 [ACK] Seq = 26291213 Ack = 3730 Win = 63137 Len = 1

我背后的故事。我的问题是我可以使用什么类型的策略来帮助加速HTTP上的打印假脱机。我是否应该在X页面“切断”打印卷轴并重新打上其余部分?我应该改变我的打印算法吗?如何在不损失.jpeg质量的情况下缩小打印线轴的尺寸?是否有RSClientPrint的开源或商业替代方案可以处理我需要的业务逻辑?

现在编码良好!如果您还有其他需要请告诉我!

        [AcceptVerbs(HttpVerbs.Post)]
    [Authorization(Roles = Roles.NonInquiry)]
    public ActionResult ReprintLabels(int eventId, int areaCode, int lowerLabelNumber, int upperLabelNumber)
    {
        if (!_eventAreaService.IsAreaEditable(eventId, areaCode))
            return RedirectToAction("Index", new { eventId = eventId });

        var printContext = _eventAreaService.ReprintLabels(eventId, areaCode, lowerLabelNumber, upperLabelNumber);

        ActionResult result = RedirectToAction("Index", new { eventId = eventId });
        if (printContext != null)
        {
            var redirectUrl = Url.RouteUrl(new { controller = "EventArea", action = "Index", eventId = eventId });
            Session[PrintContextViewModel.SessionKey] = new PrintContextViewModel(printContext, redirectUrl);

            result = RedirectToAction("PrintLabels", "LabelPrint");
        }

        return result;
    }

public InventoryAreaPrintContext ReprintLabels(int eventId, int areaCode, int lowerLabelBound, int upperLabelBound)
    {
        var user = _authentication.CurrentUser;

        if (user.IsInRole(Roles.CorporateInquiry) || user.IsInRole(Roles.StoreInquiry))
            throw new InvalidOperationException("User must be a non-inquiry role.");

        List<Fixture> fixturesToVoid = GetLabelsInRange(eventId, areaCode, lowerLabelBound, upperLabelBound).Where(f => f.StatusCode == FixtureStatus.Ready).ToList();

        if (fixturesToVoid.Count < 1) return null;

        // Void all old labels and tally the labels that to be recreated
        //      for each area involved.
        var voidFixturesByArea = new Dictionary<int, int>();
        foreach (var f in fixturesToVoid)
        {
            if (!voidFixturesByArea.ContainsKey(f.AreaCode))
                voidFixturesByArea[f.AreaCode] = 1;
            else
                voidFixturesByArea[f.AreaCode]++;

            f.StatusCode = FixtureStatus.VoidReplace;
            _fixtureRepo.Update(f);
        }

        var storeEvent = _storeEventRepository.FindEvent(user.DefaultStore, eventId);
        var lastUsedLabel = storeEvent.LastUsedLabelNumber;
        var affectedAreas = new List<InventoryArea>();

        // Create new labels for the affected areas.
        foreach (var pair in voidFixturesByArea)
        {
            var area = _areaRepo.FindByKey(user.DefaultStore.GroupCode, user.DefaultStore.ID, eventId, pair.Key);
            var fixtures = _fixtureBuilder.AddFixtures(lastUsedLabel.Value, area, pair.Value);
            fixtures.ForEach(f => _fixtureRepo.Insert(f));

            area.Fixtures = fixtures;
            affectedAreas.Add(area);
        }

        // Update the store event counts.
        var numberOfLabels = fixturesToVoid.Count();

        storeEvent.LastUsedLabelNumber += numberOfLabels;

        _storeEventRepository.Update(storeEvent);

        return new InventoryAreaPrintContext(_barcodeGenerator) { InventoryAreas = affectedAreas, StoreEvent = storeEvent, Store = user.DefaultStore };
    }

public class BarcodeGenerator : IBarcodeGenerator
{
    private readonly BarCodeImage.CodeSetEncoder _codeSetEncoder;

    public BarcodeGenerator(BarCodeImage.CodeSetEncoder codeSetEncoder)
    {
        _codeSetEncoder = codeSetEncoder;
    }

    public byte[] CreateBarcode(string barcodeText)
    {
        byte[] data;
        var generator = new BarCodeImage(barcodeText, _codeSetEncoder, true)
                            {
                                InsetText = false,
                                Font = new Font(
                                    FontFamily.GenericSansSerif,
                                    10,
                                    FontStyle.Regular,
                                    GraphicsUnit.Pixel)
                            };

        /** 
         * Keep the image dimensions at the same ratio as they will be displayed in the report.
         * Currently the report is set to a height to width ratio of 1/5 so we set the image
         * height to width at 1/5 as well. Otherwise the barcode will not scan properly.
         **/
        using (var image = generator.Render(50, 250))
        using (var ms = new MemoryStream())
        {
            image.Save(ms, ImageFormat.Jpeg);
            data = ms.GetBuffer();
        }

        return data;
    }
}

1 个答案:

答案 0 :(得分:0)

将图像包装发送到打印假脱机程序时出现了一些问题。我最后做的是使用iTextSharp的条形码128类,基本上用字体而不是图像构建条形码,然后对于人类可读的文本,我只是传入我的条形码对象的fixture标签字符串,并将该值设置为我的值.RDLC报告。如果有人想要任何代码,请随时告诉我。