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();
            }
        }
Exemple #2
0
        public static bool addCredit(UInt64 amount)
        {
            SL500 sl = new SL500();
            if (request() == true)
            {
                if (sl.anticoll() == true)
                {
                    sl.select();

                    if (sl.authentify(1) == 0)
                    {
                        status = sl.dataWrite((byte)block._credit, BitConverter.GetBytes(amount));
                        if (status == 0)
                        {
                            return true;
                        }
                        return false;
                    }
                    return false;
                }
                return false;
            }
            return false;
        }
Exemple #3
0
        public static bool delCredit()
        {
            SL500 sl = new SL500();
            if (request() == true)
            {
                if (sl.anticoll() == true)
                {
                    sl.select();

                    if (sl.authentify(1) == 0)
                    {
                        status = sl.dataWrite((byte)block._credit, new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 });
                        if (status == 0)
                        {
                            return true;
                        }
                        return false;
                    }
                    return false;
                }
                return false;
            }
            return false;
        }
Exemple #4
0
        public static bool updateInfo(List<string> l)
        {
            SL500 sl = new SL500();
            if (request() == true)
            {
                if (sl.anticoll() == true)
                {
                    string select = sl.select();
                    if (select != "e")
                    {
                        if (sl.authentify(2) == 0)
                        {
                            int status = 1;

                            byte[] text = new byte[16];
                            text = Encoding.ASCII.GetBytes(l[1]);
                            status = sl.dataWrite((byte)block._name, text);

                            sl.authentify(2);
                            text = Encoding.ASCII.GetBytes(l[2]);
                            status = sl.dataWrite((byte)block._surname, text);

                            sl.authentify(2);
                            text = Encoding.ASCII.GetBytes(l[3]);
                            status = sl.dataWrite((byte)block._func, text);

                            if (status != 0)
                            {
                                return false;
                            }
                            return true;
                        }
                        return false;
                    }
                    return false;
                }
                return false;
            }
            return false;
        }
Exemple #5
0
        public static bool write(List<string> l)
        {
            SL500 sl = new SL500();
            if (request() == true)
            {
                if (sl.anticoll() == true)
                {
                    string select = sl.select();
                    if (select != "e")
                    {
                        if (sl.authentify(1) == 0)
                        {
                            byte[] type = new byte[] { (byte)int.Parse(l[1]), 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, (byte)int.Parse(l[5]), 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };

                            sl.dataWrite((byte)6, type);

                            sl.authentify(2);
                            int status = 1;

                            byte[] text = new byte[16];
                            text = Encoding.ASCII.GetBytes(l[2]);
                            status = sl.dataWrite((byte)block._name, text);

                            sl.authentify(2);
                            text = Encoding.ASCII.GetBytes(l[3]);
                            status = sl.dataWrite((byte)block._surname, text);

                            sl.authentify(2);
                            text = Encoding.ASCII.GetBytes(l[4]);
                            status = sl.dataWrite((byte)block._func, text);

                            sl.authentify(1);
                            text = BitConverter.GetBytes(program.Owner);
                            status = sl.dataWrite((byte)block._owner, text);

                            if (l[1] == "2")
                            {
                                text = BitConverter.GetBytes(0);
                                status = sl.dataWrite((byte)block._credit, text);
                            }
                            if (status != 0)
                            {
                                return false;
                            }
                            return true;

                        }
                        return false;
                    }
                    return false;
                }
                return false;
            }
            return false;
        }
Exemple #6
0
        public static List<string> readCard()
        {
            SL500 sl = new SL500();

            /****************list blocks*********************/
            // 0 ... card number
            // 1 ... card type
            // 2 ... credit
            // 3 ... name
            // 4 ... surname
            // 5 ... function or some else

            List<string> result = new List<string>();
            char[] _trim = new char[] { '\0', ' ' };

            if (request() == true)
            {
                if (sl.anticoll() == true)
                {
                    string select = sl.select();

                    result.Add(select);
                    if (select != "e")
                    {
                        if (sl.authentify(1) == 0)
                        {
                            string type = sl.readType(0);
                            result.Add(type);
                            int owner = SL500.ownerId(0);
                            if (owner != -1 && owner == program.Owner || owner == 0)
                            {
                                sl.authentify(1);
                                string credit = sl.data((byte)block._credit);
                                result.Add(credit.Trim(_trim));

                                sl.authentify(2);
                                string name = sl.data((byte)block._name);
                                result.Add(name.Trim(_trim));

                                sl.authentify(2);
                                string surname = sl.data((byte)block._surname);
                                result.Add(surname.Trim(_trim));

                                sl.authentify(2);
                                string func = sl.data((byte)block._func);
                                result.Add(func.Trim(_trim));

                                sl.authentify(1);
                                string discount = sl.readType(1);
                                result.Add(discount);

                                return result;
                            }
                            else
                            {
                                result.Add(owner.ToString());
                            }
                        }
                        return result;
                    }
                    return null;
                }
                return null;
            }
            return null;


        }
