Ejemplo n.º 1
0
 private void Page_Unloaded(object sender, RoutedEventArgs e)
 {
     //TPU_CLOSE();
     CZLHTpuHandler.Close();
     rfidReader.Dispose();
     rfidReader = null;
     //this.parent.RestartSecond();
     //this.parent.SelfHelpInfo.TicketNumberList = new List<string>();
 }
Ejemplo n.º 2
0
        ////*******************出票部分*****************
        //[DllImport("hhjttpu.dll", CharSet = CharSet.Unicode, SetLastError = true)]
        //private static extern uint TPU_OPEN(byte[] lpbytSerialnumber);
        //[DllImport("hhjttpu.dll", CharSet = CharSet.Unicode, SetLastError = true)]
        //private static extern uint TPU_CLOSE();
        //[DllImport("hhjttpu.dll", CharSet = CharSet.Unicode, SetLastError = true)]
        //private static extern uint TPU_RST(byte Mod);
        //[DllImport("hhjttpu.dll", CharSet = CharSet.Unicode, SetLastError = true)]
        //private static extern uint TPU_GET_ST(byte[] recbuf);
        //[DllImport("hhjttpu.dll", CharSet = CharSet.Unicode, SetLastError = true)]
        //private static extern uint TPU_SEND_TK(byte BoxId);
        //[DllImport("hhjttpu.dll", CharSet = CharSet.Unicode, SetLastError = true)]
        //private static extern uint TPU_OUT(byte OutWay);
        //[DllImport("hhjttpu.dll", CharSet = CharSet.Unicode, SetLastError = true)]
        //private static extern uint TPU_GET_VERSION(byte[] recbuf);
        //[DllImport("hhjttpu.dll", CharSet = CharSet.Unicode, SetLastError = true)]
        //private static extern uint TPU_GET_BOXID(byte BoxId, byte[] recbuf);
        //[DllImport("hhjttpu.dll", CharSet = CharSet.Unicode, SetLastError = true)]
        //private static extern uint TPU_GET_TKNUM(byte BoxId, byte[] recbuf);
        //[DllImport("hhjttpu.dll", CharSet = CharSet.Unicode, SetLastError = true)]
        //private static extern uint TPU_SET_TKNUM(byte BoxId, short num);
        //[DllImport("hhjttpu.dll", CharSet = CharSet.Unicode, SetLastError = true)]
        //private static extern uint TPU_TEST(byte TestMod);
        ////*******************出票部分*****************


        public GPPage6(MainWindow parentWindow)
        {
            this.parent = parentWindow;
            this.InitializeComponent();
            base.Background = new ImageBrush
            {
                ImageSource = new BitmapImage(new Uri(AppDomain.CurrentDomain.BaseDirectory + "\\pic\\bg1.png")),
                Stretch     = Stretch.Fill
            };
            //this.api = new OldSenderCardControl(ConfigHelper.GetConfigValue("comport", "senderPort"), int.Parse(ConfigHelper.GetConfigValue("comport", "senderBaudRate")), ConfigHelper.GetConfigValue("comport", "CardPort"), int.Parse(ConfigHelper.GetConfigValue("comport", "CardBaudRate")));
            //this.api.ReadCardDataEvent += new OldSenderCardControl.ReadDataHanlder(this.Api_ReadCardDataEvent);
            //this.api.RunErrorEvent += new OldSenderCardControl.RunErrorHanlder(this.Api_RunErrorEvent);
            //this.api.ReceiveControlEvent += new OldSenderCardControl.ReceiveControlHanlder(this.Api_ReceiveControlEvent);
            this.counttimer          = new DispatcherTimer();
            this.counttimer.Interval = new TimeSpan(0, 0, 0, 1, 0);
            this.counttimer.Tick    += new EventHandler(this.timer_Tick);
            //****************打开串口******************************
            string strCOM = ConfigurationManager.AppSettings["COM"].ToString();//出票机串口号 //ConfigHelper.GetConfigValue("comport", "senderPort").ToString();

            try
            {
                //TPU_CLOSE();
                Thread.Sleep(200);
                num = CZLHTpuHandler.Open(strCOM.Trim(), 1500);//打开串口
                if (num != 0)
                {
                    _log.Error("出票机控制板连接失败,状态码:" + num.ToString());
                }
                //if (this.parent.mSelfHelpClass.BoxNumber == "1")//表示A票箱
                //{
                //    curBoxNumber = 0;
                //}
                //else if (this.parent.mSelfHelpClass.BoxNumber == "2")//表示B票箱
                //{
                //    curBoxNumber = 1;
                //}
            }
            catch (Exception ex)
            {
                MessageBox.Show("串口打开失败!不能进行出票操作.");
                _log.Error(typeof(GPPage6), ex);
            }
            //****************打开串口******************************
        }
Ejemplo n.º 3
0
        //***************读卡函数************
//        public void DoWork()
//        {
//            B_CallBackEventArg arg = new B_CallBackEventArg();
//            arg.message = "";
//            while (!_shoudStop)
//            {

//                #region
//                try
//                {
//                    rfidReader.WaitForTicketPresent(-1);

//                    //读取发行信息
//                    TicketPublishInfo tpInfo = rfidReader.readTicketPublishInfo();
//                    arg.TicketNumber = tpInfo.ID.ToString();//票号
//                    //读取销售信息
//                    TicketSaleInfo? tsInfo = rfidReader.readTicketSaleInfo();
//                    if (!tsInfo.HasValue)//未做过销售的
//                    {
//                        #region //验证出票与购票的票种是否相同
//                        if (tpInfo.TicketClass.ToString() == this.parent.mSelfHelpClass.TicketTypeID)
//                        {
//                            //获到票种实体
//                            mticketType = D_TicketType.GetTicketTypeInfo(tpInfo.TicketClass.ToString());

//                            #region//首先判断票种是否存在
//                            if (mticketType.TICKET_TYPE_ID != null)//当前票票种存在的
//                            {
//                                Yu_Price = T_SellTicketRecord.Get_sl_period_Price(tpInfo.TicketClass.ToString());//获取预售期票价
//                                #region//是否团体票
//                                if (mticketType.TEAM_FLAG == "Y")//团体票
//                                {
//                                    BeginDate = DateTime.Now;
//                                    EndDate = DateTime.Now.AddMinutes(M_Configuration.Teamtickettime);//从参数表中取出结束时间//Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd 16:00:00"));
//                                    arg.message = "此门票为团体票,不能在此销售!";
//                                    //  reportChange(-1, arg, null);
//                                    wkThread_progressReport(-1, arg, null);
//                                    rfidReader.LongBeep();
//                                }
//                                else
//                                {
//                                    if (mticketType.DAY_VALIDATE_FLAG == "Y")//当日有效
//                                    {
//                                        BeginDate = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd 00:00:00"));
//                                        EndDate = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd 23:59:59"));
//                                    }
//                                    else //非当日有效
//                                    {
//                                        BeginDate = DateTime.Now;
//                                        EndDate = DateTime.Now.AddYears(2);
//                                    }
//                                }
//                                #endregion
//                                #region//  循环写票
//                                if (this.cardCount > 0)//未出完票的
//                                {
//                                    //************************写入售票内容*****************
//                                    #region//写票
//                                    if (rfidReader.writeTicketSaleInfo(BeginDate, EndDate, 1))
//                                    {
//                                        if (this.parent.mSelfHelpClass.OperType == "0")//购票时生成销售明细单号
//                                        {
//                                            XiaoMX = T_SellTicketRecord.CreateTableUID(M_Configuration.CLIENTID, T_SellTicketRecord.LocalTicketMX_Prefix_ZG, this.cardCount);
//                                        }
//                                        //保存数据
//                                        #region//保存
//                                        if (T_SellTicketRecord.Insert_SL_ORDER_DETAIL(mticketType, tpInfo.ID.ToString(), Convert.ToInt32(this.parent.mSelfHelpClass.OperType), this.parent.mSelfHelpClass, XiaoMX,this.cardCount))
//                                        {
//                                            rfidReader.Beep();
//                                            try
//                                            {
//                                                if (this.api.OutputCard())//出票
//                                                {
//                                                    this.cardCount--;//读取成功且出票成功再计数
//                                                }
//                                                else//出票不成功
//                                                {
//                                                    isError = true;
//                                                    arg.message = "未成功出票!";
//                                                    wkThread_progressReport(-1, arg, null);
//                                                }
//                                            }
//                                            catch (Exception ex)
//                                            {
//                                                _log.Error(typeof(GPPage6), ex);
//                                            }
//                                        }
//                                        else
//                                        {
//                                            arg.message = "保存票据信息失败!";
//                                            wkThread_progressReport(-1, arg, null);
//                                        }
//#endregion

