/*private static readonly string[] input = {"Cake", "Cake", "Cake", "Cake", "Bread", "Bread", "Bread", "Bread", "Apple", "Apple", "Apple", "Apple", "Apple", "Apple"};*/

        static void Main(string[] args)
        {
            // TO MANUAL ENTER UNCOMMENT THIS

            /*ShoppingCart shoppingCart = GetShoppingCart(input);
             *
             * var config = GetConfig(CONFIG_FILE_NAME);
             * var priceList = new PriceList(config.GetPrices());
             * var bill = GenerateBill(config, priceList, shoppingCart);
             *
             * BillPrinter pr = new BillPrinter();
             * pr.print(bill, shoppingCart, priceList);*/

            // AND COMMENT BELOW
            if (args == null)
            {
                Console.WriteLine("Args is null");
            }
            else
            {
                ShoppingCart.ShoppingCart shoppingCart = GetShoppingCart(args);

                var config    = GetConfig();
                var priceList = new PriceList(config.GetPrices());
                var bill      = GenerateBill(config, priceList, shoppingCart);

                BillPrinter pr = new BillPrinter();
                pr.print(OUTPUT_BILL_FILE_NAME, bill, shoppingCart, priceList);
            }
        }
        public void WriteBillToClient(Client client)
        {
            VATManager vatManager     = new VATManager();
            double     appropriateVAT = vatManager.GetAppropriateVAT(this, client);
            double     priceAfterVAT  = vatManager.ApplyVATToPrice(appropriateVAT, this.Service.ServicePrice);

            Bill bill = new Bill(client.Name, this.Name, Service, appropriateVAT, priceAfterVAT);

            BillPrinter.PrintBillToConsole(bill);
        }
Beispiel #3
0
        /// <summary>
        /// 一次把一个加油单完整打印出来
        /// </summary>
        /// <param name="bill"></param>
        /// <returns></returns>
        private string getPrintTextForBill(BillPrinter bill)
        {
            string reText = string.Format(@"      加油单
单  号:{0}
车辆编号:{1}
VIN   :{2}
油  品:{3}       {6}
加油量 :{4}         {7}
加油时间:{5}", bill.Id, bill.CarNumber, bill.CarVin, bill.OilName, bill.Volume, bill.Time, bill.OilName, bill.Volume);

            reText += string.Format(@"
-------------------------------
   {0}
-------------------------------", firmName);
            return(reText);
        }
Beispiel #4
0
        /// <summary>
        /// 分5个步骤把一个加油单打出来,额外打印加大字号的油品及加油量
        /// </summary>
        /// <param name="bill"></param>
        /// <param name="step"></param>
        /// <returns></returns>
        private string getPrintTextByStepForBill(BillPrinter bill, int step)
        {
            string reText = "";

            switch (step)
            {
            case 1:
                //不带回车、正常打印
                reText = string.Format(@"      加油单
单  号:{0}
车辆编号:{1}
VIN   :{2}
油  品:{3}     ", bill.Id, bill.CarNumber, bill.CarVin, bill.OilName);
                break;

            case 2:
                //带回车、放大打印
                reText = bill.OilName.ToString();
                break;

            case 3:
                //不带回车、正常打印
                reText = string.Format(@"加油量 :{0}        ", bill.Volume);
                break;

            case 4:
                //带回车、放大打印
                reText = bill.Volume.ToString();
                break;

            case 5:
                reText  = string.Format(@"加油时间:{0}", bill.Time);
                reText += string.Format(@"
-------------------------------
   {0}
-------------------------------", firmName);
                break;
            }
            return(reText);
        }
Beispiel #5
0
        private bool tryPrint(BillPrinter bill)
        {
            bool re = false;

            try
            {
                if (PrinterHelper.TxOpenPrinter(1, 0))
                {
                    int status = PrinterHelper.TxGetStatus();
                    if (status == 16)
                    {
                        string printText = "";
                        ShowTipInfo(string.Format("正在打印加油单:{0}-{1}-{2}-{3}-{4}", bill.Id, bill.DriverName, bill.OilerName, bill.OilName, bill.Volume), Color.YellowGreen);
                        //无故障情况下才执行打印
                        PrinterHelper.TxInit();
                        if (printType == 2)
                        {
                            printText = getPrintTextByStepForBill(bill, 1);
                            PrinterHelper.TxResetFont();
                            PrinterHelper.TxOutputString(printText);
                            printText = getPrintTextByStepForBill(bill, 2);
                            PrinterHelper.TxDoFunction(1, 1, 1);//放大打印
                            PrinterHelper.TxOutputStringLn(printText);
                            printText = getPrintTextByStepForBill(bill, 3);
                            PrinterHelper.TxResetFont();
                            PrinterHelper.TxOutputString(printText);
                            printText = getPrintTextByStepForBill(bill, 4);
                            PrinterHelper.TxDoFunction(1, 1, 1);//放大打印
                            PrinterHelper.TxOutputStringLn(printText);
                            printText = getPrintTextByStepForBill(bill, 5);
                            PrinterHelper.TxResetFont();
                            PrinterHelper.TxOutputStringLn(printText);
                        }
                        else
                        {
                            printText = getPrintTextForBill(bill);
                            PrinterHelper.TxDoFunction(1, 0, 1);//放大打印,只放大纵向
                            PrinterHelper.TxOutputStringLn(printText);
                        }
                        PrinterHelper.TxDoFunction(10, 30, 0);//走纸30毫米
                        Thread.Sleep(1000);
                        bool isSuccess = PrinterHelper.CheckIsPrintSuccess();
                        if (isSuccess)
                        {
                            re = true;
                            ShowTipInfo(string.Format("加油单打印成功:{0}-{1}-{2}-{3}-{4}", bill.Id, bill.DriverName, bill.OilerName, bill.OilName, bill.Volume), Color.Green);
                        }
                        else
                        {
                            ShowTipInfo("打印失败,有可能是打印机内纸不够、打印机断电或其他异常,请确保打印机接上电源并且其内有足够的纸,然后执行一次关闭打印机后再打开打印机。", Color.Red);
                        }
                    }
                    else if (status == 56)
                    {
                        ShowTipInfo("检测到打印机内没有纸,如果有纸,请执行一次关闭打印机后再打开打印机。", Color.Red);
                    }
                    else
                    {
                        ShowTipInfo("打印机繁忙或异常,请尝试执行一次关闭打印机后再打开打印机,可能能解决问题。", Color.Red);
                    }
                }
                else
                {
                    ShowTipInfo("无法连接打印机,请确保打印机电源打开并且正常连接到电脑", Color.Red);
                }
            }
            catch (Exception ex) {
                re = false;
                ShowTipInfo(string.Format("打印时出现异常:{0}", ex.ToString()), Color.Red);
            }
            finally
            {
                PrinterHelper.TxClosePrinter();
            }
            return(re);
        }