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

📄 frmassets.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 AdminGoods
{
	/// <summary>
	/// frmAssets 的摘要说明。
	/// </summary>
	public class frmAssets : System.Windows.Forms.Form
	{
		private System.Windows.Forms.DataGrid dataGrid1;
		private System.Windows.Forms.TextBox textBox1;
		private System.Windows.Forms.ComboBox comboBox1;
		private System.Windows.Forms.Button button1;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.Button button2;
		/// <summary>
		/// 必需的设计器变量。
		/// </summary>
		private System.ComponentModel.Container components = null;

		public frmAssets()
		{
			//
			// 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.dataGrid1 = new System.Windows.Forms.DataGrid();
			this.textBox1 = new System.Windows.Forms.TextBox();
			this.comboBox1 = new System.Windows.Forms.ComboBox();
			this.button1 = new System.Windows.Forms.Button();
			this.label1 = new System.Windows.Forms.Label();
			this.label2 = new System.Windows.Forms.Label();
			this.button2 = new System.Windows.Forms.Button();
			((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();
			this.SuspendLayout();
			// 
			// dataGrid1
			// 
			this.dataGrid1.AlternatingBackColor = System.Drawing.Color.LightGray;
			this.dataGrid1.BackColor = System.Drawing.Color.Gainsboro;
			this.dataGrid1.BackgroundColor = System.Drawing.Color.Silver;
			this.dataGrid1.BorderStyle = System.Windows.Forms.BorderStyle.None;
			this.dataGrid1.CaptionBackColor = System.Drawing.Color.LightSteelBlue;
			this.dataGrid1.CaptionForeColor = System.Drawing.Color.MidnightBlue;
			this.dataGrid1.DataMember = "";
			this.dataGrid1.FlatMode = true;
			this.dataGrid1.Font = new System.Drawing.Font("Tahoma", 8F);
			this.dataGrid1.ForeColor = System.Drawing.Color.Black;
			this.dataGrid1.GridLineColor = System.Drawing.Color.DimGray;
			this.dataGrid1.GridLineStyle = System.Windows.Forms.DataGridLineStyle.None;
			this.dataGrid1.HeaderBackColor = System.Drawing.Color.MidnightBlue;
			this.dataGrid1.HeaderFont = new System.Drawing.Font("Tahoma", 8F, System.Drawing.FontStyle.Bold);
			this.dataGrid1.HeaderForeColor = System.Drawing.Color.White;
			this.dataGrid1.LinkColor = System.Drawing.Color.MidnightBlue;
			this.dataGrid1.Location = new System.Drawing.Point(16, 56);
			this.dataGrid1.Name = "dataGrid1";
			this.dataGrid1.ParentRowsBackColor = System.Drawing.Color.DarkGray;
			this.dataGrid1.ParentRowsForeColor = System.Drawing.Color.Black;
			this.dataGrid1.SelectionBackColor = System.Drawing.Color.CadetBlue;
			this.dataGrid1.SelectionForeColor = System.Drawing.Color.White;
			this.dataGrid1.Size = new System.Drawing.Size(608, 224);
			this.dataGrid1.TabIndex = 0;
			// 
			// textBox1
			// 
			this.textBox1.Location = new System.Drawing.Point(272, 24);
			this.textBox1.Name = "textBox1";
			this.textBox1.Size = new System.Drawing.Size(160, 21);
			this.textBox1.TabIndex = 1;
			this.textBox1.Text = "";
			// 
			// comboBox1
			// 
			this.comboBox1.Items.AddRange(new object[] {
														   "所有类别"});
			this.comboBox1.Location = new System.Drawing.Point(96, 24);
			this.comboBox1.Name = "comboBox1";
			this.comboBox1.Size = new System.Drawing.Size(96, 20);
			this.comboBox1.TabIndex = 2;
			this.comboBox1.Text = "comboBox1";
			// 
			// button1
			// 
			this.button1.Location = new System.Drawing.Point(464, 24);
			this.button1.Name = "button1";
			this.button1.Size = new System.Drawing.Size(64, 24);
			this.button1.TabIndex = 3;
			this.button1.Text = "Query";
			this.button1.Click += new System.EventHandler(this.button1_Click);
			// 
			// label1
			// 
			this.label1.Location = new System.Drawing.Point(216, 24);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(48, 16);
			this.label1.TabIndex = 4;
			this.label1.Text = "Code";
			// 
			// label2
			// 
			this.label2.Location = new System.Drawing.Point(40, 24);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(40, 16);
			this.label2.TabIndex = 5;
			this.label2.Text = "Class";
			// 
			// button2
			// 
			this.button2.Location = new System.Drawing.Point(552, 24);
			this.button2.Name = "button2";
			this.button2.Size = new System.Drawing.Size(56, 24);
			this.button2.TabIndex = 6;
			this.button2.Text = "Close";
			this.button2.Click += new System.EventHandler(this.button2_Click);
			// 
			// frmAssets
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(640, 293);
			this.Controls.Add(this.button2);
			this.Controls.Add(this.label2);
			this.Controls.Add(this.label1);
			this.Controls.Add(this.button1);
			this.Controls.Add(this.comboBox1);
			this.Controls.Add(this.textBox1);
			this.Controls.Add(this.dataGrid1);
			this.MaximizeBox = false;
			this.MinimizeBox = false;
			this.Name = "frmAssets";
			this.Text = "资产管理";
			this.Load += new System.EventHandler(this.frmAssets_Load);
			((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
			this.ResumeLayout(false);

		}
		#endregion

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

		}

		private void frmAssets_Load(object sender, System.EventArgs e)
		{
			this.InitGrid ();
			this.InitDorpDownList();
			

			this.comboBox1.DataSource = this.listAllAssetsClass().DefaultView ;

			this.comboBox1 .ValueMember = "className";

			this.comboBox1 .Refresh ();

		}
		private void InitDorpDownList()
		{
			AssetsClassDAO dao = new AssetsClassDAO();

			//IList list = dao.listAllAssetsForList();

			//for(int i=0;i<list.Count ;i++)
			//{
				//this.comboBox1 .Items .Add (new Item(list.));
			//}

		}

		
		private  int queryClassID(string className)
		{
			int last = 0;

			Database db = new Database ();

			System.Data .SqlClient .SqlConnection conn;
			System.Data .SqlClient .SqlCommand cmd;
			System.Data .SqlClient .SqlDataReader rs;
			string sql = "";
			try
			{
				conn = db.openConn ();
				cmd = new System.Data.SqlClient.SqlCommand ();
				sql = "select * from assetsClass where  className =  '"+ className +"'  ";
				cmd.CommandText = sql;
				cmd.Connection = conn;

				rs = cmd.ExecuteReader (System.Data .CommandBehavior .CloseConnection );

				while(rs.Read ())
				{
					
					last =Convert.ToInt32 (  rs["ID"].ToString() );

				}
			}
			catch(Exception ex)
			{
				string sm = ex.Message ;
				last = 0;
			}
			finally
			{
				db.closeConn ();
			}

			return last;
		}

		private  int queryWorkID(string className)
		{
			int last = 0;

			Database db = new Database ();

			System.Data .SqlClient .SqlConnection conn;
			System.Data .SqlClient .SqlCommand cmd;
			System.Data .SqlClient .SqlDataReader rs;
			string sql = "";
			try
			{
				conn = db.openConn ();
				cmd = new System.Data.SqlClient.SqlCommand ();
				sql = "select * from worker where  username =  '"+ className +"'  ";
				cmd.CommandText = sql;
				cmd.Connection = conn;

				rs = cmd.ExecuteReader (System.Data .CommandBehavior .CloseConnection );

				while(rs.Read ())
				{
					
					last =Convert.ToInt32 (  rs["ID"].ToString() );

				}
			}
			catch(Exception ex)
			{
				string sm = ex.Message ;
				last = 0;
			}
			finally
			{
				db.closeConn ();
			}

			return last;
		}
		private  DataTable listAllAssetsClass()
		{
			System.Data.SqlClient.SqlConnection conn;		

			SqlDataAdapter dp;
			string sql;
			DataSet ds = new DataSet();
			Database db = new Database();

			DataTable last = new DataTable();
			try
			{
				//sql = "select id,username,realname ,workcode,workage,address from worker  where worktype = '1'";

				sql = "select id,className from assetsClass";

				conn = db.openConn();
				
				dp = new System.Data.SqlClient.SqlDataAdapter(sql,conn);	 
 
				dp.Fill(ds,"worker");

				last = ds.Tables["worker"];

			}
			catch
			{
				last = null;
			}
			finally
			{
				db.closeConn();
			}
			return last;
		}

		private void InitGrid()
		{
			AssetsDAO dao = new  AssetsDAO();

			this.dataGrid1 .DataSource = dao.listAllAssets ();
			this.dataGrid1.Refresh ();


		}

		private void button1_Click(object sender, System.EventArgs e)
		{
			AssetsDAO dao = new  AssetsDAO();

			if(this.textBox1 .Text .Trim () .ToString () == "")
			{
				int classid = this.queryClassID( this.comboBox1 .SelectedValue.ToString ());


				this.dataGrid1 .DataSource = dao.executeSQL (	 "select a.id,a.name,a.code ,w.realname,c.className  from assets as a ,worker as w ,assetsClass as c where  a.workerID = w.ID and a.classID = c.ID  and a.classID = " + classid +" " ).DefaultView ;
				this.dataGrid1.Refresh ();
			}
			else
			{
				int classid = this.queryClassID( this.comboBox1 .SelectedValue.ToString ());

				string name = this.textBox1 .Text .Trim ().ToString ();

				this.dataGrid1 .DataSource = dao.executeSQL (	 "select a.id,a.name,a.code ,w.realname,c.className  from assets as a ,worker as w ,assetsClass as c where  a.workerID = w.ID and a.classID = c.ID  and a.classID = " + classid +"  and  name like  '%"+ name +"%'" ).DefaultView ;
				this.dataGrid1.Refresh ();

			}

			this.textBox1 .Text = "";
			
		}
	}
}

⌨️ 快捷键说明

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