📄 frmprofileset.cs
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Model;
using BLL;
namespace MyQQ
{
public partial class frmProfileSet : Form
{
private bool _IsSelectedProfile = true;
private bool _HasUpdate = false;
/// <summary>
/// 标示是否已更新资料
/// </summary>
public bool HasUpdate
{
get { return _HasUpdate; }
set { _HasUpdate = value; }
}
public frmProfileSet()
{
InitializeComponent();
}
public UsersInfo ObjectEntity
{
get
{
UsersInfo obj = new UsersInfo();
obj.NickName = txtNickName.Text;
obj.Sex = cboSex.SelectedItem.ToString();
obj.Age = int.Parse(txtAge.Text);
obj.Name = txtName.Text;
obj.Star = new StarInfo(int.Parse(cboStar.SelectedValue.ToString()));
obj.BloodType = new BloodTypeInfo(int.Parse(cboBloodType.SelectedValue.ToString()));
obj.Id = AppSetter.CurrentUser.Id;
obj.FaceId = int.Parse(picMyHeader.Tag.ToString());
return obj;
}
set
{
txtId.Text = value.Id.ToString();
txtNickName.Text = value.NickName;
txtAge.Text = value.Age.ToString();
cboSex.SelectedItem = value.Sex;
txtName.Text = value.Name;
cboStar.SelectedValue = value.Star.Id;
cboBloodType.SelectedValue = value.BloodType.Id;
picMyHeader.Image = AppSetter.AllHeaders.Images[value.FaceId];
picMyHeader.Tag = value.FaceId;
if (value.FriendshipPolicy.Id == (int)EnumFriendshipPolicyType.AllowAnybody)
this.rdoAllowAnybody.Checked = true;
else if (value.FriendshipPolicy.Id == (int)EnumFriendshipPolicyType.NeedIdentity)
this.rdoNeedIdentity.Checked = true;
else if (value.FriendshipPolicy.Id == (int)EnumFriendshipPolicyType.RejectAnybody)
this.rdoNotAllow.Checked = true;
}
}
private void BindComboBox()
{
this.cboBloodType.DataSource = BloodType.SelectAll();
this.cboBloodType.DisplayMember = "BloodType";
this.cboBloodType.ValueMember = "Id";
this.cboStar.DataSource = Star.SelectAll();
this.cboStar.DisplayMember = "Star";
this.cboStar.ValueMember = "Id";
}
private void frmProfileSet_Load(object sender, EventArgs e)
{
BindComboBox();
this.ObjectEntity = Users.Select(AppSetter.CurrentUser.Id);
ShowProfilePanel(true);
}
private void btnlHeaders_Click(object sender, EventArgs e)
{
frmHeadersList frm = new frmHeadersList();
frm.IsInstant = false;//不及时保存头像
frm.ShowDialog();
this.picMyHeader.Image = AppSetter.AllHeaders.Images[frm.CurrentSelectedIndex];
picMyHeader.Tag = frm.CurrentSelectedIndex;
}
/// <summary>
/// 基本资料更新
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnOK_Click(object sender, EventArgs e)
{
try
{
if (_IsSelectedProfile)
{
CheckProfileInput();
Users.UpdateProfile(this.ObjectEntity);
_HasUpdate = true;
AppSetter.CurrentUser = this.ObjectEntity;
}
else
{
int idAllow = 1;
if (rdoAllowAnybody.Checked)
idAllow = 1;
else if (rdoNeedIdentity.Checked)
idAllow = 2;
else if (rdoNotAllow.Checked)
idAllow = 3;
if (string.IsNullOrEmpty(txtPassword.Text + txtPassword2.Text + txtPassword3.Text))
{
Users.ChangeIdentity(AppSetter.CurrentUser.Id, idAllow);
}
else
{
CheckSecurityInput();
Users.ChangeSecurity(AppSetter.CurrentUser.Id, txtPassword.Text, idAllow);
}
}
MessageBox.Show("您已成功更新资料!");
}
catch (Exception err)
{
MessageBox.Show(err.Message);
}
}
/// <summary>
///验证安全设置输入
/// </summary>
private void CheckSecurityInput()
{
if (string.IsNullOrEmpty(txtPassword2.Text))
throw new Exception("密码不能为空,请重新输入!");
if (txtPassword2.Text != txtPassword3.Text)
throw new Exception("您输入的密码不一致,请重新输入!");
}
/// <summary>
/// 验证个人资料输入
/// </summary>
private void CheckProfileInput()
{
if (string.IsNullOrEmpty(txtNickName.Text.Trim()))
throw new Exception("昵称不能为空,请重新输入!");
int iAge = 0;
if (string.IsNullOrEmpty(txtAge.Text))
throw new Exception("年龄不能为空,请重新输入!");
else
if (!int.TryParse(txtAge.Text, out iAge))
throw new Exception("年龄必须是数字!");
}
private void btnCancel_Click(object sender, EventArgs e)
{
this.Close();
}
private void btnProfile_Click(object sender, EventArgs e)
{
ShowProfilePanel(true);
}
/// <summary>
/// 交替显示编辑区
/// </summary>
/// <param name="isShow"></param>
private void ShowProfilePanel(bool isShow)
{
if (isShow)
{
_IsSelectedProfile = true;
panProfile.Show();
panSecurity.Hide();
btnProfile.ImageIndex = 0;
btnSecurity.ImageIndex = 3;
}
else
{
_IsSelectedProfile = false;
panProfile.Hide();
panSecurity.Show();
btnProfile.ImageIndex = 1;
btnSecurity.ImageIndex = 2;
}
}
private void ClearPassword()
{
txtPassword.Text = "";
txtPassword2.Text = "";
txtPassword3.Text = "";
}
private void btnSecurity_Click(object sender, EventArgs e)
{
ShowProfilePanel(false);
ClearPassword();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -