All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
PHP动态网页编程:include()与require()的对比_php资料_编程技术
.net操纵xml文件类
ASP.NET,表单验证
优化php代码42种方法总结_[PHP教程]
SQL初学者教程:学会使用SQL UPDATE语句_[SQL Server教程]
如何在十天内学会php之第七天_php资料_编程技术
使用ASP.NET语法创建Web服务器控件模板_[Asp.Net教程]
DataGrid和DataList中CommandButton的问题_[Asp.Net教程]
ASP.NET实例:手把手教你如何扩展GridView之自动排序篇_[Asp.Net教程]
Asp.net日期字符串格式化显示方法_[Asp.Net教程]
Reading number is top 10 pictures
The money of more than 100 countries and regions1
Sell the barbecue as says father du breul1
中国的十元人民币的秘密
Parking technology is great, that give you the keys can't stolen
这玉米,买还是不卖?
8090后结婚的各种XX事
Absolutely shocked. National geographic 50 animal photographys4
Gang rape
Very beautiful interior decoration
XuRe xuan cool and refreshing photoes2
Download software ranking
WebService在.NET中的实战应用教学视频 → 第3集
传奇私服架设教程
WebService在.NET中的实战应用教学视频 → 第2集
株洲本地在线棋牌游戏
The Bermuda triangle1
塘西风月痕
Professional killers2 for Android
Unix video tutorial4
XML+Web+Service开发教程
虚拟机5.5.3版
qq published in(发表于) 2014/7/11 9:24:05 Edit(编辑)
C#教程:建立动态链接库

C#教程:建立动态链接库

C#教程:建立动态链接库

建立动态链接库

创建动态链接库步骤如下所示。

(1)创建一个项目,项目类型为动态链接库,设置其名称为Ex35_01,单击【确定】按钮。

(2)引用EnterpriseServices,选择“项目”/“添加引用”,弹出“添加引用”对话框,如图1所示,在列表中选择System. EnterpriseServices,单击【确定】按钮即可。

(3)在“解决方案资源管理器”窗口中,将Class1.cs文件改名为Account.cs文件。

(4)在Account.cs程序文件中,引用命名空间System.Data、System.Data.SqlClient、using System.Diagnostics、System.EnterpriseServices,代码如下:



图1 引用EnterpriseServices

using System;

using System.Collections.Generic;

using System.Text;

using System.EnterpriseServices;

using System.Data;

using System.Data.SqlClient;

using System.Diagnostics;

namespace Ex35_01

{

public class Account

{

//在此编写类中的方法

}

}

自定义Saveing方法用于银行转账业务中的存款,并且将存款日志写入到Windows系统事件查看器中。代码如下:

public void Saveing(string bank, float balance, string account)

{

try

{

SqlConnection con = new SqlConnection("Server=(local);DataBase=db_35;uid=sa;pwd=;");

con.Open();

SqlCommand cmd = new SqlCommand("UPDATE " + bank + " set balance = balance + " + Convert.ToSingle (balance) + " WHERE account = '"+account+"'", con);

int i = (int)cmd.ExecuteNonQuery();

con.Close();

WriteInfo(DateTime.Now.ToString() + " 银行名称:" + bank + " 账号:" + account + "存入金额为:" + balance.ToString());

}

catch (Exception ex)

{

WriteError(ex.Message);

throw new Exception(ex.Message);

}

}

自定义Fetch方法用于银行转账业务中的取款,并且将存款日志写入到Windows系统事件查看器中。代码如下:

public void Fetch(string bank, float balance, string account)

{

try

{

if (balance > Convert.ToSingle(GetBalance(bank, balance, account)))

{

throw new Exception("银行:" + bank + " 账号:" + account + "余额不足!");

}

SqlConnection con = new SqlConnection("Server=(local);DataBase=db_35;uid=sa;pwd=;");

con.Open();

SqlCommand cmd = new SqlCommand("UPDATE " + bank + " SET balance = balance - " + Convert.ToSingle (balance) + " WHERE (account = '"+account+"')", con);

int i = (int)cmd.ExecuteNonQuery();

con.Close();

WriteInfo(DateTime.Now.ToString() + " 银行名称:" + bank + " 账号:" + account + "提取金额为:" + balance. ToString());

}

catch (Exception ex)

{

WriteError(ex.Message.ToString());

throw new Exception(ex.Message);

}

}

自定义GetBalance方法主要用于获取储蓄账号中的余额,并且在转账过程中判断余额是否充足。代码如下:

public Single GetBalance(string bank, float balance, string account)

{

SqlConnection con = new SqlConnection("Server=(local);DataBase=db_35;uid=sa;pwd=;");

SqlDataAdapter dap = new SqlDataAdapter("select * from " + bank + " where account ='" + account + "'", con);

DataSet ds = new DataSet();

dap.Fill(ds);

return Convert.ToSingle(ds.Tables[0].Rows[0]["balance"].ToString());

}

自定义WriteError方法主要将转账失败信息写入到Windows系统事件查看器中,代码如下:

public void WriteError(string error)

{

EventLog.WriteEntry("示例_01 COM+组件服务", error, EventLogEntryType.Error);

}

自定义WriteInfo方法主要将转账成功信息写入到Windows系统事件查看器中,代码如下:

public void WriteInfo(string info)

{

EventLog.WriteEntry("示例_01 COM+组件服务", info, EventLogEntryType.Information);

}

(5)编写转账类Transfer,添加一个类文件,并设置名称为Transfer.cs。在Transfer.cs程序文件中,引用命名空间System.EnterpriseServices,并且设置COM+组件的属性。代码如下:

using System;

using System.Collections.Generic;

using System.Text;

using System.EnterpriseServices;

namespace Ex35_01

{

//设置COM+属性

[Transaction(TransactionOption.RequiresNew)] //使用新事务创建组件



添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.