?? 添加用戶.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 + -