uwholesale.~pas
来自「DELPHI编程入门篇.从基础入手,浅显易懂,一定物有所值.」· ~PAS 代码 · 共 696 行 · 第 1/2 页
~PAS
696 行
unit Uwholesale;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, ADODB, Menus, dxCntner, dxEditor, dxExEdtr, dxEdLib,
Buttons, Grids, ComCtrls, StdCtrls, ExtCtrls, RpCon, RpConDS, RpDefine,
RpRave;
type
Tfrmwholesale = 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;
StringGrid2: TStringGrid;
SpeedButton2: TSpeedButton;
SpeedButton5: TSpeedButton;
SpeedButton6: TSpeedButton;
SpeedButton7: TSpeedButton;
SpeedButton9: TSpeedButton;
dxButtonEdit1: TdxButtonEdit;
PopupMenu1: TPopupMenu;
N1: TMenuItem;
N2: TMenuItem;
ADOQuery1: TADOQuery;
ADOQuery2: TADOQuery;
ADOQuery3: TADOQuery;
Panel1: TPanel;
Label1: TLabel;
Label2: TLabel;
Label4: TLabel;
SpeedButton1: TSpeedButton;
Label10: TLabel;
Edit1: TEdit;
DTPicker1: TDateTimePicker;
DTPicker2: TDateTimePicker;
ComboBox1: TComboBox;
StringGrid1: TStringGrid;
RvProject1: TRvProject;
wholesaleConnection1: TRvDataSetConnection;
wholesaleConnection2: TRvDataSetConnection;
procedure FormCreate(Sender: TObject);
procedure SpeedButton1Click(Sender: TObject);
procedure SpeedButton2Click(Sender: TObject);
procedure SpeedButton5Click(Sender: TObject);
procedure SpeedButton6Click(Sender: TObject);
procedure SpeedButton9Click(Sender: TObject);
procedure N1Click(Sender: TObject);
procedure N2Click(Sender: TObject);
procedure StringGrid1Click(Sender: TObject);
procedure StringGrid2SelectCell(Sender: TObject; ACol, ARow: Integer;
var CanSelect: Boolean);
procedure StringGrid2KeyPress(Sender: TObject; var Key: Char);
procedure StringGrid2KeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure StringGrid2Exit(Sender: TObject);
procedure dxButtonEdit1Exit(Sender: TObject);
procedure dxButtonEdit1ButtonClick(Sender: TObject;
AbsoluteIndex: Integer);
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
procedure SpeedButton7Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
frmwholesale: Tfrmwholesale;
implementation
uses Udatamodule, Ufilprod;
{$R *.dfm}
procedure Tfrmwholesale.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]:='商品售价';
stringgrid2.Cells[6,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 wholesale ';
adoquery1.Open;
if adoquery1.RecordCount > 0 then
begin
edit2.Text:=adoquery1.FieldValues['wholesaleid'];
edit3.Text:=adoquery1.FieldValues['handleman'];
edit4.Text:=adoquery1.FieldValues['accounts'];
dtpicker3.Date:=adoquery1.FieldValues['saledate'];
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['wholesaleid'];
stringgrid1.Cells[2,arow]:=adoquery1.FieldValues['clientid'];
stringgrid1.Cells[3,arow]:=adoquery1.FieldValues['saledate'];
adoquery1.Next;
inc(arow);
end;
adoquery1.Close;
stringgrid1.Cols[0].Clear;
stringgrid1.Cells[0,1]:='*';
adoquery1.SQL.Text:='select wholesale1.wholesaleid,pluinfo.prname,wholesale1.salenum,'+
' wholesale1.price,wholesale1.costprice from wholesale1 inner join pluinfo on '+
' wholesale1.prid = pluinfo.prid where wholesaleid = '''+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['wholesaleid'];
stringgrid2.Cells[2,i]:=adoquery1.FieldValues['prname'];
stringgrid2.Cells[3,i]:=adoquery1.FieldValues['salenum'];
stringgrid2.Cells[4,i]:=adoquery1.FieldValues['costprice'];
stringgrid2.Cells[5,i]:=adoquery1.FieldValues['price'];
stringgrid2.Cells[6,i]:=floattostr(strtofloat(stringgrid2.Cells[3,i])*strtofloat(stringgrid2.Cells[4,i]));
adoquery1.Next;
end;
end;
adoquery1.Close;
end;
end;
procedure Tfrmwholesale.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;
stringgrid2.RowCount:=2;
adoquery1.SQL.Text:='select wholesaleid,clientid,saledate,handleman,filid,'
+'accounts from wholesale where saledate between #'+datetostr(dtpicker1.date)
+'# and #'+datetostr(dtpicker2.date)+'#';
if edit1.Text <> '' then
adoquery1.SQL.Add('and wholesaleid = '''+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['wholesaleid'];
edit3.Text:=adoquery1.FieldValues['handleman'];
edit4.Text:=adoquery1.FieldValues['accounts'];
dtpicker3.Date:=adoquery1.FieldValues['saledate'];
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['wholesaleid'];
stringgrid1.Cells[2,arow]:=adoquery1.FieldValues['clientid'];
stringgrid1.Cells[3,arow]:=adoquery1.FieldValues['saledate'];
adoquery1.Next;
inc(arow);
end;
adoquery1.Close;
stringgrid1.Cols[0].Clear;
stringgrid1.Cells[0,1]:='*';
adoquery1.SQL.Text:='select wholesale1.wholesaleid,pluinfo.prname,wholesale1.salenum,'+
' wholesale1.price,wholesale1.costprice from wholesale1 inner join pluinfo on '+
'wholesale1.prid = pluinfo.prid where wholesaleid = '''+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['wholesaleid'];
stringgrid2.Cells[2,i]:=adoquery1.FieldValues['prname'];
stringgrid2.Cells[3,i]:=adoquery1.FieldValues['salenum'];
stringgrid2.Cells[4,i]:=adoquery1.FieldValues['costprice'];
stringgrid2.Cells[5,i]:=adoquery1.FieldValues['price'];
stringgrid2.Cells[6,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 Tfrmwholesale.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(wholesaleid) as maxid from wholesale where wholesaleid 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 Tfrmwholesale.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)+'行商品编号不能为空');
stringgrid2.Col:=1;
exit;
end;
if stringgrid2.Cells[3,i] = '' then
begin
showmessage('第'+inttostr(i)+'行商品数量不能为空');
stringgrid2.Col:=3;
exit;
end;
if stringgrid2.Cells[5,i] = '' then
begin
showmessage('第'+inttostr(i)+'行商品售价不能为空');
stringgrid2.Col:=5;
exit;
end;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?