IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Bases de données Delphi Discussion :

Gestion des exceptions


Sujet :

Bases de données Delphi

  1. #1
    Membre chevronné
    Homme Profil pro
    CTO
    Inscrit en
    Avril 2006
    Messages
    355
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Meurthe et Moselle (Lorraine)

    Informations professionnelles :
    Activité : CTO
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2006
    Messages : 355
    Points : 1 856
    Points
    1 856
    Par défaut Gestion des exceptions
    Bonjour,

    Je cherche à intégrer une gestion des exceptions à coup de ShowMessage sur l'ouverture de la base de données ainsi que sur l'exécutions des requetes, je pense qu'il faut utiliser try mais j'ai du mal à l'utiliser dans le cas des bases de données :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    unit Unit1;
     
    interface
     
    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, mysql, DB, DBTables, Grids, DBGrids, DBCtrls, Mask;
     
    type
      Tconnexion = class(TForm)
        Label1: TLabel;
        Label2: TLabel;
        Label3: TLabel;
        EditUser: TEdit;
        EditPassword: TEdit;
        Button1: TButton;
        Database1: TDatabase;
        Query1: TQuery;
        DataSource1: TDataSource;
        procedure Button1Click(Sender: TObject);
      private
        { Déclarations privées }
      public
     
     
      end;
     
    var
      connexion: Tconnexion;
     
     
    implementation
     
    uses Unit2, Unit3;
     
    {$R *.dfm}
     
    procedure Tconnexion.Button1Click(Sender: TObject);
    begin
    Query1.SQL.Text := 'select count(usr_id) as verif from utilisateurs where usr_adm_flg=1 AND usr_lgn = ''' + EditUser.text + ''' AND usr_pass = ''' + EditPassword.Text + '''';
      Query1.active:=True;
      If Query1.FieldbyName('verif').Asstring='1' then
        begin
       // connexion.visible:=false;
        form2.visible:=true ;
        fprofs.visible:=true;
        end
      else
        ShowMessage('Identifiants incorrects');
        end;
     
     
     
    end.
    Pouvez vous m'aider ?

  2. #2
    Membre habitué
    Profil pro
    Inscrit en
    Août 2006
    Messages
    185
    Détails du profil
    Informations personnelles :
    Âge : 48
    Localisation : Belgique

    Informations forums :
    Inscription : Août 2006
    Messages : 185
    Points : 192
    Points
    192
    Par défaut
    Bonjour,

    Voilà une manière de faire :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    Query1.SQL.Text := 'select count(usr_id) as verif from utilisateurs where usr_adm_flg=1 AND usr_lgn = ''' + EditUser.text + ''' AND usr_pass = ''' + EditPassword.Text + '''';
    try
      Query1.active:=True;
      If Query1.FieldbyName('verif').Asstring='1' then
        begin
        form2.visible:=true ;
        fprofs.visible:=true;
        end
      else
        ShowMessage('Identifiants incorrects');
        end;
    except
    on e:message do
       showmessage(e.message)
       end; //end du try
    Tu peux le faire, tu veux le faire tu vas le faire Bref, soyons positif

  3. #3
    Membre chevronné
    Homme Profil pro
    CTO
    Inscrit en
    Avril 2006
    Messages
    355
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Meurthe et Moselle (Lorraine)

    Informations professionnelles :
    Activité : CTO
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2006
    Messages : 355
    Points : 1 856
    Points
    1 856
    Par défaut
    Merci pour cette réponse rapide, malheuresement, je me remet difficilement à Delphi et il faut que je déclare e visiblement, d'autre part étrangement, en ajoutant try, il ne supporte pas le end; après le ShowMessage('identifiants incorrects'), une piste ?

  4. #4
    Modérateur
    Avatar de Rayek
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Mars 2005
    Messages
    5 235
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 50
    Localisation : France, Haute Savoie (Rhône Alpes)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Mars 2005
    Messages : 5 235
    Points : 8 504
    Points
    8 504
    Par défaut
    Citation Envoyé par Antjac Voir le message
    Merci pour cette réponse rapide, malheuresement, je me remet difficilement à Delphi et il faut que je déclare e visiblement, d'autre part étrangement, en ajoutant try, il ne supporte pas le end; après le ShowMessage('identifiants incorrects'), une piste ?
    Montre nous ton code, ca sera plus simple.
    Modérateur Delphi

    Le guide du bon forumeur :
    __________
    Rayek World : Youtube Facebook

  5. #5
    Membre chevronné
    Homme Profil pro
    CTO
    Inscrit en
    Avril 2006
    Messages
    355
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Meurthe et Moselle (Lorraine)

    Informations professionnelles :
    Activité : CTO
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2006
    Messages : 355
    Points : 1 856
    Points
    1 856
    Par défaut
    Connexion:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
     
    unit Unit1;
     
    interface
     
    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, mysql, DB, DBTables, Grids, DBGrids, DBCtrls, Mask;
     
    type
      Tconnexion = class(TForm)
        Label1: TLabel;
        Label2: TLabel;
        Label3: TLabel;
        EditUser: TEdit;
        EditPassword: TEdit;
        Button1: TButton;
        Database1: TDatabase;
        Query1: TQuery;
        DataSource1: TDataSource;
        procedure Button1Click(Sender: TObject);
      private
        { Déclarations privées }
      public
     
     
      end;
     
    var
      connexion: Tconnexion;
     
     
    implementation
     
    uses Unit2, Unit3;
     
    {$R *.dfm}
     
    procedure Tconnexion.Button1Click(Sender: TObject);
    begin
    Query1.SQL.Text := 'select count(usr_id) as verif from utilisateurs where usr_adm_flg=1 AND usr_lgn = ''' + EditUser.text + ''' AND usr_pass = ''' + EditPassword.Text + '''';
      try
      Query1.active:=True;
      If Query1.FieldbyName('verif').Asstring='1' then
        begin
       // connexion.visible:=false;
        form2.visible:=true ;
        fprofs.visible:=true;
        end
      else
        ShowMessage('Identifiants incorrects');
      end;
     
    except
    on e.message do
    showmessage(e.message)
    end;
    end.
    Unit2 :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
     
    unit Unit2;         
     
    interface
     
    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, ComCtrls, StdCtrls, Grids, Contnrs, ExtCtrls, xmldom, XMLIntf,
      msxmldom, XMLDoc, DateUtils, DB, DBTables, DBGrids, Menus;
     
     
    Type TGrille = class(TStringGrid)
      private
        Fnum_semaine: integer;
        Fnom_grille: string;
      published
        property num_semaine: integer read Fnum_semaine  write Fnum_semaine;
        property nom_grille: string read Fnom_grille write Fnom_grille;
    end;
     
    Type Tplage = class(TRichEdit)
      private
        Fhdeb: Integer;
        Fhfin: Integer;
        Fjour: string;
        Fsalle: string;
        Fmodule: string;
        Fformateur: string;
        Fsemaine: integer;
        Fnom_edt: string;
      public
      published
        property nom_edt: string read Fnom_edt write Fnom_edt;
        property hdeb: Integer read Fhdeb write Fhdeb;
        property hfin: Integer read Fhfin write Fhfin;
        property jour: string read Fjour write Fjour;
        property salle: string read Fsalle write Fsalle;
        property module: string read Fmodule write Fmodule;
        property formateur: string read Fformateur write Fformateur;
        property semaine: integer read Fsemaine write Fsemaine;
    end;
     
     
      type Ttab_day = array[1..6] of String;
     
    type
      TForm2 = class(TForm)
        btn_ajoutplage: TButton;
        PageControl1: TPageControl;
        lst_edt: TListBox;
        lst_jours: TListBox;
        edt_hdeb: TLabeledEdit;
        edt_hfin: TLabeledEdit;
        cbx_profs: TComboBox;
        cbx_salles: TComboBox;
        Label1: TLabel;
        edt_num_semaine: TEdit;
        btn_chg_semaine: TButton;
        Query1: TQuery;
        DataSource1: TDataSource;
        RichEdit1: TRichEdit;
        MainMenu1: TMainMenu;
        Menu11: TMenuItem;
        Menu21: TMenuItem;
        SSmenu11: TMenuItem;
        DBGrid1: TDBGrid;
        Query2: TQuery;
        DBGrid2: TDBGrid;
        DataSource2: TDataSource;
        PopupMenu1: TPopupMenu;
        test1: TMenuItem;
        procedure ajout_edt(fil_num: integer; fil_code: string);
        procedure btn_ajoutplageClick(Sender: TObject);
        procedure FormCreate(Sender: TObject);
        procedure plagemousedown(Sender: TObject;Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
        procedure btn_chg_semaineClick(Sender: TObject);
     
      private
        { Déclarations privées }
      public
        function is_affected(index_edt,  hdeb, hfin, semaine: Integer; jour:string): boolean;
        function Trouve_jour(jour: string): integer;
        function calcul_date_semaine(date: Tdatetime; option:integer=0): Ttab_day;
        function creation_grille(tab: Ttabsheet; nb_semaine:Integer): Tgrille;
        function ajout_plage(Grille:TGrille; jour, hdeb: Tdatetime ; nbh:double; num_semaine, fil_num :Integer): TRichEdit;
     
        { Déclarations publiques }
     
      end;
     
     
     
    var
      Form2: TForm2;
      nb_edt: Integer;
      j: integer;
      Tab_heure: array[1..12] of Integer;
      Tab_jours: array[1..6] of String = ('Lundi', 'Mardi', 'Mercredi', 'Jeudi', 'Vendredi', 'Samedi');
     
    implementation
     
    {$R *.dfm}
     
    {
    Nom:
      ajout_edt
     
    But:
      Ajout un onglet correspondant à une filière
      Crée dynamiquement la grille (emploi du temps) correspondante
     
    Entrées:
      fil_num: integer => l'identifiant de la filiere
      fil_code: string => le nom ("raccourci") de la filiere
     
    Sortie:
      Aucune
     
    }
    procedure TForm2.ajout_edt(fil_num: integer; fil_code: string);
    var
      Tab: TTabSheet;
      semaine: integer;
    begin
          //Création de l'onglet
          With Tab do
          begin
            Tab := TTabsheet.Create(self);
            PageControl := PageControl1;
            Height := PageControl1.Height;
            Width := PageControl1.Width;
            Caption := fil_code;
            Name := 'EDT_' + fil_code;
            Parent := PageControl1;
            tag :=  fil_num;
          end;
     
           semaine:= strtoint(edt_num_semaine.Text);
          //Création de la grille
            creation_grille(Tab, semaine);
     
          lst_edt.Items.Add(Tab.Caption);
          nb_edt := nb_edt + 1;
     
    end;
     
     
    {
    nom:
      btn_ajoutplageClick
     
    But:
      permet de tester la création/ajout d'une plage horaire sur une (plusieurs) grille(s)
     
    Entrées:
      Sender: TObject => l'objet qui appelle la procédure (un bouton dans le cas présent)
     
    Sortie:
      Aucune
     
    }
    procedure TForm2.btn_ajoutplageClick(Sender: TObject);
    var
     
      i,   index_hdeb, index_hfin, num_semaine: integer;
      jour_plage: string;
      selected: boolean;
      nom_edt_tmp: string;
     
    begin
      selected := false;
      jour_plage := '';
      i := 0;
      repeat
        if lst_jours.Selected[i] = true then
         begin
          jour_plage := lst_jours.Items[i];
          selected := true;
         end
        else i := i+1;
      until (selected = true) or (i=6);
     
      if (jour_plage <> '') and ( StrToInt(edt_hfin.Text) >  StrToInt(edt_hdeb.Text) )
          and ( StrToInt(edt_hdeb.Text) > 7) and (StrToInt(edt_hfin.Text)<21)
          and ( cbx_salles.Text <> 'Liste des salles' ) and (cbx_profs.Text <> 'Liste des Profs')
      then
      begin
        index_hdeb := StrToInt(edt_hdeb.Text);
        index_hfin := StrToInt(edt_hfin.Text);
     
        for i := 0 to nb_edt-1 do
        begin
     
          if lst_edt.Selected[i] = true then
          begin
            num_semaine := strtoint(edt_num_semaine.text);
            if not is_affected(i, index_hdeb, index_hfin, num_semaine, jour_plage) then
            begin
              nom_edt_tmp := PageControl1.Pages[i].Caption;
            end
            else
            begin
              Showmessage('deja affecte');
            end;
          end;
        end;
      end
      else
      begin
        ShowMessage('Erreur dans les sélections');
      end;
    end;
     
    {
    nom:
      FormCreate
     
    But:
      Initialise la création des onglets correspondants aux filières.
     
    Entrées:
      Sender: TObject => l'objet qui appelle la procédure (la fenêtre)
     
    Sortie:
      Aucune
     
    }
     
    procedure TForm2.FormCreate(Sender: TObject);
    begin
      edt_num_semaine.Text := inttostr(weekoftheyear(now));
      Query1.SQL.Clear;
      Query1.SQL.Add('SELECT fil_num, fil_code FROM filiere');
      Query1.open;
       while not Query1.Eof do
       begin
        ajout_edt(Query1.Fields[0].AsInteger, Query1.Fields[1].asstring);
        Query1.Next;
       end;
    end;
     
    {
    nom:
      plagemousedown
     
    But:
      Sera utilisée pour la mise en place d'un menu contextuel sur les plages
     
    Entrées:
      Sender: TObject => l'objet qui appelle la procédure (la fenêtre)
      Button:TMouseButton => le bouton enfoncé (right, left, middle)
      Shift: TShiftState =>  définit si la touche Shift est enfoncée
      X, Y: Integer =>   les coordonnées de la souris au moment du clic
     
    Sortie:
      Aucune
     
    }
    procedure TForm2.plagemousedown(Sender: TObject;Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
    var
      Plage: TPlage;
    begin
        Plage := Sender as TPlage;
        RichEdit1.Text := Plage.nom_edt;
    end;
     
     
    {
    nom:
      is_affected
     
    But:
      Permet de vérifier si une plage est déjà affectée
      A retravailler avec la base de données
     
    Entrées:
      index_edt,
      hdeb,
      hfin,
      semaine: Integer;
      jour:string
     
    Sortie:
      booléen: Vrai => une plage est déjà affectée pour cette date / heure
               Faux => aucune plage présente affection possible.
    }
     
    function TForm2.is_affected(index_edt, hdeb, hfin, semaine: Integer; jour:string): boolean;
    var
      aff: boolean;
    begin
      aff := false;
      {i:= 0;
      grille :=PageControl1.Pages[index_edt].Components[0] as Tgrille;
      while (aff = false) and (i < Liste_plage.Count) do
      begin
        plage_tmp := liste_plage.Items[i] as Tplage;
       //tmp.nom_edt = grille.nom_grille)
        if (plage_tmp.nom_edt = grille.nom_grille) and (plage_tmp.jour = jour) and (plage_tmp.semaine = semaine) and (not ( (hdeb>=plage_tmp.hfin) or (hfin<=plage_tmp.hdeb) ) ) then aff := true
        else inc(i);
      end;}
      Result := aff
    end;
     
     
     
    {
    nom:
      Trouve_jour
     
    But:
      Sera utilisée pour la mise en place d'un menu contextuel sur les plages
     
    Entrées:
      Sender: TObject => l'objet qui appelle la procédure (la fenêtre)
      Button:TMouseButton => le bouton enfoncé (right, left, middle)
      Shift: TShiftState =>  définit si la touche Shift est enfoncée
      X, Y: Integer =>   les coordonnées de la souris au moment du clic
     
    Sortie:
      Aucune
     
    }
    function TForm2.Trouve_jour(jour: string): integer;
    var
      trouver: boolean;
      index : integer;
    begin
      trouver := false;
      index := 1;
      repeat
        if Tab_jours[index] = jour then
          trouver := true
        else
          index := index + 1;
     
      until (trouver = true) or (index = 7);
      if (trouver = false) and (index = 7) then
        index := 0;
     
      Result:=index;
    end;
     
    function TForm2.calcul_date_semaine(date: Tdatetime; option:integer=0): Ttab_day;
    var
      tab: Ttab_day;
      i, jour_date:integer;
    begin
      jour_date := dayoftheweek(date);
      for i:=1 to 6 do
      begin
        if i < jour_date then
        begin
          if option = 0 then
            tab[i] := FormatDatetime( 'dddd dd/mm', (date - jour_date + i) )
          else
            tab[i] := FormatDatetime( 'yyyy-mm-dd', (date - jour_date + i) )
        end;
        if i = jour_date then
        begin
          if option = 0 then
            tab[i] := FormatDatetime( 'dddd dd/mm', date )
          else
            tab[i] := FormatDatetime( 'yyyy-mm-dd', date )
        end;
        if i > jour_date then
        begin
          if option = 0 then
            tab[i] := FormatDatetime( 'dddd dd/mm', (date + (i - jour_date ) ) )
          else
            tab[i] := FormatDatetime( 'yyyy-mm-dd', (date + (i - jour_date ) ) )
        end;
      end;
     
      Result := tab;
    end;
     
    function TForm2.creation_grille(tab: Ttabsheet; nb_semaine:Integer): Tgrille;
    var
      Grille, g: TGrille;
      i,k, m: integer;
      tab_date: Ttab_day;
    Const
      SelectionNulle : TGridRect = ( Left : -1 ; Top : -1 ; Right : -1 ; Bottom : -1 ) ;
    begin
          With  Grille do
          begin
            Grille := TGrille.Create(Tab);
            Parent := Tab;
            Name := 'Grille_' + IntToStr(j);
            Width := Tab.Width;
            Height := Tab.Height;
            align := alclient;
            ColCount := 7;
            RowCount := 49;
            DefaultColWidth := 100;
            ColWidths[0] := 50;
            DefaultRowHeight := 12;
            num_semaine :=  nb_semaine;
            nom_grille :=  'Grille_' + IntToStr(nb_semaine) + '_' + tab.Caption;
            selection := SelectionNulle;
           end;
     
          k :=  (weekoftheyear(now) - nb_semaine);
          tab_date := calcul_date_semaine( now - 7*k );
          for i:=1 to 6 do
          begin
            Grille.Cells[i,0] := uppercase(tab_date[i]);
          end;
     
          k:=1;
          for i := 1 to 12 do
          begin
            g := Tgrille.Create(Grille);
            g.Parent := grille;
            g.DefaultRowHeight := 15;
            g.Height := 60;
            g.Width := 50;
            g.ScrollBars :=  ssnone;
            g.DefaultColWidth := 25;
            g.Color := clBtnFace;
            g.FixedCols := 2;
            g.FixedRows := 4;
            g.Options := [];
            //g.Align := alclient;
            g.ColCount := 2;
            g.Top := Grille.Cellrect(0,k).top;
            g.left := Grille.cellrect(0,k).left;
            g.BorderStyle := bsnone;
            g.RowCount := 4;
            g.GridLineWidth := 0;
            g.Cells[0, 0] := inttostr(i+7);
            g.Selection := SelectionNulle;
            for m:= 0 to 3 do
            begin
              if m=0 then g.cells[1,m] := '00'
              else g.cells[1,m] := inttostr(m*15);
            end;
            k := k+4;
          end;
     
          k :=  (weekoftheyear(now) - nb_semaine);
          tab_date := calcul_date_semaine( now - 7*k, 1);
          Query2.Close;
          Query2.SQL.Clear;
          Query2.SQL.Text := 'SELECT edt.fil_num, edt_date, edt_hdeb, edt_nbh, salle1_code FROM edt, filiere WHERE edt_date BETWEEN ''' + tab_date[1] + ''' AND ''' + tab_date[6] + ''' AND filiere.fil_num = edt.fil_num AND fil_code LIKE ''' + Tab.Caption + '''';
         // RichEdit1.Text := Query2.SQL.Text;
          Query2.Open;
     
         while not Query2.Eof do
          begin
            ajout_plage(Grille, Query2.Fields[1].AsDateTime, Query2.Fields[2].AsDateTime, Query2.Fields[3].AsFloat, nb_semaine, Query2.fields[0].asinteger);
            Query2.Next;
          end;
          inc(j);
       Result:=grille;
    end;
     
    function TForm2.ajout_plage(Grille:TGrille; jour, hdeb: Tdatetime ; nbh:double; num_semaine, fil_num :Integer): TRichEdit;
    var
      Edit: TRichEdit;
      pos, val_jour, diff_h, diff_m, inbh: integer;
      info_plage: string;
      tmp: Tdatetime;
      menu: Tpopupmenu;
      item: TmenuItem;
      items: array[1..2] of TmenuItem;
    begin
      inbh:= strtoint(floattostr(nbh));
      val_jour := dayoftheweek(jour);
      tmp := encodetime(8, 00, 00, 00);
      diff_h := strtoint(formatdatetime('h', (hdeb - tmp)));
      diff_m := strtoint(formatdatetime('n', (hdeb - tmp)));
      pos := (1 + diff_h * 4) + strtoint(floattostr( diff_m / 60 * 4));
      info_plage := 'Plage temporaire' + chr(10) + formatdatetime('hh:mm', hdeb) + ' - ' + formatdatetime('hh:mm', (hdeb+(nbh/24)) );
      Edit := Tplage.Create(Grille);
      With Edit do
      begin
        Parent := Grille;
        BorderStyle := BsNone;
        BevelInner := bvnone;
        Bevelkind := bkFlat;
        BevelOuter := bvRaised;
        Text := info_plage;
        ReadOnly := True;
        Color := cl3DLight;
        Top := Grille.CellRect(val_jour , pos ).Top;
        Left := Grille.CellRect(val_jour , pos ).Left;
        Height := Grille.DefaultRowHeight * inbh * 4  + inbh *4;
        Width := Grille.DefaultColWidth;
        name := 'plage_' + inttostr(fil_num) + '_' + inttostr(num_semaine) + '_' + formatdatetime('ddmmyyy', jour) + '_' + formatdatetime('hhmm', hdeb);
     
      end;
     
     
      menu := Tpopupmenu.Create(Edit);
      menu.Name := 'menu_'+ edit.Name;
      item := TmenuItem.Create(self);
      item.Caption := 'Modifier';
      item.Name := 'item_modif';
      items[1] := item;
     
      item := TmenuItem.Create(self);
      item.Caption := 'Supprimer';
      item.Name := 'item_suppr';
      items[2] := item;
     
      menu.Items.Add(items);
      edit.PopupMenu := menu;
     
      Result:=Edit;
     
    end;
     
    procedure TForm2.btn_chg_semaineClick(Sender: TObject);
    var
      TS: TTabsheet;
      semaine: integer;
     
    begin
      Ts := PageControl1.ActivePage;
      semaine := strtoint(edt_num_semaine.text);
      TS.Components[0].Free;
      creation_grille(TS, semaine);
    end;
     
    initialization
      nb_edt := 0;
      j := 1;
    end.
    Unit3:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
     
    unit Unit3;
     
    interface
     
    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, ComCtrls, StdCtrls, Grids, Contnrs, ExtCtrls, xmldom, XMLIntf,
      msxmldom, XMLDoc, DateUtils, DB, DBTables, DBGrids, Menus, DBCtrls;
     
     
    type
     TGrille = class(TStringGrid)
      private
        Fnum_semaine: integer;
        Fnom_grille: string;
      published
        property num_semaine: integer read Fnum_semaine  write Fnum_semaine;
        property nom_grille: string read Fnom_grille write Fnom_grille;
    end;
     
    Type
     
      Tfprofs = class(TForm)
        profs: TPageControl;
        TabSheet1: TTabSheet;
        TabSheet3: TTabSheet;
        Label15: TLabel;
        btnvalidcontraintes: TButton;
        listofrmateurs: TDataSource;
        Label1: TLabel;
        contraintes: TStringGrid;
        Label2: TLabel;
        DBMemContrainte: TDBMemo;
        qryformcontrainte: TQuery;
        formcontrainteds: TDataSource;
        Memochange: TMemo;
        qryformcontrainteform_contrainte: TStringField;
        queryformateurs: TQuery;
        queryformateursform_ident: TStringField;
        queryformateursform_num: TIntegerField;
        DBCBformateurs: TDBLookupComboBox;
        qrymodifcontraintes: TQuery;
     
     
     
        procedure TabSheet1Show(Sender: TObject);
        procedure TabSheet1MouseUp(Sender: TObject; Button: TMouseButton;
          Shift: TShiftState; X, Y: Integer);
        procedure contraintesDrawCell(Sender: TObject; ACol, ARow: Integer;
          Rect: TRect; State: TGridDrawState);
        procedure contraintesDblClick(Sender: TObject);
        procedure contraintesMouseUp(Sender: TObject; Button: TMouseButton;
          Shift: TShiftState; X, Y: Integer);
        procedure FormShow(Sender: TObject);
        procedure queryformateursAfterScroll(DataSet: TDataSet);
        procedure btnvalidcontraintesClick(Sender: TObject);
        procedure DBCBformateursCloseUp(Sender: TObject);
     
     
     
     
     
     
     
     
      private
        { Déclarations privées }
      public
        CActiv:integer;
        LActiv:integer;
      end;
     
    var
      fprofs: Tfprofs;
       nb_edt: Integer;
      j: integer;
      Tab_heure: array[1..12] of Integer;
      Tab_jours: array[1..6] of String = ('Lundi', 'Mardi', 'Mercredi', 'Jeudi', 'Vendredi', 'Samedi');
     
    implementation
     
    {$R *.dfm}
    var Col,Row:Longint;
     
     
     
     
     
     
    procedure Tfprofs.TabSheet1Show(Sender: TObject);
    begin
    contraintes.cells[1,0]:='Lundi';
    contraintes.cells[2,0]:='Mardi';
    contraintes.cells[3,0]:='Mercredi';
    contraintes.cells[4,0]:='Jeudi';
    contraintes.cells[5,0]:='Vendredi';
    contraintes.cells[6,0]:='Samedi';
    contraintes.cells[0,1]:='8h00';
    contraintes.cells[0,2]:='8h30';
    contraintes.cells[0,3]:='9h00';
    contraintes.cells[0,4]:='9h30';
    contraintes.cells[0,5]:='10h00';
    contraintes.cells[0,6]:='10h30';
    contraintes.cells[0,7]:='11h00';
    contraintes.cells[0,8]:='11h30';
    contraintes.cells[0,9]:='12h00';
    contraintes.cells[0,10]:='12h30';
    contraintes.cells[0,11]:='13h00';
    contraintes.cells[0,12]:='13h30';
    contraintes.cells[0,13]:='14h00';
    contraintes.cells[0,14]:='14h30';
    contraintes.cells[0,15]:='15h00';
    contraintes.cells[0,16]:='15h30';
    contraintes.cells[0,17]:='16h00';
    contraintes.cells[0,18]:='16h30';
    contraintes.cells[0,19]:='17h00';
    contraintes.cells[0,20]:='17h30';
    contraintes.cells[0,21]:='18h00';
    contraintes.cells[0,22]:='18h30';
    contraintes.cells[0,23]:='19h00';
    contraintes.cells[0,24]:='19h30';
    end;
     
     
    procedure Tfprofs.TabSheet1MouseUp(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    begin
      // ici je recupere les coordonnées de la cellules en fonction du clic souris
        contraintes.MouseToCell(X,Y,Col,Row);
    end;
     
     
     
    procedure Tfprofs.contraintesDrawCell(Sender: TObject; ACol, ARow: Integer;
      Rect: TRect; State: TGridDrawState);
     
    begin
     
          // ici je selectionne la couleur en fonction de l'etat de la cellule
     
        with contraintes.Canvas do
        begin
            if (Arow >0) and (Acol>0) then
            begin
            if Memochange.lines[Acol-1][Arow]='x' then Brush.color:=clred
            else Brush.color:=clwhite;
            fillrect(rect);
            textout(Rect.Left,Rect.Top,contraintes
             .cells[Acol,Arow]);
     
            end;
        end;
     
    end;
     
     
    procedure Tfprofs.contraintesDblClick(Sender: TObject);
     
    var st:string;
    begin
      // le filtres les colonnes et rangées fixes.
     
      if (row=0) and (col=0) then exit;
     
      // ici je modifié mon memo pour mettre un 'X' sur la cellule cliqué.
      // tu peux aussi modifier directement la base a la place de du memo
      // en fais je ne fais de mettre ou enlever le x correspondant a la cellule cliqué
      St:=Memochange.lines[col-1];
      if st[row]='x'then st[row]:='-'  else st[row]:='x';
      Memochange.lines[col-1]:=st;
      contraintes.repaint;
    end;
     
     
     
     
    procedure Tfprofs.contraintesMouseUp(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    begin
         // ici je recupere les coordonnées de la cellules en fonction du clic souris
        contraintes.MouseToCell(X,Y,Col,Row);
    end;
     
    procedure Tfprofs.FormShow(Sender: TObject);
    begin
        queryformateurs.open;
        qryformcontrainte.open;
    end;
     
    procedure Tfprofs.queryformateursAfterScroll(DataSet: TDataSet);
     
      var stEntiere,stpartielle :string;
         i,j:integer;
         changements:string;
         requetemodif:string;
    begin
     
        stEntiere:=DBMemContrainte.Text;
        memochange.clear;
        if DbMemContrainte.text='' then
        begin
        changements:='------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------';
        requetemodif:='UPDATE formateur SET form_contrainte=''' + changements + ''' WHERE form_num='+queryformateursform_num.AsString;
        qrymodifcontraintes.sql.Clear;
        qrymodifcontraintes.sql.Add(requetemodif);
        qrymodifcontraintes.ExecSQL;
        DBMemContrainte.Refresh;
        stEntiere:=DBMemContrainte.Text;
        memochange.clear;
        end;
     
     
        for j:=1 to 6 do
        begin
            for i:=1 to 23 do stpartielle:=stpartielle+stEntiere[i];
            memochange.Lines.add(stpartielle);
            stpartielle:='';
            delete(stEntiere,1,23);
         end;
         contraintes.repaint;
     
    end;
     
    procedure Tfprofs.btnvalidcontraintesClick(Sender: TObject);
    var requetemodif:string;
        changements:string;
        k:integer;
    begin
    for k:=0 to 5 do changements:=changements + memochange.Lines[k];
    requetemodif:='UPDATE formateur SET form_contrainte=''' + changements + ''' WHERE form_num='+queryformateursform_num.AsString;
    qrymodifcontraintes.sql.Clear;
    qrymodifcontraintes.sql.Add(requetemodif);
    qrymodifcontraintes.ExecSQL;
     
    end;
     
     
    procedure Tfprofs.DBCBformateursCloseUp(Sender: TObject);
    begin
       label15.Visible:=true;
       contraintes.Visible:=true;
       btnvalidcontraintes.visible:=true;
     
     
     
    end;
     
    end.

  6. #6
    Membre habitué
    Profil pro
    Inscrit en
    Août 2006
    Messages
    185
    Détails du profil
    Informations personnelles :
    Âge : 48
    Localisation : Belgique

    Informations forums :
    Inscription : Août 2006
    Messages : 185
    Points : 192
    Points
    192
    Par défaut
    Tu as un end; mal placé

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    procedure Tconnexion.Button1Click(Sender: TObject);
    begin
    Query1.SQL.Text := 'select count(usr_id) as verif from utilisateurs where usr_adm_flg=1 AND usr_lgn = ''' + EditUser.text + ''' AND usr_pass = ''' + EditPassword.Text + '''';
      try
      Query1.active:=True;
      If Query1.FieldbyName('verif').Asstring='1' then
        begin
       // connexion.visible:=false;
        form2.visible:=true ;
        fprofs.visible:=true;
        end
      else
        ShowMessage('Identifiants incorrects');
      end; A supprimer  
    except
       on e.message do sorry, c'est e:exception
       showmessage(e.message)
       end;
    end.
    tu ne dois pas déclarer le e, c'est fait avec la ligne on e:exception
    Tu peux le faire, tu veux le faire tu vas le faire Bref, soyons positif

Discussions similaires

  1. [ADOConnect] gestion des exception en tout temps
    Par portu dans le forum Bases de données
    Réponses: 1
    Dernier message: 20/04/2005, 19h01
  2. [ORACLE 9i] Gestion des exceptions
    Par sygale dans le forum SQL
    Réponses: 6
    Dernier message: 19/08/2004, 15h06
  3. Gestion des exception (EOleException)
    Par shurized dans le forum Bases de données
    Réponses: 5
    Dernier message: 30/06/2004, 17h25
  4. [XMLRAD] gestion des exceptions
    Par pram dans le forum XMLRAD
    Réponses: 2
    Dernier message: 28/01/2003, 17h48
  5. c: gestion des exceptions
    Par vince_lille dans le forum C
    Réponses: 7
    Dernier message: 05/06/2002, 14h11

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo