ufilprod.pas

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

PAS
268
字号
unit Ufilprod;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Grids, DB, ADODB, StdCtrls, Buttons;

type
  Tfrmfilprod = class(TForm)
    StringGrid1: TStringGrid;
    ADOQuery1: TADOQuery;
    Label1: TLabel;
    ComboBox1: TComboBox;
    SpeedButton1: TSpeedButton;
    procedure FormCreate(Sender: TObject);
    procedure StringGrid1DblClick(Sender: TObject);
    procedure SpeedButton1Click(Sender: TObject);
  private
    { Private declarations }
  public
    whosel:string;
    { Public declarations }
  end;

var
  frmfilprod: Tfrmfilprod;

implementation

uses Udatamodule, Ubook, Ustockin, Urefund, Uwholesale, Uwhref, Uredeploy,
  Urecloss;

{$R *.dfm}

procedure Tfrmfilprod.FormCreate(Sender: TObject);
var
  i:integer;
begin
  stringgrid1.Cells[0,0]:='商品编号';
  stringgrid1.Cells[1,0]:='条码';
  stringgrid1.Cells[2,0]:='商品名称';
  adoquery1.SQL.Text:='select distinct prid ,plu,prname from pluinfo ';
  adoquery1.Open;
  if adoquery1.RecordCount > 0 then
  begin
    i:=1;
    stringgrid1.RowCount:=adoquery1.RecordCount+1;
    while not adoquery1.Eof do
    begin
      stringgrid1.Cells[0,i]:=adoquery1.Fields[0].AsString;
      stringgrid1.Cells[1,i]:=adoquery1.Fields[1].AsString;
      stringgrid1.Cells[2,i]:=adoquery1.Fields[2].AsString;
      adoquery1.Next;
      inc(i);
    end;
  end;
  adoquery1.Close;
  adoquery1.SQL.Text:='select filname from filiale';
  adoquery1.Open;
  while not adoquery1.Eof do
  begin
    combobox1.Items.Add(adoquery1.FieldValues['filname']);
    adoquery1.next;
  end;  
  adoquery1.Close;  
end;

procedure Tfrmfilprod.StringGrid1DblClick(Sender: TObject);
var
  i,prnum,arow:integer;
begin
  if whosel = 'stockin' then
  begin
    prnum:=0;
    for i:=1 to frmstockin.StringGrid2.RowCount - 1 do
    begin
      if frmstockin.StringGrid2.Cells[1,i] = stringgrid1.Cells[0,stringgrid1.Row] then
        inc(prnum);
    end;
    if prnum = 0 then
    begin
      arow:=frmstockin.StringGrid2.Row;
      frmstockin.StringGrid2.Cells[1,arow]:=stringgrid1.Cells[0,stringgrid1.Row];
      frmstockin.StringGrid2.Cells[2,arow]:=stringgrid1.Cells[2,stringgrid1.Row];
      frmstockin.dxButtonEdit1.Text:=frmstockin.stringgrid2.Cells[frmstockin.stringgrid2.Col,frmstockin.stringgrid2.Row];
      self.Close;
    end
    else
    showmessage('该商品已经添加');
  end;
  if whosel = 'book' then
  begin
    prnum:=0;
    for i:=1 to frmbook.StringGrid1.RowCount - 1 do
    begin
      if frmbook.StringGrid1.Cells[1,i] = stringgrid1.Cells[0,stringgrid1.Row] then
      inc(prnum);
    end;
    if prnum = 0 then
    begin
      frmbook.StringGrid1.Cells[1,frmbook.stringgrid1.Row]:=stringgrid1.Cells[0,stringgrid1.Row];
      frmbook.StringGrid1.Cells[2,frmbook.stringgrid1.Row]:=stringgrid1.Cells[2,stringgrid1.Row];
      frmbook.dxButtonEdit1.Text:=frmbook.StringGrid1.Cells[frmbook.stringgrid1.Col,frmbook.stringgrid1.row];
      self.Close;
    end
    else
      showmessage('该商品已经添加');
  end;
  if whosel='refund' then
  begin
    prnum:=0;
    with frmrefund.StringGrid2 do
    begin
      for i:=1 to RowCount - 1 do
      begin
        if Cells[1,i] = stringgrid1.Cells[0,stringgrid1.Row] then
        inc(prnum);
      end;
      if prnum = 0 then
      begin
        Cells[1,Row]:=stringgrid1.Cells[0,stringgrid1.Row];
        Cells[2,Row]:=stringgrid1.Cells[2,stringgrid1.Row];
        frmrefund.dxButtonEdit1.Text:=Cells[Col,row];
        self.Close;
      end
      else
        showmessage('该商品已经添加');
    end;
  end;
  if whosel='wholesale' then
  begin
    prnum:=0;
    with frmwholesale.StringGrid2 do
    begin
      for i:=1 to RowCount - 1 do
      begin
        if Cells[1,i] = stringgrid1.Cells[0,stringgrid1.Row] then
        inc(prnum);
      end;
      if prnum = 0 then
      begin
        Cells[1,Row]:=stringgrid1.Cells[0,stringgrid1.Row];
        Cells[2,Row]:=stringgrid1.Cells[2,stringgrid1.Row];
        frmwholesale.dxButtonEdit1.Text:=Cells[Col,row];
        adoquery1.SQL.Text:='select stockin1.stoprice,stockin.stockdate'
        +' from stockin1 inner join stockin on stockin1.stockid = stockin.stockid '
        +'where ((stockin1.prid ='''+Cells[1,Row]+''') and (stockin.stockdate <=#'
        +datetostr(date)+'#)) order by stockin.stockdate desc';
        adoquery1.Open;
        if adoquery1.Fieldbyname('stoprice').AsString <> '' then
        Cells[4,Row]:=adoquery1.FieldValues['stoprice'];
        adoquery1.Close;
        self.Close;
      end
      else
        showmessage('该商品已经添加');
    end;
  end;
  if whosel='whrefund' then
  begin
    prnum:=0;
    with frmwhref.StringGrid2 do
    begin
      for i:=1 to RowCount - 1 do
      begin
        if Cells[1,i] = stringgrid1.Cells[0,stringgrid1.Row] then
        inc(prnum);
      end;
      if prnum = 0 then
      begin
        Cells[1,Row]:=stringgrid1.Cells[0,stringgrid1.Row];
        Cells[2,Row]:=stringgrid1.Cells[2,stringgrid1.Row];
        frmwhref.dxButtonEdit1.Text:=Cells[Col,row];
        self.Close;
      end
      else
        showmessage('该商品已经添加');
    end;
  end;
  if whosel='redeploy' then
  begin
    prnum:=0;
    with frmredeploy.StringGrid2 do
    begin
      for i:=1 to RowCount - 1 do
      begin
        if Cells[1,i] = stringgrid1.Cells[0,stringgrid1.Row] then
        inc(prnum);
      end;
      if prnum = 0 then
      begin
        Cells[1,Row]:=stringgrid1.Cells[0,stringgrid1.Row];
        Cells[2,Row]:=stringgrid1.Cells[2,stringgrid1.Row];
        frmredeploy.dxButtonEdit1.Text:=Cells[Col,row];
        self.Close;
      end
      else
        showmessage('该商品已经添加');
    end;
  end;
  if whosel='recloss' then
  begin
    prnum:=0;
    with frmrecloss.StringGrid2 do
    begin
      for i:=1 to RowCount - 1 do
      begin
        if Cells[1,i] = stringgrid1.Cells[0,stringgrid1.Row] then
        inc(prnum);
      end;
      if prnum = 0 then
      begin
        Cells[1,Row]:=stringgrid1.Cells[0,stringgrid1.Row];
        Cells[2,Row]:=stringgrid1.Cells[2,stringgrid1.Row];
        frmrecloss.dxButtonEdit1.Text:=Cells[Col,row];
        self.Close;
      end
      else
        showmessage('该商品已经添加');
    end;
  end;
end;

procedure Tfrmfilprod.SpeedButton1Click(Sender: TObject);
var
  sfilid:string;
  i,arow:integer;
begin
  if combobox1.Text = '' then
  begin
    showmessage('请输入分店名称');
    exit;
  end;
  for i:=1 to stringgrid1.RowCount-1 do
  stringgrid1.Rows[i].Clear;
  stringgrid1.RowCount:=2;
  if combobox1.Text = '全部' then
  begin
    adoquery1.SQL.Text:='select distinct prid ,plu,prname from pluinfo';
  end
  else
  begin
    adoquery1.SQL.Text:='select filid from filiale where filname = '''+combobox1.Text+'''';
    adoquery1.Open;
    sfilid:=adoquery1.FieldValues['filid'];
    adoquery1.Close;
    adoquery1.SQL.Text:='select busary.prid,pluinfo.plu,pluinfo.prname from busary'
    +' inner join pluinfo on busary.prid = pluinfo.prid where filid = '''+sfilid+'''';
  end;
  adoquery1.Open;
  if adoquery1.RecordCount > 0 then
  begin
    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;
      adoquery1.Next;
      inc(arow);
    end;  
  end;  
end;

end.

⌨️ 快捷键说明

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