//                                    }
//                                    else//写票失败
//                                    {
//                                        arg.message = "写入票据信息失败!";
//                                        wkThread_progressReport(-1, arg, null);
//                                    }
//#endregion
//                                }
//                                else
//                                {
//                                    rfidReader.Beep();
//                                    arg.message = "已完成售票,请取票!";
//                                    wkThread_progressReport(-1, arg, null);
//                                }
//                                #endregion

//                            }
//                            else//该票的票种不存在
//                            {
//                                arg.message = "系统中不存在当前票种!";
//                                //  reportChange(-1, arg, null);
//                                wkThread_progressReport(-1, arg, null);
//                                rfidReader.LongBeep();
//                            }
//                            #endregion
//                        }
//                        else//购票与出票 票种不符
//                        {
//                            arg.message = "当前门票同所购门票的票种不符!";
//                            // reportChange(-1, arg, null);
//                            wkThread_progressReport(-1, arg, null);
//                            rfidReader.LongBeep();
//                        }
//                        #endregion
//                    }
//                    else//已做过销售的
//                    {
//                        arg.message = "当前门票已做过销售处理!";
//                        // reportChange(-1, arg, null);
//                        wkThread_progressReport(-1, arg, null);
//                        rfidReader.LongBeep();
//                    }
//                }
//                catch (Exception ex)
//                {
//                    if (_shoudStop)
//                        return;
//                    arg.message = ex.Message;
//                    //  reportChange(-1, arg, ex);
//                    wkThread_progressReport(-1, arg, ex);
//                    _log.Error(typeof(GPPage6), ex);
//                }
//                finally
//                {
//                    rfidReader.WaitForTicketRemoval(-1);
//                }
//                #endregion


