www.pudn.com > Source.rar > Unit26.pas, change:2007-02-04,size:11799b


unit Unit26; 
 
interface 
 
uses 
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, 
  StdCtrls, Buttons, Grids, DBGrids, ExtCtrls, DBCtrls, ComCtrls; 
 
type 
  TVentes = class(TForm) 
    Dbgrid1: TDBGrid; 
    Timer: TTimer; 
    Panel1: TPanel; 
    Image1: TImage; 
    Image2: TImage; 
    Modifier: TBitBtn; 
    Supprimer: TBitBtn; 
    imprimer: TBitBtn; 
    Fermer: TBitBtn; 
    Nouveau: TBitBtn; 
    DBNavigator1: TDBNavigator; 
    Btreglement: TBitBtn; 
    Transfrere: TBitBtn; 
    Panel2: TPanel; 
    Label3: TLabel; 
    Client: TEdit; 
    Date_Au: TDateTimePicker; 
    N_piece: TEdit; 
    TypePiece: TComboBox; 
    Label2: TLabel; 
    Label1: TLabel; 
    Label5: TLabel; 
    GroupBox1: TGroupBox; 
    Tri: TComboBox; 
    Choix_Filtre: TRadioGroup; 
    Date_Du: TDateTimePicker; 
    GroupBox2: TGroupBox; 
    GroupBox3: TGroupBox; 
    Livraison_Partielle: TBitBtn; 
    StatusBar: TStatusBar; 
    info: TBitBtn; 
    soldee: TBitBtn; 
    Label6: TLabel; 
    Reg_Bt: TBitBtn; 
    procedure NouveauClick(Sender: TObject); 
    procedure ModifierClick(Sender: TObject); 
    procedure ClientChange(Sender: TObject); 
    procedure TransfrereClick(Sender: TObject); 
    procedure imprimerClick(Sender: TObject); 
    procedure BtreglementClick(Sender: TObject); 
    procedure SupprimerClick(Sender: TObject); 
    procedure TimerTimer(Sender: TObject); 
    procedure FormActivate(Sender: TObject); 
    procedure FormClose(Sender: TObject; var Action: TCloseAction); 
    procedure N_pieceChange(Sender: TObject); 
    procedure TypePieceCloseUp(Sender: TObject); 
    procedure Date_AuCloseUp(Sender: TObject); 
    procedure Date_DuCloseUp(Sender: TObject); 
    procedure Choix_FiltreClick(Sender: TObject); 
    procedure infoClick(Sender: TObject); 
    procedure Dbgrid1DrawColumnCell(Sender: TObject; const Rect: TRect; 
      DataCol: Integer; Column: TColumn; State: TGridDrawState); 
    procedure soldeeClick(Sender: TObject); 
    procedure Reg_BtClick(Sender: TObject); 
  private 
    { Private declarations } 
  public 
    { Public declarations } 
  end; 
 
var 
  Ventes: TVentes; 
 
implementation 
 
uses Unit3, Unit27, Unit28, Unit34, Unit35, Unit36, Unit40, Unit75, Unit63, 
  Unit64, Regroup_Unit; 
 
{$R *.dfm} 
 
procedure TVentes.NouveauClick(Sender: TObject); 
begin 
if Not( FileExists('C:\Windows\System\_sqldb.dll'))  AND (data.T_Ventes.RecordCount>20) then 
 RAise exception.Create('Version Démo !'); 
 
If data.Articles.IsEmpty then Raise exception.Create('il n''existe Aucun Articles...'); 
if Choix_Ventes.ShowModal=mrOk then 
  begin 
  data.T_Ventes.Filtered:=false; 
  data.T_Ventes.Append; 
  Sai_vente.PageControl.ActivePageIndex:=0; 
  Sai_Vente.Showmodal; 
  Ventes.ClientChange(Sender); 
  end; 
end; 
 
procedure TVentes.ModifierClick(Sender: TObject); 
begin 
if  Data.T_VentesType.Value='Facture' Then choix_ventes.Choix.ItemIndex:=0; 
if  Data.T_VentesType.Value= 'Devis'  Then choix_ventes.Choix.ItemIndex:=1; 
if  Data.T_VentesType.Value= 'Avoir'  Then choix_ventes.Choix.ItemIndex:=2; 
if  Data.T_VentesType.Value= 'Commande'  Then choix_ventes.Choix.ItemIndex:=3; 
if  Data.T_VentesType.Value= 'Livraison'  Then choix_ventes.Choix.ItemIndex:=4; 
 
