unit fmodacreedor;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics,math, Controls, Forms,
  Dialogs, StdCtrls, Mask, DBCtrls, Buttons, ExtCtrls, DB, DBClient,
  Provider, FMTBcd, SqlExpr;

type
  Tfmodifiacreedor = class(TForm)
    Panel1: TPanel;
    dterceros: TDataSource;
    dproveedores: TDataSource;
    dgrupo: TDataSource;
    GroupBox1: TGroupBox;
    Label12: TLabel;
    Label13: TLabel;
    DBEdit12: TDBEdit;
    Label14: TLabel;
    DBEdit13: TDBEdit;
    Label15: TLabel;
    DBEdit14: TDBEdit;
    Label20: TLabel;
    DBEdit19: TDBEdit;
    DBLookupComboBox1: TDBLookupComboBox;
    DBEdit11: TDBEdit;
    Label24: TLabel;
    pgrupo: TDataSetProvider;
    cgrupo: TClientDataSet;
    botongrabar: TSpeedButton;
    cancelar: TSpeedButton;
    BSalir: TSpeedButton;
    GroupBox2: TGroupBox;
    Label4: TLabel;
    Label6: TLabel;
    Label11: TLabel;
    Label1: TLabel;
    Label10: TLabel;
    DBEdit4: TDBEdit;
    DBEdit6: TDBEdit;
    DBEdit10: TDBEdit;
    DBEdit8: TDBEdit;
    DBEdit9: TDBEdit;
    GroupBox4: TGroupBox;
    Label3: TLabel;
    Label2: TLabel;
    DBEdit2: TDBEdit;
    DBEdit3: TDBEdit;
    Label7: TLabel;
    GroupBox5: TGroupBox;
    DBMemo1: TDBMemo;
    Cvalidaproveedor: TClientDataSet;
    Pvalprov: TDataSetProvider;
    cgrupoGRPR_COD: TStringField;
    cgrupoGRPR_NOM: TStringField;
    cgrupoGRPR_CTAPROV: TStringField;
    cgrupoGRPR_CTARTFTE: TStringField;
    cgrupoGRPR_CTARTIVA: TStringField;
    cgrupoGRPR_CTARTICA: TStringField;
    GroupBox3: TGroupBox;
    Label18: TLabel;
    Label17: TLabel;
    Label19: TLabel;
    Label16: TLabel;
    Label21: TLabel;
    Label22: TLabel;
    Label23: TLabel;
    DBEdit17: TDBEdit;
    DBEdit16: TDBEdit;
    DBEdit18: TDBEdit;
    DBEdit15: TDBEdit;
    DBEdit20: TDBEdit;
    DBEdit21: TDBEdit;
    DBEdit22: TDBEdit;
    ptercero: TDataSetProvider;
    cterceros: TClientDataSet;
    ctercerosTERC_NIT: TStringField;
    ctercerosTERC_NOM: TStringField;
    ctercerosTERC_DIR: TStringField;
    ctercerosTERC_CIU: TStringField;
    ctercerosTERC_TEL: TStringField;
    ctercerosTERC_CONTACTO: TStringField;
    ctercerosTERC_OBS: TBlobField;
    ctercerosTERC_EMAIL: TStringField;
    ctercerosTERC_FAX: TStringField;
    ctercerosTERC_CEL: TStringField;
    ctercerosTERC_CLIE: TStringField;
    ctercerosTERC_PROV: TStringField;
    ctercerosTERC_EMPL: TStringField;
    ctercerosTERC_CTARTFTE: TStringField;
    ctercerosTERC_CTARTIVA: TStringField;
    ctercerosTERC_CTARTICA: TStringField;
    ctercerosTERC_CTAVENTA: TStringField;
    ctercerosTERC_CTACLIENTE: TStringField;
    ctercerosTERC_CTAPROV: TStringField;
    ctercerosTERC_CTAEMPL: TStringField;
    cproveedor: TClientDataSet;
    SpeedButton1: TSpeedButton;
    Cciudades: TClientDataSet;
    Pciudades: TDataSetProvider;
    Dciudades: TDataSource;
    DBLookupComboBox3: TDBLookupComboBox;
    SpeedButton3: TSpeedButton;
    Label5: TLabel;
    ctercerosCIUD_COD: TStringField;
    ctercerosTERC_DV: TStringField;
    ctercerosTproveedores: TDataSetField;
    cproveedorTERC_NIT: TStringField;
    cproveedorGRPR_COD: TStringField;
    cproveedorPROV_COD: TStringField;
    cproveedorPROV_CODIGOINT: TStringField;
    cproveedorPROV_VENDEDOR: TStringField;
    cproveedorPROV_CARTERA: TStringField;
    cproveedorPROV_RETEFTE: TFMTBCDField;
    cproveedorPROV_RTEIVA: TFMTBCDField;
    cproveedorPROV_RTEICA: TFMTBCDField;
    cproveedorPROV_RTFTEBASE: TFMTBCDField;
    CciudadesCIUD_COD: TStringField;
    CciudadesCIUD_NOM: TStringField;
    DBEdit: TDBEdit;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormCreate(Sender: TObject);
    procedure FormActivate(Sender: TObject);
    procedure FormKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure cancelarClick(Sender: TObject);
    procedure botongrabarClick(Sender: TObject);
    procedure BSalirClick(Sender: TObject);
    procedure buscarClick(Sender: TObject);
    procedure SpeedButton1Click(Sender: TObject);
    procedure SpeedButton3Click(Sender: TObject);
    procedure Enteratab(Sender: TObject; var Key: Char);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  fmodifiacreedor: Tfmodifiacreedor;

