udeptsale.~pas

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

~PAS
146
字号
unit Udeptsale;

interface

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

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

var
  frmdeptsale: Tfrmdeptsale;
  sqlstr:string;

implementation

uses Udatamodule;

{$R *.dfm}

procedure Tfrmdeptsale.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;
  adoquery1.SQL.Text:='select classname from classinfo';
  while not adoquery1.Eof do
  begin
    combobox2.Items.Add(adoquery1.Fields[0].asstring);
    adoquery1.Next;
  end;
  adoquery1.Close;
  combobox1.ItemIndex:=0;
  combobox2.ItemIndex:=0;
end;

procedure Tfrmdeptsale.SpeedButton1Click(Sender: TObject);
var
  sfilid,sprkind:string;
  i:integer;
begin
  for i:=1 to stringgrid1.RowCount-1 do
    stringgrid1.Rows[i].Clear;
  stringgrid1.RowCount:=2;  
  adoquery1.SQL.Text:='select deptsale.deptid,classinfo.classname,deptsale.filid,'
  +'deptsale.salenum,deptsale.saletotal,deptsale.transdate from deptsale'
  +' inner join classinfo on deptsale.deptid = classinfo.classid 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;
    adoquery2.Close;
    adoquery1.SQL.Add('and deptsale.deptid = '''+sfilid+'''');
  end;
  if combobox2.Text <> '全部' then
  begin
    adoquery2.SQL.Text:='select classid from classinfo where classname = '''+combobox2.Text+'''';
    adoquery2.Open;
    sprkind:=adoquery2.Fields[0].AsString;
    adoquery2.Close;
    adoquery1.SQL.Add('and pluinfo.classid = '''+sprkind+'''');
  end;
  adoquery1.Open;
  if adoquery1.RecordCount > 0 then
  begin
    sqlstr:=adoquery1.SQL.Text;
    stringgrid1.RowCount:=adoquery1.RecordCount+1;
    for i:=1 to stringgrid1.RowCount-1 do
    begin
      stringgrid1.Cells[0,i]:=adoquery1.FieldValues['deptid'];
      stringgrid1.Cells[1,i]:=adoquery1.FieldValues['classname'];
      stringgrid1.Cells[2,i]:=adoquery1.FieldValues['filid'];
      stringgrid1.Cells[3,i]:=adoquery1.FieldValues['salenum'];
      stringgrid1.Cells[4,i]:=adoquery1.FieldValues['saletotal'];
      stringgrid1.Cells[5,i]:=adoquery1.FieldValues['transdate'];
      adoquery1.Next;
    end;
  end;
  adoquery1.Close;
end;

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

procedure Tfrmdeptsale.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 + -
显示快捷键?