“常用工具包”

http://wap.oschina.net/project/tag/143?sort=view

NPOI 是 POI 项目的 .NET 版本。POI(http://poi.apache.org/)是一个开源的Java读写Excel、WORD等微软OLE2组件文档的项目。

使用 NPOI 你就可以在没有安装 Office 或者相应环境的机器上对 WORD/EXCEL 文档进行读写。

开发语言: .NET
收录时间:2009年01月22日
主页: http://www.codeplex.com/npoi
下载: http://www.codeplex.com/npoi/Release/ProjectReleases.aspx#ReleaseFiles
JSON.NET,这是一个.NET框架使用的 JSON 解析和操作的类库。

示例代码:

Product product = new Product();
product.Name = "Apple";
product.Expiry = new DateTime(2008, 12, 28);
product.Price = 3.99M;
product.Sizes = new string[] { "Small", "Medium", "Large" };
 
string json = JavaScriptConvert.SerializeObject(product);
//{
//  "Name": "Apple",
//  "Expiry": new Date(1230422400000),
//  "Price": 3.99,
//  "Sizes": [
//    "Small",
//    "Medium",
//    "Large"
//  ]
//}
 
Product deserializedProduct = JavaScriptConvert.DeserializeObject<Product>(json);

 

MyXLS 是一个快速和简单的读写 Excel 文件的 .NET 组件,可用在 ASP.NET 网站和 .NET 应用程序中,无需安装 Excel 程序,支持 Excel 97 以及以后的版本。

示例代码:

XlsDocument doc = new XlsDocument();
doc.FileName = "HelloWorld.xls";
Worksheet sheet = doc.Workbook.Worksheets.Add("Hello World Sheet");
Cell cell = sheet.Cells.Add(1, 1, "Hello!");
cell.Font.Weight = FontWeight.Bold;

doc.Save();

 

开发语言: .NET ASP
收录时间:2009年08月04日
主页: http://myxls.in2bits.org/
文档: http://myxls.in2bits.org/QuickStart.ashx
下载: http://myxls.in2bits.org/Downloads.ashx

iTextSharp 是用来生成 PDF 文档的 C# 组件

开发语言: C#
收录时间:2008年11月11日
主页: http://itextsharp.sourceforge.net/

Report.NET 是一个功能强大且易用的用来生成 PDF 文档的 C# 组件

 

开发语言: C#
收录时间:2008年11月11日
主页: http://report.sourceforge.net/

dnAnalytics 是 .NET 框架的一个数值计算类库。

 

DotNetZip 是一个短小易用的用来操作 zip 文件的 .NET 应用,可以在 .NET 的任何一种语言中使用。

代码示例:

 

 

开发语言: .NET
收录时间:2009年01月14日

PDFsharp is a C# library that easily creates PDF documents on the fly. The same GDI+ like drawing routines can be used to create PDF documents, draw on the screen, or send output to any printer. PDFsharp can also modify, merge, and split existing PDF files or incorporate pages from existing PDF files into new PDF documents.

使用这个API,程序员们就可以通过自己的程序直接生成Word和,PowerPoint,Excel 2007版本的文件,这是OpenXML编程的基础.

 

SharpPDF is a C# library that implements different objects for the creation of PDF documents with few steps. It is created for .NET framework 1.1 and it can create 100% compatible PDF

 

PDFjet是一个用于动态生成PDF文档的Java类库。支持绘制点、线、方框、圆、贝塞尔曲线(Bezier Curves) 、多边形、星形、复杂路径和形状。支持unicode,文本间距调整,嵌入超链接等。它同时有Java和.NET两个版本。

 

开发语言: Java .NET
收录时间:2008年09月12日
主页: http://pdfjet.com/os/edition.html
下载: http://pdfjet.com/java/download.html

SAX dot NET 是 Java 的 SAX API 的 C# 移植版本。

 

开发语言: C#
收录时间:2008年11月11日
主页: http://saxdotnet.sourceforge.net/
下载: http://sourceforge.net/projects/saxdotnet/

NSpring 为 .NET 平台提供了一个易用的集合、日志框架、对象池以及应用开发框架等其他工具。

 

开发语言: C# .NET
收录时间:2009年09月05日
主页: http://sourceforge.net/projects/nspring/
下载: http://sourceforge.net/projects/nspring/files/

开源数据访问组件DAC

 

项目描述:

数据访问组件,提供了一组类库和一个代码生成工具,使.net项目中数据访问更简化.

功能:
  • 多种数据库支持.
  • 提供DataSet, DataTable 和数据实体查询.
  • 执行SQL脚本及存储过程.
  • 条件表达式.
  • 常用SQL方法, 如MAX, MIN等可能被应用在查询中.
  • 数据实体代码及XML文件生成.
使用:
基本功能:
1. 使用 "EntitiesGenerator" 生成工具生成实体项目。
  参见 blog: How to use the "Enties Generator" tool to create an entities project.

2. 添加一个文件名为"connection.config"的数据库连接配置文件,到应用程序的运行目录,文件格式及内容如下:
xml version="1.0" encoding="utf-8" ?>
<connections>
<connection databaseType="SQL">Data Source=./SQLEXPRESS;AttachDbFilename="|DataDirectory|Database1.mdf";
Integrated Security=True;User Instance=True<connection>
<connections>

3. 假定我们有个实体类,名叫 "Issue", 可以使用以下代码将它插入数据库
	RaisingStudio.Data.Providers.DataContext dc = new RaisingStudio.Data.Providers.DataContext();
dc.Insert(issue);

4. 更新实体.
	dc.Update(issue);

5. 删除实体, 可以通过给定实体或实体的主键值进行。
	dc.Delete(issue);

	dc.Delete(issueID);

6. 查询实体, 通过三个不同的方法,可以分别获得 IEnumerable, IList or DataTable 作为返回结果。
	IEnumerable query = dc.Query();
foreach(Issue issue in query)
{
}
	IList issueList = dc.QueryForList();
在查询中,还可以使用“条件表达式”.
	DataTable dataTable = dc.QueryForDataTable(Issue._.IssueID > 1);

7. 可以通过GetData()方法,查询单个实体,使用包含主键值的实体,主键值或条件表达式作为参数。
	Issue issue = new Issue();
issue.IssueID = 2;
issue = dc.GetData(issue);
	Issue issue = dc.GetData(2);
	Issue issue = dc.GetData(Issue._.IssueID == 2);

8. 更新DataTable.
	int result = dc.UpdateDataTable(dataTable);

高级特性:

1. 常用SQL方法, 包括 GetCount, GetMin, GetMax, GetSum and GetAvg.
int result = dc.GetCount();
object minValue = dc.GetMin(Issue._.Progress);
decimal maxValue = Convert.ToDecimal(dc.GetMax(Issue._.Progress,
Issue._.Title == "test title"));

2. Save 和 Exists.
int result = dc.Save(issue);
bool saved = dc.Exists(issue);
bool ex = dc.Exists(Issue._.Title == "test title");

3. 部分列.
Issue issue = dc.GetData(2, Issue._.Status);
issue.Status = IssueStatus.Fixed;
int result = dc.Update(issue, Issue._.Status);

4. 批量操作.
int result = dc.Delete(Issue._.Status == IssueStatus.Fixed);
result = dc.Update(issue, Issue._.Status == IssueStatus.Fixed, Issue._.Status);

5. 排序, 使用 "OrderBy" 方法或  ^ 和  ^ ! 运算符应用在查询中,可以对查询进行排序.
IEnumerable query = dc.Query(Issue.All.OrderBy(Issue._.IssueID));
query = dc.Query(Issue._.Status == IssueStatus.Fixed ^ Issue._.IssueID);

6. 分页.
 IList issueList = dc.QueryForList(Issue.All, 0, 100);

7. 事务.
try
{
this.dc.BeginTransaction();
try
{
int result = this.dc.Insert(issue);
this.dc.CommitTransaction();
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex);
this.dc.RollbackTransaction();
throw;
}
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex);
throw;
}

8. 多主键.
MutipleKeysTable mt = dc.GetData(new object[] { key1, key2 }, 
MutipleKeysTable.Except(MutipleKeysTable._.Value2));

9. 使用 common command 查询.
CommonCommand cmd = new CommonCommand();
cmd.CommandText = string.Format("SELECT [IssueID], [{0}] FROM .[Issue] WHERE [{0}] = @p1", Issue._.Title);
cmd.Parameters.Add("@p1", "test title");
Issue issue = dc.GetData(cmd);

10. 执行 common command, 支持 ExecuteForDataTable, ExecuteForList, ExecuteQuery, ExecuteReader, ExecuteScalar 和 ExecuteNoQuery 等方法.
RaisingStudio.Data.CommonCommand cmd = new CommonCommand(
string.Format("UPDATE .[{0}] SET [{1}] = [{1}] + 1 WHERE [{2}] = @p1",
Issue._, Issue._.Progress, Issue._.IssueID));
cmd.AddParameter("@p1", System.Data.DbType.Int32, maxID);
int result = this.dc.ExecuteNoQuery(cmd);

11. SQL 脚本日志.
DataContext dc = new DataContext();
dc.Log = System.Console.Out;

12. 多种数据库 providers, 添加如下的 xml 项到 "providers.config" 配置文件中, 就可以在 "connections.config" 中使用.
    <provider 
