📄 transactionlistform.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace MvmMoney
{
/// <summary>
/// Summary description for TransactionListForm.
/// </summary>
public class TransactionListForm : System.Windows.Forms.Form, IMoneyDbChangeListener
{
private System.Windows.Forms.ListView listView1;
private System.Windows.Forms.ColumnHeader columnHeader1;
private System.Windows.Forms.ColumnHeader columnHeader2;
private System.Windows.Forms.MenuItem menuItem_Done;
private System.Windows.Forms.ColumnHeader columnHeader3;
private System.Windows.Forms.MenuItem menuItem_Delete;
private System.Windows.Forms.MainMenu mainMenu1;
public TransactionListForm()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
this.listView1.Font=new Font("Nina",10,System.Drawing.FontStyle.Regular);
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
base.Dispose( disposing );
Form1.db.RemoveChangeListener(this);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.mainMenu1 = new System.Windows.Forms.MainMenu();
this.menuItem_Done = new System.Windows.Forms.MenuItem();
this.menuItem_Delete = new System.Windows.Forms.MenuItem();
this.listView1 = new System.Windows.Forms.ListView();
this.columnHeader3 = new System.Windows.Forms.ColumnHeader();
this.columnHeader1 = new System.Windows.Forms.ColumnHeader();
this.columnHeader2 = new System.Windows.Forms.ColumnHeader();
//
// mainMenu1
//
this.mainMenu1.MenuItems.Add(this.menuItem_Done);
this.mainMenu1.MenuItems.Add(this.menuItem_Delete);
//
// menuItem_Done
//
this.menuItem_Done.Text = "Back";
this.menuItem_Done.Click += new System.EventHandler(this.menuItem_Done_Click);
//
// menuItem_Delete
//
this.menuItem_Delete.Text = "Delete";
this.menuItem_Delete.Click += new System.EventHandler(this.menuItem_Delete_Click);
//
// listView1
//
this.listView1.Columns.Add(this.columnHeader3);
this.listView1.Columns.Add(this.columnHeader1);
this.listView1.Columns.Add(this.columnHeader2);
this.listView1.FullRowSelect = true;
this.listView1.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.Nonclickable;
this.listView1.View = System.Windows.Forms.View.Details;
this.listView1.ItemActivate += new System.EventHandler(this.listView1_ItemActivate);
//
// columnHeader3
//
this.columnHeader3.Text = "ID";
this.columnHeader3.Width = 30;
//
// columnHeader1
//
this.columnHeader1.Text = "Date";
this.columnHeader1.Width = 75;
//
// columnHeader2
//
this.columnHeader2.Text = "Amount";
this.columnHeader2.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
this.columnHeader2.Width = 63;
//
// TransactionListForm
//
this.Controls.Add(this.listView1);
this.Menu = this.mainMenu1;
this.Load += new System.EventHandler(this.TransactionListForm_Load);
}
#endregion
private void TransactionListForm_Load(object sender, System.EventArgs e)
{
Form1.db.RegisterChangeListener(this);
}
private void menuItem_Done_Click(object sender, System.EventArgs e)
{
this.Close();
}
public void SetAccount(string AccountName)
{
this.Text=AccountName;
this.ShowTransactionData();
}
private void ShowTransactionData()
{
this.listView1.Items.Clear();
DataRow[] rows=Form1.db.GetTransactions(Form1.db.GetAccountId(this.Text));
foreach(DataRow row in rows)
{
System.Windows.Forms.ListViewItem item=new ListViewItem(new string[]{row["ID"].ToString(),System.DateTime.Parse(row["Date"].ToString()).ToShortDateString(),row["Amount"].ToString()});
this.listView1.Items.Insert(0,item);
}
}
public void OnAccountChanged()
{
this.Close();
}
public void OnBalanceChanged()
{
//do nothing.
}
public void OnTransactionChanged()
{
this.ShowTransactionData();
}
private void listView1_ItemActivate(object sender, System.EventArgs e)
{
if(this.listView1.SelectedIndices.Count>0)
{
int index=this.listView1.SelectedIndices[0];
int transID=System.Int32.Parse(this.listView1.Items[index].SubItems[0].Text);
DataRow row=Form1.db.GetTransactionInfo(transID);
string message="Transaction Infomation:\r\n\r\n";
message+="Account: "+this.Text+"\r\n";
message+="Date: "+System.DateTime.Parse(row["Date"].ToString()).ToShortDateString()+"\r\n";
message+="Type: "+row["Type"]+"\r\n";
message+="Amount: "+row["Amount"]+"\r\n";
message+="Note: "+row["Note"];
System.Windows.Forms.MessageBox.Show(message,"Transaction",System.Windows.Forms.MessageBoxButtons.OK,System.Windows.Forms.MessageBoxIcon.None,System.Windows.Forms.MessageBoxDefaultButton.Button1);
}
}
private void menuItem_Delete_Click(object sender, System.EventArgs e)
{
if(this.listView1.SelectedIndices.Count>0)
{
int index=this.listView1.SelectedIndices[0];
string message="Permanently delete this transaction? \r\n\r\nDate: "+this.listView1.Items[index].SubItems[1].Text+"\r\nAmount: "+this.listView1.Items[index].SubItems[2].Text;
System.Windows.Forms.DialogResult result=System.Windows.Forms.MessageBox.Show(message,"Deleting Transaction",System.Windows.Forms.MessageBoxButtons.OKCancel,System.Windows.Forms.MessageBoxIcon.Question,System.Windows.Forms.MessageBoxDefaultButton.Button1);
if(result==System.Windows.Forms.DialogResult.OK)
{
Form1.db.DeleteTransaction(System.Int32.Parse(this.listView1.Items[index].SubItems[0].Text));
}
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -