/// <summary> /// 将 UserSex 枚举值转换为其对应的字符串表示。 /// </summary> /// <param name="value">UserSex 枚举值。</param> /// <returns>枚举值对应的字符串表示。</returns> /// <exception cref="ArgumentException"/> public static string ConvertToString(UserSex value) { switch (value) { case UserSex.Female: return(FemaleString); case UserSex.Male: return(MaleString); default: throw new ArgumentException("传入的 UserSex 枚举值非法。"); } }
/// <summary> /// 根据指定的用户性别从给定的数据源中查询用户信息实体对象。 /// </summary> /// <param name="source">数据源。</param> /// <param name="sex">用户性别。</param> /// <returns>一个可查询对象,包含了所有的满足条件的用户信息实体对象。</returns> /// <exception cref="ArgumentNullException"/> public static IQueryable <UserProfileEntity> QueryUserProfileEntitiesBySex( IQueryable <UserProfileEntity> source, UserSex sex) { if (source == null) { throw new ArgumentNullException(nameof(source)); } var entities = from item in source where item.Sex == sex select item; return(entities); }
/// <summary> /// 选择性别 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnSex_Press(object sender, EventArgs e) { popSex.Groups.Clear(); PopListGroup poli = new PopListGroup(); popSex.Groups.Add(poli); poli.Title = "性别选择"; UserSex UserSex = new UserSex(); DataTable table = UserSex.GetSex(); foreach (DataRow row in table.Rows) { poli.Items.Add(new PopListItem(row["SexName"].ToString(), row["SexID"].ToString())); if (((int)sex).Equals(row["SexID"])) { popSex.SetSelections(poli.Items[(poli.Items.Count - 1)]); } } popSex.ShowDialog(); }
public bool Create(string email, string password, string fullname, UserSex sex, string location, DateTime birthday) { //using (var db = new MeetUpDbContext()) //{ var mailExists = db.Users.Any(u => u.Email == email && u.Deleted == 0); if (mailExists) { return(false); } var salt = HelperFunctions.GetSalt(); var hashedPass = HelperFunctions.Get_HASH_SHA512(password, email, salt); var role = UserRole.User; if (this.Count() == 0) { role = UserRole.Admin; } var user = new User { Email = email, Password = hashedPass, Salt = salt, FullName = fullname, Role = role, CreateTime = DateTime.Now, LastOnline = DateTime.Now, Sex = sex, Location = location, Birthday = birthday }; db.Users.Add(user); db.SaveChanges(); return(true); //} }
public bool Create(string email, string password, string fullname, string description, DateTime?birthday = null, UserRole role = UserRole.User, UserSex sex = UserSex.Other) { using (var db = new MeetUpDbContext()) { var mailExists = db.Users.Any(u => u.Email == email); if (mailExists) { return(false); } var salt = HelperFunctions.Get_SALT(); var hashedPass = HelperFunctions.Get_HASH_SHA512(password, email, salt); var user = new User { Email = email, Password = hashedPass, Salt = salt, FullName = fullname, Description = description, Birthday = birthday, Sex = sex, Role = role, CreateTime = DateTime.Today, LastOnline = DateTime.Today }; db.Users.Add(user); db.SaveChanges(); return(true); } }
public User(string ID, string Name, string Underwrite, UserSex Sex, Bitmap Head, string Mobile, string Email) { //样式控制 base.AutoSize = false; base.Text = string.Empty; base.Anchor = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right; base.BackColor = Color.White; //屏闭系统绘制 this.SetStyle( ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.UserPaint, true); this.UpdateStyles(); this.DoubleBuffered = true; //初始化 this.userID = ID; this.userName = Name; this.Underwrite = "(" + Underwrite + ")"; this.sex = Sex; this.head = Head; this.mobile = Mobile; this.email = Email; this.state = OnlineState.Offline; this.ForeColor = Color.FromArgb(40, 40, 40); //头像跳动 this.headTimer = new System.Timers.Timer(); this.headTimer.Interval = 300; this.headTimer.Elapsed += delegate { if (this.headToRight) { this.headX += 2; if (this.headX == 6) { this.headToRight = false; } } else { this.headX -= 2; if (this.headX == 2) { this.headToRight = true; } } this.headY = this.headX == 4 ? 3 : 5; this.Invalidate(new Rectangle(0, 0, 34, 34)); }; this.Messages = new UserMessage(); this.Messages.CountChanged += delegate { if (this.Messages.Count == 0) { this.headTimer.Enabled = false; this.headX = this.headY = 4; this.Invalidate(new Rectangle(0, 0, 34, 34)); } else { this.headTimer.Enabled = true; } }; //提示 this.toolTip = new ToolTip(); this.toolTip.UseAnimation = true; this.toolTip.UseFading = true; this.toolTip.ShowAlways = true; //设置可用工具 this.toolList = new List <ToolSwitch>(); this.toolList.Add(ToolSwitch.IM_Chat); this.toolList.Add(ToolSwitch.IM_Speech); if (this.Mobile != null && this.Mobile.Trim().Length > 0) { this.toolList.Add(ToolSwitch.IM_Message); } if (this.Email != null && this.Email.Trim().Length > 0) { this.toolList.Add(ToolSwitch.IM_Email); } }
/// <summary> /// Initializes a new instance of the <see cref="T:System.Object"/> class. /// </summary> public User(DateTime? timestamp = null, string name = null, int? age = null, UserSex? sex = null) { if(timestamp.HasValue) Timestamp = timestamp.Value; Name = name; if(age.HasValue) Age = age.Value; if (sex.HasValue) Sex = sex.Value; }
private void Button_Click(object sender, RoutedEventArgs e) { var errorsWhileEdit = ""; if (Birthday.Text.Length == 0) { errorsWhileEdit = "Invalid Birthday \n"; } if ((EmailText.Text.Length == 0) || (!new EmailAddressAttribute().IsValid(EmailText.Text))) { errorsWhileEdit += "Invalid Email address \n"; } if (PasswordNameText.Password.Length <= 4) { errorsWhileEdit += "Invalid Password \n"; } if (ConfirmationPasswordNameText.Password.Length <= 4) { errorsWhileEdit += "Invalid Confirmation Password \n"; } if (FullNameText.Text.Length == 0) { errorsWhileEdit += "Invalid Full name \n"; } if (PasswordNameText.Password != ConfirmationPasswordNameText.Password) { errorsWhileEdit += "Password and confirmation password do not match. \n"; } if ((!Convert.ToBoolean(UserRoleRadioButton.IsChecked)) && (!Convert.ToBoolean(AdminRoleRadioButton.IsChecked))) { errorsWhileEdit += "Choose User Role \n"; } else { if (Convert.ToBoolean(UserRoleRadioButton.IsChecked)) { userRole = UserRole.User; } if (Convert.ToBoolean(AdminRoleRadioButton.IsChecked)) { userRole = UserRole.Admin; } } if ((!Convert.ToBoolean(MaleRadioButton.IsChecked)) && (!Convert.ToBoolean(FemaleRadioButton.IsChecked))) { errorsWhileEdit += "Choose User Sex \n"; } else { if (Convert.ToBoolean(MaleRadioButton.IsChecked)) { userSex = UserSex.Male; } if (Convert.ToBoolean(FemaleRadioButton.IsChecked)) { userSex = UserSex.Female; } } if (errorsWhileEdit != "") { MessageBox.Show("Please check the following fields: \n" + errorsWhileEdit); } else { userService = new UserService(); userService.Create(EmailText.Text, PasswordNameText.Password.ToString(), FullNameText.Text, DescriptionNameText.Text, DateTime.Parse(Birthday.Text), userRole, userSex); this.NavigationService.Navigate(new ListUsersPage()); } }
public List<User> Search(string query, UserSex sex, int year) { Transport transport = new Transport(); NameValueCollection data = new NameValueCollection(); data["q"] = query; data["count"] = "1000"; data["country"] = "2"; //Ukraine data["city"] = "650"; //Dnipropetrovsk data["sex"] = ((int)sex).ToString(); data["has_photo"] = "1"; data["fields"] = "sex"; if (year != 0) { data["birth_year"] = year.ToString(); } data["access_token"] = m_SessionInfo.AccessToken; string response = transport.MakePostRequest("users.search", data); int errorCode = Transport.GetErrorCode(response); if (errorCode != 0) { throw new Exception("Unexpected error"); } bool ignoreOverflow = year != 0; return ParseUsers(response, ignoreOverflow); }
public List<User> Search(string query, UserSex sex) { try { return Search(query, sex, 0); } catch (TooManyResultsException) { s_log.Warn("Too many results for query. try to split by years"); } List<User> result = new List<User>(); for (int year = 1940; year <= DateTime.Now.Year; ++year) { try { result.AddRange(Search(query, sex, year)); } catch (TooManyResultsException) { s_log.Warn("Too many results for query. Results will be truncated for year: " + year); } } return result; }