data.T_Ventes.Edit; 
Sai_vente.PageControl.ActivePageIndex:=0; 
Sai_Vente.Showmodal; 
end; 
 
procedure TVentes.ClientChange(Sender: TObject); 
Var 
ch:String; 
begin 
//IF Client.GetTextLen<> 0 then 
begin 
Case Tri.ItemIndex OF 
//Tous 
//0: Ch:=''; 
//Facture 
1: Ch:= 'Type=''Facture''' ; 
//Devis 
2: Ch:= 'Type=''Devis''' ; 
//Avoir 
3: Ch:= 'Type=''Avoir''' ; 
//Commande 
4: Ch:= 'Type=''Commande''' ; 
//Bon de Livraison 
//5: Ch:= 'Type=''Livraison''' ; 
//Commandes non Livrées 
5:ch:='(Transfere=''False'' And Type=''Commande'')'; 
//Bon de Livraison non Facturée 
//7:ch:='(Transfere=''False'' And Type=''Livraison'')'; 
//Facture non Régler 
6: Ch:= '(TYPE=''Facture'') AND (Regler=False) ' ; 
//Avoir non Régler 
7:Ch:= '(Type=''Avoir'') AND (Regler=False) ' ; 
//Bin de livraison non Régler 
//10:Ch:= '(Type=''Livraison'') AND (Regler=False) ' ; 
 
END; 
 
IF tri.ItemIndex<>0 then 
  BEGIN 
   IF Client.GetTextLen=0 THEN     Data.T_Ventes.Filter:=ch 
     ELSE 
   Data.T_Ventes.Filter:='Raison='''+Client.Text+'*'' AND '+Ch; 
  END 
ELSE 
  BEGIN 
  IF Client.GetTextLen<>0 THEN Data.T_Ventes.Filter:='Raison='''+Client.Text+'*''' 
      ELSE 
    BEGIN 
    Data.T_Ventes.Filtered:=false; 
    EXIT; 
    END; 
  END; 
Data.T_Ventes.Filtered:=true; 
end; 
end; 
 
procedure TVentes.TransfrereClick(Sender: TObject); 
begin 
if data.T_VentesType.Value='Avoir' Then 
Raise exception.Create('Imposible de transfèrer cette Pièce "Avoir" '); 
TransfereVente.ShowModal; 
end; 
 
procedure TVentes.imprimerClick(Sender: TObject); 
begin 
// 
Imprime_Vente.ShowModal; 
end; 
 
procedure TVentes.BtreglementClick(Sender: TObject); 
begin 
if  Data.T_VentesType.Value='Facture' Then choix_ventes.Choix.ItemIndex:=0; 
if  Data.T_VentesType.Value= 'Avoir'  Then choix_ventes.Choix.ItemIndex:=2; 
if  Data.T_VentesType.Value= 'Livraison'  Then choix_ventes.Choix.ItemIndex:=4; 
data.T_Ventes.Edit; 
Sai_vente.PageControl.ActivePageIndex:=1; 
Sai_Vente.Showmodal; 
 
end; 
 
procedure TVentes.SupprimerClick(Sender: TObject); 
begin 
 
if MessageDlg('Confirmer la Suppression',mtConfirmation, [mbYes, mbNo], 0) = mrYes then 
    Data.T_Ventes.Delete; 
 
end; 
 
procedure TVentes.TimerTimer(Sender: TObject); 
var 
TotalErg,SurErg:integer; 
begin 
{dbgrid1.Hint:='Total TTC  ='+Data.T_VentesTotal_TTC.AsString+ 
              ''#13''+ 
              'Versement  ='+Data.T_VentesMt_Rgler.AsString+''#13''+ 
              'SOLD       ='+Data.T_VentesMontant_Rest.AsString; 
 } 
 
TotalErg:=data.T_Ventes.RecordCount;SurErg:=data.T_Ventes.RecNo; 
StatusBar.Panels[1].Text:=' '+IntToStr(TotalErg)+': '+IntToStr(SurErg); 
 
