unit Usocietes;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, DB,Grids, DBGrids, ExtCtrls, StdCtrls, Buttons, IBCustomDataSet,
  IBTable, IBQuery, ComCtrls, ToolWin, IBUpdateSQL, Menus,IniFiles,
  SMIBase, SMIWiz;

type
  Tfrmsocietes = class(TForm)
    ToolBar1: TToolBar;
    Panel1: TPanel;
    DSsociete: TDataSource;
    Panel4: TPanel;
    BitBtn1: TBitBtn;
    BitBtn2: TBitBtn;
    BitBtn3: TBitBtn;
    PopupMenu1: TPopupMenu;
    Ajouter1: TMenuItem;
    Modifier1: TMenuItem;
    Supprimer1: TMenuItem;
    N1: TMenuItem;
    Fermer1: TMenuItem;
    PopupMenu2: TPopupMenu;
    Ajouter2: TMenuItem;
    Modifier2: TMenuItem;
    Supprimer2: TMenuItem;
    StatusBar1: TStatusBar;
    Panel2: TPanel;
    DBGrid1: TDBGrid;
    BitBtn4: TBitBtn;
    Panel3: TPanel;
    Label1: TLabel;
    LabChpRech: TLabel;
    eValChampRech: TEdit;
    procedure BitBtn1Click(Sender: TObject);
    procedure BitBtn2Click(Sender: TObject);
    procedure BitBtn3Click(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure BitBtn4Click(Sender: TObject);
    procedure DBGrid1TitleClick(Column: TColumn);
    procedure eValChampRechChange(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure DBGrid1DblClick(Sender: TObject);

  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmsocietes: Tfrmsocietes;
  aNomChampRech:string;
implementation

uses  Umain, Uparamsociete,udataprix, uMotPasse;

{$R *.dfm}

procedure Tfrmsocietes.BitBtn1Click(Sender: TObject);
begin
Application.CreateForm(Tfrmparamsociete,frmparamsociete);
DataPRIX.Societe.append;
frmparamsociete.Show;
end;

procedure Tfrmsocietes.BitBtn2Click(Sender: TObject);
var
asupprimer:string;

begin
Application.CreateForm(TFrmMotPasse,FrmMotPasse);
FrmMotPasse.ShowModal;
if (FrmMotPasse.ModalResult=mrOk) and (trim(frmMotPasse.eMotPasse.Text)='masterkey') then

 dataprix.Societe.delete;

end;

procedure Tfrmsocietes.BitBtn3Click(Sender: TObject);
begin
Application.CreateForm(Tfrmparamsociete,frmparamsociete);
dataprix.Societe.Edit;
frmparamsociete.Show;
end;

procedure Tfrmsocietes.FormShow(Sender: TObject);
begin
dataprix.Societe.Close;
dataprix.Societe.open;
end;

procedure Tfrmsocietes.BitBtn4Click(Sender: TObject);
begin
 close;
end;

procedure Tfrmsocietes.DBGrid1TitleClick(Column: TColumn);
begin
  DBGrid1.Columns[0].Color := $00FFFFF4  ;
  DBGrid1.Columns[1].Color := $00FFFFF4  ;
  DBGrid1.Columns[2].Color := $00FFFFF4 ;

   dataprix.Societe.Close;
   dataprix.Societe.SQL.Clear;
   dataprix.Societe.SQL.Add('select * from societe'
                                     + ' Order by ' +  Column.FieldName);
   aNomChampRech:= Column.FieldName;
   LabChpRech.Caption:=Column.Title.Caption;
   dataprix.Societe.Open;
   Column.Color:=clSilver;
end;

procedure Tfrmsocietes.eValChampRechChange(Sender: TObject);
VAR  asFiltre:STRING;
begin

asFiltre := '';
if(eValChampRech.Text <> '') then
   asFiltre :='Raison_Sociale LIKE ' + QuotedStr(eValChampRech.Text +'%');
if(eValChampRech.Text <> '') then
   begin
   if(asFiltre <> '') then
      asFiltre :=  asFiltre + ' and';
      asFiltre :=  asFiltre + ' Raison_Sociale LIKE ' + QuotedStr(eValChampRech.Text +'%');
   end;
    dataprix.Societe.Active := false;
    dataprix.Societe.SQL.Clear;
if(asFiltre <> '') then
   dataprix.Societe.SQL.Add('select * from societe'
                                + ' Where ' +  asFiltre
                                + ' Order by Raison_Sociale'  )
else
   dataprix.Societe.SQL.Add('select * from societe'
                                + ' Order by Raison_Sociale'  );
 dataprix.Societe.Active := True;
 dataprix.Societe.First;

end;

procedure Tfrmsocietes.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
Action:=caFree;
end;

procedure Tfrmsocietes.DBGrid1DblClick(Sender: TObject);
 var i:integer;
begin
if frmmain.indicesociete=1 then
 begin
  Panel2.Visible:=False;
  Panel4.Visible:=False;
  i:=dataprix.Societe.RecNo;
  Frmmain.matricule:=dataprix.SocieteMFISCAL.Value;
  Frmmain.cle:=dataprix.Societecle.Value;
  Frmmain.Societe:=dataprix.SocieteMFISCAL.Value+dataprix.Societecle.Value;
  Frmmain.Adresse:=dataprix.SocieteADRESSE.value;
  Frmmain.Activite:=dataprix.SocieteACTIVITEPRINCIPALE.Value;
  Frmmain.Nomsociete:=dataprix.SocieteRAISONSOCIALE.Value;
  Frmmain.exercice:=dataprix.societeEXERCICE.Text;
  Frmmain.societeactive.Caption:=trim(dataprix.societeRAISONSOCIALE.value)+'   '+Frmmain.Societe+'  Exercice: '+frmmain.exercice;
  frmsocietes.close;
 end
else
 begin
  BitBtn3Click(sender);
 end;

end;

end.
