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

📄 upackagequery.~pas

📁 是分布式粮库程序,是采用Delphi实现的
💻 ~PAS
字号:
unit upackagequery;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, DB, DBTables, Grids, DBGrids, StdCtrls, Buttons, DBCtrls,
  ExtCtrls;

type
  Tfpackagequery = class(TForm)
    Panel1: TPanel;
    GroupBox1: TGroupBox;
    GroupBox2: TGroupBox;
    GroupBox3: TGroupBox;
    Label1: TLabel;
    DBLookupComboBox1: TDBLookupComboBox;
    Label2: TLabel;
    DBLookupComboBox2: TDBLookupComboBox;
    Label3: TLabel;
    DBLookupComboBox3: TDBLookupComboBox;
    Label4: TLabel;
    Label5: TLabel;
    stTotal: TStaticText;
    stNew: TStaticText;
    Label9: TLabel;
    stOld: TStaticText;
    Label10: TLabel;
    Label7: TLabel;
    stMisc: TStaticText;
    Label8: TLabel;
    Label11: TLabel;
    Label6: TLabel;
    Label13: TLabel;
    btnReset: TBitBtn;
    btnQuery: TBitBtn;
    DBGrid1: TDBGrid;
    unitQuery: TQuery;
    siteQuery: TQuery;
    depotQuery: TQuery;
    DataSource1: TDataSource;
    DataSource2: TDataSource;
    DataSource3: TDataSource;
    Query1: TQuery;
    DataSource4: TDataSource;
    Query1BDEDesigner: TStringField;
    Query1BDEDesigner2: TStringField;
    Query1BDEDesigner3: TStringField;
    Query1BDEDesigner4: TStringField;
    Query1BDEDesigner5: TIntegerField;
    Query1BDEDesigner6: TIntegerField;
    Query1BDEDesigner7: TIntegerField;
    Query1sum: TIntegerField;
    btnExit: TBitBtn;
    fdpidQuery: TQuery;
    ComboBox1: TComboBox;
    fdpositionquery: TQuery;
    BitBtn1: TBitBtn;
    Label12: TLabel;
    Label14: TLabel;
    DBLookupComboBox6: TDBLookupComboBox;
    DBLookupComboBox4: TDBLookupComboBox;
    chubeiQuery: TQuery;
    chubeiDataSource: TDataSource;
    guishuQuery: TQuery;
    guishuDataSource: TDataSource;
    Label15: TLabel;
    DBLookupComboBox5: TDBLookupComboBox;
    FoodTypeQuery: TQuery;
    FoodTypeDataSource: TDataSource;
    Query1BDEDesigner8: TStringField;
    Query1BDEDesigner9: TStringField;
    Query1BDEDesigner10: TStringField;
    procedure btnExitClick(Sender: TObject);
    procedure unitQueryAfterScroll(DataSet: TDataSet);
    procedure siteQueryAfterScroll(DataSet: TDataSet);
    procedure depotQueryAfterScroll(DataSet: TDataSet);
    procedure FormCreate(Sender: TObject);
    procedure btnResetClick(Sender: TObject);
    procedure Query1CalcFields(DataSet: TDataSet);
    procedure btnQueryClick(Sender: TObject);
    procedure BitBtn1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  fpackagequery: Tfpackagequery;
  queryitem:string;
  s:string;

implementation
  uses unitdatamodul,global,uexcel;
{$R *.dfm}

procedure Tfpackagequery.btnExitClick(Sender: TObject);
begin
  close;
end;

procedure Tfpackagequery.unitQueryAfterScroll(DataSet: TDataSet);
begin
    SiteQuery.ParamByName('UnitId').AsInteger:=DataSet.FieldByName('UNIT_ID').AsInteger;
    SiteQuery.Close;
    SiteQuery.Open;
    if DataSet.FieldByName('UNIT_ID').AsInteger= 99999997 then
           DBLookupComboBox2.Enabled:=false
    else   DBLookupComboBox2.Enabled:=true;
           DBLookupComboBox2.KeyValue:=99999998;
end;

procedure Tfpackagequery.siteQueryAfterScroll(DataSet: TDataSet);
begin
    depotQuery.ParamByName('SiteId').AsInteger:=DataSet.FieldByName('site_ID').AsInteger;
    depotQuery.ParamByName('unitId').AsInteger:=DataSet.FieldByName('unit_ID').AsInteger;
    depotQuery.Close;
    depotQuery.Open;
    if DataSet.FieldByName('site_ID').AsInteger=99999998 then
           DBLookupComboBox3.Enabled:=false
    else   DBLookupComboBox3.Enabled:=true;
           DBLookupComboBox3.KeyValue:=99999999;
