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

📄 storagesearch.cs

📁 进销存管理系统 C#完整源码 内含SQl建库脚本等
💻 CS
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace 进销存管理系统
{
	/// <summary>
	/// StorageSearch 的摘要说明。
	/// </summary>
	public class StorageSearch : System.Windows.Forms.Form
	{
		private DataSet ds = new DataSet();
		private DataView dv;
		private LinkDataBase link = new LinkDataBase();	
		private string sendTableName = "库存商品";
		private string sendStrSQL = "select 库存库.货号,拼音编码,品名,单位,仓库,库存数量,库存单价,库存金额 " +
			"from 库存库,商品清单 where 库存库.货号 = 商品清单.货号";

		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.Label label3;
		private System.Windows.Forms.GroupBox groupBox1;
		private System.Windows.Forms.Button btn_Search;
		private System.Windows.Forms.DataGrid dgrd_StorageSearch;
		private System.Windows.Forms.TextBox txt_WareWord;
		private System.Windows.Forms.TextBox txt_WareNum;
		private System.Windows.Forms.ComboBox cmb_Storage;
		/// <summary>
		/// 必需的设计器变量。
		/// </summary>
		private System.ComponentModel.Container components = null;

		public StorageSearch()
		{
			//
			// Windows 窗体设计器支持所必需的
			//
			InitializeComponent();
			//
			// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
			//
			this.selectDataBase();
			this.DataGridStateControl();
		}

		/// <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.btn_Search = new System.Windows.Forms.Button();
			this.txt_WareWord = new System.Windows.Forms.TextBox();
			this.txt_WareNum = new System.Windows.Forms.TextBox();
			this.label1 = new System.Windows.Forms.Label();
			this.label2 = new System.Windows.Forms.Label();
			this.label3 = new System.Windows.Forms.Label();
			this.cmb_Storage = new System.Windows.Forms.ComboBox();
			this.groupBox1 = new System.Windows.Forms.GroupBox();
			this.dgrd_StorageSearch = new System.Windows.Forms.DataGrid();
			this.groupBox1.SuspendLayout();
			((System.ComponentModel.ISupportInitialize)(this.dgrd_StorageSearch)).BeginInit();
			this.SuspendLayout();
			// 
			// btn_Search
			// 
			this.btn_Search.Location = new System.Drawing.Point(601, 13);
			this.btn_Search.Name = "btn_Search";
			this.btn_Search.Size = new System.Drawing.Size(48, 24);
			this.btn_Search.TabIndex = 4;
			this.btn_Search.Text = "查询";
			this.btn_Search.Click += new System.EventHandler(this.btn_Search_Click);
			// 
			// txt_WareWord
			// 
			this.txt_WareWord.Location = new System.Drawing.Point(301, 15);
			this.txt_WareWord.Name = "txt_WareWord";
			this.txt_WareWord.TabIndex = 2;
			this.txt_WareWord.Text = "";
			// 
			// txt_WareNum
			// 
			this.txt_WareNum.Location = new System.Drawing.Point(113, 15);
			this.txt_WareNum.Name = "txt_WareNum";
			this.txt_WareNum.TabIndex = 1;
			this.txt_WareNum.Text = "";
			// 
			// label1
			// 
			this.label1.Location = new System.Drawing.Point(71, 19);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(40, 16);
			this.label1.TabIndex = 3;
			this.label1.Text = "货号:";
			// 
			// label2
			// 
			this.label2.Location = new System.Drawing.Point(228, 19);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(64, 16);
			this.label2.TabIndex = 4;
			this.label2.Text = "商品拼音:";
			// 
			// label3
			// 
			this.label3.Location = new System.Drawing.Point(416, 19);
			this.label3.Name = "label3";
			this.label3.Size = new System.Drawing.Size(40, 16);
			this.label3.TabIndex = 5;
			this.label3.Text = "仓库:";
			// 
			// cmb_Storage
			// 
			this.cmb_Storage.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
			this.cmb_Storage.Location = new System.Drawing.Point(459, 15);
			this.cmb_Storage.Name = "cmb_Storage";
			this.cmb_Storage.Size = new System.Drawing.Size(121, 20);
			this.cmb_Storage.Sorted = true;
			this.cmb_Storage.TabIndex = 3;
			// 
			// groupBox1
			// 
			this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right)));
			this.groupBox1.Controls.Add(this.btn_Search);
			this.groupBox1.Controls.Add(this.label2);
			this.groupBox1.Controls.Add(this.cmb_Storage);
			this.groupBox1.Controls.Add(this.label3);
			this.groupBox1.Controls.Add(this.txt_WareNum);
			this.groupBox1.Controls.Add(this.label1);
			this.groupBox1.Controls.Add(this.txt_WareWord);
			this.groupBox1.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
			this.groupBox1.Location = new System.Drawing.Point(0, -2);
			this.groupBox1.Name = "groupBox1";
			this.groupBox1.Size = new System.Drawing.Size(720, 50);
			this.groupBox1.TabIndex = 7;
			this.groupBox1.TabStop = false;
			// 
			// dgrd_StorageSearch
			// 
			this.dgrd_StorageSearch.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
				| System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right)));
			this.dgrd_StorageSearch.CaptionVisible = false;
			this.dgrd_StorageSearch.DataMember = "";
			this.dgrd_StorageSearch.HeaderForeColor = System.Drawing.SystemColors.ControlText;
			this.dgrd_StorageSearch.Location = new System.Drawing.Point(0, 50);
			this.dgrd_StorageSearch.Name = "dgrd_StorageSearch";
			this.dgrd_StorageSearch.Size = new System.Drawing.Size(720, 326);
			this.dgrd_StorageSearch.TabIndex = 5;
			// 
			// StorageSearch
			// 
			this.AcceptButton = this.btn_Search;
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(720, 373);
			this.Controls.Add(this.dgrd_StorageSearch);
			this.Controls.Add(this.groupBox1);
			this.Name = "StorageSearch";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.Text = "【库存查询】";
			this.groupBox1.ResumeLayout(false);
			((System.ComponentModel.ISupportInitialize)(this.dgrd_StorageSearch)).EndInit();
			this.ResumeLayout(false);

		}
		#endregion

		//---------------将查询得到的仓库信息添加到下拉列表框中---------------
		private void selectDataBase()
		{
			this.ds = this.link.SelectDataBase(sendStrSQL,sendTableName);
			this.dv = new DataView(ds.Tables[0]);
			this.dgrd_StorageSearch.DataSource = dv;
			this.cmb_Storage.Items.Add(""); //首先加入一个空白,以用作查询全部仓库的库存货物
			//从库存库中读取所有仓库并排斥性的加入保存仓库号的组合框中
			for (int i=0;i<ds.Tables[0].Rows.Count;i++)//外循环是判断库存库中的有多少行
			{
				for (int j=0;j<this.cmb_Storage.Items.Count;j++)//内循环是判断当前要加进去的仓库号在组合框中是否已存在
				{
					if (ds.Tables[0].Rows[i][4].ToString().Trim() == this.cmb_Storage.Items[j].ToString())
					{
						goto END;//如果组合框中已存在当前要加入的仓库号,则转到END标识处,组合框中不加入该仓库号
					}
				}
				//如果组合框中尚不存在该仓库号,则将它加进去
				this.cmb_Storage.Items.Add(ds.Tables[0].Rows[i][4].ToString().Trim());
			END:{};
			}
			this.cmb_Storage.SelectedIndex = 0;
		}

		//--------------根据输入查询库存中商品信息--------------
		private void btn_Search_Click(object sender, System.EventArgs e)
		{
			string strRowFilter = "";
			string strWareNumFilter ="货号 like '" + txt_WareNum.Text.Trim() + "%'";
			string strWareWordFilter ="拼音编码 like '" + txt_WareWord.Text.Trim() + "%'";
			int selectedNum = cmb_Storage.SelectedIndex;
			string strStorageFilter ="仓库 = '" + cmb_Storage.Items[selectedNum].ToString().Trim()+ "'";
			
			if (txt_WareNum.Text.Trim() != "")
				strRowFilter += strWareNumFilter + " and ";
			if (txt_WareWord.Text.Trim() != "")
				strRowFilter += strWareWordFilter + " and ";
			if (cmb_Storage.Items[selectedNum].ToString().Trim() != "")
				strRowFilter += strStorageFilter + " and ";

			if (strRowFilter != "")  // 存在查询条件
				strRowFilter = strRowFilter.Substring(0,strRowFilter.Length-5);
			dv.RowFilter = strRowFilter;
		}

		//-----------设置表格状态--------------
		private void DataGridStateControl()
		{
			DataGridTableStyle ts = new DataGridTableStyle();
			DataGridNoActiveCellColumn aColumnTextColumn;
			ts.AlternatingBackColor = Color.LightGray;
			ts.MappingName = this.ds.Tables[0].TableName;
			int numCols = this.ds.Tables[0].Columns.Count;
			for (int i = 0;i< numCols;i++)
			{
				aColumnTextColumn = new DataGridNoActiveCellColumn();
				aColumnTextColumn.MappingName = this.ds.Tables[0].Columns[i].ColumnName;
				aColumnTextColumn.HeaderText = this.ds.Tables[0].Columns[i].ColumnName;
				aColumnTextColumn.NullText = "";
				aColumnTextColumn.Format = "D";				
				ts.GridColumnStyles.Add(aColumnTextColumn);
			}
			this.dgrd_StorageSearch.TableStyles.Add(ts);
		}

		
	}
}

⌨️ 快捷键说明

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