快速搭建ERP的資料庫框架

2021-04-17 05:45:08 字數 4725 閱讀 3966

(本文以sql server為資料庫伺服器,t-sql是標準sql語言的擴充。)在

erp的軟體中,資料庫是它的靈魂。每乙個

erp軟體都有自己的資料庫,而這些資料庫中最關鍵的是

資料庫框架。那麼什麼是

資料庫框架?他的

作用是什麼?為什麼要在安裝時搭建資料庫框架?本文就來解答這些問題。

在編寫erp,mis,s/b等資料庫的應用程式時,首先要做的一件事就是建立資料庫框架,它至少包括:資料庫和資料庫中的表,當然還有檢視、儲存過程等,這就是資料庫框架(不含具體的資料)。然後是使用vb,vc,vfp,pb等程式語言開發使用者介面,接受使用者對資料庫的操作。當你成功的開發了乙個erp軟體後,你需要將它打包,最後交給客戶安裝並使用。這時就有乙個問題,當你打包的時候,不可以將sql server打包到安裝程式中,所以使用者在使用時就必須先建立資料庫框架,而使用者並不知道資料庫的框架結構,erp軟體又必須訪問特定的資料庫框架才可以成功執行,這時我們就需要有乙個可以自動生成資料庫框架的程式。舉個例:當開發乙個人力資源管理系統時,需要乙個資料庫框架,這最起碼在資料庫包含乙個表,表中包含姓名,年齡,工資等資訊,然後通過客戶端來訪問這個表。如果沒有這個表,程式就不可能成功的執行。現在大家清楚了什麼是資料庫框架和他的作用了吧!

現在的erp軟體中都帶有自動生成資料庫框架的功能,不同軟體的實現方法不同,總結一下,大約有3種:

1.以嚮導的形式出現;

2.在安裝時以配置系統的形式出現;

3.整合在主程式中,當主程式第一次執行的時候自動生成資料庫框架。

不論是那種方式,他們的用途都是一樣。    

如果大家有《管家婆》的erp,可以安裝來看看。它要求先安裝sql server ,安裝完後開啟sql server你會發現sql server資料庫中只有它預設的幾個資料庫,並沒什麼不同。接著開始安裝《管家婆》,安裝完後隨便用一下他的功能,再大開sql server你會發現,資料庫已不同了,增加了一些資料庫(增加的資料庫因使用的功能和《管家婆》的版本不同而不同)。這些增加的資料庫就是為了使用資料庫框架自動生成。

那麼,如何用程式實現自動生成資料庫框架?現在,我們就來建立乙個這樣的程式。在本程式中共建立5個按鈕分別是:建立資料庫,建立表,建立約束,建立儲存過程,顯示資料。實現的**如下:

public class form1

inherits system.windows.forms.form

private sub button1_click(byval sender as system.object, byval e as system.eventargs)

handles button1.click

dim con as new oledb.oledbconnection("provider=sqloledb.1;integrated

security=sspi;persist security info=false;initial catalog=northwind;data

source=.;use procedure for prepare=1;auto translate=true;packet

size=4096;workstation id=j;use encryption for data=false;tag with column collation

when possible=false")

con.open()

dim cmd as new oledb.oledbcommand("create database jk", con)

cmd.executenonquery()

con.close()

'建立資料庫

end sub

private sub button2_click(byval sender as system.object, byval e as

system.eventargs) handles button2.click

dim con2 as new oledb.oledbconnection("provider=sqloledb.1;integrated

security=sspi;persist security info=false;initial catalog=jk;data source=.;use

procedure for prepare=1;auto translate=true;packet size=4096;workstation id=j;use

encryption for data=false;tag with column collation when possible=false")

con2.open()

dim cmd as new oledb.oledbcommand("create table kk(id int identity(1,1) not

null constraint id primary key,name char(4) not null)", con2)

cmd.executenonquery()

dim cmd2 as new oledb.oledbcommand("create table pp(id int not null,ads

char(20) null)", con2)

cmd2.executenonquery()

con2.close()

'建立2個表

end sub

private sub button3_click(byval sender as system.object, byval e as

system.eventargs) handles button3.click

dim con2 as new oledb.oledbconnection("provider=sqloledb.1;integrated

security=sspi;persist security info=false;initial catalog=jk;data source=.;use

procedure for prepare=1;auto translate=true;packet size=4096;workstation id=j;use

encryption for data=false;tag with column collation when possible=false")

con2.open()

dim com as new oledb.oledbcommand("alter table pp add primary key (id)",

con2)

com.executenonquery()

con2.close()

'建立約束

end sub

private sub button4_click(byval sender as system.object, byval e as

system.eventargs) handles button4.click

dim con2 as new oledb.oledbconnection("provider=sqloledb.1;integrated

security=sspi;persist security info=false;initial catalog=jk;data source=.;use

procedure for prepare=1;auto translate=true;packet size=4096;workstation id=j;use

encryption for data=false;tag with column collation when possible=false")

con2.open()  

dim com as new oledb.oledbcommand("create proc procname as select * from

kk", con2)

com.executenonquery()

con2.close()

'建立儲存過程

end sub

private sub button5_click(byval sender as system.object, byval e as

system.eventargs) handles button5.click

dim con2 as new oledb.oledbconnection("provider=sqloledb.1;integrated

security=sspi;persist security info=false;initial catalog=jk;data source=.;use

procedure for prepare=1;auto translate=true;packet size=4096;workstation id=j;use

encryption for data=false;tag with column collation when possible=false")

dim com as new oledb.oledbcommand("procname", con2)

dim da as new oledb.oledbdataadapter()

da.selectcommand = com

dim ds as new dataset()

da.fill(ds)

datagrid1.datasource = ds

'顯示資料

end sub

end class

快速搭建ERP的框架

本文以sqlserver為資料庫伺服器,t sql是標準sql語言的擴充。在erp的中,資料庫是它的靈魂。每乙個erp軟體都有自己的資料庫,而這些資料庫中最關鍵的是資料庫框架。那麼什麼是資料庫框架?他的 作用是什麼?為什麼要在安裝時搭建資料庫框架?本文就來解答這些問題。在編寫erp,mis,s b等...

搭建Android資料庫框架(增)

定義乙個idaoinf介面 public inte ce idaoinf實現乙個工廠類 public class daofactory file dbfile new file root,run.db mdatabase sqlitedatabase.openorcreatedatabase dbf...

快速搭建Redis快取資料庫

之前一篇隨筆 redis安裝及主從配置已經詳細的介紹過redis的安裝於配置。本文要講的是如何在已經安裝過redis的機器上快速的建立出乙個新的redis快取資料庫。一 環境介紹 1 linux版本 red hat enterprise linux server release 6.1 santia...