name="MYSQL"
description="MySQL, MySQL provider "
enabled="false"
assemblyName="MySql.Data, Version=5.2.5.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d"
connectionClass="MySql.Data.MySqlClient.MySqlConnection"
commandClass="MySql.Data.MySqlClient.MySqlCommand"
parameterClass="MySql.Data.MySqlClient.MySqlParameter"
parameterDbTypeClass="MySql.Data.MySqlClient.MySqlDbType"
parameterDbTypeProperty="MySqlDbType"
dataAdapterClass="MySql.Data.MySqlClient.MySqlDataAdapter"
commandBuilderClass="MySql.Data.MySqlClient.MySqlCommandBuilder"
usePositionalParameters="false"
useParameterPrefixInSql="true"
useParameterPrefixInParameter="true"
parameterPrefix="?"
allowMARS="false"
/>

13. 自定义数据类型“转换器”,  以下就是一个 "TypeConverter" 示例代码,及如何配置到 "converters.config" 配置文件中.
public class PointConverter : IDbTypeConverter
{
#region IDbTypeConvertermember
public object ConvertFromDbType(object value)
{
string s = value as string;
if (!string.IsNullOrEmpty(s))
{
string[] sa = s.Split(',');
if ((sa != null) && (sa.Length == 3))
{
int x = int.Parse(sa[0]);
int y = int.Parse(sa[1]);
int z = int.Parse(sa[2]);
return new Point(x, y, z);
}
}
return null;
}
public object ConvertToDbType(object value)
{
if (value is Point)
{
Point point = (Point)value;
return point.ToString();
}
return null;
}
#endregion
}
    
dbType="string"
converterType="RaisingStudio.Data.Entities.PointConverter,
RaisingStudio.Data.Entities, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null">
<converter>

14. “实体定义”配置, "*.definition.xml" 文件可以作为资源文件嵌入到程序集在,也可以留在文件系统上,"EntitiesGenerator" 实体生成工具生在项目是采用的嵌入资源的方式, 如果要使用文件的方式,则需要配置一个名叫"definitions.config"的配置文件,样式如下:
xml version="1.0" encoding="utf-8"?>
<definitionsConfig xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<aliases>

<aliases>
<definitions>
<definition name="UTIssue" resource="definitions/Issue.definition.xml" />
<definition name="UTSystemUser" resource="definitions/SystemUser.definition.xml" />
<definitions>
<definitionsConfig>


15. Common command 管理器. 把 SQL脚本配置在 "commands.config" 中后,可以用如下代码读取使用。
xml version="1.0" encoding="utf-8" ?>
<commands parameterPrefix=":">
<command name="select">SELECT * FROM DAC_ISSUE<command>
<command name="select2">

SELECT * FROM DAC_USER
]]>
command>
<command name="select3" commandType="StoredProcedure">SELECT_DAC_ISSUEcommand>
<command name="select4">

SELECT * FROM DAC_ISSUE DI
WHERE DI.ISSUE_ID = :ISSUE_ID
]]>
<command>
<commands>
CommonCommand cmd = CommandManager.Instance.GetCommand("select");
System.Data.DataTable dt = this.dc.ExecuteForDataTable(cmd);

 

 

   try
{
using (ZipFile zip = new ZipFile("MyZipFile.zip")
{
// add this file into the "images" directory in the zip archive
zip.AddFile("c://photos//personal//7440-N49th.png", "images");
// add this file into a different directory in the archive
zip.AddFile("c://Desktop//2005_Annual_Report.pdf", "files");
zip.AddFile("ReadMe.txt");
zip.Save();
}
}
catch (System.Exception ex1)
{
System.Console.Error.WriteLine("exception: " + ex1);
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值