Exemplo n.º 1
0
        private static void Host_PostBatch(object sender, Chromium.Remote.Event.CfrV8HandlerExecuteEventArgs e)
        {
            UpdateBatchParam(e);

            Task.Factory.StartNew(() =>
            {
                try
                {
                    int index = -1;
                    CardBatch batchReceived = null;
                    foreach (CardInfo item in CardManager.CardInfos)
                    {
                        if (item.Id == 0 && item.CardType < 3)
                        {
                            index += 1;

                            item.CardTime            = CardManager.BatchParam.CardTime;
                            item.CardDistance        = CardManager.BatchParam.CardDistance;
                            item.ParkingRestrictions = CardManager.BatchParam.ParkingRestrictions;
                            item.CardPartition       = CardManager.BatchParam.CardPartition;

                            byte[] by = DistanceIssue.Issue(item);
                            bool ret  = SerialPortManager.WriteSerialPortData(SerialPortManager.Device1, by);
                            if (ret)
                            {
                                ReceivedManager.SetReceivedFunction <CardBatch>();
                                if (batchReceived == null)
                                {
                                    batchReceived = ReceivedManager.GetReceivedFun <CardBatch>();
                                }
                                batchReceived.IssueInfo = item;

                                for (int i = 0; i < 250; i++)
                                {
                                    Thread.Sleep(10);
                                    if (batchReceived.IssueInfo == null)
                                    {
                                        if (item.Id > 0)
                                        {
                                            ViewCallFunction.ViewDisplayBatchContent(item, index);
                                        }
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    Log4Helper.ErrorInfo(ex.Message, ex);
                    ViewCallFunction.ViewAlert(ex.Message);
                }
                finally
                {
                    int count = CardManager.CardInfos.Where(w => w.Id == 0 && w.CardType < 3).Count();
                    ViewCallFunction.ViewBatchOver(count);
                }
            });
        }
Exemplo n.º 2
0
        private static void Host_PostIssue(object sender, Chromium.Remote.Event.CfrV8HandlerExecuteEventArgs e)
        {
            try
            {
                int index = e.Arguments[0].IntValue;
                Chromium.Remote.CfrTime cTime = e.Arguments[1].DateValue;
                DateTime time      = new DateTime(cTime.Year, cTime.Month, cTime.DayOfMonth);
                int      distance  = e.Arguments[2].IntValue;
                int      limit     = e.Arguments[3].IntValue;
                int      type      = e.Arguments[4].IntValue;
                int      partition = e.Arguments[5].IntValue;

                CardInfo info = CardManager.CardInfos[index];
                info.CardType            = type;
                info.CardDistance        = distance;
                info.CardTime            = time;
                info.ParkingRestrictions = limit;
                info.CardPartition       = partition;
                info.CardCount           = DistanceIssue.SetCount(info.CardCount);

                byte[] by;
                if (info.CardType == (int)PortEnums.CardTypes.Card2 && (info.ViceCardInfos != null && info.ViceCardInfos.Count > 0))
                {
                    info.CardTime = info.ViceCardInfos.Max(w => w.CardTime);

                    ViceCardRemoveLock lockReceived = null;
                    foreach (CardInfo item in info.ViceCardInfos)
                    {
                        if (item.CardLock == 1)
                        {
                            by = DistanceIssue.Issue(item);
                            SerialPortManager.WriteSerialPortData(SerialPortManager.Device1, by);

                            ReceivedManager.SetReceivedFunction <ViceCardRemoveLock>();
                            if (lockReceived == null)
                            {
                                lockReceived = ReceivedManager.GetReceivedFun <ViceCardRemoveLock>();
                            }
                            lockReceived.RemoveLockInfo = item;

                            for (int i = 0; i < 250; i++)
                            {
                                Thread.Sleep(10);
                                if (lockReceived.RemoveLockInfo == null)
                                {
                                    if (item.CardLock == 0)
                                    {
                                        ViewCallFunction.ViewRemoveLock(info.ViceCardInfos);
                                    }
                                    break;
                                }
                            }
                        }
                    }
                }

                by = DistanceIssue.Issue(info);
                bool ret = SerialPortManager.WriteSerialPortData(SerialPortManager.Device1, by);
                if (ret)
                {
                    ReceivedManager.SetReceivedFunction <CardIssue>();
                    ReceivedManager.GetReceivedFun <CardIssue>().IssueInfo = info;
                }
                e.SetReturnValue(ret);
            }
            catch (Exception ex)
            {
                Log4Helper.ErrorInfo(ex.Message, ex);
                ViewCallFunction.ViewAlert(ex.Message);
            }
        }