資源簡介
本系統是沒有經過數據庫的系統,可以直接讀取EXCEL文件的一類考試系統

代碼片段和文件信息
using?System;
using?System.Collections.Generic;
using?System.Linq;
using?System.Text;
using?System.Windows.Forms;
using?System.Data.OleDb;
using?System.Data;
/**************
?*?作者:李星
?*?時間:2013-11-11
?*?功能:知識競賽系統(獲取數據支撐類)
?*?************/
namespace?Exam
{
????class?DBHelper
????{
????????//定義全局數據存儲容器
????????static?DataTable?dt?=?null;
????????#region--獲取基礎數據--
????????///?
????????///?選擇文件(目前沒此需求)
????????///?
????????private?static?string?WriteExcel()
????????{
????????????string?filePath?=?““;
????????????try
????????????{
????????????????//獲取Excel文件路徑和名稱??
????????????????OpenFileDialog?odXls?=?new?OpenFileDialog();
????????????????//?指定相應的打開文檔的目錄??
????????????????odXls.InitialDirectory?=?“C://“;
????????????????//?設置文件格式??
????????????????odXls.Filter?=?“Excel?files?(*.xls)|*.xls“;
????????????????odXls.FilterIndex?=?2;
????????????????odXls.RestoreDirectory?=?true;
????????????????if?(odXls.ShowDialog()?==?DialogResult.OK)
????????????????{
????????????????????filePath?=?odXls.FileName;
????????????????}
????????????}
????????????catch?(Exception?Ex)
????????????{
????????????}
????????????return?filePath;
????????}
????????///?
????????///?顯示數據
????????///?
????????public?static??DataTable?ShowTable()
????????{
????????????//string?fileName?=?WriteExcel();
????????????string?fileName?=?“tiku.xls“;
????????????OleDbConnection?ole?=?null;
????????????OleDbDataAdapter?da?=?null;
???????????
????????????string?strConn?=?“Provider=Microsoft.Jet.OLEDB.4.0;“
?????????????????????????????+?“Data?Source=“?+?fileName?+?“;“
?????????????????????????????+?“Extended?Properties=Excel?5.0“;
????????????string?strExcel?=?“select?*?from?[比賽$]“;
????????????try
????????????{
????????????????ole?=?new?OleDbConnection(strConn);
????????????????ole.Open();
????????????????da?=?new?OleDbDataAdapter(strExcel?ole);
????????????????dt?=?new?DataTable();
????????????????da.Fill(dt);
???????????????
???????????????
????????????????ole.Close();
????????????}
????????????catch?(Exception?Ex)
????????????{
????????????????MessageBox.Show(Ex.Message);
????????????}
????????????finally
????????????{
????????????????if?(ole?!=?null)
????????????????????ole.Close();
????????????}
????????????return?dt;
????????}
????????#endregion
????????#region---把獲取得到的數據放入DataTable---
???????
????????public?static?DataTable?GetQuestion(string?name)
????????{
????????????DataTable?newdt?=?new?DataTable();
????????????if?(dt?!=?null)
????????????{
????????????????
????????????????newdt.Columns.Add(“Flag“?typeof(string));
????????????????newdt.Columns.Add(“Name“?typeof(string));
????????????????newdt.Columns.Add(“Item“?typeof(string));
????????????????newdt.Columns.Add(“Answer“?typeof(string));
????????????????foreach?(?DataRow?row??in?dt.Rows?)
????????????????{
????????????????????if?(!row[“Flag“].ToString().Trim().Equals(““)?&&?row[“Flag
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件??????29184??2013-11-14?13:51??Exam\bin\Debug\Exam.exe
?????文件??????54784??2013-11-14?13:51??Exam\bin\Debug\Exam.pdb
?????文件??????14328??2013-11-17?12:27??Exam\bin\Debug\Exam.vshost.exe
?????文件????????490??2009-06-11?05:14??Exam\bin\Debug\Exam.vshost.exe.manifest
?????文件??????31232??2013-11-12?08:19??Exam\bin\Debug\tiku.xls
?????文件??????31232??2013-11-12?08:19??Exam\bin\Debug\tiku.xls~RF12f97b.TMP
?????文件???????3866??2013-11-11?20:18??Exam\DBHelper.cs
????......R??????5056??2013-11-11?20:23??Exam\Exam.csproj
?????文件????????257??2013-11-10?10:08??Exam\Exam.csproj.vspscc
?????文件???????1605??2013-11-12?11:34??Exam\Exam.sln
????..A..H.?????22016??2013-11-17?12:29??Exam\Exam.suo
?????文件????????256??2013-11-10?10:08??Exam\Exam.vssscc
????......R???????624??2013-11-10?08:46??Exam\frmBct.cs
????......R??????2344??2013-11-08?10:30??Exam\frmBct.Designer.cs
????......R??????5814??2013-11-08?10:30??Exam\frmBct.resx
????......R???????610??2013-11-10?08:47??Exam\frmRwt.cs
????......R??????2353??2013-11-08?10:30??Exam\frmRwt.Designer.cs
????......R??????5814??2013-11-08?10:30??Exam\frmRwt.resx
?????文件???????3715??2013-11-11?11:18??Exam\frmXzt.cs
?????文件??????14305??2013-11-11?11:18??Exam\frmXzt.Designer.cs
?????文件??????11117??2013-11-11?11:18??Exam\frmXzt.resx
?????文件???????9638??2013-11-14?13:51??Exam\Main.cs
?????文件??????11558??2013-11-14?13:41??Exam\Main.Designer.cs
?????文件???????6582??2013-11-14?13:41??Exam\Main.resx
?????文件????????223??2013-11-12?08:21??Exam\mssccprj.scc
?????文件????????510??2013-11-17?12:27??Exam\obj\Debug\Exam.csproj.FileListAbsolute.txt
?????文件???????1023??2013-11-14?13:41??Exam\obj\Debug\Exam.csproj.GenerateResource.Cache
?????文件??????29184??2013-11-14?13:51??Exam\obj\Debug\Exam.exe
?????文件????????180??2013-11-14?13:41??Exam\obj\Debug\Exam.frmBct.resources
?????文件????????180??2013-11-14?13:41??Exam\obj\Debug\Exam.frmRwt.resources
............此處省略25個文件信息
- 上一篇:c#自定義透明按鈕控件
- 下一篇:WPF 環形菜單控件
評論
共有 條評論