Com.Aote.ObjectTools.GeneralICCard.ReWriteCard C# (CSharp) Method

ReWriteCard() public method

public ReWriteCard ( ) : void
return void
        public void ReWriteCard()
        {
            IsBusy = true;
            Error = "";
            State = State.Start;
            //执行写卡线程
            Thread thread = new Thread(() =>
            {
                dynamic ocx = AutomationFactory.CreateObject("HJIC.HJICCtrl.1");
                AutomationFactory.GetEvent(ocx, "ReadGasCard");
                int openRen = ocx.ReadGasCard();
                //读卡失败
                if (openRen != 0)
                {
                    if (this.Dispatcher.CheckAccess())
                    {
                        Error = "擦卡不成功!错误代码" + openRen;
                        State = State.Error;
                    }
                    else
                    {
                        this.Dispatcher.BeginInvoke(() =>
                        {
                            Error = "擦卡不成功!错误代码" + openRen;
                            State = State.Error;
                        });
                    }
                }
                else
                {
                    //获取擦卡所需数据
                    AutomationFactory.GetEvent(ocx, "GetCardId");
                    string _cardId = ocx.GetCardId();
                    AutomationFactory.GetEvent(ocx, "GetFactory");
                    string _factory = ocx.GetFactory();
                    AutomationFactory.GetEvent(ocx, "GetKlx");
                    int _klx = ocx.GetKlx();
                    AutomationFactory.GetEvent(ocx, "GetDqdm");
                    string _dqdm = ocx.GetDqdm();
                    //擦卡
                    AutomationFactory.GetEvent(ocx, "FormatGasCard");
                    int sellRen = ocx.FormatGasCard(_factory, Kmm, _klx, _cardId, _dqdm);
                    //擦卡后,写初始化卡
                    if (sellRen == 0)
                    {
                        //写初始化卡
                        AutomationFactory.GetEvent(ocx, "WriteGasCard");
                        sellRen = ocx.WriteNewCard(Factory, Kmm, Klx, Kzt, CardId, Dqdm, Yhh, Tm, Gas, BuyTimes, Ljgql, Bkcs, Bjql, Czsx, Tzed, Sqrq);
                        //售气成功返回true,失败false;
                        AutomationFactory.GetEvent(ocx, "GetKmm");
                        AutomationFactory.GetEvent(ocx, "GetCardId");
                        string mm = ocx.GetKmm();
                        string kh = ocx.GetCardId();
                        if (sellRen == 0)
                        {
                            if (this.Dispatcher.CheckAccess())
                            {
                                Kmm = mm;
                                CardId = kh;
                                State = State.End;
                            }
                            else
                            {
                                this.Dispatcher.BeginInvoke(() =>
                                {
                                    Kmm = mm;
                                    CardId = kh;
                                    State = State.End;
                                });
                            }
                        }
                        else
                        {
                            if (this.Dispatcher.CheckAccess())
                            {
                                Error = "发卡不成功!错误代码" + sellRen;
                                State = State.Error;
                            }
                            else
                            {
                                this.Dispatcher.BeginInvoke(() =>
                                {
                                    Error = "发卡不成功!错误代码" + sellRen;
                                    State = State.Error;
                                });
                            }
                        }
                    }
                    else
                    {
                        if (this.Dispatcher.CheckAccess())
                        {
                            Error = "擦卡不成功!错误代码" + sellRen;
                            State = State.Error;
                        }
                        else
                        {
                            this.Dispatcher.BeginInvoke(() =>
                            {
                                Error = "擦卡不成功!错误代码" + sellRen;
                                State = State.Error;
                            });
                        }
                    }
                }
                //IsBusy=false;
                if (this.Dispatcher.CheckAccess())
                {
                    IsBusy = false;
                }
                else
                {
                    this.Dispatcher.BeginInvoke(() =>
                    {
                        IsBusy = false;
                    });
                }
                if (this.Dispatcher.CheckAccess())
                {
                    OnCompleted(null);
                }
                else
                {
                    this.Dispatcher.BeginInvoke(() =>
                    {
                        OnCompleted(null);
                    });
                }
            });
            thread.Start();
        }
        #endregion

Usage Example

Example #1
0
        private static void OnCanRewriteCardChanged(DependencyObject dp, DependencyPropertyChangedEventArgs e)
        {
            GeneralICCard card = (GeneralICCard)dp;

            if (card.CanRewriteCard)
            {
                card.ReWriteCard();
            }
        }