// private string strClassName = ConfigurationManager.AppSettings["RandCode"];
 /// <summary>
 /// 多线程打印
 /// </summary>
 /// <param name="printType"></param>
 /// <param name="data"></param>
 /// <param name="clientNo"></param>
 public void ThreadPrint(PrintStatus printType, PrintData data, string clientNo)
 {
     ThreadPrintType = printType;
     ThreadPrintData = data;
     ThreadClientNo  = clientNo;
     printThread     = new System.Threading.Thread(new System.Threading.ThreadStart(Print));
     printThread.Start();
 }
        /// <summary>
        /// 执行打印操作
        /// </summary>
        /// <param name="_PrintType"></param>
        /// <param name="data"></param>
        public void Print(PrintStatus printType, PrintData data, string clientNo)
        {
            SeatManage.EnumType.Printer printerStatus = PrintStatusHandle();
            TerminalInfoV2 term = SeatManage.Bll.TerminalOperatorService.GetTeminalSetting(clientNo);

            if (printerStatus == SeatManage.EnumType.Printer.NoPaper)
            {
                if (term.PrinterStatus == true)
                {
                    term.PrinterStatus  = false;
                    term.LastPrintTimes = term.PrintedTimes;
                    term.PrintedTimes   = 0;
                    SeatManage.Bll.TerminalOperatorService.UpdateTeminalSetting(term);
                }
                if (PrinterException != null)
                {
                    PrinterException(SeatManage.EnumType.Printer.NoPaper);
                }
                return;
            }
            else if (printerStatus == SeatManage.EnumType.Printer.Normal)
            {
                term.PrinterStatus            = true;
                term.DeviceSetting.IsAnyPaper = true;
            }

            _PrintType = printType;
            printData  = data;
            XmlDocument doc = new XmlDocument();//原模板

            doc.LoadXml(GetPrintTemplate());
            PrintDocument pd = new PrintDocument();                   //打印操作的对象

            pd.DefaultPageSettings.Margins = new Margins(0, 0, 0, 0); //设置边距
            switch (PrintType)
            {
            //根据凭条的类型,在模板前增加【预约】或【等待】字样的节点
            case PrintStatus.General:
                newDoc = doc;
                break;

            case PrintStatus.Book:
                newDoc = InsertXmlNode(PrintStatus.Book, doc);
                break;

            case PrintStatus.Wait:
                newDoc = InsertXmlNode(PrintStatus.Wait, doc);
                break;
            }
            pd.PrintPage += new PrintPageEventHandler(pd_PrintPage);
            pd.Print();
            term.PrintedTimes++;
            SeatManage.Bll.TerminalOperatorService.UpdateTeminalSetting(term);
        }
        /// <summary>
        /// 选座操作
        /// </summary>
        public void ChooseSeat()
        {
            //进出记录相关属性赋值。
            clientobject.EnterOutLogData.EnterOutlog.EnterOutLogNo = SeatManage.SeatManageComm.SeatComm.RndNum();
            clientobject.EnterOutLogData.EnterOutlog.EnterOutState = SeatManage.EnumType.EnterOutLogType.SelectSeat;
            clientobject.EnterOutLogData.EnterOutlog.Flag          = SeatManage.EnumType.Operation.Reader;
            clientobject.EnterOutLogData.EnterOutlog.EnterOutType  = SeatManage.EnumType.LogStatus.Valid;

            ReadingRoomWindow readingRoomWindow = new ReadingRoomWindow();

            readingRoomWindow.ShowDialog();
            if (clientobject.EnterOutLogData.FlowControl == SeatManage.EnumType.ClientOperation.Exit)//阅览室选座操作为退出,结束选座流程
            {
                return;
            }
            switch (readingRoomWindow.viewModel.RoomSelectSeatMethod)
            {
            case SelectSeatMode.AutomaticMode:
                string tempSeatNo = T_SM_Seat.RandomAllotSeat(clientobject.EnterOutLogData.EnterOutlog.ReadingRoomNo);
                SeatManage.EnumType.SeatLockState lockseat = T_SM_Seat.LockSeat(tempSeatNo);
                if (lockseat == SeatLockState.Locked)    //座位锁定失败,则提示
                {
                    clientobject.EnterOutLogData.EnterOutlog.Remark      = string.Format("在终端{0}刷卡,自动选择{1} {2}号座位", clientobject.ClientSetting.ClientNo, clientobject.EnterOutLogData.Student.AtReadingRoom.Name, tempSeatNo.Substring(tempSeatNo.Length - clientobject.EnterOutLogData.Student.AtReadingRoom.Setting.SeatNumAmount));
                    clientobject.EnterOutLogData.EnterOutlog.SeatNo      = tempSeatNo;
                    clientobject.EnterOutLogData.EnterOutlog.TerminalNum = clientobject.ClientSetting.ClientNo;
                    clientobject.EnterOutLogData.EnterOutlog.ShortSeatNo = SeatComm.SeatNoToShortSeatNo(clientobject.EnterOutLogData.Student.AtReadingRoom.Setting.SeatNumAmount, clientobject.EnterOutLogData.EnterOutlog.SeatNo);
                }
                else
                {
                    clientobject.EnterOutLogData.EnterOutlog.SeatNo = "";
                    PopupWindow popWindow = new PopupWindow(TipType.SeatLocking);
                    popWindow.ShowDialog();
                }
                break;

            case SelectSeatMode.ManualMode:
                //座位选择的操作为退出,结束选座流程;操作为选座,跳出循环;否则操作为back,继续执行循环操作
                break;
            }
            if (string.IsNullOrEmpty(clientobject.EnterOutLogData.EnterOutlog.ReadingRoomNo) || string.IsNullOrEmpty(clientobject.EnterOutLogData.EnterOutlog.SeatNo))
            {
                //如果阅览室编号或者座位号为空,则不执行插入操作。
                return;
            }
            int          newLogId = -1;
            HandleResult result   = EnterOutOperate.AddEnterOutLog(clientobject.EnterOutLogData.EnterOutlog, ref newLogId);//插入进出记录

            if (result == HandleResult.Successed)
            {
                T_SM_Seat.UnLockSeat(clientobject.EnterOutLogData.EnterOutlog.SeatNo);//记录插入成功,解锁座位
                if (clientobject.EnterOutLogData.WaitSeatLogModel != null)
                {
                    //等待记录的实体不为空,说明当前读者操作为等待座位。
                    //TODO:添加等待记录
                    clientobject.EnterOutLogData.WaitSeatLogModel.EnterOutLogID = newLogId;
                    T_SM_SeatWaiting.AddWaitSeatLog(clientobject.EnterOutLogData.WaitSeatLogModel);
                    PrintData data = new PrintData();
                    data.CardNo          = clientobject.EnterOutLogData.WaitSeatLogModel.CardNo;
                    data.EnterTime       = ServiceDateTime.Now;
                    data.ReaderName      = clientobject.EnterOutLogData.Student.Name;
                    data.ReadingRoomName = clientobject.EnterOutLogData.Student.AtReadingRoom.Name;
                    data.SeatNo          = SeatComm.SeatNoToShortSeatNo(clientobject.EnterOutLogData.Student.AtReadingRoom.Setting.SeatNumAmount, clientobject.EnterOutLogData.EnterOutlog.SeatNo);
                    data.SecCardNo       = clientobject.EnterOutLogData.EnterOutlog.CardNo;
                    double timelength = NowReadingRoomState.GetSeatHoldTime(clientobject.EnterOutLogData.Student.AtReadingRoom.Setting.SeatHoldTime, data.EnterTime);
                    data.WaitEndDateTime = data.EnterTime.AddMinutes(timelength);
                    printer.ThreadPrint(PrintStatus.Wait, data, clientobject.ClientSetting.ClientNo);

                    PopupWindow popWindow = new PopupWindow(TipType.WaitSeatSuccess);
                    popWindow.ShowDialog();
                }
                else
                {
                    PrintData data = new PrintData();
                    data.CardNo          = clientobject.EnterOutLogData.EnterOutlog.CardNo;
                    data.EnterTime       = ServiceDateTime.Now;
                    data.ReaderName      = clientobject.EnterOutLogData.Student.Name;
                    data.ReadingRoomName = clientobject.EnterOutLogData.Student.AtReadingRoom.Name;
                    data.SeatNo          = SeatComm.SeatNoToShortSeatNo(clientobject.EnterOutLogData.Student.AtReadingRoom.Setting.SeatNumAmount, clientobject.EnterOutLogData.EnterOutlog.SeatNo);
                    if (clientobject.ClientSetting.DeviceSetting.UsingPrintSlip == PrintSlipMode.AutoPrint)
                    {
                        printer.ThreadPrint(PrintStatus.General, data, clientobject.ClientSetting.ClientNo);
                    }
                    if (clientobject.ClientSetting.DeviceSetting.UsingPrintSlip == PrintSlipMode.UserChoose)
                    {
                        PopupWindow printWindow = new PopupWindow(TipType.PrintConfIrm);
                        printWindow.ShowDialog();
                        if (printWindow.viewModel.OperateResule == HandleResult.Successed)
                        {
                            printer.ThreadPrint(PrintStatus.General, data, clientobject.ClientSetting.ClientNo);
                        }
                    }
                    //提示选座成功
                    PopupWindow popWindow = new PopupWindow(TipType.SelectSeatResult);
                    popWindow.ShowDialog();
                }
            }
        }
        /// <summary>
        /// 预约等待
        /// </summary>
        public void BespeakSeatWait()
        {
            DateTime nowDate = ServiceDateTime.Now;

            if (clientobject.EnterOutLogData.Student.BespeakLog.Count > 0)
            {
                BespeakLogInfo bespeaklog = clientobject.EnterOutLogData.Student.BespeakLog[0];
                //if (!SelectSeatProven.CheckReadingRoomInThisClient(bespeaklog.ReadingRoomNo, clientobject.ClientSetting.DeviceSetting))
                //{  //验证房间号是否属于本触摸屏所管理的阅览室
                //    Tip_Framework uc = new Tip_Framework(TipType.BeapeatRoomNotExists, 9);
                //}
                ReadingRoomSetting set     = clientobject.EnterOutLogData.Student.AtReadingRoom.Setting;
                DateTime           dtBegin = bespeaklog.BsepeakTime.AddMinutes(-double.Parse(set.SeatBespeak.ConfirmTime.BeginTime));
                DateTime           dtEnd   = bespeaklog.BsepeakTime.AddMinutes(double.Parse(set.SeatBespeak.ConfirmTime.EndTime));
                if (DateTimeOperate.DateAccord(dtBegin, dtEnd, nowDate) || (set.SeatBespeak.NowDayBespeak && bespeaklog.SubmitTime == bespeaklog.BsepeakTime))
                {
                    //TODO:预约时间在开始时间和结束时间之间,执行预约确认操作
                    //TODO:预约确认时,判断当前座位上是否有人。
                    EnterOutLogInfo seatUsedInfo = T_SM_EnterOutLog.GetUsingEnterOutLogBySeatNo(bespeaklog.SeatNo);

                    if (seatUsedInfo != null && seatUsedInfo.EnterOutState != EnterOutLogType.Leave)
                    { //条件满足,说明座位正在使用。
                        seatUsedInfo.EnterOutState = EnterOutLogType.Leave;
                        seatUsedInfo.EnterOutType  = LogStatus.Valid;
                        seatUsedInfo.TerminalNum   = clientobject.ClientSetting.ClientNo;
                        seatUsedInfo.Remark        = string.Format("预约该座位的读者在终端{0}刷卡确认入座,设置在座读者离开", clientobject.ClientSetting.ClientNo);
                        seatUsedInfo.Flag          = Operation.OtherReader;
                        int newId = -1;
                        if (EnterOutOperate.AddEnterOutLog(seatUsedInfo, ref newId) == HandleResult.Successed)
                        {
                            List <WaitSeatLogInfo> waitInfoList = SeatManage.Bll.T_SM_SeatWaiting.GetWaitSeatList(null, seatUsedInfo.EnterOutLogID, null, null, null);
                            if (waitInfoList.Count > 0)
                            {
                                this.clientobject.EnterOutLogData.WaitSeatLogModel              = waitInfoList[0];
                                this.clientobject.EnterOutLogData.WaitSeatLogModel.OperateType  = Operation.Reader;
                                this.clientobject.EnterOutLogData.WaitSeatLogModel.WaitingState = EnterOutLogType.WaitingCancel;
                                this.clientobject.EnterOutLogData.WaitSeatLogModel.NowState     = LogStatus.Valid;
                                if (!T_SM_SeatWaiting.UpdateWaitLog(this.clientobject.EnterOutLogData.WaitSeatLogModel))
                                {
                                    PopupWindow errorWindow = new PopupWindow(TipType.Exception);
                                    errorWindow.ShowDialog();
                                    return;
                                }
                            }
                        }
                        else
                        {
                            PopupWindow errorWindow = new PopupWindow(TipType.Exception);
                            errorWindow.ShowDialog();
                            return;
                        }
                    }
                    EnterOutLogInfo newEnterOutLog = new EnterOutLogInfo();//构造
                    newEnterOutLog.CardNo                    = bespeaklog.CardNo;
                    newEnterOutLog.EnterOutLogNo             = SeatComm.RndNum();
                    newEnterOutLog.EnterOutState             = EnterOutLogType.BookingConfirmation;
                    newEnterOutLog.EnterOutType              = LogStatus.Valid;
                    newEnterOutLog.Flag                      = Operation.Reader;
                    newEnterOutLog.ReadingRoomNo             = bespeaklog.ReadingRoomNo;
                    newEnterOutLog.ReadingRoomName           = bespeaklog.ReadingRoomName;
                    newEnterOutLog.ShortSeatNo               = bespeaklog.ShortSeatNum;
                    newEnterOutLog.SeatNo                    = bespeaklog.SeatNo;
                    newEnterOutLog.TerminalNum               = clientobject.ClientSetting.ClientNo;
                    newEnterOutLog.Remark                    = string.Format("在终端{0}刷卡,入座预约的{1} {2}号座位", clientobject.ClientSetting.ClientNo, bespeaklog.ReadingRoomName, bespeaklog.ShortSeatNum);
                    clientobject.EnterOutLogData.EnterOutlog = newEnterOutLog;
                    int          logid  = -1;
                    HandleResult result = EnterOutOperate.AddEnterOutLog(newEnterOutLog, ref logid); //添加入座记录
                    if (result == HandleResult.Successed)
                    {
                        bespeaklog.BsepeakState = BookingStatus.Confinmed;
                        bespeaklog.CancelPerson = Operation.Reader;
                        bespeaklog.CancelTime   = nowDate;
                        bespeaklog.Remark       = string.Format("在终端{0}刷卡,入座预约的{1} {2}号座位", clientobject.ClientSetting.ClientNo, bespeaklog.ReadingRoomName, bespeaklog.ShortSeatNum);
                        T_SM_SeatBespeak.UpdateBespeakList(bespeaklog);
                        PrintData data = new PrintData();
                        data.CardNo          = bespeaklog.CardNo;;
                        data.EnterTime       = nowDate;
                        data.ReaderName      = clientobject.EnterOutLogData.Student.Name;
                        data.ReadingRoomName = clientobject.EnterOutLogData.Student.AtReadingRoom.Name;
                        data.SeatNo          = SeatComm.SeatNoToShortSeatNo(set.SeatNumAmount, bespeaklog.SeatNo);
                        if (clientobject.ClientSetting.DeviceSetting.UsingPrintSlip == PrintSlipMode.AutoPrint)
                        {
                            printer.ThreadPrint(PrintStatus.General, data, clientobject.ClientSetting.ClientNo);
                        }
                        if (clientobject.ClientSetting.DeviceSetting.UsingPrintSlip == PrintSlipMode.UserChoose)
                        {
                            PopupWindow printWindow = new PopupWindow(TipType.PrintConfIrm);
                            printWindow.ShowDialog();
                            if (printWindow.viewModel.OperateResule == HandleResult.Successed)
                            {
                                printer.ThreadPrint(PrintStatus.General, data, clientobject.ClientSetting.ClientNo);
                            }
                        }
                    }
                    PopupWindow popWindow = new PopupWindow(TipType.BespeatSeatConfirmSuccess);
                    popWindow.ShowDialog();
                }
                else if (nowDate.CompareTo(dtBegin) < 0)
                {
                    //TODO:预约时间过早,请在dtBegin 到dtEnd刷卡确认。
                    PopupWindow popWindow = new PopupWindow(TipType.BookConfirmWarn);
                    popWindow.ShowDialog();
                    if (popWindow.viewModel.OperateResule == HandleResult.Successed)
                    {
                        bespeaklog.BsepeakState = BookingStatus.Cencaled;
                        bespeaklog.CancelPerson = Operation.Reader;
                        bespeaklog.CancelTime   = ServiceDateTime.Now;
                        bespeaklog.Remark       = string.Format("在终端{0}刷卡取消{1},{2}号座位的预约。", clientobject.ClientSetting.ClientNo, bespeaklog.ReadingRoomName, bespeaklog.ShortSeatNum);
                        int         i = T_SM_SeatBespeak.UpdateBespeakList(bespeaklog);
                        PopupWindow popWindowCancel = new PopupWindow(TipType.BookCancelSuccess);
                        popWindowCancel.ShowDialog();
                    }
                }
                else if (nowDate.CompareTo(dtEnd) < 0)
                {
                    //TODO:最迟确认时间为:dtEnd。
                }
                else
                {
                    //TODO:未知原因,预约确认失败。
                }
            }
        }