当前位置:编程学习 > C#/ASP.NET >>

C#教学经验谈(3):储蓄计算器的源程序

答案:在C#教学的第二个案例前,先介绍了一个储蓄计算器的实验,该实验项目是从微软的教学光盘中取出的,部分源程序已经给出,要求学生完成事务处理部分。在做这个实验的时候,要求学生最好能够独立设计此项目。在这里,将该项目的代码给出如下。有特点的是,控件的名称使用的是中文。



using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace Saving
{
enum Compound
{
每月计算利息,
每季度计算利息
}
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Label label1;
private System.Windows.Forms.NumericUpDown 初始金额;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.NumericUpDown 利率;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.ComboBox 计算规则;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.Label label6;
private System.Windows.Forms.Button 计算;
private System.Windows.Forms.NumericUpDown 存期;
private System.Windows.Forms.NumericUpDown 每月存入;
private System.Windows.Forms.NumericUpDown 存款总额;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;

public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();

//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
计算规则.Items.Add(Compound.每月计算利息);
计算规则.Items.Add(Compound.每季度计算利息);
计算规则.SelectedItem = 计算规则.Items[0];
}

/// <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.初始金额 = new System.Windows.Forms.NumericUpDown();
this.label2 = new System.Windows.Forms.Label();
this.利率 = new System.Windows.Forms.NumericUpDown();
this.label3 = new System.Windows.Forms.Label();
this.存期 = new System.Windows.Forms.NumericUpDown();
this.label4 = new System.Windows.Forms.Label();
this.计算规则 = new System.Windows.Forms.ComboBox();
this.label5 = new System.Windows.Forms.Label();
this.每月存入 = new System.Windows.Forms.NumericUpDown();
this.label6 = new System.Windows.Forms.Label();
this.存款总额 = new System.Windows.Forms.NumericUpDown();
this.计算 = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.初始金额)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.利率)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.存期)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.每月存入)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.存款总额)).BeginInit();
this.SuspendLayout();
//
// label1
//
this.label1.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.label1.Location = new System.Drawing.Point(32, 32);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(88, 16);
this.label1.TabIndex = 0;
this.label1.Text = "初始金额:";
//
// 初始金额
//
this.初始金额.DecimalPlaces = 2;
this.初始金额.Increment = new System.Decimal(new int[] {
100,
0,
0,
0});
this.初始金额.Location = new System.Drawing.Point(112, 32);
this.初始金额.Maximum = new System.Decimal(new int[] {
-1156317184,
46566128,
0,
0});
this.初始金额.Name = "初始金额";
this.初始金额.Size = new System.Drawing.Size(168, 21);
this.初始金额.TabIndex = 1;
this.初始金额.ThousandsSeparator = true;
this.初始金额.Value = new System.Decimal(new int[] {
1000,
0,
0,
0});
//
// label2
//
this.label2.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.label2.Location = new System.Drawing.Point(32, 72);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(88, 16);
this.label2.TabIndex = 0;
this.label2.Text = "利率(%):";
//
// 利率
//
this.利率.DecimalPlaces = 2;
this.利率.Increment = new System.Decimal(new int[] {
1,
0,
0,
65536});
this.利率.Location = new System.Drawing.Point(112, 72);
this.利率.Name = "利率";
this.利率.Size = new System.Drawing.Size(168, 21);
this.利率.TabIndex = 1;
this.利率.ThousandsSeparator = true;
this.利率.Value = new System.Decimal(new int[] {
20,
0,
0,
65536});
//
// label3
//
this.label3.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.label3.Location = new System.Drawing.Point(32, 112);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(88, 16);
this.label3.TabIndex = 0;
this.label3.Text = "存期(年):";
//
// 存期
//
this.存期.Location = new System.Drawing.Point(112, 112);
this.存期.Name = "存期";
this.存期.Size = new System.Drawing.Size(168, 21);
this.存期.TabIndex = 1;
this.存期.ThousandsSeparator = true;
this.存期.Value = new System.Decimal(new int[] {
5,
0,
0,
0});
//
// label4
//
this.label4.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.label4.Location = new System.Drawing.Point(32, 152);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(88, 16);
this.label4.TabIndex = 0;
this.label4.Text = "计算规则:";
//
// 计算规则
//
this.计算规则.Location = new System.Drawing.Point(112, 152);
this.计算规则.MaxDropDownItems = 2;
this.计算规则.Name = "计算规则";
this.计算规则.Size = new System.Drawing.Size(168, 20);
this.计算规则.TabIndex = 2;
//
// label5
//
this.label5.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.label5.Location = new System.Drawing.Point(32, 192);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(88, 16);
this.label5.TabIndex = 0;
this.label5.Text = "每月存入:";
//
// 每月存入
//
this.每月存入.DecimalPlaces = 2;
this.每月存

上一个:C#执行存储过程的简化
下一个:Regular Expression 正则表达式-1 (C#)

CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,