⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 storage.pas

📁 完整的delphi书籍源代码,大家有空的时候自己慢慢看看
💻 PAS
字号:
unit Storage;

interface

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

type
  TStorageFrm = class(TForm)
    GroupBox1: TGroupBox;
    RadioButton1: TRadioButton;
    Button1: TButton;
    Button2: TButton;
    RadioButton2: TRadioButton;
    GroupBox2: TGroupBox;
    StringGrid1: TStringGrid;
    ADOQuery1: TADOQuery;
    ADOQuery2: TADOQuery;
    Edit1: TEdit;
    Button3: TButton;
    Button4: TButton;
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  StorageFrm: TStorageFrm;
  count:integer;

implementation

{$R *.dfm}

procedure TStorageFrm.FormCreate(Sender: TObject);
begin
     with stringgrid1 do
     begin
      cells[0,0]:='货品条码';
      cells[1,0]:='货品名称';
      cells[2,0]:='货品规格';
      cells[3,0]:='计量单位';
      cells[4,0]:='入库数量';
      cells[5,0]:='出库数量';
      cells[6,0]:='库存下限';
      cells[7,0]:='库存数量';
      cells[8,0]:='库存上限';
     end;
end;

procedure TStorageFrm.Button1Click(Sender: TObject);
var StockQuantity,SellQuantity,StorageQuantity:real;
    ProductCode,ProductName,Spec,PUnit,MinSto,MaxSto:string;
    i:integer;
