附录 2
新华书店进销存管理系统部分程序源代码
1、 主程序 程序代码
SET DEFAULT TO C:\毕业设计
PUBLIC nkfgl,nxsgl,ncggl,nkcgl,nxtgl
STORE .f. TO nkfgl,nxsgl,ncggl,nkcgl,nxtgl
PUBLIC nname,ndepartment
STORE "" TO nname,ndepartment
Do Form loginf
Read Events
Do Form main
Read Events
Quit
2、 主表单 代码
表单 Init 过程程序代码
do with this,.T.
= nname
= ndepartment
3、 系统登入表单 代码
表单登入按钮 Click 事件程序代码
SELECT user
GO TOP
*检查用户名和密码是否输入
If empty() then
= "请输入用户名"
return
else
if empty() then
= "请输入密码"
return
endif
endif
*操作 USER 表,查询满足条件记录
locate for name = alltrim()
if !found()
="用户不存在"
return
else
if != alltrim() then
="密码错误"
return
endif
endif
nname =
ndepartment =
nkfgl =
nxsgl =
ncggl =
nkcgl =
nxtgl =
clear events
4、 系统管理表单 代码
表单 Init 过程程序代码
= .f.
= .f.
= .f.
= .f.
= .f.
= .f.
= .f.
= .f.
= .f.
= .f.
= .f.
= .f.
= .f.
_record
_reccommand
表单自定义过程 DIS_RECORD 程序代码
PUBLIC newcommand
STORE .f. TO newcommand
if reccount("user") = 0
= ""
= ""
= ""
= 0
= 0
= 0
= 0
= 0
else
=
=
=
if then
= 1
else
= 0
endif
if then
= 1
else
= 0
endif
if then
= 1
else
= 0
endif
if then
= 1
else
= 0
endif
if then
= 1
else
= 0
endif
endif
表单自定义过程 DIS_RECCOMMAND 程序代码
private n
store 0 to n
n = reccount("user")
if n=1 .or. n=0 then
= .f.
= .f.
= .f.
= .f.
else
if recno("user")=1 then
= .f.
= .f.
= .t.
= .t.
else
if recno("user")=n then
= .t.
= .t.
= .f.
= .f.
else
= .t.
= .t.
= .t.
= .t.
endif
endif
endif
表单保存按钮 Click 事件程序代码
if empty() then
=messagebox("请输入用户名",0+48+0,"出错")
return
endif
if empty() then
=messagebox("请输入密码",0+48+0,"出错")
return
endif
if .not.(alltrim() == alltrim()) then
=messagebox("密码重复错误,请重新输入",0+48+0,"出错")
= ""
= ""
return
endif
if empty() then
=messagebox("请选择所属部门",0+48+0,"出错")
return
endif
if
==
ue===0 then
=messagebox("至少选择一个用户权限",0+48+0,"出错")
return
endif
if
==
ue===1 then
mesbox=messagebox("此用户将具有全部权限,请确认",4+48+0,"警告")
if mesbox=7 then
return
endif
endif
*用户权限处理
PRIVATE nname,npassword,ndepartment,nkf,nxs,ncg,nkc,nxt
nname = alltrim()
npassword = alltrim()
ndepartment = alltrim()
if = 1 then
nkf = .t.
else
nkf = .f.
endif
if = 1 then
nxs = .t.
else
nxs = .f.
endif
if = 1 then
ncg = .t.
else
ncg = .f.
endif
if = 1 then
nkc = .t.
else
nkc = .f.
endif
if = 1 then
nxt = .t.
else
nxt = .f.
endif
*判断是新记录保存还是修改记录
If newcommand then &&
newcommand = .t. 是新记录保存
locate for =alltrim()
if found() then
=messagebox("用户已经存在",0+48+0,"出错")
return
endif
*数据表 user 保存记录
insert into user(name,password,department,kfgl,xsgl,cggl,kcgl,xtgl) values
(nname,npassword,ndepartment,nkf,nxs,ncg,nkc,nxt)
=messagebox("保存完毕",0+48+0,"提示")
else
update user set password=
npassword,department=ndepartment,kfgl=nkf,xsgl=nxs,cggl=ncg,kcgl=nkc,xtgl
=nxt where name= nname
=messagebox("修改完成",0+48+0,"提示")
endif
*表单初始化
= .f.
= .f.
= .f.
= .f.
= .f.
= .f.
= .f.
= .f.
= .f.
= .t.
= .t.
= .t.
= .t.
= .t.
= .t.
= .t.
= .t.
= .t.
=.f.
=.f.
= .t.
= .f.
= .f.
_reccommand
_record
newcommand = .f.
表单浏览按钮 Click 事件程序代码
DEFINE WINDOW browsewin FROM 1,1 TO 30,80 noFLOAT CLOSE
nominimize nogrow nozoom system
brow fields name,department,kfgl,xsgl,cggl,kcgl window browsewin
noappend nomodify nodelete
release window browsewin
5、 图书管理表单 代码
自定义过程 AUTO_BOOKID 程序代码
select book
set order to bookid
go bottom
private autoid1,autoid2,autoid3,autoid4
autoid1 = alltrim(str(val(substr(alltrim(),2,6))+1,6,0))
autoid2 = len(autoid1)
if autoid2 != 6 then
for n = autoid2 to 5
autoid1 = "0" + autoid1
endfor
endif
autoid4 = "B" + alltrim(autoid1)
= autoid4
新建按钮 Click 事件程序代码
= .t.
= .t.
= .t.
= .t.
= .t.
= .t.
= .t.
= .t.
= .f.
= .f.
= .f.
= .f.
= .f.
= .f.
= .f.
= .f.
= .f.
=.t.
=.t.
= .t.
= ""
= ""
= ""
= ""
= ""
= ""
= 0
= 0
_bookid
= .t.
删除按钮 Click 事件程序代码
if reccount("book")=1 then
=messagebox("只有一条记录,不能删除",0+16+0,"出错")
return
else
nbookid = alltrim()
nbookname = alltrim()
mesbox=messagebox("是否删除"+nbookid+"号图书",4+48+0,"警告")
if mesbox=7 then
return
else
use book EXCLUSIVE
delete from book where bookid=nbookid
pack
=messagebox(nbookid+"图书已经删除",0+48+0,"提示")
endif
endif
_record
_reccommand
= "book"
保存按钮 Click 事件程序代码
if empty()
=messagebox("请输入书名",0+48+0,"出错")
return
endif
if empty()
=messagebox("请输入书号",0+48+0,"出错")
return
endif
if empty()
=messagebox("请输入出版社",0+48+0,"出错")
return
endif
if empty()
=messagebox("请输入作者信息",0+48+0,"出错")
return
endif
if empty()
=messagebox("请选择图书类型",0+48+0,"出错")
return
endif
if = 0
=messagebox("请输入价格",0+48+0,"出错")
return
endif
PRIVATE
nbookid,nbookname,nbookno,nbookphouse,nbookwriter,nbookcd,nbookclass,n
bookprice,nbookdiscount
nbookid = alltrim()
nbookname = alltrim()
nbookno = alltrim()
nbookphouse = alltrim()
nbookwriter = alltrim()
nbookcd = alltrim()
nbookclass = alltrim()
nbookprice =
nbookdiscount =
*判断是新记录保存还是修改记录
If then &&
newcommand = .t. 是新记录保存
*数据表 book 保存记录
insert into book
(bookid,bookname,bookno,bookphouse,bookwriter,bookcd,bookclass,bookpric
e,bookdiscount) values
(nbookid,nbookname,nbookno,nbookphouse,nbookwriter,nbookcd,nbookclass,
nbookprice,nbookdiscount)
=messagebox("保存完毕",0+48+0,"提示")
else
update book set
bookname=nbookname,bookno=nbookno,bookphouse=nbookphouse,bookwrite
r=nbookwriter,bookcd=nbookcd,bookclass=nbookclass,bookprice=nbookprice,
bookdiscount=nbookdiscount where bookid=nbookid
=messagebox("修改完成",0+48+0,"提示")
endif
*表单初始化
= .f.
= .f.
= .f.
= .f.
= .f.
= .f.
= .f.
= .f.
= .t.
= .t.
= .t.
= .t.
= .t.
=.f.
=.f.
= .t.
_record
_reccommand
= .f.
浏览按钮 Click 事件程序代码
DEFINE WINDOW browsewin FROM 1,1 TO 30,160 noFLOAT CLOSE
nominimize nogrow nozoom system
brow fields
bookid,bookname,bookno,bookphouse,bookwriter,bookcd,bookclass,bookprice
,bookdiscount window browsewin noappend nomodify nodelete
release window browsewin
6、 会员输入表单 程序代码
自定义过程 AUTO_VIPID 程序代码
select vip
set order to vipid
go bottom
private autoid1,autoid2,autoid3,autoid4
autoid1 = alltrim(str(val(substr(alltrim(),2,6))+1,6,0))
autoid2 = len(autoid1)
if autoid2 != 6 then
for n = autoid2 to 5
autoid1 = "0" + autoid1
endfor
endif
autoid4 = "V" + alltrim(autoid1)
= autoid4
保存按钮 Click 事件程序代码
*输入数据校验
if empty()
=messagebox("请输入会员姓名",0+16+0,"出错")
return
endif
if = 0
=messagebox("请选择会员性别",0+16+0,"出错")
return
else
private nvipsex
store "" to nvipsex
if = 1
store "男" to nvipsex
else
stor "女" to nvipsex
endif
endif
if empty()
=messagebox("请输入会员联系地址",0+16+0,"出错")
return
endif
if empty()
=messagebox("请输入会员联系电话",0+16+0,"出错")
return
endif
if empty()
=messagebox("请输入邮政编码",0+16+0,"出错")
return
endif
*保存数据
private nvipid,nvipname,nvipadd,nvipphone,nvipcode
nvipid = alltrim()
nvipname = alltrim()
nvipadd = alltrim()
nvipphone = alltrim()
nvipcode = alltrim()
insert into vip
(vipid,vipname,vipsex,vipadd,vipphone,vipcode,vipsum,vipdiscount) values
(nvipid,nvipname,nvipsex,nvipadd,nvipphone,nvipcode,0,0)
=messagebox("保存成功",0+48+0,"提示")
nmesbox=messagebox("是否打印会员卡?",4+32+0,"会员卡打印")
if nmesbox = 6
select
,,,,, from vip
where = nvipid into cursor vipcard
select vipcard
report form to print
use in vipcard
endif
_vipid
清除按钮 Click 事件程序代码
= ""
= 0
= ""
= ""
= ""
7、 会员查询表单 程序代码
表单自定义过程 DIS_GRID 程序代码
= .t.
= 8
= "会员编号"
= 80
= .f.
= .f.
= "会员姓名"
= 80
= .f.
= .f.
= "会员性别"
= 80
= .f.
= .f.
= "联系地址"
= 250
= .f.
= .f.
= "联系电话"
= 80
= .f.
= .f.
= "邮政编码"
= 80
= .f.
= .f.
= "累计购书金额"
= 80
= .f.
= .f.
= "会员优惠折扣"
= 80
= .f.
= .f.
表单 Init 过程程序代码
_grid
public ncombo1,ncombo2,ntext1,chsql,cxsql
store "" to ncombo1,ncombo2,ntext1,chsql,cxsql
= 0
= .f.
= Null
select
,,,,,,
um, from vip into cursor hycx_temptable order by
= "hycx_temptable"
_grid
表单添加条件按钮 Click 事件程序代码
if empty() .or. empty() .or.
empty()
=messagebox("请输入条件",0+48+0,"出错")
return
endif
if = 1
chsql = " AND "
endif
if = 2
chsql = " OR "
endif
chsql = chsql + ncombo1 + ncombo2 + ntext1
= + chsql
if .()
= 1
= .t.
endif
= ""
= ""
= ""
chsql = ""
表单条件查询按钮 Click 事件程序代码
if empty()
=messagebox("请输入查询条件",0+16+0,"出错")
return
endif
cxsql = alltrim()
= Null
select
,,,,,,
um, from vip where &cxsql into cursor hycx_temptable order
by
= "hycx_temptable"
_grid
= 0
= .f.
= ""
= ""
= ""
= ""
store "" to ncombo1,ncombo2,ntext1,chsql,cxsql
8、 会员修改表单 程序代码
表单 Init 过程程序代码
LPARAMETERS nPar1
select vip
set order to vipid
locate for = nPar1
=
=
if = "男"
= 1
else
= 2
endif
=
=
=
保存按钮 Click 事件程序代码
*输入数据校验
if empty()
=messagebox("请输入会员姓名",0+48+0,"出错")
return
endif
if = 0
=messagebox("请选择会员性别",0+48+0,"出错")
return
else
private nvipsex
store "" to nvipsex
if = 1
store "男" to nvipsex
else
stor "女" to nvipsex
endif
endif
if empty()
=messagebox("请输入会员联系地址",0+48+0,"出错")
return
endif
if empty()
=messagebox("请输入会员联系电话",0+48+0,"出错")
return
endif
if empty()
=messagebox("请输入邮政编码",0+48+0,"出错")
return
endif
*修改数据
private nvipid,nvipname,nvipadd,nvipphone,nvipcode
nvipid = alltrim()
nvipname = alltrim()
nvipadd = alltrim()
nvipphone = alltrim()
nvipcode = alltrim()
update vip set = nvipname, = nvipsex, =
nvipadd, = nvipphone, = nvipcode where =
nvipid
=messagebox("修改已完成",0+48+0,"提示")
删除按钮 Click 事件程序代码
nvipid = alltrim()
mesbox=messagebox("是否删除" + nvipid + "号会员",4+48+0,"警告")
if mesbox=7 then
return
else
use vip EXCLUSIVE
delete from vip where = nvipid
pack
=messagebox("会员" + nvipid + "已经删除",0+48+0,"提示")
endif
9、 会员卡打印表单 程序代码
打印按钮 Click 事件程序代码
if empty()
=messagebox("请输入会员编号",0+16+0,"出错")
return
else
nvipid =
endif
nmesbox=messagebox("是否打印会员卡?",4+32+0,"会员卡打印")
if nmesbox = 6
select
,,,,, from vip
where = nvipid into cursor vipcard
select vipcard
report form to print
use in vipcard
endif
输入框 Text1 的 Valid 事件程序代码
= alltrim()
if .()
select vip
go top
locate for =
if found()
=
=
=
=
=
else
=messagebox("会员编号不存在",0+16+0,"出错")
= ""
= ""
= ""
= ""
= ""
= ""
endif
endif
10、 采购员管理表单 程序代码
表单自定义过程 AUTO_BUYERID 程序代码
select buyer
set order to buyerid
go bottom
private autoid1,autoid2,autoid3,autoid4
autoid1 = alltrim(str(val(substr(alltrim(),4,2))+1,2,0))
autoid2 = len(autoid1)
if autoid2 =1
autoid1 = "0" + autoid1
endif
autoid4 = "BUY" + alltrim(autoid1)
= autoid4
表单表单保存按钮 Click 程序代码
private
nbuyerid,nbuyername,nbuyersex,nbuyerbirthday,nbuyeradd,nbuyerphone
if empty()
=messagebox("请输入采购员姓名",0+48+0,"出错")
return
endif
if = 0
=messagebox("请选择采购员性别",0+48+0,"出错")
return
endif
if = {}
=messagebox("请输入出生年月",0+48+0,"出错")
return
endif
if empty() then
=messagebox("请输入家庭住址",0+48+0,"出错")
return
endif
if empty() then
=messagebox("请输入联系电话",0+48+0,"出错")
return
endif
nbuyerid = alltrim()
nbuyername = alltrim()
if = 1
nbuyersex = "男"
else
nbuyersex = "女"
endif
nbuyerbirthday = dtoc()
nbuyeradd = alltrim()
nbuyerphone = alltrim()
*判断是新记录保存还是修改记录
If = .t. && newcommand = .t. 是新记录保存
*数据表 buyer 保存记录
insert into
buyer(buyerid,buyername,buyersex,buyerbirthday,buyeradd,buyerphone)
values
(nbuyerid,nbuyername,nbuyersex,nbuyerbirthday,nbuyeradd,nbuyerphone)
=messagebox("保存完毕",0+48+0,"提示")
else
update buyer set
buyername=nbuyername,buyersex=nbuyersex,buyerbirthday=nbuyerbirthday,b
uyeradd=nbuyeradd,buyerphone=nbuyerphone where buyerid=nbuyerid
=messagebox("修改完成",0+48+0,"提示")
endif
*表单初始化
= .f.
= .f.
= .f.
= .f.
= .f.
= .f.
= .t.
= .t.
= .t.
= .t.
= .t.
= .t.
= .t.
= .t.
= .t.
=.f.
=.f.
= .t.
_record
_reccommand
= .f.
表单删除按钮 Click 程序代码
if reccount("buyer")=1 then
=messagebox("只有一条记录,不能删除",0+16+0,"出错")
return
else
nbuyerid = alltrim()
nbuyername = alltrim()
mesbox=messagebox(" 是 否 删 除 "+nbuyerid+" 号 采 购 员
"+nbuyername,4+48+0,"警告")
if mesbox=7 then
return
else
use buyer EXCLUSIVE
delete from buyer where =nbuyerid
pack
=messagebox(nbuyerid+"号采购员"+nbuyername+"已经删除",0+48+0,"
提示")
endif
endif
_record
_reccommand
表单浏览按钮 Click 程序代码
DEFINE WINDOW browsewin FROM 1,1 TO 30,120 noFLOAT CLOSE
nominimize nogrow nozoom system
select buyer
set order to buyerid
brow fields buyerid,buyername,buyersex,buyerbirthday,buyeradd,buyerphone
window browsewin noappend nomodify nodelete
release window browsewin
表单自定义过程 DIS_RECORD 程序代码
select buyer
set order to buyerid
if reccount("buyer") = 0
= ""
= ""
= 0
= {}
= ""
= ""
else
=
=
if = "男"
= 1
else
= 2
endif
=
=
=
endif
11、 采购员信息查找表单 程序代码
表单查找按钮 Click 事件程序代码
if = 1 .and. empty()
=messagebox("请输入采购员编号",0+16+0,"出错")
return
endif
if = 2 .and. empty()
=messagebox("请输入采购员姓名",0+16+0,"出错")
return
endif
if = 0
=messagebox("请选择条件",0+16+0,"出错")
return
endif
select buyer
set order to buyerid
go top
if = 1
locate for buyerid == alltrim()
if .()
=messagebox("没有附和条件记录",0+16+0,"出错")
return
endif
else
locate for buyername = alltrim()
if .()
=messagebox("没有附和条件记录",0+16+0,"出错")
return
endif
endif
_record
_reccommand