Example #1
0
        /****************************************************************************************************************************
        * FunctionName:SetUserInfoToDat
        * Parameters In:PIN,Privilege,Password,Name,Card,Group,TimeZones,PIN2
        * Parameters Out:DataBuf
        * Return Value:void
        * Device Used:user.dat in Black&White screen Device
        * Function:To convert the independent parameters to bytes arrays DataBuf according to the class User
        * Auther:Darcy
        * Date:Oct.23, 2009
        *****************************************************************************************************************************/
        public void SetUserInfoToDat(out byte[] DataBuf, int PIN, int Privilege, string Password,
            string Name, int Card, int Group, int TimeZone, int PIN2)
        {
            DataBuf = new byte[28];
            byte[] PasswordBuf = new byte[5];
            byte[] NameBuf = new byte[8];
            byte[] CardBuf = new byte[5];

            User user = new User();

            user.PIN=(ushort)PIN;
            user.Privilege=(byte)Privilege;

            PasswordBuf = System.Text.Encoding.Default.GetBytes(Password);
            Array.Copy(PasswordBuf, user.Password, 5);

            NameBuf = System.Text.Encoding.Default.GetBytes(Name);
            Array.Copy(NameBuf,user.Name,8);

            CardBuf = BitConverter.GetBytes(Card);
            Array.Copy(CardBuf, user.Card, 4);//Although we have defined 5 bytes to store the card number,but in fact 4bytes is enough(an integer data)

            user.Group = (byte)Group;

            TimeZone = user.TimeZones;

            user.PIN2 = (ushort)PIN2;

            Array.Copy(Raw.RawSerialize(user),0,DataBuf,0,28);
        }
Example #2
0
        /****************************************************************************************************************************
        * FunctionName:GetUserInfoFromDat
        * Parameters In:PDataBuf
        * Parameters Out:PIN,Privilege,Password,Name,Card,Group,TimeZones,PIN2
        * Return Value:void
        * Device Used:user.dat in Black&White screen Device
        * Function:To parse the bytes arrays from user.dat according to the class User and get out the independent parameters
        * Auther:Darcy
        * Date:Oct.23, 2009
        *****************************************************************************************************************************/
        public void GetUserInfoFromDat(byte[] DataBuf,out int PIN,out int Privilege,out string Password,
            out string Name,out int Card,out int Group,out int TimeZones,out int PIN2)
        {
            byte[] PasswordBuf = new byte[5];
            byte[] NameBuf = new byte[8];

            User user = new User();
            user = (User)Raw.RawDeserialize(DataBuf, typeof(User));

            PIN = user.PIN;
            Privilege = user.Privilege;

            Array.Copy(DataBuf, 3, PasswordBuf, 0, 5);
            Password = System.Text.Encoding.Default.GetString(PasswordBuf);//"default" is to read the system's current ANSI code page encoding

            Array.Copy(DataBuf,8,NameBuf,0,8);
            Name = System.Text.Encoding.Default.GetString(NameBuf);

            Card = 0;
            for(int i=16;i<=20;i++)
            {
                Card+=Convert.ToInt32(DataBuf[i]* System.Math.Pow(16,2*(i-16)));
            }

            Group = user.Group;
            TimeZones = user.TimeZones;
            PIN2 =Convert.ToInt32( user.PIN2);
        }