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

📄 allocateasset.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>
	/// allocateasset 的摘要说明。
	/// </summary>
	public class allocateasset : System.Windows.Forms.Form
	{
		private System.Windows.Forms.CheckedListBox checkedListBox1;
		private System.Windows.Forms.CheckedListBox checkedListBox2;
		private System.Windows.Forms.Button button1;
		private System.Windows.Forms.Button button3;
		private System.Windows.Forms.Button button4;
		private System.Windows.Forms.Label label1;
		/// <summary>
		/// 必需的设计器变量。
		/// </summary>
		private System.ComponentModel.Container components = null;

		public allocateasset()
		{
			//
			// 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.checkedListBox1 = new System.Windows.Forms.CheckedListBox();
			this.checkedListBox2 = new System.Windows.Forms.CheckedListBox();
			this.button1 = new System.Windows.Forms.Button();
			this.button3 = new System.Windows.Forms.Button();
			this.button4 = new System.Windows.Forms.Button();
			this.label1 = new System.Windows.Forms.Label();
			this.SuspendLayout();
			// 
			// checkedListBox1
			// 
			this.checkedListBox1.AllowDrop = true;
			this.checkedListBox1.CheckOnClick = true;
			this.checkedListBox1.HorizontalScrollbar = true;
			this.checkedListBox1.Location = new System.Drawing.Point(8, 32);
			this.checkedListBox1.Name = "checkedListBox1";
			this.checkedListBox1.Size = new System.Drawing.Size(216, 292);
			this.checkedListBox1.TabIndex = 0;
			this.checkedListBox1.SelectedIndexChanged += new System.EventHandler(this.checkedListBox1_SelectedIndexChanged);
			// 
			// checkedListBox2
			// 
			this.checkedListBox2.AllowDrop = true;
			this.checkedListBox2.CheckOnClick = true;
			this.checkedListBox2.HorizontalScrollbar = true;
			this.checkedListBox2.Location = new System.Drawing.Point(280, 32);
			this.checkedListBox2.Name = "checkedListBox2";
			this.checkedListBox2.Size = new System.Drawing.Size(224, 292);
			this.checkedListBox2.TabIndex = 1;
			this.checkedListBox2.SelectedIndexChanged += new System.EventHandler(this.checkedListBox2_SelectedIndexChanged);
			// 
			// button1
			// 
			this.button1.Location = new System.Drawing.Point(120, 400);
			this.button1.Name = "button1";
			this.button1.TabIndex = 2;
			this.button1.Text = "确定";
			this.button1.Click += new System.EventHandler(this.button1_Click);
			// 
			// button3
			// 
			this.button3.Location = new System.Drawing.Point(216, 400);
			this.button3.Name = "button3";
			this.button3.TabIndex = 4;
			this.button3.Text = "取消";
			this.button3.Click += new System.EventHandler(this.button3_Click);
			// 
			// button4
			// 
			this.button4.Location = new System.Drawing.Point(312, 400);
			this.button4.Name = "button4";
			this.button4.TabIndex = 5;
			this.button4.Text = "退出";
			this.button4.Click += new System.EventHandler(this.button4_Click);
			// 
			// label1
			// 
			this.label1.Location = new System.Drawing.Point(224, 160);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(56, 23);
			this.label1.TabIndex = 6;
			this.label1.Text = "分配 > >";
			this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
			// 
			// allocateasset
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(512, 454);
			this.Controls.Add(this.label1);
			this.Controls.Add(this.button4);
			this.Controls.Add(this.button3);
			this.Controls.Add(this.button1);
			this.Controls.Add(this.checkedListBox2);
			this.Controls.Add(this.checkedListBox1);
			this.Name = "allocateasset";
			this.Text = "allocateasset";
			this.Load += new System.EventHandler(this.allocateasset_Load);
			this.ResumeLayout(false);

		}
		#endregion

		private void allocateasset_Load(object sender, System.EventArgs e)
		{
			string s1 = "";
			string s2 = "";
			string s3 = "";
		   Connection s = new Connection();
			SqlConnection conn = new SqlConnection(s.getConnectionString);
			conn.Open();
			string strsql1 = "select * from asset where not exists(select * from employee where employee.employeeNo = asset.assetNo)";
			SqlCommand cmd = new SqlCommand(strsql1,conn);
			SqlDataReader dr1 = cmd.ExecuteReader();
			while (dr1.Read())
			{
				s1 = Convert.ToString(dr1["assetNo"]);
				s2 = Convert.ToString(dr1["assetDescription"]);
				s3 = "资产号:" + s1 + "备注:" + s2;
				this.checkedListBox1.Items.Add(s3);
				s3 = "";
				s1 = "";
				s2 = "";
			}
			dr1.Close();
			string strsql2 = "select * from employee where not exists (select * from asset where asset.employeeNo = employee.employeeNo)";
			
			
			SqlCommand cmd1 = new SqlCommand(strsql2,conn);
			SqlDataReader dr2 = cmd1.ExecuteReader();
			while (dr2.Read())
			{
				s1 = "未分配 ";
				s1 += "员工号:";
				s1 += Convert.ToString(dr2["employeeNo"]);
				s1 += " 姓名:";
				s1 += Convert.ToString(dr2["employeeName"]);
				this.checkedListBox2.Items.Add(s1);
				s1 = "";
			}
			dr2.Close();
			string strsql3 = "select * from employee where  exists (select * from asset where asset.employeeNo = employee.employeeNo)";
			SqlCommand cmd2 = new SqlCommand(strsql3,conn);
			SqlDataReader dr3 = cmd2.ExecuteReader();
			while (dr3.Read())
			{
				s2 = "已分配 ";
				s2 += "员工号:";
				s2 += Convert.ToString(dr3["employeeNo"]);
				s2 += " 姓名:";
				s2 += Convert.ToString(dr3["employeeName"]);
				this.checkedListBox2.Items.Add(s2);
				s2 = "";
			}
			dr3.Close();
			conn.Close();
		}

		private void checkedListBox1_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			int i;
			for ( i = 0; i < this.checkedListBox1.Items.Count;i++)
			{
				if (this.checkedListBox1.GetItemChecked(i) == true)
				{
					break;
				}
			}
			for (int j = 0; j < this.checkedListBox1.Items.Count;j++)
			{

					this.checkedListBox1.SetItemChecked(j,false);

			}
		}

		private void checkedListBox2_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			for (int i = 0; i < this.checkedListBox2.Items.Count;i++)
			{
				if (this.checkedListBox2.GetItemChecked(i) == true)
				{
                     break;
				}
			}
			for (int j = 0; j < this.checkedListBox2.Items.Count;j++)
			{
				this.checkedListBox2.SetItemChecked(j,false);
			}
		}

		private void button1_Click(object sender, System.EventArgs e)
		{
			bool check1 = false;
			bool check2 = false;
			string asset = "";
			string assetNo = "";
			string employee = "";
			string employeeNo = "";
			string s1 = "";
			string s2 = "";
			int t = 0;
			int t1 = 0;
			for (int i = 0;i < this.checkedListBox1.Items.Count;i++)
			{
				if (this.checkedListBox1.GetItemChecked(i) == true)
				{
					asset = this.checkedListBox1.Items[i].ToString();
					t = i;
					for (int k = 4;k < asset.Length;k++)
					{
						if (asset[k] != '备')
						assetNo += asset[k];
						else
							break;
					}
					check1 =  true;
					//MessageBox.Show(assetNo);
					break;
				}
			}
			//asset
			for (int j = 0;j < this.checkedListBox2.Items.Count;j++)
			{
				if (this.checkedListBox2.GetItemChecked(j) == true)
				{
					t1 = j;
					employee = this.checkedListBox2.Items[j].ToString();
					for (int k = 8;k < employee.Length;k++)
					{
						if (employee[k] != '姓')
							employeeNo += employee[k];
						else
							break;
					}
					check2 = true;
					//MessageBox.Show(employeeNo);
					break;
				}
			}
			if (!check1)
			{
				MessageBox.Show("请选择要分配的资产!");
				this.checkedListBox1.Focus();
			}
			else
			{
				if (check2)
				{
                   string str1 = "update asset set employeeNo = '" + employeeNo + "' where assetNo = '" + assetNo +"'";
					Connection s = new Connection();
					SqlConnection conn = new SqlConnection(s.getConnectionString);
					conn.Open();
					SqlCommand cmd2 = new SqlCommand(str1,conn);
					try
					{
						cmd2.ExecuteNonQuery();
                        MessageBox.Show("分配成功!");
						this.checkedListBox1.Items.RemoveAt(t);
						s1 = this.checkedListBox2.Items[t1].ToString();
						if (s1[0] == '未')
						{
							s2 += "已";
							for (int i = 1;i < s1.Length;i++)
							{
								s2 += s1[i]; 
							}
							//s2 = s1;
							this.checkedListBox2.Items.Remove(s1);
							
							this.checkedListBox2.Items.Add(s2);
						}
					}
					catch
					{
						MessageBox.Show("分配失败!");
					}
					conn.Close();
				}
				else
				{
					MessageBox.Show("请选择被分配给的员工!");
					this.checkedListBox1.Focus();
				}
			}
		}

		private void button3_Click(object sender, System.EventArgs e)
		{
			for (int i = 0;i < this.checkedListBox1.Items.Count;i++)
				this.checkedListBox1.SetItemChecked(i,false);
			for (int j = 0;j < this.checkedListBox2.Items.Count;j++)
				this.checkedListBox2.SetItemChecked(j,false);

		}

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


	}
}

⌨️ 快捷键说明

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