unit UElegirArch;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Data.DB, Data.Win.ADODB, Vcl.StdCtrls,
  Vcl.Buttons ;

type
  TFElegirArch = class(TForm)
    ComboBox1: TComboBox;
    Memo1: TMemo;
    BitBtn1: TBitBtn;
    BitBtn2: TBitBtn;
    Pruebas: TADOQuery;
    procedure BitBtn1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  FElegirArch: TFElegirArch;

implementation

{$R *.dfm}

uses UImportarSiri, Uconexion, Udm;

Function Existe(Consulta: TADOQuery; curp: string): integer;
  var
    cade, para: string;
 begin
   para:= chr(39) + curp + chr(39);
   cade:= 'Select IdEmpleado from Empleados where Curp = ' + para + ' or Curp_2 = ' + para;
   //showmessage(cade);
   with Consulta do
    begin
      active:= false;
      sql.Clear;
      sql.Add(cade);
      active:= true;
      result:= fieldbyname('IdEmpleado').AsInteger;
    end;
 end;


procedure TFElegirArch.BitBtn1Click(Sender: TObject);
 var
   enco: integer;
begin
with FImportarSiri do
 begin
   Timporta.Active:=false;
   //Timporta.Connection:= ADOConnection1;
   Timporta.TableName:= FElegirArch.Combobox1.Text;
   Timporta.Active:=true;
   //showmessage('¡Conectado!');
   TImporta.First;
   TNodos.Active:= false;
   TNodos.Active:= true;
   Screen.Cursor:= CrHourGlass;
  while not(Timporta.Eof) do
    begin
       enco := Existe(pruebas, Timporta.Fields.FieldByNumber(1).Asstring);
       if (enco > 0) then
       begin
        TNodos.Locate('IdEmpleado',enco,[]);
        TNodos.edit;
        //TNodos.FieldByName('NumEmp').AsString:=  ObtenerNumEmp(pruebas,Timporta.Fields.FieldByNumber(1).Asstring);
        TNodos.FieldByName('Fecha_nac').AsDateTime:=  Timporta.FieldByName('Fecha_nac').AsDateTime;
        TNodos.FieldByName('Entidad_Nac').AsInteger:=  Timporta.FieldByName('Entidad_Nac').AsInteger;
        TNodos.FieldByName('EdoCivil').AsString:=  Timporta.FieldByName('EdoCivil').AsString;
        TNodos.FieldByName('Sexo').AsString:=  Timporta.FieldByName('Sexo').AsString;
        TNodos.FieldByName('Domicilio').AsString:=  Timporta.FieldByName('Domicilio').AsString;
        TNodos.FieldByName('Colonia').AsString:=  Timporta.FieldByName('Colonia').AsString;
        TNodos.FieldByName('Poblacion').AsString:=  Timporta.FieldByName('Poblacion').AsString;
        TNodos.FieldByName('CodPos').AsString:=  Timporta.FieldByName('CodPos').AsString;
        TNodos.FieldByName('Entidad').AsInteger:=  Timporta.FieldByName('Entidad').AsInteger;
        TNodos.FieldByName('Nombramiento').AsInteger:=  Timporta.FieldByName('Nombramiento').AsInteger;
        TNodos.FieldByName('RegAfore').AsInteger:=  Timporta.FieldByName('RegAfore').AsInteger;
        TNodos.FieldByName('FechaIngreso').AsDateTime:=  Timporta.FieldByName('FechaIngreso').AsDateTime;
        TNodos.FieldByName('FechaCot').AsDateTime:=  Timporta.FieldByName('FechaCot').AsDateTime;
        TNodos.FieldByName('CredFov').AsInteger:=  Timporta.FieldByName('CredFov').AsInteger;
        TNodos.FieldByName('DiasCot').AsString:=  Timporta.FieldByName('DiasCot').AsString;
        TNodos.FieldByName('DiasInc').AsString:=  Timporta.FieldByName('DiasInc').AsString;
        TNodos.FieldByName('DiasAus').AsString:=  Timporta.FieldByName('DiasAus').AsString;
        TNodos.FieldByName('SueldoBasCot').AsCurrency:=  Timporta.FieldByName('SueldoBasCot').AsFloat;
        TNodos.FieldByName('SueldoRCV').AsCurrency:=  Timporta.FieldByName('SueldoRCV').AsFloat;
        TNodos.FieldByName('SueldoViv').AsCurrency:=  Timporta.FieldByName('SueldoRCV').AsFloat;
        TNodos.FieldByName('AhorroSol').AsInteger:=  Timporta.FieldByName('AhorroSol').AsInteger;
        TNodos.FieldByName('ImpAhoSol').AsCurrency:=  Timporta.FieldByName('ImpAhoSol').AsFloat;
        TNodos.Post;
       end
       else
        FElegirArch.memo1.Lines.Add(Timporta.Fields.FieldByNumber(1).Asstring);
       TImporta.Next;
      end;

   TNodos.Active:= false;
  TNodos.Active:= true;
  end;
  bitbtn1.Enabled:=true;
  Screen.Cursor:= CrDefault;
  messagedlg('Importación terminada',mtinformation,[mbok],0);
end;

end.
