致 谢
附 录
进货订单信息设置窗体(frmdh)的数据显示与删除的代码如下:
option explicit
public txtsql as string
dim mrc as adodb.recordset
private sub cmdadd_click()
gintdhmode = 1
frmdh1.show 1
end sub
private sub cmddelete_click()
dim txtsql as string
dim intcount as integer
dim mrc as adodb.recordset
dim msgtext as string
if msglist.rows > 1 then
if msgbox("真的要删除编号为" & trim(msglist.textmatrix(msglist.row, 1)) & "的进货单记录吗?", vbokcancel + vbexclamation, "警告") = vbok then
intcount = msglist.row
txtsql = "delete from dh where dh_no ='" & trim(msglist.textmatrix(intcount, 1)) & "'"
set mrc = executesql(txtsql, msgtext)
unload frmdh
frmdh.txtsql = "select dh_no,in_date,ywman,gfdm,wzdm,cxend,sl,in_danj,i_zk,i_zke,bz from dh"
frmdh.show
end if
end if
end sub
private sub cmdmodify_click()
dim intcount as integer
if frmdh.msglist.rows > 1 then
gintdhmode = 2
intcount = msglist.row
if intcount > 0 then
frmdh1.txtsql = "select * from dh where dh_no ='" & trim(msglist.textmatrix(intcount, 1)) & "'"
frmdh1.show 1
else
msgbox "警告", vbokonly + vbexclamation, "请首先选择需要修改的纪录!"
end if
end if
end sub
private sub form_load()
showtitle
showdata
end sub
private sub form_resize()
if me.windowstate <> vbminimized and fmainform.windowstate <> vbminimized then
'边界处理
if me.scaleheight < 10 * lbltitle.height then
exit sub
end if
if me.scalewidth < lbltitle.width + lbltitle.width / 2 then
exit sub
end if
'控制控件的位置
lbltitle.top = lbltitle.height
lbltitle.left = (me.width - lbltitle.width) / 2
msglist.top = lbltitle.top + lbltitle.height + lbltitle.height / 2
msglist.width = me.scalewidth - 200
msglist.left = me.scaleleft + 100
msglist.height = me.scaleheight - msglist.top - 1500
frame2.top = msglist.top + msglist.height + 50
frame2.left = me.scalewidth / 2 - 3000
end if
end sub
public sub formclose()
unload me
end sub
private sub showdata()
dim j as integer
dim i as integer
dim msgtext as string
set mrc = executesql(txtsql, msgtext)
with msglist
.rows = 1
do while not mrc.eof
.rows = .rows + 1
for i = 1 to mrc.fields.count
if not isnull(trim(mrc.fields(i - 1))) then
select case mrc.fields(i - 1).type
case addbdate
.textmatrix(.rows - 1, i) = format(mrc.fields(i - 1) & "", "yyyy-mm-dd")
case else
.textmatrix(.rows - 1, i) = mrc.fields(i - 1) & ""
end select
end if
next i
mrc.movenext
loop
end with
mrc.close
end sub
'显示grid表头
private sub showtitle()
dim i as integer
with msglist
.cols = 12
.textmatrix(0, 1) = "进货单编号"
.textmatrix(0, 2) = "日期"
.textmatrix(0, 3) = "业务员"
.textmatrix(0, 4) = "供应商代码"
.textmatrix(0, 5) = "物资代码"
.textmatrix(0, 6) = "有效期限"
.textmatrix(0, 7) = "数量"
.textmatrix(0, 8) = "进货单价"
.textmatrix(0, 9) = "折扣"
.textmatrix(0, 10) = "总金额"
.textmatrix(0, 11) = "备注信息"
'固定表头
.fixedrows = 1
'设置各列的对齐方式
for i = 0 to 10
.colalignment(i) = 0
next i
'表头项居中
.fillstyle = flexfillrepeat
.col = 0
.row = 0
.rowsel = 1
.colsel = .cols - 1
.cellalignment = 4
'设置单元大小
.colwidth(0) = 1000
.colwidth(1) = 1000
.colwidth(2) = 2000
.colwidth(3) = 1000
.colwidth(4) = 1000
.colwidth(5) = 1000
.colwidth(6) = 1000
.colwidth(7) = 1000
.colwidth(8) = 1000
.colwidth(9) = 1000
.colwidth(10) = 1000
.colwidth(11) = 2000
.row = 1
end with
end sub
private sub msglist_mouseup(button as integer, shift as integer, x as single, y as single)
'右键弹出
if button = 2 and shift = 0 then
end if
end sub
上述代码很好的展示了该窗体的实现和删除的功能。作者: giantling 时间: 2006-6-5 09:17
还有英文的作者: giantling 时间: 2006-6-5 09:17
database programming of visual basic
visual basic conduct and actions applied the " sharp weapon" of development of the procedure also expresses on the database development of applying the procedure, it good interface with mighty control a function makes database plait the distance mulched become simple. but even if such, the database applies the development of the procedure to still calculate top is knowledge( certainly this is very simple of) that vb plait distance inside of a little bit difficult, this is because you not only want to acquaint with the vb inside to weave the distance concerning the database still understand the knowledge of the database. so we introduce first the basic knowledge of the database, be regarded as the warm-up exercise that study database weave distance front!
one, warm-up exercise
needing first avowal is, relation database that database knowledge that we here introduce all point. the so-called relation database is to means data as that the form gather, passing to establish simple form an a kind of database for of relation to defining construction.
i ignore the watch at how saving way in physics in the document in database is, it can see to make an a line for with row, with electronics form is similar with the row. in relation database, the line were called the record, but the row then is called word segment. the underneath is an example of customer's form.
table 1 customer form
customer's number name address city street postal code
1723 doe john 1234 fifth avenue new york ny 1004
3391 smith mary 9876 myrtle levee boston ma 6078
3765 blasé mortimer 2296j river road peoria il 7011
this form inside each an all in formations for is a record, it including particular customer, but each record then included the same type with the word segment of the quantity: customer's number, name etc.
form is logic set that a kind of related information that press a line of arranging with row, similar in single form in work.
each row of the word a database form inside calls a word segment. watch is from every kind of word a definition of its containment of, each word a data for describing its implying. while creating to set up a database, the beard assign for each word segment a the piece belongs to the sex with the other according to the type, biggest length. the word segment can include every kind of word sign, arithmetic figure even sketch.
an information of relevant customer deposits in the line of the form, is called record. by any large, arbitrarily two records for database form to create set up can't be same.
key be a certain word segment( or several words segment) of the form inside, it() for fast inspect but drive index. the key can be unique, and also can then the right and wrong is unique, being decided by it() whether admission repetition. unique key can specify for main key, using each one that come to unique marking form. for example, in anterior example, customer the marking number( customer's number) is the main key of the form, because customer's number was uniquely the marking a customer.
the relation database can be constituted by several forms, form and form can in different way mutually connection. for example, customer's database can also have the form of all order forms of a certain customer in a containment. it only use a customer that an each repetition all customer's information for quoting from that order form, but not in order form, is shown as watch below:
table 2 order the form
order customer's number date contents quantity
14764 3391 2/23/94 27 $22.95
14932 3391 3/17/94 46 $9.57
15108 8765 2/15/96 27 $22.95
in this form, customer the number word segment quoted from the customer's customer in the form number word segment, from but contact the order form with the customer. can see, customer 3391( mary smith) ordered on in february of 94 23 27 item, ordered on in march of 94 17 46 item. use to be called the exterior key to the key that establish the relation, because of it with the main key connection of the " exterior" form( customer's form).
a rightness of many relate to last relation in the form type more to be called a rightness of much relating to with many rightness, a certain and particular order form can be a customer a hair because a customer can send out several order forms, .can also establish many a relation for munchies. for example, the inventory form of the item( stock) that list the all selling:
from the inventory form inside, can see to exists with the stock an at the customer many a relation for mulches. too is to say, a customer can order several stocks item, but a stock item is again can drive several customers order. many right nesses much relates to is to pass two independence a rightness of to much relate to define of, the public" many" form included the exterior key of two other forms. in that example, order goods the s form to is all and mutually with the form of customer( pass customer's number) with inventory form( pass the " contents") the connection. pass these three forms, we can see, the mary smith( customer's number 3391) ordered the straw hat(" contents"27) with the garden gloves(" contents"46), but the mary smith( customer's number 3391) ordered the straw hat with mortimer blaselflatz ( customer's number 8765) all.(" contents"27)if orders goods customer's form with the related word segment of the inventory form and form of" order goods" the word a coupling gets up, establishing a" connection" form, so this relation clearer.
table 4 connection form
order customer's number name contents describe
14764 33391 smith mary 27 straw hat
14932 33391 smith mary 46 garden gloves
15168 8765 blaselfatz mortimer 27 straw hat
the norm turns the database design of mission be method that the data of buildup, but the data of buildup, should can dissolve otiose repetition, and for have the necessary information offering to check to seek the path quickly. for attaining this kind of target but separate information to the process gone to in every kind of independent form, be called the norm turn.
it is complicated process to use many appointed rules to proceed the norm with the type of the different class that norm turn. that process studies and discuss already beyond the reach of textual scope. but, the norm of the simple database in majority turn and can use the simple experience in underneath rule completes: include the form of the information of repetition must be divided into independent a few forms dissolve repetition.
for example, make student with course to should of student's database, included the next the information that watch show.
table 5
student course describe professor
1 4 introduction to physiology dawson
2 3 applied basketweaing carruth
3 1 physics for short-cooks adams
4 2 introduction to physiology damsons
if have chosen to learn 12 curricular 1000 students, the each curricular elucidation will show with the teacher 100 many- to choose that curricular and each student repeat once. to avoid this kind of low efficiency, should to turn the dichotomous and independent form in form to the norm, an is used to mean the student, the another uses mean the course, such as table 6, table 7 show.
table 6
student course
1 4
2 3
3 1
4 4
table 7
course describe professor
1 physics for short- cooks adams
2 counterculture sociology beckley
3 applied basketweaing carruth
4 introduction to physiology damsons
now the form was turned by the norm, so, to changes the particular and curricular course describe or" data", as long as change a record all right.
is a basic knowledge concerning database above, this is what study database plait distance must. although the database technique is used as a course, its depth is not this space and can describe with the wide degree of, be used as the primer with simple database plait the distance should be all right already.
like, underneath we can start practicing. we usually meet the database system is to registers the system, ignoring you are in the unit, or attend what buildup, the register is to cans not help of, and it of the construction is more simple, we take a register system as an example. the analysis is once a data for involving.
two, understanding the elements
for the register, want the on the trail of information include:
● name ● sex
● native place ● age
● date of birth ● unit
● address ● postal service codes
● telephone ● fax
certainly, can create to set up a form in brief, make above each piece according to item to should a word segment.
need to point the form the main key in parties now, in order to unique marking each a record, increase register number conduct and actions unique key respectively in register form, guarantee a two records like this all different.
to the database after making an above analysis, we can start establishing the database.
three, set up the firm in camp
here we study to establish the database how, needing to make sure the type that to establish the database first. pass in visual basic the data interview control piece or data interview object ( dao) can visit the following database:
1. the database of jet, namely microsoft access
2. the database of isam, such as: dbase, etc. of foxpro
3. the database of odbc, every follow the standard of odbc customer/ server database. such as: microsoft sql server, oracle
by any large, if develop the personal small scaled database system, use access database comparison accommodation, to develop the big and medium-sized database system uses the database of odbc fester. but dbase with the database of foxpro because of already dated, unless special circumstance, do not use otherwise. in our example, chose to use the database of access certainly. establish the database of access contain two kinds of methods: while establishing the database in microsoft access. click" new set up" button can establish the new form.( such as figure 1)here we main introduction the second method: the usage can see to turn the data management machine, do not need to weave the distance and then can create to set up the database. can see to turn the data management machine is the applied procedure of a great use, it is a vb business enterprise version is supplementary with the profession version, in the catalogue\..\ devastation\ vb\ samples\ the visdata is next, its interface is as follows the diagram.
click the menu" document" item is next" new set up" son item" microsoft access" son item of" edition 7.0 mdb" item. input the new setting up the name of the database in flick window way open" register", appear the underneath figure 3 show the window way:
want the born and new form, the single shot in right key database window way flicks the menu open, then the choice" new form" ordinaries, establishing in" watch construction" dialog box appeared later on a word for wanting segment. the every time faces to join in the form new word segment, single shot" increment word segment" button, will appear the figure 4 of" increment word segment" dialog box.
"increment word a type for" options in the dialog box, such as table,10 showing, according to word segment. in our the register database that establish, the type of the each word segment, such as table11.
want to notice of is, because the word segment registers the number be used unique marking record of, therefore, it can't be inputted by customer. so while defining the word's segment need to be defined for long data type, the " automatic born word segment" item is valid, and picks out this item. be the customer like this to input to record with other the different value every input a new record, system would on the word's segment automatically.
in access database, the key word realizes with the index of, conduct and actions plait distance personnel at gather to weave the distance to the record of the form type, needs to adjust to use index. while searching, the technique of rushmore uses the index information the excellent turning the search automatically. after completing the form definition, click" increment index" button, flick such aspen figure 5 show the window way.
in window way the right side contain three optioned, its meaning, such as table,12.
increase the index dialog box options
after completing such as figure 6.
certainly, the academic association database establishes too not a dynasty the business of the one night, the reader no harm much practices once. underneath you can circulate the vb started our plait distance.
four, a long distance meets
applied procedure in the database of visual basic contain three parts, such as figure 7 show.
customer procedure is part that procedure member development of, and also is we will soon weave to write with the vb. the database engine is a database to drive the procedure, using its procedure member can use united format interview every kind of database, whether this database is a native the database of visual basic, or an other the database format of any format for supporting, a data for using interview object is similar to wove distance technique is all. the database is then the part that we up complete. can see from this construction the customer have nothing to do with at the particular database that visit. that we at use the vb the plait write the database procedure, need to can make the procedure visit the appointed database.
if is a simple database applied, can use the data control piece to carry out big and parts of data interview operate, but basic need not plait writes the code. control an a data for or several words segment for controlling mutually and bindingly first piece the automatic manifestation comes from the front record with the data.作者: sdkdming 时间: 2006-12-2 18:11