📄 余额查询.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 + -