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

📄 bank.aspx.cs

📁 ASP.NET构建的笑傲江湖社区(C#,全源码提供)
💻 CS
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace xajh
{
	/// <summary>
	/// bank 的摘要说明。
	/// </summary>
	public class bank : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.TextBox upmoney;
		protected System.Web.UI.WebControls.TextBox oldmoney_c;
		protected System.Web.UI.WebControls.TextBox oldmoney_x;
		protected System.Web.UI.WebControls.Button byts_submit;
		protected System.Web.UI.WebControls.RadioButtonList bank_kind;
		protected System.Web.UI.WebControls.Literal byts_errormsg;
		protected x.UserInfo info;
	
		private void Page_Load(object sender, System.EventArgs e)
		{
			if (this.Session["info"] == null)
			{
				this.Server.Transfer ("error.aspx?v=relogin");
			}
			info = (x.UserInfo) this.Session["info"];
			if (!this.Page.IsPostBack)
			{
				OleDbConnection MyConn = new OleDbConnection(var.public_conn);
				MyConn.Open();
				OleDbCommand MyComm = new OleDbCommand("select [银两],[存款] from [注册用户] where [id]=" + info.DataID,MyConn);
				OleDbDataReader dr = MyComm.ExecuteReader();
				if (dr.Read())
				{
					this.oldmoney_c.Text = dr["存款"].ToString();
					this.oldmoney_x.Text = dr["银两"].ToString();
					dr.Close();
					MyConn.Close();
					MyConn.Dispose();
				}
				else
				{
					dr.Close();
					MyConn.Close();
					MyConn.Dispose();
					this.byts_errormsg.Text = "用户名未找到!";
					return;
				}
			}
		}

		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN:该调用是 ASP.NET Web 窗体设计器所必需的。
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{    
			this.byts_submit.Click += new System.EventHandler(this.byts_submit_Click);
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion

		private void byts_submit_Click(object sender, System.EventArgs e)
		{
			this.byts_errormsg.Text = "";
			string upvalue = this.upmoney.Text;
			upvalue = upvalue.Replace(" ","");
			if (upvalue == "")
			{
				this.byts_errormsg.Text = "必须填写操作数额!";
				return;
			}
			for (int i = 0; i < upvalue.Length; i ++)
			{
				if (char.IsNumber(upvalue, i) != true)
				{
					this.byts_errormsg.Text = "操作数额必须为数字!";
					return;
				}
			}
			int upv;
			try
			{
				upv = int.Parse(upvalue);
			}
			catch
			{
				this.byts_errormsg.Text = "输入数据溢出!(数据不允许超过21亿)";
				return;
			}
			if (upv <= 0)
			{
				this.byts_errormsg.Text = "操作数额不能等于或者小于 0 !";
				return;
			}
			OleDbConnection MyConn = new OleDbConnection(var.public_conn);
			MyConn.Open();
			OleDbCommand MyComm = new OleDbCommand(@"select [银两],[存款] from [注册用户] where [id]=" + info.DataID,MyConn);
			OleDbDataReader dr = MyComm.ExecuteReader();
			string sql = "update [注册用户] set ";
			if (dr.Read())
			{
				int m_x;
				int m_c;
				if (this.bank_kind.SelectedIndex == 0)
				{
					m_x = (int) dr["银两"] - upv;
					m_c = (int) dr["存款"] + upv;
				}
				else
				{
					m_x = (int) dr["银两"] + upv;
					m_c = (int) dr["存款"] - upv;
				}
				if (m_x < 0 || m_c < 0)
				{
					dr.Close();
					MyConn.Close();
					MyConn.Dispose();
					this.byts_errormsg.Text = "操作数额超过范围!";
					return;
				}
				this.oldmoney_x.Text = m_x.ToString();
				this.oldmoney_c.Text = m_c.ToString();
				this.upmoney.Text = "0";
				sql += "[银两]=" + m_x + ",[存款]=" + m_c + " where id=" + info.DataID;
				dr.Close();
				try
				{
					MyComm.CommandText = sql;
					MyComm.ExecuteNonQuery();
					MyConn.Close();
					MyConn.Dispose();
				}
				catch
				{
					MyConn.Close();
					MyConn.Dispose();
					this.byts_errormsg.Text = "数据库溢出!(数据库中不允许存在超过21亿的值)!";
				}
			}
			else
			{
				dr.Close();
				MyConn.Close();
				MyConn.Dispose();
				this.byts_errormsg.Text = "用户名未找到!";
			}
		}
	}
}

⌨️ 快捷键说明

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