Exemplo n.º 1
0
        public Description(Guid guid)
        {
            _uniqueid  = guid;
            _timestamp = DateTime.Now;
            _title     = "";
            _age       = new Range(Range.Type.AGE);
            _gender    = (GenderType)0;
            _sexuality = (SexualityType)0;
            _area      = (AreaType)0;
            _smoking   = (SmokingType)0;
            _drinking  = (DrinkingType)0;

            _alteredfields = new Dictionary <string, bool>();
            SetAlteredFields(false);
        }
Exemplo n.º 2
0
        // Select all users from the database
        public List <User> SelectAllUsers()
        {
            string query = "SELECT * FROM user AS usr " +
                           "INNER JOIN description AS dscr ON usr.u_id = dscr.d_id " +
                           "INNER JOIN userdescription AS ud ON usr.u_id = ud.u_id " +
                           "INNER JOIN description AS pref ON ud.d_id = pref.d_id";

            //Create a list to store the result
            List <User> list = new List <User>();

            //Open connection
            if (this.OpenConnection() == true)
            {
                //Create Command
                MySqlCommand cmd = new MySqlCommand(query, connection);
                //Create a data reader and Execute the command
                MySqlDataReader dataReader = cmd.ExecuteReader();

                //Read the data and store them in the list
                while (dataReader.Read())
                {
                    User u = new User(new Guid(dataReader["u_id"].ToString()));
                    u.Username  = dataReader["username"].ToString();
                    u.FirstName = dataReader["firstname"].ToString();
                    u.LastName  = dataReader["lastname"].ToString();
                    u.Password  = dataReader["password"].ToString();
                    u.Birthday  = Tools.DTfromTS(Convert.ToDouble(dataReader["birthday"]));
                    u.Email     = dataReader["email"].ToString();
                    u.Location  = new GeoLocation(Convert.ToSingle(dataReader["loc_lat"]), Convert.ToSingle(dataReader["loc_lon"]), Tools.DTfromTS(Convert.ToDouble(dataReader["loc_tim"])));

                    u.Description           = new Description(new Guid(dataReader[10].ToString()));
                    u.Description.TimeStamp = Tools.DTfromTS(Convert.ToDouble(dataReader[11]));
                    u.Description.Title     = dataReader[12].ToString();
                    u.Description.Age.Set(Convert.ToInt32(dataReader[13].ToString()), Convert.ToInt32(dataReader[14].ToString()));
                    u.Description.Gender = EnumList <GenderType> .FromString(dataReader[15].ToString());

                    u.Description.Sexuality = EnumList <SexualityType> .FromString(dataReader[16].ToString());

                    //country = 17
                    u.Description.Area = EnumList <AreaType> .FromString(dataReader[18].ToString());

                    //city = 19
                    u.Description.Smoking = EnumList <SmokingType> .FromString(dataReader[20].ToString());

                    u.Description.Drinking = EnumList <DrinkingType> .FromString(dataReader[21].ToString());

                    u.Preferences.Add(new Description(new Guid(dataReader[24].ToString())));
                    u.Preferences[0].TimeStamp = Tools.DTfromTS(Convert.ToDouble(dataReader[25]));
                    u.Preferences[0].Title     = dataReader[26].ToString();
                    u.Preferences[0].Age.Set(Convert.ToInt32(dataReader[27].ToString()), Convert.ToInt32(dataReader[28].ToString()));
                    u.Preferences[0].Gender = EnumList <GenderType> .FromString(dataReader[29].ToString());

                    u.Preferences[0].Sexuality = EnumList <SexualityType> .FromString(dataReader[30].ToString());

                    //country = 31
                    u.Preferences[0].Area = EnumList <AreaType> .FromString(dataReader[32].ToString());

                    //city = 33
                    u.Preferences[0].Smoking = EnumList <SmokingType> .FromString(dataReader[34].ToString());

                    u.Preferences[0].Drinking = EnumList <DrinkingType> .FromString(dataReader[35].ToString());

                    list.Add(u);
                }

                //close Data Reader
                dataReader.Close();

                //close Connection
                this.CloseConnection();

                //return list to be displayed
                return(list);
            }
            else
            {
                return(list);
            }
        }
Exemplo n.º 3
0
        private void btn_ok_Click(object sender, EventArgs e)
        {
            long now = Tools.DTtoTS(DateTime.Now);

            for (int i = 0; i < num_amount.Value; i++)
            {
                User user = new User();

                //user.UniqueID;
                user.Username  = GenerateUsername(user.UniqueID);
                user.Password  = "******";
                user.Email     = GenerateEmail(user.Username);
                user.FirstName = GenerateFirstname();
                user.LastName  = GenerateLastname();
                user.Birthday  = Tools.DTfromTS(now - (_rng.Next(18, 80) * _rng.Next(30758400, 31000000)));

                user.Location = new GeoLocation(Convert.ToSingle((_rng.NextDouble() * (double)(num_latmax.Value - num_latmin.Value)) + (double)num_latmin.Value),
                                                Convert.ToSingle((_rng.NextDouble() * (double)(num_lonmax.Value - num_lonmin.Value)) + (double)num_lonmin.Value));

                user.Description = new Description();
                //user.Description.UniqueID;
                user.Description.TimeStamp = DateTime.Now;
                user.Description.Title     = "Description";
                user.Description.SetAge(_rng.Next(18, 99));
                user.Description.Gender = EnumList <GenderType> .FromString(GenerateBinaryString(1, 5));

                user.Description.Sexuality = EnumList <SexualityType> .FromString(GenerateBinaryString(1, 4));

                user.Description.Area = EnumList <AreaType> .FromString(GenerateBinaryString(1, 5));

                user.Description.Smoking = EnumList <SmokingType> .FromString(GenerateBinaryString(1, 3));

                user.Description.Drinking = EnumList <DrinkingType> .FromString(GenerateBinaryString(1, 2));

                Description p = new Description();
                //user.Description.UniqueID;
                p.TimeStamp = DateTime.Now;
                p.Title     = "pref" + _rng.Next(1, 9999).ToString("0000");
                p.SetAge(_rng.Next(18, 99), _rng.Next(18, 99));
                p.Gender = EnumList <GenderType> .FromString(GenerateBinaryString(5, 5));

                p.Sexuality = EnumList <SexualityType> .FromString(GenerateBinaryString(4, 4));

                p.Area = EnumList <AreaType> .FromString(GenerateBinaryString(5, 5));

                p.Smoking = EnumList <SmokingType> .FromString(GenerateBinaryString(3, 3));

                p.Drinking = EnumList <DrinkingType> .FromString(GenerateBinaryString(2, 2));

                user.Preferences.Add(p);

                string result = _db.SaveUser(user);

                if (!result.Equals("E10"))
                {
                    MessageBox.Show("Couldn't save user at iteration (Errorcode: " + result + ") " + (i + 1), "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
            }

            Close();
        }
Exemplo n.º 4
0
        private static User UserFromStringV01(String s)
        {
            User u = null;

            try
            {
                String[] parts = s.Split("\\{".ToCharArray());
                String[] ss    = parts[0].Split("\\|".ToCharArray());

                u           = new User(new Guid(ss[0]));
                u.Email     = ss[1];
                u.Username  = ss[2];
                u.Password  = ss[3];
                u.FirstName = ss[4];
                u.LastName  = ss[5];
                u.Birthday  = Tools.DTfromTS(Convert.ToInt32(ss[6]));
                u.Location  = new GeoLocation(
                    Convert.ToSingle(ss[7]),
                    Convert.ToSingle(ss[8]),
                    Tools.DTfromTS(Convert.ToInt32(ss[9]))
                    );
                Description d = new Description(new Guid(ss[0]));
                d.TimeStamp = Tools.DTfromTS(Convert.ToSingle(ss[10]));
                d.Title     = ss[11];
                d.Age.Set(Convert.ToInt16(ss[12]), (Convert.ToInt16(ss[13])));
                d.Gender = EnumList <GenderType> .FromString(ss[14]);

                d.Sexuality = EnumList <SexualityType> .FromString(ss[15]);

                d.Area = EnumList <AreaType> .FromString(ss[16]);

                d.Smoking = EnumList <SmokingType> .FromString(ss[17]);

                d.Drinking = EnumList <DrinkingType> .FromString(ss[18]);

                u.Description = d;

                // Add preference descriptions if available
                if (parts.Length > 1)
                {
                    for (int i = 1; i < parts.Length; i++)
                    {
                        ss = parts[i].Split("\\|".ToCharArray());

                        Description p = new Description(new Guid(ss[0]));
                        p.TimeStamp = Tools.DTfromTS(Convert.ToSingle(ss[1]));
                        p.Title     = ss[2];
                        p.Age.Set(Convert.ToInt16(ss[3]), (Convert.ToInt16(ss[4])));
                        p.Gender = EnumList <GenderType> .FromString(ss[5]);

                        p.Sexuality = EnumList <SexualityType> .FromString(ss[6]);

                        p.Area = EnumList <AreaType> .FromString(ss[7]);

                        p.Smoking = EnumList <SmokingType> .FromString(ss[8]);

                        p.Drinking = EnumList <DrinkingType> .FromString(ss[9]);

                        u.Preferences.Add(p);
                    }
                }
            }
            catch (Exception e)
            {
                u = null;
            }

            return(u);
        }