if (data.T_VentesType.Value='Avoir')OR(data.T_VentesType.Value='Facture') OR (data.T_VentesType.Value='Livraison') Then 
  BEGIN 
  IF (data.T_VentesRegler.Value=True) THen  StatusBar.Panels[2].Text:=' Pièce : Réglée' ELSE 
  StatusBar.Panels[2].Text:=' Pièce : Non Réglée'; 
  END 
      ELSE   StatusBar.Panels[2].Text:=''; 
 
case Choix_Filtre.ItemIndex of 
0: Begin 
   Date_Du.Enabled:=True; 
   Date_Du.Color:=Clwhite; 
   Date_Au.Enabled:=True; 
   Date_Au.Color:=clwhite; 
   Client.Enabled:=False; 
   Client.Color:=clBtnFace; 
   N_piece.Enabled:=false; 
   N_Piece.Color:=clBtnFace; 
   TypePiece.Enabled:=False; 
   TypePiece.Color:=clBtnFace; 
   Tri.Enabled:=False; 
   Tri.Color:=clBtnFace; 
end; 
 
1:Begin 
   Date_Du.Enabled:=False; 
   date_du.Color:=clBtnFace; 
   Date_Au.Enabled:=False; 
   date_au.Color:=clBtnFace; 
   Client.Enabled:=True; 
   client.Color:=clwhite; 
   N_piece.Enabled:=False; 
   N_piece.Color:=clBtnFace; 
   TypePiece.Enabled:=False; 
   TypePiece.Color:=clBtnFace; 
   Tri.Enabled:=True; 
   Tri.Color:=clwhite; 
  end; 
 
2: Begin 
   Date_Du.Enabled:=False; 
   date_du.Color:=clBtnFace; 
   Date_Au.Enabled:=False; 
   date_au.Color:=clBtnFace; 
   Client.Enabled:=False; 
   client.Color:=clBtnFace; 
   N_piece.Enabled:=True; 
   N_piece.Color:=clwhite; 
   TypePiece.Enabled:=True; 
   TypePiece.Color:=clWhite; 
   Tri.Enabled:=False; 
   Tri.Color:=clBtnFace; 
   end; 
END; 
 
 
if data.T_Ventes.IsEmpty then 
        Begin 
        Modifier.Enabled:=False; 
        Supprimer.Enabled:=False; 
        Transfrere.Enabled:=False; 
        Btreglement.Enabled:=false; 
        imprimer.Enabled:=False; 
        Livraison_Partielle.Enabled:=False; 
        info.Enabled:=False; 
        soldee.Enabled:=False; 
        end 
else 
        Begin 
IF (data.T_VentesType.Value='Avoir') OR (data.T_VentesTransfere.Value=True) then Transfrere.Enabled:=False Else Transfrere.Enabled:=True; 
 
If (data.T_VentesType.Value='Commande') and (data.T_VentesTransfere.Value=False)  then 
Livraison_Partielle.Enabled:=True ELSE Livraison_Partielle.Enabled:=FAlse; 
 
if ((data.T_VentesType.Value='Facture')OR (data.T_VentesType.Value='Avoir')) And (Data.T_VentesRegler.Value=False) THEN 
  BEgin 
  Btreglement.Enabled:=True; 
  soldee.Enabled:=True; 
  end 
ELSE 
  begin 
  Btreglement.Enabled:=FAlse; 
  soldee.Enabled:=FAlse; 
  end; 
 
//If (data.T_VentesType.Value='Commande') or (data.T_VentesType.Value='Devis') then 
//  Btreglement.Enabled:=False  else   soldee.Enabled:=True; 
 
 
 
        Modifier.Enabled:=True; 
        Supprimer.Enabled:=True; 
        //Transfrere.Enabled:=True; 
        //Btreglement.Enabled:=True; 
        Imprimer.Enabled:=true; 
        if (tri.ItemIndex=0) Or (tri.ItemIndex=2) OR (tri.ItemIndex=4)OR (tri.ItemIndex=4) then info.Enabled:=False ELSE         info.Enabled:=True; 
        end; 
end; 
 
procedure TVentes.FormActivate(Sender: TObject); 
begin 
Timer.Enabled:=True; 
Choix_FiltreClick(sender); 
data.Articles.CachedUpdates:=True; 
end; 
 
