StoreQuery.cpp
上传用户:tangpei45
上传日期:2013-07-14
资源大小:9104k
文件大小:2k
源码类别:

百货/超市行业

开发平台:

C++ Builder

  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include "StoreQuery.h"
  5. //---------------------------------------------------------------------------
  6. #pragma package(smart_init)
  7. #pragma resource "*.dfm"
  8. TfmStoreQuery *fmStoreQuery;
  9. //---------------------------------------------------------------------------
  10. __fastcall TfmStoreQuery::TfmStoreQuery(TComponent* Owner)
  11.     : TForm(Owner)
  12. {
  13. }
  14. //---------------------------------------------------------------------------
  15. void __fastcall TfmStoreQuery::FormCreate(TObject *Sender)
  16. {
  17.     // 初始化仓库下拉选项
  18.     TQuery* pQuery = new TQuery(NULL);
  19.     pQuery->DatabaseName = "db";
  20.     pQuery->SQL->Clear();
  21.     pQuery->SQL->Add("select 仓库名 from 仓库清单");
  22.     pQuery->Open();
  23.     while(!pQuery->Eof)
  24.     {
  25.         cboStore->Items->Add(pQuery->FieldByName("仓库名")->AsString);
  26.         pQuery->Next();
  27.     }
  28.     pQuery->Close();
  29.     delete pQuery;
  30.     cboStore->Text = "";
  31.     edGoodCode->Text = "";
  32.     edGoodPY->Text = "";
  33. }
  34. //---------------------------------------------------------------------------
  35. void __fastcall TfmStoreQuery::btQueryClick(TObject *Sender)
  36. {
  37.     Query1->Filtered = false;
  38.     // 设置Query控件的filter属性可以起到查询条件的作用
  39.     AnsiString szCon;
  40.     if(edGoodCode->Text.Length()>0) szCon = "货号='" + edGoodCode->Text + "'";
  41.     if(edGoodPY->Text.Length()>0)
  42.     {
  43.         if(szCon.Length()>0 ) szCon += " and 拼音编码 = '" + edGoodPY->Text + "*'";
  44.         else szCon = "拼音编码 = '" + edGoodPY->Text + "*'";
  45.     }
  46.     if(cboStore->Text.Length()>0)
  47.     {
  48.         if(szCon.Length()>0 ) szCon += " and 仓库 = '" + cboStore->Text + "'";
  49.         else szCon = "仓库 = '" + cboStore->Text + "'";
  50.     }
  51.     Query1->Filter = szCon;
  52.     Query1->Filtered = true;
  53. }
  54. //---------------------------------------------------------------------------
  55. void __fastcall TfmStoreQuery::FormClose(TObject *Sender,
  56.       TCloseAction &Action)
  57. {
  58.   // 删除窗体并回收空间
  59.     Action = caFree;    
  60. }
  61. //---------------------------------------------------------------------------