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

📄 stocksearchform.cs

📁 超市管理系统的完整版文档
💻 CS
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data.SqlClient; //加进数据库类链接
using SupDataBase;//命名空间修改
using System.Data;
using System.Data.SqlTypes;
using System.Data.Odbc;
using System.Text;
using SupDataBase;
namespace WindowsApplication1
{
	/// <summary>
	/// StocksearchForm 的摘要说明。
	/// </summary>
	public class StocksearchForm : System.Windows.Forms.Form
	{
		private System.Windows.Forms.GroupBox groupBox1;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.Button button1;
		private System.Windows.Forms.DataGrid m_GoodListdataGrid;
		/// <summary>
		/// 必需的设计器变量。
		/// </summary>
		private System.ComponentModel.Container components = null;
		private System.Data.DataView m_dataview;
		private System.Data.DataTable datatable;
		private System.Windows.Forms.TextBox m_txtNumber;

		private SqlConnection m_connection;

		public StocksearchForm()
		{
			//
			// Windows 窗体设计器支持所必需的
			//
			InitializeComponent();
			//m_connection=DBUtil.GetConnection();//获得数据库链接
			//m_sqlDataAdapter=new SqlDataAdapter();//初始化适配器
           
            m_connection=DBUtil.GetConnection();
			datatable = new System.Data.DataTable();

			datatable.Columns.Add(new System.Data.DataColumn("商品ID"));
			datatable.Columns.Add(new System.Data.DataColumn("商品条码"));
			datatable.Columns.Add(new System.Data.DataColumn("商品名称"));
			datatable.Columns.Add(new System.Data.DataColumn("进价"));
			datatable.Columns.Add(new System.Data.DataColumn("售价"));
			datatable.Columns.Add(new System.Data.DataColumn("商品库存"));
			datatable.Columns.Add(new System.Data.DataColumn("计量单位"));
			datatable.Columns.Add(new System.Data.DataColumn("备注"));

			m_dataview = new System.Data.DataView(datatable);
			//
			// 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.groupBox1 = new System.Windows.Forms.GroupBox();
			this.m_GoodListdataGrid = new System.Windows.Forms.DataGrid();
			this.button1 = new System.Windows.Forms.Button();
			this.m_txtNumber = new System.Windows.Forms.TextBox();
			this.label1 = new System.Windows.Forms.Label();
			this.groupBox1.SuspendLayout();
			((System.ComponentModel.ISupportInitialize)(this.m_GoodListdataGrid)).BeginInit();
			this.SuspendLayout();
			// 
			// groupBox1
			// 
			this.groupBox1.Controls.Add(this.m_GoodListdataGrid);
			this.groupBox1.Controls.Add(this.button1);
			this.groupBox1.Controls.Add(this.m_txtNumber);
			this.groupBox1.Controls.Add(this.label1);
			this.groupBox1.Location = new System.Drawing.Point(16, 16);
			this.groupBox1.Name = "groupBox1";
			this.groupBox1.Size = new System.Drawing.Size(712, 488);
			this.groupBox1.TabIndex = 0;
			this.groupBox1.TabStop = false;
			this.groupBox1.Text = "库存查询";
			// 
			// m_GoodListdataGrid
			// 
			this.m_GoodListdataGrid.CaptionVisible = false;
			this.m_GoodListdataGrid.DataMember = "";
			this.m_GoodListdataGrid.HeaderForeColor = System.Drawing.SystemColors.ControlText;
			this.m_GoodListdataGrid.Location = new System.Drawing.Point(24, 64);
			this.m_GoodListdataGrid.Name = "m_GoodListdataGrid";
			this.m_GoodListdataGrid.Size = new System.Drawing.Size(664, 400);
			this.m_GoodListdataGrid.TabIndex = 3;
			// 
			// button1
			// 
			this.button1.Location = new System.Drawing.Point(280, 24);
			this.button1.Name = "button1";
			this.button1.Size = new System.Drawing.Size(72, 24);
			this.button1.TabIndex = 2;
			this.button1.Text = " 查询";
			this.button1.Click += new System.EventHandler(this.button1_Click);
			// 
			// m_txtNumber
			// 
			this.m_txtNumber.Location = new System.Drawing.Point(128, 24);
			this.m_txtNumber.Name = "m_txtNumber";
			this.m_txtNumber.Size = new System.Drawing.Size(120, 21);
			this.m_txtNumber.TabIndex = 1;
			this.m_txtNumber.Text = "5";
			// 
			// label1
			// 
			this.label1.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.label1.Location = new System.Drawing.Point(40, 32);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(80, 16);
			this.label1.TabIndex = 0;
			this.label1.Text = "库存数小于";
			// 
			// StocksearchForm
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(744, 526);
			this.Controls.Add(this.groupBox1);
			this.Name = "StocksearchForm";
			this.Text = "StocksearchForm";
			this.Load += new System.EventHandler(this.StocksearchForm_Load);
			this.groupBox1.ResumeLayout(false);
			((System.ComponentModel.ISupportInitialize)(this.m_GoodListdataGrid)).EndInit();
			this.ResumeLayout(false);

		}
		#endregion

		private void button1_Click(object sender, System.EventArgs e)
		{
			string N = this.m_txtNumber.Text;
			if(N == "")
			{
			  MessageBox.Show("请输入上限值");
			  return;
			}

            reflesh();
		
		}

		private void StocksearchForm_Load(object sender, System.EventArgs e)
		{
		   reflesh();
		}

		private void reflesh()
		{   
			string num="5";
			if(this.m_txtNumber.Text !="")
			{
			  num = this.m_txtNumber.Text;
			}
		    
			try
			{
				String sql  ="select * from Goods where StockNumber<"+ num +" order by StockNumber";
				System.Data.DataRow datarow;

				m_connection.Open();
				SqlCommand cmd = new SqlCommand(sql, m_connection);
				SqlDataReader reader = cmd.ExecuteReader();
				if (datatable.Rows.Count>0)
				{
					datatable.Rows.Clear();
				}

				while (reader.Read())
				{
					datarow = datatable.NewRow();
					datarow[0] = reader["GoodsID"].ToString();
					datarow[1] = reader["GoodsCode"].ToString();
					datarow[2] = reader["GoodsName"].ToString();
					datarow[3] = reader["purchaseprice"].ToString();
					datarow[4] = reader["saleprice"].ToString();
					datarow[5] = reader["stocknumber"].ToString();
					datarow[6] = reader["unit"].ToString();
					datarow[7] = reader["remark"].ToString();
					datatable.Rows.Add(datarow);
				}
				//	System.Data.DataView m_dataview = new System.Data.DataView(datatable);
				m_dataview.AllowNew = false;
				m_dataview.AllowEdit = false;
				m_dataview.AllowDelete = false;

				m_GoodListdataGrid.DataSource = m_dataview;
				m_connection.Close();

			}
			catch(SqlException ex)
			{			
				string s = ex.ToString();
				m_connection.Close();
				MessageBox.Show(s);
			}

		
		}

		
	}
}

⌨️ 快捷键说明

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