コード例 #1
0
ファイル: RandomForm.cs プロジェクト: tydaikho/stalkr
        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();
        }
コード例 #2
0
ファイル: Tools.cs プロジェクト: tydaikho/stalkr
        public static String UserToStringV01(User u, bool full)
        {
            StringBuilder sb = new StringBuilder();

            try
            {
                GeoLocation l = u.Location;
                Description d = u.Description;

                sb.Append(u.UniqueID)										.Append("|");
                sb.Append(u.Email)											.Append("|");
                sb.Append(u.Username)										.Append("|");
                sb.Append(u.Password)										.Append("|");
                sb.Append(u.FirstName)										.Append("|");
                sb.Append(u.LastName)										.Append("|");
                sb.Append(Convert.ToInt32(Tools.DTtoTS(u.Birthday)))		.Append("|");
                sb.Append(Convert.ToSingle(l.Latitude))						.Append("|");
                sb.Append(Convert.ToSingle(l.Longitude))					.Append("|");
                sb.Append(Convert.ToInt32(Tools.DTtoTS(l.TimeStamp)))		.Append("|");
                sb.Append(Convert.ToInt32(Tools.DTtoTS(d.TimeStamp)))		.Append("|");
                sb.Append(d.Title)											.Append("|");
                sb.Append(Convert.ToInt16(d.Age.Min))						.Append("|");
                sb.Append(Convert.ToInt16(d.Age.Max))						.Append("|");
                sb.Append(d.Gender.ToString())								.Append("|");
                sb.Append(d.Sexuality.ToString())							.Append("|");
                sb.Append(d.Area.ToString())								.Append("|");
                sb.Append(d.Smoking.ToString())								.Append("|");
                sb.Append(d.Drinking.ToString());
                foreach (Description p in u.Preferences)
                {
                    sb.Append("{");
                    sb.Append(p.UniqueID.ToString())						.Append("|");
                    sb.Append(Convert.ToInt32(Tools.DTtoTS(p.TimeStamp)))	.Append("|");
                    sb.Append(p.Title)										.Append("|");
                    sb.Append(Convert.ToInt16(p.Age.Min))					.Append("|");
                    sb.Append(Convert.ToInt16(p.Age.Max))					.Append("|");
                    sb.Append(p.Gender.ToString())							.Append("|");
                    sb.Append(p.Sexuality.ToString())						.Append("|");
                    sb.Append(p.Area.ToString())							.Append("|");
                    sb.Append(p.Smoking.ToString())							.Append("|");
                    sb.Append(p.Drinking.ToString());
                }
            }
            catch (Exception e)
            {
                sb = new StringBuilder();
            }

            return sb.ToString();
        }
コード例 #3
0
ファイル: UserForm.cs プロジェクト: tydaikho/stalkr
        // Contructor
        public UserForm(User user)
        {
            InitializeComponent();

            _db = WSconnect.Instance;
            DateTime now = DateTime.Now;
            date_birth.MinDate = new DateTime(now.Year - 99, now.Month, now.Day);
            date_birth.MaxDate = new DateTime(now.Year - 18, now.Month, now.Day);

            if (user == null) { _user = new User(); }
            else { _user = user; }

            txt_guid.Text = _user.UniqueID.ToString().ToUpper();
            txt_email.Text = _user.Email;
            txt_user.Text = _user.Username;
            txt_pass.Text = _user.Password;
            txt_firstname.Text = _user.FirstName;
            txt_lastname.Text = _user.LastName;
            if (_user.Birthday > date_birth.MaxDate || _user.Birthday < date_birth.MinDate)
            {
                date_birth.Value = date_birth.MaxDate;
            }
            else
            {
                date_birth.Value = _user.Birthday;
            }

            if (_user.Location != null)
            {
                num_lat.Value = Convert.ToDecimal(_user.Location.Latitude);
                num_lon.Value = Convert.ToDecimal(_user.Location.Longitude);
                date_location.Value = _user.Location.TimeStamp;
            }

            if (_user.Description != null)
            {
                txt_description.Text = "Description object";
                btn_desc_add.Enabled = false;
                btn_desc_del.Enabled = false;
                btn_desc_edit.Enabled = true;
            }
            else
            {
                btn_desc_add.Enabled = true;
                btn_desc_del.Enabled = false;
                btn_desc_edit.Enabled = false;
            }
        }
コード例 #4
0
ファイル: Tools.cs プロジェクト: tydaikho/stalkr
 /// <summary>
 /// Converts a User object into a string
 /// </summary>
 /// <param name="u">User object to convert</param>
 /// <returns></returns>
 public static String UserToString(User u, bool full)
 {
     String result = UserToStringV02(u, full);
     System.Console.Out.WriteLine(result);
     return result;
 }
