⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 deletemaintenance.cs

📁 本系统为资产管理系统
💻 CS
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;
namespace AssetManagement
{
	/// <summary>
	/// deleteMaintenance 的摘要说明。
	/// </summary>
	public class deleteMaintenance : 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.Label label3;
		private System.Windows.Forms.Button button1;
		private System.Windows.Forms.Button button2;
		/// <summary>
		/// 必需的设计器变量。
		/// </summary>
		private System.ComponentModel.Container components = null;

		public deleteMaintenance()
		{
			//
			// 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.label3 = new System.Windows.Forms.Label();
			this.button1 = new System.Windows.Forms.Button();
			this.button2 = new System.Windows.Forms.Button();
			this.SuspendLayout();
			// 
			// label1
			// 
			this.label1.Location = new System.Drawing.Point(32, 64);
			this.label1.Name = "label1";
			this.label1.TabIndex = 0;
			this.label1.Text = "维护编号";
			this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
			// 
			// textBox1
			// 
			this.textBox1.Location = new System.Drawing.Point(160, 64);
			this.textBox1.Name = "textBox1";
			this.textBox1.Size = new System.Drawing.Size(136, 21);
			this.textBox1.TabIndex = 1;
			this.textBox1.Text = "";
			this.textBox1.TextChanged += new System.EventHandler(this.textBox1_TextChanged);
			// 
			// label2
			// 
			this.label2.Location = new System.Drawing.Point(32, 112);
			this.label2.Name = "label2";
			this.label2.TabIndex = 2;
			this.label2.Text = "资产号";
			this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
			// 
			// label3
			// 
			this.label3.Location = new System.Drawing.Point(168, 112);
			this.label3.Name = "label3";
			this.label3.Size = new System.Drawing.Size(128, 23);
			this.label3.TabIndex = 3;
			// 
			// button1
			// 
			this.button1.Location = new System.Drawing.Point(136, 168);
			this.button1.Name = "button1";
			this.button1.TabIndex = 4;
			this.button1.Text = "删除";
			this.button1.Click += new System.EventHandler(this.button1_Click);
			// 
			// button2
			// 
			this.button2.Location = new System.Drawing.Point(248, 168);
			this.button2.Name = "button2";
			this.button2.TabIndex = 5;
			this.button2.Text = "退出";
			this.button2.Click += new System.EventHandler(this.button2_Click);
			// 
			// deleteMaintenance
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(352, 214);
			this.Controls.Add(this.button2);
			this.Controls.Add(this.button1);
			this.Controls.Add(this.label3);
			this.Controls.Add(this.label2);
			this.Controls.Add(this.textBox1);
			this.Controls.Add(this.label1);
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
			this.MaximizeBox = false;
			this.Name = "deleteMaintenance";
			this.Text = "deleteMaintenance";
			this.Load += new System.EventHandler(this.deleteMaintenance_Load);
			this.ResumeLayout(false);

		}
		#endregion

		private void button1_Click(object sender, System.EventArgs e)
		{
			if (this.textBox1.Text.Trim() == "")
			{
				MessageBox.Show("维护号不能为空!");
				this.textBox1.Focus();
			}
			else
			{
				bool check = false;
				Connection s = new Connection();
				SqlConnection conn = new SqlConnection(s.getConnectionString);
				conn.Open();
				string str1 = "select * from maintenance";
				SqlCommand cmd = new SqlCommand(str1,conn);
				SqlDataReader dr = cmd.ExecuteReader();
				while (dr.Read())
				{
					if (this.textBox1.Text.Trim() == Convert.ToString(dr["maintenanceNo"]))
					{
						check = true;
						this.label2.Visible = true;
						//this.label2.Text = "资产编号";
						this.label3.Visible = true;
						this.label3.Text  = Convert.ToString(dr["assetNo"]);
						break;
					}
				}
				dr.Close();
				if (check)
				{
					string str2 = "delete maintenance where maintenanceNo = '" + this.textBox1.Text.Trim() + "'";
					SqlCommand cmd1 = new SqlCommand(str2,conn);
					try
					{
						cmd1.ExecuteNonQuery();
						MessageBox.Show("删除成功!");
					}
					catch
					{
						MessageBox.Show("删除失败!");
					}
				}
				else
				{
					MessageBox.Show("维护号不存在!");
					this.textBox1.Focus();
					this.textBox1.Text = "";
				}
				conn.Close();
			}
		}

		private void textBox1_TextChanged(object sender, System.EventArgs e)
		{
			if (this.textBox1.Text.Trim().Length > 8)
			{
				MessageBox.Show("输入的编号无效!");
				this.textBox1.Text = "";
				this.textBox1.Focus();
			}
			else
			{
				bool check = true;
				Connection s = new Connection();
				SqlConnection conn = new SqlConnection(s.getConnectionString);
				conn.Open();
				string str1 = "select * from maintenance";
				SqlCommand cmd = new SqlCommand(str1,conn);
				SqlDataReader dr = cmd.ExecuteReader();
				while (dr.Read())
				{
					if (this.textBox1.Text.Trim() == Convert.ToString(dr["maintenanceNo"]))
					{
						this.label2.Visible = true;
						this.label3.Visible = true;
						this.label3.Text  = Convert.ToString(dr["assetNo"]);
						check = false;
						break;
					}
				}
				dr.Close();
				conn.Close();
				if (check)
				{
					this.label2.Visible = false;
					this.label3.Visible = false;
				}
			}
		}

		private void button2_Click(object sender, System.EventArgs e)
		{
			this.Close();
		}

		private void deleteMaintenance_Load(object sender, System.EventArgs e)
		{
			this.label2.Visible = false;
			this.label3.Visible = false;
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -