public override void Update(ViewModelReturnData VMReturnData)
        {
            //Only update this view if visible

            if (VMReturnData.AdvancedMenu_Active)
            {
                VMReturnData.OptionsPressed = true;
                this.View.Visibility        = Visibility.Visible;


                if (_HotflagBtnPressed)
                {
                    CardDetails WriteCardDetails = new CardDetails()
                    {
                        Hotflaged_status = true, HotFlagedDate = DateTime.Now, HotFlagedVID = 123
                    };
                    RFIDCardInfoWrite rFIDCardInfoWrite = new RFIDCardInfoWrite();
                    _HotflagBtnPressed = false;
                    byte[] temp = rFIDCardInfoWrite.Block9(WriteCardDetails);
                    if (MernokRFID_interface.Mifare_Write_Block(Mifare_key.A, 0, WriteCardDetails.Block9_Addr, temp))
                    {
                    }

                    VMReturnData.CardProramed_done = true;
                    VMReturnData.App_datareset();
                }

                if (_mernokcardBtnPressed)
                {
                    _mernokcardBtnPressed = false;
                    VMReturnData.MernokCardPresent_active = true;
                    VMReturnData.NewMernokCard            = true;
                }

                if (_FormatbtnPressed)
                {
                    _FormatbtnPressed = false;
                    RFIDCardInfoWrite rFIDCardInfoWrite = new RFIDCardInfoWrite();
                    CardDetails       WriteCardDetails  = new CardDetails()
                    {
                        cardUID          = 0,
                        AccessLevel      = 0,
                        ByPassBits       = 0,
                        Client_Group     = 0,
                        Client_Site      = 0,
                        EngineerName     = "",
                        EngineerUID      = 0,
                        Expiry_Date      = DateTime.MinValue,
                        HotFlagedDate    = DateTime.MinValue,
                        HotFlagedVID     = 0,
                        Hotflaged_status = false,
                        IssuerUID        = 0,
                        Issue_Date       = DateTime.MinValue,
                        OperationalArea  = 0,
                        OperatorName     = "",
                        Options          = 0,
                        ProductCode      = 0,
                        Training_Date    = DateTime.MinValue,
                        VehicleGroup     = Enumerable.Repeat((byte)0, 16).ToArray(),
                        VID                = Enumerable.Repeat((UInt16)0, 16).ToArray(),
                        VehicleNames       = Enumerable.Repeat("", 16).ToArray(),
                        VehicleLicenceType = Enumerable.Repeat((uint)0, 32).ToArray(),
                        Warning_Date       = DateTime.MinValue
                    };
                    rFIDCardInfoWrite.WriteInfoToCard(WriteCardDetails, VMReturnData.CardType);

                    VMReturnData.CardProramed_done = true;
                    VMReturnData.App_datareset();
                }


                #region Exit button
                else if (_buttonExitPressed)
                {
                    _buttonExitPressed = false;
                    VMReturnData.AdvancedMenu_Active = false;
                }
                #endregion
            }
            else
            {
                VMReturnData.OptionsPressed = false;
                this.View.Visibility        = Visibility.Collapsed;
            }
        }
        public int WriteInfoToCard(CardDetails WriteCardDetails, int CardType)
        {
            // byte[] key = { (byte)'S', 0, 2, 1, 3, 7, 255, 07, 128, 105, 255, 255, 255, 255, 255, 255};
            // if (MernokRFID_interface.MiFair_Store_Access_Key(0x0A, key)){

            // }

            byte[] temp = new byte[16];
            temp = Block1(WriteCardDetails);
            if (MernokRFID_interface.Mifare_Write_Block(Mifare_key.A, 0, cardDetailsW.Block1_Addr, temp))
            {
                temp = Block2(WriteCardDetails);
                if (MernokRFID_interface.Mifare_Write_Block(Mifare_key.A, 0, cardDetailsW.Block2_Addr, temp))
                {
                    temp = Block3(WriteCardDetails);
                    if (MernokRFID_interface.Mifare_Write_Block(Mifare_key.A, 0, cardDetailsW.Block3_Addr, temp))
                    {
                        temp = Block4(WriteCardDetails);
                        if (MernokRFID_interface.Mifare_Write_Block(Mifare_key.A, 0, cardDetailsW.Block4_Addr, temp))
                        {
                            temp = Block5(WriteCardDetails);
                            if (MernokRFID_interface.Mifare_Write_Block(Mifare_key.A, 0, cardDetailsW.Block5_Addr, temp))
                            {
                                temp = Block6(WriteCardDetails);
                                if (MernokRFID_interface.Mifare_Write_Block(Mifare_key.A, 0, cardDetailsW.Block6_Addr, temp))
                                {
                                    temp = Block7(WriteCardDetails);
                                    if (MernokRFID_interface.Mifare_Write_Block(Mifare_key.A, 0, cardDetailsW.Block7_Addr, temp))
                                    {
                                        temp = Block8(WriteCardDetails);
                                        if (MernokRFID_interface.Mifare_Write_Block(Mifare_key.A, 0, cardDetailsW.Block8_Addr, temp))
                                        {
                                            temp = Block9(WriteCardDetails);
                                            if (MernokRFID_interface.Mifare_Write_Block(Mifare_key.A, 0, cardDetailsW.Block9_Addr, temp))
                                            {
                                                temp = Block10(WriteCardDetails);
                                                if (MernokRFID_interface.Mifare_Write_Block(Mifare_key.A, 0, cardDetailsW.Block10_Addr, temp))
                                                {
                                                    temp = Block11(WriteCardDetails);
                                                    if (MernokRFID_interface.Mifare_Write_Block(Mifare_key.A, 0, cardDetailsW.Block11_Addr, temp))
                                                    {
                                                        temp = Block12(WriteCardDetails);
                                                        if (MernokRFID_interface.Mifare_Write_Block(Mifare_key.A, 0, cardDetailsW.Block12_Addr, temp))
                                                        {
                                                            if (CardType == 1 || CardType == 4)
                                                            {
                                                                for (int i = 0; i < 3; i++)
                                                                {
                                                                    temp = Block17_31_VehicleNames(WriteCardDetails, i);
                                                                    if (temp != null)
                                                                    {
                                                                        MernokRFID_interface.Mifare_Write_Block(Mifare_key.A, 0, cardDetailsW.Block17_1_Addr + i, temp);
                                                                    }
                                                                    else
                                                                    {
                                                                        MernokRFID_interface.Mifare_Write_Block(Mifare_key.A, 0, cardDetailsW.Block17_1_Addr + i, Encoding.ASCII.GetBytes(""));
                                                                    }
                                                                }

                                                                for (int i = 0; i < 3; i++)
                                                                {
                                                                    temp = Block17_31_VehicleNames(WriteCardDetails, i + 3);
                                                                    if (temp != null)
                                                                    {
                                                                        MernokRFID_interface.Mifare_Write_Block(Mifare_key.A, 0, cardDetailsW.Block17_2_Addr + i, temp);
                                                                    }
                                                                    else
                                                                    {
                                                                        MernokRFID_interface.Mifare_Write_Block(Mifare_key.A, 0, cardDetailsW.Block17_2_Addr + i, Encoding.ASCII.GetBytes(""));
                                                                    }
                                                                }
                                                            }

                                                            if (CardType == 4)
                                                            {
                                                                for (int i = 0; i < 3; i++)
                                                                {
                                                                    temp = Block17_31_VehicleNames(WriteCardDetails, i + 9);
                                                                    if (temp != null)
                                                                    {
                                                                        MernokRFID_interface.Mifare_Write_Block(Mifare_key.A, 0, cardDetailsW.Block17_3_Addr + i, temp);
                                                                    }
                                                                    else
                                                                    {
                                                                        MernokRFID_interface.Mifare_Write_Block(Mifare_key.A, 0, cardDetailsW.Block17_3_Addr + i, Encoding.ASCII.GetBytes(""));
                                                                    }
                                                                }

                                                                for (int i = 0; i < 3; i++)
                                                                {
                                                                    temp = Block17_31_VehicleNames(WriteCardDetails, i + 12);
                                                                    if (temp != null)
                                                                    {
                                                                        MernokRFID_interface.Mifare_Write_Block(Mifare_key.A, 0, cardDetailsW.Block17_4_Addr + i, temp);
                                                                    }
                                                                    else
                                                                    {
                                                                        MernokRFID_interface.Mifare_Write_Block(Mifare_key.A, 0, cardDetailsW.Block17_4_Addr + i, Encoding.ASCII.GetBytes(""));
                                                                    }
                                                                }

                                                                for (int i = 0; i < 3; i++)
                                                                {
                                                                    temp = Block17_31_VehicleNames(WriteCardDetails, i + 15);
                                                                    if (temp != null)
                                                                    {
                                                                        MernokRFID_interface.Mifare_Write_Block(Mifare_key.A, 0, cardDetailsW.Block17_5_Addr + i, temp);
                                                                    }
                                                                    else
                                                                    {
                                                                        MernokRFID_interface.Mifare_Write_Block(Mifare_key.A, 0, cardDetailsW.Block17_5_Addr + i, Encoding.ASCII.GetBytes(""));
                                                                    }
                                                                }
                                                            }

                                                            temp = Block31_OperatorSurname(WriteCardDetails);
                                                            if (MernokRFID_interface.Mifare_Write_Block(Mifare_key.A, 0, cardDetailsW.Block18_Addr, temp))
                                                            {
                                                                temp = Block32_Dover(WriteCardDetails);
                                                                if (MernokRFID_interface.Mifare_Write_Block(Mifare_key.A, 0, cardDetailsW.Block19_Addr, temp))
                                                                {
                                                                    temp = Blank_Block_Temp_1(WriteCardDetails);
                                                                    MernokRFID_interface.Mifare_Write_Block(Mifare_key.A, 0, 60, temp);
                                                                    temp = Blank_Block_Temp_2(WriteCardDetails);
                                                                    MernokRFID_interface.Mifare_Write_Block(Mifare_key.A, 0, 61, temp);
                                                                    temp = Blank_Block_Temp_3(WriteCardDetails);
                                                                    MernokRFID_interface.Mifare_Write_Block(Mifare_key.A, 0, 62, temp);
                                                                    return(100);
                                                                }
                                                                else
                                                                {
                                                                    return(14);
                                                                }
                                                            }
                                                            else
                                                            {
                                                                return(13);
                                                            }
                                                        }
                                                        else
                                                        {
                                                            return(12);
                                                        }
                                                    }
                                                    else
                                                    {
                                                        return(11);
                                                    }
                                                    //MessageBox.Show("Card Successfullly Programed");
                                                }
                                                else
                                                {
                                                    return(10);
                                                }
                                                //MessageBox.Show("Card Programeing failed at block 10");
                                            }
                                            else
                                            {
                                                return(9);
                                            }
                                            //MessageBox.Show("Card Programeing failed at block 9");
                                        }
                                        else
                                        {
                                            return(8);
                                        }
                                        //MessageBox.Show("Card Programeing failed at block 8");
                                    }
                                    else
                                    {
                                        return(7);
                                    }
                                    //MessageBox.Show("Card Programeing failed at block 7");
                                }
                                else
                                {
                                    return(6);
                                }
                                // MessageBox.Show("Card Programeing failed at block 6");
                            }
                            else
                            {
                                return(5);
                            }
                            // MessageBox.Show("Card Programeing failed at block 5");
                        }
                        else
                        {
                            return(4);
                        }
                        //MessageBox.Show("Card Programeing failed at block 4");
                    }
                    else
                    {
                        return(2);
                    }
                    //MessageBox.Show("Card Programeing failed at block 2");
                }
                else
                {
                    return(1);
                }
                //MessageBox.Show("Card Programeing failed at block 1");
            }
            return(0);
        }