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

📄 unitmain.cpp

📁 通过oci实现的oracle查询分析器功能和可以 尤其对BLOB字段的度曲
💻 CPP
📖 第 1 页 / 共 3 页
字号:
      while (!Query3->Eof)
      {
         if (dd!=Query3->GetFieldValueByName("table_name"))
         {
         node1=TreeView1->Items->AddChild(node0,Query3->GetFieldValueByName("table_name"));
         node1->ImageIndex=1;
         node1->SelectedIndex=1;
         }
         node2=TreeView1->Items->AddChild(node1,Query3->GetFieldValueByName("index_name"));

         node2->ImageIndex=2;
         node2->SelectedIndex=2;
         jbm->Add("索引:(表:"+node1->Text+") *** "+node2->Text);
         jbjg->Add("INDEX*"+node2->Text);
         dd=Query3->GetFieldValueByName("table_name");
         Application->ProcessMessages();
         Query3->Next();
      }
    };

    delete Query3;
    DBDatabase->DisConnectDataBase(DBHandle);
    TreeView1->Items->EndUpdate();
    delete tablename;
    delete fieldsname;
    delete ztname;
    Application->MessageBox("数据库连接成功!","系统提示",MB_OK);
    DataConnected=true;
  }
  else
  {
     ShowMessage( "ConnectDataBase失败\n");
     DBDatabase->DisConnectDataBase(DBHandle);
  }

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

void __fastcall TFormmain::FormCreate(TObject *Sender)
{
  Formmain->DoubleBuffered=true;
  Formmain->StringGrid2->DoubleBuffered=true;
  DataConnected=false;
  sqljstj=false;
  Dataoutjg=false;
  hs = new TStringList();
  ys = new TStringList();
  jbjg = new TStringList();
  jbm = new TStringList();
  blobc = new TStringList();
  Querytx = new TOCIQuery();
  StatusBar1->Panels->Items[0]->Width=TreeView1->Width;
}
void __fastcall TFormmain::wls(TObject *Sender)
{

  TIniFile *myinifile;
  AnsiString IniFileName=ExtractFilePath(ParamStr(0))+"paraini.ini";
  myinifile = new TIniFile(IniFileName);
  myinifile->ReadSection("函数",hs);
  myinifile->ReadSection("标准用词",ys);
  delete  myinifile;
}
//---------------------------------------------------------------------------

void __fastcall TFormmain::SpeedButton3Click(TObject *Sender)
{
  RichEdit1->Clear();
}
//---------------------------------------------------------------------------



DWORD WINAPI Thread1(LPVOID lpParameter)   // thread data
{
 DATABASEHANDLE     DBHandle;
   Formmain->sqljstj=false;
  if (Formmain->DataConnected==false)
  {
    Application->MessageBox("数据库未连接!","系统提示",MB_OK);
    Abort() ;
  } ;
   if (Formmain->RichEdit1->Text.Trim()=="")
  {
    Application->MessageBox("SQL语句为空!","系统提示",MB_OK);
    Abort() ;
  } ;
  AnsiString sql="";
  if  (Formmain->RichEdit1->SelText.Trim()!="")
    sql=Formmain->RichEdit1->SelText.Trim();
  else
    sql=Formmain->RichEdit1->Text.c_str();
  Formmain->status = Formmain->DBDatabase->ConnectDataBase(DBHandle);
  if( Formmain->status >= 0 )
  {
    TOCIQuery * Query1;
      Query1 = new TOCIQuery();
      Query1->DBHandle   = DBHandle;
    try
    {


      Query1->AddSQL(sql.c_str());
      Query1->ExecSQL();
     }
    catch(const Exception& e)
    {
      delete Query1;
      Formmain->DBDatabase->DisConnectDataBase(DBHandle);
      Application->MessageBox(e.Message.c_str(),"提示",MB_ICONERROR+MB_OK);
      Abort() ;
    }
    if (Query1->FieldCount==0)
    {
      delete Query1;
      Formmain->DBDatabase->DisConnectDataBase(DBHandle);
      Abort() ;
    }


    Formmain->StringGrid2->ColCount=Query1->FieldCount+1;
    Formmain->StringGrid2->Cells[0][0]="序号";


    for (int i=0;i<Query1->FieldCount ;i++)
    {
        Formmain->StringGrid2->Cells[i+1][0]=Query1->GetFieldName(i);

    } ;
    Formmain->StringGrid2->RowCount=2;
    for (int j=0;j<Query1->FieldCount ;j++)
    {
          Formmain->StringGrid2->Cells[j+1][1]="";
    }
    if (!Query1->Eof )
    {
      for (int i=1;i<=Formmain->CSpinEdit1->Value ;i++)
      {
        Formmain->StringGrid2->RowCount=i+1;
        Formmain->StringGrid2->Cells[0][i]=i;

        for (int j=0;j<Query1->FieldCount ;j++)
        {
          Formmain->StringGrid2->Cells[j+1][i]=Query1->GetFieldValueByIndex(j);
        }
       // Formmain->StringGrid2->Cells[0][i]=Query1->GetRowid();
        Query1->Next();
        if (Query1->Eof)
          break;

      }
    }
   delete Query1;
   Formmain->DBDatabase->DisConnectDataBase(DBHandle);
   Formmain->sqljstj=true;
 }
 else
 {
   ShowMessage( "ConnectDataBase失败\n");
   Formmain->DBDatabase->DisConnectDataBase(DBHandle);
 }
 return 0;
}

