📄 删除用户.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 + -