コード例 #5
0
ファイル: Tools.cs プロジェクト: tydaikho/stalkr
        private static String UserToStringV02(User u, bool full)
        {
            StringBuilder sb = new StringBuilder();

            try
            {
                GeoLocation l = u.Location;
                Description d = u.Description;

                // User
                sb.Append(u.UniqueID);																sb.Append("|");
                if (full || u.IsChanged("email"))		{ sb.Append(u.Email); }						sb.Append("|");
                if (full || u.IsChanged("username"))	{ sb.Append(u.Username); }					sb.Append("|");
                if (full || u.IsChanged("password"))	{ sb.Append(u.Password); }					sb.Append("|");
                if (full || u.IsChanged("firstname"))	{ sb.Append(u.FirstName); }					sb.Append("|");
                if (full || u.IsChanged("lastname"))	{ sb.Append(u.LastName); }					sb.Append("|");
                if (full || u.IsChanged("birthday"))
                    { sb.Append(Tools.DTtoTS(u.Birthday)).ToString(); }								sb.Append("|");
                if (full || u.IsChanged("location")) {
                    sb.Append(l.Latitude.ToString(LOCFORM))											  .Append("|");
                    sb.Append(l.Longitude.ToString(LOCFORM))										  .Append("|");
                    sb.Append(Tools.DTtoTS(l.TimeStamp).ToString())									  .Append("|");
                } else { sb.Append("|||"); }

                // Description
                if (full || d.IsChanged("timestamp"))
                    { sb.Append(Tools.DTtoTS(d.TimeStamp).ToString()); }							sb.Append("|");
                if (full || d.IsChanged("title"))		{ sb.Append(d.Title); }						sb.Append("|");
                if (full || d.IsChanged("age")) {
                    sb.Append(d.Age.Min.ToString())													  .Append("|");
                    sb.Append(d.Age.Max.ToString())													  .Append("|");
                } else { sb.Append("||"); }
                if (full || d.IsChanged("gender"))		{ sb.Append(d.Gender.ToString()); }			sb.Append("|");
                if (full || d.IsChanged("sexuality"))	{ sb.Append(d.Sexuality.ToString()); }		sb.Append("|");
                if (full || d.IsChanged("area"))		{ sb.Append(d.Area.ToString()); }			sb.Append("|");
                if (full || d.IsChanged("smoking"))		{ sb.Append(d.Smoking.ToString()); }		sb.Append("|");
                if (full || d.IsChanged("drinking"))	{ sb.Append(d.Drinking.ToString()); }

                // Preferences
                foreach (Description p in u.Preferences)
                {
                    sb.Append("{");
                    sb.Append(p.UniqueID.ToString())												  .Append("|");
                    if (full || p.IsChanged("timestamp"))
                    { sb.Append(Tools.DTtoTS(p.TimeStamp).ToString()); }							sb.Append("|");
                    if (full || p.IsChanged("title"))		{ sb.Append(p.Title); }					sb.Append("|");
                    if (full || p.IsChanged("age"))
                    {
                        sb.Append(p.Age.Min.ToString())												  .Append("|");
                        sb.Append(p.Age.Max.ToString())												  .Append("|");
                    }
                    else { sb.Append("||"); }
                    if (full || p.IsChanged("gender"))		{ sb.Append(p.Gender.ToString()); }		sb.Append("|");
                    if (full || p.IsChanged("sexuality"))	{ sb.Append(p.Sexuality.ToString()); }	sb.Append("|");
                    if (full || p.IsChanged("area"))		{ sb.Append(p.Area.ToString()); }		sb.Append("|");
                    if (full || p.IsChanged("smoking"))		{ sb.Append(p.Smoking.ToString()); }	sb.Append("|");
                    if (full || p.IsChanged("drinking"))	{ sb.Append(p.Drinking.ToString()); }
                }
            }
            catch (Exception e)
            {
                sb = new StringBuilder();
            }

            return sb.ToString();
        }
コード例 #6
0
ファイル: Tools.cs プロジェクト: tydaikho/stalkr
        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;
        }
コード例 #7
0
ファイル: MainForm.cs プロジェクト: tydaikho/stalkr
        // Self-explanatory...
        private void StartEditUserForm(User user)
        {
            // Open the "Edit User" form with the corresponding user object in the list
            UserForm userform = new UserForm(user);

            DialogResult dr = userform.ShowDialog();

            if (dr == DialogResult.OK)
            {
                status_label.Text = USEROK;
            }
            else
            {
                status_label.Text = USERCANCEL;
            }

            LoadUsers(false);
        }
コード例 #8
0
ファイル: WSconnect.cs プロジェクト: tydaikho/stalkr
 public string SaveUser(User user)
 {
     string result = "";
     if (_permission[3] == '1' && _permission[4] == '1')
     {
         result = _ws.adminSaveUser(_username, _password, Tools.UserToString(user, false));
     }
     return result;
 }
コード例 #9
0
ファイル: DBconnect.cs プロジェクト: tydaikho/stalkr
        // 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;
            }
        }