All articles(网络文学目录) All Pictures(图片目录) All Softwares(软件目录)

 
C#教程:COM+组件建立客户端程序

Writer: qq Article type: Programming skills(编程技巧) Time: 2014/7/11 9:22:10 Browse times: 353 Comment times: 0

C#教程:COM+组件建立客户端程序


Head photo

Go homepage
Upload pictures
Write articles

C#教程:COM+组件建立客户端程序

建立客户端程序
下面将建立客户端程序,设计结果如图1所示。详细步骤如下所示。

图1 客户端设计结果图
(1)创建一个项目,项目类型为Windows应用程序,设置其名称为35_02,单击【确定】按钮,项目创建成功。
(2)向Windows窗体添加5个TextBox控件和一个Button控件,它们分别用于输入银行转账信息和执行银行转账命令。
(3)引用EnterpriseServices。选择“项目”/“添加引用”,弹出“添加引用”对话框,在列表中选择System. EnterpriseServices,单击【确定】按钮即可。
(4)添加引用COM+服务组件——引用Ex35_01.DLL即可。选择“项目”/“添加引用”,弹出“添加引用”对话框,然后选择“浏览”选项卡,找到注册Ex35_01.DLL文件位置,如图2所示,最后单击【确定】按钮。

图2 添加COM+服务组件
(5)客户端实现代码。
首先,添加Ex35_01命名空间,其次,声明Transfer服务类对象,通过类对象调用银行转账BankTransfer方法,实现转账功能。完整代码如下:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Ex35_01;
namespace _5_02
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Transfer tt = new Transfer();
bool bl= tt.BankTransfer(txtFromBank.Text, txtFromAccount.Text, txtToBank.Text, txtToAccount.Text, Single. Parse(txtBalance.Text));
if (bl)
MessageBox.Show("银行转账成功!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon. Information);
else
MessageBox.Show("银行转账失败!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
完整程序代码如下:
★★★★★Form1.cs窗体代码文件完整程序代码★★★★★
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Ex35_01;
//using System.EnterpriseServices.CompensatingResourceManager;
namespace _5_02
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Transfer tt = new Transfer();
bool bl= tt.BankTransfer(txtFromBank.Text, txtFromAccount.Text, txtToBank.Text, txtToAccount.Text, Single.Parse(txtBalance.Text));
if (bl)
MessageBox.Show("银行转账成功!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
else
MessageBox.Show("银行转账失败!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
★ ★★★★Form1.Designer.cs窗体设计文件完整程序代码★★★★★
namespace _5_02
{
partial class Form1
{
///


/// 必需的设计器变量。
///

private System.ComponentModel.IContainer components = null;
///
/// 清理所有正在使用的资源。
///

/// 如果应释放托管资源,为 true;否则为 false。
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows 窗体设计器生成的代码
///
/// 设计器支持所需的方法 - 不要
/// 使用代码编辑器修改此方法的内容。
///

private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.txtFromBank = new System.Windows.Forms.TextBox();
this.txtFromAccount = new System.Windows.Forms.TextBox();
this.txtToBank = new System.Windows.Forms.TextBox();
this.txtToAccount = new System.Windows.Forms.TextBox();




There are 0 records,
Comment:
Must be registered users to comment(必须是注册用户才能发表评论)

Disclaimer Privacy Policy About us Site Map
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.