uwhref.~pas
来自「DELPHI编程入门篇.从基础入手,浅显易懂,一定物有所值.」· ~PAS 代码 · 共 679 行 · 第 1/2 页
~PAS
679 行
unit Uwhref;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Menus, dxCntner, dxEditor, dxExEdtr, dxEdLib, Buttons, Grids,
DB, ADODB, ComCtrls, StdCtrls, ExtCtrls, RpCon, RpConDS, RpDefine, RpRave;
type
Tfrmwhref = class(TForm)
Panel2: TPanel;
Label3: TLabel;
Label5: TLabel;
Label6: TLabel;
Label7: TLabel;
Label8: TLabel;
Label9: TLabel;
Edit2: TEdit;
ComboBox2: TComboBox;
DTPicker3: TDateTimePicker;
ComboBox3: TComboBox;
Edit3: TEdit;
Edit4: TEdit;
ADOQuery1: TADOQuery;
ADOQuery2: TADOQuery;
ADOQuery3: TADOQuery;
StringGrid1: TStringGrid;
Panel1: TPanel;
Label1: TLabel;
Label2: TLabel;
Label4: TLabel;
SpeedButton1: TSpeedButton;
Label10: TLabel;
Edit1: TEdit;
DTPicker1: TDateTimePicker;
DTPicker2: TDateTimePicker;
ComboBox1: TComboBox;
StringGrid2: TStringGrid;
dxButtonEdit1: TdxButtonEdit;
PopupMenu1: TPopupMenu;
N1: TMenuItem;
N2: TMenuItem;
SpeedButton2: TSpeedButton;
SpeedButton5: TSpeedButton;
SpeedButton6: TSpeedButton;
SpeedButton7: TSpeedButton;
SpeedButton9: TSpeedButton;
RvProject1: TRvProject;
whrefConnection1: TRvDataSetConnection;
whrefConnection2: TRvDataSetConnection;
procedure FormCreate(Sender: TObject);
procedure SpeedButton1Click(Sender: TObject);
procedure SpeedButton2Click(Sender: TObject);
procedure SpeedButton5Click(Sender: TObject);
procedure SpeedButton6Click(Sender: TObject);
procedure StringGrid1Click(Sender: TObject);
procedure StringGrid2KeyPress(Sender: TObject; var Key: Char);
procedure StringGrid2KeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure StringGrid2Exit(Sender: TObject);
procedure StringGrid2SelectCell(Sender: TObject; ACol, ARow: Integer;
var CanSelect: Boolean);
procedure N1Click(Sender: TObject);
procedure N2Click(Sender: TObject);
procedure dxButtonEdit1ButtonClick(Sender: TObject;
AbsoluteIndex: Integer);
procedure dxButtonEdit1Exit(Sender: TObject);
procedure SpeedButton9Click(Sender: TObject);
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
procedure SpeedButton7Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
frmwhref: Tfrmwhref;
implementation
uses Udatamodule, Ufilprod;
{$R *.dfm}
procedure Tfrmwhref.FormCreate(Sender: TObject);
var
i,arow:integer;
begin
stringgrid1.Cells[1,0]:='单据编号';
stringgrid1.Cells[2,0]:='客户';
stringgrid1.Cells[3,0]:='销售日期';
stringgrid2.Cells[1,0]:='商品编号';
stringgrid2.Cells[2,0]:='商品名称';
stringgrid2.Cells[3,0]:='商品数量';
stringgrid2.Cells[4,0]:='商品售价';
stringgrid2.Cells[5,0]:='商品总价';
dtpicker1.Date:=date-7;
dtpicker2.Date:=date;
dtpicker3.Date:=date;
adoquery1.SQL.Text:='select clientid,clientname from clients';
adoquery1.Open;
while not adoquery1.Eof do
begin
combobox1.Items.Add(adoquery1.FieldValues['clientid']+' '+adoquery1.FieldValues['clientname']);
combobox2.Items.Add(adoquery1.FieldValues['clientid']+' '+adoquery1.FieldValues['clientname']);
adoquery1.Next;
end;
adoquery1.Close;
adoquery1.SQL.Text:='select filname from filiale';
adoquery1.Open;
while not adoquery1.Eof do
begin
combobox3.Items.Add(adoquery1.FieldValues['filname']);
adoquery1.Next;
end;
adoquery1.Close;
adoquery1.SQL.Text:='select * from whrefund ';
adoquery1.Open;
if adoquery1.RecordCount > 0 then
begin
edit2.Text:=adoquery1.FieldValues['wrefid'];
edit3.Text:=adoquery1.FieldValues['handleman'];
edit4.Text:=adoquery1.FieldValues['accounts'];
dtpicker3.Date:=adoquery1.FieldValues['refdate'];
for i:=0 to combobox2.Items.Count-1 do
if copy(combobox2.Items.Strings[i],1,5) = adoquery1.FieldByName('clientid').AsString then
begin
combobox2.ItemIndex:=i;
break;
end;
adoquery2.SQL.Text:='select filname from filiale where filid = '''+adoquery1.FieldValues['filid']+'''';
adoquery2.Open;
for i:=0 to combobox3.Items.Count-1 do
begin
if combobox3.Items.Strings[i] = adoquery2.FieldByName('filname').AsString then
begin
combobox3.ItemIndex:=i;
break;
end;
end;
stringgrid1.RowCount:=adoquery1.RecordCount+1;
arow:=1;
while not adoquery1.Eof do
begin
stringgrid1.Cells[1,arow]:=adoquery1.FieldValues['wrefid'];
stringgrid1.Cells[2,arow]:=adoquery1.FieldValues['clientid'];
stringgrid1.Cells[3,arow]:=adoquery1.FieldValues['refdate'];
adoquery1.Next;
inc(arow);
end;
adoquery1.Close;
stringgrid1.Cols[0].Clear;
stringgrid1.Cells[0,1]:='*';
adoquery1.SQL.Text:='select whrefund1.wrefid,pluinfo.prname,whrefund1.refnum,'+
' whrefund1.price from whrefund1 inner join pluinfo on whrefund1.prid = pluinfo.prid'+
' where whrefund1.wrefid = '''+edit2.Text+'''';
adoquery1.Open;
if adoquery1.RecordCount > 0 then
begin
stringgrid2.RowCount:=adoquery1.RecordCount+1;
for i:=1 to stringgrid2.RowCount-1 do
begin
stringgrid2.Cells[1,i]:=adoquery1.FieldValues['wrefid'];
stringgrid2.Cells[2,i]:=adoquery1.FieldValues['prname'];
stringgrid2.Cells[3,i]:=adoquery1.FieldValues['refnum'];
stringgrid2.Cells[4,i]:=adoquery1.FieldValues['price'];
stringgrid2.Cells[5,i]:=floattostr(strtofloat(stringgrid2.Cells[3,i])*strtofloat(stringgrid2.Cells[4,i]));
adoquery1.Next;
end;
end;
adoquery1.Close;
end;
end;
procedure Tfrmwhref.SpeedButton1Click(Sender: TObject);
var
i,arow:integer;
begin
for i:=1 to stringgrid1.RowCount-1 do
stringgrid1.Rows[i].Clear;
stringgrid1.RowCount:=2;
for i:=1 to stringgrid2.RowCount-1 do
stringgrid2.Rows[i].Clear;
stringgrid1.RowCount:=2;
adoquery1.SQL.Text:='select wrefid,clientid,refdate,handleman,filid,'
+'accounts from whrefund where refdate between #'+datetostr(dtpicker1.date)
+'# and #'+datetostr(dtpicker2.date)+'#';
if edit1.Text <> '' then
adoquery1.SQL.Add('and wrefid = '''+edit1.Text+'''');
if combobox1.Text <> '' then
adoquery1.SQL.add('and clientid = '''+copy(combobox1.Text,1,5)+'''');
adoquery1.Open;
if adoquery1.RecordCount > 0 then
begin
edit2.Text:=adoquery1.FieldValues['wrefid'];
edit3.Text:=adoquery1.FieldValues['handleman'];
edit4.Text:=adoquery1.FieldValues['accounts'];
dtpicker3.Date:=adoquery1.FieldValues['refdate'];
for i:=0 to combobox2.Items.Count-1 do
if copy(combobox2.Items.Strings[i],1,5) = adoquery1.FieldByName('clientid').AsString then
begin
combobox2.ItemIndex:=i;
break;
end;
adoquery2.SQL.Text:='select filname from filiale where filid = '''+adoquery1.FieldValues['filid']+'''';
adoquery2.Open;
for i:=0 to combobox3.Items.Count-1 do
begin
if combobox3.Items.Strings[i] = adoquery2.FieldByName('filname').AsString then
begin
combobox3.ItemIndex:=i;
break;
end;
end;
stringgrid1.RowCount:=adoquery1.RecordCount+1;
arow:=1;
while not adoquery1.Eof do
begin
stringgrid1.Cells[1,arow]:=adoquery1.FieldValues['wrefid'];
stringgrid1.Cells[2,arow]:=adoquery1.FieldValues['clientid'];
stringgrid1.Cells[3,arow]:=adoquery1.FieldValues['refdate'];
adoquery1.Next;
inc(arow);
end;
adoquery1.Close;
stringgrid1.Cols[0].Clear;
stringgrid1.Cells[0,1]:='*';
adoquery1.SQL.Text:='select whrefund1.wrefid,pluinfo.prname,whrefund1.refnum,'+
' whrefund1.price from whrefund1 inner join pluinfo on whrefund1.prid = pluinfo.prid'+
' where whrefund1.wrefid = '''+edit2.Text+'''';
adoquery1.Open;
if adoquery1.RecordCount > 0 then
begin
stringgrid2.RowCount:=adoquery1.RecordCount+1;
for i:=1 to stringgrid2.RowCount-1 do
begin
stringgrid2.Cells[1,i]:=adoquery1.FieldValues['wrefid'];
stringgrid2.Cells[2,i]:=adoquery1.FieldValues['prname'];
stringgrid2.Cells[3,i]:=adoquery1.FieldValues['refnum'];
stringgrid2.Cells[4,i]:=adoquery1.FieldValues['price'];
stringgrid2.Cells[5,i]:=floattostr(strtofloat(stringgrid2.Cells[3,i])*strtofloat(stringgrid2.Cells[4,i]));
adoquery1.Next;
end;
end;
adoquery1.Close;
end
else begin
edit2.Text:='';
edit3.Text:='';
edit4.Text:='';
combobox2.ItemIndex:=-1;
combobox3.ItemIndex:=-1;
end;
end;
procedure Tfrmwhref.SpeedButton2Click(Sender: TObject);
var
ayear,amonth,adate:word;
smonth,sdate,maxid:string;
i:integer;
begin
dtpicker3.Date:=date;
combobox2.Enabled:=true;combobox2.ItemIndex:=-1;
combobox3.Enabled:=true;combobox3.ItemIndex:=-1;
edit3.Enabled:=true;edit3.Text:='';
edit4.Text:='';
dtpicker3.Enabled:=true;
edit1.Enabled:=false;
dtpicker1.Enabled:=false;
dtpicker2.Enabled:=false;
combobox1.Enabled:=false;
speedbutton1.Enabled:=false;
speedbutton2.Enabled:=false;
speedbutton5.Enabled:=true;
speedbutton6.Enabled:=true;
speedbutton7.Enabled:=false;
speedbutton9.Enabled:=false;
decodedate(date,ayear,amonth,adate);
smonth:=inttostr(amonth);sdate:=inttostr(adate);
if length(smonth) < 2 then smonth:= '0'+smonth;
if length(sdate) < 2 then sdate:='0'+sdate;
maxid:=inttostr(ayear)+smonth+sdate;
adoquery1.SQL.Text:='select max(wrefid) as maxid from whrefund where wrefid like '''+maxid+'%''';
adoquery1.Open;
if adoquery1.FieldValues['maxid'] = null then
edit2.Text:=maxid+'0001'
else
edit2.Text:=inttostr(strtoint64(adoquery1.FieldValues['maxid'])+1);
adoquery1.Close;
for i:=1 to stringgrid2.RowCount-1 do
stringgrid2.Rows[i].Clear;
stringgrid2.RowCount:=2;
stringgrid1.Cols[0].Clear;
end;
procedure Tfrmwhref.SpeedButton5Click(Sender: TObject);
var
i:integer;
sclient,sfiliale:string;
totalacc:real;
begin
if edit2.Text = '' then
begin
showmessage('单据编号不能为空');
exit;
end;
if combobox2.Text = '' then
begin
showmessage('客户不能为空!');
exit;
end;
if combobox3.Text = '' then
begin
showmessage('出库分店不能为空');
exit;
end;
if edit3.Text = '' then
begin
showmessage('经手人不能为空');
exit;
end;
totalacc:=0;
for i:=1 to stringgrid2.RowCount-1 do
begin
if stringgrid2.Cells[1,i] = '' then
begin
showmessage('第'+inttostr(i)+'行商品编号不能为空');
exit;
end;
if stringgrid2.Cells[3,i] = '' then
begin
showmessage('第'+inttostr(i)+'行商品数量不能为空');
exit;
end;
if stringgrid2.Cells[4,i] = '' then
begin
showmessage('第'+inttostr(i)+'行商品价格不能为空');
exit;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?