📄 editaccount.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace MvmMoney
{
/// <summary>
/// Summary description for EditAccount.
/// </summary>
public class EditAccount : System.Windows.Forms.Form
{
private System.Windows.Forms.MainMenu mainMenu1;
private System.Windows.Forms.MenuItem menuItem_Save;
private System.Windows.Forms.MenuItem menuItem_Cancel;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.TextBox textBox_AcntName;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.TextBox textBox_Balance;
private string accountname;
public EditAccount(string AccountName)
{
this.accountname=AccountName;
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
this.SetInputMode(this.textBox_AcntName,InputMode.Text);
this.SetInputMode(this.textBox_Balance,InputMode.Numbers);
this.textBox_AcntName.Focus();
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
base.Dispose( disposing );
}
// Interop declarations
[DllImport("coredll.dll", EntryPoint="GetCapture")]
private static extern IntPtr GetCapture();
[DllImport("coredll.dll", EntryPoint="GetWindow")]
private static extern IntPtr GetWindow(IntPtr hWnd, int uCmd);
[DllImport("coredll.dll", EntryPoint="SendMessage")]
private static extern uint SendMessage(IntPtr hWnd, uint msg, uint wParam,
uint lParam);
// Constants required for interop
const int GW_CHILD = 5;
const uint EM_SETINPUTMODE = 0x00DE;
public void SetInputMode(Control ctrl, InputMode mode)
{
// Get the handle for the current control
ctrl.Capture = true;
IntPtr h = GetCapture();
ctrl.Capture = false;
// Get the child window for the control
IntPtr hEditbox = GetWindow(h, GW_CHILD);
// Set the input mode
SendMessage(hEditbox, EM_SETINPUTMODE, 0, (uint)mode);
}
// Input mode enumeration
public enum InputMode
{
Spell = 0,
T9 = 1,
Numbers = 2,
Text = 3
}
#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_Save = new System.Windows.Forms.MenuItem();
this.menuItem_Cancel = new System.Windows.Forms.MenuItem();
this.label1 = new System.Windows.Forms.Label();
this.textBox_AcntName = new System.Windows.Forms.TextBox();
this.label2 = new System.Windows.Forms.Label();
this.textBox_Balance = new System.Windows.Forms.TextBox();
//
// mainMenu1
//
this.mainMenu1.MenuItems.Add(this.menuItem_Save);
this.mainMenu1.MenuItems.Add(this.menuItem_Cancel);
//
// menuItem_Save
//
this.menuItem_Save.Text = "Save";
this.menuItem_Save.Click += new System.EventHandler(this.menuItem_Save_Click);
//
// menuItem_Cancel
//
this.menuItem_Cancel.Text = "Cancel";
this.menuItem_Cancel.Click += new System.EventHandler(this.menuItem_Cancel_Click);
//
// label1
//
this.label1.Location = new System.Drawing.Point(8, 8);
this.label1.Size = new System.Drawing.Size(152, 22);
this.label1.Text = "Account Name";
//
// textBox_AcntName
//
this.textBox_AcntName.Location = new System.Drawing.Point(8, 32);
this.textBox_AcntName.Size = new System.Drawing.Size(152, 25);
this.textBox_AcntName.Text = "";
//
// label2
//
this.label2.Location = new System.Drawing.Point(8, 64);
this.label2.Size = new System.Drawing.Size(152, 22);
this.label2.Text = "Current Balance";
//
// textBox_Balance
//
this.textBox_Balance.Location = new System.Drawing.Point(8, 88);
this.textBox_Balance.Size = new System.Drawing.Size(152, 25);
this.textBox_Balance.Text = "";
//
// EditAccount
//
this.Controls.Add(this.textBox_AcntName);
this.Controls.Add(this.textBox_Balance);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Menu = this.mainMenu1;
this.Text = "EditAccount";
this.Load += new System.EventHandler(this.EditAccount_Load);
}
#endregion
private void menuItem_Cancel_Click(object sender, System.EventArgs e)
{
this.Close();
}
private void menuItem_Save_Click(object sender, System.EventArgs e)
{
this.textBox_AcntName.Text=this.textBox_AcntName.Text.Trim();
if(this.textBox_AcntName.Text.Trim().Length==0)
{
MessageBox.Show("Please input account name.","Error",MessageBoxButtons.OK,MessageBoxIcon.Exclamation,MessageBoxDefaultButton.Button1);
return;
}
if( !this.textBox_AcntName.Text.Equals(this.accountname) && Form1.db.GetAccountId(this.textBox_AcntName.Text)!=-1)
{
MessageBox.Show("The account name \""+this.textBox_AcntName.Text+"\" existed. Input another one.","Error",MessageBoxButtons.OK,MessageBoxIcon.Hand,MessageBoxDefaultButton.Button1);
return;
}
try
{
double balance=System.Double.Parse(this.textBox_Balance.Text);
balance=(System.Math.Ceiling(balance*100))/100;
this.textBox_Balance.Text=""+balance;
}
catch(Exception)
{
MessageBox.Show("Invalid initial balance value.","Error",MessageBoxButtons.OK,MessageBoxIcon.Hand,MessageBoxDefaultButton.Button1);
return;
}
Form1.db.SetBalance(Form1.db.GetAccountId(this.accountname),System.Double.Parse(this.textBox_Balance.Text));
Form1.db.SetAccountName(this.accountname,this.textBox_AcntName.Text);
this.Close();
}
private void EditAccount_Load(object sender, System.EventArgs e)
{
this.Text=this.accountname;
this.textBox_AcntName.Text=this.accountname;
this.textBox_Balance.Text=""+Form1.db.GetBalance(Form1.db.GetAccountId(this.accountname));
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -