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

📄 充值.cs

📁 管理学院机房计费系统,VISUAL STUDIO .NET 2003 c# 语言实现,SQL SERVER 2000数据库. 现运行正常.
💻 CS
📖 第 1 页 / 共 2 页
字号:
						this.sqlConnection1.Open();
						cmdCzls.ExecuteNonQuery();
					}
					catch(SqlException exe)
					{
						MessageBox.Show("写充值流水表出现错误!","充值",MessageBoxButtons.OK,MessageBoxIcon.Error);
					}
					finally
					{
						this.sqlConnection1.Close();
					}

					//显示充值后的结果
					sql="select * from 帐户表 where 条形码='"+ this.textBox1.Text +"'";
					SqlCommand cmd1=new SqlCommand(sql,this.sqlConnection1);
					this.sqlConnection1.Open();
					SqlDataReader reader1=cmd1.ExecuteReader();
					try
					{
						
						if(reader1.Read())
						{
							this.textBox2.Text=reader1.GetString(2);
							this.textBox3.Text=reader1.GetString(1);
							this.balance=(Decimal)reader1.GetSqlDecimal(3);
							this.textBox4.Text=this.balance.ToString();
							MessageBox.Show("充值成功!实际缴费"+ this.textBox5.Text +"元,充值"+ floMoney.ToString() +"元","充值",MessageBoxButtons.OK,MessageBoxIcon.Information);
						}
						//else
						//{
						//	MessageBox.Show("出现错误,请管理员解决!","充值",MessageBoxButtons.OK,MessageBoxIcon.Error);
						//}
				
						
					}
					catch(SqlException exe)
					{
						MessageBox.Show("无此用户!","充值",MessageBoxButtons.OK,MessageBoxIcon.Error);
						this.textBox1.Text="";
						this.textBox2.Text="";
						this.textBox3.Text="";
						this.textBox4.Text="";
						this.textBox5.Text="";
					}
					finally
					{
						reader1.Close();
						this.sqlConnection1.Close();
						this.textBox5.Text="";
					}

				}
			}

			catch(FormatException exe)
			{
				MessageBox.Show("输入金额无效!","充值",MessageBoxButtons.OK,MessageBoxIcon.Error);
				this.textBox5.Text="";
			}
			finally
			{
				this.textBox1.Clear();
				this.textBox1.Focus();
				this.textBox1.SelectAll();
			}

			finish:;

		}

		private void button2_Click(object sender, System.EventArgs e)
		{
			this.textBox1.Focus();
			this.textBox1.SelectAll();
			
		}

		private void textBox1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
		{
			if(e.KeyChar == (char)13)
			{
				sql="select * from 帐户表 where 条形码='"+ this.textBox1.Text +"'";
				SqlCommand cmd=new SqlCommand(sql,this.sqlConnection1);
				this.sqlConnection1.Open();
				SqlDataReader reader=cmd.ExecuteReader();
				try
				{
			    
					if(reader.Read())
					{
						this.textBox2.Text=reader.GetString(2);
						this.textBox3.Text=reader.GetString(1);
						this.balance=(Decimal)reader.GetSqlDecimal(3);
						this.textBox4.Text=this.balance.ToString();
					}
					else
						MessageBox.Show("无此用户!","充值",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
				
				}
				catch(SqlException exe)
				{
					MessageBox.Show("出现错误!","充值",MessageBoxButtons.OK,MessageBoxIcon.Error);
					this.textBox1.Text="";
					this.textBox2.Text="";
					this.textBox3.Text="";
					this.textBox4.Text="";
					this.textBox5.Text="";
				}
				finally
				{
					reader.Close();
					this.sqlConnection1.Close();
				} 
			}
		}

		private void textBox1_Leave(object sender, System.EventArgs e)
		{
			sql="select * from 帐户表 where 条形码='"+ this.textBox1.Text +"'";
			SqlCommand cmd=new SqlCommand(sql,this.sqlConnection1);
			this.sqlConnection1.Open();
			SqlDataReader reader=cmd.ExecuteReader();
			try
			{
			    
				if(reader.Read())
				{
					this.textBox2.Text=reader.GetString(2);
					this.textBox3.Text=reader.GetString(1);
					this.balance=(Decimal)reader.GetSqlDecimal(3);
					this.textBox4.Text=this.balance.ToString();
				}
				else
				{
					MessageBox.Show("无此用户!","充值",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
					this.textBox1.Clear();
					this.textBox1.Focus();
				}
			}
			catch(SqlException exe)
			{
				MessageBox.Show("出现错误!","充值",MessageBoxButtons.OK,MessageBoxIcon.Error);
				this.textBox1.Text="";
				this.textBox2.Text="";
				this.textBox3.Text="";
				this.textBox4.Text="";
				this.textBox5.Text="";
			}
			finally
			{
				reader.Close();
				this.sqlConnection1.Close();
			} 
		
		}

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

		private void frmAddMoney_Closed(object sender, System.EventArgs e)
		{
			//frmMain.lbale=monDqcz();
		}
		private string monDqcz()//返回当前充值额
		{
			DateTime dtNow=DateTime.Now;
			string strDate=dtNow.Date.ToString();
			string strSql="select sum(收费) from 收费流水表 where 时间>'"+ strDate +"' and 值班教师='"+ frmMain.strTeacher +"'";
			SqlCommand cmdSf=new SqlCommand(strSql,this.sqlConnection1);
			this.sqlConnection1.Open();
			SqlDataReader sdaSf=cmdSf.ExecuteReader();
			try
			{
				if(sdaSf.Read())
				{
					return sdaSf.GetDecimal(0).ToString();
				}
				else 
				{
					return "0";
				}
			}
			
			catch(SqlException exe)
			{
				return "error";
			}
			catch(SqlNullValueException exe)
			{
				return "0";
			}
			finally
			{
				sdaSf.Close();
				this.sqlConnection1.Close();
			}
		}

		private void textBox5_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
		{
			if(e.KeyChar == (char)13)
			{
				try
				{
					Decimal money=Decimal.Parse(this.textBox5.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.textBox3.Text))
					{
						floMoney*=2;						
					}
					else
					{
						if(floMoney>=intYh1 && floMoney<intYh2)
						{
							floMoney*=(1+intPower1/100);
						}
						if(floMoney>=intYh2)
						{
							floMoney*=(1+intPower2/100);			
						}
					}
				
					//充值
					balance=balance+(Decimal)floMoney;
					sql="update 帐户表 set 余额='"+ this.balance.ToString() +"',锁定= '0' where 条形码='"+ this.textBox1.Text +"'";
					SqlCommand cmd=new SqlCommand(sql,this.sqlConnection1);
					this.sqlConnection1.Open();
					try
					{
						this.numAff=cmd.ExecuteNonQuery();
						if(numAff==0)
						{
							MessageBox.Show("充值失败,账户错!","充值",MessageBoxButtons.OK,MessageBoxIcon.Error);
							//MessageBox.Show("充值成功!","充值",MessageBoxButtons.OK,MessageBoxIcon.Information);
							goto finish;		
						}
					}
					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.textBox5.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();
						}

						//显示充值后的结果
						sql="select * from 帐户表 where 条形码='"+ this.textBox1.Text +"'";
						SqlCommand cmd1=new SqlCommand(sql,this.sqlConnection1);
						this.sqlConnection1.Open();
						SqlDataReader reader1=cmd1.ExecuteReader();
						try
						{
						
							if(reader1.Read())
							{
								this.textBox2.Text=reader1.GetString(2);
								this.textBox3.Text=reader1.GetString(1);
								this.balance=(Decimal)reader1.GetSqlDecimal(3);
								this.textBox4.Text=this.balance.ToString();
								MessageBox.Show("充值成功!实际缴费"+ this.textBox5.Text +"元,充值"+ floMoney.ToString() +"元","充值",MessageBoxButtons.OK,MessageBoxIcon.Information);
							}
							//else
							//{
							//	MessageBox.Show("出现错误,请管理员解决!","充值",MessageBoxButtons.OK,MessageBoxIcon.Error);
							//}
				
						
						}
						catch(SqlException exe)
						{
							MessageBox.Show("无此用户!","充值",MessageBoxButtons.OK,MessageBoxIcon.Error);
							this.textBox1.Text="";
							this.textBox2.Text="";
							this.textBox3.Text="";
							this.textBox4.Text="";
							this.textBox5.Text="";
						}
						finally
						{
							reader1.Close();
							this.sqlConnection1.Close();
							this.textBox5.Text="";
						}

					}
				}

				catch(FormatException exe)
				{
					MessageBox.Show("输入金额无效!","充值",MessageBoxButtons.OK,MessageBoxIcon.Error);
					this.textBox5.Text="";
				}
				finally
				{
					this.textBox1.Clear();
					this.textBox1.Focus();
					this.textBox1.SelectAll();
				}

			finish:;
			}
		}

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

⌨️ 快捷键说明

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