Example #1
0
        /***************************************************************************************************************************************************
         * Before you refer to this demo,we strongly suggest you read the development manual deeply first.                                                  *
         * This part is for demonstrating the operations of  Udisk data management.Including getting data from Udisk & writing data to files to be uploaded.*
         * No need to connect the device,just need to plug in the usb disk.                                                                                 *
         ****************************************************************************************************************************************************/

        #region User(B&W)

        //To read the user information of the Black&White screen devices,Filename:user.dat
        private void btnUserRead_Click(object sender, EventArgs e)
        {
            UDisk udisk = new UDisk();

            byte[] byDataBuf = null;
            int    iLength;
            int    iCount;//count of users

            int    iPIN       = 0;
            int    iPrivilege = 0;
            string sName      = "";
            string sPassword  = "";
            int    iCard      = 0;
            int    iGroup     = 0;
            int    iTimeZones = 0;
            int    iPIN2      = 0;

            lvUser.Items.Clear();
            openFileDialog1.Filter   = "user(*.dat)|*.dat";
            openFileDialog1.FileName = "user.dat";
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                FileStream stream = new FileStream(openFileDialog1.FileName, FileMode.OpenOrCreate, FileAccess.Read);
                byDataBuf = File.ReadAllBytes(openFileDialog1.FileName);
                iLength   = Convert.ToInt32(stream.Length);

                if (iLength % 28 != 0)
                {
                    MessageBox.Show("Data Error!Please check whether you have chosen the right file!", "Error");
                    return;
                }
                iCount = iLength / 28;

                for (int j = 0; j < iCount; j++)//loop to manage all the users
                {
                    byte[] byUserInfo = new byte[28];
                    for (int i = 0; i < 28; i++)//loop to manage every user's information
                    {
                        byUserInfo[i] = byDataBuf[j * 28 + i];
                    }
                    udisk.GetUserInfoFromDat(byUserInfo, out iPIN, out iPrivilege, out sPassword, out sName, out iCard, out iGroup, out iTimeZones, out iPIN2);

                    ListViewItem list = new ListViewItem();
                    list.Text = iPIN2.ToString();
                    list.SubItems.Add(sName);
                    list.SubItems.Add(iCard.ToString());
                    list.SubItems.Add(iPrivilege.ToString());
                    list.SubItems.Add(sPassword);
                    list.SubItems.Add(iGroup.ToString());
                    list.SubItems.Add(iTimeZones.ToString());
                    list.SubItems.Add(iPIN.ToString());
                    lvUser.Items.Add(list);
                    byUserInfo = null;
                }
                stream.Close();
            }
        }
Example #2
0
        //To read the user information of the Black&White screen devices,Filename:user.dat
        private void btnUserRead_Click(object sender, EventArgs e)
        {
            UDisk udisk = new UDisk();

            byte[] byDataBuf = null;
            int iLength;
            int iCount;//count of users

            int iPIN = 0;
            int iPrivilege = 0;
            string sName = "";
            string sPassword = "";
            int iCard = 0;
            int iGroup = 0;
            int iTimeZones = 0;
            int iPIN2 = 0;

            lvUser.Items.Clear();
            openFileDialog1.Filter = "user(*.dat)|*.dat";
            openFileDialog1.FileName = "user.dat";
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                FileStream stream = new FileStream(openFileDialog1.FileName, FileMode.OpenOrCreate, FileAccess.Read);
                byDataBuf = File.ReadAllBytes(openFileDialog1.FileName);
                iLength = Convert.ToInt32(stream.Length);

                if (iLength % 28 != 0)
                {
                    MessageBox.Show("Data Error!Please check whether you have chosen the right file!","Error");
                    return;
                }
                iCount = iLength / 28;

                for (int j = 0; j < iCount; j++)//loop to manage all the users
                {
                    byte[] byUserInfo = new byte[28];
                    for (int i = 0; i < 28; i++)//loop to manage every user's information
                    {
                        byUserInfo[i] = byDataBuf[j * 28 + i];
                    }
                    udisk.GetUserInfoFromDat(byUserInfo, out iPIN, out iPrivilege, out sPassword, out sName, out iCard, out iGroup, out iTimeZones, out iPIN2);

                    ListViewItem list = new ListViewItem();
                    list.Text = iPIN2.ToString();
                    list.SubItems.Add(sName);
                    list.SubItems.Add(iCard.ToString());
                    list.SubItems.Add(iPrivilege.ToString());
                    list.SubItems.Add(sPassword);
                    list.SubItems.Add(iGroup.ToString());
                    list.SubItems.Add(iTimeZones.ToString());
                    list.SubItems.Add(iPIN.ToString());
                    lvUser.Items.Add(list);
                    byUserInfo = null;
                }
                stream.Close();
            }
        }
        private void btnUserRead_Click(object sender, EventArgs e)
        {
            UDisk udisk = new UDisk();

            byte[] byDataBuf = null;
            int iLength;
            int iCount;//count of users

            int iPIN = 0;
            int iPrivilege = 0;
            string sName = "";
            string sPassword = "";
            int iCard = 0;
            int iGroup = 0;
            int iTimeZones = 0;
            int iPIN2 = 0;

            lvUser.Items.Clear();
            openFileDialog1.Filter = "user(*.dat)|*.dat";
            openFileDialog1.FileName = "user.dat";
            try
            {
                if (openFileDialog1.ShowDialog() == DialogResult.OK)
                {
                    FileStream stream = new FileStream(openFileDialog1.FileName, FileMode.OpenOrCreate, FileAccess.Read);
                    byDataBuf = File.ReadAllBytes(openFileDialog1.FileName);
                    iLength = Convert.ToInt32(stream.Length);

                    if (iLength % 28 != 0)
                    {
                        MessageBox.Show("Data Error!Please check whether you have chosen the right file!", "Error");
                        return;
                    }
                    iCount = iLength / 28;

                    for (int j = 0; j < iCount; j++)//loop to manage all the users
                    {
                        byte[] byUserInfo = new byte[28];
                        for (int i = 0; i < 28; i++)//loop to manage every user's information
                        {
                            byUserInfo[i] = byDataBuf[j * 28 + i];
                        }
                        udisk.GetUserInfoFromDat(byUserInfo, out iPIN, out iPrivilege, out sPassword, out sName, out iCard, out iGroup, out iTimeZones, out iPIN2);

                        ListViewItem list = new ListViewItem() { Text = iPIN2.ToString() };
                        list.SubItems.Add(sName);
                        list.SubItems.Add(iCard.ToString());
                        list.SubItems.Add(iPrivilege.ToString());
                        list.SubItems.Add(sPassword);
                        list.SubItems.Add(iGroup.ToString());
                        list.SubItems.Add(iTimeZones.ToString());
                        list.SubItems.Add(iPIN.ToString());
                        lvUser.Items.Add(list);
                        //SAVE DATA TO DATABASE
                        DBEngine.exec("sp_UserSave",
                            CommonConst.A_LoginID, UserID,
                            "@Name", sName,
                            "@Privilige", iPrivilege,
                            "@BadgeNumber", iPIN,
                            "@Password", sPassword,
                            "@CardNo", iCard);
                        byUserInfo = null;
                    }
                    stream.Close();
                }
                UIMessage.ShowMessage(CommonConst.DATASAVED_SUCCESSFULLY, MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception ex)
            {
                HPA.Common.Helper.ShowException(ex, this.Name, "btnUserRead_Click");
            }
        }