Пример #1
0
        private async void Button_Clicked_1(object sender, EventArgs e)
        {
            IPosPrinter printer = DependencyService.Get <IPosPrinter>();

            if (printer == null)
            {
                await DisplayAlert("Error", "Printer is NULL", "OK");
            }
            else
            {
                await printer.Print();
            }
        }
Пример #2
0
        public void PrintWorkSaleSummary(int id)
        {
            string sql    = @"select w.CreatedByName,s.Name as StoreName,w.PosId,w.StartDate,w.EndDate,t.TotalAmount,t.TotalOnlineAmount,t.paymentWay from WorkSchedule w left join (
select o.WorkScheduleCode,total(OrderAmount) as TotalAmount,total(OnlinePayAmount) as TotalOnlineAmount,paymentWay from  saleorder o where o.Status = 3 group by o.WorkScheduleCode,o.paymentWay
) t on t.WorkScheduleCode = w.Code
inner join Store s on s.Id = w.StoreId
where w.Id=@Id";
            var    models = _query.Query <WorkSaleSummaryDto>(sql, new { Id = id }).ToList();

            if (models.Count == 0)
            {
                throw new Exception("没有数据");
            }
            string template = FileHelper.ReadText("WorkSaleSummaryTemplate.txt");

            if (string.IsNullOrEmpty(template))
            {
                throw new AppException("收银汇总模板为空");
            }
            template = template.ToLower();
            var lineLocation = template.LastIndexOf("##itemtemplate##");
            //分离商品item模板
            string billTemplate = template.Substring(0, lineLocation);
            var    itemStr      = template.Substring(lineLocation);
            var    len          = itemStr.IndexOf("{"); //去掉 ##itemtemplate## 以及换行符 从{{productname}}
            string itemTemplate = itemStr.Substring(len);
            var    model        = models[0];


            billTemplate = billTemplate.ToLower();
            billTemplate = billTemplate.Replace("{{storename}}", model.StoreName);
            billTemplate = billTemplate.Replace("{{createdbyname}}", model.CreatedByName);
            billTemplate = billTemplate.Replace("{{posid}}", model.PosId.ToString());
            billTemplate = billTemplate.Replace("{{startdate}}", model.StartDate.ToString("yyyy-MM-dd HH:mm:ss"));
            billTemplate = billTemplate.Replace("{{enddate}}", model.EndDate.HasValue? model.EndDate.Value.ToString("yyyy-MM-dd HH:mm:ss"):"");
            billTemplate = billTemplate.Replace("{{today}}", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
            // 金额
            string productItems = "";

            foreach (var item in models)
            {
                string tempItem = itemTemplate;
                tempItem      = tempItem.Replace("{{totalamount}}", item.TotalAmount.ToString("F2"));
                tempItem      = tempItem.Replace("{{totalonlineamount}}", item.TotalOnlineAmount.ToString("F2"));
                tempItem      = tempItem.Replace("{{paymentway}}", item.PaymentWay.Description());
                productItems += tempItem;
            }
            billTemplate = billTemplate.Replace("{{items}}", productItems);
            _printService.Print(billTemplate);
        }
Пример #3
0
        public void PrintTicket(SaleOrder model)
        {
            var store = _db.Stores.FirstOrDefault(n => n.Id == model.StoreId);
            //打印模板
            string posTemplate = FileHelper.ReadText("PosBillTemplate.txt");

            if (string.IsNullOrEmpty(posTemplate))
            {
                throw new AppException("小票模板为空");
            }
            posTemplate = posTemplate.ToLower();
            var lineLocation = posTemplate.LastIndexOf("##itemtemplate##");
            //分离商品item模板
            string billTemplate = posTemplate.ToLower().Substring(0, lineLocation);
            var    itemStr      = posTemplate.Substring(lineLocation);
            var    len          = itemStr.IndexOf("{"); //去掉 ##itemtemplate## 以及换行符 从{{productname}}
            string itemTemplate = itemStr.Substring(len);

            //开始替换
            billTemplate = billTemplate.Replace("{{storename}}", store == null ? " " : store.Name);
            billTemplate = billTemplate.Replace("{{createdate}}", model.CreatedOn.ToString("yyyy-MM-dd HH:mm:ss"));
            billTemplate = billTemplate.Replace("{{ordercode}}", model.Code);
            billTemplate = billTemplate.Replace("{{createdby}}", model.CreatedBy.ToString());
            billTemplate = billTemplate.Replace("{{status}}", model.Status.Description());
            //明细
            string productItems = "";

            foreach (var item in model.Items)
            {
                string tempItem = itemTemplate;
                tempItem = tempItem.Replace("{{productname}}", item.ProductName);
                tempItem = tempItem.Replace("{{productcode}}", item.ProductCode);
                tempItem = tempItem.Replace("{{price}}", item.RealPrice.ToString("F2"));
                tempItem = tempItem.Replace("{{quantity}}", item.Quantity.ToString());
                decimal amount = item.RealPrice * item.Quantity;
                tempItem      = tempItem.Replace("{{amount}}", amount.ToString("F2"));
                productItems += tempItem;;
            }
            billTemplate = billTemplate.Replace("{{items}}", productItems);
            //应收应付
            billTemplate = billTemplate.Replace("{{orderamount}}", model.OrderAmount.ToString("F2"));
            billTemplate = billTemplate.Replace("{{quantitytotal}}", model.GetQuantityTotal().ToString());
            billTemplate = billTemplate.Replace("{{discountamount}}", model.GetTotalDiscountAmount().ToString("F2"));
            billTemplate = billTemplate.Replace("{{payamount}}", model.PayAmount.ToString("F2"));
            billTemplate = billTemplate.Replace("{{chargeamount}}", model.GetChargeAmount().ToString("F2"));
            billTemplate = billTemplate.Replace("{{paymentway}}", model.PaymentWay.Description());
            billTemplate = billTemplate.Replace("{{onlinepayamount}}", model.OnlinePayAmount.ToString("F2"));

            _printService.Print(billTemplate);
        }