/// <summary> ///修改帐户信息 /// </summary> private void toolStripButton_Modify_Click(object sender, EventArgs e) { if (this.listView1.SelectedItems.Count == 0) { return; } FormAddAccount faa = new FormAddAccount(); //新对象窗口faa Account acc = new Account(); //新对象acc ListViewItem item = this.listView1.SelectedItems[0]; //定义item为当前选中的列表 faa.textBox_UserName.Text = item.SubItems[1].Text; faa.textBox_BankbookNum.Text = item.SubItems[2].Text; faa.textBox_cardNum.Text = item.SubItems[3].Text; faa.dateTimePicker_StartDate.Text = item.SubItems[4].Text; faa.textBox_BankName.Text = item.SubItems[5].Text; faa.textBox_MoneyType.Text = item.SubItems[6].Text; faa.textBox_AccountType.Text = item.SubItems[7].Text; faa.textBox_IniBalance.Text = item.SubItems[8].Text; faa.textBox_RemainBalance.Text = item.SubItems[9].Text; faa.textBox_Reamrk.Text = item.SubItems[10].Text; //获取所有信息(序号、户主...) if (faa.ShowDialog() == DialogResult.OK) { acc.IniBlance = double.Parse(faa.textBox_IniBalance.Text); acc.MoneyType = faa.textBox_MoneyType.Text; acc.OwnerName = faa.textBox_UserName.Text; acc.RemainBlance = double.Parse(faa.textBox_RemainBalance.Text); acc.Remark = faa.textBox_Reamrk.Text; acc.StartDate = faa.dateTimePicker_StartDate.Value; acc.AccountType = faa.textBox_AccountType.Text; acc.BankbookNum = faa.textBox_BankbookNum.Text; acc.BankName = faa.textBox_BankName.Text; acc.CardNum = faa.textBox_cardNum.Text; this.accountManager.AccoutList.Add(acc); //向列表中添加acc string[] its = new string[] { (this.listView1.SelectedIndices[0] + 1).ToString(), acc.OwnerName.ToString(), acc.BankbookNum.ToString(), acc.CardNum.ToString(), acc.StartDate.ToString(), acc.BankName.ToString(), acc.MoneyType.ToString(), acc.AccountType.ToString(), acc.IniBlance.ToString(), acc.RemainBlance.ToString(), acc.Remark.ToString() }; ListViewItem lvi = new ListViewItem(its); this.listView1.Items[this.listView1.SelectedIndices[0]] = lvi; //重新写入选中项的数据 } }
/// <summary> /// 添加帐户信息 /// </summary> private void toolStripSplitButton_Add_Click(object sender, EventArgs e) { FormAddAccount faa = new FormAddAccount(); Account acc = new Account(); if (faa.ShowDialog(this) == DialogResult.OK) //显示FormAddAccount窗口,判断返回结果为OK时进行的操作 { acc.IniBlance = double.Parse(faa.textBox_IniBalance.Text); //转化为double型 acc.MoneyType = faa.textBox_MoneyType.Text; acc.OwnerName = faa.textBox_UserName.Text; acc.RemainBlance = double.Parse(faa.textBox_RemainBalance.Text); //转化为double型 acc.Remark = faa.textBox_Reamrk.Text; acc.StartDate = faa.dateTimePicker_StartDate.Value; acc.AccountType = faa.textBox_AccountType.Text; acc.BankbookNum = faa.textBox_BankbookNum.Text; acc.BankName = faa.textBox_BankName.Text; acc.CardNum = faa.textBox_cardNum.Text; this.accountManager.AccoutList.Add(acc); string[] items = new string[] { (this.listView1.Items.Count + 1).ToString(), acc.OwnerName.ToString(), acc.BankbookNum.ToString(), acc.CardNum.ToString(), acc.StartDate.ToString(), acc.BankName.ToString(), acc.MoneyType.ToString(), acc.AccountType.ToString(), acc.IniBlance.ToString(), acc.RemainBlance.ToString(), acc.Remark.ToString() }; ListViewItem lvi = new ListViewItem(items); this.listView1.Items.Add(lvi); //将新的账户信息添加到列表中 } }