begin
    for i:=1 to count do
     begin
      with stringgrid1 do
       begin
        cells[0,i]:='';
        cells[1,i]:='';
        cells[2,i]:='';
        cells[3,i]:='';
        cells[4,i]:='';
        cells[5,i]:='';
        cells[6,i]:='';
        cells[7,i]:='';
        cells[8,i]:='';
       end;
      next;
     end;

    if Radiobutton1.checked=true then
       if edit1.text='' then
          showmessage('请输入相应查询条件')
       else
       begin
        with adoquery1 do
         begin
          close;
          sql.clear;
          sql.add('select * from Product where ProductPYSZ='+''''+edit1.text+'''');
          open;
          first;
          if Recordcount=0 then
            showmessage('没有您查询的货品,请检查输入条件的正确性!')
          else
          begin
            ProductCode:=fieldbyname('ProductCode').asstring;
            ProductName:=fieldbyname('ProductName').asstring;
            Spec:=fieldbyname('Spec').asstring;
            PUnit:=fieldbyname('Unit').asstring;
            MinSto:= fieldbyname('Minsto').asstring;
            Maxsto:= fieldbyname('Maxsto').asstring;

            with adoquery2 do
            begin
             close;
             sql.clear;
             sql.add('select sum(quantity) StockQuantity from Stock');
             sql.add(' where productname='+''''+productname+'''');
             open;
             first;
             if fieldbyname('StockQuantity').asstring='' then
                StockQuantity:=0
             else
                StockQuantity:=fieldbyname('StockQuantity').asfloat;
            end;
           
            with adoquery2 do
            begin
             close;
             sql.clear;
             sql.add('select sum(quantity) Sellquantity from Sell');
             sql.add('where ProductName='+''''+ProductName+'''' );
             open;
             first;
             if fieldbyname('Sellquantity').AsString='' then
                Sellquantity:=0
             else
                Sellquantity:=fieldbyname('Sellquantity').AsFloat;
             end;
             StorageQuantity:=Stockquantity-Sellquantity;

            with stringgrid1 do
            begin
             cells[0,1]:=ProductCode;
             cells[1,1]:=ProductName;
             cells[2,1]:=Spec;
             cells[3,1]:=PUnit;
             cells[4,1]:=floattostr(StockQuantity);
             cells[5,1]:=floattostr(SellQuantity);
             cells[6,1]:=MinSto;
             cells[7,1]:=floattostr(StorageQuantity);
             cells[8,1]:=MaxSto;
            end;
        end;
      end;
    end;

    if Radiobutton2.checked=true then
       begin
        with adoquery1 do
         begin
          close;
          sql.clear;
          sql.add('select sum(Quantity) StockQuantity,ProductName ');
          sql.add('from Stock group by ProductName');
          open;
          first;
          count:=recordcount;
          for i:=1 to recordcount do
           begin
            ProductName:=fieldbyname('ProductName').asstring;
            StockQuantity:=fieldbyname('StockQuantity').asfloat;
            with adoquery2 do
             begin
              close;
              sql.clear;
              sql.add('select sum(Quantity) SellQuantity from Sell');
              sql.add('where ProductName='+''''+ProductName+'''');
              open;
              first;
              if fieldbyname('SellQuantity').AsString='' then
                 SellQuantity:=0
              else
                 SellQuantity:=fieldbyname('SellQuantity').Asfloat;
             end;
            StorageQuantity:=Stockquantity-Sellquantity;

            with adoquery2 do
             begin
              close;
              sql.clear;
              sql.add('select * from Product where ProductName=');
              sql.add(''''+ProductName+'''');
              open;
              first;
              ProductCode:=fieldbyname('ProductCode').asstring;
              Spec:=fieldbyname('Spec').asstring;
              PUnit:=fieldbyname('Unit').asstring;
              MinSto:= fieldbyname('Minsto').asstring;
              Maxsto:= fieldbyname('Maxsto').asstring;
              with stringgrid1 do
               begin
                cells[0,i]:=ProductCode;
                cells[1,i]:=ProductName;
                cells[2,i]:=Spec;
                cells[3,i]:=PUnit;
                cells[4,i]:=floattostr(StockQuantity);
                cells[5,i]:=floattostr(SellQuantity);
                cells[6,i]:=MinSto;
                cells[7,i]:=floattostr(StorageQuantity);
                cells[8,i]:=MaxSto;
               end;
             end;
            next;
           end;
        end;
      end;

end;

procedure TStorageFrm.Button2Click(Sender: TObject);
begin
    StorageFrm.hide;
end;

procedure TStorageFrm.Button3Click(Sender: TObject);
var StockQuantity,SellQuantity,StorageQuantity:real;
    ProductCode,ProductName,Spec,PUnit,MinSto,MaxSto:string;
    i,flag:integer;
begin
    flag:=0;
    for i:=1 to count do
     begin
      with stringgrid1 do
       begin
        cells[0,i]:='';
        cells[1,i]:='';
        cells[2,i]:='';
        cells[3,i]:='';
        cells[4,i]:='';
        cells[5,i]:='';
        cells[6,i]:='';
        cells[7,i]:='';
        cells[8,i]:='';
       end;
      next;
     end;
       with adoquery1 do
         begin
          close;
          sql.clear;
          sql.add('select sum(Quantity) StockQuantity,ProductName ');
          sql.add('from Stock group by ProductName');
          open;
          first;
          count:=recordcount;
          for i:=1 to recordcount do
           begin
            ProductName:=fieldbyname('ProductName').asstring;
            StockQuantity:=fieldbyname('StockQuantity').asfloat;
            with adoquery2 do
             begin
              close;
              sql.clear;
              sql.add('select sum(Quantity) SellQuantity from Sell');
              sql.add('where ProductName='+''''+ProductName+'''');
              open;
              first;
              if fieldbyname('SellQuantity').AsString='' then
                 SellQuantity:=0
              else
                 SellQuantity:=fieldbyname('SellQuantity').Asfloat;
             end;
            StorageQuantity:=Stockquantity-Sellquantity;

            with adoquery2 do
             begin
              close;
              sql.clear;
              sql.add('select * from Product where ProductName=');
              sql.add(''''+ProductName+'''');
              open;
              first;
              ProductCode:=fieldbyname('ProductCode').asstring;
              Spec:=fieldbyname('Spec').asstring;
              PUnit:=fieldbyname('Unit').asstring;
              MinSto:= fieldbyname('Minsto').asstring;
              Maxsto:= fieldbyname('Maxsto').asstring;
              if strtofloat(MinSto)> StorageQuantity then
              begin
              flag:=1;
              with stringgrid1 do
               begin
                cells[0,i]:=ProductCode;
                cells[1,i]:=ProductName;
                cells[2,i]:=Spec;
                cells[3,i]:=PUnit;
                cells[4,i]:=floattostr(StockQuantity);
                cells[5,i]:=floattostr(SellQuantity);
                cells[6,i]:=MinSto;
                cells[7,i]:=floattostr(StorageQuantity);
                cells[8,i]:=MaxSto;
               end;
              end;
             end;
            next;
           end;
           if flag=0 then
              showmessage('没有短线货品!');
        end;

end;

procedure TStorageFrm.Button4Click(Sender: TObject);
var StockQuantity,SellQuantity,StorageQuantity:real;
    ProductCode,ProductName,Spec,PUnit,MinSto,MaxSto:string;
    i,flag:integer;
begin
    flag:=0;
    for i:=1 to count do
     begin
      with stringgrid1 do
       begin
        cells[0,i]:='';
        cells[1,i]:='';
        cells[2,i]:='';
        cells[3,i]:='';
        cells[4,i]:='';
        cells[5,i]:='';
        cells[6,i]:='';
        cells[7,i]:='';
        cells[8,i]:='';
       end;
      next;
     end;
       with adoquery1 do
         begin
          close;
          sql.clear;
          sql.add('select sum(Quantity) StockQuantity,ProductName ');
          sql.add('from Stock group by ProductName');
          open;
          first;
          count:=recordcount;
          for i:=1 to recordcount do
           begin
            ProductName:=fieldbyname('ProductName').asstring;
            StockQuantity:=fieldbyname('StockQuantity').asfloat;
            with adoquery2 do
             begin
              close;
              sql.clear;
              sql.add('select sum(Quantity) SellQuantity from Sell');
              sql.add('where ProductName='+''''+ProductName+'''');
              open;
              first;
              if fieldbyname('SellQuantity').AsString='' then
                 SellQuantity:=0
              else
                 SellQuantity:=fieldbyname('SellQuantity').AsFloat;
             end;
            StorageQuantity:=Stockquantity-Sellquantity;

            with adoquery2 do
             begin
              close;
              sql.clear;
              sql.add('select * from Product where ProductName=');
              sql.add(''''+ProductName+'''');
              open;
              first;
              ProductCode:=fieldbyname('ProductCode').asstring;
              Spec:=fieldbyname('Spec').asstring;
              PUnit:=fieldbyname('Unit').asstring;
              MinSto:= fieldbyname('Minsto').asstring;
              Maxsto:= fieldbyname('Maxsto').asstring;
              if strtofloat(MaxSto)< StorageQuantity then
              begin
              flag:=1;
              with stringgrid1 do
               begin
                cells[0,i]:=ProductCode;
                cells[1,i]:=ProductName;
                cells[2,i]:=Spec;
                cells[3,i]:=PUnit;
                cells[4,i]:=floattostr(StockQuantity);
                cells[5,i]:=floattostr(SellQuantity);
                cells[6,i]:=MinSto;
                cells[7,i]:=floattostr(StorageQuantity);
                cells[8,i]:=MaxSto;
               end;
              end;
             end;
            next;
           end;
           if flag=0 then
              showmessage('没有超储货品!');
        end;

end;

end.

⌨️ 快捷键说明

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