urecloss.~pas

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

~PAS
500
字号
unit Urecloss;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Grids, Buttons, ComCtrls, ExtCtrls, dxCntner,
  dxEditor, dxExEdtr, dxEdLib, Menus, DB, ADODB, RpCon, RpConDS, RpDefine,
  RpRave, RVClass,RVCsStd, RpBase, RpSystem;

type
  Tfrmrecloss = class(TForm)
    Panel1: TPanel;
    Label1: TLabel;
    Edit1: TEdit;
    Label2: TLabel;
    DatePicker1: TDateTimePicker;
    DatePicker2: TDateTimePicker;
    SpeedButton1: TSpeedButton;
    StringGrid1: TStringGrid;
    Panel2: TPanel;
    Label3: TLabel;
    Label4: TLabel;
    Edit2: TEdit;
    Label5: TLabel;
    Edit3: TEdit;
    Label6: TLabel;
    Label7: TLabel;
    DatePicker3: TDateTimePicker;
    ComboBox1: TComboBox;
    Label8: TLabel;
    SpeedButton2: TSpeedButton;
    SpeedButton3: TSpeedButton;
    SpeedButton4: TSpeedButton;
    SpeedButton5: TSpeedButton;
    SpeedButton6: TSpeedButton;
    PopupMenu1: TPopupMenu;
    N1: TMenuItem;
    N2: TMenuItem;
    ADOQuery1: TADOQuery;
    ADOQuery2: TADOQuery;
    ADOQuery3: TADOQuery;
    StringGrid2: TStringGrid;
    dxButtonEdit1: TdxButtonEdit;
    RvProject1: TRvProject;
    lossConnection1: TRvDataSetConnection;
    RvDataSetConnection2: TRvDataSetConnection;
    procedure FormCreate(Sender: TObject);
    procedure StringGrid1SelectCell(Sender: TObject; ACol, ARow: Integer;
      var CanSelect: Boolean);
    procedure SpeedButton1Click(Sender: TObject);
    procedure SpeedButton2Click(Sender: TObject);
    procedure SpeedButton3Click(Sender: TObject);
    procedure SpeedButton6Click(Sender: TObject);
    procedure SpeedButton4Click(Sender: TObject);
    procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
    procedure StringGrid2SelectCell(Sender: TObject; ACol, ARow: Integer;
      var CanSelect: Boolean);
    procedure dxButtonEdit1Exit(Sender: TObject);
    procedure dxButtonEdit1ButtonClick(Sender: TObject;
      AbsoluteIndex: Integer);
    procedure N1Click(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure SpeedButton5Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmrecloss: Tfrmrecloss;

implementation

uses Udatamodule, Ufilprod;

{$R *.dfm}

procedure Tfrmrecloss.FormCreate(Sender: TObject);
var
  i,arow:integer;
begin
  datepicker1.Date:=date-7;
  datepicker2.Date:=date;
  datepicker3.Date:=date;
  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]:='损失原因';
  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 losskid,lossdate,filid,handleman from recloss';
  adoquery1.Open;
  if adoquery1.RecordCount > 0 then
  begin
    stringgrid1.RowCount:=adoquery1.RecordCount+1;
    stringgrid1.Cells[0,1]:='*';
    edit2.Text:=adoquery1.Fields[0].AsString;
    adoquery2.SQL.Text:='select filname from filiale where filid = '''+adoquery1.FieldValues['filid']+'''';
    adoquery2.Open;
    for i:=0 to combobox1.Items.Count-1 do
    if combobox1.Items.Strings[i] = adoquery2.FieldByName('filname').AsString then
    combobox1.itemindex:=i;
    adoquery2.Close;
    datepicker3.Date:=adoquery1.FieldValues['lossdate'];
    edit3.text:=adoquery1.Fields[3].AsString;
    arow:=1;
    while not adoquery1.eof do
    begin
      stringgrid1.Cells[1,arow]:=adoquery1.Fields[0].AsString;
      stringgrid1.Cells[2,arow]:=adoquery1.FieldValues['filid'];
      stringgrid1.Cells[3,arow]:=adoquery1.Fields[1].AsString;
      adoquery1.Next;
      inc(arow);
    end;
  end;
  adoquery1.Close;
  adoquery1.SQL.Text:='select recloss1.prid,pluinfo.prname,recloss1.lossnum,'
  +'recloss1.cause from recloss1 inner join pluinfo on recloss1.prid ='
  +' pluinfo.prid where lossid = '''+edit2.Text+'''';
  adoquery1.Open;
  if adoquery1.RecordCount > 0 then
  begin
    stringgrid2.RowCount:=adoquery1.RecordCount + 1;
    arow:=1;
    while not adoquery1.Eof do
    begin
      stringgrid2.Cells[1,arow]:=adoquery1.Fields[0].AsString;
      stringgrid2.Cells[2,arow]:=adoquery1.Fields[1].AsString;
      stringgrid2.Cells[3,arow]:=adoquery1.Fields[2].AsString;
      stringgrid2.Cells[4,arow]:=adoquery1.Fields[3].AsString;
      adoquery1.Next;
      inc(arow);
    end;
  end;
end;

procedure Tfrmrecloss.StringGrid1SelectCell(Sender: TObject; ACol,
  ARow: Integer; var CanSelect: Boolean);
var
  i,irow:integer;
begin
  if ((not speedbutton3.Enabled) and (stringgrid1.Cells[1,arow] <> '')) then
  begin
    stringgrid1.Cols[0].Clear;
    stringgrid1.Cells[0,arow]:='*';
    edit2.Text:=stringgrid1.Cells[1,arow];
    adoquery2.SQL.Text:='select filname from filiale where filid = '''+stringgrid1.Cells[2,arow]+'''';
    adoquery2.Open;
    for i:=0 to combobox1.Items.Count-1 do
    if combobox1.Items.Strings[i] = adoquery2.FieldByName('filname').AsString then
    combobox1.itemindex:=i;
    adoquery2.Close;
    datepicker3.date:=strtodate(stringgrid1.Cells[3,arow]);
    adoquery1.SQL.Text:='select handleman from recloss where losskid = '''+edit2.Text+'''';
    adoquery1.Open;
    edit3.Text:=adoquery1.Fields[0].AsString;
    adoquery1.Close;
    for i:=1 to stringgrid2.RowCount-1 do
      stringgrid2.Rows[i].Clear;
    stringgrid2.RowCount:=2;  
    adoquery1.SQL.Text:='select recloss1.prid,pluinfo.prname,recloss1.lossnum,'
    +'recloss1.cause from recloss1 inner join pluinfo on recloss1.prid ='
    +' pluinfo.prid where lossid = '''+edit2.Text+'''';
    adoquery1.Open;
    if adoquery1.RecordCount > 0 then
    begin
      stringgrid2.RowCount:=adoquery1.RecordCount + 1;
      irow:=1;
      while not adoquery1.Eof do
      begin
        stringgrid2.Cells[1,irow]:=adoquery1.Fields[0].AsString;
        stringgrid2.Cells[2,irow]:=adoquery1.Fields[1].AsString;
        stringgrid2.Cells[3,irow]:=adoquery1.Fields[2].AsString;
        stringgrid2.Cells[4,irow]:=adoquery1.Fields[3].AsString;
        adoquery1.Next;
        inc(irow);
      end;
    end;
  end;
end;

procedure Tfrmrecloss.SpeedButton1Click(Sender: TObject);
var
  i,arow:integer;
begin
  for i:=1 to stringgrid2.RowCount-1 do
  stringgrid2.Rows[i].Clear;
  stringgrid2.RowCount:=2;
  for i:=1 to stringgrid1.RowCount-1 do
  stringgrid1.Rows[i].Clear;
  stringgrid1.Rowcount:=2;
  adoquery1.SQL.Text:='select losskid,lossdate,filid,handleman from recloss where'
  +' lossdate between #'+datetostr(datepicker1.Date)+'# and #'+datetostr(datepicker2.Date)+'#';
  if edit1.Text <> '' then
    adoquery1.SQL.add('and losskid = '''+edit1.Text+'''');
  adoquery1.Open;
  if adoquery1.RecordCount > 0 then
  begin
    stringgrid1.RowCount:=adoquery1.RecordCount+1;
    stringgrid1.Cells[0,1]:='*';
    edit2.Text:=adoquery1.Fields[0].AsString;
    adoquery2.SQL.Text:='select filname from filiale where filid = '''+adoquery1.Fields[2].AsString+'''';
    adoquery2.Open;
    for i:=1 to combobox1.Items.Count-1 do
    if combobox1.Items.Strings[i] = adoquery2.FieldByName('filname').AsString then
    combobox1.itemindex:=i;
    adoquery2.Close;
    datepicker3.Date:=adoquery1.FieldValues['lossdate'];
    edit3.text:=adoquery1.Fields[3].AsString;
    arow:=1;
    while not adoquery1.eof do
    begin
      stringgrid1.Cells[1,arow]:=adoquery1.Fields[0].AsString;
      stringgrid1.Cells[2,arow]:=adoquery1.Fields[2].AsString;
      stringgrid1.Cells[3,arow]:=adoquery1.Fields[1].AsString;
      adoquery1.Next;
      inc(arow);
    end;
    adoquery1.Close;
    adoquery1.SQL.Text:='select recloss1.prid,pluinfo.prname,recloss1.lossnum,'
    +'recloss1.cause from recloss1 inner join pluinfo on recloss1.prid ='
    +' pluinfo.prid where lossid = '''+stringgrid1.Cells[1,stringgrid1.Row]+'''';
    adoquery1.Open;
    if adoquery1.RecordCount > 0 then
    begin
      stringgrid2.RowCount:=adoquery1.RecordCount + 1;
      arow:=1;
      while not adoquery1.Eof do
      begin
        stringgrid2.Cells[1,arow]:=adoquery1.Fields[0].AsString;
        stringgrid2.Cells[2,arow]:=adoquery1.Fields[1].AsString;
        stringgrid2.Cells[3,arow]:=adoquery1.Fields[2].AsString;
        stringgrid2.Cells[4,arow]:=adoquery1.Fields[3].AsString;
        adoquery1.Next;
        inc(arow);
      end;
    end;
  end;
end;

⌨️ 快捷键说明

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