Beispiel #1
0
        protected int drawShift(Graphics g, ShiftForPrinting protocol)
        {
            PrinterGraphics printerG = new PrinterGraphics(g, protocol.PrinterFormat.PaperSize, protocol.PrinterFormat.Font, protocol.PrinterFormat.PaddingRight);

            decimal receivablePriceAll = 0, realPriceAll = 0;

            printerG.DrawStringLine($"交接班", protocol.PrinterFormat.ShiftBigFontSize, align: StringAlignment.Center);
            foreach (Shift shift in protocol.Shifts)
            {
                printerG.DrawStringLine($"班次: {shift.Id}", protocol.PrinterFormat.ShiftFontSize);
                printerG.DrawStringLine($"时间: {shift.DateTime.ToString("yyyy-MM-dd HH:mm:ss")}", protocol.PrinterFormat.ShiftFontSize);

                printGrid433(printerG, new string[] { "支付名称", "应收", "实收" }, protocol.PrinterFormat.ShiftSmallFontSize);
                foreach (ShiftDetail detail in shift.ShiftDetails)
                {
                    receivablePriceAll += detail.ReceivablePrice;
                    realPriceAll       += detail.RealPrice;
                    printGrid433(printerG, new string[] { detail.PayKind, $"¥{detail.ReceivablePrice}", $"¥{detail.RealPrice}" }, protocol.PrinterFormat.ShiftFontSize);
                }
                printHr(printerG);
            }

            printerG.DrawStringLine("总计:", protocol.PrinterFormat.ShiftSmallFontSize);
            printGrid55f(printerG, new string[] { "应收", $"¥{receivablePriceAll}" }, protocol.PrinterFormat.ShiftFontSize);
            printGrid55f(printerG, new string[] { "实收", $"¥{realPriceAll}" }, protocol.PrinterFormat.ShiftFontSize);
            printGrid55f(printerG, new string[] { "盈亏", $"¥{(realPriceAll - receivablePriceAll)}" }, protocol.PrinterFormat.ShiftFontSize);

            printEnd(printerG);

            g.Dispose();

            return(printerG.GetHeight());
        }
Beispiel #2
0
        protected Bitmap generateShiftBmp(ShiftForPrinting protocol)
        {
            Bitmap   bmp        = new Bitmap(protocol.PrinterFormat.PaperSize, maxHeight);
            Graphics g          = Graphics.FromImage(bmp);
            int      realHeight = drawShift(g, protocol);

            return(cutBmp(bmp, realHeight));
        }
Beispiel #3
0
        public async Task Print(ShiftForPrinting protocol)
        {
            handleIPPrinterFormat(protocol.PrinterFormat);

            IPAddress ip  = IPAddress.Parse(protocol.Printer.IpAddress);
            Bitmap    bmp = generateShiftBmp(protocol);
            await IPPrinter.GetInstance().Print(ip, bmp, protocol.PrinterFormat.ColorDepth);
        }
Beispiel #4
0
        public void Printer(ShiftForPrinting protocol)
        {
            PrintDocument pd = new PrintDocument();

            pd.PrinterSettings.PrinterName = protocol.Printer.Name;
            pd.PrintPage += (sender, e) => {
                drawShift(e.Graphics, protocol);
            };
            pd.Print();
        }
        async Task <ShiftForPrinting> getShiftsForPrinting(List <int> ids, DateTime dateTime)
        {
            object postData = new {
                HotelId  = Config.HotelId,
                Ids      = ids,
                DateTime = dateTime
            };
            string response = await HttpPost.PostAsync(Config.RemoteGetShiftsForPrintingUrl, postData);

            if (response == null)
            {
                return(null);
            }

            ShiftForPrinting protocol = JsonConvert.DeserializeObject <ShiftForPrinting>(response);

            return(protocol);
        }
        /// <summary>
        /// 打印交接班
        /// </summary>
        async Task printShifts(List <int> Ids, DateTime dateTime)
        {
            ShiftForPrinting sp = null;

            try {
                sp = await getShiftsForPrinting(Ids, dateTime);

                if (sp == null)
                {
                    serverLog("获取交接班信息失败,请检查网络设置", LogLevel.Error);
                    return;
                }
                ShiftPrinter shiftPrinter = new ShiftPrinter();
                serverLog($"发送打印命令 交接班", LogLevel.Info);

                await shiftPrinter.Print(sp);

                serverLog($"发送命令成功 交接班", LogLevel.Success);
            }
            catch (Exception e) {
                serverLog($"无法打印 交接班, 错误信息: {e.Message}", LogLevel.Error);
                remoteLog(Log.LogLevel.Error, $"ShiftInfos, {e.Message}", $"Data: {JsonConvert.SerializeObject(sp)}, Error: {e}");
            }
        }