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

📄 form1.cs

📁 Visual C#2005程序设计教程
💻 CS
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace WinApp9_11商品统计
{
	/// <summary>
	/// Form1 的摘要说明。
	/// </summary>
	public class Form1 : System.Windows.Forms.Form
	{
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.Label label3;
		/// <summary>
		/// 必需的设计器变量。
		/// </summary>
		private System.ComponentModel.Container components = null;

		public Form1()
		{
			//
			// 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.label1 = new System.Windows.Forms.Label();
			this.label2 = new System.Windows.Forms.Label();
			this.label3 = new System.Windows.Forms.Label();
			this.SuspendLayout();
			// 
			// label1
			// 
			this.label1.AutoSize = true;
			this.label1.Font = new System.Drawing.Font("宋体", 10.8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.label1.Location = new System.Drawing.Point(32, 40);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(62, 24);
			this.label1.TabIndex = 0;
			this.label1.Text = "label1";
			// 
			// label2
			// 
			this.label2.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
			this.label2.Font = new System.Drawing.Font("宋体", 10.8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.label2.Location = new System.Drawing.Point(32, 64);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(480, 88);
			this.label2.TabIndex = 1;
			this.label2.Text = "label2";
			// 
			// label3
			// 
			this.label3.AutoSize = true;
			this.label3.Font = new System.Drawing.Font("宋体", 10.8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.label3.Location = new System.Drawing.Point(32, 160);
			this.label3.Name = "label3";
			this.label3.Size = new System.Drawing.Size(62, 24);
			this.label3.TabIndex = 2;
			this.label3.Text = "label3";
			// 
			// Form1
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(8, 18);
			this.ClientSize = new System.Drawing.Size(544, 224);
			this.Controls.Add(this.label3);
			this.Controls.Add(this.label2);
			this.Controls.Add(this.label1);
			this.Name = "Form1";
			this.Text = "Form1";
			this.Load += new System.EventHandler(this.Form1_Load);
			this.ResumeLayout(false);

		}
		#endregion

		/// <summary>
		/// 应用程序的主入口点。
		/// </summary>
		[STAThread]
		static void Main() 
		{
			Application.Run(new Form1());
		}

		private void Form1_Load(object sender, System.EventArgs e)
		{
			label1.Text = "品牌   仓库1  仓库2  仓库3  仓库4  仓库5    合计";
			string [ ,] goods=new string[4,6];			// 定义一个2维数组
			goods[0, 0] = "联想" ; goods[0, 1] ="10";goods[0, 2] ="50";		// 向数组赋值
			goods[0, 3] ="70";goods[0, 4] ="10"; goods[0, 5] ="10";
			goods[1, 0] = "方正" ;goods[1, 1] ="15"; goods[1, 2] ="10";
			goods[1, 3] ="80";goods[1, 4] ="13"; goods[1, 5] ="80";
			goods[2, 0] ="同方" ; goods[2, 1] ="50"; goods[2, 2] ="80";
			goods[2, 3] ="10"; goods[2, 4] ="40"; goods[2, 5] ="10";
			goods[3, 0] = "戴尔" ;goods[3, 1] ="60"; goods[3, 2] ="90";
			goods[3, 3] ="30";goods[3, 4] ="50";goods[3, 5] ="15";
			label2.Text = "";
			label3.Text = "合计     ";
			this.Text = "商品统计";
			int i, j, sum=0, total=0;   // i、j为循环变量,sum、total用于存放合计数据
			for (i=0;i<4;i=i+1)		// 显示行数据(包括合计值)
			{	for (j=0;j<6;j=j+1)
				{	label2.Text = label2.Text + goods[i, j] + "     ";
					if (j !=0) sum = sum + int.Parse(goods[i, j]);}		//第一列数据为名称不参与统计
				label2.Text =label2.Text +sum + "\n";
				total = total + sum;
				sum = 0;}
			for (i=1;i<6;i=i+1)		//在Label3中显示仓库合计值及总合计
			{	for (j=0;j<4;j=j+1)
					sum = sum + int.Parse(goods[j, i]);
				label3.Text = label3.Text+ sum +"    ";
				sum = 0;}
			label3.Text = label3.Text+ total;
		}
	}
}

⌨️ 快捷键说明

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