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

📄 frmserver.cs

📁 实现ATM模拟
💻 CS
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.IO;
using System.Threading;
using System.Net;
using System.Net.Sockets;
using server.业务层;

namespace Server
{
	/// <summary>
	/// Form1 的摘要说明。
	/// </summary>
	public class Form1 : System.Windows.Forms.Form
	{
		private System.ComponentModel.IContainer components;

		public Form1()
		{
			//
			// Windows 窗体设计器支持所必需的
			//
			InitializeComponent();

			//
			// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
			//
		}

		/// <summary>
		/// 清理所有正在使用的资源。
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if (components != null) 
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows 窗体设计器生成的代码
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{
			this.components = new System.ComponentModel.Container();
			this.lsb1 = new System.Windows.Forms.ListBox();
			this.lblCunSum = new System.Windows.Forms.Label();
			this.txtCunSum = new System.Windows.Forms.TextBox();
			this.txtQuSum = new System.Windows.Forms.TextBox();
			this.lblQuSum = new System.Windows.Forms.Label();
			this.timer1 = new System.Windows.Forms.Timer(this.components);
			this.SuspendLayout();
			// 
			// lsb1
			// 
			this.lsb1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
			this.lsb1.ItemHeight = 12;
			this.lsb1.Location = new System.Drawing.Point(0, 0);
			this.lsb1.Name = "lsb1";
			this.lsb1.Size = new System.Drawing.Size(320, 314);
			this.lsb1.TabIndex = 0;
			// 
			// lblCunSum
			// 
			this.lblCunSum.Location = new System.Drawing.Point(328, 8);
			this.lblCunSum.Name = "lblCunSum";
			this.lblCunSum.Size = new System.Drawing.Size(100, 16);
			this.lblCunSum.TabIndex = 1;
			this.lblCunSum.Text = "存款金额总计";
			// 
			// txtCunSum
			// 
			this.txtCunSum.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
			this.txtCunSum.Location = new System.Drawing.Point(328, 32);
			this.txtCunSum.Name = "txtCunSum";
			this.txtCunSum.ReadOnly = true;
			this.txtCunSum.Size = new System.Drawing.Size(128, 21);
			this.txtCunSum.TabIndex = 2;
			this.txtCunSum.Text = "";
			// 
			// txtQuSum
			// 
			this.txtQuSum.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
			this.txtQuSum.Location = new System.Drawing.Point(328, 104);
			this.txtQuSum.Name = "txtQuSum";
			this.txtQuSum.ReadOnly = true;
			this.txtQuSum.Size = new System.Drawing.Size(128, 21);
			this.txtQuSum.TabIndex = 3;
			this.txtQuSum.Text = "";
			// 
			// lblQuSum
			// 
			this.lblQuSum.Location = new System.Drawing.Point(328, 72);
			this.lblQuSum.Name = "lblQuSum";
			this.lblQuSum.Size = new System.Drawing.Size(100, 16);
			this.lblQuSum.TabIndex = 5;
			this.lblQuSum.Text = "取款金额总计";
			// 
			// timer1
			// 
			this.timer1.Enabled = true;
			this.timer1.Interval = 1000;
			this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
			// 
			// Form1
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(456, 317);
			this.Controls.Add(this.lblQuSum);
			this.Controls.Add(this.txtQuSum);
			this.Controls.Add(this.txtCunSum);
			this.Controls.Add(this.lblCunSum);
			this.Controls.Add(this.lsb1);
			this.Name = "Form1";
			this.Text = "银行交易服务器";
			this.Load += new System.EventHandler(this.Form1_Load);
			this.ResumeLayout(false);

		}
		#endregion

		/// <summary>
		/// 应用程序的主入口点。
		/// </summary>
		[STAThread]
		static void Main() 
		{
			Application.Run(new Form1());
		}

		private System.Windows.Forms.ListBox lsb1;
		private System.Windows.Forms.Label lblCunSum;
		private System.Windows.Forms.TextBox txtCunSum;
		private System.Windows.Forms.TextBox txtQuSum;
		private System.Windows.Forms.Label lblQuSum;
		private System.Windows.Forms.Timer timer1;

		Thread th;
		private void Form1_Load(object sender, System.EventArgs e)
		{
			th=new Thread(new ThreadStart(Listen));
			th.Start();
			this.timer1.Start();
		}
		public void xianshi()
		{
			this.txtCunSum.Text=ServerSystem.cunqian+"元";
			this.txtQuSum.Text=ServerSystem.quqian+"元";
		}
		public void Listen()
		{
			TcpListener lis=new TcpListener(9000);
			lis.Start();
			while(true)
			{
				Socket sock=lis.AcceptSocket();
				NetworkStream net=new NetworkStream(sock);
				StreamWriter sw=new StreamWriter(net);
				StreamReader sr=new StreamReader(net);
				string line=sr.ReadLine();
				string []order=line.Split('|');
				switch(order[0])
				{
					case "GETMONEY":
						sw.WriteLine(server.业务层.ServerSystem.GetMoney(order[1],int.Parse(order[2])));
						sw.Flush();
						this.lsb1.Items.Add(line);
						break;
					case "SETMONEY":
						sw.WriteLine(server.业务层.ServerSystem.SetMoney(order[1],double.Parse(order[2])));
						sw.Flush();
						this.lsb1.Items.Add(line);
						break;
					case "QUERYBALANCE":
						sw.WriteLine(server.业务层.ServerSystem.QueryBalance(order[1]));
						sw.Flush();
						this.lsb1.Items.Add(line);
						break;
					case "TRANSFER":
						sw.WriteLine(server.业务层.ServerSystem.TransferMoney(order[1],order[2],int.Parse(order[3])));
						sw.Flush();
						this.lsb1.Items.Add(line);					
						break;
					case "QUERYACCOUNTEXISTS":
						sw.WriteLine(server.业务层.ServerSystem.Denglu(order[1],order[2]));
						sw.Flush();
						this.lsb1.Items.Add(line);
						break;
				}
				sw.Flush();
				sw.Close();
				sr.Close();
				net.Close();
			}		
		}

		private void timer1_Tick(object sender, System.EventArgs e)
		{
			xianshi();
		}

//		public void SetupPassWord(string line)//设置密码
//		{
//			byte[] m=System.Text.Encoding.ASCII.GetBytes(line);
//			for(int i=0;i<m.Length;i++)
//			{
//				m+=5;
//			}
//			line=System.Text.Encoding.ASCII.GetBytes(m);
//		}
	}
}

⌨️ 快捷键说明

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