/// <summary> /// 2.1 方式添加 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button1_Click(object sender, EventArgs e) { string strUserName = textBox1.Text.Trim(); string strPwd = textBox2.Text.Trim(); if (string.IsNullOrEmpty(strUserName) || string.IsNullOrEmpty(strPwd)) { MessageBox.Show("用户名和密码不可为空!"); return; } //1.调用用户的业务逻辑,实现用户信息添加 UserInfo _user = new UserInfo(); _user.userName = strUserName; _user.userPwd = strPwd; UserInfoManager usermanager = new UserInfoManager(); DataSet _Dt = usermanager.GetList(string.Format("userName='******'", strUserName)); if (_Dt.Tables != null && _Dt.Tables[0].Rows.Count > 0) { MessageBox.Show("同名称用户已存在,请输入其它用户名!"); return; } if (usermanager.Add(_user)) { _user.ID = usermanager.GetMaxId(); } else { MessageBox.Show("添加失败!"); } //2.添加成功将用户信息(需要获取此)添加到当前_RecordListView和RecordList列表中 if (RecordList == null) { RecordList = new List <UserInfo>(); } RecordList.Add(_user); _RecordListView.AddObject(_user);//刷新ListView 列表 }