实例介绍
【实例简介】
1.在sql server中新建数据库posdb
2.打开sql server的查询分析器posdb-SQL.sql,运行生成posdb的表
3.在bde中新建数据别名posdb关联到数据库posdb
4.初始化帐号:admin,密码:zhong
4.运行程序。
【核心代码】
unit pfm_sptuihuodmx;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Db, DBTables, Grids, DBGrids, StdCtrls, Mask, DBCtrls, Buttons, ComCtrls,
pfm_sptuihuodsel, ExtCtrls, ADODB, pvar_lib;
type
Tfm_sptuihuodmx = class(TForm)
PageControl1: TPageControl;
TabSheet1: TTabSheet;
GroupBox1: TGroupBox;
Label4: TLabel;
Label12: TLabel;
Label13: TLabel;
Label18: TLabel;
Label23: TLabel;
Label24: TLabel;
Label25: TLabel;
Label26: TLabel;
Label27: TLabel;
Label28: TLabel;
Label29: TLabel;
Label30: TLabel;
Label31: TLabel;
Label32: TLabel;
Label33: TLabel;
DBEdit4: TDBEdit;
DBEdit5: TDBEdit;
DBEdit12: TDBEdit;
DBEdit13: TDBEdit;
DBEdit18: TDBEdit;
DBEdit23: TDBEdit;
DBEdit24: TDBEdit;
DBEdit25: TDBEdit;
DBEdit26: TDBEdit;
DBEdit27: TDBEdit;
DBEdit28: TDBEdit;
DBEdit29: TDBEdit;
DBEdit30: TDBEdit;
DBEdit31: TDBEdit;
DBEdit32: TDBEdit;
GroupBox2: TGroupBox;
Label1: TLabel;
Label5: TLabel;
Label16: TLabel;
Label11: TLabel;
Label21: TLabel;
Label20: TLabel;
Label22: TLabel;
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Edit4: TEdit;
Edit8: TEdit;
Edit9: TEdit;
Edit10: TEdit;
Query3: TQuery;
Query3spbm: TStringField;
Query3sptxm: TStringField;
Query3spmc: TStringField;
Query3ggxh: TStringField;
Query3dengji: TStringField;
Query3zhuangtai: TStringField;
Query3baozhuangdw: TStringField;
Query3baozhuangsl: TStringField;
Query3hh: TStringField;
Query3gysmc: TStringField;
Query3cd: TStringField;
Query3xsfs: TStringField;
Query3wsjj: TFloatField;
Query3jhsl: TFloatField;
Query3wsdj: TFloatField;
Query3xssl: TFloatField;
Query3yhl: TFloatField;
Query3splb: TStringField;
DataSource3: TDataSource;
BitBtn_quit: TBitBtn;
BBtn_yskcl: TBitBtn;
GroupBox3: TGroupBox;
LView1: TListView;
Panel1: TPanel;
Edit11: TEdit;
Label2: TLabel;
Label3: TLabel;
Edit12: TEdit;
Label6: TLabel;
Edit13: TEdit;
Query1: TQuery;
Label14: TLabel;
Edit5: TEdit;
lbltishi: TLabel;
BBtnjhd: TBitBtn;
BBtncancel: TBitBtn;
BBtnSave: TBitBtn;
BBtndel: TBitBtn;
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure BBtn_yskclClick(Sender: TObject);
procedure Edit11KeyPress(Sender: TObject; var Key: Char);
procedure Edit12KeyPress(Sender: TObject; var Key: Char);
procedure Edit13KeyPress(Sender: TObject; var Key: Char);
procedure Edit5KeyPress(Sender: TObject; var Key: Char);
procedure BBtndelClick(Sender: TObject);
procedure BBtnjhdClick(Sender: TObject);
procedure BBtncancelClick(Sender: TObject);
procedure BBtnSaveClick(Sender: TObject);
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
procedure LView1Click(Sender: TObject);
private
{ Private declarations }
function MyCheckData():boolean;
function GetSpxx(spcode:string):boolean;
public
{ Public declarations }
end;
var
fm_sptuihuodmx: Tfm_sptuihuodmx;
implementation
uses pfm_yfkcl;
{$R *.DFM}
procedure Tfm_sptuihuodmx.FormCreate(Sender: TObject);
var
i:integer;
lvcol:TListColumn;
begin
lvcol:=lview1.Columns.Add();
lvcol.Caption:='商品编码';
lvcol.width:=60;
lvcol:=lview1.Columns.Add();
lvcol.Caption:='商品条形码';
lvcol.width:=110;
lvcol:=lview1.Columns.Add();
lvcol.Caption:='商品名称';
lvcol.width:=120;
lvcol:=lview1.Columns.Add();
lvcol.Caption:='退货数量';
lvcol.width:=80;
lvcol:=lview1.Columns.Add();
lvcol.Caption:='退货单价';
lvcol.width:=80;
lvcol:=lview1.Columns.Add();
lvcol.Caption:='单据号';
lvcol.width:=100;
for i:= 0 to componentcount-1 do
begin
if components[i].ClassName='TEdit' then
begin
(components[i] as tedit).text:='';
end;
end;
end;
function Tfm_sptuihuodmx.MyCheckData():boolean;
begin
myCheckData:=true;
end;
procedure Tfm_sptuihuodmx.FormClose(Sender: TObject; var Action: TCloseAction);
begin
action:=caFree;
end;
procedure Tfm_sptuihuodmx.BBtn_yskclClick(Sender: TObject);
begin
{if application.MessageBox('是否商品退货明细单录入完成,#13填写应付款单','注意',MB_YESNO)=ID_NO then
begin
exit;
end;
fm_yfkcl:=tfm_yfkcl.create(application);
fm_yfkcl.Edit1.Text:=edit1.text;
fm_yfkcl.edit2.text:=edit2.text;
fm_yfkcl.showmodal;}
end;
procedure Tfm_sptuihuodmx.Edit11KeyPress(Sender: TObject; var Key: Char);
var
ListItem:Tlistitem;
begin
//商品编码或条形码
if key<>#13 then exit;
getspxx(edit11.text);
if not query3.eof then
begin
ListItem:=LView1.items.Insert(0);
ListItem.Caption:=query3.fieldbyname('spbm').asstring;
LIstItem.SubItems.add(query3.fieldbyname('sptxm').asstring);
LIstItem.SubItems.add(query3.fieldbyname('spmc').asstring);
LIstItem.SubItems.add('1');// 2-退货数量
LIstItem.SubItems.add(query3.fieldbyname('wsjj').asstring);//3-无税单价
LIstItem.SubItems.add(edit5.text);//4-单据号
ListItem.selected:=true;
edit12.text:='1';
edit13.Text:=query3.fieldbyname('wsjj').asstring;
edit12.SetFocus;
end
else
begin
edit11.text:='';
lbltishi.caption:='没有这个商品';
end;
end;
function Tfm_sptuihuodmx.GetSpxx(spcode:string):boolean;
var
spcodelen:integer;
tmpstr:string;
begin
spcodelen:=length(spcode);
if spcodelen<=6 then
begin
tmpstr:='000000' spcode;
spcode:=copy(tmpstr,spcodelen 1,6);
spcodelen:=6;
end
else if spcodelen<>13 then //输入的编码位数>6但不是13位
begin
GetSpxx:=false;
exit;
end;
edit11.text:=spcode;
query3.close;
query3.sql.clear;
if spcodelen=6 then
begin
query3.sql.add('select * from t_spxx where spbm=''' spcode '''');
end
else
begin
query3.sql.add('select * from t_spxx where sptxm=''' spcode '''');
end;
query3.open;
GetSpxx:=true;
end;
procedure Tfm_sptuihuodmx.Edit12KeyPress(Sender: TObject; var Key: Char);
var
retcode,num:integer;
begin
if key<>#13 then exit;
if lview1.SelCount=0 then exit;
val((sender as Tedit).text,num,retcode);
if retcode=0 then
begin
lview1.Selected.SubItems.strings[2]:=(sender as Tedit).text;
lbltishi.caption:='请输入商品的进货单价';
edit13.SetFocus;
end
else
begin
lbltishi.caption:='请输入整数';
(sender as tedit).text:='';
end;
end;
procedure Tfm_sptuihuodmx.Edit13KeyPress(Sender: TObject; var Key: Char);
begin
if key<>#13 then exit;
if lview1.SelCount=0 then exit;
try
strtofloat((sender as tedit).text);
lview1.Selected.SubItems.strings[3]:=(sender as tedit).text;
lbltishi.caption:='请输入单据号';
edit5.setfocus;
except
on EConvertError do
begin
lbltishi.caption:='你输入的不是数字';
end;
end;
end;
procedure Tfm_sptuihuodmx.Edit5KeyPress(Sender: TObject; var Key: Char);
begin
if key<>#13 then exit;
if lview1.SelCount=0 then exit;
lview1.Selected.SubItems.strings[4]:=(sender as tedit).text;
edit1.setfocus;
lbltishi.caption:='请输入商品编码或条形码';
edit11.setfocus;
end;
procedure Tfm_sptuihuodmx.BBtndelClick(Sender: TObject);
begin
if lview1.SelCount=0 then exit;
if application.MessageBox(pchar('确定要删除选中进货记录'),pchar('警告'),mb_YESNO)<>IDYES then exit;
lview1.Selected.Delete;
end;
procedure Tfm_sptuihuodmx.BBtnjhdClick(Sender: TObject);
begin
fm_sptuihuodsel:=Tfm_sptuihuodsel.create(self);
if fm_sptuihuodsel.showmodal=IdOK then
begin
edit3.text:=datetimetostr(fm_sptuihuodsel.mDateTime);
edit1.text:=inttostr(fm_sptuihuodsel.mLsh);
edit2.text:=fm_sptuihuodsel.mCkmc;
edit4.text:=fm_sptuihuodsel.mGysmc;
edit8.text:=fm_sptuihuodsel.mJbrm;
edit9.text:=fm_sptuihuodsel.mShrm;
edit10.text:=fm_sptuihuodsel.mCzym;
end;
fm_sptuihuodsel.free;
end;
procedure Tfm_sptuihuodmx.BBtncancelClick(Sender: TObject);
begin
close;
end;
procedure Tfm_sptuihuodmx.BBtnSaveClick(Sender: TObject);
var
insertsql:string;
lsh,ckmc,rq,gysmc,jbrm,shrm,czym:string;
spbm,sptxm,spnum,spthdj,djhm:string;
i:integer;
begin
if application.MessageBox(pchar('保存后而退出?'),pchar('警告'),mb_YESNO)<>IDYES then exit;
if edit1.text='' then
begin
showmessage('还未填写进货单');
exit;
end;
if lview1.Items.Count<1 then
begin
showmessage('尚未录入进货单明细记录');
exit;
end;
lsh:=edit1.text;
ckmc:=edit2.text;
datetimetostring(rq,'yyyy-mm-dd',strtodatetime(edit3.text));
gysmc:=edit4.text;
jbrm:=edit8.text;
shrm:=edit9.text;
czym:=edit10.text;
query1.Active:=false;
query1.sql.clear;
insertsql:='insert into tb_sptuihuod(lsh,ckmc,gysmc,rq,czym,jbrm,shrm) values(';
query1.sql.add(insertsql);
insertsql:=lsh ',''' ckmc ''',''' gysmc ''',''' rq ''',''' czym ''',''' jbrm ''',''' shrm ''')';
query1.sql.add(insertsql);
query1.ExecSQL;
for i:=0 to lview1.items.count-1 do
begin
spbm:=lview1.items[i].caption;
sptxm:=lview1.items[i].subitems[0];
spnum:=lview1.items[i].subitems[2];
spthdj:=lview1.items[i].subitems[3];
djhm:=lview1.items[i].subitems[4];
query1.sql.clear;
query1.sql.add('insert into tb_sptuihuodmx(lsh,spbm,sptxm,spnum,spthdj,djhm) values(');
query1.sql.add(lsh ',''' spbm ''',''' sptxm ''',' spnum ',' spthdj ',''' djhm ''')');
query1.ExecSQL;
end;
lview1.Items.Clear;
AddOptRecord('生成退货单:流水号(' lsh '),仓库代码(' ckmc '),供应商代码(' gysmc ')');
close;
end;
procedure Tfm_sptuihuodmx.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
if lview1.Items.count=0 then exit;
if application.MessageBox(pchar('不保存而退出?'),pchar('警告'),mb_YESNO)<>IDYES then
canclose:=false;
end;
procedure Tfm_sptuihuodmx.LView1Click(Sender: TObject);
var
i:integer;
begin
if lview1.SelCount>0 then
begin
i:=lview1.Selected.Index;
edit11.text:=lview1.items[i].caption;//spbm
//sptxm:=lview1.items[i].subitems[0];
edit12.text:=lview1.items[i].subitems[2];//spnum
edit13.text:=lview1.items[i].subitems[3];//spthdj:
edit5.text:=lview1.items[i].subitems[4];//djhm
end;
end;
end.
标签: 又一个超市管理系统demo
小贴士
感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。
- 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
- 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
- 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
- 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。
关于好例子网
本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明


网友评论
我要评论