【例子介绍】
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.
评论