end;

procedure Tfpackagequery.depotQueryAfterScroll(DataSet: TDataSet);
begin
    if DataSet.FieldByName('depot_ID').AsInteger=99999999 then
    begin
//    edit1.Text :='';
//    edit1.Enabled:=false
    combobox1.Text:='';
    combobox1.Enabled :=false;
    end else
//    edit1.Enabled:=true;
    begin
    combobox1.Enabled :=true;
    combobox1.Items.Clear ;
    fdpositionquery.ParamByName('unit_id').AsInteger :=dataset.fieldbyname('unit_id').AsInteger ;
    fdpositionquery.ParamByName('site_id').AsInteger :=dataset.fieldbyname('site_id').AsInteger ;
    fdpositionquery.ParamByName('depot_id').AsInteger :=dataset.fieldbyname('depot_id').AsInteger ;
    fdpositionquery.Close;
    fdpositionquery.Open;
    fdpositionquery.First ;
    while not fdpositionquery.Eof do
    begin
    combobox1.Items.Add(fdpositionquery.fieldbyname('name').AsString);
    fdpositionquery.Next;
    end;
    end;
end;

procedure Tfpackagequery.FormCreate(Sender: TObject);
var i:integer;
    newtotal:integer;
    oldtotal:integer;
    misctotal:integer;
begin
   if global.g_user.UnitID=0 then
   begin
    unitquery.Open;
    dblookupcombobox1.KeyValue:=99999997;
    dblookupcombobox2.Enabled:=false;
    s:=query1.SQL.Text ;
   end else
   begin
    Dblookupcombobox1.KeyValue :=global.g_user.UnitID;
    unitquery.Open;
    dblookupcombobox1.Enabled :=false;
    sitequery.ParamByName('unitid').AsInteger := Dblookupcombobox1.KeyValue;
    sitequery.Open;
    s:=query1.SQL.Text+' and ent_instack.unit_id='+inttostr(DBLookupComboBox1.KeyValue) ;
   end;
    DBLookupComboBox2.KeyValue:=99999998;
    DBLookupComboBox3.KeyValue:=99999999;
    DBLookupComboBox3.Enabled:=false;
    chubeiquery.Active :=true;
    guishuquery.Active :=true;
    foodtypequery.Active :=true;
    dblookupcombobox4.KeyValue :='不指定';
    dblookupcombobox5.KeyValue :='不指定';
    dblookupcombobox6.KeyValue :='不指定';

    Query1.SQL.Clear;
    query1.SQL.Add(s+' order by ent_instack.unit_id,ent_instack.site_id,ent_instack.depot_id,ent_instack.foodposition_id');
     try
       Query1.Open;
     except
       Application.MessageBox('查询库存时出错!','系统错误',MB_OK+MB_ICONERROR);
       Exit;
     end;

     newtotal:=0;
     oldtotal:=0;
     misctotal:=0;
     for i:=1 to query1.RecordCount do
      begin
       newtotal:=newtotal+query1.fieldbyname('新包装').AsInteger;
       oldtotal:=oldtotal+query1.fieldbyname('旧包装').AsInteger;
       misctotal:=misctotal+query1.fieldbyname('杂包装').AsInteger;
       query1.Next ;
      end;

    stnew.Caption :=inttostr(newtotal);
    stold.Caption :=inttostr(oldtotal);
    stmisc.Caption :=inttostr(misctotal);
    sttotal.Caption :=inttostr(newtotal+oldtotal+misctotal);

end;

procedure Tfpackagequery.btnResetClick(Sender: TObject);
var i:integer;
    newtotal:integer;
    oldtotal:integer;
    misctotal:integer;
begin
   if global.g_user.UnitID=0 then
    dblookupcombobox1.KeyValue :=99999997
   else
    dblookupcombobox1.KeyValue :=global.g_user.UnitID;

    DBLookupComboBox2.KeyValue:=99999998;
    DBLookupComboBox3.KeyValue:=99999999;
    dblookupcombobox4.KeyValue :='不指定';
    dblookupcombobox5.KeyValue :='不指定';
    dblookupcombobox6.KeyValue :='不指定';

    Query1.SQL.Clear;
    query1.SQL.Add(s+' order by ent_instack.unit_id,ent_instack.site_id,ent_instack.depot_id,ent_instack.foodposition_id');
     try
       Query1.Open;
     except
       Application.MessageBox('查询库存时出错!','系统错误',MB_OK+MB_ICONERROR);
       Exit;
     end;
     newtotal:=0;
     oldtotal:=0;
     misctotal:=0;
     for i:=1 to query1.RecordCount do
      begin
       newtotal:=newtotal+query1.fieldbyname('新包装').AsInteger;
       oldtotal:=oldtotal+query1.fieldbyname('旧包装').AsInteger;
       misctotal:=misctotal+query1.fieldbyname('杂包装').AsInteger;
       query1.Next ;
      end;

    stnew.Caption :=inttostr(newtotal);
    stold.Caption :=inttostr(oldtotal);
    stmisc.Caption :=inttostr(misctotal);
    sttotal.Caption :=inttostr(newtotal+oldtotal+misctotal);
