using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Drawing;
using System.Drawing.Printing;
using System.Security.Cryptography;

namespace tool
{
    /// <summary>
    /// 凭证码
    /// </summary>
    public class QRCode
    {
        //private string terminalFlag;
        //private int num;
        //public QRCode(string _terminalFlag, int _num)
        //{
        //    terminalFlag = _terminalFlag;
        //    num = _num;
        //}
        private string context;
        private string commedkey;

        public QRCode(string _commedkey,string _context)
        {
            context = _context;
            commedkey = _commedkey;
        }
       
        /// <summary>
        /// 凭证码生成
        /// </summary>
        /// <param name="context">内容</param>
        /// <returns></returns>
        private Image Generate()
        {
            Image img = null;
            //Credence credence = new Credence();
            //context = credence.Generate(terminalFlag, num);
            //之前使用的是凭证，现在可能要改成取车消息的json字符串！！！！！！！！！！！！！！！！！！！！！
            if (commedkey != "")
            {
                //BitMap是Image的子类（自己整合编写的）
                img = QRcodeGenerator.Encode(commedkey);
            }
            return img;
        }
        /// <summary>
        /// 凭证码打印
        /// </summary>
        public void Print(PrintDocument document)
        {
            //Log.WriteLog(LogType.PROCESS, LogFile.LOG, "正在生成二维码");
            //生成二维码
            Image img = Generate();
            //Log.WriteLog(LogType.PROCESS, LogFile.LOG, "二维码生成成功");
            //定义打印机
            Printer printer = new Printer(img, document, context);
            //Log.WriteLog(LogType.PROCESS, LogFile.LOG, "打印机连接成功");
            //打印
            printer.Print();
        }

    }
}
