usalesman.pas

来自「DELPHI编程入门篇.从基础入手,浅显易懂,一定物有所值.」· PAS 代码 · 共 150 行

PAS
150
字号
unit Usalesman;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Grids, ComCtrls, Buttons, ExtCtrls, DB, ADODB, RpCon,
  RpConDS, RpDefine, RpRave;

type
  Tfrmsalesman = class(TForm)
    Panel1: TPanel;
    SpeedButton1: TSpeedButton;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label5: TLabel;
    Label4: TLabel;
    DatePicker1: TDateTimePicker;
    DatePicker2: TDateTimePicker;
    ComboBox1: TComboBox;
    StringGrid1: TStringGrid;
    SpeedButton2: TSpeedButton;
    SpeedButton3: TSpeedButton;
    Edit1: TEdit;
    ADOQuery1: TADOQuery;
    ADOQuery2: TADOQuery;
    RvProject1: TRvProject;
    salesmanConnection1: TRvDataSetConnection;
    procedure FormCreate(Sender: TObject);
    procedure SpeedButton1Click(Sender: TObject);
    procedure Edit1Exit(Sender: TObject);
    procedure Edit1KeyPress(Sender: TObject; var Key: Char);
    procedure SpeedButton3Click(Sender: TObject);
    procedure SpeedButton2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmsalesman: Tfrmsalesman;
  sqlstr:string;

implementation

uses Udatamodule;

{$R *.dfm}

procedure Tfrmsalesman.FormCreate(Sender: TObject);
begin
  datepicker1.Date:=date-7;
  datepicker2.Date:=date;
  stringgrid1.Cells[0,0]:='收款员编号';
  stringgrid1.Cells[1,0]:='收款员名称';
  stringgrid1.Cells[2,0]:='分店号';
  stringgrid1.Cells[3,0]:='销售数量';
  stringgrid1.Cells[4,0]:='销售金额';
  stringgrid1.Cells[5,0]:='上传时间';
  adoquery1.SQL.Text:='select filname from filiale';
  adoquery1.Open;
  while not adoquery1.Eof do
  begin
    combobox1.Items.Add(adoquery1.Fields[0].asstring);
    adoquery1.Next;
  end;
  adoquery1.Close;
  combobox1.ItemIndex:=0;
end;

procedure Tfrmsalesman.SpeedButton1Click(Sender: TObject);
var
  i,arow:integer;
  sfilid:string;
begin
  for i:=1 to stringgrid1.RowCount-1 do
  stringgrid1.Rows[i].Clear;
  stringgrid1.RowCount:=2;
  adoquery1.SQL.Text:='select busman.empid,empinfo.empname,busman.filid,'
  +'busman.salenum,busman.saletotal,busman.transdate from busman inner join '
  +'empinfo on busman.empid = empinfo.empid where transdate between '
  +'#'+datetostr(datepicker1.date)+'# and #'+datetostr(datepicker2.date)+'#';
  if combobox1.Text <> '全部' then
  begin
    adoquery2.SQL.Text:='select filid from filiale where filname = '''+combobox1.Text+'''';
    adoquery2.Open;
    sfilid:=adoquery2.Fields[0].AsString;
    adoquery1.SQL.Add('and busman.filid = '''+sfilid+'''');
  end;
  if edit1.Text <> '' then
  adoquery1.SQL.Add('and busman.empid = '''+edit1.Text+'''');
  adoquery1.Open;
  if adoquery1.RecordCount > 0 then
  begin
    sqlstr:=adoquery1.SQL.Text;
    stringgrid1.RowCount:=adoquery1.RecordCount+1;
    arow:=1;
    while not adoquery1.Eof do
    begin
      stringgrid1.Cells[0,arow]:=adoquery1.Fields[0].AsString;
      stringgrid1.Cells[1,arow]:=adoquery1.Fields[1].AsString;
      stringgrid1.Cells[2,arow]:=adoquery1.Fields[2].AsString;
      stringgrid1.Cells[3,arow]:=adoquery1.Fields[3].AsString;
      stringgrid1.Cells[4,arow]:=adoquery1.Fields[4].AsString;
      stringgrid1.Cells[5,arow]:=adoquery1.Fields[5].AsString;
      adoquery1.Next;
      inc(arow);
    end;
  end;    
end;

procedure Tfrmsalesman.Edit1Exit(Sender: TObject);
begin
  while length(edit1.Text) < 5 do
  edit1.Text:='0'+edit1.Text;
end;

procedure Tfrmsalesman.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
  if ((not (key in ['0'..'9'])) and (key <> #8)) then
  begin
    showmessage('');
    key:=chr(0);
    exit;
  end;
end;

procedure Tfrmsalesman.SpeedButton3Click(Sender: TObject);
begin
  modalresult:=mrcancel;
end;

procedure Tfrmsalesman.SpeedButton2Click(Sender: TObject);
begin
  if stringgrid1.Cells[0,1] <> '' then
  begin
    adoquery1.SQL.Text:=sqlstr;
    adoquery1.Open;
    rvproject1.Execute;
    rvproject1.Close;
    adoquery1.Close;
  end
  else
    showmessage('请先查询要打印的数据');  
end;

end.

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?