/// <summary> /// 删除按钮事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnDel_Click(object sender, EventArgs e) { if (MessageBox.Show(this, "您确定要删除选择的密码信息吗?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.No) return; UsersBLL bll = new UsersBLL(); Users userInfo = new Users(); try { for (int i = 0; i < dgvInfos.Rows.Count; i++) { if (dgvInfos.Rows[i].Cells["cb"].Value != null && dgvInfos.Rows[i].Cells["cb"].Value.ToString() == "1") { bll.Delete(Convert.ToInt32(dgvInfos.Rows[i].Cells["id"].Value)); } } } catch (Exception ex) { MessageBox.Show(ex.Message); } ClearInput(); Search(); }
/// <summary> /// 保存按钮事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnSave_Click(object sender, EventArgs e) { if (CheckData()) { UsersBLL ubll = new UsersBLL(); Users userInfo = new Users(); EncryptBLL ebll = new EncryptBLL(); try { userInfo.Key = txtKey.Text; userInfo.UName = txtName.Text; userInfo.Pw = ebll.GetEncryptStr(txtPw.Text); userInfo.Type = ebll.GetName(); if (txtID.Text == "") { ubll.Add(userInfo); } else { userInfo.ID = Convert.ToInt32(txtID.Text); ubll.Update(userInfo); } } catch (Exception ex) { MessageBox.Show(ex.Message); } ClearInput(); Search(); } }
/// <summary> /// 查询 /// </summary> private void Search() { dgvInfos.AutoGenerateColumns = false; UsersBLL bll = new UsersBLL(); List<Users> list = bll.GetList(); if (list != null) { dgvInfos.DataSource = list; } }
/// <summary> /// 列表双击事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void dgvInfos_CellDoubleClick(object sender, DataGridViewCellEventArgs e) { tabControl1.SelectedIndex = 1; UsersBLL ubll = new UsersBLL(); if (e.RowIndex < 0) return; txtKey.Text = dgvInfos.Rows[e.RowIndex].Cells["key"].Value.ToString(); txtName.Text = dgvInfos.Rows[e.RowIndex].Cells["name"].Value.ToString(); txtPw.Text = dgvInfos.Rows[e.RowIndex].Cells["pw"].Value.ToString(); txtID.Text = dgvInfos.Rows[e.RowIndex].Cells["id"].Value.ToString(); }