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

📄 添加用户.cs

📁 管理学院机房计费系统,VISUAL STUDIO .NET 2003 c# 语言实现,SQL SERVER 2000数据库. 现运行正常.
💻 CS
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;

namespace 机房计费系统
{
	/// <summary>
	/// Form2 的摘要说明。
	/// </summary>
	public class frmAddUser : System.Windows.Forms.Form
	{
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.TextBox textBox1;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.TextBox textBox2;
		private System.Windows.Forms.Label label3;
		private System.Windows.Forms.TextBox textBox3;
		private System.Windows.Forms.Button button1;
		private System.Data.SqlClient.SqlConnection sqlConnection1;
		private int numAff;
		private String sql;
		private System.Windows.Forms.Label label4;
		private System.Windows.Forms.TextBox textBox4;
		private System.Windows.Forms.Button button2;
		private System.Windows.Forms.Label label5;
		private System.Windows.Forms.CheckBox checkBox1;
		private System.Windows.Forms.Label label6;
		/// <summary>
		/// 必需的设计器变量。
		/// </summary>
		private System.ComponentModel.Container components = null;

		public frmAddUser()
		{
			//
			// 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.label1 = new System.Windows.Forms.Label();
			this.textBox1 = new System.Windows.Forms.TextBox();
			this.label2 = new System.Windows.Forms.Label();
			this.textBox2 = new System.Windows.Forms.TextBox();
			this.label3 = new System.Windows.Forms.Label();
			this.textBox3 = new System.Windows.Forms.TextBox();
			this.button1 = new System.Windows.Forms.Button();
			this.sqlConnection1 = new System.Data.SqlClient.SqlConnection();
			this.label4 = new System.Windows.Forms.Label();
			this.textBox4 = new System.Windows.Forms.TextBox();
			this.button2 = new System.Windows.Forms.Button();
			this.label5 = new System.Windows.Forms.Label();
			this.checkBox1 = new System.Windows.Forms.CheckBox();
			this.label6 = new System.Windows.Forms.Label();
			this.SuspendLayout();
			// 
			// label1
			// 
			this.label1.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.label1.Location = new System.Drawing.Point(56, 48);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(56, 23);
			this.label1.TabIndex = 0;
			this.label1.Text = "条形码";
			this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			this.label1.Click += new System.EventHandler(this.label1_Click);
			// 
			// textBox1
			// 
			this.textBox1.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.textBox1.Location = new System.Drawing.Point(136, 40);
			this.textBox1.Name = "textBox1";
			this.textBox1.Size = new System.Drawing.Size(264, 26);
			this.textBox1.TabIndex = 1;
			this.textBox1.Text = "";
			// 
			// label2
			// 
			this.label2.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.label2.Location = new System.Drawing.Point(56, 96);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(56, 24);
			this.label2.TabIndex = 2;
			this.label2.Text = "班级";
			this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// textBox2
			// 
			this.textBox2.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.textBox2.Location = new System.Drawing.Point(136, 88);
			this.textBox2.Name = "textBox2";
			this.textBox2.Size = new System.Drawing.Size(104, 26);
			this.textBox2.TabIndex = 2;
			this.textBox2.Text = "";
			this.textBox2.TextChanged += new System.EventHandler(this.textBox2_TextChanged);
			// 
			// label3
			// 
			this.label3.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.label3.Location = new System.Drawing.Point(56, 144);
			this.label3.Name = "label3";
			this.label3.Size = new System.Drawing.Size(56, 23);
			this.label3.TabIndex = 4;
			this.label3.Text = "姓名";
			this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// textBox3
			// 
			this.textBox3.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.textBox3.Location = new System.Drawing.Point(136, 136);
			this.textBox3.Name = "textBox3";
			this.textBox3.Size = new System.Drawing.Size(104, 26);
			this.textBox3.TabIndex = 3;
			this.textBox3.Text = "";
			// 
			// button1
			// 
			this.button1.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.button1.Location = new System.Drawing.Point(112, 232);
			this.button1.Name = "button1";
			this.button1.Size = new System.Drawing.Size(88, 24);
			this.button1.TabIndex = 6;
			this.button1.Text = "添加";
			this.button1.Click += new System.EventHandler(this.button1_Click);
			// 
			// sqlConnection1
			// 
			this.sqlConnection1.ConnectionString = "workstation id=XU;packet size=4096;integrated security=SSPI;data source=XU;persis" +
				"t security info=False;initial catalog=jifei";
			// 
			// label4
			// 
			this.label4.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.label4.Location = new System.Drawing.Point(56, 184);
			this.label4.Name = "label4";
			this.label4.Size = new System.Drawing.Size(56, 23);
			this.label4.TabIndex = 7;
			this.label4.Text = "缴费额";
			this.label4.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// textBox4
			// 
			this.textBox4.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.textBox4.Location = new System.Drawing.Point(136, 176);
			this.textBox4.Name = "textBox4";
			this.textBox4.Size = new System.Drawing.Size(104, 26);
			this.textBox4.TabIndex = 4;
			this.textBox4.Text = "";
			// 
			// button2
			// 
			this.button2.Location = new System.Drawing.Point(280, 232);
			this.button2.Name = "button2";
			this.button2.Size = new System.Drawing.Size(88, 23);
			this.button2.TabIndex = 9;
			this.button2.Text = "关闭";
			this.button2.Click += new System.EventHandler(this.button2_Click);
			// 
			// label5
			// 
			this.label5.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.label5.ImageAlign = System.Drawing.ContentAlignment.BottomLeft;
			this.label5.Location = new System.Drawing.Point(248, 184);
			this.label5.Name = "label5";
			this.label5.Size = new System.Drawing.Size(24, 23);
			this.label5.TabIndex = 10;
			this.label5.Text = "元";
			// 
			// checkBox1
			// 
			this.checkBox1.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.checkBox1.Location = new System.Drawing.Point(296, 176);
			this.checkBox1.Name = "checkBox1";
			this.checkBox1.Size = new System.Drawing.Size(112, 24);
			this.checkBox1.TabIndex = 11;
			this.checkBox1.Text = "研究生账户";
			this.checkBox1.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// label6
			// 
			this.label6.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.label6.Location = new System.Drawing.Point(264, 96);
			this.label6.Name = "label6";
			this.label6.Size = new System.Drawing.Size(168, 23);
			this.label6.TabIndex = 12;
			this.label6.Text = "(与借阅证班级一致)";
			// 
			// frmAddUser
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(480, 278);
			this.Controls.Add(this.label6);
			this.Controls.Add(this.checkBox1);
			this.Controls.Add(this.label5);
			this.Controls.Add(this.button2);
			this.Controls.Add(this.textBox4);
			this.Controls.Add(this.label4);
			this.Controls.Add(this.button1);
			this.Controls.Add(this.textBox3);
			this.Controls.Add(this.label3);
			this.Controls.Add(this.textBox2);
			this.Controls.Add(this.label2);
			this.Controls.Add(this.textBox1);
			this.Controls.Add(this.label1);
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Fixed3D;
			this.MaximizeBox = false;
			this.MinimizeBox = false;
			this.Name = "frmAddUser";
			this.ShowInTaskbar = false;
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.Text = "新建账户";
			this.Load += new System.EventHandler(this.frmAddUser_Load);
			this.ResumeLayout(false);

		}
		#endregion

		private void label1_Click(object sender, System.EventArgs e)
		{
		
		}

		private void textBox2_TextChanged(object sender, System.EventArgs e)
		{
		
		}

		private void button1_Click(object sender, System.EventArgs e)
		{
			//MessageBox.Show(IsMaster(this.textBox2.Text).ToString());
			string strMsg="";
			if(this.textBox1.TextLength==0)
			{
				MessageBox.Show("新用户添加失败,条码扫描出错!","新建账户",MessageBoxButtons.OK,MessageBoxIcon.Error);
				goto finish;
			}
			if(IsMaster(this.textBox2.Text) & !this.checkBox1.Checked)
			{
				MessageBox.Show("请检查是否正确输入研究生账户信息!","新建账户",MessageBoxButtons.OK,MessageBoxIcon.Error);	
				goto finish;
			}
			if(!IsMaster(this.textBox2.Text) & this.checkBox1.Checked)
			{
				MessageBox.Show("请检查是否正确输入研究生账户信息!","新建账户",MessageBoxButtons.OK,MessageBoxIcon.Error);	
				goto finish;
			}
			try
			{
				Decimal money=Decimal.Parse(this.textBox4.Text);
				float floMoney=(float)money;

				//添加优惠额
				
				sql="select * from 优惠表 order by 金额限 desc";
				SqlCommand cmdYh=new SqlCommand(sql,this.sqlConnection1);
				this.sqlConnection1.Open();
				SqlDataReader readerYh=cmdYh.ExecuteReader();
				readerYh.Read();
				float intYh1=float.Parse(readerYh.GetString(0));
				float intPower1=float.Parse(readerYh.GetString(1));
				readerYh.Read();
				float intYh2=float.Parse(readerYh.GetString(0));
				float intPower2=float.Parse(readerYh.GetString(1));
				readerYh.Close();
				this.sqlConnection1.Close();

				//计算优惠额 

				if(IsMaster(this.textBox2.Text) & this.checkBox1.Checked)
				{
					floMoney*=2;
					strMsg="研究生账户添加成功";
				}
				else
				{
					if(floMoney>=intYh1 && floMoney<intYh2)
					{
						floMoney*=(1+intPower1/100);
					}
					if(floMoney>=intYh2)
					{
						floMoney*=(1+intPower2/100);			
					}
					strMsg="新账户添加成功";
				}
				
				sql="insert 帐户表 values ('"+ this.textBox1.Text +"','"+ this.textBox2.Text +"','"+ this.textBox3.Text +"','"+ floMoney.ToString() +"','0','0')";
				SqlCommand cmd=new SqlCommand(this.sql,this.sqlConnection1);
				this.sqlConnection1.Open();
				try
				{
					numAff=cmd.ExecuteNonQuery();
					MessageBox.Show(strMsg+"!实际缴费"+ this.textBox4.Text +"元,充值"+ floMoney.ToString() +"元","新建账户",MessageBoxButtons.OK,MessageBoxIcon.Information);
				}

				catch(SqlException exe)
				{
					MessageBox.Show("新账户添加失败请检查输入!","新建账户",MessageBoxButtons.OK,MessageBoxIcon.Error);	
					goto finish;
				}

				finally
				{
					this.sqlConnection1.Close();
				}

				//写充值表
				DateTime dtNow=DateTime.Now;
				sql="insert into 收费流水表 (时间,条形码,值班教师,收费,充值) values('"+ dtNow.ToString() +"','"+ this.textBox1.Text +"','"+ frmMain.strTeacher +"','"+ this.textBox4.Text +"','"+ floMoney.ToString() +"')";
				SqlCommand cmdCzls=new SqlCommand(sql,this.sqlConnection1);
				try
				{
					this.sqlConnection1.Open();
					cmdCzls.ExecuteNonQuery();
				}
				catch(SqlException exe)
				{
					MessageBox.Show("写充值流水表出现错误!","新建账户",MessageBoxButtons.OK,MessageBoxIcon.Error);
				}
				finally
				{
					this.sqlConnection1.Close();
				}

				//

			}
			catch(FormatException exe)
			{
				MessageBox.Show("输入金额无效!","新建账户",MessageBoxButtons.OK,MessageBoxIcon.Error);
				this.textBox4.Text="";
			}
			finally
			{
			
			}
			finish:
				this.textBox1.Clear();
				this.textBox2.Clear();
				this.textBox3.Clear();
				this.textBox4.Clear();
				this.textBox1.Focus();
				this.textBox1.SelectAll();
				this.checkBox1.Checked=false;
		}


		private void button2_Click(object sender, System.EventArgs e)
		{
			//this.textBox1.Text="";
			//this.textBox1.Focus();
			//this.textBox1.SelectAll();
			//this.textBox2.Text="";
			//this.textBox3.Text="";
			//this.textBox4.Text="";
			this.Close();

		}

		private void frmAddUser_Load(object sender, System.EventArgs e)
		{
		
		}

		private bool IsMaster(string s)
		{
			if(s.IndexOf("研")==-1)
			{
				return false;
			}
			else
			{
				return true;
			}
		}
	}
}

⌨️ 快捷键说明

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