?? 充值.cs
字號:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;
using System.Text;
using System.Data.SqlTypes;
namespace 機(jī)房計費(fèi)系統(tǒng)
{
/// <summary>
/// Form1 的摘要說明。
/// </summary>
public class frmAddMoney : 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.Label label4;
private System.Windows.Forms.TextBox textBox4;
private System.Windows.Forms.Button button1;
private System.Data.SqlClient.SqlConnection sqlConnection1;
private String sql;
private int numAff;
private Decimal balance;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.TextBox textBox5;
private System.Windows.Forms.Label label6;
/// <summary>
/// 必需的設(shè)計器變量。
/// </summary>
private System.ComponentModel.Container components = null;
public frmAddMoney()
{
//
// Windows 窗體設(shè)計器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 調(diào)用后添加任何構(gòu)造函數(shù)代碼
//
}
/// <summary>
/// 清理所有正在使用的資源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows 窗體設(shè)計器生成的代碼
/// <summary>
/// 設(shè)計器支持所需的方法 - 不要使用代碼編輯器修改
/// 此方法的內(nèi)容。
/// </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.label4 = new System.Windows.Forms.Label();
this.textBox4 = new System.Windows.Forms.TextBox();
this.button1 = new System.Windows.Forms.Button();
this.sqlConnection1 = new System.Data.SqlClient.SqlConnection();
this.label5 = new System.Windows.Forms.Label();
this.textBox5 = new System.Windows.Forms.TextBox();
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(24, 40);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(72, 23);
this.label1.TabIndex = 0;
this.label1.Text = "條形碼";
this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
//
// 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(120, 32);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(272, 26);
this.textBox1.TabIndex = 1;
this.textBox1.Text = "";
this.textBox1.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.textBox1_KeyPress);
this.textBox1.TextChanged += new System.EventHandler(this.textBox1_TextChanged);
this.textBox1.Leave += new System.EventHandler(this.textBox1_Leave);
//
// 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(24, 88);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(72, 23);
this.label2.TabIndex = 2;
this.label2.Text = "姓名";
this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
//
// textBox2
//
this.textBox2.Enabled = false;
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(120, 80);
this.textBox2.Name = "textBox2";
this.textBox2.Size = new System.Drawing.Size(112, 26);
this.textBox2.TabIndex = 4;
this.textBox2.Text = "";
//
// 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(24, 136);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(72, 23);
this.label3.TabIndex = 4;
this.label3.Text = "班級";
this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
//
// textBox3
//
this.textBox3.Enabled = false;
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(120, 128);
this.textBox3.Name = "textBox3";
this.textBox3.Size = new System.Drawing.Size(112, 26);
this.textBox3.TabIndex = 5;
this.textBox3.Text = "";
//
// 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(24, 184);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(72, 23);
this.label4.TabIndex = 6;
this.label4.Text = "余額";
this.label4.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
//
// textBox4
//
this.textBox4.Enabled = false;
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(120, 176);
this.textBox4.Name = "textBox4";
this.textBox4.Size = new System.Drawing.Size(112, 26);
this.textBox4.TabIndex = 7;
this.textBox4.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(176, 280);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(88, 23);
this.button1.TabIndex = 3;
this.button1.Text = "確認(rèn)";
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";
//
// label5
//
this.label5.Font = new System.Drawing.Font("宋體", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.label5.Location = new System.Drawing.Point(32, 232);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(64, 23);
this.label5.TabIndex = 9;
this.label5.Text = "繳費(fèi)";
this.label5.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
//
// textBox5
//
this.textBox5.Font = new System.Drawing.Font("宋體", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.textBox5.Location = new System.Drawing.Point(120, 224);
this.textBox5.MaxLength = 3;
this.textBox5.Name = "textBox5";
this.textBox5.Size = new System.Drawing.Size(112, 26);
this.textBox5.TabIndex = 2;
this.textBox5.Text = "";
this.textBox5.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.textBox5_KeyPress);
//
// 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(240, 232);
this.label6.Name = "label6";
this.label6.TabIndex = 11;
this.label6.Text = "元";
//
// frmAddMoney
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(464, 326);
this.Controls.Add(this.label6);
this.Controls.Add(this.textBox5);
this.Controls.Add(this.textBox4);
this.Controls.Add(this.textBox3);
this.Controls.Add(this.textBox2);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.label5);
this.Controls.Add(this.button1);
this.Controls.Add(this.label4);
this.Controls.Add(this.label3);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Fixed3D;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "frmAddMoney";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "充值";
this.Load += new System.EventHandler(this.frmAddMoney_Load);
this.Closed += new System.EventHandler(this.frmAddMoney_Closed);
this.ResumeLayout(false);
}
#endregion
private void textBox1_TextChanged(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);
}
catch(SqlException exe)
{
MessageBox.Show("出現(xiàn)錯誤!","充值",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 frmAddMoney_Load(object sender, System.EventArgs e)
{
}
private void button1_Click(object sender, System.EventArgs e)
{
try
{
Decimal money=Decimal.Parse(this.textBox5.Text);
float floMoney=(float)money;
//添加優(yōu)惠額
sql="select * from 優(yōu)惠表 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();
//計算優(yōu)惠額
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 收費(fèi)流水表 (時間,條形碼,值班教師,收費(fèi),充值) values('"+ dtNow.ToString() +"','"+ this.textBox1.Text +"','"+ frmMain.strTeacher +"','"+ this.textBox5.Text +"','"+ floMoney.ToString() +"')";
SqlCommand cmdCzls=new SqlCommand(sql,this.sqlConnection1);
try
{
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -