|
[code=csharp]using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace UserManageSystem
{
public partial class frmUserManage : Form
{
public frmUserManage()
{
InitializeComponent();
}
class UserInfo {
public UserInfo() {
}
public UserInfo(string uname, string fav, string Gender, string type) {
UserName = uname;
Favorite = fav;
this.Gender = Gender;
Type = type;
}
public string UserName { get; set; }
public string Favorite { get; set; }
public string Gender { get; set; }
public string Type { get; set; }
public override string ToString()
{
return UserName;
}
}
private void btnAdd_Click(object sender, EventArgs e)
{
//创建用户对象
UserInfo u = new UserInfo();
u.UserName = txtUserName.Text;
//爱好
string fav = "";
if (chkFavMusic.Checked) {
fav = fav + chkFavMusic.Text + "|";
}
if (chkFavArt.Checked) {
fav = fav + chkFavArt.Text;
if (fav.EndsWith("|")) fav = fav.Substring(0,fav.Length - 2);
u.Favorite = fav;
//性别
if (rdoMale.Checked)
{
u.Gender = "男";
}
else
{
u.Gender = "女";
}
u.Type = cmbType.Text;
listBoxUser.Items.Add(u);
}
}
private void btnDelete_Click(object sender, EventArgs e)
{
if (listBoxUser.SelectedIndex < 0) {
MessageBox.Show("请选择一个用户进行删除", "提示",
MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
//删除
listBoxUser.Items.Remove(listBoxUser.SelectedIndex);
}
private void listBoxUser_SelectedIndexChanged(object sender, EventArgs e)
{
UserInfo u = (UserInfo)listBoxUser.SelectedItem;
txtUserName.Text = u.UserName;
string[] favs = u.Favorite.Split('|');
chkFavMusic.Checked = false;
chkFavArt.Checked = false;
for (int i = 0; i < favs.Length; i++) {
if (favs == chkFavMusic.Text) chkFavMusic.Checked = true;
if (favs == chkFavArt.Text) chkFavArt.Checked = true;
}
//设置性别
rdoFemale.Checked = (u.Gender == "女");
rdoMale.Checked = (u.Gender == "男");
//设置类别
cmbType.SelectedIndex = cmbType.Items.IndexOf(u.Type);
}
private void btnModify_Click(object sender, EventArgs e)
{
UserInfo u = (UserInfo)listBoxUser.SelectedItem;
u.UserName = txtUserName.Text;
string fav = "";
if (chkFavMusic.Checked)
{
fav = fav + chkFavMusic.Text + "|";
}
if (chkFavArt.Checked)
{
fav = fav + chkFavArt.Text + "|";
}
if (fav.EndsWith("|")) fav = fav.Substring(0, fav.Length - 1);
u.Favorite = fav;
if (rdoMale.Checked)
{
u.Gender = "男";
}
else
{
u.Gender = "女";
}
u.Type = cmbType.Text;
}
}
}[/code]
求大神做这样的一个程序 具体图片参照文档http://www.worlduc.com/blog2012.aspx?bid=921543
|
|