1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
|
//---------------------------------------------------------------------------
#include <windows.h>
#include <vcl.h>
#pragma hdrstop
#define __WIN__
#include "include/mysql.h"
#include <registry.hpp>
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::test_serveurClick(TObject *Sender)
{
ListBox->Clear();
ListBox1->Clear();
ListBox2->Clear();
ListBox3->Clear();
MYSQL *mySQL;
mySQL = mysql_init(NULL);
if (!mysql_real_connect(mySQL, "127.0.0.1", "cedced", "12345678" ,"articles", 3306, NULL, 0))
{
Panel1->Color=clRed;
Panel1->Caption="Echec";
// la connection a échoué
}
else
{
Panel1->Caption="Ok";
// la connection a réussi
// liste données d une table
MYSQL_RES *myRES2;
MYSQL_ROW myROW2;
AnsiString aStr2;
TListItem *ListItem;
TListColumn *pColumn;
if (!mysql_query(mySQL, "select * from articles order by ref"))
{ myRES2 = mysql_store_result(mySQL);
if (myRES2)
{
for(unsigned int i = 0; i < 10; i++)
{
myROW2 = mysql_fetch_row(myRES2);
for(unsigned int j = 0; j < mysql_num_fields(myRES2); j++)
{
/////////////////// debut boucle ajout dans listbox souhaitée
if ( j==0 ) { aStr.sprintf("%s", myROW2[j]); ListBox1->Items->Add(aStr); }
if ( j==1 ) { aStr.sprintf("%s", myROW2[j]); ListBox2->Items->Add(aStr); }
if ( j==2 ) { aStr.sprintf("%s", myROW2[j]); ListBox3->Items->Add(aStr); }
/////////////////// fin boucle ajout dans listbox souhaitée
}
}
}
mysql_free_result(myRES2);
}
//////////////////
mysql_close(mySQL);
}
}
/////////////////////////////////////////////
///////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////
void __fastcall TForm1::ListBox1DrawItem(TWinControl *Control, int Index,
TRect &Rect, TOwnerDrawState State)
{
// on récupère le TListBox qui a lancé l'évènement, et son TCanvas
TListBox * pListBox = ((TListBox *)Control);
TCanvas * pCanvas = pListBox->Canvas;
// on met les lignes paires en fond jaune
if ((Index % 2)==0)
{
pCanvas->Brush->Color = clYellow;
}
// on met les lignes sélectionnées en jaune sur fond rouge
if(State.Contains(odSelected))
{
ListBox1->Canvas->Brush->Color = clRed;
ListBox1->Canvas->Font->Color = clYellow;
}
// on dessine le fond de la cellule
pCanvas->FillRect(Rect);
// on dessine le texte de la cellule
AnsiString Data = pListBox->Items->Strings[Index];
Rect.left += 2;
pCanvas->TextOut(Rect.Left,Rect.Top,Data);
}
//--------------------------------------------------------------------------- |
Partager