void __fastcall TFormmain::SpeedButton2Click(TObject *Sender)
{

/*  if( Thread1Id != -1 ) {
        TerminateThread(Thread1Handle,0);
        Thread1Id = -1;

    }
    Thread1Handle= CreateThread(
              NULL,
              0,
              Thread1,
              0,
              0,
              &Thread1Id); */
   // if(!SetThreadPriority(Thread1Handle,THREAD_PRIORITY_HIGHEST))
    //{}

  DATABASEHANDLE DBHandle;
  txjb="";
  Formmain->sqljstj=false;
  if (Formmain->DataConnected==false)
  {
    Application->MessageBox("数据库未连接!","系统提示",MB_OK);
    Abort() ;
  } ;
   if (Formmain->RichEdit1->Text.Trim()=="")
  {
    Application->MessageBox("SQL语句为空!","系统提示",MB_OK);
    Abort() ;
  } ;
  SpeedButton2->Enabled=false;
  AnsiString sql="";
  if  (Formmain->RichEdit1->SelText.Trim()!="")
    sql=Formmain->RichEdit1->SelText.Trim();
  else
    sql=Formmain->RichEdit1->Text.c_str();
  rowiddz=-1;
  blobc->Clear();
  Formmain->status = Formmain->DBDatabase->ConnectDataBase(DBHandle);
  if( Formmain->status >= 0 )
  {
    TOCIQuery * Query1;
    Query1 = new TOCIQuery();
    Query1->DBHandle   = DBHandle;
    try
    {


      Query1->AddSQL(sql.c_str());
      Query1->ExecSQL();
     }
    catch(const Exception& e)
    {
      delete Query1;
      Formmain->DBDatabase->DisConnectDataBase(DBHandle);
      Application->MessageBox(e.Message.c_str(),"提示",MB_ICONERROR+MB_OK);
      SpeedButton2->Enabled=true;
      Abort() ;
    }
    if (Query1->FieldCount==0)
    {
      delete Query1;
      Formmain->DBDatabase->DisConnectDataBase(DBHandle);
      SpeedButton2->Enabled=true;
      Abort() ;
    }


    Formmain->StringGrid2->ColCount=Query1->FieldCount+1;
    Formmain->StringGrid2->Cells[0][0]="序号";


    for (int i=0;i<Query1->FieldCount ;i++)
    {
       Formmain->StringGrid2->Cells[i+1][0]=Query1->Fields(i)->FieldName;
       if (Formmain->StringGrid2->Cells[i+1][0].Trim()=="ROWID")
       {
          rowiddz=i+1;
          txjb=sql;
       }
       if (Query1->Fields(i)->Type==OCI_TYPECODE_BLOB)
       {
         blobc->Add(i);
       }


    } ;
    Formmain->StringGrid2->RowCount=2;
    for (int j=0;j<Query1->FieldCount ;j++)
    {
          Formmain->StringGrid2->Cells[j+1][1]="";
    }

    if (!Query1->Eof )
    {
      for (int i=1;i<=Formmain->CSpinEdit1->Value ;i++)
      {

        Formmain->StringGrid2->RowCount=i+1;
        Formmain->StringGrid2->Cells[0][i]=i;
        Formmain->StatusBar1->Panels->Items[1]->Text="当前返回第:"+IntToStr(i)+" 行";
        for (int j=0;j<Query1->FieldCount ;j++)
        {
          Formmain->StringGrid2->Cells[j+1][i]=Query1->Fields(j)->Value;
        }
       // Formmain->StringGrid2->Cells[0][i]=Query1->GetRowid();
        Query1->Next();

        Application->ProcessMessages();
        if (Query1->Eof)
          break;

      }
    }
  Formmain->StatusBar1->Panels->Items[1]->Text="";
   delete Query1;
   Formmain->DBDatabase->DisConnectDataBase(DBHandle);
   Formmain->sqljstj=true;
 }
 else
 {
   ShowMessage( "ConnectDataBase失败\n");
   Formmain->DBDatabase->DisConnectDataBase(DBHandle);
 }
 SpeedButton2->Enabled=true;
}
//---------------------------------------------------------------------------


