?? 刪除用戶.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 frmDeleteUser : System.Windows.Forms.Form
{
private System.Windows.Forms.Label label1;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private System.Data.SqlClient.SqlConnection sqlConnection1;
private String sql;
private int numAff;
/// <summary>
/// 必需的設計器變量。
/// </summary>
private System.ComponentModel.Container components = null;
public frmDeleteUser()
{
//
// 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.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.sqlConnection1 = new System.Data.SqlClient.SqlConnection();
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, 48);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(40, 24);
this.label1.TabIndex = 0;
this.label1.Text = "條碼";
this.label1.TextAlign = System.Drawing.ContentAlignment.TopRight;
//
// 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(88, 40);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(304, 26);
this.textBox1.TabIndex = 1;
this.textBox1.Text = "";
//
// button1
//
this.button1.Location = new System.Drawing.Point(112, 120);
this.button1.Name = "button1";
this.button1.TabIndex = 2;
this.button1.Text = "刪除";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// button2
//
this.button2.Location = new System.Drawing.Point(256, 120);
this.button2.Name = "button2";
this.button2.TabIndex = 3;
this.button2.Text = "清空";
this.button2.Click += new System.EventHandler(this.button2_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";
//
// frmDeleteUser
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(448, 174);
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.label1);
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "frmDeleteUser";
this.ShowInTaskbar = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "刪除用戶";
this.Load += new System.EventHandler(this.frmDeleteUser_Load);
this.ResumeLayout(false);
}
#endregion
private void button2_Click(object sender, System.EventArgs e)
{
this.textBox1.Text="";
this.textBox1.Focus();
this.textBox1.SelectAll();
}
private void button1_Click(object sender, System.EventArgs e)
{
if(this.textBox1.TextLength==0)
{
MessageBox.Show("條碼掃描錯誤!","刪除用戶",MessageBoxButtons.OK,MessageBoxIcon.Error);
goto finish;
}
sql="delete from 帳戶表 where 條形碼='"+this.textBox1.Text+"'";
SqlCommand cmd=new SqlCommand(this.sql,this.sqlConnection1);
this.sqlConnection1.Open();
try
{
numAff=cmd.ExecuteNonQuery();
}
catch(SqlException exe)
{
MessageBox.Show("出現錯誤!","刪除用戶",MessageBoxButtons.OK,MessageBoxIcon.Error);
}
finally
{
this.sqlConnection1.Close();
if(numAff==1)
MessageBox.Show("刪除成功!","刪除用戶",MessageBoxButtons.OK,MessageBoxIcon.Information);
this.textBox1.Focus();
this.textBox1.SelectAll();
}
finish:
this.textBox1.Focus();
this.textBox1.SelectAll();
}
private void frmDeleteUser_Load(object sender, System.EventArgs e)
{
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -