📄 doclib.cs
字号:
using System;
using System.Data;
using System.Data.SqlClient;
namespace Njnu.DAL
{
/// <summary>
/// DocLib 的摘要说明。
/// </summary>
public class DocLib
{
/// <summary>
/// 添加Doc文档,文档编号时用
/// </summary>
/// <param name="doc">文档对象</param>
/// <param name="tableName">待插入的表名</param>
/// <returns></returns>
public bool AddDoc(Common.Doc doc, string tableName)
{
SqlParameter[] parameters = {};
int effectCount = 0;
string str = "insert " + tableName + "(docID, cateID, docPath) values('" + doc.DocID + "','" + doc.CateID + "','" + doc.Path + "')";
using(SqlDatabase sqlDB = new SqlDatabase(str, parameters))
{
effectCount = (int)sqlDB.Run();
}
return ( ( effectCount==1?true:false) );
}
//设置文档已处理
public bool SetDone(Common.Doc doc, string tableName)
{
SqlParameter[] parameters = {};
int effectCount = 0;
string str = "update " + tableName + " set IsDone = 1 where docID = '" + doc.DocID +"'";
using(SqlDatabase sqlDB = new SqlDatabase(str, parameters))
{
effectCount = (int)sqlDB.Run();
}
return ( ( effectCount==1?true:false) );
}
//获取未处理过的文档
public DataTable GetAllDoc(string tableName)
{
DataTable dt = new DataTable();
SqlParameter[] parameters = {};
string str = "select * from " + tableName + " where isDone = 0";
using(SqlDatabase sqlDB = new SqlDatabase(str, parameters))
{
sqlDB.Run(dt);
}
return dt;
}
//获取所有测试文档
public DataTable GetAllTestDoc()
{
DataTable dt = new DataTable();
SqlParameter[] parameters = {};
string str = "select * from DocInforLib_test";
using(SqlDatabase sqlDB = new SqlDatabase(str, parameters))
{
sqlDB.Run(dt);
}
return dt;
}
//获取文档总数,在tf*idf公式中用到
public int GetDocCount()
{
DataTable dt = new DataTable();
SqlParameter[] parameters = {};
string str = "select count(docID) from DocInforLib";
using(SqlDatabase sqlDB = new SqlDatabase(str, parameters))
{
sqlDB.Run(dt);
}
return Convert.ToInt32( dt.Rows[0][0] );
}
//获取某一个类别的文档总数,在合并特征项时用到
public int GetDocCountByCateID(string cateID)
{
DataTable dt = new DataTable();
SqlParameter[] parameters = {};
string str = "select count(docID) from DocInforLib where cateID = '" + cateID + "'";
using(SqlDatabase sqlDB = new SqlDatabase(str, parameters))
{
sqlDB.Run(dt);
}
return Convert.ToInt32( dt.Rows[0][0] );
}
//获取测试文档的文件名
public string GetDocName(string docID)
{
DataTable dt = new DataTable();
SqlParameter[] parameters = {};
string str = "select docPath from DocInforLib_test where docID = '" + docID + "'";
using(SqlDatabase sqlDB = new SqlDatabase(str, parameters))
{
sqlDB.Run(dt);
}
int i = dt.Rows[0][0].ToString().LastIndexOf("\\");
int a =dt.Rows[0][0].ToString().Length;
string docPath = dt.Rows[0][0].ToString();
string docName = docPath.Substring(i, a-i);
return docName;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -