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

📄 search.cpp

📁 机器须安装SQL Server2000 程序安装完之后
💻 CPP
字号:
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "Search.h"
#include "Main.h"
#include "DataMoudle.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TSearchForm *SearchForm;
//---------------------------------------------------------------------------
__fastcall TSearchForm::TSearchForm(TComponent* Owner)
    : TForm(Owner)
{
    mark=0;
}
//---------------------------------------------------------------------------
void __fastcall TSearchForm::FormClose(TObject *Sender,
      TCloseAction &Action)
{
   Action=caFree;
   MainForm->search=0; //打开标志为空
}
//---------------------------------------------------------------------------
void __fastcall TSearchForm::FormCreate(TObject *Sender)
{
  //  if (DM->ADOTRoomType->State == dsInactive)
 //       DM->ADOTRoomType->Open();

 //   if (DM->ADOTRoom->State == dsInactive)
 //         DM->ADOTRoom->Open();



}
//---------------------------------------------------------------------------



void __fastcall TSearchForm::RadioButton1Click(TObject *Sender)
{
    truefalse(1);
    Init();
    DBGrid1->DataSource=DSRoom;
    if(RadioButton1->Checked==true)
    {
        ComboBox1->Items->Clear();
        ADOQuery1->Active=false;
        ADOQuery1->SQL->Clear();
        ADOQuery1->SQL->Add("select * from roomtype");
        ADOQuery1->Active=true;
          while(!ADOQuery1->Eof)
        {         //动态的把所证件类别添加在ComboBox组件里。

                ComboBox1->Items->Add(ADOQuery1->FieldByName("TypeName")->AsString);
                ADOQuery1->Next();
        }
    }
}
//---------------------------------------------------------------------------

void __fastcall TSearchForm::RadioButton2Click(TObject *Sender)
{
    truefalse(1);
    Init();
     DBGrid1->DataSource=DSRoom;

    if(RadioButton2->Checked==true)
    {
        ComboBox1->Items->Clear();
        ADOQuery1->Active=false;
        ADOQuery1->SQL->Clear();
        ADOQuery1->SQL->Add("select * from floor");
        ADOQuery1->Active=true;
          while(!ADOQuery1->Eof)
        {

                ComboBox1->Items->Add(ADOQuery1->FieldByName("Floor")->AsString);
                ADOQuery1->Next();
        }
    }
}
//---------------------------------------------------------------------------

void __fastcall TSearchForm::RadioButton3Click(TObject *Sender)
{
    truefalse(1);
     DBGrid1->DataSource=DSRoom;
     if(RadioButton3->Checked==true)
    {
        ComboBox1->Items->Clear();
        ADOQuery2->Active=false;
        ADOQuery2->SQL->Clear();
        ADOQuery2->SQL->Add("select * from room");
        ADOQuery2->Active=true;

    }
     
}
//---------------------------------------------------------------------------

void __fastcall TSearchForm::ComboBox1Change(TObject *Sender)
{
      if(RadioButton1->Checked==true)
     {
        ADOQuery2->Active=false;
        ADOQuery2->SQL->Clear();
        ADOQuery2->SQL->Add("select * from room where roomlevelcode="+QuotedStr(ComboBox1->ItemIndex+1));
        ADOQuery2->Active=true;
     }
     if(RadioButton2->Checked==true)
     {
        ADOQuery2->Active=false;
        ADOQuery2->SQL->Clear();
        ADOQuery2->SQL->Add("select * from room where floor="+QuotedStr(ComboBox1->ItemIndex+1));
        ADOQuery2->Active=true;
     }
}
//---------------------------------------------------------------------------
int __fastcall TSearchForm:: truefalse(int a)
{
    if(a==0)
    {
        Label1->Visible==true;
        Label2->Visible=true;
        DateTimePicker1->Visible=true;
        DateTimePicker2->Visible=true;
    }
     if(a==1)
    {
        Label1->Visible=false;
        Label2->Visible=false;
        DateTimePicker1->Visible=false;
        DateTimePicker2->Visible=false;
    }
}
void __fastcall TSearchForm::RadioButton4Click(TObject *Sender)
{
    truefalse(0) ;
     DBGrid1->DataSource=DSRoom;

        AnsiString SQL;

         SQL="select * from room where roomno not in(select roomno from roomorder where orderno in(select orderno from orders where booked=1 or used=1 and checked=0 )and EndTime>="+QuotedStr(DateTimePicker2->DateTime.DateString())+")" ;

        ADOQuery2->Active=false;
        ADOQuery2->SQL->Clear();
        ADOQuery2->SQL->Add(SQL);
        ADOQuery2->Active=true;
}
//---------------------------------------------------------------------------

void __fastcall TSearchForm::RadioButton5Click(TObject *Sender)
{
    truefalse(0);

     DBGrid1->DataSource=DataSource2;
        AnsiString SQL;

       SQL="select * from roomorder  where orderno not in (select orders.orderno from orders where used=1 or checked=1 and StartTime>="+QuotedStr(DateTimePicker1->DateTime.DateString())+" and EndTime<="+QuotedStr(DateTimePicker2->DateTime.DateString())+")";

        ADOQuery3->Active=false;
        ADOQuery3->SQL->Clear();
        ADOQuery3->SQL->Add(SQL);
        ADOQuery3->Active=true;
}
//---------------------------------------------------------------------------

void __fastcall TSearchForm::DateTimePicker2Change(TObject *Sender)
{
    if(DateTimePicker1->DateTime<=DateTimePicker2->DateTime);
    else
    {
        ShowMessage("输入的时间格式不对,请重新输入");
        return;
    }

     if(RadioButton4->Checked==true)
     {
          AnsiString SQL;

         SQL="select * from room where roomno not in(select roomno from roomorder where orderno in(select orderno from orders where booked=1 or used=1 and checked=0 )and EndTime>="+QuotedStr(DateTimePicker2->DateTime.DateString())+")" ;

        ADOQuery2->Active=false;
        ADOQuery2->SQL->Clear();
        ADOQuery2->SQL->Add(SQL);
        ADOQuery2->Active=true;


     }

     if(RadioButton5->Checked==true)
     {
        DBGrid1->DataSource=DataSource2;
        AnsiString SQL;

       SQL="select * from roomorder  where orderno not in (select orders.orderno from orders where used=1 or checked=1 and StartTime>="+QuotedStr(DateTimePicker1->DateTime.DateString())+" and EndTime<="+QuotedStr(DateTimePicker2->DateTime.DateString())+")";

        ADOQuery3->Active=false;
        ADOQuery3->SQL->Clear();
        ADOQuery3->SQL->Add(SQL);
        ADOQuery3->Active=true;


    }
 }
//---------------------------------------------------------------------------

void __fastcall TSearchForm::DBGrid1DrawColumnCell(TObject *Sender,
      const TRect &Rect, int DataCol, TColumn *Column,
      TGridDrawState State)
{
    if(RadioButton1->Checked==true||RadioButton3->Checked==true)
    {
        if( ADOQuery2->FieldByName("RoomStateCode")->AsInteger==1)
        {
            DBGrid1->Canvas->Font->Color=clRed;
            DBGrid1->DefaultDrawColumnCell(Rect,DataCol,Column,State);

        }

        /////
         if( ADOQuery2->FieldByName("RoomStateCode")->AsInteger==2)
        {
            DBGrid1->Canvas->Font->Color=clGreen;
            DBGrid1->DefaultDrawColumnCell(Rect,DataCol,Column,State);

        }
         if( ADOQuery2->FieldByName("RoomStateCode")->AsInteger==4)
        {
            DBGrid1->Canvas->Font->Color=clBlue;
            DBGrid1->DefaultDrawColumnCell(Rect,DataCol,Column,State);

        }
    }
      //////////////////
     if(RadioButton2->Checked==true)
    {
        if( ADOQuery2->FieldByName("RoomStateCode")->AsInteger==1)
        {
            DBGrid1->Canvas->Font->Color=clRed;
            DBGrid1->DefaultDrawColumnCell(Rect,DataCol,Column,State);

        }

        /////
         if( ADOQuery2->FieldByName("RoomStateCode")->AsInteger==2)
        {
            DBGrid1->Canvas->Font->Color=clGreen;
            DBGrid1->DefaultDrawColumnCell(Rect,DataCol,Column,State);

        }
         if( ADOQuery2->FieldByName("RoomStateCode")->AsInteger==4)
        {
            DBGrid1->Canvas->Font->Color=clBlue;
            DBGrid1->DefaultDrawColumnCell(Rect,DataCol,Column,State);

        }
    }

     if(RadioButton4->Checked==true)
     {

         if( ADOQuery2->FieldByName("RoomStateCode")->AsInteger==1)
        {
            DBGrid1->Canvas->Font->Color=clRed;
            DBGrid1->DefaultDrawColumnCell(Rect,DataCol,Column,State);

        }

        /////
         if( ADOQuery2->FieldByName("RoomStateCode")->AsInteger==2)
        {
            DBGrid1->Canvas->Font->Color=clGreen;
            DBGrid1->DefaultDrawColumnCell(Rect,DataCol,Column,State);

        }
         if( ADOQuery2->FieldByName("RoomStateCode")->AsInteger==4)
        {
            DBGrid1->Canvas->Font->Color=clBlue;
            DBGrid1->DefaultDrawColumnCell(Rect,DataCol,Column,State);

        }
     }

     /*
         if(RadioButton5->Checked==true)

     {
        if( ADOQuery1->FieldByName("RoomStateCode")->AsInteger==1)
        {
            DBGrid1->Canvas->Font->Color=clRed;
            DBGrid1->DefaultDrawColumnCell(Rect,DataCol,Column,State);

        }

        /////
         if( ADOQuery1->FieldByName("RoomStateCode")->AsInteger==2)
        {
            DBGrid1->Canvas->Font->Color=clGreen;
            DBGrid1->DefaultDrawColumnCell(Rect,DataCol,Column,State);

        }
         if( ADOQuery1->FieldByName("RoomStateCode")->AsInteger==4)
        {
            DBGrid1->Canvas->Font->Color=clBlue;
            DBGrid1->DefaultDrawColumnCell(Rect,DataCol,Column,State);

        }


     }
    */
}
//---------------------------------------------------------------------------


void __fastcall TSearchForm::FormShow(TObject *Sender)
{
    DateTimePicker1->DateTime=Now();
    DateTimePicker2->DateTime=Now();
    RadioButton3->Checked=true;
    ADOQuery2->FieldList->FieldByName("RoomStateCode")->ReadOnly=true;
 //    ADOQuery2->FieldList->FieldByName("newcleartype")->ReadOnly=true;
}
//---------------------------------------------------------------------------

void __fastcall TSearchForm::Button3Click(TObject *Sender)
{
    Close();    
}
//---------------------------------------------------------------------------

void __fastcall TSearchForm::Button1Click(TObject *Sender)
{
    //DBGrid1->ReadOnly=false;
    ADOQuery2->FieldList->FieldByName("newcleartype")->ReadOnly=false;
    mark=1;
}
//---------------------------------------------------------------------------

void __fastcall TSearchForm::Init()
{
       ADOQuery2->Active=false;
        ADOQuery2->SQL->Clear();
        ADOQuery2->SQL->Add("select * from room");
        ADOQuery2->Active=true;

}

void __fastcall TSearchForm::DBGrid1CellClick(TColumn *Column)
{
    TheType=ADOQuery2->FieldByName("RoomStateCode")->AsInteger;
    if((ADOQuery2->Active==true)&&(mark==1))
       {

        int type;
        type=ADOQuery2->FieldByName("RoomStateCode")->AsInteger;
        if(type==4)
        {
           // DBGrid1->ReadOnly=true;
           ADOQuery2->FieldList->FieldByName("RoomStateCode")->ReadOnly=true;
        }
        else
        //DBGrid1->ReadOnly=false;
        ADOQuery2->FieldList->FieldByName("RoomStateCode")->ReadOnly=false;
    }
}
//---------------------------------------------------------------------------






void __fastcall TSearchForm::ADOQuery2BeforePost(TDataSet *DataSet)
{
     int type;
        type=ADOQuery2->FieldByName("RoomStateCode")->AsInteger;

    if(type==4)
    {
        ADOQuery2->FieldByName("RoomStateCode")->AsInteger=TheType;
        type=TheType;
    }
}
//---------------------------------------------------------------------------

⌨️ 快捷键说明

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