Exemple #7
0
        public static void ownerNew(string own)
        {

            try
            {
                SL500 sl = new SL500();
                byte[] write = new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
                byte[] owner = BitConverter.GetBytes(int.Parse(own));
                Array.Copy(owner, 0, write, 0, owner.Length);
                if (request() == true)
                {
                    if (sl.anticoll() == true)
                    {
                        string select = sl.select();
                        if (select != "e")
                        {
                            if (sl.authentify(1) == 0)
                            {
                                sl.dataWrite((byte)block._owner, write);
                            }
                        }
                    }
                }
            }
            catch (Exception add)
            {
                //using (FileStream fs = new FileStream(@"log\log.txt", FileMode.Append, FileAccess.Write))
                //{
                //    byte[] write = Encoding.ASCII.GetBytes("OWNER WRITE NULL ERROR\r\n");
                //    fs.Write(write, 0, write.Length);
                //    write = Encoding.ASCII.GetBytes(add.Message);
                //    fs.Write(write, 0, write.Length);
                //    write = Encoding.ASCII.GetBytes("\r\n--------------------------------------\r\n");
                //    fs.Write(write, 0, write.Length);
                //    fs.Flush();
                //    fs.Close();
                //}
            }
        }
Exemple #8
0
        // Start HERE
        public static bool changeState(int c) // 0 - deactivate, 1-activate
        {
            try
            {
                SL500 sl = new SL500();
                IntPtr key;
                IntPtr writeValue;
                byte[] selection;
                byte[] authen;
                if (c == 0)
                {
                    selection = unactive;
                    authen = active;
                }
                else
                {
                    selection = active;
                    authen = unactive;
                }

                byte mode = 0x60;

                if (request() == true)
                {
                    if (sl.anticoll() == true)
                    {
                        sl.select();

                        key = Marshal.AllocHGlobal(1024);

                        for (int i = 0; i < 7; i++)
                            Marshal.WriteByte(key, i, authen[i]);
                        status = rf_M1_authentication2(icdev, mode, 0x04, key); // Autentify to card
                        if (status != 0)
                        {
                            Marshal.FreeHGlobal(key);
                            return false;
                        }
                        Marshal.FreeHGlobal(key);

                        writeValue = Marshal.AllocHGlobal(1024);

                        for (int i = 0; i < selection.Length; i++)
                            Marshal.WriteByte(writeValue, i, selection[i]);

                        status = rf_M1_write(icdev, 0x07, writeValue); // write key A 
                        if (status == 0)
                        {
                            key = Marshal.AllocHGlobal(1024);

                            for (int i = 0; i < 7; i++)
                                Marshal.WriteByte(key, i, authen[i]);
                            status = rf_M1_authentication2(icdev, mode, 0x08, key); // Autentify to card
                            if (status != 0)
                            {
                                Marshal.FreeHGlobal(key);
                                return false;
                            }
                            Marshal.FreeHGlobal(key);

                            status = rf_M1_write(icdev, (byte)11, writeValue);
                            if (status == 0)
                            {

                                Marshal.FreeHGlobal(writeValue);
                                return true;
                            }

                            Marshal.FreeHGlobal(writeValue);
                            return false;
                        }

                        return false;
                    }
                    return false;
                }
                return false;
            }
            catch (Exception add)
            {
                //using (FileStream fs = new FileStream(@"log\log.txt", FileMode.Append, FileAccess.Write))
                //{
                //    byte[] write = Encoding.ASCII.GetBytes("CHANGE STATE: " + c.ToString() + "\r\n");
                //    fs.Write(write, 0, write.Length);
                //    write = Encoding.ASCII.GetBytes(add.Message);
                //    fs.Write(write, 0, write.Length);
                //    write = Encoding.ASCII.GetBytes("\r\n--------------------------------------\r\n");
                //    fs.Write(write, 0, write.Length);
                //    fs.Flush();
                //    fs.Close();
                //}

                return false;
            }
        }