我知道:這類工具在網上已有不少。但下載後一試用,很是不爽!
要麼過於龐大,使用起來比較複雜,似乎殺雞焉用牛刀;
要麼太過簡單,使用起來難以滿足我的需求。
而此工具要做到既小巧,又實用,可謂之“眾裡尋他千百度,擺渡百度無覓處” ^_^
No way out, do it yourself ! so, 有了下文 。。。
根據實際需求,站在使用者角度,編寫了此工具。
本人之此工具,不可謂之很有技術含量,但一定小巧實用;
本人之此工具,不可謂之多麼強大完美,但一定體貼入微;
實現功能:
1、能自動獲得使用者資料庫中的所有資料表;
2、能根據使用者所選的資料表,自動產生實體類;
3、能根據使用者的需求和選擇,動態產生建構函式;
4、文本顯示實現了關鍵字彩色區分;
5、能一鍵複製到剪下板中,供使用者拷貝;
6、能自動產生 C# 實體類的(*.cs)代碼檔案;
介面:
SQL語句參考代碼:
SQL代碼
use master
go
-- 查看 DBMS 中所有對象
select * from sysobjects
-- 查看 DBMS 中所有資料庫
select * from sysdatabases
------------------------------------------------------
use yourDataBase
go
-- 查看"yourDataBase"資料庫中所有的表
select * from yourDataBase.information_schema.tables
-- 查看"yourDataBase"資料庫中所有的欄位
select * from yourDataBase.information_schema.columns
-- 查看"yourDataBase"資料庫中,"yourTable"表的相關欄位的屬性
select column_name,data_type --資料類型
from yourDataBase.information_schema.columns
where table_name='yourTable'
select column_name,is_nullable --是否為空白
from yourDataBase.information_schema.columns
where table_name='yourTable'
C#語句參考代碼:
C#代碼
// 1 提供將資料置於系統剪貼簿中以及從中檢索資料的方法。
Clipboard.SetDataObject(richTextBox1.Text);
// 2 讓瀏覽器開啟超連結位址
private void richTextBox1_LinkClicked(object sender, LinkClickedEventArgs e)
{
System.Diagnostics.Process.Start(e.LinkText);
// 或 System.Diagnostics.Process.Start("IExplore.exe", e.LinkText);
}
// 3 改變關鍵字的顏色
private void changeColor(string keyword) // keyword 關鍵字
{
int n_bool = 0;
int start = 0;
while (n_bool != -1)
{
n_bool = txtEntityClass.Find(keyword, start,
RichTextBoxFinds.WholeWord | RichTextBoxFinds.MatchCase);
start = (n_bool == 1) ? start + keyword.Length : start + 1;
txtEntityClass.SelectionColor = Color.Blue;
}
}
// 4 可以考慮將 RichTextBox 控制項替換為 WebBrowser 控制項;
實體類產生工具[下載]
補記:
1. 對資料庫中少用的資料類型,在C#語言中補充了相互關聯類型的映射;
2. 修複了C#產生欄位的順序沒按照資料庫表中欄位的順序的BUG;
感謝“永遠的阿哲”所提供的反饋!