/// <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; UserInfoEntity userInfo = new UserInfoEntity(); UserInfoOperation oprUserinfo = new UserInfoOperation(); 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") { userInfo.ID = Convert.ToInt32(dgvInfos.Rows[i].Cells["id"].Value); oprUserinfo.Delete(userInfo); } } } 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) { UserInfoOperation oprUserinfo = new UserInfoOperation(); UserInfoEntity userInfo = new UserInfoEntity(); try { userInfo.Key = txtKey.Text; userInfo.Name = txtName.Text; userInfo.Pw = oprUserinfo.GetStr(selType.SelectedItem.ToString(), txtPw.Text, UserInfoOperation.CryptMode.Encrypt); userInfo.Type = selType.SelectedItem.ToString(); if (txtID.Text == "") { userInfo.ID = GetMaxID(); oprUserinfo.Insert(userInfo); } else { userInfo.ID = Convert.ToInt32(txtID.Text); oprUserinfo.Update(userInfo); } } catch (Exception ex) { MessageBox.Show(ex.Message); } ClearInput(); Search(); }
/// <summary> /// 加载窗体 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void FrmManage_Load(object sender, EventArgs e) { UserInfoOperation userInfo = new UserInfoOperation(); selType.DataSource = userInfo.GetTypeList(); selType.SelectedIndex = 0; Search(); }
/// <summary> /// 查询 /// </summary> private void Search() { while (dgvInfos.Rows.Count != 0) { dgvInfos.Rows.RemoveAt(0); } UserInfoOperation userInfo = new UserInfoOperation(); dgvInfos.AutoGenerateColumns = false; if (userInfo.GetInfos().Tables.Count > 0) dgvInfos.DataSource = userInfo.GetInfos().Tables[0]; }
/// <summary> /// 列表双击事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void dgvInfos_CellDoubleClick(object sender, DataGridViewCellEventArgs e) { tabControl1.SelectedIndex = 1; UserInfoOperation userInfo = new UserInfoOperation(); 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 = userInfo.GetStr(dgvInfos.Rows[e.RowIndex].Cells["type"].Value.ToString(), dgvInfos.Rows[e.RowIndex].Cells["pw"].Value.ToString(), UserInfoOperation.CryptMode.Decrypt); txtID.Text = dgvInfos.Rows[e.RowIndex].Cells["id"].Value.ToString(); selType.SelectedItem = dgvInfos.Rows[e.RowIndex].Cells["type"].Value.ToString(); }