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 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190
|
//---------------------------------------------------------------------------
#include <windows.h>
#include <vcl.h>
#pragma hdrstop
#include <stdio.h>
#include <stdlib.h>
#define __WIN__
#include "include/mysql.h"
#include <registry.hpp>
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
int valbouton = 0 ;
int nbsql = 20*valbouton ;
int nblimit = 20 ;
int remplircombo ;
int lb1select = -1;
AnsiString leorderby = "ref";
AnsiString Mon_ip ="127.0.0.1" ;
AnsiString Mon_user ="nieb" ;
AnsiString Mon_pass ="123456";
AnsiString Ma_table ="articles";
TForm1 *Form1;
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
///////////////// Debut de definition de mes fonctions ///////////
////////////////////////////////////////////////////////////////////////////////
void TForm1::verifbouton ()
{
if ( valbouton == ComboBox1->Items->Count )
{ Pagesuivante->Enabled=False ; Pageprecedente->Enabled=False ; }
else {
if ( valbouton < ComboBox1->Items->Count && valbouton >0 )
{ Pagesuivante->Enabled=True ; Pageprecedente->Enabled=True ; }
else {
if ( valbouton == 0 )
{ Pagesuivante->Enabled=True ; Pageprecedente->Enabled=False ; }
else {}
}}}
/////////////////
void TForm1::larequete()
{
// Remplir le combobox pour le bouton naviguer
ComboBox1->ItemIndex= valbouton ; nbsql = 20*valbouton ;
MYSQL *mySQL; mySQL = mysql_init(NULL);
if (!mysql_real_connect(mySQL, Mon_ip.c_str() , Mon_user.c_str(), Mon_pass.c_str() ,Ma_table.c_str(), 3306, NULL, 0))
{ Panel1->Color=clRed; Panel1->Caption="Echec"; } // la connection a échoué
else { Panel1->Caption="Ok"; // la connection a réussi
MYSQL_RES *myREStotal; MYSQL_ROW myROWtotal;
if (!mysql_query(mySQL, "select ref from articles" ) )
{ myREStotal = mysql_store_result(mySQL);
ComboBox1->Clear();
unsigned int remplircombo = myREStotal->row_count / nblimit ;
if ( myREStotal->row_count % nblimit > 0 ) { remplircombo = remplircombo + 1 ; }
for( unsigned int k = 0 ; k < remplircombo ; k++ )
{ComboBox1->Items->Add(k+1); }
ListBox1->Clear(); ListBox2->Clear(); ListBox3->Clear();
MYSQL_RES *myRES; MYSQL_ROW myROW; AnsiString aStr;
AnsiString marequete = "select * from articles order by "+leorderby+" limit "+IntToStr(nbsql)+","+IntToStr(nblimit) ;
if (!mysql_query(mySQL, marequete.c_str() ) )
{ myRES = mysql_store_result(mySQL);
if (myRES)
{
for(unsigned int i = 0 ; i < myRES->row_count ; i++)
{ myROW = mysql_fetch_row(myRES);
for(unsigned int j = 0; j < mysql_num_fields(myRES); j++)
{
if ( j==0 ) { aStr.sprintf("%s", myROW[j]); ListBox1->Items->Add(aStr); }
if ( j==1 ) { aStr.sprintf("%s", myROW[j]); ListBox2->Items->Add(aStr); }
if ( j==2 ) { aStr.sprintf("%s", myROW[j]); ListBox3->Items->Add(aStr); }
}
}
if ( nbsql > myREStotal->row_count - 20 )
{ Pagesuivante->Enabled=False ;}
mysql_free_result(myRES); mysql_close(mySQL);
}}}}
ComboBox1->ItemIndex=valbouton;
}
///////////////// fonction selection 3 items selectionnés ///////////
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;
if(State.Contains(odSelected))
{ int lb1select ; lb1select = ListBox1-> ItemIndex ;
ListBox2->ItemIndex=lb1select; ListBox3->ItemIndex=lb1select; }
// 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);
}
////////////////////////////////////////////////////////////////////////////////
///////////////// Fin de definition de mes fonctions ///////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
///////////////// Debut des interactions avec les objets ///////////
////////////////////////////////////////////////////////////////////////////////
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{ }
///////////////// Bouton connection articles ///////////
void __fastcall TForm1::test_serveurClick(TObject *Sender)
{ test_serveur->Enabled=False ; larequete(); Pageprecedente->Enabled=False;
Pagesuivante->Enabled=True; Annuler->Enabled=True;
Page->Enabled=True; Appeler->Enabled=True; }
///////////////// Bouton Page suivante ///////////
void __fastcall TForm1::PagesuivanteClick(TObject *Sender)
{ valbouton = valbouton + 1 ; verifbouton(); larequete(); }
///////////////// Bouton Page precedente ///////////
void __fastcall TForm1::PageprecedenteClick(TObject *Sender)
{ valbouton = valbouton + -1 ; verifbouton(); larequete(); }
//---------------------------------------------------------------------------
void __fastcall TForm1::PageClick(TObject *Sender)
{ valbouton = ComboBox1->ItemIndex ; verifbouton(); larequete(); }
//---------------------------------------------------------------------------
void __fastcall TForm1::AppelerClick(TObject *Sender)
{
lb1select=ListBox1->ItemIndex; ListBox2->ItemIndex=lb1select;
ListBox3->ItemIndex=lb1select; AnsiString tableauinsert[3] ;
tableauinsert[0]=ListBox1->Items->Strings[lb1select] ;
tableauinsert[1]=ListBox2->Items->Strings[lb1select] ;
tableauinsert[2]=ListBox3->Items->Strings[lb1select];
if ( lb1select == -1 )
{
Application->MessageBox("Le travail d'impression n'a pas terminé l'impression.", "Alerte !", MB_OK);
//Application->MessageBox("Selectionner une rangée , svp .", "Continuer ", MB_OK);
}
else
{
if ( Appeler->Caption=="Appeler" )
{ Edit1->Text=tableauinsert[0]; Edit2->Text=tableauinsert[1];
Edit3->Text=tableauinsert[2]; ListBox1->Enabled=False ; Appeler->Caption="Modifier" ;
Pagesuivante->Enabled=False; Pageprecedente->Enabled=False; Page->Enabled=False; }
else
{ MYSQL *mySQL; mySQL = mysql_init(NULL);
if
(!mysql_real_connect(mySQL, Mon_ip.c_str() , Mon_user.c_str(), Mon_pass.c_str() ,Ma_table.c_str(), 3306, NULL, 0))
{ Panel1->Color=clRed; Panel1->Caption="Echec"; }
else
{ Panel1->Caption="Ok"; }
MYSQL_RES *myRESenlever; MYSQL_ROW myROWenlever; AnsiString aStrenlever;
MYSQL_RES *myRESmodifier; MYSQL_ROW myROWmodifier; AnsiString aStrmodifier;
// on supprime l enregistrement à modifier grace à l array utilisé AnsiString tableauinsert[3] ;
AnsiString marequeteenlever = "delete from articles where ref="+tableauinsert[0] ;
if (!mysql_query(mySQL, marequeteenlever.c_str() ) )
{myRESenlever = mysql_store_result(mySQL);}
// on insert les valeurs des edit dans la table
AnsiString marequetemodifier = "insert into articles values('"+Edit1->Text+"','"+Edit2->Text+"','"+Edit3->Text+"')" ;
if (!mysql_query(mySQL, marequetemodifier.c_str() ) )
{myRESmodifier = mysql_store_result(mySQL);}
Edit1->Clear(); Edit2->Clear(); Edit3->Clear();
tableauinsert[0]=0; tableauinsert[1]=0; tableauinsert[2]=0;
ListBox1->Enabled=True ; Appeler->Caption="Appeler" ;
larequete(); // on actualise les listbox
Pagesuivante->Enabled=True; Pageprecedente->Enabled=True; Page->Enabled=True;
}}}
//---------------------------------------------------------------------------
void __fastcall TForm1::AnnulerClick(TObject *Sender)
{Edit1->Clear(); Edit2->Clear(); Edit3->Clear();
ListBox1->Enabled=True ; Appeler->Caption="Appeler" ;
Pagesuivante->Enabled=True; Pageprecedente->Enabled=True; Page->Enabled=True;}
//--------------------------------------------------------------------------- |