Exemplo n.º 1
0
        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            if (!caled)
            {
                caled = true;

                scan = new Thread(() =>
                {
                    while (todo)
                    {
                        if (!Common.rederAvaible)
                        {
                            COM.scan();
                            if (Common.rederAvaible)
                            {
                                SL500.rf_init_com(Common.PortName, 9600);
                                this.Dispatcher.Invoke((Action)(() =>
                                {
                                    Storyboard sb = this.FindResource("readerToCard") as Storyboard;
                                    sb.Begin();
                                }));
                            }
                        }

                        if (Common.rederAvaible)
                        {
                            SL500 sl = new SL500();

                            Thread.Sleep(500);

                            if (waitRemove)
                            {
                                while (SL500.request())
                                {
                                    Thread.Sleep(500);
                                }

                                waitRemove = false;

                                this.Dispatcher.Invoke((Action)(() =>
                                {
                                    Storyboard sb = this.FindResource("invalidToCard") as Storyboard;
                                    sb.Begin();
                                }));
                            }
                            else
                            {
                                while (!SL500.request())
                                {
                                    Thread.Sleep(500);
                                }

                                if (sl.anticoll())
                                {
                                    sl.select();

                                    if (sl.authentify(1) == 0)
                                    {
                                        int owner = SL500.ownerId(0);

                                        if (owner > 0)
                                        {
                                            string[] typedebit = sl.TypeAndDebit();
                                            Dictionary<string, string> setting = new Dictionary<string, string>();
                                            if (typedebit[0] == "6")
                                            {
                                                if (typedebit[1] == "1")
                                                {
                                                    setting.Add("Debit", "True");
                                                    ApplicationSettings.DEBIT = true;
                                                }
                                                else
                                                {
                                                    setting.Add("Debit", "False");
                                                    ApplicationSettings.DEBIT = false;
                                                }

                                                Helper.Helper.appSettings(setting);

                                                this.Dispatcher.Invoke((Action)(() =>
                                                {
                                                    this.company_id.Content = owner.ToString();
                                                    Storyboard sb = this.FindResource("cardToSave") as Storyboard;
                                                    sb.Begin();
                                                }));

                                                waitRemove = true;
                                            }
                                            else
                                            {
                                                this.Dispatcher.Invoke((Action)(() =>
                                                {
                                                    Storyboard sb = this.FindResource("invalidType") as Storyboard;
                                                    sb.Begin();
                                                }));

                                                waitRemove = true;
                                            }
                                        }
                                    }
                                }

                            }
                        }
                    }
                });
                scan.IsBackground = true;
                scan.Start();
            }
        }