void __fastcall TFormmain::RichEdit1DragDrop(TObject *Sender,
      TObject *Source, int X, int Y)
{
      AnsiString cc="";
     TTreeNode *node1  = ((TTreeView *)Source)->Selected;

       if  ((node1->Level==1)&& ((node1->Parent->Text=="表")||(node1->Parent->Text=="视图"))  )
       {
         for (int i=0;i<node1->Count ;i++)
         {
           if  (i!=node1->Count-1)
           cc=cc+node1->Item[i]->Text+"," ;
           else
           cc=cc+node1->Item[i]->Text;
         }
         cc=" Select "+cc+" from " +node1->Text;
       };
       if ( (node1->Level==2) && ((node1->Parent->Parent->Text=="表")||(node1->Parent->Parent->Text=="视图")))
       {
         cc=node1->Text;
       } ;
        if  ((node1->Level==1)&& ((node1->Parent->Text=="系统函数") || (node1->Parent->Text=="自定义函数")  || (node1->Parent->Text=="过程")))
       {
         cc=node1->Text;
       };
     Clipboard()->AsText=cc;
     RichEdit1->PasteFromClipboard();
    


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


void __fastcall TFormmain::RichEdit1DragOver(TObject *Sender,
      TObject *Source, int X, int Y, TDragState State, bool &Accept)
{
  if ((TTreeView *)Source!=NULL)
    Accept=true;
}
//---------------------------------------------------------------------------
















void __fastcall TFormmain::StringGrid2DrawCell(TObject *Sender, int ACol,
      int ARow, TRect &Rect, TGridDrawState State)
{
  StringGrid2->Canvas->FillRect(Rect);
  if (ARow==0 ||ACol==0)
  {
    if (ARow==0 && ACol==0)
      StringGrid2->Canvas->Font->Color=clBlue;
    StringGrid2->Canvas->Font->Style=TFontStyles() << fsBold;
    DrawText(StringGrid2->Canvas->Handle,StringGrid2->Cells[ACol][ARow].c_str(),StringGrid2->Cells[ACol][ARow].Length(),&Rect, DT_CENTER | DT_SINGLELINE | DT_VCENTER);
  }
  else
    DrawText(StringGrid2->Canvas->Handle,StringGrid2->Cells[ACol][ARow].c_str(),StringGrid2->Cells[ACol][ARow].Length(),&Rect, DT_LEFT | DT_SINGLELINE | DT_VCENTER);
  
}
//---------------------------------------------------------------------------


void __fastcall TFormmain::SpeedButton6Click(TObject *Sender)
{
  Close();        
}
//---------------------------------------------------------------------------

void __fastcall TFormmain::SpeedButton7Click(TObject *Sender)
{
PageControl1->ActivePageIndex=4;
}
//---------------------------------------------------------------------------

void __fastcall TFormmain::BitBtn3Click(TObject *Sender)
{
PageControl1->ActivePageIndex=3;        
}
//---------------------------------------------------------------------------




void __fastcall TFormmain::BitBtn8Click(TObject *Sender)
{
tz=true;        
}
//---------------------------------------------------------------------------






void __fastcall TFormmain::SpeedButton9Click(TObject *Sender)
{
  if (OpenDialog1->Execute())
    RichEdit1->Lines->LoadFromFile(OpenDialog1->FileName);
}
//---------------------------------------------------------------------------

void __fastcall TFormmain::SpeedButton8Click(TObject *Sender)
{
 if (SaveDialog3->Execute())
    RichEdit1->Lines->SaveToFile(SaveDialog3->FileName);        
}
//---------------------------------------------------------------------------


⌨️ 快捷键说明

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