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

📄 form_buyandsale.cs

📁 中小型书店图书购书系统
💻 CS
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;

namespace 图书管理系统
{
	/// <summary>
	/// Form_BuyAndSale 的摘要说明。
	/// </summary>
	public class Form_BuyAndSale : System.Windows.Forms.Form
	{
		private System.Windows.Forms.Button butSearch;
		private System.Windows.Forms.Label label3;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.Button butISBN;
		private System.Windows.Forms.Button butAll;
		private System.Windows.Forms.Button butThisYear;
		private System.Windows.Forms.Button butThisQuarter;
		private System.Windows.Forms.ListBox listBox1;
		private System.Windows.Forms.ListBox listBox2;
		private System.Windows.Forms.ListBox listBox3;
		private System.Windows.Forms.Button butsaletime;
		private System.Windows.Forms.Button butsalequantity;
		private System.Windows.Forms.TextBox Max;
		private System.Windows.Forms.TextBox Min;
		/// <summary>
		/// 必需的设计器变量。
		/// </summary>
		private System.ComponentModel.Container components = null;

		public Form_BuyAndSale()
		{
			//
			// 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()
		{
			System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form_BuyAndSale));
			this.butSearch = new System.Windows.Forms.Button();
			this.label3 = new System.Windows.Forms.Label();
			this.Max = new System.Windows.Forms.TextBox();
			this.Min = new System.Windows.Forms.TextBox();
			this.label2 = new System.Windows.Forms.Label();
			this.label1 = new System.Windows.Forms.Label();
			this.butISBN = new System.Windows.Forms.Button();
			this.butAll = new System.Windows.Forms.Button();
			this.butThisYear = new System.Windows.Forms.Button();
			this.butThisQuarter = new System.Windows.Forms.Button();
			this.listBox1 = new System.Windows.Forms.ListBox();
			this.butsaletime = new System.Windows.Forms.Button();
			this.butsalequantity = new System.Windows.Forms.Button();
			this.listBox2 = new System.Windows.Forms.ListBox();
			this.listBox3 = new System.Windows.Forms.ListBox();
			this.SuspendLayout();
			// 
			// butSearch
			// 
			this.butSearch.BackColor = System.Drawing.Color.Transparent;
			this.butSearch.Location = new System.Drawing.Point(349, 344);
			this.butSearch.Name = "butSearch";
			this.butSearch.Size = new System.Drawing.Size(32, 24);
			this.butSearch.TabIndex = 32;
			this.butSearch.Text = "Go!";
			this.butSearch.Click += new System.EventHandler(this.butSearch_Click);
			// 
			// label3
			// 
			this.label3.BackColor = System.Drawing.Color.Transparent;
			this.label3.Location = new System.Drawing.Point(307, 352);
			this.label3.Name = "label3";
			this.label3.Size = new System.Drawing.Size(40, 16);
			this.label3.TabIndex = 31;
			this.label3.Text = "的书";
			// 
			// Max
			// 
			this.Max.Location = new System.Drawing.Point(251, 344);
			this.Max.Name = "Max";
			this.Max.Size = new System.Drawing.Size(48, 21);
			this.Max.TabIndex = 30;
			this.Max.Text = "";
			// 
			// Min
			// 
			this.Min.Location = new System.Drawing.Point(163, 344);
			this.Min.Name = "Min";
			this.Min.Size = new System.Drawing.Size(50, 21);
			this.Min.TabIndex = 28;
			this.Min.Text = "";
			// 
			// label2
			// 
			this.label2.BackColor = System.Drawing.Color.Transparent;
			this.label2.Location = new System.Drawing.Point(227, 352);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(24, 16);
			this.label2.TabIndex = 29;
			this.label2.Text = "到";
			// 
			// label1
			// 
			this.label1.BackColor = System.Drawing.Color.Transparent;
			this.label1.Location = new System.Drawing.Point(91, 352);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(72, 16);
			this.label1.TabIndex = 27;
			this.label1.Text = "显示销量为";
			// 
			// butISBN
			// 
			this.butISBN.BackColor = System.Drawing.Color.Transparent;
			this.butISBN.Location = new System.Drawing.Point(64, 23);
			this.butISBN.Name = "butISBN";
			this.butISBN.Size = new System.Drawing.Size(136, 24);
			this.butISBN.TabIndex = 24;
			this.butISBN.Text = "ISBN";
			this.butISBN.Click += new System.EventHandler(this.butISBN_Click);
			// 
			// butAll
			// 
			this.butAll.BackColor = System.Drawing.Color.Transparent;
			this.butAll.Location = new System.Drawing.Point(276, 304);
			this.butAll.Name = "butAll";
			this.butAll.Size = new System.Drawing.Size(80, 24);
			this.butAll.TabIndex = 23;
			this.butAll.Text = "查看全部";
			this.butAll.Click += new System.EventHandler(this.butAll_Click);
			// 
			// butThisYear
			// 
			this.butThisYear.BackColor = System.Drawing.Color.Transparent;
			this.butThisYear.Location = new System.Drawing.Point(196, 304);
			this.butThisYear.Name = "butThisYear";
			this.butThisYear.Size = new System.Drawing.Size(80, 24);
			this.butThisYear.TabIndex = 22;
			this.butThisYear.Text = "今年图书";
			this.butThisYear.Click += new System.EventHandler(this.butThisYear_Click);
			// 
			// butThisQuarter
			// 
			this.butThisQuarter.BackColor = System.Drawing.Color.Transparent;
			this.butThisQuarter.Location = new System.Drawing.Point(116, 304);
			this.butThisQuarter.Name = "butThisQuarter";
			this.butThisQuarter.Size = new System.Drawing.Size(80, 24);
			this.butThisQuarter.TabIndex = 17;
			this.butThisQuarter.Text = "本季度图书";
			this.butThisQuarter.Click += new System.EventHandler(this.butThisQuarter_Click);
			// 
			// listBox1
			// 
			this.listBox1.ItemHeight = 12;
			this.listBox1.Location = new System.Drawing.Point(64, 47);
			this.listBox1.Name = "listBox1";
			this.listBox1.Size = new System.Drawing.Size(136, 232);
			this.listBox1.TabIndex = 20;
			// 
			// butsaletime
			// 
			this.butsaletime.BackColor = System.Drawing.Color.Transparent;
			this.butsaletime.Location = new System.Drawing.Point(200, 23);
			this.butsaletime.Name = "butsaletime";
			this.butsaletime.Size = new System.Drawing.Size(112, 24);
			this.butsaletime.TabIndex = 18;
			this.butsaletime.Text = "销售时间";
			this.butsaletime.Click += new System.EventHandler(this.butsaletime_Click);
			// 
			// butsalequantity
			// 
			this.butsalequantity.BackColor = System.Drawing.Color.Transparent;
			this.butsalequantity.Location = new System.Drawing.Point(312, 23);
			this.butsalequantity.Name = "butsalequantity";
			this.butsalequantity.Size = new System.Drawing.Size(96, 24);
			this.butsalequantity.TabIndex = 33;
			this.butsalequantity.Text = "销售数量";
			this.butsalequantity.Click += new System.EventHandler(this.butsalequantity_Click);
			// 
			// listBox2
			// 
			this.listBox2.ItemHeight = 12;
			this.listBox2.Location = new System.Drawing.Point(200, 47);
			this.listBox2.Name = "listBox2";
			this.listBox2.Size = new System.Drawing.Size(112, 232);
			this.listBox2.TabIndex = 35;
			// 
			// listBox3
			// 
			this.listBox3.ItemHeight = 12;
			this.listBox3.Location = new System.Drawing.Point(312, 47);
			this.listBox3.Name = "listBox3";
			this.listBox3.Size = new System.Drawing.Size(96, 232);
			this.listBox3.TabIndex = 36;
			// 
			// Form_BuyAndSale
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("$this.BackgroundImage")));
			this.ClientSize = new System.Drawing.Size(472, 382);
			this.ControlBox = false;
			this.Controls.Add(this.listBox3);
			this.Controls.Add(this.listBox2);
			this.Controls.Add(this.butsalequantity);
			this.Controls.Add(this.butSearch);
			this.Controls.Add(this.label3);
			this.Controls.Add(this.Max);
			this.Controls.Add(this.Min);
			this.Controls.Add(this.label2);
			this.Controls.Add(this.label1);
			this.Controls.Add(this.butISBN);
			this.Controls.Add(this.butAll);
			this.Controls.Add(this.butThisYear);
			this.Controls.Add(this.butThisQuarter);
			this.Controls.Add(this.listBox1);
			this.Controls.Add(this.butsaletime);
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
			this.Name = "Form_BuyAndSale";
			this.StartPosition = System.Windows.Forms.FormStartPosition.Manual;
			this.Text = "Form_BuyAndSale";
			this.Load += new System.EventHandler(this.Form_BuyAndSale_Load);
			this.ResumeLayout(false);

		}
		#endregion

		SQL sql;
		string lastSQL="";
		public void show()
		{
			listBox1.Items.Clear();
			listBox2.Items.Clear();
			listBox3.Items.Clear();
			if(sql.rows.GetLength(0)!=0)
			{
				for(int i=0;i<sql.rows.GetLength(0);i++)
				{
					listBox1.Items.Add(sql.rows[i,0].ToString());
					listBox2.Items.Add(sql.rows[i,1].ToString());
					listBox3.Items.Add(sql.rows[i,2].ToString());
				}
			}
			else
			{
				listBox1.Text="";
				listBox2.Text="";
				listBox3.Text="";
				MessageBox.Show("无符合查询条件的结果!","提示");
			}
		}

		private void Form_BuyAndSale_Load(object sender, System.EventArgs e)
		{
			sql=new SQL("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=图书管理系统数据库.mdb");
			sql.ExecuteSQL("select * from 图书销售情况表");
			show();
			lastSQL="select * from 图书销售情况表 ";
		}

		private void butISBN_Click(object sender, System.EventArgs e)
		{
			sql.ExecuteSQL(lastSQL+" order by bookISBN");
			show();
		}

		private void butsaletime_Click(object sender, System.EventArgs e)
		{
			sql.ExecuteSQL(lastSQL+" order by saledate");
			show();
		}

		private void butsalequantity_Click(object sender, System.EventArgs e)
		{
			sql.ExecuteSQL(lastSQL+" order by salequantity");
			show();
		}

		private void butThisQuarter_Click(object sender, System.EventArgs e)
		{
						
			int month=System.DateTime.Now.Month;
			int space=(3-month%3)%3;
			string min=System.DateTime.Now.Year.ToString()+STR.add0(Convert.ToString(month+space-2))+"00";
			string max=System.DateTime.Now.Year.ToString()+STR.add0(Convert.ToString(month+space))+"99";
			sql.ExecuteSQL("select * from 图书销售情况表 where saledate>'"+min+"' and saledate<'"+max+"'");
			show();
			lastSQL="select * from 图书销售情况表 where saledate>'"+min+"' and saledate<'"+max+"'";
		}

		private void butThisYear_Click(object sender, System.EventArgs e)
		{
			string min=System.DateTime.Now.Year.ToString()+"0000";
			string max=System.DateTime.Now.Year.ToString()+"9999";
			sql.ExecuteSQL("select * from 图书销售情况表 where saledate>'"+min+"' and saledate<'"+max+"'");
			show();
			lastSQL="select * from 图书销售情况表 where saledate>'"+min+"' and saledate<'"+max+"'";
		}

		private void butAll_Click(object sender, System.EventArgs e)
		{
			sql.ExecuteSQL("select * from 图书销售情况表");
			show();
			lastSQL="select * from 图书销售情况表 ";
		}

		private void butSearch_Click(object sender, System.EventArgs e)
		{
			try
			{
				int.Parse(Min.Text);
				int.Parse(Max.Text);
			}
			catch
			{
				MessageBox.Show("数值格式不正确!");
				Min.Text="";
				Max.Text="";
				return;
			}
			if(int.Parse(Min.Text)>int.Parse(Max.Text))
			{
				MessageBox.Show("最小值应小于或等于最大值!","提示");
				Min.Text="";
				Max.Text="";
				return;
			}
			sql.ExecuteSQL("select * from 图书销售情况表 where salequantity between "+Min.Text+" and "+Max.Text);
			show();
			lastSQL="select * from 图书销售情况表 where salequantity between "+Min.Text+" and "+Max.Text;
		}
	}
}

⌨️ 快捷键说明

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