using System;
using System.Collections.Generic;
using System.IO;
using System.Threading;
using ChuPiao.AutoPrint.Machine.Models;
using ChuPiao.AutoPrint.Machine.TjJingCaiV1.MacLotPlayMode;
using ChuPiao.AutoPrint.Machine.TjJingCaiV1.MacReport;
using ChuPiao.Common.Enums;
using ChuPiao.Common.Models;
using ChuPiao.Common.Utils;
using ChuPiao.Common.Communication.GtdJson.Packs;
using ChuPiao.Common.Communication.GtdJson;

namespace ChuPiao.AutoPrint.Machine.TjJingCaiV1
{
    /// <summary>
    /// 天津竟彩彩票机
    /// </summary>
    public class TjJingCaiMachineV1 : BaseLotMachine
    {
        #region Overrides of BaseLotMachine

        Dictionary<int, M_LotPlayModeMapEntity> _lotPlayMapList = null;
        /// <summary>
        /// 玩法映射
        /// </summary>
        public override Dictionary<int, M_LotPlayModeMapEntity> LotPlayMap
        {
            get
            {
                if (_lotPlayMapList == null)
                {
                    _lotPlayMapList = new Dictionary<int, M_LotPlayModeMapEntity>();
                    /*M_LotPlayModeMapEntity[] playarr = new M_LotPlayModeMapEntity[49];
                    playarr[0] = new M_LotPlayModeMapEntity(911, "竟彩", 91101, "常规玩法", 9110101, "足球胜平负", 911, "竟彩足球", 91101, "胜平负");
                    playarr[1] = new M_LotPlayModeMapEntity(911, "竟彩", 91101, "常规玩法", 9110102, "足球比分", 911, "竟彩足球", 91102, "比分");
                    playarr[2] = new M_LotPlayModeMapEntity(911, "竟彩", 91101, "常规玩法", 9110103, "足球总进球", 911, "竟彩足球", 91103, "总进球");
                    playarr[3] = new M_LotPlayModeMapEntity(911, "竟彩", 91101, "常规玩法", 9110104, "足球半全场", 911, "竟彩足球", 91104, "半全场");
                    playarr[4] = new M_LotPlayModeMapEntity(911, "竟彩", 91101, "常规玩法", 9110105, "篮球让分胜负", 951, "竟彩篮球", 95101, "让分胜负");
                    playarr[5] = new M_LotPlayModeMapEntity(911, "竟彩", 91101, "常规玩法", 9110106, "篮球胜负", 951, "竟彩篮球", 95102, "胜负");
                    playarr[6] = new M_LotPlayModeMapEntity(911, "竟彩", 91101, "常规玩法", 9110107, "篮球胜分差", 951, "竟彩篮球", 95103, "胜分差");
                    playarr[7] = new M_LotPlayModeMapEntity(911, "竟彩", 91101, "常规玩法", 9110108, "篮球大小分", 951, "竟彩篮球", 95104, "大小分");
                    playarr[8] = new M_LotPlayModeMapEntity(911, "竟彩", 91101, "常规玩法", 9110109, "冠军", 971, "竟彩名次", 97101, "冠军");
                    playarr[9] = new M_LotPlayModeMapEntity(911, "竟彩", 91101, "常规玩法", 9110110, "冠亚军", 971, "竟彩名次", 97102, "冠亚军");
                    playarr[10] = new M_LotPlayModeMapEntity(911, "竟彩", 91101, "常规玩法", 9110111, "足球混合过关", 911, "竟彩足球", 91199, "混合过关");
                    playarr[11] = new M_LotPlayModeMapEntity(911, "竟彩", 91101, "常规玩法", 9110112, "篮球混合过关", 951, "竟彩篮球", 95199, "混合过关");

                    playarr[12] = new M_LotPlayModeMapEntity(705, "联网22选5", 70501, "常规玩法", 7050101, "单式", 705, "22选5", 70501, "单式");
                    playarr[13] = new M_LotPlayModeMapEntity(705, "联网22选5", 70501, "常规玩法", 7050102, "复式", 705, "22选5", 70502, "复式");
                    playarr[14] = new M_LotPlayModeMapEntity(704, "七星彩", 70401, "常规玩法", 7040101, "单式", 704, "七星彩", 70401, "单式");
                    playarr[15] = new M_LotPlayModeMapEntity(704, "七星彩", 70401, "常规玩法", 7040102, "复式", 704, "七星彩", 70402, "复式");
                    playarr[16] = new M_LotPlayModeMapEntity(703, "排列五", 70301, "常规玩法", 7030101, "单式", 703, "排列5", 70301, "单式");
                    playarr[17] = new M_LotPlayModeMapEntity(703, "排列五", 70301, "常规玩法", 7030102, "复式", 703, "排列5", 70302, "复式");
                    playarr[18] = new M_LotPlayModeMapEntity(702, "联网排列型", 70201, "排列三", 7020101, "单式", 702, "排列三", 70201, "直选单式");
                    playarr[19] = new M_LotPlayModeMapEntity(702, "联网排列型", 70201, "排列三", 7020102, "组选", 702, "排列三", 70211, "组选三单式");
                    playarr[20] = new M_LotPlayModeMapEntity(702, "联网排列型", 70201, "排列三", 7020102, "组选", 702, "排列三", 70221, "组选六单式");
                    playarr[21] = new M_LotPlayModeMapEntity(702, "联网排列型", 70201, "排列三", 7020103, "复式", 702, "排列三", 70202, "直选复式");
                    playarr[22] = new M_LotPlayModeMapEntity(702, "联网排列型", 70203, "排列三组选3复式", 7020301, "复式", 702, "排列三", 70212, "组三复式");
                    playarr[23] = new M_LotPlayModeMapEntity(702, "联网排列型", 70204, "排列三组选6复式", 7020401, "复式", 702, "排列三", 70222, "组六复式");
                    playarr[24] = new M_LotPlayModeMapEntity(702, "联网排列型", 70205, "排列三直选和值", 7020501, "和值", 702, "排列三", 70203, "直选和值");
                    playarr[25] = new M_LotPlayModeMapEntity(702, "联网排列型", 70206, "排列三组选和值", 7020601, "和值", 702, "排列三", 70232, "组选和值");
                    playarr[26] = new M_LotPlayModeMapEntity(702, "联网排列型", 70207, "排列三直选组合复式", 7020701, "组合复式", 702, "排列三", 70206, "直选组合复式");
                    playarr[27] = new M_LotPlayModeMapEntity(702, "联网排列型", 70208, "排列三直选组合胆拖", 7020801, "组合胆拖", 702, "排列三", 70204, "直选组合胆拖");
                    playarr[28] = new M_LotPlayModeMapEntity(702, "联网排列型", 70209, "排列三组选3胆拖", 7020901, "胆拖", 702, "排列三", 70214, "组三胆拖");
                    playarr[29] = new M_LotPlayModeMapEntity(702, "联网排列型", 70210, "排列三组选6胆拖", 7021001, "胆拖", 702, "排列三", 70224, "组六胆拖");
                    playarr[30] = new M_LotPlayModeMapEntity(702, "联网排列型", 70211, "排列三直选跨度复式", 7021101, "跨度", 702, "排列三", 70205, "直选跨度");
                    playarr[31] = new M_LotPlayModeMapEntity(702, "联网排列型", 70212, "排列三组选3跨度复式", 7021201, "跨度", 702, "排列三", 70215, "组三跨度");
                    playarr[32] = new M_LotPlayModeMapEntity(702, "联网排列型", 70213, "排列三组选6跨度复式", 7021301, "跨度", 702, "排列三", 70225, "组六跨度");
                    playarr[33] = new M_LotPlayModeMapEntity(701, "大乐透", 70101, "常规玩法", 7010101, "单式", 701, "大乐透", 70101, "单式");
                    playarr[34] = new M_LotPlayModeMapEntity(701, "大乐透", 70101, "常规玩法", 7010102, "复式", 701, "大乐透", 70102, "复式");
                    playarr[35] = new M_LotPlayModeMapEntity(701, "大乐透", 70101, "常规玩法", 7010103, "胆拖", 701, "大乐透", 70103, "胆拖");
                    playarr[36] = new M_LotPlayModeMapEntity(701, "大乐透", 70102, "追加玩法", 7010201, "单式", 701, "大乐透", 70111, "追加单式");
                    playarr[37] = new M_LotPlayModeMapEntity(701, "大乐透", 70102, "追加玩法", 7010202, "复式", 701, "大乐透", 70112, "追加复式");
                    playarr[38] = new M_LotPlayModeMapEntity(701, "大乐透", 70102, "追加玩法", 7010203, "胆拖", 701, "大乐透", 70113, "追加胆拖");
                    playarr[39] = new M_LotPlayModeMapEntity(711, "大乐透幸运彩", 71101, "幸运玩法", 7110101, "单式", 701, "大乐透", 70121, "12选2单式");
                    playarr[40] = new M_LotPlayModeMapEntity(711, "大乐透幸运彩", 71101, "幸运玩法", 7110102, "复式", 701, "大乐透", 70122, "12选2复式");
                    playarr[41] = new M_LotPlayModeMapEntity(603, "6场半全场胜负", 60301, "六场", 6030101, "单式", 603, "六场半全场", 60301, "单式");
                    playarr[42] = new M_LotPlayModeMapEntity(603, "6场半全场胜负", 60301, "六场", 6030102, "复式", 603, "六场半全场", 60302, "复式");
                    playarr[43] = new M_LotPlayModeMapEntity(602, "4场进球", 60201, "四场", 6020101, "单式", 602, "四场进球", 60201, "单式");
                    playarr[44] = new M_LotPlayModeMapEntity(602, "4场进球", 60201, "四场", 6020102, "复式", 602, "四场进球", 60202, "复式");
                    playarr[45] = new M_LotPlayModeMapEntity(601, "足球胜负平", 60101, "十四场", 6010101, "单式", 601, "胜负彩", 60101, "十四场单式");
                    playarr[46] = new M_LotPlayModeMapEntity(601, "足球胜负平", 60101, "十四场", 6010102, "复式", 601, "胜负彩", 60102, "十四场复式");
                    playarr[47] = new M_LotPlayModeMapEntity(611, "任选9场", 61101, "九场", 6110101, "单式", 601, "胜负彩", 60111, "九场单式");
                    playarr[48] = new M_LotPlayModeMapEntity(611, "任选9场", 61101, "九场", 6110102, "复式", 601, "胜负彩", 60112, "九场复式");*/
                    M_LotPlayModeMapEntity[] playarr = new M_LotPlayModeMapEntity[81];
                    playarr[0] = new M_LotPlayModeMapEntity(911, "竟彩", 91101, "常规玩法", 9110101, "足球胜平负", 911, "竟彩足球", 91106, "胜平负");
                    playarr[1] = new M_LotPlayModeMapEntity(911, "竟彩", 91101, "常规玩法", 9110102, "足球比分", 911, "竟彩足球", 91102, "比分");
                    playarr[2] = new M_LotPlayModeMapEntity(911, "竟彩", 91101, "常规玩法", 9110103, "足球总进球", 911, "竟彩足球", 91103, "总进球");
                    playarr[3] = new M_LotPlayModeMapEntity(911, "竟彩", 91101, "常规玩法", 9110104, "足球半全场", 911, "竟彩足球", 91104, "半全场");
                    playarr[4] = new M_LotPlayModeMapEntity(911, "竟彩", 91101, "常规玩法", 9110105, "篮球让分胜负", 951, "竟彩篮球", 95101, "让分胜负");
                    playarr[5] = new M_LotPlayModeMapEntity(911, "竟彩", 91101, "常规玩法", 9110106, "篮球胜负", 951, "竟彩篮球", 95102, "胜负");
                    playarr[6] = new M_LotPlayModeMapEntity(911, "竟彩", 91101, "常规玩法", 9110107, "篮球胜分差", 951, "竟彩篮球", 95103, "胜分差");
                    playarr[7] = new M_LotPlayModeMapEntity(911, "竟彩", 91101, "常规玩法", 9110108, "篮球大小分", 951, "竟彩篮球", 95104, "大小分");
                    playarr[8] = new M_LotPlayModeMapEntity(911, "竟彩", 91101, "常规玩法", 9110109, "冠军", 971, "竟彩名次", 97101, "冠军");
                    playarr[9] = new M_LotPlayModeMapEntity(911, "竟彩", 91101, "常规玩法", 9110110, "冠亚军", 971, "竟彩名次", 97102, "冠亚军");
                    playarr[10] = new M_LotPlayModeMapEntity(911, "竟彩", 91101, "常规玩法", 9110111, "足球混合过关", 911, "竟彩足球", 91199, "混合过关");
                    playarr[11] = new M_LotPlayModeMapEntity(911, "竟彩", 91101, "常规玩法", 9110112, "篮球混合过关", 951, "竟彩篮球", 95199, "混合过关");
                    playarr[12] = new M_LotPlayModeMapEntity(911, "竟彩", 91101, "常规玩法", 9110113, "足球让球胜平负", 911, "竟彩足球", 91101, "让球胜平负");

                    playarr[13] = new M_LotPlayModeMapEntity(705, "联网22选5", 70501, "常规玩法", 7050101, "单式", 705, "22选5", 70501, "单式");
                    playarr[14] = new M_LotPlayModeMapEntity(705, "联网22选5", 70501, "常规玩法", 7050102, "复式", 705, "22选5", 70502, "复式");
                    playarr[15] = new M_LotPlayModeMapEntity(704, "7星彩", 70401, "常规玩法", 7040101, "单式", 704, "7星彩", 70401, "单式");
                    playarr[16] = new M_LotPlayModeMapEntity(704, "7星彩", 70401, "常规玩法", 7040102, "复式", 704, "7星彩", 70402, "复式");

                    playarr[17] = new M_LotPlayModeMapEntity(703, "排列五", 70301, "常规玩法", 7030101, "单式", 703, "排列5", 70301, "单式");
                    playarr[18] = new M_LotPlayModeMapEntity(703, "排列五", 70301, "常规玩法", 7030102, "复式", 703, "排列5", 70302, "复式");
                    playarr[19] = new M_LotPlayModeMapEntity(702, "联网排列型", 70201, "排列三", 7020101, "单式", 702, "排列三", 70201, "直选单式");
                    playarr[20] = new M_LotPlayModeMapEntity(702, "联网排列型", 70201, "排列三", 7020102, "组选", 702, "排列三", 70211, "组选三单式");
                    playarr[21] = new M_LotPlayModeMapEntity(702, "联网排列型", 70201, "排列三", 7020102, "组选", 702, "排列三", 70221, "组选六单式");
                    playarr[22] = new M_LotPlayModeMapEntity(702, "联网排列型", 70201, "排列三", 7020103, "复式", 702, "排列三", 70202, "直选复式");
                    playarr[23] = new M_LotPlayModeMapEntity(702, "联网排列型", 70203, "排列三组选3复式", 7020301, "复式", 702, "排列三", 70212, "组三复式");
                    playarr[24] = new M_LotPlayModeMapEntity(702, "联网排列型", 70204, "排列三组选6复式", 7020401, "复式", 702, "排列三", 70222, "组六复式");
                    playarr[25] = new M_LotPlayModeMapEntity(702, "联网排列型", 70205, "排列三直选和值", 7020501, "和值", 702, "排列三", 70203, "直选和值");
                    playarr[26] = new M_LotPlayModeMapEntity(702, "联网排列型", 70206, "排列三组选和值", 7020601, "和值", 702, "排列三", 70232, "组选和值");
                    playarr[27] = new M_LotPlayModeMapEntity(702, "联网排列型", 70207, "排列三直选组合复式", 7020701, "组合复式", 702, "排列三", 70206, "直选组合复式");
                    playarr[28] = new M_LotPlayModeMapEntity(702, "联网排列型", 70208, "排列三直选组合胆拖", 7020801, "组合胆拖", 702, "排列三", 70204, "直选组合胆拖");
                    playarr[29] = new M_LotPlayModeMapEntity(702, "联网排列型", 70209, "排列三组选3胆拖", 7020901, "胆拖", 702, "排列三", 70214, "组三胆拖");
                    playarr[30] = new M_LotPlayModeMapEntity(702, "联网排列型", 70210, "排列三组选6胆拖", 7021001, "胆拖", 702, "排列三", 70224, "组六胆拖");
                    playarr[31] = new M_LotPlayModeMapEntity(702, "联网排列型", 70211, "排列三直选跨度复式", 7021101, "跨度", 702, "排列三", 70205, "直选跨度");
                    playarr[32] = new M_LotPlayModeMapEntity(702, "联网排列型", 70212, "排列三组选3跨度复式", 7021201, "跨度", 702, "排列三", 70215, "组三跨度");
                    playarr[33] = new M_LotPlayModeMapEntity(702, "联网排列型", 70213, "排列三组选6跨度复式", 7021301, "跨度", 702, "排列三", 70225, "组六跨度");

                    playarr[34] = new M_LotPlayModeMapEntity(701, "大乐透", 70101, "常规玩法", 7010101, "单式", 701, "大乐透", 70101, "单式");
                    playarr[35] = new M_LotPlayModeMapEntity(701, "大乐透", 70101, "常规玩法", 7010102, "复式", 701, "大乐透", 70102, "复式");
                    playarr[36] = new M_LotPlayModeMapEntity(701, "大乐透", 70101, "常规玩法", 7010103, "胆拖", 701, "大乐透", 70103, "胆拖");
                    playarr[37] = new M_LotPlayModeMapEntity(701, "大乐透", 70102, "追加玩法", 7010201, "单式", 701, "大乐透", 70111, "追加单式");
                    playarr[38] = new M_LotPlayModeMapEntity(701, "大乐透", 70102, "追加玩法", 7010202, "复式", 701, "大乐透", 70112, "追加复式");
                    playarr[39] = new M_LotPlayModeMapEntity(701, "大乐透", 70102, "追加玩法", 7010203, "胆拖", 701, "大乐透", 70113, "追加胆拖");
                    playarr[40] = new M_LotPlayModeMapEntity(711, "大乐透幸运彩", 71101, "幸运玩法", 7110101, "单式", 701, "大乐透", 70121, "12选2单式");
                    playarr[41] = new M_LotPlayModeMapEntity(711, "大乐透幸运彩", 71101, "幸运玩法", 7110102, "复式", 701, "大乐透", 70122, "12选2复式");
                    playarr[42] = new M_LotPlayModeMapEntity(603, "6场半全场胜负", 60301, "六场", 6030101, "单式", 603, "六场半全场", 60301, "单式");
                    playarr[43] = new M_LotPlayModeMapEntity(603, "6场半全场胜负", 60301, "六场", 6030102, "复式", 603, "六场半全场", 60302, "复式");
                    playarr[44] = new M_LotPlayModeMapEntity(602, "4场进球", 60201, "四场", 6020101, "单式", 602, "四场进球", 60201, "单式");
                    playarr[45] = new M_LotPlayModeMapEntity(602, "4场进球", 60201, "四场", 6020102, "复式", 602, "四场进球", 60202, "复式");
                    playarr[46] = new M_LotPlayModeMapEntity(601, "足球胜负平", 60101, "十四场", 6010101, "单式", 601, "胜负彩", 60101, "十四场单式");
                    playarr[47] = new M_LotPlayModeMapEntity(601, "足球胜负平", 60101, "十四场", 6010102, "复式", 601, "胜负彩", 60102, "十四场复式");
                    playarr[48] = new M_LotPlayModeMapEntity(611, "任选9场", 61101, "九场", 6110101, "单式", 601, "胜负彩", 60111, "九场单式");
                    playarr[49] = new M_LotPlayModeMapEntity(611, "任选9场", 61101, "九场", 6110102, "复式", 601, "胜负彩", 60112, "九场复式");

                    playarr[50] = new M_LotPlayModeMapEntity(503, "湖北11选5", 50301, "任选一", 5030102, "复式", 503, "湖北11选5", 50301, "前1直选单式");
                    playarr[51] = new M_LotPlayModeMapEntity(503, "湖北11选5", 50301, "任选一", 5030102, "复式", 503, "湖北11选5", 50351, "前1直选复式");
                    playarr[52] = new M_LotPlayModeMapEntity(503, "湖北11选5", 50302, "任选二", 5030201, "单式", 503, "湖北11选5", 50322, "任选2单式");
                    playarr[53] = new M_LotPlayModeMapEntity(503, "湖北11选5", 50302, "任选二", 5030202, "复式", 503, "湖北11选5", 50372, "任选2复式");
                    playarr[54] = new M_LotPlayModeMapEntity(503, "湖北11选5", 50302, "任选二", 5030203, "胆拖", 503, "湖北11选5", 50342, "任选2胆拖");
                    playarr[55] = new M_LotPlayModeMapEntity(503, "湖北11选5", 50303, "任选三", 5030301, "单式", 503, "湖北11选5", 50323, "任选3单式");
                    playarr[56] = new M_LotPlayModeMapEntity(503, "湖北11选5", 50303, "任选三", 5030302, "复式", 503, "湖北11选5", 50373, "任选3复式");
                    playarr[57] = new M_LotPlayModeMapEntity(503, "湖北11选5", 50303, "任选三", 5030303, "胆拖", 503, "湖北11选5", 50343, "任选3胆拖");
                    playarr[58] = new M_LotPlayModeMapEntity(503, "湖北11选5", 50304, "任选四", 5030401, "单式", 503, "湖北11选5", 50324, "任选4单式");
                    playarr[59] = new M_LotPlayModeMapEntity(503, "湖北11选5", 50304, "任选四", 5030402, "复式", 503, "湖北11选5", 50374, "任选4复式");
                    playarr[60] = new M_LotPlayModeMapEntity(503, "湖北11选5", 50304, "任选四", 5030403, "胆拖", 503, "湖北11选5", 50344, "任选4胆拖");
                    playarr[61] = new M_LotPlayModeMapEntity(503, "湖北11选5", 50305, "任选五", 5030501, "单式", 503, "湖北11选5", 50325, "任选5单式");
                    playarr[62] = new M_LotPlayModeMapEntity(503, "湖北11选5", 50305, "任选五", 5030502, "复式", 503, "湖北11选5", 50375, "任选5复式");
                    playarr[63] = new M_LotPlayModeMapEntity(503, "湖北11选5", 50305, "任选五", 5030503, "胆拖", 503, "湖北11选5", 50345, "任选5胆拖");
                    playarr[64] = new M_LotPlayModeMapEntity(503, "湖北11选5", 50306, "任选六", 5030601, "单式", 503, "湖北11选5", 50326, "任选6单式");
                    playarr[65] = new M_LotPlayModeMapEntity(503, "湖北11选5", 50306, "任选六", 5030602, "复式", 503, "湖北11选5", 50376, "任选6复式");
                    playarr[66] = new M_LotPlayModeMapEntity(503, "湖北11选5", 50306, "任选六", 5030603, "胆拖", 503, "湖北11选5", 50346, "任选6胆拖");
                    playarr[67] = new M_LotPlayModeMapEntity(503, "湖北11选5", 50307, "任选七", 5030701, "单式", 503, "湖北11选5", 50327, "任选7单式");
                    playarr[68] = new M_LotPlayModeMapEntity(503, "湖北11选5", 50307, "任选七", 5030702, "复式", 503, "湖北11选5", 50377, "任选7复式");
                    playarr[69] = new M_LotPlayModeMapEntity(503, "湖北11选5", 50307, "任选七", 5030703, "胆拖", 503, "湖北11选5", 50347, "任选7胆拖");
                    playarr[70] = new M_LotPlayModeMapEntity(503, "湖北11选5", 50308, "任选八", 5030801, "单式", 503, "湖北11选5", 50328, "任选8单式");
                    playarr[71] = new M_LotPlayModeMapEntity(503, "湖北11选5", 50309, "选前二组选", 5030901, "单式", 503, "湖北11选5", 50312, "前2组选单式");
                    playarr[72] = new M_LotPlayModeMapEntity(503, "湖北11选5", 50309, "选前二组选", 5030902, "复式", 503, "湖北11选5", 50362, "前2组选复式");
                    playarr[73] = new M_LotPlayModeMapEntity(503, "湖北11选5", 50309, "选前二组选", 5030903, "胆拖", 503, "湖北11选5", 50332, "前2组选胆拖");
                    playarr[74] = new M_LotPlayModeMapEntity(503, "湖北11选5", 50310, "选前二直选", 5031001, "单式", 503, "湖北11选5", 50302, "前2直选单式");
                    playarr[75] = new M_LotPlayModeMapEntity(503, "湖北11选5", 50310, "选前二直选", 5031003, "定位复式", 503, "湖北11选5", 50352, "前2直选定位复式");
                    playarr[76] = new M_LotPlayModeMapEntity(503, "湖北11选5", 50311, "选前三组选", 5031101, "单式", 503, "湖北11选5", 50313, "前3组选单式");
                    playarr[77] = new M_LotPlayModeMapEntity(503, "湖北11选5", 50311, "选前三组选", 5031102, "复式", 503, "湖北11选5", 50363, "前3组选复式");
                    playarr[78] = new M_LotPlayModeMapEntity(503, "湖北11选5", 50311, "选前三组选", 5031103, "胆拖", 503, "湖北11选5", 50333, "前3组选胆拖");
                    playarr[79] = new M_LotPlayModeMapEntity(503, "湖北11选5", 50312, "选前三直选", 5031201, "单式", 503, "湖北11选5", 50303, "前3直选单式");
                    playarr[80] = new M_LotPlayModeMapEntity(503, "湖北11选5", 50312, "选前三直选", 5031203, "定位复式", 503, "湖北11选5", 50353, "前3直选定位复式");

                    foreach (M_LotPlayModeMapEntity entity in playarr)
                    {
                        _lotPlayMapList.Add(entity.M_PlayId, entity);
                    }
                }
                return _lotPlayMapList;
            }
        }

        /// <summary>
        /// 彩票机初始化
        /// </summary>
        public override void Initialize()
        {
            try
            {

                if (MachineInfo.M_KeyboardType == (int)KeyboardType.NewKeyboard)
                {
                    VirtualKeyboard = new VirtualKeyboardV2(MachineInfo.M_VirtualKeyboardPort,
                                                             MachineInfo.M_VirtualKeyboardPortBps);
                }
                else if (MachineInfo.M_KeyboardType == (int)KeyboardType.OldKeyboard)
                {
                    VirtualKeyboard = new VirtualKeyboardV1(MachineInfo.M_VirtualKeyboardPort,
                                                             MachineInfo.M_VirtualKeyboardPortBps);
                }

                //VirtualScanner = new VirtualScanner(MachineInfo.M_VirtualScannerPort,MachineInfo.M_VirtualScannerPortBps);

                VirtualPrinter = new VirtualPrinter(MachineInfo.M_VirtualPrinterPort,
                                                         MachineInfo.M_VirtualPrinterPortBps);
                VirtualKeyboard.Log = Log;
                VirtualKeyboard.Port = MachineInfo.M_VirtualKeyboardPort;
                VirtualKeyboard.PortBps = MachineInfo.M_VirtualKeyboardPortBps;
                VirtualKeyboard.KeyboardType = (KeyboardType)MachineInfo.M_KeyboardType;
                VirtualKeyboard.MachineInfo = MachineInfo;
                //VirtualScanner.Log = Log;
                //VirtualScanner.Port = MachineInfo.M_VirtualScannerPort;
                //VirtualScanner.PortBps = MachineInfo.M_VirtualScannerPortBps;
                //VirtualScanner.MachineInfo = MachineInfo;
                VirtualPrinter.Log = Log;
                VirtualPrinter.LogPath = Path.Combine(@"D:\data\logs", MachineInfo.M_Number + @"\");
                VirtualPrinter.Port = MachineInfo.M_VirtualPrinterPort;
                VirtualPrinter.PortBps = MachineInfo.M_VirtualPrinterPortBps;
                VirtualPrinter.MachineInfo = MachineInfo;
                VirtualPrinter.LotMachine = this;
                VirtualPrinter.LastPrintCounter = MachineInfo.M_LastPrintCounter;

                VirtualKeyboard.Initialize();
                //VirtualScanner.Initialize();
                VirtualPrinter.Initialize();
            }
            catch (Exception exception)
            {
                Log.Warn(string.Concat("彩票机初始化异常。错误信息：", exception));
            }
        }

        /// <summary>
        /// 启动驱动
        /// </summary>
        public override void StartDriver()
        {
            VirtualPrinter.Start();
            VirtualKeyboard.Start();
            //VirtualScanner.Start();
        }

        /// <summary>
        /// 停止驱动
        /// </summary>
        public override void StopDriver()
        {
            VirtualKeyboard.Stop();
            VirtualPrinter.Stop();
            //VirtualScanner.Stop();
        }

        /// <summary>
        /// 重启驱动
        /// </summary>
        public override void ReStartDriver()
        {
            if (MachineInfo.M_Status != (int)MachineStatusEnum.Stopped)
            {
                Log.Info("不处于停止状态的机器禁止重启驱动");
                return;
            }
            StopDriver();
            int wait = 0;
            while (wait < 3000)
            {
                if (VirtualKeyboard.Status == VirtualKeyboardStatus.Stopped && VirtualPrinter.Status == VirtualPrinterStatus.Stopped)
                {
                    break;
                }
                wait += 100;
                Thread.Sleep(100);
            }
            Initialize();//重新初始化
            StartDriver();
        }
        public M_LotPlayModeMapEntity GetLotPlayMapByPlayId(int playId)
        {
            return LotPlayMap[playId];
        }


        /// <summary>
        /// 打印指定的票
        /// </summary>
        public override void Print(L_LotTicketEntity ticketEntity, DecodePrintData decodePrintData)
        {
            //判断与前一张票内容是否一致
            bool isSame = false;
            if ((ticketEntity.LotId == (int)Lottype.Jz || ticketEntity.LotId == (int)Lottype.Jl) && LastSucTicket != null && ticketEntity.L_Money == LastSucTicket.L_Money && ticketEntity.L_PlayId == LastSucTicket.L_PlayId && ticketEntity.L_Code == LastSucTicket.L_Code &&
                ticketEntity.L_CodeType == LastSucTicket.L_CodeType && ticketEntity.L_Mutiple == LastSucTicket.L_Mutiple && ticketEntity.L_Expect == LastSucTicket.L_Expect && ticketEntity.L_CurrentExpect == LastSucTicket.L_CurrentExpect)
            {
                isSame = true;
                Log.Info("与上一张票一致！");
            }

            CurrentTicket = ticketEntity;

            M_LotPlayModeMapEntity lotPlayMap = GetLotPlayMapByPlayId(ticketEntity.L_PlayId);
            ticketEntity.MacLotId = lotPlayMap.M_MacLotId;
            ticketEntity.MacPlayId = lotPlayMap.M_MacPlayId;
            ticketEntity.MacModeId = lotPlayMap.M_MacModeId;

            //切换彩种玩法
            SetCurrentLotPlayMode(ticketEntity);

            Log.Info(string.Concat("生产流水号：", ticketEntity.L_TicketSn, " 彩种：", ticketEntity.L_LotName, ticketEntity.LotId, " 玩法：", ticketEntity.L_PlayName, ticketEntity.L_PlayId, " 开始出票……"));
            //Log.Info("开始模拟打印"+ticketEntity.L_TicketSn);
            //PrintPayMoneyReport(new DecodeMachinePayMoneyReport());
            //清空打印接收缓存
            VirtualPrinter.ClearBuffer();
            MacLotPlayModeServiceFactory modeServiceFactory = new MacLotPlayModeServiceFactory();
            IMacLotPlayModeService modeService = modeServiceFactory.GetLotPlayService(ticketEntity.MacModeId);


            //键盘出票
            //等待发送键码列表
            List<KeycodeInfo> keycodeInfoList;
            if (!isSame)
            {
                keycodeInfoList = modeService.GetSendKeycodeList(ticketEntity, MachineInfo);
            }
            else
            {
                keycodeInfoList = new List<KeycodeInfo>();
                keycodeInfoList.Add(new KeycodeInfo("enter", MachineInfo.MachineConfigEntity.C_SendCommandInterval));
                keycodeInfoList.Add(new KeycodeInfo("wait500", MachineInfo.MachineConfigEntity.C_SendCommandInterval));
                keycodeInfoList.Add(new KeycodeInfo("f7", MachineInfo.MachineConfigEntity.C_SendCommandInterval));
                keycodeInfoList.Add(new KeycodeInfo("wait500", MachineInfo.MachineConfigEntity.C_SendCommandInterval));
                keycodeInfoList.Add(new KeycodeInfo("enter", MachineInfo.MachineConfigEntity.C_SendCommandInterval));

                //是否输入密码
                keycodeInfoList.AddRange(modeService.GetPasswordKeycodeList(ticketEntity, MachineInfo));
            }


            //根据设置加键码间隔
            if (LocalConfigUtil.KeyInterval != 0)
            {
                Random random = new Random();
                int min = LocalConfigUtil.KeyInterval - 50;
                int max = LocalConfigUtil.KeyInterval + 50;
                foreach (KeycodeInfo ki in keycodeInfoList)
                {

                    ki.SendInterval += random.Next(min, max);
                }
            }

            //测试的时候注意，直到这一步，票已经发给彩票机了
            VirtualKeyboard.Input(keycodeInfoList);

            decodePrintData.InputData = VirtualPrinter.Output();

            modeService.DecodeData(ticketEntity, MachineInfo, decodePrintData);

            //TODO TEST
            //JcTicketSimulator.Build(ticketEntity,decodePrintData);
            if (decodePrintData.DecodeSuccess)
            {
                ticketEntity.L_TicketCode = decodePrintData.L_PrintTicketEntity.P_TicketCode;
                ticketEntity.L_RandomCode = decodePrintData.L_PrintTicketEntity.P_RandomCode;
                ticketEntity.L_Password = decodePrintData.L_PrintTicketEntity.P_Password;
                ticketEntity.L_SucTime = decodePrintData.L_PrintTicketEntity.P_SucTime;
                ticketEntity.L_SaleAddress = decodePrintData.L_PrintTicketEntity.P_SaleAddress;
                ticketEntity.L_CodeRate = decodePrintData.L_PrintTicketEntity.L_CodeRate;
                ticketEntity.L_MaxGetMoney = decodePrintData.L_PrintTicketEntity.L_MaxGetMoney;
                ticketEntity.L_CodeReference = decodePrintData.L_PrintTicketEntity.L_CodeReference;
                ticketEntity.L_Status = (int)TicketStatus.Suc;
                ticketEntity.L_LimitType = 0;

                LastSucTicket = CurrentTicket;

                //出票成功后，清除缓存
                ClearBuffer();
                //Wait(500);
            }
            Log.Debug(string.Concat("生产流水号：", ticketEntity.L_TicketSn, " Print完成"));
        }

        /// <summary>
        /// 重新获取数据
        /// </summary>
        /// <param name="ticketEntity"></param>
        /// <param name="decodePrintData"></param>
        public override void ReGetdata(L_LotTicketEntity ticketEntity, DecodePrintData decodePrintData)
        {
            MacLotPlayModeServiceFactory modeServiceFactory = new MacLotPlayModeServiceFactory();
            IMacLotPlayModeService modeService = modeServiceFactory.GetLotPlayService(ticketEntity.MacModeId);
            decodePrintData.InputData = VirtualPrinter.ReOutput();
            modeService.DecodeData(ticketEntity, MachineInfo, decodePrintData);
            if (decodePrintData.DecodeSuccess)
            {
                ticketEntity.L_TicketCode = decodePrintData.L_PrintTicketEntity.P_TicketCode;
                ticketEntity.L_RandomCode = decodePrintData.L_PrintTicketEntity.P_RandomCode;
                ticketEntity.L_Password = decodePrintData.L_PrintTicketEntity.P_Password;
                ticketEntity.L_SucTime = decodePrintData.L_PrintTicketEntity.P_SucTime;
                ticketEntity.L_SaleAddress = decodePrintData.L_PrintTicketEntity.P_SaleAddress;
                ticketEntity.L_CodeRate = decodePrintData.L_PrintTicketEntity.L_CodeRate;
                ticketEntity.L_MaxGetMoney = decodePrintData.L_PrintTicketEntity.L_MaxGetMoney;
                ticketEntity.L_CodeReference = decodePrintData.L_PrintTicketEntity.L_CodeReference;
                ticketEntity.L_Status = (int)TicketStatus.Suc;
                ticketEntity.L_LimitType = 0;
                ticketEntity.L_PrnText = decodePrintData.L_PrintTicketEntity.P_PrnText;
                ticketEntity.L_NotifyStatus = (int)NotifyStatus.NotifyAble;

                LastSucTicket = CurrentTicket;
            }
        }

        /// <summary>
        /// 测试电子票解析
        /// </summary>
        /// <param name="ticketEntity"></param>
        /// <param name="decodePrintData"></param>
        public override void TestDecodeTicket(L_LotTicketEntity ticketEntity, DecodePrintData decodePrintData)
        {
            MacLotPlayModeServiceFactory modeServiceFactory = new MacLotPlayModeServiceFactory();
            IMacLotPlayModeService modeService = modeServiceFactory.GetLotPlayService(ticketEntity.MacModeId);
            modeService.DecodeData(ticketEntity, MachineInfo, decodePrintData);
        }



        /// <summary>
        /// 获取缓冲区票
        /// </summary>
        /// <returns></returns>
        public override CaptureDataInfo GetCacheTicket()
        {
            return null;
        }

        /// <summary>
        /// 获取最后一张票
        /// </summary>
        /// <returns></returns>
        public override CaptureDataInfo GetLastTicket()
        {
            return null;
        }

        /// <summary>
        /// 兑奖指定的票
        /// </summary>
        /// <param name="ticketEntity"></param>
        public override void Encash(L_LotTicketEntity ticketEntity)
        {
            /*DecodeMachineReport decodeMachineReport;
            if (!LastEncashSuc || LastMachineReport == null)
            {
                //打印机器报表
                decodeMachineReport = new DecodeMachineReport();
                for (int i = 0; i < 3; i++)
                {
                    this.PrintCurrentDayReport(decodeMachineReport);
                    if (decodeMachineReport.DecodeSuccess)
                    {
                        break;
                    }
                    else
                    {
                        Log.Info(string.Concat("打印报表失败：", decodeMachineReport.ErrorMessage));
                    }
                }
                if (decodeMachineReport.DecodeSuccess)
                {
                    LastMachineReport = decodeMachineReport.MachineReportEntity;
                }
                else
                {
                    Log.Warn(string.Concat("打印报表失败：", decodeMachineReport.ErrorMessage));
                    return;
                }
            }*/

            OnEncashing(ticketEntity);
            //Log.Info("开始模拟兑奖" + ticketEntity.L_TicketSn);
            List<KeycodeInfo> keycodeList = new List<KeycodeInfo>();
            int waittime = 1000;    //有1秒缓冲

            //兑奖前键码
            //for (int i = 0; i < MachineInfo.MachineConfigEntity.C_BeforeEncashKeys.Length; i++)
            //{
            //    keycodeList.Add(new KeycodeInfo(MachineInfo.MachineConfigEntity.C_BeforeEncashKeys.Substring(i, 1), MachineInfo.MachineConfigEntity.C_SendCommandInterval));
            //}
            if (!string.IsNullOrEmpty(MachineInfo.MachineConfigEntity.C_BeforeEncashKeys))
            {
                foreach (string key in MachineInfo.MachineConfigEntity.C_BeforeEncashKeys.Split(','))
                {
                    keycodeList.Add(new KeycodeInfo(key, MachineInfo.MachineConfigEntity.C_SendCommandInterval, true));
                }
            }
            //票号
            for (int i = 0; i < ticketEntity.L_TicketCode.Length; i++)
            {
                keycodeList.Add(new KeycodeInfo(ticketEntity.L_TicketCode.Substring(i, 1), MachineInfo.MachineConfigEntity.C_SendKeyInterval, true));
            }
            //竞彩票号不足24位，只有20位，不会自动跳到密码框，可以按right
            keycodeList.Add(new KeycodeInfo("right", MachineInfo.MachineConfigEntity.C_SendKeyInterval, true));
            //密码
            for (int i = 0; i < ticketEntity.L_Password.Length; i++)
            {
                keycodeList.Add(new KeycodeInfo(ticketEntity.L_Password.Substring(i, 1), MachineInfo.MachineConfigEntity.C_SendKeyInterval, true));
            }
            //兑奖确认
            //if (!string.IsNullOrEmpty(MachineInfo.MachineConfigEntity.C_AfterEncashKeys))
            //{
            //    foreach (string key in MachineInfo.MachineConfigEntity.C_AfterEncashKeys.Split(','))
            //    {
            //        keycodeList.Add(new KeycodeInfo(key, MachineInfo.MachineConfigEntity.C_SendCommandInterval));
            //    }
            //}
            if (ticketEntity.EncashOption == 1)
            {
                if (!string.IsNullOrEmpty(MachineInfo.MachineConfigEntity.C_AfterEncashKeysNoReturn))
                {
                    foreach (string key in MachineInfo.MachineConfigEntity.C_AfterEncashKeysNoReturn.Split(','))
                    {
                        keycodeList.Add(new KeycodeInfo(key, MachineInfo.MachineConfigEntity.C_SendCommandInterval, true));
                    }
                }
            }
            else
            {
                if (!string.IsNullOrEmpty(MachineInfo.MachineConfigEntity.C_AfterEncashKeys))
                {
                    foreach (string key in MachineInfo.MachineConfigEntity.C_AfterEncashKeys.Split(','))
                    {
                        keycodeList.Add(new KeycodeInfo(key, MachineInfo.MachineConfigEntity.C_SendCommandInterval, true));
                    }
                }
            }
            //等待间隔
            //keycodeList.Add(new KeycodeInfo("wait", 1000));
            this.VirtualKeyboard.Input(keycodeList);
            waittime += SendKeysTime(keycodeList);
            Log.Info(string.Concat("等待：", waittime, "毫秒"));
            Thread.Sleep(waittime);

            MacCurrentMode = null;
            MacCurrentExpect = null;

            //打印机器报表
            /*decodeMachineReport = new DecodeMachineReport();
            for (int i = 0; i < 3; i++)
            {
                this.PrintCurrentDayReport(decodeMachineReport);
                if (decodeMachineReport.DecodeSuccess)
                {
                    break;
                }
                else
                {
                    Log.Info(string.Concat("打印报表失败：", decodeMachineReport.ErrorMessage));
                }
            }
            if (decodeMachineReport.DecodeSuccess)
            {
                R_MachineReportEntity currentMachineReport = decodeMachineReport.MachineReportEntity;

                Log.Info(string.Concat("最近一次报表 已兑奖票数：", LastMachineReport.R_EncashTicket, " 已兑奖金额：", LastMachineReport.R_EncashMoney, "当前报表 已兑奖票数：", currentMachineReport.R_EncashTicket, " 已兑奖金额：", currentMachineReport.R_EncashMoney));
                if (currentMachineReport.R_EncashTicket == LastMachineReport.R_EncashTicket + 1 && currentMachineReport.R_EncashMoney == LastMachineReport.R_EncashMoney + ticketEntity.L_GetMoney)
                {
                    //兑奖成功
                    ticketEntity.L_EncashStatus = (int)EncashStatus.Success;
                    JcL_LotTicketService lotTicketService = new JcL_LotTicketService();
                    lotTicketService.SetTicketEncashed(ticketEntity);
                    Log.Info(string.Concat("设置生产流水号：", ticketEntity.L_TicketSn, "兑奖成功"));
                }
                LastMachineReport = currentMachineReport;
            }
            else
            {
                Log.Warn(string.Concat("打印报表失败：", decodeMachineReport.ErrorMessage));
                return;
            }*/

            OnEncashed(ticketEntity);
        }

        /// <summary>
        /// 打印缴款报表
        /// </summary>
        /// <param name="isPaperOut">是否出纸</param>
        /// <param name="decodePrintData"></param>
        public override void PrintPayMoneyReport(DecodeMachinePayMoneyReport decodePrintData, bool isPaperOut)
        {
            try
            {
                MachineStatusEnum status = (MachineStatusEnum)MachineInfo.M_Status;
                if (status != MachineStatusEnum.Stopped)
                {
                    Log.Info("机器不是停止状态，无法打印缴款报表");
                    return;
                }

                List<KeycodeInfo> keycodeList = new List<KeycodeInfo>();

                if (!MachineInfo.M_HasJc)
                {
                    MachineInfo.MachineConfigEntity.C_UpdateMoneyKeys = MachineInfo.MachineConfigEntity.C_UpdateMoneyKeys.Replace(",0,9,", ",0,8,");
                }

                if (!string.IsNullOrEmpty(MachineInfo.MachineConfigEntity.C_UpdateMoneyKeys))
                {
                    foreach (string key in MachineInfo.MachineConfigEntity.C_UpdateMoneyKeys.Split(','))
                    {
                        keycodeList.Add(new KeycodeInfo(key, MachineInfo.MachineConfigEntity.C_SendCommandInterval));
                    }
                }
                VirtualPrinter.ClearBuffer();


                VirtualKeyboard.Input(keycodeList);
                decodePrintData.InputData = VirtualPrinter.Output();
                if (isPaperOut)
                {
                    //PrinterClient.AddBytes(decodePrintData.InputData.CaptureDataBytes);
                }
                MacReportService macReportService = new MacReportService();
                macReportService.DecodeMachinePayMoneyReport(MachineInfo, decodePrintData);

                ReturnTopGui();
            }
            catch (Exception ex)
            {
                Log.Error(string.Format("【{0}】【{1}】异常：{2}\r\n{3}", "打印缴款报表", MachineInfo.M_Number, ex.Message, ex.StackTrace));
                //return (int)(WcfCodeEnum.UpdateMahineMoneyException);
                decodePrintData.ErrorMessage += ex.Message;
                //return decodePrintData;
            }
        }

        /// <summary>
        /// 打印时段报表，竞彩实际上打的竞彩时段报表
        /// </summary>
        /// <returns></returns>
        public override void PrintReport(DateTime startTime, DateTime endTime, DecodeMachineReport decodePrintData, bool isPaperOut)
        {
            try
            {
                MachineStatusEnum status = (MachineStatusEnum)MachineInfo.M_Status;
                if (status != MachineStatusEnum.Stopped)
                {
                    Log.Info("机器不是停止状态，无法打印时段报表");
                    return;
                }

                MacReportService macReportService = new MacReportService();
                List<KeycodeInfo> keycodeInfoList = macReportService.GetMachineReportKeycodeList(MachineInfo, startTime, endTime);
                //清空打印接收缓存
                VirtualPrinter.ClearBuffer();

                VirtualKeyboard.Input(keycodeInfoList);
                decodePrintData.InputData = VirtualPrinter.Output();
                if (isPaperOut)
                {
                    //PrinterClient.AddBytes(decodePrintData.InputData.CaptureDataBytes);
                }
                macReportService.DecodeMachineReportReport(MachineInfo, decodePrintData);

                ReturnTopGui();
            }
            catch (Exception ex)
            {
                Log.Error(string.Format("【{0}】【{1}】异常：{2}\r\n{3}", "打印时段报表", MachineInfo.M_Number, ex.Message, ex.StackTrace));
                throw new Exception(ex.Message);
            }
        }

        /// <summary>
        /// 打印竟彩机器报表
        /// </summary>
        /// <returns></returns>
        public override void PrintJcReport(DateTime startTime, DateTime endTime, DecodeMachineReport decodePrintData, bool isPaperOut)
        {
            try
            {
                MachineStatusEnum status = (MachineStatusEnum)MachineInfo.M_Status;
                if (status != MachineStatusEnum.Stopped)
                {
                    Log.Info("机器不是停止状态，无法打印竟彩时段报表");
                    return;
                }

                //MacReportService macReportService = new MacReportService();
                //Common.Communication.CpdJson.Packs.P12020PrintJcTimeReport reqPack = new Common.Communication.CpdJson.Packs.P12020PrintJcTimeReport();
                //reqPack.MacNumber = MachineInfo.M_Number;
                //reqPack.StartTime = startTime;
                //reqPack.EndTime = endTime;
                //reqPack.IsPaperOut = isPaperOut;
                //Common.Communication.CpdJson.PackRetBase packRetBase = Common.Communication.CpdJson.PackManager.Instance.Transaction(MachineInfo.M_Number, reqPack, Log);
                //if (packRetBase == null)
                //{
                //    throw new Exception(string.Concat("打印竟彩时段报表失败。机器号：", MachineInfo.M_Number));
                //}
                //if (packRetBase.ReturnCode != 0)
                //{
                //    throw new Exception(string.Concat("彩票机返回错误编码：", packRetBase.ReturnCode, " 错误信息：", packRetBase.ReturnMessage));
                //}
                //Common.Communication.CpdJson.Packs.P12020PrintJcTimeReportRet resPack = packRetBase as Common.Communication.CpdJson.Packs.P12020PrintJcTimeReportRet;
                //if (resPack == null)
                //{
                //    throw new Exception(string.Concat("打印竟彩时段报表失败。机器号：", MachineInfo.M_Number));
                //}
                //decodePrintData.InputData = new CaptureDataInfo(resPack.PrnText.Length > 0 ? HexStringUtil.StringToByte(resPack.PrnText) : new byte[] { });
                //if (decodePrintData.InputData.CaptureDataBytes.Length > 0)
                //{
                //    this.VirtualPrinter.SaveLastFile(decodePrintData.InputData.CaptureDataBytes);
                //}

                MacReportService macReportService = new MacReportService();
                List<KeycodeInfo> keycodeInfoList = macReportService.GetJcMachineReportKeycodeList(MachineInfo, startTime, endTime);
                //清空打印接收缓存
                VirtualPrinter.ClearBuffer();

                VirtualKeyboard.Input(keycodeInfoList);
                decodePrintData.InputData = VirtualPrinter.Output();
                if (isPaperOut)
                {
                    //PrinterClient.AddBytes(decodePrintData.InputData.CaptureDataBytes);
                }

                macReportService.DecodeMachineReportReport(MachineInfo, decodePrintData);
                //if (!decodePrintData.DecodeSuccess)
                //{
                //    macReportService.DecodeMachineReportReport(MachineInfo, decodePrintData);
                //}
                Log.Info(string.Concat("打印竟彩时段报表完成，DecodeSuccess：", decodePrintData.DecodeSuccess + " DecodeMessage:" + decodePrintData.ErrorMessage));

                ReturnTopGui();
            }
            catch (Exception ex)
            {
                Log.Error(string.Format("【{0}】【{1}】异常：{2}\r\n{3}", "打印竟彩时段报表", MachineInfo.M_Number, ex.Message, ex.StackTrace));
                throw new Exception(ex.Message);
            }
        }
        public override void PrintCurrentDayReport(DecodeMachineReport decodePrintData, bool isPaperOut)
        {
            DateTime now = DateTime.Now;
            DateTime startTime = new DateTime(now.Year, now.Month, now.Day);
            DateTime endTime = startTime;
            try
            {
                MachineStatusEnum status = (MachineStatusEnum)MachineInfo.M_Status;
                if (status == MachineStatusEnum.Printing)
                {
                    Log.Info("出票中的机器，无法打印时段报表");
                    return;
                }

                MacReportService macReportService = new MacReportService();
                List<KeycodeInfo> keycodeInfoList = macReportService.GetMachineReportKeycodeList(MachineInfo, startTime, endTime);
                //清空打印接收缓存
                VirtualPrinter.ClearBuffer();

                VirtualKeyboard.Input(keycodeInfoList);
                decodePrintData.InputData = VirtualPrinter.Output();
                macReportService.DecodeMachineReportReport(MachineInfo, decodePrintData);

                MacCurrentMode = null;
                MacCurrentExpect = null;
            }
            catch (Exception ex)
            {
                Log.Error(string.Format("【{0}】【{1}】异常：{2}\r\n{3}", "打印时段报表", MachineInfo.M_Number, ex.Message, ex.StackTrace));
                throw new Exception(ex.Message);
            }
        }

        /// <summary>
        /// 打印机器玩法报表
        /// </summary>
        /// <returns></returns>
        public override void PrintPlayReport(M_PlayTypeEntity playTypeEntity, DateTime startTime, DateTime endTime, DecodeMachinePlayReport decodePrintData, bool isPaperOut)
        {
            try
            {
                MachineStatusEnum status = (MachineStatusEnum)MachineInfo.M_Status;
                if (status != MachineStatusEnum.Stopped)
                {
                    Log.Info("机器不是停止状态，无法打印玩法时段报表");
                    return;
                }

                MacReportService macReportService = new MacReportService();
                List<KeycodeInfo> keycodeInfoList = macReportService.GetMachinePlayReportKeycodeList(MachineInfo, playTypeEntity, startTime, endTime);
                //清空打印接收缓存
                VirtualPrinter.ClearBuffer();

                VirtualKeyboard.Input(keycodeInfoList);
                decodePrintData.InputData = VirtualPrinter.Output();
                if (isPaperOut)
                {
                    //PrinterClient.AddBytes(decodePrintData.InputData.CaptureDataBytes);
                }
                macReportService.DecodeMachinePlayReportReport(MachineInfo, decodePrintData);
                MacCurrentMode = null;
                MacCurrentExpect = null;

                //EnterSaleGui();//进入销售界面
            }
            catch (Exception ex)
            {
                Log.Error(string.Format("【{0}】【{1}】异常：{2}\r\n{3}", "打印玩法时段报表", MachineInfo.M_Number, ex.Message, ex.StackTrace));
                throw new Exception(ex.Message);
            }
        }

        /// <summary>
        /// 查看机器中奖金额
        /// </summary>
        /// <param name="ticketEntity"></param>
        public override void ViewPrizeMoney(L_LotTicketEntity ticketEntity)
        {
            try
            {

                MachineStatusEnum status = (MachineStatusEnum)MachineInfo.M_Status;
                if (status != MachineStatusEnum.Stopped)
                {
                    Log.Info("机器不是停止状态，无法查看机器中奖金额");
                    return;
                }
                List<KeycodeInfo> keycodeList = new List<KeycodeInfo>();
                //进入兑奖界面
                if (!string.IsNullOrEmpty(MachineInfo.MachineConfigEntity.C_BeforeEncashKeys))
                {
                    foreach (string key in MachineInfo.MachineConfigEntity.C_BeforeEncashKeys.Split(','))
                    {
                        keycodeList.Add(new KeycodeInfo(key, MachineInfo.MachineConfigEntity.C_SendCommandInterval));
                    }
                }
                //票号
                for (int i = 0; i < ticketEntity.L_TicketCode.Length; i++)
                {
                    keycodeList.Add(new KeycodeInfo(ticketEntity.L_TicketCode.Substring(i, 1), MachineInfo.MachineConfigEntity.C_SendKeyInterval));
                }
                //密码
                for (int i = 0; i < ticketEntity.L_Password.Length; i++)
                {
                    keycodeList.Add(new KeycodeInfo(ticketEntity.L_TicketCode.Substring(i, 1), MachineInfo.MachineConfigEntity.C_SendKeyInterval));
                }
                //兑奖确认（停留在奖金界面）
                if (!string.IsNullOrEmpty(MachineInfo.MachineConfigEntity.C_ViewPrizeKeys))
                {
                    foreach (string key in MachineInfo.MachineConfigEntity.C_ViewPrizeKeys.Split(','))
                    {
                        keycodeList.Add(new KeycodeInfo(key, MachineInfo.MachineConfigEntity.C_SendCommandInterval));
                    }
                }
                VirtualKeyboard.Input(keycodeList);
                MacCurrentMode = null;
                MacCurrentExpect = null;
            }
            catch (Exception ex)
            {
                Log.Error(string.Format("【{0}】【{1}】异常：{2}\r\n{3}", "查看机器中奖金额", MachineInfo.M_Number, ex.Message, ex.StackTrace));
                throw new Exception(ex.Message);
            }
        }
        /// <summary>
        /// 字符间插入字符串
        /// </summary>
        /// <param name="source"></param>
        /// <param name="chr"></param>
        /// <returns></returns>
        private string InsertChar(string source, string chr)
        {
            int length = source.Length;
            if (length > 1)
            {
                for (int i = length - 1; i > 0; i--)
                {
                    source = source.Insert(i, chr);
                }
            }

            return source;
        }
        /// <summary>
        /// 登录彩票机
        /// </summary>
        public override void Login()
        {
            try
            {
                MachineStatusEnum status = (MachineStatusEnum)MachineInfo.M_Status;
                if (status != MachineStatusEnum.Stopped)
                {
                    Log.Info("机器不是停止状态，无法登录");
                    return;
                }
                Log.Info("开始执行登录彩票机命令");

                List<KeycodeInfo> keycodeList = new List<KeycodeInfo>();
                string loginKeys = MachineInfo.MachineConfigEntity.C_LoginKeys;
                if (!string.IsNullOrEmpty(loginKeys))
                {
                    string zxNumber = InsertChar(MachineInfo.M_ZxNumber, ",");
                    string zxPassword = InsertChar(MachineInfo.M_ZxPassword, ",");
                    loginKeys = loginKeys.Replace("zxnumber", zxNumber).Replace("zxpassword", zxPassword);
                    foreach (string key in loginKeys.Split(','))
                    {
                        keycodeList.Add(new KeycodeInfo(key, MachineInfo.MachineConfigEntity.C_SendCommandInterval));
                    }
                }
                VirtualKeyboard.Input(keycodeList);
            }
            catch (Exception ex)
            {
                Log.Error(string.Format("【{0}】【{1}】异常：{2}\r\n{3}", "登录彩票机", MachineInfo.M_Number, ex.Message, ex.StackTrace));
                //return (int)(WcfCodeEnum.LoginMahineException);
            }
        }

        /// <summary>
        /// 关闭彩票机
        /// </summary>
        public override void Shutdown()
        {
            try
            {
                MachineStatusEnum status = (MachineStatusEnum)MachineInfo.M_Status;
                if (status != MachineStatusEnum.Stopped)
                {
                    Log.Info("机器不是停止状态，无法关闭");
                    return;
                }

                List<KeycodeInfo> keycodeList = new List<KeycodeInfo>();
                string shutdownKeys = MachineInfo.MachineConfigEntity.C_ShutdownKeys;
                if (!string.IsNullOrEmpty(shutdownKeys))
                {
                    foreach (string key in shutdownKeys.Split(','))
                    {
                        keycodeList.Add(new KeycodeInfo(key, MachineInfo.MachineConfigEntity.C_SendCommandInterval));
                    }
                }
                VirtualKeyboard.Input(keycodeList);
            }
            catch (Exception ex)
            {
                Log.Error(string.Format("【{0}】【{1}】异常：{2}\r\n{3}", "关闭彩票机", MachineInfo.M_Number, ex.Message, ex.StackTrace));
                //return (int)(WcfCodeEnum.ShutdownMahineException);
            }
        }

        /// <summary>
        /// 打印测试票
        /// </summary>
        public override CaptureDataInfo PrintTestTicket(bool isPaperOut)
        {
            CaptureDataInfo captureData = new CaptureDataInfo(new byte[] { });
            try
            {
                MachineStatusEnum status = (MachineStatusEnum)MachineInfo.M_Status;
                if (status != MachineStatusEnum.Stopped)
                {
                    Log.Info("机器不是停止状态，无法打印测试票");
                    return captureData;
                }

                VirtualPrinter.ClearBuffer();
                List<KeycodeInfo> keycodeList = new List<KeycodeInfo>();
                if (!string.IsNullOrEmpty(MachineInfo.MachineConfigEntity.C_PrintTestTicketKeys))
                {
                    foreach (string key in MachineInfo.MachineConfigEntity.C_PrintTestTicketKeys.Split(','))
                    {
                        keycodeList.Add(new KeycodeInfo(key, MachineInfo.MachineConfigEntity.C_SendCommandInterval));
                    }
                }
                VirtualKeyboard.Input(keycodeList);

                captureData = new CaptureDataInfo(VirtualPrinter.Output().CaptureDataBytes);
                //PrinterClient.AddBytes(VirtualPrinter.Output().CaptureDataBytes);

                MacCurrentMode = null;
                MacCurrentExpect = null;
                IsPrintedTest = true;

            }
            catch (Exception ex)
            {
                Log.Error(string.Format("【{0}】【{1}】异常：{2}\r\n{3}", "打印测试票", MachineInfo.M_Number, ex.Message, ex.StackTrace));
            }
            return captureData;
        }


        /// <summary>
        /// 打印对阵信息
        /// </summary>
        public override CaptureDataInfo PrintMatch(int lotId)
        {
            CaptureDataInfo captureData = new CaptureDataInfo(new byte[] { });
            try
            {
                VirtualPrinter.ClearBuffer();
                List<KeycodeInfo> keycodeList = new List<KeycodeInfo>();

                if (lotId == (int)Lottype.Jz)
                {
                    if (!string.IsNullOrEmpty(MachineInfo.MachineConfigEntity.C_PrintJzMatchKeys))
                    {
                        foreach (string key in MachineInfo.MachineConfigEntity.C_PrintJzMatchKeys.Split(','))
                        {
                            keycodeList.Add(new KeycodeInfo(key, MachineInfo.MachineConfigEntity.C_SendCommandInterval));
                        }
                    }
                }
                else if (lotId == (int)Lottype.Jl)
                {
                    if (!string.IsNullOrEmpty(MachineInfo.MachineConfigEntity.C_PrintJlMatchKeys))
                    {
                        foreach (string key in MachineInfo.MachineConfigEntity.C_PrintJlMatchKeys.Split(','))
                        {
                            keycodeList.Add(new KeycodeInfo(key, MachineInfo.MachineConfigEntity.C_SendCommandInterval));
                        }
                    }
                }

                VirtualKeyboard.Input(keycodeList);

                captureData = new CaptureDataInfo(VirtualPrinter.Output().CaptureDataBytes);
                //PrinterClient.AddBytes(VirtualPrinter.Output().CaptureDataBytes);


                if (captureData.CaptureDataBytes.Length > 0)
                {
                    //this.VirtualPrinter.SaveLastFile(captureData.CaptureDataBytes);
                    Log.Info(string.Concat("打印对阵成功，彩种ID：", lotId));
                }
                else
                {
                    Log.Info(string.Concat("打印对阵失败，彩种ID：", lotId));
                }

                ReturnTopGui();

                IsPrintedTest = true;
            }
            catch (Exception ex)
            {
                Log.Error(string.Format("【{0}】【{1}】异常：{2}\r\n{3}", "打印对阵", MachineInfo.M_Number, ex.Message, ex.StackTrace));
            }
            return captureData;
        }

        /// <summary>
        /// 打印足彩对阵信息
        /// </summary>
        /// <param name="lotId">足彩彩种id</param>
        /// <param name="index">1-当前期；2-下一期；3-下下期</param>
        /// <returns></returns>
        public override CaptureDataInfo PrintZcMatch(int lotId, int index)
        {
            return new CaptureDataInfo(new byte[] { });
        }

        /// <summary>
        /// 打印开奖报表
        /// </summary>
        public override CaptureDataInfo PrintOpenCodeReport(int lotId)
        {
            CaptureDataInfo captureData = new CaptureDataInfo(new byte[] { });
            try
            {
                List<KeycodeInfo> keycodeList = new List<KeycodeInfo>();
                string keys = "esc,esc,esc,f3,wait500,1,2,wait200,0,5,wait4000,enter";
                foreach (string key in keys.Split(','))
                {
                    keycodeList.Add(new KeycodeInfo(key, MachineInfo.MachineConfigEntity.C_SendCommandInterval));
                }

                //清空打印接收缓存
                VirtualPrinter.ClearBuffer();

                VirtualKeyboard.Input(keycodeList);
                captureData = new CaptureDataInfo(VirtualPrinter.Output().CaptureDataBytes);

                ReturnTopGui();
            }
            catch (Exception ex)
            {
                Log.Error(string.Format("【{0}】【{1}】异常：{2}\r\n{3}", "打印开奖报表", MachineInfo.M_Number, ex.Message, ex.StackTrace));
                throw new Exception(ex.Message);
            }
            return captureData;
        }

        /// <summary>
        /// 清楚彩票机合计金额
        /// </summary>
        /// <returns>是否成功</returns>
        public override void ClearMahineMoney()
        {
            try
            {
                //MachineStatusEnum status = (MachineStatusEnum)MachineInfo.M_Status;
                //if (status != MachineStatusEnum.Stopped)
                //{
                //    Log.Info("机器不是停止状态，无法清除彩票机合计");
                //    return;
                //}

                List<KeycodeInfo> keycodeList = new List<KeycodeInfo>();
                if (!string.IsNullOrEmpty(MachineInfo.MachineConfigEntity.C_ClearAmountKeys))
                {
                    foreach (string key in MachineInfo.MachineConfigEntity.C_ClearAmountKeys.Split(','))
                    {
                        keycodeList.Add(new KeycodeInfo(key, MachineInfo.MachineConfigEntity.C_SendCommandInterval));
                    }
                }
                VirtualKeyboard.Input(keycodeList);

                ReturnTopGui();

            }
            catch (Exception ex)
            {
                Log.Error(string.Format("【{0}】【{1}】异常：{2}\r\n{3}", "清除彩票机合计", MachineInfo.M_Number, ex.Message, ex.StackTrace));
                //return (int)(WcfCodeEnum.ClearMahineMoneyException);
            }
        }

        /// <summary>
        /// 清除彩票机错误
        /// </summary>
        /// <param name="errorType"></param>
        /*public override void ClearError(int errorType)
        {
            try
            {
                string msg = string.Concat("清除彩票机弹窗[", errorType == (int)MachineErrorType.JcExpectUpdate ? "奖期已更新" : "条件已改变", "]");
                Log.Info(msg);
                List<KeycodeInfo> keycodeList = new List<KeycodeInfo>();
                keycodeList.Add(new KeycodeInfo("enter", 30));
                keycodeList.Add(new KeycodeInfo("esc", 1500));
                keycodeList.Add(new KeycodeInfo("enter", 1500));
                if (errorType == (int)MachineErrorType.JlConditionChange && CurrentTicket.LotId == (int)Lottype.Jl)
                {
                    Log.Info("清除彩票机弹窗[条件已改变]后，重新进入销售界面");
                    keycodeList.Add(new KeycodeInfo("esc", 1500));
                    keycodeList.Add(new KeycodeInfo("esc", 1500));
                    //keycodeList.Add(new KeycodeInfo("wait1500", 1500));
                    keycodeList.Add(new KeycodeInfo("0", 1500));
                    keycodeList.Add(new KeycodeInfo("1", 30));
                    keycodeList.Add(new KeycodeInfo("5", 30));
                    keycodeList.Add(new KeycodeInfo("1", 30));
                }
                this.VirtualKeyboard.Input(keycodeList);
                int totaltime = 0;
                foreach (KeycodeInfo keycodeInfo in keycodeList)
                {
                    totaltime += keycodeInfo.SendInterval;
                }
                Wait2(totaltime); 
            }
            catch (Exception exception)
            {
                Log.Error(string.Concat("清除彩票机错误异常。错误信息：",exception));
            }
        }*/
        /// <summary>
        /// 清除彩票机错误
        /// </summary>
        /// <param name="errorType"></param>
        public override void ClearError(int errorType)
        {
            try
            {
                MachineErrorType machineErrorType = (MachineErrorType)errorType;

                string msg = string.Concat("清除彩票机弹窗[", EnumDescription.GetFieldText(machineErrorType), "]");

                List<KeycodeInfo> keycodeList = new List<KeycodeInfo>();

                ////错误界面可能会有是否退出系统的对话框，需要
                //keycodeList.Add(new KeycodeInfo("esc", 300));
                //keycodeList.Add(new KeycodeInfo("esc", 300));
                if (machineErrorType == MachineErrorType.JcStopSale)
                {
                    //错误界面可能会有是否退出系统的对话框，需要
                    keycodeList.Add(new KeycodeInfo("esc", 300));
                    keycodeList.Add(new KeycodeInfo("esc", 300));

                    keycodeList.Add(new KeycodeInfo("enter", 300));
                }
                else if (machineErrorType == MachineErrorType.JcExpectUpdate)
                {
                    //错误界面可能会有是否退出系统的对话框，需要
                    keycodeList.Add(new KeycodeInfo("esc", 300));
                    keycodeList.Add(new KeycodeInfo("esc", 300));

                    keycodeList.Add(new KeycodeInfo("enter", 300));
                    keycodeList.Add(new KeycodeInfo("esc", 1500));
                    keycodeList.Add(new KeycodeInfo("enter", 1500));
                }
                else
                {
                    //keycodeList.Add(new KeycodeInfo("enter", 300));
                    //keycodeList.Add(new KeycodeInfo("esc", 1500));
                    //keycodeList.Add(new KeycodeInfo("enter", 1500));
                    //if (CurrentTicket.LotId == (int)Lottype.Jl)
                    //{
                    msg = "清除彩票机弹窗[条件已改变]，并重新进入销售界面";
                    ////keycodeList.Add(new KeycodeInfo("esc", 2000));
                    ////keycodeList.Add(new KeycodeInfo("esc", 3000));
                    ////keycodeList.Add(new KeycodeInfo("0", 4000));
                    ////keycodeList.Add(new KeycodeInfo("1", 300));
                    ////keycodeList.Add(new KeycodeInfo("5", 300));
                    ////keycodeList.Add(new KeycodeInfo("1", 300));
                    //keycodeList.Add(new KeycodeInfo("5", 300));
                    //keycodeList.Add(new KeycodeInfo("1", 300));
                    //keycodeList.Add(new KeycodeInfo("f3", 3000));
                    //keycodeList.Add(new KeycodeInfo("esc", 300));

                    keycodeList.Add(new KeycodeInfo("enter", 300));
                    keycodeList.Add(new KeycodeInfo("f3", 3000));
                    keycodeList.Add(new KeycodeInfo("esc", 300));
                    keycodeList.Add(new KeycodeInfo("esc", 300));
                    keycodeList.Add(new KeycodeInfo("enter", 300));
                    //}
                    //else
                    //{
                    //    keycodeList.Add(new KeycodeInfo("enter", 300));
                    //    keycodeList.Add(new KeycodeInfo("esc", 1500));
                    //    keycodeList.Add(new KeycodeInfo("enter", 1500));
                    //}
                }
                keycodeList.Add(new KeycodeInfo("wait", 300));
                Log.Info(msg);
                VirtualKeyboard.Input(keycodeList);
                int totaltime = 0;
                foreach (KeycodeInfo keycodeInfo in keycodeList)
                {
                    totaltime += keycodeInfo.SendInterval;
                }
                Wait2(totaltime);
                Log.Info(msg + "已完成");

                ReturnTopGui();
            }
            catch (Exception exception)
            {
                Log.Error(string.Concat("清除彩票机错误异常。错误信息：", exception));
            }
        }

        /// <summary>
        /// 清除彩票机弹窗“奖期已更新”（竟彩）
        /// </summary>
        public override void ClearExpectUpdate()
        {
            try
            {
                Log.Info("清除彩票机弹窗[奖期已更新]");
                List<KeycodeInfo> keycodeList = new List<KeycodeInfo>();
                keycodeList.Add(new KeycodeInfo("5", 30));
                keycodeList.Add(new KeycodeInfo("1", 30));
                keycodeList.Add(new KeycodeInfo("enter", 300));
                keycodeList.Add(new KeycodeInfo("esc", 300));
                this.VirtualKeyboard.Input(keycodeList);
            }
            catch (Exception exception)
            {
                Log.Error(string.Concat("清除彩票机弹窗[奖期已更新]异常。错误信息：", exception));
            }
        }

        /// <summary>
        /// 刷新机器额度
        /// </summary>
        /// <returns></returns>
        public override void RefreshMahineMoney()
        {
            try
            {
                MachineStatusEnum status = (MachineStatusEnum)MachineInfo.M_Status;
                if (status != MachineStatusEnum.Stopped)
                {
                    Log.Info("机器不是停止状态，无法刷新机器额度");
                    return;
                }
                List<KeycodeInfo> keycodeList = new List<KeycodeInfo>();
                if (!string.IsNullOrEmpty(MachineInfo.MachineConfigEntity.C_RefreshMoneyKeys))
                {
                    foreach (string key in MachineInfo.MachineConfigEntity.C_RefreshMoneyKeys.Split(','))
                    {
                        keycodeList.Add(new KeycodeInfo(key, MachineInfo.MachineConfigEntity.C_SendCommandInterval));
                    }
                }
                VirtualKeyboard.Input(keycodeList);

                ReturnTopGui();
            }
            catch (Exception ex)
            {
                Log.Error(string.Format("【{0}】【{1}】异常：{2}\r\n{3}", "刷新机器额度", MachineInfo.M_Number, ex.Message, ex.StackTrace));
                //return (int)(WcfCodeEnum.RefreshMahineMoneyException);
            }
        }

        /// <summary>
        /// 刷新广播信息
        /// </summary>
        /// <returns></returns>
        public override void RefreshMahineBroadcast()
        {
            try
            {
                MachineStatusEnum status = (MachineStatusEnum)MachineInfo.M_Status;
                if (status != MachineStatusEnum.Stopped)
                {
                    Log.Info("机器不是停止状态，无法刷新广播信息");
                    return;
                }
                List<KeycodeInfo> keycodeList = new List<KeycodeInfo>();
                if (!string.IsNullOrEmpty(MachineInfo.MachineConfigEntity.C_RefreshBroadcastKeys))
                {
                    foreach (string key in MachineInfo.MachineConfigEntity.C_RefreshBroadcastKeys.Split(','))
                    {
                        keycodeList.Add(new KeycodeInfo(key, MachineInfo.MachineConfigEntity.C_SendCommandInterval));
                    }
                }
                VirtualKeyboard.Input(keycodeList);
                ReturnTopGui();
            }
            catch (Exception ex)
            {
                Log.Error(string.Format("【{0}】【{1}】异常：{2}\r\n{3}", "刷新广播信息", MachineInfo.M_Number, ex.Message, ex.StackTrace));
                //return (int)(WcfCodeEnum.RefreshMahineBroadcastException);
            }
        }

        /// <summary>
        /// 切换当前玩法
        /// </summary>
        /// <param name="ticketEntity"></param>
        public override void SetCurrentLotPlayMode(L_LotTicketEntity ticketEntity)
        {
            int totalwaittime = 0;
            int keycount = 0;
            bool ischangceplaytype = false;
            if (MacCurrentMode == null)
            {
                ischangceplaytype = true;
            }
            else
            {
                if (MacCurrentMode.C_MacModeId != ticketEntity.MacModeId)
                {
                    ischangceplaytype = true;
                }
            }

            string oldexpect = MacCurrentExpect;
            int oldlotid = MacCurrentMode == null ? -1 : MacCurrentMode.C_MacLotId;
            M_MachineModeConfigEntity machineModeConfig = MachineInfo.MachineModeConfigs[ticketEntity.MacModeId];
            List<KeycodeInfo> keycodeList = new List<KeycodeInfo>();
            #region 切换彩种玩法
            if (MacCurrentMode == null)
            {
                //切换彩种及玩法
                if (!string.IsNullOrEmpty(machineModeConfig.C_MacLotKeys))
                {
                    foreach (string keyname in machineModeConfig.C_MacLotKeys.Split(','))
                    {
                        keycodeList.Add(new KeycodeInfo(keyname, machineModeConfig.C_MacLotKeysInterval));
                    }
                }

                if (!string.IsNullOrEmpty(machineModeConfig.C_MacPlayKeys))
                {
                    foreach (string keyname in machineModeConfig.C_MacPlayKeys.Split(','))
                    {
                        keycodeList.Add(new KeycodeInfo(keyname, machineModeConfig.C_MacPlayKeysInterval));
                    }
                    keycount += 10;
                }
            }
            else
            {
                if (MacCurrentMode.C_MacLotId != machineModeConfig.C_MacLotId)
                {
                    //切换彩种及玩法
                    if (!string.IsNullOrEmpty(machineModeConfig.C_MacLotKeys))
                    {
                        foreach (string keyname in machineModeConfig.C_MacLotKeys.Split(','))
                        {
                            keycodeList.Add(new KeycodeInfo(keyname, machineModeConfig.C_MacLotKeysInterval));
                        }
                        keycount += 10;
                    }


                    if (!string.IsNullOrEmpty(machineModeConfig.C_MacPlayKeys))
                    {
                        foreach (string keyname in machineModeConfig.C_MacPlayKeys.Split(','))
                        {
                            keycodeList.Add(new KeycodeInfo(keyname, machineModeConfig.C_MacPlayKeysInterval));
                        }
                        keycount += 10;
                    }
                    oldexpect = "";

                }
                else
                {
                    if (MacCurrentMode.C_MacPlayId != machineModeConfig.C_MacPlayId)
                    {
                        //切换玩法
                        if (!string.IsNullOrEmpty(machineModeConfig.C_MacPlayKeys))
                        {
                            foreach (string keyname in machineModeConfig.C_MacPlayKeys.Split(','))
                            {
                                keycodeList.Add(new KeycodeInfo(keyname, machineModeConfig.C_MacPlayKeysInterval));
                            }
                            keycount += 10;
                        }
                        oldexpect = "";
                    }
                }
            }
            #endregion
            if (keycodeList.Count > 0)
            {
                keycount += keycodeList.Count;
                Log.Info("切换彩种玩法");
                VirtualKeyboard.Input(keycodeList);
                foreach (KeycodeInfo keycodeInfo in keycodeList)
                {
                    totalwaittime += keycodeInfo.SendInterval;
                }
                keycodeList.Clear();
            }


            #region 切换期号
            if (machineModeConfig.C_MacLotId == 601 || machineModeConfig.C_MacLotId == 611 || machineModeConfig.C_MacLotId == 602 || machineModeConfig.C_MacLotId == 603)
            {

                if (oldlotid == machineModeConfig.C_MacLotId)
                {
                    //彩种与上一次相同
                    if (oldexpect != ticketEntity.L_Expect)
                    {
                        //期号与上一次不同

                        if (ticketEntity.L_CurrentExpect == ticketEntity.L_Expect)
                        {
                            //当前期
                            if (!string.IsNullOrEmpty(machineModeConfig.C_CurrentExpectKeys))
                            {
                                foreach (string keyname in machineModeConfig.C_CurrentExpectKeys.Split(','))
                                {
                                    keycodeList.Add(new KeycodeInfo(keyname, machineModeConfig.C_CurrentExpectKeysInterval));
                                }
                            }
                        }
                        else
                        {
                            //下一期
                            if (!string.IsNullOrEmpty(machineModeConfig.C_NextExpectKeys))
                            {
                                foreach (string keyname in machineModeConfig.C_NextExpectKeys.Split(','))
                                {
                                    keycodeList.Add(new KeycodeInfo(keyname, machineModeConfig.C_NextExpectKeysInterval));
                                }
                            }
                        }
                    }
                }
                else
                {
                    //彩种与上一次不相同 进入彩种即是当前期
                    if (ticketEntity.L_CurrentExpect != ticketEntity.L_Expect)
                    {
                        if (!string.IsNullOrEmpty(machineModeConfig.C_NextExpectKeys))
                        {
                            foreach (string keyname in machineModeConfig.C_NextExpectKeys.Split(','))
                            {
                                keycodeList.Add(new KeycodeInfo(keyname, machineModeConfig.C_NextExpectKeysInterval));
                            }
                        }
                    }
                }
            }
            #endregion
            if (keycodeList.Count > 0)
            {
                keycount += keycodeList.Count;
                Log.Info("切换期号");
                VirtualKeyboard.Input(keycodeList);
                foreach (KeycodeInfo keycodeInfo in keycodeList)
                {
                    totalwaittime += keycodeInfo.SendInterval;
                }
                keycodeList.Clear();
            }

            #region 切换投注模式
            if (MacCurrentMode == null)
            {
                //进入投注模式
                if (!machineModeConfig.C_IsEveryInit && !string.IsNullOrEmpty(machineModeConfig.C_MacModeKeys))
                {
                    foreach (string keyname in machineModeConfig.C_MacModeKeys.Split(','))
                    {
                        keycodeList.Add(new KeycodeInfo(keyname, machineModeConfig.C_MacModeKeysInterval));
                    }
                }
            }
            else
            {
                if (MacCurrentMode.C_MacModeId != machineModeConfig.C_MacModeId)
                {

                    if (MacCurrentMode.C_MacPlayId == machineModeConfig.C_MacPlayId)
                    {
                        //返回初始投注模式
                        if (!string.IsNullOrEmpty(MacCurrentMode.C_ToInitModeKeys))
                        {
                            foreach (string keyname in MacCurrentMode.C_ToInitModeKeys.Split(','))
                            {
                                keycodeList.Add(new KeycodeInfo(keyname, MacCurrentMode.C_ToInitModeKeysInterval));
                            }
                        }
                    }


                    //进入投注模式
                    if (!machineModeConfig.C_IsEveryInit && !string.IsNullOrEmpty(machineModeConfig.C_MacModeKeys))
                    {
                        foreach (string keyname in machineModeConfig.C_MacModeKeys.Split(','))
                        {
                            keycodeList.Add(new KeycodeInfo(keyname, machineModeConfig.C_MacModeKeysInterval));
                        }
                    }
                }
            }
            #endregion
            if (keycodeList.Count > 0)
            {
                keycount += keycodeList.Count;
                Log.Info("切换投注模式");
                VirtualKeyboard.Input(keycodeList);
                foreach (KeycodeInfo keycodeInfo in keycodeList)
                {
                    totalwaittime += keycodeInfo.SendInterval;
                }
                keycodeList.Clear();
            }
            /*if (keycount > 0)
            {
                int waittime = MachineInfo.MachineConfigEntity.C_ChangePlayInterval + keycount * 130;
                Log.Info(string.Concat("切换彩种玩法投注模式期号等待", waittime));
                keycodeList.Add(new KeycodeInfo("wait" + waittime, waittime));
                VirtualKeyboard.Input(keycodeList);
                foreach (KeycodeInfo keycodeInfo in keycodeList)
                {
                    totalwaittime += keycodeInfo.SendInterval;
                }
                keycodeList.Clear();
            }*/

            if (!ischangceplaytype)
            {
                int waittime = 200;
                if (FuShiPlayList.Contains(ticketEntity.L_PlayId))
                {
                    waittime = MachineInfo.MachineConfigEntity.C_ChangePlayInterval;
                }
                keycodeList.Add(new KeycodeInfo("wait" + waittime, waittime));
                VirtualKeyboard.Input(keycodeList);
                foreach (KeycodeInfo keycodeInfo in keycodeList)
                {
                    totalwaittime += keycodeInfo.SendInterval;
                }
                keycodeList.Clear();
                //Wait(waittime);
            }
            if (totalwaittime > 0)
            {
                Wait(totalwaittime);
            }

            //设置机器当前界面的期号及投注模式
            MacCurrentExpect = ticketEntity.L_Expect;
            MacCurrentMode = (M_MachineModeConfigEntity)machineModeConfig.Clone();
        }

        /// <summary>
        /// 返回顶级界面
        /// </summary>
        public override void ReturnTopGui()
        {
            MacCurrentMode = null;
            MacCurrentExpect = null;

            List<KeycodeInfo> keycodeList = new List<KeycodeInfo>();
            keycodeList.Add(new KeycodeInfo("esc", 300));
            keycodeList.Add(new KeycodeInfo("esc", 300));
            keycodeList.Add(new KeycodeInfo("esc", 300));
            Log.Info("彩票机进入顶级界面");
            VirtualKeyboard.Input(keycodeList);
        }

        /// <summary>
        /// 进入销售主界面（竟彩）
        /// </summary>
        public override void EnterSaleGui()
        {
            ReturnTopGui();

            List<KeycodeInfo> keycodeList = new List<KeycodeInfo>();
            keycodeList.Add(new KeycodeInfo("5", 300));
            keycodeList.Add(new KeycodeInfo("1", 30));
            Log.Info("彩票机进入竟彩销售主界面");
            VirtualKeyboard.Input(keycodeList);
        }

        /// <summary>
        /// 彩票机充值
        /// </summary>
        public override void Recharge(int money)
        {
            List<KeycodeInfo> keycodeList = new List<KeycodeInfo>();

            ReturnTopGui();
            Wait2(2000);

            keycodeList.Add(new KeycodeInfo("/", 500));  //调起弹窗
            keycodeList.Add(new KeycodeInfo("f1", 300));  //默认支付宝
            string moneyStr = money.ToString();
            for (int i = 0; i < moneyStr.Length; i++)
            {
                keycodeList.Add(new KeycodeInfo(moneyStr.Substring(i, 1), 300));  //输入金额
            }
            keycodeList.Add(new KeycodeInfo("enter", 300));   //调出二维码
            int totaltime = 0;
            foreach (KeycodeInfo keycodeInfo in keycodeList)
            {
                totaltime += keycodeInfo.SendInterval;
            }
            VirtualKeyboard.Input(keycodeList);
            Wait2(totaltime);
            Log.Info("已调出充值二维码，开始取充值成功弹窗的指令");

            //开始取充值成功弹窗的指令
            DateTime startTime = DateTime.Now;
            while (DateTime.Now.Subtract(startTime).TotalSeconds < 60)  //防止在60秒倒数快结束时支付成功，有可能70多秒才会检测到弹窗，给点掉弹窗留足余量
            {
                try
                {
                    //获取指令
                    A10009GetCommand pack = new A10009GetCommand();
                    pack.AgentId = MachineInfo.M_Number;
                    pack.Salt = MachineInfo.M_Salt;
                    A10009GetCommandRet packRet = PackManager.Instance.Send(pack) as A10009GetCommandRet;
                    if (packRet.Code > 0)
                    {
                        Log.Info("获取到指令:" + packRet.Command);
                        if (packRet.Command == "enter_paysuc")    //充值成功弹窗指令
                        {
                            keycodeList.Clear();
                            keycodeList.Add(new KeycodeInfo("enter", 300));
                            VirtualKeyboard.Input(keycodeList);

                            break;
                        }
                    }
                }
                catch (Exception ex)
                {
                    Log.Warn("获取成功弹窗指令失败！" + ex.ToString());
                }
                finally
                {
                    Wait2(3 * 1000);
                }
            }

            ReturnTopGui();

        }

        #endregion
    }
}
