5.3具体设计过程 5.3.1差旅费报销单设计 1、首先新建一个Application,将Form1的Caption属性设置为差旅费报销单,然后在此设计面板上加上若干控件,其中包括:TOpenDialog、TButton、TShape、TLabel以及TSpeedButton,在差旅费报销单设计中主要实现的几个功能按钮为“由文件装入”、“保存为文本”、“保存”、“打印”、“预览”、“新建”、“关闭”。 paper51.com 其中,“由文件装入”的OnClick事件的处理程序如下, paper51.com
procedureTFrmChuChai.Button1Click(Sender: TObject); http://www.paper51.com begin copyright paper51.com opendialog1.Filter:='*.clf'; 内容来自论文无忧网 www.paper51.com ifOpenDialog1.Execute then 内容来自www.paper51.com
begin copyright paper51.com if OpenDialog1.Files.Count>1 then http://www.paper51.com else 内容来自论文无忧网 www.paper51.com
readtxtdata(opendialog1.FileName); paper51.com
end; 内容来自论文无忧网 www.paper51.com end; 内容来自论文无忧网 www.paper51.com
“保存为文本”的OnClick事件的处理程序如下,在保存成功后会用Message.Box显示“保存成功”提示。 内容来自论文无忧网 www.paper51.com procedureTFrmChuChai.Button2Click(Sender: TObject); http://www.paper51.com vartxtrecord:Ttxtrecord; 内容来自www.paper51.com begin 内容来自www.paper51.com txtrecord.istxt:=true; copyright paper51.com
txtrecord.ccr:=f23.Text; 内容来自论文无忧网 www.paper51.com txtrecord.qsrq:=f4.DateString+'-'+f5.DateString; 内容来自论文无忧网 www.paper51.com ifauto_sql(self,'chuchai',1,query1,txtrecord)='exit' then 内容来自www.paper51.com
exit;// paper51.com application.MessageBox('保存成功','提示',64); 内容来自www.paper51.com
end; 内容来自www.paper51.com SpeedButton“保存” 的OnClick事件的处理程序如下: http://www.paper51.com procedureTFrmChuChai.SpeedButton1Click(Sender: TObject); paper51.com var copyright paper51.com sqlstr:string; paper51.com txtrecord:Ttxtrecord; copyright paper51.com
begin copyright paper51.com txtrecord.istxt:=false; 内容来自www.paper51.com sqlstr:=auto_sql(self,'chuchai',m_mode,query1,txtrecord); 内容来自论文无忧网 www.paper51.com with query1 do http://www.paper51.com
begin http://www.paper51.com close; 内容来自论文无忧网 www.paper51.com sql.text:=sqlstr; http://www.paper51.com sql.SaveToFile('error.log'); http://www.paper51.com try http://www.paper51.com execsql; 内容来自www.paper51.com m_mode:=2; 内容来自www.paper51.com application.MessageBox('保存成功','提示',64); 内容来自www.paper51.com
except paper51.com application.MessageBox('保存失败!','提示',64); paper51.com end; 内容来自www.paper51.com end; 内容来自www.paper51.com
end; 内容来自论文无忧网 www.paper51.com “打印”的OnClick事件的处理程序如下,其中的 *.mws文件为本公司自定义报表文件。 http://www.paper51.com
procedureTFrmChuChai.SpeedButton2Click(Sender: TObject); copyright paper51.com begin paper51.com OpenReport(self,'差旅报销单.mws',nil,0,'','',true); 内容来自论文无忧网 www.paper51.com
end; copyright paper51.com “预览”的OnClick事件的处理程序如下, copyright paper51.com procedureTFrmChuChai.SpeedButton5Click(Sender: TObject); 内容来自论文无忧网 www.paper51.com begin copyright paper51.com
OpenReport(self,'差旅报销单.mws',nil,0,'','',false); 内容来自www.paper51.com end; http://www.paper51.com “新建”的OnClick事件的处理程序如下,原理是使用Clear清除现有表格中有的数据, copyright paper51.com procedureTFrmChuChai.SpeedButton3Click(Sender: TObject); copyright paper51.com begin http://www.paper51.com clearctl(self,'2'); 内容来自论文无忧网 www.paper51.com m_mode:=1; http://www.paper51.com end; 内容来自www.paper51.com
而“关闭”的OnClick事件的处理程序仅仅是调用close来退出当前程序。 paper51.com
其他几个表单,如费用报销单、记帐凭证、现金支票以及进帐单的设计与差旅费报销单的设计类似,这里就不在赘述,下面介绍一下主页面的设计: 内容来自论文无忧网 www.paper51.com 5.3.2主页面设计 http://www.paper51.com 主页面上主要包含了TEdit、TLabel、TButton、TListView、TImageList等控件,其中的功能按钮主要包括:“查询”、“删除”、“新建”、“关闭”, paper51.com
其中,“查询”的OnClick事件处理程序为: copyright paper51.com procedureTFrmList.Button1Click(Sender: TObject); 内容来自论文无忧网 www.paper51.com varlist_item:Tlistitem; paper51.com
begin copyright paper51.com if trim(edit1.Text) ='' then exit; 内容来自论文无忧网 www.paper51.com with query2,listview1do 内容来自www.paper51.com begin http://www.paper51.com items.Clear ; 内容来自www.paper51.com
close; copyright paper51.com if edit1.Text='差旅费报销单' then copyright paper51.com begin paper51.com sql.text:='selectid,f1,f24 ,f3 from chuchai where 1=1'; 内容来自www.paper51.com
if trim(edit2.Text) <>'' then 内容来自论文无忧网 www.paper51.com sql.add(' and datepart(''yyyy'',f1)='+edit2.text); 内容来自论文无忧网 www.paper51.com if trim(edit3.Text) <>'' then paper51.com sql.add(' and datepart(''m'',f1)='+edit3.text); copyright paper51.com end 内容来自www.paper51.com else if edit1.Text='费用报销单' then 内容来自www.paper51.com begin paper51.com sql.text:='select id,f1,f3,f6,f9,f12,f15 from feiyong where 1=1'; copyright paper51.com if trim(edit2.Text) <>'' then copyright paper51.com sql.add('and datepart(''yyyy'',f1)='+edit2.text); paper51.com if trim(edit3.Text) <>'' then 内容来自www.paper51.com
sql.add(' and datepart(''m'',f1)='+edit3.text); 内容来自论文无忧网 www.paper51.com end 内容来自www.paper51.com
else if edit1.Text='记帐凭证' then 内容来自论文无忧网 www.paper51.com begin 内容来自www.paper51.com sql.text:='selectid,f1,f3 from jizhang where 1=1'; paper51.com if trim(edit2.Text) <>'' then paper51.com sql.add(' and datepart(''yyyy'',f1)='+edit2.text); copyright paper51.com if trim(edit3.Text) <>'' then 内容来自www.paper51.com sql.add(' and datepart(''m'',f1)='+edit3.text); copyright paper51.com end http://www.paper51.com
else if edit1.Text='现金支票' then 内容来自www.paper51.com begin paper51.com sql.text:='select id,f1,f6 from zhipiao where 1=1'; http://www.paper51.com if trim(edit2.Text) <>'' then 内容来自论文无忧网 www.paper51.com sql.add(' and datepart(''yyyy'',f1)='+edit2.text); copyright paper51.com
if trim(edit3.Text) <>'' then paper51.com sql.add(' and datepart(''m'',f1)='+edit3.text); paper51.com end http://www.paper51.com else if edit1.Text='进帐单' then paper51.com
begin paper51.com sql.text:='select id,f1,f10 from jinzhangdan where 1=1'; copyright paper51.com if trim(edit2.Text) <>'' then copyright paper51.com sql.add(' and datepart(''yyyy'',f1)='+edit2.text); copyright paper51.com if trim(edit3.Text) <>'' then 内容来自论文无忧网 www.paper51.com sql.add(' and datepart(''m'',f1)='+edit3.text); copyright paper51.com
end; paper51.com sql.SaveToFile('error.log'); paper51.com open; 内容来自论文无忧网 www.paper51.com
while not query2.eof do 内容来自www.paper51.com begin 内容来自www.paper51.com list_item:=items.Add ; copyright paper51.com if edit1.Text='差旅费报销单' then 内容来自www.paper51.com begin copyright paper51.com list_item.caption:=fields[0].asstring; paper51.com list_item.SubItems.Add(copy(fields[1].asstring,1,4)); 内容来自论文无忧网 www.paper51.com list_item.SubItems.Add(copy(fields[1].asstring,6,2)); 内容来自论文无忧网 www.paper51.com
list_item.SubItems.Add(fields[2].asstring); paper51.com list_item.SubItems.Add(fields[3].asstring); http://www.paper51.com listview1.Columns.Items[3].Width:=100; copyright paper51.com end 内容来自www.paper51.com else if edit1.Text='费用报销单' then paper51.com begin 内容来自www.paper51.com
list_item.caption:=fields[0].asstring; 内容来自论文无忧网 www.paper51.com list_item.SubItems.Add(copy(fields[1].asstring,1,4)); copyright paper51.com list_item.SubItems.Add(copy(fields[1].asstring,6,2)); paper51.com
list_item.SubItems.Add(''); 内容来自论文无忧网 www.paper51.com listview1.Columns.Items[3].Width:=0; 内容来自www.paper51.com list_item.SubItems.Add(fields[2].asstring+' '+fields[3].asstring+''+fields[4].asstring+' '+fields[5].asstring); copyright paper51.com
end copyright paper51.com else if edit1.Text='记帐凭证' then http://www.paper51.com
begin copyright paper51.com list_item.caption:=fields[0].asstring; copyright paper51.com list_item.SubItems.Add(copy(fields[1].asstring,1,4)); 内容来自论文无忧网 www.paper51.com list_item.SubItems.Add(copy(fields[1].asstring,6,2)); paper51.com
list_item.SubItems.Add(''); http://www.paper51.com listview1.Columns.Items[3].Width:=0; 内容来自www.paper51.com list_item.SubItems.Add(fields[2].asstring); 内容来自www.paper51.com end 内容来自论文无忧网 www.paper51.com else if edit1.Text='现金支票' then 内容来自www.paper51.com
begin http://www.paper51.com list_item.caption:=fields[0].asstring; 内容来自论文无忧网 www.paper51.com list_item.SubItems.Add(copy(fields[1].asstring,1,4)); paper51.com list_item.SubItems.Add(copy(fields[1].asstring,6,2)); copyright paper51.com list_item.SubItems.Add(''); http://www.paper51.com listview1.Columns.Items[3].Width:=0; http://www.paper51.com list_item.SubItems.Add(fields[2].asstring); 内容来自论文无忧网 www.paper51.com end 内容来自www.paper51.com else if edit1.Text='进帐单' then http://www.paper51.com
begin paper51.com list_item.caption:=fields[0].asstring; paper51.com list_item.SubItems.Add(copy(fields[1].asstring,1,4)); 内容来自论文无忧网 www.paper51.com
list_item.SubItems.Add(copy(fields[1].asstring,6,2)); 内容来自论文无忧网 www.paper51.com list_item.SubItems.Add(''); paper51.com listview1.Columns.Items[3].Width:=0; copyright paper51.com
list_item.SubItems.Add(fields[2].asstring); paper51.com end; paper51.com next; paper51.com end; paper51.com end; paper51.com end; 内容来自www.paper51.com “删除”的OnClick事件处理程序如下: copyright paper51.com
procedureTFrmList.Button2Click(Sender: TObject); copyright paper51.com var i:integer; paper51.com
begin 内容来自论文无忧网 www.paper51.com with query2 do 内容来自论文无忧网 www.paper51.com begin 内容来自论文无忧网 www.paper51.com for i:=listview1.SelCount-1 downto 0 do 内容来自www.paper51.com
begin paper51.com cur_id:=listview1.Selected.Caption ; paper51.com close; 内容来自论文无忧网 www.paper51.com if edit1.Text='差旅费报销单' then http://www.paper51.com
sql.text:='delete from chuchai where id='+cur_id http://www.paper51.com else if edit1.Text='费用报销单' then paper51.com sql.text:='deletefrom feiyong where id='+cur_id 内容来自www.paper51.com
else if edit1.Text='记帐凭证' then 内容来自www.paper51.com
sql.text:='delete from jizhang where id='+cur_id; copyright paper51.com if application.MessageBox('确定删除吗','提示',36)<>6then exit; 内容来自www.paper51.com execsql; copyright paper51.com listview1.Selected.Delete ; paper51.com end; 内容来自www.paper51.com end; http://www.paper51.com end; paper51.com “新建”的OnClick事件的处理程序: http://www.paper51.com procedureTFrmList.SpeedButton1Click(Sender: TObject); paper51.com begin http://www.paper51.com
cur_id:=''; 内容来自www.paper51.com openform(false); copyright paper51.com
end; http://www.paper51.com 其他略 paper51.com
|