//            }
//        }
        //void wkThread_progressReport(int pProgressPercentage, object UserState, Exception ex)
        //{
        //    arg = (B_CallBackEventArg)UserState;
        //    //this.Invoke(new ShowinfoDelegate(ShowInfo));
        //    if (pProgressPercentage >= 0)
        //    {
        //      //  str_ChangTicket = arg.TicketNumber;
        //    }
        //    else
        //    {
        //      //  MessageBox.Show("提示信息:"+arg.message, T_SellTicketRecord.str_Apption,MessageBoxButton.OK,MessageBoxImage.Information);
        //    }
        //}
        //***************读卡函数************



        //*********************刮票、写票、出票操作函数****************
        private void OutPutTicket()
        {
            //刮票 写票 出票部分
            #region
            bool isok = false;
            bool isup = false;//上传
            try
            {
                while (this.cardCount > 0)                          //未出完票的
                {
                    if (this.parent.mSelfHelpClass.OperType == "1") //取票还是购票 0表示购票 1表示取票 自助售票类
                    {
                        displayErrorMessage("暂不支持自助取票!", "error");
                        break;
                        //取票
                        #region
                        //*****************实际取票时 需要判定的情况比较多
                        //if (M_Configuration.TicketTypeID_1 != M_Configuration.TicketTypeID_2)//不同票种
                        //{
                        //不同票种出票
                        //#region
                        //    if (M_Configuration.TicketTypeID_1 == this.parent.mSelfHelpClass.listorderdetail[this.cardCount - 1].TicketTypeId)
                        //    {
                        //        curBoxNumber = 0;//A票箱号
                        //        this.parent.mSelfHelpClass.BoxNumber = "A";
                        //        _log.Info("出A票箱!");
                        //    }
                        //    else if (M_Configuration.TicketTypeID_2 == this.parent.mSelfHelpClass.listorderdetail[this.cardCount - 1].TicketTypeId)
                        //    {
                        //        curBoxNumber = 1;//B票箱号
                        //        this.parent.mSelfHelpClass.BoxNumber = "B";
                        //        _log.Info("出B票箱!");
                        //    }
                        //    else
                        //    {
                        //        _log.Error("票箱内不含当前票种!");
                        //    }
                        //    #endregion
                        //}
                        //else if (M_Configuration.TicketTypeID_1 == M_Configuration.TicketTypeID_2)//同一票种的
                        //{
                        //    if (T_SellTicketRecord.Judge_TicketAlarmCount("A", 1))//A箱不够出B票箱
                        //    {
                        //        curBoxNumber = 1;//B票箱号
                        //        this.parent.mSelfHelpClass.BoxNumber = "B";
                        //        _log.Info("出B票箱!");
                        //    }
                        //    else if (T_SellTicketRecord.Judge_TicketAlarmCount("B", 1))//B箱不够出A票箱
                        //    {
                        //        curBoxNumber = 0;//A票箱号
                        //        this.parent.mSelfHelpClass.BoxNumber = "A";
                        //        _log.Info("出A票箱!");
                        //    }
                        //}
                        #endregion
                    }
                    else if (this.parent.mSelfHelpClass.OperType == "0")//取票还是购票 0表示购票 1表示取票 自助售票类
                    {
                        DataTable dt = T_SellTicketRecord.Get_BoxTicketInfo();
                        for (int i = 0; i < dt.Rows.Count; i++)
                        {
                            if (dt.Rows[i]["ticket_type_id"].ToString() == this.parent.mSelfHelpClass.TicketTypeID &&
                                (int)dt.Rows[i]["surplusCount"] >= this.cardCount + (int)dt.Rows[i]["alarmCount"])
                            {
                                if (dt.Rows[i]["boxNumber"].ToString() == "A")
                                {
                                    this.parent.mSelfHelpClass.BoxNumber = "A";
                                    curBoxNumber = 0;//A票箱号
                                    break;
                                }
                                else
                                {
                                    this.parent.mSelfHelpClass.BoxNumber = "B";
                                    curBoxNumber = 1;//B票箱号
                                    break;
                                }
                            }
                        }
                    }
                    Thread.Sleep(100);
                    //1.刮票
                    //num = TPU_SEND_TK(Convert.ToByte(curBoxNumber));//0表示A票箱 1表示B票箱
                    num = CZLHTpuHandler.SendTicket((byte)curBoxNumber);
                    //  num =0;//测试代码
                    _log.Info("刮票结果:" + num.ToString());
                    Thread.Sleep(200);
                    if (num == 0)
                    {
                        _log.Info("刮票成功!");
                        isok = T_SellTicketRecord.Update_SL_TicketCount(this.parent.mSelfHelpClass.BoxNumber);
                        if (isok)
                        {
                            _log.Info("更新票箱余票成功!");
                        }
                        else
                        {
                            _log.Error("更新票箱余票失败!");
                        }
                        //2.写票
                        #region
                        if (WriteTicket() == true)
                        //if(1==1)//测试代码
                        {
                            Thread.Sleep(100);
                            _log.Info("写票成功!");
                            //********************写票成功后是各种更新及上传********

                            #region//各种更新上传
                            //******************出一张票就上传一次
                            for (int i = 0; i < 3; i++)
                            {
                                try
                                {
                                    isup = B_SellTicketUpData.SellTicketDataUP_MX(this.parent.Client, this.parent.mSelfHelpClass.OrderID, this.parent.mSelfHelpClass, CurTicketID); // CurTicketID
                                    if (isup == true)                                                                                                                               //上传成功
                                    {
                                        break;
                                    }
                                    else
                                    {
                                        _log.Warn("上传出票数据失败,开始重试。上传计数:" + (i + 1).ToString());
                                    }
                                }
                                catch (Exception ex)
                                {
                                    _log.Error("上传出票数据失败,开始重试。上传计数:" + (i + 1).ToString(), ex);
                                }
                            }
                            if (isup)
                            {
                                _log.Info("出票上传成功!");
                                //******开始出票**
                                //num = TPU_OUT(0);//出票   TPU_OUT返回1为出票成功
                                num = CZLHTpuHandler.OutTicket(0);
                                //   num = 1;//测试代码
                                if (num != 0)
                                {
                                    //num = TPU_OUT(0);//再出一次
                                    num = CZLHTpuHandler.OutTicket(0);
                                }
                                if (num == 0)//出票成功
                                {
                                    _log.Info("出票成功!");
                                    this.cardCount--;
                                }
                                else//出票失败
                                {
                                    #region//出票失败的
                                    _log.Error("出票操作失败!");
                                    M_Configuration.RunState = Convert.ToInt32(DeviceStatus.OutCardFault); //出票机故障
                                    this.cardCount           = -99999;                                     //返回首页
                                    displayErrorMessage("出票卡票!请联系工作人员取走卡票,并到人工售票窗口补取余票。", "error");
                                    #endregion
                                }
                                //*******开始出票**
                            }
                            else
                            {
                                //*******************************数据上传失败就回收票*********
                                try
                                {
                                    rfidReader.clearTicketSaleInfo();
                                }
                                catch { }
                                //num = TPU_OUT(1);//出不了就回收   废票回收无法判断是否执行成功
                                num = CZLHTpuHandler.OutTicket(1);
                                if (num == 0)//回收成功
                                {
                                    _log.Info("出票上传失败,门票回收成功!");
                                }
                                else
                                {
                                    _log.Error("出票上传失败,门票回收失败!状态码:" + num.ToString());
                                }

                                //*****更新废票箱
                                isok = T_SellTicketRecord.Update_SL_AbolishCount(false);//更新废票箱票数;
                                if (isok)
                                {
                                    _log.Info("更新废票箱成功!");
                                }
                                else
                                {
                                    _log.Error("更新废票箱失败!");
                                }
                                //*******************************数据上传失败就回收票*********

                                this.cardCount = -99999;
                                this.parent.ticketbox_isErr = 100;
                            }
                            #endregion
                        }
                        else
                        {
                            #region 写票失败的
                            try
                            {
                                rfidReader.clearTicketSaleInfo();
                            }
                            catch { }
                            num = CZLHTpuHandler.OutTicket(1);
                            if (num == 0)//回收成功
                            {
                                _log.Info("写票操作失败,门票回收成功!");
                            }
                            else
                            {
                                _log.Error("写票操作失败,门票回收失败!状态码:" + num.ToString());
                            }

                            //          废票回收无法获取到是否回收成功状态
                            //*****更新废票箱
                            isok = T_SellTicketRecord.Update_SL_AbolishCount(false);//更新废票箱票数;
                            if (isok)
                            {
                                _log.Info("更新废票箱成功!");
                            }
                            else
                            {
                                _log.Error("更新废票箱失败!");
                            }

                            if (this.parent.ticketbox_isErr == 1)//票种放反
                            {
                                this.cardCount = 0;
                            }
                            #endregion
                        }
                        #endregion
                    }
                    else
                    {
                        //_log.Error("刮票操作失败!");
                        //TPU_RST(0);
                        num = CZLHTpuHandler.Reset();
                        if (num == 0)//回收成功
                        {
                            _log.Error("刮票操作失败,控制板重置成功!");
                        }
                        else
                        {
                            _log.Error("刮票操作失败,控制板重置失败!状态码:" + num.ToString());
                        }

                        M_Configuration.RunState = Convert.ToInt32(DeviceStatus.OutCardFault); //出票机故障
                        this.cardCount           = -99999;                                     //返回首页
                        displayErrorMessage("出票失败!请到人工售票窗口取票。", "error");
                    }
                }
                #endregion
                if (this.cardCount == 0)
                {
                    displayErrorMessage("出票完成,请取走门票。", "INFO", true);
                }
            }
            catch (Exception ex)
            {
                _log.Error("出票失败,未知异常。", ex);
                displayErrorMessage("出票失败!请到人工售票窗口取票。", "error");
            }
            finally
            {
                CZLHTpuHandler.Close();
            }
        }