⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 transferform.cs

📁 国人开发的电子钱包
💻 CS
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Runtime.InteropServices;

namespace MvmMoney
{
	/// <summary>
	/// Summary description for TransferForm.
	/// </summary>
	public class TransferForm : System.Windows.Forms.Form
	{
		private System.Windows.Forms.MainMenu mainMenu1;
		private System.Windows.Forms.MenuItem menuItem_Done;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.ComboBox comboBox_From;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.ComboBox comboBox_To;
		private System.Windows.Forms.Label label3;
		private System.Windows.Forms.TextBox textBox_Amount;
		private System.Windows.Forms.MenuItem menuItem_Cancel;
	
		public TransferForm()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			//
			// TODO: Add any constructor code after InitializeComponent call
			//
			DataTable accounts=Form1.db.GetAccounts();
			foreach(DataRow row in accounts.Rows)
			{
				this.comboBox_From.Items.Add(row["Name"]);
				this.comboBox_To.Items.Add(row["Name"]);
			}

			this.SetInputMode(this.textBox_Amount,InputMode.Numbers);
			this.comboBox_From.Focus();
			this.comboBox_From.SelectedIndex=0;
			this.comboBox_To.SelectedIndex=1;
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			base.Dispose( disposing );
		}

		#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_Cancel = new System.Windows.Forms.MenuItem();
			this.label1 = new System.Windows.Forms.Label();
			this.comboBox_From = new System.Windows.Forms.ComboBox();
			this.label2 = new System.Windows.Forms.Label();
			this.comboBox_To = new System.Windows.Forms.ComboBox();
			this.label3 = new System.Windows.Forms.Label();
			this.textBox_Amount = new System.Windows.Forms.TextBox();
			// 
			// mainMenu1
			// 
			this.mainMenu1.MenuItems.Add(this.menuItem_Done);
			this.mainMenu1.MenuItems.Add(this.menuItem_Cancel);
			// 
			// menuItem_Done
			// 
			this.menuItem_Done.Text = "Done";
			this.menuItem_Done.Click += new System.EventHandler(this.menuItem_Done_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 = "From:";
			// 
			// comboBox_From
			// 
			this.comboBox_From.Location = new System.Drawing.Point(8, 32);
			this.comboBox_From.Size = new System.Drawing.Size(152, 26);
			// 
			// label2
			// 
			this.label2.Location = new System.Drawing.Point(8, 64);
			this.label2.Size = new System.Drawing.Size(152, 22);
			this.label2.Text = "To:";
			// 
			// comboBox_To
			// 
			this.comboBox_To.Location = new System.Drawing.Point(8, 88);
			this.comboBox_To.Size = new System.Drawing.Size(152, 26);
			// 
			// label3
			// 
			this.label3.Location = new System.Drawing.Point(8, 120);
			this.label3.Size = new System.Drawing.Size(152, 22);
			this.label3.Text = "Amount";
			// 
			// textBox_Amount
			// 
			this.textBox_Amount.Location = new System.Drawing.Point(8, 144);
			this.textBox_Amount.Size = new System.Drawing.Size(152, 25);
			this.textBox_Amount.Text = "0.0";
			this.textBox_Amount.LostFocus += new System.EventHandler(this.textBox_Amount_LostFocus);
			// 
			// TransferForm
			// 
			this.Controls.Add(this.comboBox_From);
			this.Controls.Add(this.label1);
			this.Controls.Add(this.comboBox_To);
			this.Controls.Add(this.label2);
			this.Controls.Add(this.textBox_Amount);
			this.Controls.Add(this.label3);
			this.Menu = this.mainMenu1;
			this.Text = "Transfer Money";

		}
		#endregion

		// 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
		}

		private void menuItem_Cancel_Click(object sender, System.EventArgs e)
		{
			this.Close();
		}

		private void menuItem_Done_Click(object sender, System.EventArgs e)
		{
			double amount;
			try
			{
				amount=System.Double.Parse(this.textBox_Amount.Text);
				amount=(System.Math.Ceiling(amount*100))/100;
				this.textBox_Amount.Text=amount+"";

				if(amount==0)
				{
					MessageBox.Show("Amount should not be zero.","Error",MessageBoxButtons.OK,MessageBoxIcon.Hand,MessageBoxDefaultButton.Button1);
					return;
				}
			}
			catch(Exception)
			{
				MessageBox.Show("Invalid amount.","Error",MessageBoxButtons.OK,MessageBoxIcon.Hand,MessageBoxDefaultButton.Button1);
				return;
			}

			int from=Form1.db.GetAccountId(this.comboBox_From.SelectedItem.ToString());
			int to=Form1.db.GetAccountId(this.comboBox_To.SelectedItem.ToString());

			if(from==to)
			{
				System.Windows.Forms.MessageBox.Show("Please don't transfer money to the account itself.","Error",System.Windows.Forms.MessageBoxButtons.OK,System.Windows.Forms.MessageBoxIcon.Hand,System.Windows.Forms.MessageBoxDefaultButton.Button1);
			}
			else
			{
				Form1.db.Transfer(from,to,amount);
				this.Close();
			}
		}

		public void SetDefaultAccount(string accountName)
		{
			this.comboBox_From.SelectedIndex=this.comboBox_From.Items.IndexOf(accountName);
		}

		private void textBox_Amount_LostFocus(object sender, System.EventArgs e)
		{
			double amount;
			try
			{
				amount=System.Double.Parse(this.textBox_Amount.Text);
				amount=(System.Math.Ceiling(amount*100))/100;
				this.textBox_Amount.Text=amount+"";
			}
			catch(Exception)
			{
				return;
			}		
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -