//新增用户信息 private void btnAdd_Click(object sender, EventArgs e) { //图书编号必须唯一 int rows = reader.dgvHeaderInfo.RowCount; lab.Text = ""; for (int i = 0; i < rows; i++) { string Columns1 = reader.dgvHeaderInfo.Rows[i].Cells[0].Value.ToString(); if (Columns1 == txtUserId.Text.Trim()) { lab.Text = "用户编号已存在!"; return; } } User r = new User(); r.UserId = txtUserId.Text.Trim(); r.UserName = txtUserName.Text.Trim(); r.TimeIn = dtTimeIn.Value; r.TimeOut = dtTimeOut.Value; r.UserTypeId = (int)cboReaderType.SelectedValue; r.DepartmentId = (int)cboDepartment.SelectedValue; r.ClassId = (int)cboClass.SelectedValue; r.IdentityCard = txtIdentityCard.Text.Trim(); r.Gender = txtGender.Text.Trim(); r.Phone = txtPhone.Text.Trim(); r.QQ = txtQQ.Text.Trim(); r.Email = txtEmail.Text.Trim(); r.Address = txtAddress.Text.Trim(); r.UserRemark = txtRemark.Text.Trim(); if (reader_bll.addUser(r) == 0) { MessageBox.Show("新增成功!"); //单击查询 刷新用户信息表 reader.btnSelect_Click(null, null); //自动找到刚刚添加成功的新行,并选中 com.AutoFindRow(txtUserId.Text.Trim(), reader.dgvHeaderInfo); } else { MessageBox.Show("新增失败!"); } }