?? 余額查詢.cs
字號:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;
namespace ATM取款機
{
/// <summary>
/// Form4 的摘要說明。
/// </summary>
public class Form4 : System.Windows.Forms.Form
{
public BindingManagerBase myBind;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private System.Data.SqlClient.SqlDataAdapter sqlDataAdapter1;
private System.Data.SqlClient.SqlCommand sqlSelectCommand1;
private System.Data.SqlClient.SqlCommand sqlInsertCommand1;
private System.Data.SqlClient.SqlCommand sqlUpdateCommand1;
private System.Data.SqlClient.SqlCommand sqlDeleteCommand1;
private System.Data.SqlClient.SqlConnection sqlConnection1;
private ATM取款機.DataSet1 dataSet11;
private System.Data.SqlClient.SqlCommand sqlCommand1;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.Label label6;
// private int position;
// private BindingManagerBase myBind;
/// <summary>
/// 必需的設計器變量。
/// </summary>
private System.ComponentModel.Container components = null;
public Form4()
{
//
// 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()
{
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form4));
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.label4 = new System.Windows.Forms.Label();
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.sqlDataAdapter1 = new System.Data.SqlClient.SqlDataAdapter();
this.sqlDeleteCommand1 = new System.Data.SqlClient.SqlCommand();
this.sqlConnection1 = new System.Data.SqlClient.SqlConnection();
this.sqlInsertCommand1 = new System.Data.SqlClient.SqlCommand();
this.sqlSelectCommand1 = new System.Data.SqlClient.SqlCommand();
this.sqlUpdateCommand1 = new System.Data.SqlClient.SqlCommand();
this.dataSet11 = new ATM取款機.DataSet1();
this.sqlCommand1 = new System.Data.SqlClient.SqlCommand();
this.label5 = new System.Windows.Forms.Label();
this.label6 = new System.Windows.Forms.Label();
((System.ComponentModel.ISupportInitialize)(this.dataSet11)).BeginInit();
this.SuspendLayout();
//
// label1
//
this.label1.BackColor = System.Drawing.Color.Blue;
this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 26.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.label1.ForeColor = System.Drawing.Color.Cornsilk;
this.label1.Location = new System.Drawing.Point(232, 216);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(264, 56);
this.label1.TabIndex = 1;
this.label1.Text = "余 額 :";
//
// label2
//
this.label2.BackColor = System.Drawing.Color.Blue;
this.label2.Font = new System.Drawing.Font("Microsoft Sans Serif", 26.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.label2.ForeColor = System.Drawing.Color.Cornsilk;
this.label2.Location = new System.Drawing.Point(488, 224);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(272, 56);
this.label2.TabIndex = 2;
//
// label3
//
this.label3.BackColor = System.Drawing.Color.Blue;
this.label3.Font = new System.Drawing.Font("Microsoft Sans Serif", 26.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.label3.ForeColor = System.Drawing.Color.Cornsilk;
this.label3.Location = new System.Drawing.Point(232, 312);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(272, 56);
this.label3.TabIndex = 3;
this.label3.Text = "可 用 余 額:";
//
// label4
//
this.label4.BackColor = System.Drawing.Color.Blue;
this.label4.Font = new System.Drawing.Font("Microsoft Sans Serif", 26.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.label4.ForeColor = System.Drawing.Color.Cornsilk;
this.label4.Location = new System.Drawing.Point(488, 312);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(272, 56);
this.label4.TabIndex = 4;
//
// button1
//
this.button1.BackColor = System.Drawing.SystemColors.HotTrack;
this.button1.Font = new System.Drawing.Font("Microsoft Sans Serif", 18F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.button1.ForeColor = System.Drawing.SystemColors.ControlLightLight;
this.button1.Location = new System.Drawing.Point(768, 488);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(104, 40);
this.button1.TabIndex = 7;
this.button1.Text = "繼 續";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// button2
//
this.button2.BackColor = System.Drawing.SystemColors.HotTrack;
this.button2.Font = new System.Drawing.Font("Microsoft Sans Serif", 18F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.button2.ForeColor = System.Drawing.SystemColors.ControlLightLight;
this.button2.Location = new System.Drawing.Point(768, 608);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(104, 40);
this.button2.TabIndex = 8;
this.button2.Text = "取 卡";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// sqlDataAdapter1
//
this.sqlDataAdapter1.DeleteCommand = this.sqlDeleteCommand1;
this.sqlDataAdapter1.InsertCommand = this.sqlInsertCommand1;
this.sqlDataAdapter1.SelectCommand = this.sqlSelectCommand1;
this.sqlDataAdapter1.TableMappings.AddRange(new System.Data.Common.DataTableMapping[] {
new System.Data.Common.DataTableMapping("Table", "用戶表", new System.Data.Common.DataColumnMapping[] {
new System.Data.Common.DataColumnMapping("用戶帳號", "用戶帳號"),
new System.Data.Common.DataColumnMapping("密碼", "密碼"),
new System.Data.Common.DataColumnMapping("金額", "金額")})});
this.sqlDataAdapter1.UpdateCommand = this.sqlUpdateCommand1;
//
// sqlDeleteCommand1
//
this.sqlDeleteCommand1.CommandText = "DELETE FROM 用戶表 WHERE (用戶帳號 = @Original_用戶帳號) AND (密碼 = @Original_密碼 OR @Original" +
"_密碼 IS NULL AND 密碼 IS NULL) AND (金額 = @Original_金額 OR @Original_金額 IS NULL AND 金" +
"額 IS NULL)";
this.sqlDeleteCommand1.Connection = this.sqlConnection1;
this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_用戶帳號", System.Data.SqlDbType.VarChar, 10, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "用戶帳號", System.Data.DataRowVersion.Original, null));
this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_密碼", System.Data.SqlDbType.VarChar, 6, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "密碼", System.Data.DataRowVersion.Original, null));
this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_金額", System.Data.SqlDbType.VarChar, 10, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "金額", System.Data.DataRowVersion.Original, null));
//
// sqlConnection1
//
this.sqlConnection1.ConnectionString = "workstation id=\"MICROSOF-AC4FA8\";packet size=4096;integrated security=SSPI;data s" +
"ource=\".\";persist security info=False;initial catalog=ATM取款機";
//
// sqlInsertCommand1
//
this.sqlInsertCommand1.CommandText = "INSERT INTO 用戶表(用戶帳號, 密碼, 金額) VALUES (@用戶帳號, @密碼, @金額); SELECT 用戶帳號, 密碼, 金額 FROM " +
"用戶表 WHERE (用戶帳號 = @用戶帳號)";
this.sqlInsertCommand1.Connection = this.sqlConnection1;
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@用戶帳號", System.Data.SqlDbType.VarChar, 10, "用戶帳號"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@密碼", System.Data.SqlDbType.VarChar, 6, "密碼"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@金額", System.Data.SqlDbType.VarChar, 10, "金額"));
//
// sqlSelectCommand1
//
this.sqlSelectCommand1.CommandText = "SELECT 用戶帳號, 密碼, 金額 FROM 用戶表";
this.sqlSelectCommand1.Connection = this.sqlConnection1;
//
// sqlUpdateCommand1
//
this.sqlUpdateCommand1.CommandText = "UPDATE 用戶表 SET 用戶帳號 = @用戶帳號, 密碼 = @密碼, 金額 = @金額 WHERE (用戶帳號 = @Original_用戶帳號) AND" +
" (密碼 = @Original_密碼 OR @Original_密碼 IS NULL AND 密碼 IS NULL) AND (金額 = @Original_" +
"金額 OR @Original_金額 IS NULL AND 金額 IS NULL); SELECT 用戶帳號, 密碼, 金額 FROM 用戶表 WHERE (" +
"用戶帳號 = @用戶帳號)";
this.sqlUpdateCommand1.Connection = this.sqlConnection1;
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@用戶帳號", System.Data.SqlDbType.VarChar, 10, "用戶帳號"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@密碼", System.Data.SqlDbType.VarChar, 6, "密碼"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@金額", System.Data.SqlDbType.VarChar, 10, "金額"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_用戶帳號", System.Data.SqlDbType.VarChar, 10, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "用戶帳號", System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_密碼", System.Data.SqlDbType.VarChar, 6, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "密碼", System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_金額", System.Data.SqlDbType.VarChar, 10, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "金額", System.Data.DataRowVersion.Original, null));
//
// dataSet11
//
this.dataSet11.DataSetName = "DataSet1";
this.dataSet11.Locale = new System.Globalization.CultureInfo("zh-CN");
//
// label5
//
this.label5.BackColor = System.Drawing.Color.Blue;
this.label5.Font = new System.Drawing.Font("Microsoft Sans Serif", 26.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.label5.ForeColor = System.Drawing.Color.Cornsilk;
this.label5.Location = new System.Drawing.Point(104, 392);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(384, 56);
this.label5.TabIndex = 9;
this.label5.Text = "今 天 可 用 金 額:";
//
// label6
//
this.label6.BackColor = System.Drawing.Color.Blue;
this.label6.Font = new System.Drawing.Font("Microsoft Sans Serif", 26.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.label6.ForeColor = System.Drawing.Color.Cornsilk;
this.label6.Location = new System.Drawing.Point(496, 384);
this.label6.Name = "label6";
this.label6.Size = new System.Drawing.Size(272, 56);
this.label6.TabIndex = 10;
//
// Form4
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("$this.BackgroundImage")));
this.ClientSize = new System.Drawing.Size(1016, 734);
this.Controls.Add(this.label6);
this.Controls.Add(this.label5);
this.Controls.Add(this.button2);
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.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "Form4";
this.Text = "余額查詢";
this.Load += new System.EventHandler(this.Form4_Load);
((System.ComponentModel.ISupportInitialize)(this.dataSet11)).EndInit();
this.ResumeLayout(false);
}
#endregion
private void Form4_Load(object sender, System.EventArgs e)
{
Form1 frm=new Form1() ;
sqlConnection1.Open();
// try
// {
string strin = "select 金額,最大金額 from 用戶表 where 用戶帳號='" + ATM取款機.Form1.kanum + "'";
SqlCommand cmd=new SqlCommand(strin,sqlConnection1);
cmd.CommandText=strin;
cmd.ExecuteNonQuery();
SqlDataReader dr=cmd.ExecuteReader();
if(dr.Read())
{
this.label2.Text=dr.GetString(0).ToString();
this.label4.Text=label2.Text;
this.label6.Text=dr.GetString(1).ToString();
}
dr.Close();
////
// sqlDataAdapter1.Fill(dataSet11,"用戶表");
//
// this.label2.Text=dataSet11.Tables["用戶表"].Rows[0][2].ToString();
// this.label4.Text=label2.Text;
sqlConnection1.Close();
}
private void button2_Click(object sender, System.EventArgs e)
{
Application.Exit();
}
private void button1_Click(object sender, System.EventArgs e)
{
Form2 frm =new Form2();
frm.Show();
this.Close();
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -