Пример #1
0
        public static Models.Collection DeserializeCollection(string data)
        {
            Models.Collection cellar = null;

            //Set up the binary formater for serialization.
            BinaryFormatter bf = new BinaryFormatter();

            //Convert the base64 string to an array of bytes to pass to the memory stream
            byte[] b = Convert.FromBase64String(data);

            //Setup memory string to hold the object in memory format and transform process.
            MemoryStream ms = new MemoryStream(b);

            //Deserialize
            try
            {
                cellar = (Models.Collection)bf.Deserialize(ms);
            }
            finally
            {
                ms.Close();
            }

            return(cellar);
        }
Пример #2
0
        private void BtnLogin_Click(object sender, EventArgs e)
        {
            try
            {
                int pinNum = Convert.ToInt32(pin1.Text + pin2.Text + pin3.Text + pin4.Text);

                //Verify info and login to account

                //Check username against all usernames in list
                Models.Collection theCollection = null;
                bool uMatch = false;

                foreach (Models.Collection c in data)
                {
                    if (username.Text == c.UserName)
                    {
                        uMatch        = true;
                        theCollection = c;
                    }
                }

                if (uMatch)
                {
                    //Check that PIN matches PIN for username
                    if (theCollection.PinNumber == pinNum)
                    {
                        //If so, open the Dashboard using the collection
                        Dashboard d = new Dashboard(theCollection);
                        d.Show();
                        Hide();
                    }
                    else
                    {
                        //Otherwise, show that they do not match
                        MessageBox.Show("The Username or password you entered is invalid. Please try again.",
                                        "Invalid Login", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        ResetInput();
                    }
                }
                else
                {
                    MessageBox.Show("The Username or password you entered is invalid. Please try again.",
                                    "Invalid Login", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    ResetInput();
                }
            }
            catch
            {
                //Shoe Messagebox Error about PIN
                MessageBox.Show("PIN must include only numbers", "Invalid Input", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                ResetInput();
            }
        }
Пример #3
0
        public static List <Models.Collection> GetCollections()
        {
            List <Models.Collection> records = new List <Models.Collection>();
            List <string>            data    = DataAdapter.GetRecords();

            foreach (string item in data)
            {
                Models.Collection newCollection = DeserializeCollection(item);
                records.Add(newCollection);
            }

            return(records);
        }
Пример #4
0
        public static string SerializeCollection(Models.Collection cellar)
        {
            //Setup memory string to hold the object in memory format and transform process.
            MemoryStream myStream = new MemoryStream();

            //Set up the binary formater for serialization.
            BinaryFormatter myFormater = new BinaryFormatter();

            myFormater.Serialize(myStream, cellar);
            //Convert to 64 bit data
            string data = Convert.ToBase64String(myStream.ToArray());

            myStream.Close();

            return(data);
        }