procedure TVentes.FormClose(Sender: TObject; var Action: TCloseAction); 
begin 
Timer.Enabled:=False; 
data.Articles.CachedUpdates:=False; 
//action:=cafree; 
end; 
 
procedure TVentes.N_pieceChange(Sender: TObject); 
begin 
IF N_Piece.GetTextLen<> 0 then 
begin 
Data.T_Ventes.Filter:='Type='''+TRIM(TypePiece.items.Strings[TypePiece.ItemIndex])+''' AND Code='''+N_Piece.Text+''''; 
Data.T_Ventes.Filtered:=true; 
end 
else 
Data.T_Ventes.Filtered:=false; 
 
end; 
 
procedure TVentes.TypePieceCloseUp(Sender: TObject); 
begin 
 
IF N_Piece.GetTextLen<> 0 then 
begin 
Data.T_Ventes.Filter:='Code='''+TRIM(TypePiece.items.Strings[TypePiece.ItemIndex])+' '+N_Piece.Text+'*'''; 
Data.T_Ventes.Filtered:=true; 
end 
else 
Data.T_Ventes.Filtered:=false; 
 
end; 
 
procedure TVentes.Date_AuCloseUp(Sender: TObject); 
begin 
Data.T_Ventes.Filter:='(Date>='''+DatetoStr(Date_du.date)+''')And (Date<='''+DateToStr(Date_Au.date)+''')'; 
Data.T_Ventes.Filtered:=True; 
 
end; 
 
procedure TVentes.Date_DuCloseUp(Sender: TObject); 
begin 
Data.T_Ventes.Filter:='(Date>='''+DatetoStr(Date_du.date)+''')And (Date<='''+DateToStr(Date_Au.date)+''')'; 
Data.T_Ventes.Filtered:=True; 
 
end; 
 
procedure TVentes.Choix_FiltreClick(Sender: TObject); 
begin 
Data.T_Ventes.Filtered:=False; 
Case choix_filtre.ItemIndex OF 
0: Ventes.Date_DuCloseUp(Sender); 
1: Ventes.ClientChange(Sender); 
2: Ventes.N_pieceChange(Sender); 
END; 
end; 
 
procedure TVentes.infoClick(Sender: TObject); 
begin 
if not data.T_Ventes.IsEmpty Then 
calcul.ShowModal; 
end; 
 
procedure TVentes.Dbgrid1DrawColumnCell(Sender: TObject; const Rect: TRect; 
  DataCol: Integer; Column: TColumn; State: TGridDrawState); 
begin 
if not ( gdFocused in State ) then 
  begin 
 
  if (DATA.T_VentesType.Value='Commande') OR (DATA.T_VentesType.Value='Devis')Then 
     Begin 
      if (data.T_VentesTransfere.Value=False) then Dbgrid1.Canvas.Font.Color := clblack 
        else Dbgrid1.Canvas.Font.Color := clSilver 
      end 
   else 
   begin 
      if (Data.T_ventesRegler.Value=False) then Dbgrid1.Canvas.Font.Color := clred 
           ELSE Dbgrid1.Canvas.Font.Color := clgreen; 
     end; 
{  if ((data.T_Ventes.RecNo mod 2)=0) then 
    dbgrid1.Canvas.Brush.Color := clInfoBk 
   else 
		dbgrid1.Canvas.Brush.Color := clwhite;} 
 
      Dbgrid1.DefaultDrawColumnCell(Rect,DataCol,Column,State); 
 
  end; 
end; 
 
procedure TVentes.soldeeClick(Sender: TObject); 
begin 
if data.T_VentesRegler.Value=True Then Raise exception.Create('Pièce déja Soldée'); 
  Data.T_Ventes.Edit; 
  data.Reglements.Append; 
  Data.ReglementsMt_rgler.Value:=Data.T_VentesMontant_Rest.Value; 
  data.ReglementsCode_cli.Value:=data.T_Ventescode_Cli.Value; 
  Data.Reglements.Post; 
  data.T_VentesRegler.Value:=True; 
  Data.T_Ventes.Post; 
 
end; 
 
procedure TVentes.Reg_BtClick(Sender: TObject); 
begin 
Regroup_Frm.showmodal; 
end; 
 
end.