ERP代碼產生器(開源,提供源碼下載)

來源:互聯網
上載者:User

ERP代碼產生器

這個代碼產生器的作用是彌補Code Smith在批量表產生方面的不足。

代碼產生器運行效果

基本的使用方法是,選擇資料庫,左邊的樹會列出資料庫中的所有表,在參數地區,Template會列出目前的目錄下的CodeSmith模板,選擇一個模板,Parameter會列出選中的模板的參數資訊,選擇產生的程式碼的存放路徑為Target Folder

解決方案視圖

下載原始碼到本地後,請先添加程式集引用,包括Code Smith和SMO

SMO是操作SQL Server中繼資料的一套非常有效率的API,以用於擷取SQL Server表資訊

程式碼只有2個表單,主表單和串連資料庫的表單,在啟動主程式後,自動會開啟資料庫連接表單

之後,會在主表單中顯示開啟的資料庫,及它的所有表。

點擊樹節點前的CheckBox,會將該表添加到要產生模板代碼的表中,中間一列是文字框,可以編輯。

Template會列出目前的目錄中所有cst結尾的檔案,這裡沒有驗證該檔案是否是CodeSmith模板檔案

lstTemplate.Items.Clear();

string[] files=Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory, "*.cst");

lstTemplate.Items.AddRange(files);

在參數填寫地區,請用=將參數名和參數值配對填寫

對於Target Folder,表單啟動時會給當前路徑預設值

txtTargetFolder.Text = AppDomain.CurrentDomain.BaseDirectory;

真正實現調用Code Smith模板,產生代碼的方法

CodeTemplateCompiler compiler = new CodeTemplateCompiler(templateFile);

compiler.Compile();

if (compiler.Errors.Count == 0){

CodeTemplate template = compiler.CreateInstance();

DatabaseSchema database = new DatabaseSchema(new SqlSchemaProvider(), connectionString);

TableSchema tableSchema = database.Tables[tableName];

template.Render(writer);

}

 

這就是這個代碼產生器的全部了,關鍵的內容還是在Code Smith模板的編寫

這裡還有一個小問題,請看圖

Table Node和它的CheckBox之前的距離太小,有些不美觀,一直找不到是如何設定參數,能讓CheckBox與Node之間的距離增大一點,以保持美觀。

 

請到http://epn.codeplex.com/擷取最新的代碼和文檔。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.