end;

procedure Tfpackagequery.Query1CalcFields(DataSet: TDataSet);
begin
with DataSet do
    FieldByName('sum').AsInteger := FieldByName('新包装').AsInteger+FieldByName('旧包装').AsInteger+FieldByName('杂包装').AsInteger;
end;

procedure Tfpackagequery.btnQueryClick(Sender: TObject);
var i:integer;
    newtotal:integer;
    oldtotal:integer;
    misctotal:integer;
begin
 queryitem:='';
   if (DBLookupComboBox1.Text<>'') and (DBLookupComboBox1.KeyValue<>99999997) then
    QueryItem:=QueryItem+' and ent_instack.unit_id='+inttostr(DBLookupComboBox1.KeyValue);
   if (DBLookupComboBox2.Text<>'') and (DBLookupComboBox2.KeyValue<>99999998) then
    QueryItem:=QueryItem+' and ent_instack.site_id='+inttostr(DBLookupComboBox2.KeyValue);
   if (DBLookupComboBox3.Text<>'') and (DBLookupComboBox3.KeyValue<>99999999) then
    QueryItem:=QueryItem+' and ent_instack.depot_id='+inttostr(DBLookupComboBox3.KeyValue);
   if combobox1.Text <> '' then
//   QueryItem:=QueryItem+' and ent_fdposition_info.name='''+edit1.Text+'''';
   begin
     fdpidquery.ParamByName('unit_id').AsInteger :=dblookupcombobox1.KeyValue ;
     fdpidquery.ParamByName('site_id').AsInteger :=dblookupcombobox2.KeyValue ;
     fdpidquery.ParamByName('depot_id').AsInteger :=dblookupcombobox3.KeyValue ;
     fdpidquery.ParamByName('foodposition_name').AsString :=combobox1.Text ;
     fdpidquery.Close;
     fdpidquery.Open;
  //   if fdpidquery.RecordCount =1 then
     QueryItem:=QueryItem+'  and ent_instack.foodposition_id='+inttostr(fdpidquery.fieldbyname('foodposition_id').AsInteger ) ;
    end;
    if dblookupcombobox4.KeyValue <>'不指定' then
     queryitem:=queryitem+' and ent_instack.ATTRIBUTE='''+dblookupcombobox4.Text+'''' ;
    if dblookupcombobox6.KeyValue <>'不指定' then
     queryitem:=queryitem+' and ent_instack.attachment='''+dblookupcombobox6.Text+'''' ;
    if dblookupcombobox5.KeyValue <>'不指定' then
     queryitem:=queryitem+' and ent_instack.in_food='''+dblookupcombobox5.Text+'''' ;

   Query1.SQL.Clear;
   if QueryItem<>'' then
   Query1.SQL.Add(s+QueryItem+' order by ent_instack.unit_id,ent_instack.site_id,ent_instack.depot_id,ent_instack.foodposition_id') else
   query1.SQL.Add(s+' order by ent_instack.unit_id,ent_instack.site_id,ent_instack.depot_id,ent_instack.foodposition_id');
   try
   showmessage(query1.sql.text);
    Query1.Open;
   except
    Application.MessageBox('查询库存时出错!','系统错误',MB_OK+MB_ICONERROR);
    Exit;
   end;
     newtotal:=0;
     oldtotal:=0;
     misctotal:=0;
     for i:=1 to query1.RecordCount do
      begin
       newtotal:=newtotal+query1.fieldbyname('新包装').AsInteger;
       oldtotal:=oldtotal+query1.fieldbyname('旧包装').AsInteger;
       misctotal:=misctotal+query1.fieldbyname('杂包装').AsInteger;
       query1.Next ;
      end;

    stnew.Caption :=inttostr(newtotal);
    stold.Caption :=inttostr(oldtotal);
    stmisc.Caption :=inttostr(misctotal);
    sttotal.Caption :=inttostr(newtotal+oldtotal+misctotal);

end;

procedure Tfpackagequery.BitBtn1Click(Sender: TObject);
begin
  createreportpackage;
end;

end.

⌨️ 快捷键说明

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