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 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631
| unit Admin;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Db, DBTables, Grids, StdCtrls, jpeg, ExtCtrls;
type
TForm2 = class(TForm)
Label1: TLabel;
Button1: TButton;
GroupBox1: TGroupBox;
GroupBox2: TGroupBox;
GroupBox3: TGroupBox;
ComboBox1: TComboBox;
ComboBox2: TComboBox;
Edit1: TEdit;
Button2: TButton;
Button3: TButton;
Button4: TButton;
Button5: TButton;
StringGrid1: TStringGrid;
StringGrid2: TStringGrid;
Query1: TQuery;
Query2: TQuery;
Query3: TQuery;
Query4: TQuery;
Query5: TQuery;
Query6: TQuery;
Query7: TQuery;
Query8: TQuery;
Query9: TQuery;
Query10: TQuery;
Query11: TQuery;
Query12: TQuery;
Query13: TQuery;
Image1: TImage;
Query14: TQuery;
Query15: TQuery;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Button5Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
procedure StringGrid1SelectCell(Sender: TObject; ACol, ARow: Integer;
var CanSelect: Boolean);
procedure Button3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form2: TForm2;
integ:array [1..10]of integer;
m:integer;
implementation
{$R *.DFM}
procedure TForm2.Button1Click(Sender: TObject);
begin
close;
form2.free;
end;
procedure TForm2.FormCreate(Sender: TObject);
begin
Application.CreateForm(TForm2,Form2);
Form2.Showmodal;
//Affichage StringGrid2 Titre Colonne
stringgrid2.cells[0,0]:='SDate';
stringgrid2.cells[1,0]:='CompteDeSCCode';
stringgrid2.cells[2,0]:='SommeDeSPrice';
stringgrid2.cells[3,0]:='Total Nombre';
stringgrid2.cells[4,0]:='Total Montant';
stringgrid2.cells[5,0]:='Stock de Livre';
//Cache le StringGrid2
StringGrid2.Visible:=false;
//Initialise les Tableaux d'entier
integ[1]:=1;
//Je Cache la Form2
Form2.hide;
//Insère l'image
//image.picture:="C:\gaetan\Exercice Delphi\IEPNET\image.jpg";
//Code pour l'affichage des Clés pub dans la ComboBox1
Query1.Close;
Query1.SQL.Clear;
Query1.SQL.Add('select MCode from Markets');
Query1.Open;
Query1.First;
while not Query1.Eof do
begin
combobox1.Items.Add(Query1.Fields[0].asstring);
Query1.Next;
end;
Query1.Close;
//Code pour l'affichage des Campagnes dans la ComboBox2
Query8.Close;
Query8.SQL.Clear;
Query8.SQL.Add('Select Titre from Campagne');
Query8.SQL.Add('GROUP BY Titre');
Query8.Open;
Query8.First;
while not Query8.Eof do
begin
combobox2.Items.Add(Query8.Fields[0].asstring);
Query8.Next;
end;
Query8.Close;
//Remplissage de la StringGrid
stringgrid1.cells[0,0]:='Clé Pub';
stringgrid1.cells[1,0]:='Description';
stringgrid1.cells[2,0]:='Type';
stringgrid1.cells[3,0]:='PCode';
stringgrid1.cells[4,0]:='Produit Vendu';
stringgrid1.cells[5,0]:='Interêt';
stringgrid1.cells[6,0]:='NbrExp';
stringgrid1.cells[7,0]:='Coût';
stringgrid1.cells[8,0]:='Retour';
stringgrid1.cells[9,0]:='Pourc.';
end;
procedure TForm2.Button5Click(Sender: TObject);
var
j,x,y:integer;
condition:boolean;
begin
ComboBox2.clear;
ComboBox2.text:='Sélectionnez';
condition:=false;
//Cherche le Titre
Query13.Close;
Query13.sql.clear;
Query13.sql.Add('Select CCode,Titre from Campagne');
Query13.Open;
if Query13.locate('Titre',Edit1.text,[loCaseInsensitive]) then
condition:=True;
Query13.Close;
//Recherche de CCode
Query6.Close;
Query6.sql.clear;
Query6.sql.Add('Select CICode from CampagneItems');
Query6.Open;
////Déterminer X le chiffre suivant dans la table pour CCode
if Query6.RecordCount=0 then
x:=1
else
begin
Query6.last;
x:=Query6.Fields[0].AsInteger+1;
end;
//Remplir la table Campagne
if (edit1.text='') or (condition=true) then
showmessage('Soit le Champ est Vide soit Le Titre existe déjà')
else
if Stringgrid1.cells[0,1]='' then
showmessage('Vous n''avez pas rajouté de donnée dans le tableau')
else
begin
Query6.Last;
y:=Query6.RecordCount+1;
Query14.Close;
Query14.sql.clear;
Query14.sql.Add('INSERT INTO Campagne');
Query14.sql.Add('values (:a,:b,:c)');
Query14.Params[0].AsInteger:=y;
Query14.Params[1].AsString:=edit1.text;
Query14.Params[2].AsDATE:=DATE();
Query14.ExecSQL;
for j:=1 to StringGRid1.RowCount-1 do
begin
Query5.Close;
Query5.sql.clear;
Query5.sql.Add('INSERT INTO CampagneItems');
Query5.sql.Add('values (:a,:b,:c)');
Query5.Params[0].AsInteger:=x;
Query5.Params[1].AsInteger:=y;
Query5.Params[2].AsString:=stringgrid1.cells[0,j];
Query5.ExecSQL;
x:=x+1;
end;
Query5.close;
//Code pour l'affichage des Campagnes dans la ComboBox2
Query8.Close;
Query8.SQL.Clear;
Query8.SQL.Add('Select Titre From Campagne');
Query8.SQL.Add('GROUP BY Titre');
Query8.Open;
Query8.First;
while not Query8.Eof do
begin
combobox2.Items.Add(Query8.Fields[0].asstring);
Query8.Next;
end;
Query8.Close;
showmessage('Votre Campagne a bien été enregistré');
end;
end;
procedure TForm2.Button2Click(Sender: TObject);
var
o:double;
i,j,k,l,m,n:integer;
condition,condition2:boolean;
s:string;
begin
condition:=false;
condition2:=false;
//Initialise un entier
m:=0;
if ComboBox1.text ='Sélectionnez' then//Condition Si on a pas sélectionné dans la ComboxBox1
begin
Showmessage('Veuillez Sélectionnez une Clé de Publication');//Afficher Avertissement
exit;
end;
//Vérifier si la clé n'est pas déjà présente dans le tableau
for n:=1 to StringGrid1.RowCount-1 do
if (stringgrid1.cells[0,n]=AnsiUpperCase(combobox1.text)) then
begin
showmessage('Vous avez Déjà inséré Cette Clé Pub');
exit;
end
else
Condition:=true;
//Recherche MCode
Query7.Close;
Query7.SQL.Clear;
Query7.SQL.Add('select MCode from Markets');
Query7.Open;
//Déterminer si le texte du ComboBox et de la requête sont égaux
while not Query7.Eof do
begin
if (AnsiUpperCase(combobox1.Text))=Query7.Fields[0].asstring then
condition2:=true;
Query7.Next;
end;
if condition=true then
begin
if condition2=true then
begin
//Recherche de la Clé Pub, de la Description, du Nombre Expédié
Query2.Close;
Query2.sql.clear;
Query2.sql.Add('SELECT ma.MCode,ma.MTirage,ma.MCost,m.MDname,ma.MDescr,p.Pname,i.Codeinteret,p.PCode');
Query2.sql.Add('FROM markets ma,media m, interet i,marketitems mi,products p');
Query2.SQL.Add('WHERE (p.pcode=mi.ipcode)');
Query2.SQL.Add('and (p.pinteret=i.codeinteret)');
Query2.SQL.Add('and (ma.mcode=mi.imcode)');
Query2.SQL.Add('and (m.mdcode=ma.mmedia)');
Query2.SQL.Add('and (ma.mcode=:x)');
Query2.Params[0].AsString:=AnsiUpperCase(combobox1.text);
Query2.Open;
//Recherche de Nombre de Retour
Query3.Close;
Query3.sql.clear;
Query3.sql.Add('SELECT COUNT(sccode) AS NombreDeRetour');
Query3.SQL.Add('FROM sales');
Query3.SQL.Add('WHERE (smcode=:x)');
Query3.Params[0].AsString:=AnsiUpperCase(combobox1.text);
Query3.Open;
while not Query3.Eof do
begin
m:=m+strtoint(Query3.Fields[0].AsString);
Query3.Next;
end;
//Affichage dans le StringGrid des Données
stringgrid1.cells[0,integ[1]]:=Query2.Fields[0].AsString;//Afficher La Clé Pub
stringgrid1.cells[1,integ[1]]:=Query2.Fields[4].AsString;//Afficher Description
stringgrid1.cells[2,integ[1]]:=Query2.Fields[3].AsString;//Afficher Type
stringgrid1.cells[3,integ[1]]:=Query2.Fields[7].AsString;//Afficher CodeProduit
stringgrid1.cells[4,integ[1]]:=Query2.Fields[5].AsString;//Afficher Produit Vendu
stringgrid1.cells[5,integ[1]]:=Query2.Fields[6].AsString;//Afficher Interêt
stringgrid1.cells[6,integ[1]]:=Query2.Fields[1].AsString;//Afficher Nombre Expédié
stringgrid1.cells[7,integ[1]]:=Query2.Fields[2].AsString;//Afficher Le Coût
stringgrid1.cells[8,integ[1]]:=inttostr(m);//Afficher Retour
if (Query2.Fields[1].AsInteger=0) then
begin
showmessage('Veuillez remplir Sales le nombre d''expédié est égal à ZERO')
end
else
begin
o:=(strtofloat(stringgrid1.cells[8,integ[1]])/(Query2.Fields[1].AsFloat))*100;
str(o:0:2,s);
stringgrid1.cells[9,integ[1]]:=s+' %';
end;
//Adapter le Nom de ligne au nombre de Clé Pub
StringGrid1.Rowcount :=integ[1]+1;
//Rajout d'entier
integ[1]:=integ[1]+1;
//Adapte les textes aux celulles
for j:=0 to 9 do
begin
k:=0;
for i:=0 to StringGrid1.Rowcount-1 do
begin
l:=Canvas.TextWidth(StringGrid1.Cells[j,i]);//reprends la taille en pixel de la cellulle
if l>k then
begin
k:=l;
StringGrid1.ColWidths[j]:=k+4;//je met +4 pour pas que les celulles soient trop collées au texte mais sinon ca marche!
end;
end;
end;
end
else
showmessage('la CléPub saisi n''existe pas!Veuillez ressaisir ou choisir dans le menu déroulant');
end;
end;
procedure TForm2.Button4Click(Sender: TObject);
var
o:double;
i,j,k,l,m,z:integer;
condition:boolean;
s:string;
begin
StringGrid1.CleanupInstance;
z:=0;
condition:=false;
if ComboBox2.text ='Sélectionnez' then//Condition Si on a pas sélectionné dans la ComboxBox1
begin
Showmessage('Veuillez Sélectionnez une Campagne');//Afficher Avertissement
exit;
end;
//Recherche Campagne
Query9.Close;
Query9.SQL.Clear;
Query9.SQL.Add('select Titre from campagne');
Query9.Open;
//Déterminer si le texte du ComboBox et de la requête sont égaux
Query9.First;
while not Query9.Eof do
begin
if combobox2.Text=Query9.Fields[0].asstring then
condition:=true;
Query9.Next;
end;
//Chercher la CléPub
Query12.Close;
Query12.sql.clear;
Query12.sql.Add('SELECT CI.CIMCode');
Query12.SQL.Add('From Campagne C,CampagneItems CI');
Query12.SQL.Add('WHERE C.CCode=CI.CCode');
Query12.SQL.Add('AND (C.Titre=:x)');
Query12.Params[0].AsString:=combobox2.text;
Query12.Open;
if condition<>true then
begin
showmessage('la CléPub saisi n''existe pas!Veuillez ressaisir ou choisir dans le menu déroulant');
exit;
end
else
begin
Query12.First;
While not Query12.Eof do
begin
m:=0;
z:=z+1;
//Recherche de la Clé Pub, de la Description, du Nombre Expédié
Query10.Close;
Query10.sql.clear;
Query10.sql.Add('SELECT ma.MCode,ma.MTirage,ma.MCost,m.MDname,ma.MDescr,p.Pname,i.Codeinteret,p.PCode');
Query10.sql.Add('FROM markets ma,media m, interet i,marketitems mi,products p');
Query10.SQL.Add('WHERE (p.pcode=mi.ipcode)');
Query10.SQL.Add('and (p.pinteret=i.codeinteret)');
Query10.SQL.Add('and (ma.mcode=mi.imcode)');
Query10.SQL.Add('and (m.mdcode=ma.mmedia)');
Query10.SQL.Add('and (ma.mcode=:x)');
Query10.Params[0].AsString:=Query12.Fields[0].AsString;
Query10.Open;
//Recherche de Nombre de Retour
Query11.Close;
Query11.sql.clear;
Query11.sql.Add('SELECT COUNT(sccode) AS NombreDeRetour');
Query11.SQL.Add('FROM sales');
Query11.SQL.Add('WHERE (smcode=:y)');
Query11.Params[0].AsString:=Query12.Fields[0].AsString;
Query11.Open;
while not Query11.Eof do
begin
m:=m+strtoint(Query11.Fields[0].AsString);
Query11.Next;
end;
//Affichage dans le StringGrid des Données
stringgrid1.cells[0,z]:=Query10.Fields[0].AsString;//Afficher La Clé Pub
stringgrid1.cells[1,z]:=Query10.Fields[4].AsString;//Afficher Description
stringgrid1.cells[2,z]:=Query10.Fields[3].AsString;//Afficher Type
stringgrid1.cells[3,z]:=Query10.Fields[7].AsString;//Afficher CodeProduit
stringgrid1.cells[4,z]:=Query10.Fields[5].AsString;//Afficher Produit Vendu
stringgrid1.cells[5,z]:=Query10.Fields[6].AsString;//Afficher Interêt
stringgrid1.cells[6,z]:=Query10.Fields[1].AsString;//Afficher Nombre Expédié
stringgrid1.cells[7,z]:=Query10.Fields[2].AsString;//Afficher Le Coût
stringgrid1.cells[8,z]:=inttostr(m);//Afficher Retour
if (Query10.Fields[1].AsInteger=0) then
showmessage('Veuillez remplir Sales le nombre d''expédié est égal à ZERO')
else
begin
o:=(strtofloat(stringgrid1.cells[8,z])/(Query10.Fields[1].AsFloat))*100;
str(o:0:2,s);
stringgrid1.cells[9,z]:=s+' %';
end;
//Adapter le Nom de ligne au nombre de Clé Pub
StringGrid1.Rowcount :=z+1;
//Adapte les textes aux celulles
for j:=0 to 9 do
begin
k:=0;
for i:=0 to StringGrid1.Rowcount-1 do
begin
l:=Canvas.TextWidth(StringGrid1.Cells[j,i]);//reprends la taille en pixel de la cellulle
if l>k then
begin
k:=l;
StringGrid1.ColWidths[j]:=k+4;//je met +4 pour pas que les celulles soient trop collées au texte mais sinon ca marche!
end;//if
end;//for
end;//for
Query12.Next;
end;//while
end;//if
end;//fin de la procedure
procedure TForm2.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
begin
With Sender As TStringGrid Do With Canvas Do
Begin
{ Sélection de la couleur de fond }
If gdFixed in State Then
Brush.Color := clBtnFace
Else If gdSelected In State Then
Brush.Color := clNavy
Else Brush.Color := clWhite;
{ Dessin du fond }
FillRect(Rect);
{ Sélection de la couleur de texte }
If gdSelected In State Then
SetTextColor(Canvas.Handle,clWhite)
Else SetTextColor(Canvas.Handle,clBlack);
{ Dessin du texte en utilisant la fonction API }
DrawText(Canvas.Handle, pChar(Cells[ACol,ARow]), -1, Rect ,
DT_CENTER or DT_NOPREFIX or DT_WORDBREAK or DT_SINGLELINE );
End;
end;
procedure TForm2.StringGrid1SelectCell(Sender: TObject; ACol,
ARow: Integer; var CanSelect: Boolean);
var
b:double;
a,c,d,i,j,k,l:integer;
begin
a:=0;
b:=0;
d:=1;
integ[6]:=ARow;
if ACol=0 then
if StringGrid1.Cells[ACol,ARow]='' then
begin
showmessage('La clé pub n''existe pas ou la création du tableau n''as pas encore commencé');
end
else
begin
//Faire Apparaitre le Tableau
StringGrid2.Visible:=true;
//Recherche Date, CompteDeSCCode, SommeDeSPRICE
Query4.Close;
Query4.sql.clear;
Query4.sql.Add('SELECT sdate,');
Query4.sql.Add('COUNT(sccode) AS CompteDeSCCode,');
Query4.sql.Add('Sum(SPRICE) as SommeDeSPRICE FROM Sales');
Query4.SQL.Add('WHERE (smcode=:x)');
Query4.SQL.add('GROUP BY sdate, smcode');
Query4.Params[0].AsString:=AnsiUpperCase(stringgrid1.cells[ACol,ARow]);
Query4.Open;
//Adapter le Nom de ligne au nombre de Clé Pub
Query4.Last;
StringGrid2.Rowcount:=Query4.RecordCount+1;
Query4.First;
Query15.Close;
Query15.sql.clear;
Query15.sql.Add('SELECT P.PStock');
Query15.sql.Add('FROM Products P');
Query15.SQL.Add('JOIN MarketItems MI ON MI.P.PCode=IPCode');
Query15.SQL.Add('JOIN Markets M ON MI.IMCode=M.MCode');
Query15.SQL.Add('WHERE (M.MCode=:x)');
Query15.Params[0].AsString:=AnsiUpperCase(stringgrid1.cells[ACol,ARow]);
Query15.Open;
if (Query15.fields[0].AsString='') or (Query15.fields[0].AsInteger=0) then
begin
c:=random(5000);
ShowMessage('Veuillez remplir dans la Table Products la valeur PStock#13#10et une variable a été attribué au Stock : '+inttostr(c));
end
else
c:=Query15.fields[0].AsInteger;
//Afficher StringGrid2
while not Query4.Eof do
begin
stringgrid2.cells[0,d]:=Query4.Fields[0].AsString;
stringgrid2.cells[1,d]:=Query4.Fields[1].AsString;
stringgrid2.cells[2,d]:=Query4.Fields[2].AsString;
a:=a+strtoint(Query4.Fields[1].AsString);
stringgrid2.cells[3,d]:=inttostr(a);
b:=b+Query4.Fields[2].AsFloat;
stringgrid2.cells[4,d]:=floattostr(b);
c:=c-strtoint(Query4.Fields[1].AsString);
stringgrid2.cells[5,d]:=inttostr(c);
Query4.Next;
d:=d+1;
end;
end
else
showmessage('Veuillez Sélectionner une Clé Pub');
//Adapter les Textes Aux Colonnes
for j:=0 to 5 do
begin
k:=0;
for i:=0 to StringGrid2.Rowcount-1 do
begin
l:=Canvas.TextWidth(StringGrid2.Cells[j,i]);//reprends la taille en pixel de la cellulle
if l>k then
begin
k:=l;
StringGrid2.ColWidths[j]:=k+4;//je met +4 pour pas que les celulles soient trop collées au texte mais sinon ca marche!
end;
end;
end;
end;
procedure TForm2.Button3Click(Sender: TObject);
var
j:integer;
begin
if StringGrid1.RowCount>2then
begin
for j:=integ[6]+1 to StringGrid1.RowCount-1 do
begin
StringGrid1.cells[0,j-1]:=StringGrid1.cells[0,j];
StringGrid1.cells[1,j-1]:=StringGrid1.cells[1,j];
StringGrid1.cells[2,j-1]:=StringGrid1.cells[2,j];
StringGrid1.cells[3,j-1]:=StringGrid1.cells[3,j];
StringGrid1.cells[4,j-1]:=StringGrid1.cells[4,j];
StringGrid1.cells[5,j-1]:=StringGrid1.cells[5,j];
StringGrid1.cells[6,j-1]:=StringGrid1.cells[6,j];
StringGrid1.cells[7,j-1]:=StringGrid1.cells[7,j];
StringGrid1.cells[8,j-1]:=StringGrid1.cells[8,j];
StringGrid1.cells[9,j-1]:=StringGrid1.cells[9,j];
end;
StringGrid1.RowCount:=StringGrid1.RowCount-1;
integ[1]:=integ[1]-1;
end
else
showmessage('il doit obligatoirement y avoir une valeur dans le tableau');
end;
end. |
Partager