implementation

uses dmcxpagar, cuadroacreedor, fbuscaacreedores, fmenucxp, fgrupos,
  ciudades;

{$R *.dfm}

procedure Tfmodifiacreedor.botongrabarClick(Sender: TObject);
begin
  if (ctercerosTERC_NIT.Value = '')then
      ShowMessage('Falta ingresar el NIT o identificación del tercero.')
  else
      if (ctercerosTERC_Nom.Value = '')then
        ShowMessage('Falta ingresar el Nombre del tercero.')
      else
        begin
        cterceros.Post;
        CTerceros.ApplyUpdates(0);
        CTerceros.Edit;
        DBEdit2.SetFocus;
        end;
end;

procedure Tfmodifiacreedor.cancelarClick(Sender: TObject);
var Mensaje : String;
begin
 Mensaje := 'Si cancela ahora perderá los datos no grabados, continuar?';
    if MessageDlg(Mensaje, mtConfirmation,
        [mbYes, mbNo], 0) = mrYes then
        begin
       CTerceros.CancelUpdates;
       CTerceros.Edit;
       end;

end;


procedure Tfmodifiacreedor.FormCreate(Sender: TObject);
begin
dmcxp.ConfigurarProviders(Self);
width :=  497;
height := 460;
top:=  ceil ((menucxp.ClientHeight-80-Height)/2);
left:= ceil ((menucxp.Clientwidth-130-width)/2);
Cciudades.open;
cgrupo.Open;
cterceros.Close;
cterceros.FetchParams;
cterceros.Params.ParamByName('ID').AsString := dmcxp.EditTerc;
cterceros.Open;
if cterceros.IsEmpty then
  begin
  showmessage ('Error.No se encuentra el Acreedor solicitado');  Close;
  end
else
  begin
  CTerceros.Edit;
  end;
end;

procedure Tfmodifiacreedor.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
if (cterceros.State = dsedit) or (cterceros.State = dsinsert)then
  cterceros.CancelUpdates;
cterceros.Close;
cgrupo.close;
Action :=caFree;
end;


procedure Tfmodifiacreedor.FormActivate(Sender: TObject);
begin
    if not cterceros.IsEmpty then
    begin
    Cciudades.Refresh;
    cgrupo.refresh;
    end;
end;

procedure Tfmodifiacreedor.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if not (ssAlt in Shift) or (ssCtrl in Shift) or (ssShift in Shift) then
begin                     //1
if key = VK_ESCAPE then  //cancelar
cancelarClick(Self);
if key = VK_F2 then //graba
botongrabarClick(Self);
if key = VK_F8 then //graba
buscarClick(Self);
end;                  //1
end;



procedure Tfmodifiacreedor.BSalirClick(Sender: TObject);
begin
close;
end;

procedure Tfmodifiacreedor.buscarClick(Sender: TObject);
begin
Tfbuscaacreedor.Create(Self);
end;

procedure Tfmodifiacreedor.SpeedButton1Click(Sender: TObject);
begin
Tfgrupo.Create(self);
end;

procedure Tfmodifiacreedor.SpeedButton3Click(Sender: TObject);
begin
Tfciudades.Create(Self);
end;

procedure Tfmodifiacreedor.Enteratab(Sender: TObject; var Key: Char);
begin
if Key=#13 then
    begin
    Key:=#0;
    Perform(WM_NEXTDLGCTL,0,0);  //TabStop rule.
    end;
end;

end.


