//新增或者编辑保存 private void button1_Click(object sender, EventArgs e) { var model = new Record(); string[] columns = { "标题", "网址", "账户", "密码", "二级密码", "备注", "添加时间" }; var des = new DEScode(Session.password); string title = des.EncryptDES(textBox1.Text); string website = des.EncryptDES(textBox2.Text); string account = des.EncryptDES(textBox3.Text); string password = des.EncryptDES(textBox4.Text); string second_password = des.EncryptDES(textBox5.Text); string remark = des.EncryptDES(richTextBox1.Text); if (textBox1.Text.Trim().Length < 1 || textBox3.Text.Trim().Length < 1 || textBox4.Text.Trim().Length < 1) { MessageBox.Show("缺少必填参数", "错误提示"); } else { string[] values = { title, website, account, password, second_password, remark, DateTime.Now.ToString() }; if (this.id > 0) { model.update(this.id, columns, values); } else { model.add(columns, values); } parent.List_Load(sender, e); this.Close(); } }
public Detail(int id) { InitializeComponent(); this.StartPosition = FormStartPosition.CenterParent; var model = new Record(); DataRow dr = model.get(id); if (dr != null) { var des = new DEScode(Session.password); label7.Text = des.DecryptDES(dr["标题"].ToString()); label8.Text = des.DecryptDES(dr["网址"].ToString()); label9.Text = des.DecryptDES(dr["账户"].ToString()); label10.Text = des.DecryptDES(dr["密码"].ToString()); label11.Text = des.DecryptDES(dr["二级密码"].ToString()); label12.Text = des.DecryptDES(dr["备注"].ToString()); } }
//重新加密 public void rebuild(string old_password, string new_password) { DataRowCollection drc = this.select(); var old_des = new DEScode(old_password); var new_des = new DEScode(new_password); foreach (DataRow row in drc) { int id = int.Parse(row["ID"].ToString()); string title = new_des.EncryptDES(old_des.DecryptDES(row["标题"].ToString())); string website = new_des.EncryptDES(old_des.DecryptDES(row["网址"].ToString())); string account = new_des.EncryptDES(old_des.DecryptDES(row["账户"].ToString())); string password = new_des.EncryptDES(old_des.DecryptDES(row["密码"].ToString())); string second_password = new_des.EncryptDES(old_des.DecryptDES(row["二级密码"].ToString())); string remark = new_des.EncryptDES(old_des.DecryptDES(row["备注"].ToString())); string[] columns = { "标题", "网址", "账户", "密码", "二级密码", "备注" }; string[] values = { title, website, account, password, second_password, remark }; this.update(id, columns, values); } }
//页面加载 public void List_Load(object sender, EventArgs e) { //渲染listview listView1.GridLines = true; listView1.FullRowSelect = true; listView1.View = View.Details; listView1.HeaderStyle = ColumnHeaderStyle.Nonclickable; listView1.Columns.Clear(); listView1.Columns.Add("ID", 50, HorizontalAlignment.Left); listView1.Columns.Add("标题", 100, HorizontalAlignment.Left); listView1.Columns.Add("网址", 200, HorizontalAlignment.Left); listView1.Columns.Add("帐号", 120, HorizontalAlignment.Left); listView1.Columns.Add("remark", "备注"); listView1.Columns["remark"].Width = -2; var model = new Record(); var data = model.select(); var des = new DEScode(Session.password); listView1.Items.Clear(); foreach (DataRow row in data) { ListViewItem item = new ListViewItem(); item.SubItems.Clear(); item.SubItems[0].Text = row["ID"].ToString(); item.SubItems.Add(des.DecryptDES(row["标题"].ToString())); item.SubItems.Add(des.DecryptDES(row["网址"].ToString())); item.SubItems.Add(des.DecryptDES(row["账户"].ToString())); item.SubItems.Add(des.DecryptDES(row["备注"].ToString())); listView1.Items.Add(item); } //渲染状态栏 toolStripStatusLabel1.Text = "欢迎光临," + Session.account; }
//构造函数 public Add(List list, int id = 0) { InitializeComponent(); this.parent = list; this.id = id; if (this.id > 0) { var model = new Record(); DataRow dr = model.get(this.id); if (dr != null) { var des = new DEScode(Session.password); textBox1.Text = des.DecryptDES(dr["标题"].ToString()); textBox2.Text = des.DecryptDES(dr["网址"].ToString()); textBox3.Text = des.DecryptDES(dr["账户"].ToString()); textBox4.Text = des.DecryptDES(dr["密码"].ToString()); textBox5.Text = des.DecryptDES(dr["二级密码"].ToString()); richTextBox1.Text = des.DecryptDES(dr["备注"].ToString()); } } this.StartPosition = FormStartPosition.CenterParent; }