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

📄 todaypurchase.cs

📁 超市管理系统的完整版文档
💻 CS
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using SupDataBase;
using System.Data.SqlClient;


namespace WindowsApplication1
{
	/// <summary>
	/// TodayPurchase 的摘要说明。
	/// </summary>
	public class TodayPurchase : System.Windows.Forms.Form
	{
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.DataGrid m_dataGrid;
		private System.Data.SqlClient.SqlConnection m_sqlConn;
		private System.Data.SqlClient.SqlCommand m_sqlCommand;
		/// <summary>
		/// 必需的设计器变量。
		/// </summary>
		private System.ComponentModel.Container components = null;

		public TodayPurchase()
		{
			//
			// 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.m_dataGrid = new System.Windows.Forms.DataGrid();
			this.label1 = new System.Windows.Forms.Label();
			this.m_sqlConn = new System.Data.SqlClient.SqlConnection();
			this.m_sqlCommand = new System.Data.SqlClient.SqlCommand();
			((System.ComponentModel.ISupportInitialize)(this.m_dataGrid)).BeginInit();
			this.SuspendLayout();
			// 
			// m_dataGrid
			// 
			this.m_dataGrid.CaptionBackColor = System.Drawing.SystemColors.ActiveCaptionText;
			this.m_dataGrid.CaptionVisible = false;
			this.m_dataGrid.DataMember = "";
			this.m_dataGrid.HeaderForeColor = System.Drawing.SystemColors.ControlText;
			this.m_dataGrid.Location = new System.Drawing.Point(8, 48);
			this.m_dataGrid.Name = "m_dataGrid";
			this.m_dataGrid.Size = new System.Drawing.Size(616, 368);
			this.m_dataGrid.TabIndex = 0;
			// 
			// label1
			// 
			this.label1.Font = new System.Drawing.Font("宋体", 15.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.label1.Location = new System.Drawing.Point(264, 16);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(104, 23);
			this.label1.TabIndex = 1;
			this.label1.Text = "今日进货";
			// 
			// TodayPurchase
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(640, 453);
			this.Controls.Add(this.label1);
			this.Controls.Add(this.m_dataGrid);
			this.Name = "TodayPurchase";
			this.Text = "今日进货";
			this.Load += new System.EventHandler(this.TodayPurchase_Load);
			((System.ComponentModel.ISupportInitialize)(this.m_dataGrid)).EndInit();
			this.ResumeLayout(false);

		}
		#endregion

		private void TodayPurchase_Load(object sender, System.EventArgs e)
		{
			System.DateTime dtime=new System.DateTime();
			dtime = System.DateTime.Now;
			try
			{
				
                string query = "select * from PurchaseRecord inner join Goods on Goods.GoodsID = PurchaseRecord.GoodsID inner join Employee on Employee.EmployeeID = PurchaseRecord.PurchaserID inner join Supplier on Supplier.SupplierID = PurchaseRecord.SupplierID where "+
					           " year(PurchaseDate)=" + dtime.Year.ToString()+" and month(PurchaseDate)=" + dtime.Month.ToString() +" and day(PurchaseDate)=" + dtime.Day.ToString();

				
				System.Data.DataTable datatable = new System.Data.DataTable();
				System.Data.DataRow datarow;
				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("进货单价(元)"));

				SqlConnection conn = DBUtil.GetConnection();
				conn.Open();
				SqlCommand cmd = new SqlCommand(query, conn);
				SqlDataReader reader = cmd.ExecuteReader();
				while (reader.Read())
				{
					datarow = datatable.NewRow();
					datarow[0] = reader["PurchaseRecordID"];
					datarow[1] = reader["PurchaseDate"];
					datarow[2] = reader["GoodsName"];
					datarow[3] = reader["EmployeeName"];
					datarow[4] = reader["Name"];
					datarow[5] = reader["PurchaserNumber"];
					datarow[6] = reader["PurchaseUnitPrice"];
					datatable.Rows.Add(datarow);
				}
				System.Data.DataView dataview = new System.Data.DataView(datatable);
                dataview.AllowNew = false;
				dataview.AllowEdit = false;
				dataview.AllowDelete = false;
			
				m_dataGrid.DataSource = dataview;
				m_sqlConn.Close();

			}
			catch(SqlException ex)
			{
				MessageBox.Show("打开数据库出错!");
			}
		}
	}
}

⌨️ 快捷键说明

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