📄 manageaccount.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using Bank;
namespace Client
{
public class Form2 : System.Windows.Forms.Form
{
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.TextBox textBox2;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.GroupBox groupBox2;
private System.Windows.Forms.RichTextBox richTextBox1;
private System.Windows.Forms.MainMenu mainMenu1;
private System.Windows.Forms.MenuItem menuItem1;
private System.Windows.Forms.MenuItem menuItem2;
private System.Windows.Forms.MenuItem menuItem3;
private System.Windows.Forms.MenuItem menuItem4;
private System.Windows.Forms.MenuItem menuItem5;
private System.Windows.Forms.MenuItem menuItem6;
private System.Windows.Forms.MenuItem menuItem7;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.TextBox textBox3;
private System.Windows.Forms.TextBox textBox4;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.Button button2;
private Bank.Bank bank;
private bool IsVerified=false;
private bool IsWithdraw=false;
private bool IsDeposit=false;
private bool IsTransfer=false;
private bool IsUpdatePwd=false;
private System.ComponentModel.Container components = null;
public Form2(string AccountNo)
{
InitializeComponent();
bank=new Bank.Bank();
textBox1.Text=AccountNo;
textBox1.ReadOnly=true;
init();
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
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.groupBox1 = new System.Windows.Forms.GroupBox();
this.button1 = new System.Windows.Forms.Button();
this.textBox2 = new System.Windows.Forms.TextBox();
this.label2 = new System.Windows.Forms.Label();
this.label1 = new System.Windows.Forms.Label();
this.textBox1 = new System.Windows.Forms.TextBox();
this.groupBox2 = new System.Windows.Forms.GroupBox();
this.button2 = new System.Windows.Forms.Button();
this.label4 = new System.Windows.Forms.Label();
this.textBox4 = new System.Windows.Forms.TextBox();
this.textBox3 = new System.Windows.Forms.TextBox();
this.label3 = new System.Windows.Forms.Label();
this.richTextBox1 = new System.Windows.Forms.RichTextBox();
this.mainMenu1 = new System.Windows.Forms.MainMenu();
this.menuItem1 = new System.Windows.Forms.MenuItem();
this.menuItem3 = new System.Windows.Forms.MenuItem();
this.menuItem4 = new System.Windows.Forms.MenuItem();
this.menuItem5 = new System.Windows.Forms.MenuItem();
this.menuItem6 = new System.Windows.Forms.MenuItem();
this.menuItem7 = new System.Windows.Forms.MenuItem();
this.menuItem2 = new System.Windows.Forms.MenuItem();
this.groupBox1.SuspendLayout();
this.groupBox2.SuspendLayout();
this.SuspendLayout();
//
// groupBox1
//
this.groupBox1.Controls.Add(this.button1);
this.groupBox1.Controls.Add(this.textBox2);
this.groupBox1.Controls.Add(this.label2);
this.groupBox1.Controls.Add(this.label1);
this.groupBox1.Controls.Add(this.textBox1);
this.groupBox1.Location = new System.Drawing.Point(8, 8);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(544, 96);
this.groupBox1.TabIndex = 0;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "帐号信息";
//
// button1
//
this.button1.Location = new System.Drawing.Point(440, 24);
this.button1.Name = "button1";
this.button1.TabIndex = 4;
this.button1.Text = "验证口令";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// textBox2
//
this.textBox2.Location = new System.Drawing.Point(160, 56);
this.textBox2.Name = "textBox2";
this.textBox2.PasswordChar = '*';
this.textBox2.Size = new System.Drawing.Size(208, 21);
this.textBox2.TabIndex = 3;
this.textBox2.Text = "";
//
// label2
//
this.label2.Location = new System.Drawing.Point(48, 56);
this.label2.Name = "label2";
this.label2.TabIndex = 2;
this.label2.Text = "口令:";
//
// label1
//
this.label1.Location = new System.Drawing.Point(48, 24);
this.label1.Name = "label1";
this.label1.TabIndex = 1;
this.label1.Text = "帐号:";
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(160, 24);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(208, 21);
this.textBox1.TabIndex = 0;
this.textBox1.Text = "";
//
// groupBox2
//
this.groupBox2.Controls.Add(this.button2);
this.groupBox2.Controls.Add(this.label4);
this.groupBox2.Controls.Add(this.textBox4);
this.groupBox2.Controls.Add(this.textBox3);
this.groupBox2.Controls.Add(this.label3);
this.groupBox2.Controls.Add(this.richTextBox1);
this.groupBox2.Location = new System.Drawing.Point(8, 112);
this.groupBox2.Name = "groupBox2";
this.groupBox2.Size = new System.Drawing.Size(544, 168);
this.groupBox2.TabIndex = 1;
this.groupBox2.TabStop = false;
this.groupBox2.Text = "操作信息";
//
// button2
//
this.button2.Location = new System.Drawing.Point(24, 112);
this.button2.Name = "button2";
this.button2.TabIndex = 5;
this.button2.Text = "确认";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// label4
//
this.label4.Location = new System.Drawing.Point(16, 72);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(112, 23);
this.label4.TabIndex = 4;
this.label4.Visible = false;
//
// textBox4
//
this.textBox4.Location = new System.Drawing.Point(144, 72);
this.textBox4.Name = "textBox4";
this.textBox4.Size = new System.Drawing.Size(136, 21);
this.textBox4.TabIndex = 3;
this.textBox4.Text = "";
this.textBox4.Visible = false;
//
// textBox3
//
this.textBox3.Location = new System.Drawing.Point(144, 24);
this.textBox3.Name = "textBox3";
this.textBox3.ReadOnly = true;
this.textBox3.Size = new System.Drawing.Size(136, 21);
this.textBox3.TabIndex = 2;
this.textBox3.Text = "";
//
// label3
//
this.label3.Location = new System.Drawing.Point(16, 24);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(112, 23);
this.label3.TabIndex = 1;
//
// richTextBox1
//
this.richTextBox1.Location = new System.Drawing.Point(328, 16);
this.richTextBox1.Name = "richTextBox1";
this.richTextBox1.Size = new System.Drawing.Size(208, 144);
this.richTextBox1.TabIndex = 0;
this.richTextBox1.Text = "";
//
// mainMenu1
//
this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem1,
this.menuItem2});
//
// menuItem1
//
this.menuItem1.Index = 0;
this.menuItem1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem3,
this.menuItem4,
this.menuItem5,
this.menuItem6,
this.menuItem7});
this.menuItem1.Text = "操作";
//
// menuItem3
//
this.menuItem3.Index = 0;
this.menuItem3.Text = "查询";
this.menuItem3.Click += new System.EventHandler(this.menuItem3_Click);
//
// menuItem4
//
this.menuItem4.Index = 1;
this.menuItem4.Text = "存款";
this.menuItem4.Click += new System.EventHandler(this.menuItem4_Click);
//
// menuItem5
//
this.menuItem5.Index = 2;
this.menuItem5.Text = "取款";
this.menuItem5.Click += new System.EventHandler(this.menuItem5_Click);
//
// menuItem6
//
this.menuItem6.Index = 3;
this.menuItem6.Text = "转帐";
this.menuItem6.Click += new System.EventHandler(this.menuItem6_Click);
//
// menuItem7
//
this.menuItem7.Index = 4;
this.menuItem7.Text = "修改口令";
this.menuItem7.Click += new System.EventHandler(this.menuItem7_Click);
//
// menuItem2
//
this.menuItem2.Index = 1;
this.menuItem2.Text = "退出";
this.menuItem2.Click += new System.EventHandler(this.menuItem2_Click);
//
// Form2
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(608, 301);
this.Controls.Add(this.groupBox2);
this.Controls.Add(this.groupBox1);
this.Menu = this.mainMenu1;
this.Name = "Form2";
this.Text = "帐号操作窗口";
this.groupBox1.ResumeLayout(false);
this.groupBox2.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
//初始化
private void init()
{
IsVerified=false;
IsWithdraw=false;
IsDeposit=false;
IsTransfer=false;
IsUpdatePwd=false;
}
//查询
private void menuItem3_Click(object sender, System.EventArgs e)
{
decimal balance;
string AccountNo=textBox1.Text;
balance=bank.QueryByAccountNo(AccountNo);
richTextBox1.AppendText("存款余额是"+balance+"\r\n");
}
//关闭窗口
private void menuItem2_Click(object sender, System.EventArgs e)
{
this.Close();
}
//存款
private void menuItem4_Click(object sender, System.EventArgs e)
{
label3.Text="请输入存款金额:";
textBox3.Text="";
textBox3.ReadOnly=false;
IsWithdraw=false;
IsDeposit=true;
IsTransfer=false;
IsUpdatePwd=false;
}
//取款
private void menuItem5_Click(object sender, System.EventArgs e)
{
if(IsVerified)
{
label3.Text="请输入取款金额:";
textBox3.Text="";
textBox3.ReadOnly=false;
IsWithdraw=true;
IsDeposit=false;
IsTransfer=false;
IsUpdatePwd=false;
}
else
{
richTextBox1.AppendText("请首先验证口令!\r\n");
}
}
//转帐
private void menuItem6_Click(object sender, System.EventArgs e)
{
if(IsVerified)
{
label3.Text="请输入帐号:";
label4.Text="请输入金额:";
label4.Visible=true;
textBox3.Text="";
textBox3.ReadOnly=false;
textBox4.Text="";
textBox4.Visible=true;
IsWithdraw=false;
IsDeposit=false;
IsTransfer=true;
IsUpdatePwd=false;
}
else
{
richTextBox1.AppendText("请首先验证口令!\r\n");
}
}
//修改口令
private void menuItem7_Click(object sender, System.EventArgs e)
{
if(IsVerified)
{
label3.Text="请输入口令:";
label4.Text="请确认口令:";
label4.Visible=true;
textBox3.Text="";
textBox3.ReadOnly=false;
textBox3.PasswordChar='*';
textBox4.Text="";
textBox4.PasswordChar='*';
textBox4.Visible=true;
IsWithdraw=false;
IsDeposit=false;
IsTransfer=false;
IsUpdatePwd=true;
}
else
{
richTextBox1.AppendText("请首先验证口令!\r\n");
}
}
//验证口令
private void button1_Click(object sender, System.EventArgs e)
{
string AccountNo=textBox1.Text;
string password=textBox2.Text;
if(bank.VerifyAccountNo(AccountNo,password))
{
IsVerified=true;
richTextBox1.AppendText("口令正确!\r\n");
}
else
{
IsVerified=false;
richTextBox1.AppendText("口令不正确!\r\n");
}
}
//确认输入
private void button2_Click(object sender, System.EventArgs e)
{
string AccountNo=textBox1.Text;
//取款
if(IsWithdraw)
{
decimal amount=decimal.Parse(textBox3.Text);
if(bank.WithdrawByAccountNo(AccountNo,amount))
{
richTextBox1.AppendText("取款成功,金额是:"+amount+"\r\n");
}
else
{
richTextBox1.AppendText("取款失败!\r\n");
}
IsWithdraw=false;
}
//存款
if(IsDeposit)
{
decimal amount=decimal.Parse(textBox3.Text);
if(bank.DepositByAccountNo(AccountNo,amount))
{
richTextBox1.AppendText("存款成功,金额是:"+amount+"\r\n");
}
else
{
richTextBox1.AppendText("存款失败!\r\n");
}
IsDeposit=false;
}
//转帐
if(IsTransfer)
{
string ToAccountNo=textBox3.Text;
decimal amount=decimal.Parse(textBox4.Text);
if(bank.TransferByAccountNo(AccountNo,ToAccountNo,amount))
{
richTextBox1.AppendText("转帐成功,帐号是:"+ToAccountNo+",\r\n");
richTextBox1.AppendText("金额是:"+amount+"\r\n");
}
else
{
richTextBox1.AppendText("转帐失败!\r\n");
}
IsDeposit=false;
}
//修改口令
if(IsUpdatePwd)
{
string pwd=textBox3.Text;
string ConfirmPwd=textBox4.Text;
if(pwd==ConfirmPwd)
{
if(bank.UpdateAccountPassword(AccountNo,pwd))
{
richTextBox1.AppendText("修改口令成功!\r\n");
}
else
{
richTextBox1.AppendText("修改口令失败!\r\n");
}
}
else
{
richTextBox1.AppendText("两次输入口令不一致!\r\n");
}
IsUpdatePwd=false;
textBox3.PasswordChar=char.Parse("\0");
textBox4.PasswordChar=char.Parse("\0");
}
textBox3.ReadOnly=true;
textBox3.Text="";
textBox4.Visible=false;
label4.Visible=false;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -