unit formatos;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, Buttons, ExtCtrls,Checa, FileCtrl, ComCtrls, Grids, Calendar,Dialogos,describe;

type
  TFormaFormatos = class(TForm)
    Formatos: TPanel;
    Label1: TLabel;
    BitBtn3: TBitBtn;
    BotonEdicion: TBitBtn;
    Rangos: TPanel;
    BitBtn4: TBitBtn;
    BitBtn5: TBitBtn;
    Rutas: TEdit;
    Directorio: TDirectoryListBox;
    Bevel1: TBevel;
    Bevel2: TBevel;
    rutformato: TLabel;
    Bevel3: TBevel;
    BotonAceptar: TSpeedButton;
    Shape1: TShape;
    Panel1: TPanel;
    Bevel4: TBevel;
    Bevel5: TBevel;
    Bevel6: TBevel;
    Panel2: TPanel;
    Label6: TLabel;
    Calendario: TCalendar;
    CambiaMes: TUpDown;
    Fecha: TLabel;
    Condicion1: TComboBox;
    Condicion2: TComboBox;
    Condicion3: TComboBox;
    Operador1: TComboBox;
    Operador2: TComboBox;
    Operador3: TComboBox;
    Valor1: TComboBox;
    Valor2: TComboBox;
    Valor3: TComboBox;
    GroupBox1: TGroupBox;
    GroupBox2: TGroupBox;
    GroupBox3: TGroupBox;
    Incluir1: TCheckBox;
    Incluir2: TCheckBox;
    Incluir3: TCheckBox;
    C1: TLabel;
    C2: TLabel;
    C3: TLabel;
    T1: TLabel;
    T2: TLabel;
    T3: TLabel;
    De: TEdit;
    Inicial: TEdit;
    Final: TEdit;
    Hasta: TEdit;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    ArchivoLista: TFileListBox;
    Label7: TLabel;
    procedure BotonEdicionClick(Sender: TObject);
    procedure BitBtn4Click(Sender: TObject);
    procedure InicialExit(Sender: TObject);
    procedure FinalExit(Sender: TObject);
    procedure BitBtn3Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure RutasKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure FormActivate(Sender: TObject);
    procedure BotonAceptarClick(Sender: TObject);
    procedure DirectorioChange(Sender: TObject);
    procedure Panel2Click(Sender: TObject);
    procedure CalendarioClick(Sender: TObject);
    procedure InicialEnter(Sender: TObject);
    procedure FinalEnter(Sender: TObject);
    procedure CambiaMesClick(Sender: TObject; Button: TUDBtnType);
    procedure BitBtn5Click(Sender: TObject);
    procedure Condicion1Change(Sender: TObject);
    procedure Condicion2Change(Sender: TObject);
    procedure Condicion3Change(Sender: TObject);
    procedure Valor1Exit(Sender: TObject);
    procedure Valor2Exit(Sender: TObject);
    procedure Valor3Exit(Sender: TObject);
    procedure ArchivoListaDblClick(Sender: TObject);
    procedure BotonAceptarMouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure Condicion1KeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure Operador1KeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure Valor1KeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure InicialKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure FinalKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure DeKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure HastaKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure CalendarioKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure Panel1MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure Label7MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  FormaFormatos: TFormaFormatos;
  campos:array[1..30] of string[15];
  tipos:array[1..30] of string[15];
  meses:array[1..12] of String[15];


procedure activacondiciones(uno,dos,tres,cuatro,cinco,seis,siete,ocho,nueve:Boolean;archivo:string);
procedure valoresiniciales(inicio,fin,desde,hastavalor:string);
implementation

uses edicion;


{$R *.DFM}

procedure valoresiniciales(inicio,fin,desde,hastavalor:string);
begin
with FormaFormatos do
begin
Inicial.Text:=inicio;
Final.Text:=fin;
De.Text:=desde;
Hasta.Text:=hastavalor;

end;
end;

procedure leearchivocampos(archivo:string);
{type
datoscampo=record
campo:String[12];
descripcion:String[40];
tipo:String[12];
longitud:Integer;
end;}

var
{dat:datoscampo;
arch:file of datoscampo;}
i,conta,inicio,fin:integer;

begin
With FormaFormatos do
begin

if archivo='clientes.cmp' then
begin
inicio:=1;
fin:=18;
end;

if archivo='proveedo.cmp' then
begin
inicio:=47;
fin:=61;

end;

if archivo='vendedor.cmp' then
begin
inicio:=31;
fin:=34;

end;

if archivo='facturae.cmp' then
begin
inicio:=74;
fin:=101;

end;

if archivo='comprase.cmp' then
begin
inicio:=135;
fin:=151;

end;

if archivo='cxp.cmp' then
begin
inicio:=295;
fin:=306;

end;

if archivo='cxc.cmp' then
begin
inicio:=268;
fin:=280;

end;


if archivo='inventar.cmp' then
begin
inicio:=228;
fin:=255;

end;
if archivo='movinven.cmp' then
begin
inicio:=185;
fin:=196;

end;


{if FileExists(leeruta+'\consulta\'+archivo) then
begin}
{AssignFile (arch,leeruta+'\consulta\'+archivo);
Reset(arch);}
Condicion1.Clear;
Condicion2.Clear;
Condicion3.Clear;
Valor1.Text:='';
Valor2.Text:='';
Valor3.Text:='';

C1.Caption:='';C2.Caption:='';C3.Caption:='';
T1.Caption:='';T2.Caption:='';T3.Caption:='';

conta:=0;
for i:=inicio to Fin do
begin
if (leecampos(i,2)<>'')and (leecampos(i,2)<>'No Disponible') then
begin
Condicion1.Items.Add(leecampos(i,2));
Condicion2.Items.Add(leecampos(i,2));
Condicion3.Items.Add(leecampos(i,2));
campos[conta+1]:=leecampos(i,1);
tipos[conta+1]:=leecampos(i,3);
conta:=conta+1;
end;

end;

end;

end;



procedure activacondiciones(uno,dos,tres,cuatro,cinco,seis,siete,ocho,nueve:Boolean;archivo:string);
begin
With FormaFormatos do
begin
Inicial.Enabled:=uno;
Final.Enabled:=uno;

De.Enabled:=dos;
Hasta.Enabled:=dos;

Incluir1.Enabled:=tres;
Incluir2.Enabled:=cuatro;
Incluir3.Enabled:=cinco;

Condicion1.Enabled:=seis;
Condicion2.Enabled:=seis;
Condicion3.Enabled:=seis;

leearchivocampos(archivo);

end;
end;


procedure TFormaFormatos.BotonEdicionClick(Sender: TObject);
begin

if Tag<>3 then
begin
FormaEdicion.AbreFormato.InitialDir:=Rutas.Text;

{activadiseno;}
{FormaEdicion.Hoja.Visible:=False;}
FormaEdicion.Hoja.Tag:=1;
FormaEdicion.ShowModal;
FormaEdicion.Hoja.Tag:=0;
{FormaEdicion.ShowModal;}
end;
Tag:=1;

Close;

end;


procedure TFormaFormatos.BitBtn4Click(Sender: TObject);
begin
if Condicion1.Text='' then T1.Caption:='';
if Condicion2.Text='' then T2.Caption:='';
if Condicion3.Text='' then T3.Caption:='';

Formaformatos.Tag:=1;
Close;
end;


procedure TFormaFormatos.InicialExit(Sender: TObject);
begin
if not fechavalida(Inicial.Text) then
Inicial.Text:='';

end;

procedure TFormaFormatos.FinalExit(Sender: TObject);
begin
if not fechavalida(Final.Text) then
Final.Text:='';

end;

procedure TFormaFormatos.BitBtn3Click(Sender: TObject);
begin
Tag:=2;
Close;
end;


procedure TFormaFormatos.FormCreate(Sender: TObject);
begin
Rutas.Text:=leeruta+'\consulta\';
meses[1]:='Enero';meses[2]:='Febrero';meses[3]:='Marzo';meses[4]:='Abril';meses[5]:='Mayo';meses[6]:='Junio';
meses[7]:='Julio';meses[8]:='Agosto';meses[9]:='Septiembre';meses[10]:='Octubre';meses[11]:='Noviembre';meses[12]:='Diciembre';

end;

procedure TFormaFormatos.RutasKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
if Ord(Char(key))=13 then
Directorio.Directory:=Rutas.Text;
end;

procedure TFormaFormatos.FormActivate(Sender: TObject);
begin
Rutas.Text:=rutformato.Caption;
{De.Clear;
Hasta.Clear;
Inicial.Clear;
Final.Clear;}
CambiaMes.Position:=Calendario.Month;
Fecha.Caption:=meses[CambiaMes.Position];
Operador1.Text:='=';
Operador2.Text:='=';
Operador3.Text:='=';
end;

procedure TFormaFormatos.BotonAceptarClick(Sender: TObject);
begin
Tag:=3;
{Directorio.Directory:=Rutas.Text;}
Close;
end;

procedure TFormaFormatos.DirectorioChange(Sender: TObject);
begin
Rutas.Text:=Directorio.Directory;
ArchivoLista.Directory:=Directorio.Directory;
end;




procedure TFormaFormatos.Panel2Click(Sender: TObject);
begin
Close;
end;

procedure TFormaFormatos.CalendarioClick(Sender: TObject);
begin
if Inicial.Tag=1 then
Inicial.Text:=DateTimeToStr(Calendario.CalendarDate);

if Final.Tag=1 then
Final.Text:=DateTimeToStr(Calendario.CalendarDate);

end;

procedure TFormaFormatos.InicialEnter(Sender: TObject);
begin
Inicial.Tag:=1;
Final.Tag:=0;
end;

procedure TFormaFormatos.FinalEnter(Sender: TObject);
begin
Inicial.Tag:=0;
Final.Tag:=1;
end;

procedure TFormaFormatos.CambiaMesClick(Sender: TObject;
  Button: TUDBtnType);
begin
Calendario.Month:=CambiaMes.Position;
Fecha.Caption:=meses[CambiaMes.Position];
end;

procedure TFormaFormatos.BitBtn5Click(Sender: TObject);
begin
Formaformatos.Tag:=0;
Close;
end;


procedure TFormaFormatos.Condicion1Change(Sender: TObject);
begin
C1.Caption:=Campos[Condicion1.ItemIndex+1];
T1.Caption:=Tipos[Condicion1.ItemIndex+1];
end;

procedure TFormaFormatos.Condicion2Change(Sender: TObject);
begin
C2.Caption:=Campos[Condicion2.ItemIndex+1];
T2.Caption:=Tipos[Condicion2.ItemIndex+1];
end;

procedure TFormaFormatos.Condicion3Change(Sender: TObject);
begin
C3.Caption:=Campos[Condicion3.ItemIndex+1];
T3.Caption:=Tipos[Condicion3.ItemIndex+1];
end;

procedure TFormaFormatos.Valor1Exit(Sender: TObject);
begin
if T1.Caption='ftFloat' then
begin
if not flotantevalido(Valor1.Text) then
begin
MuestraMensaje('Solo se Aceptan Valores Numéricos');
Valor1.SetFocus;
end;
end;

if T1.Caption='ftInteger' then
begin
if not enterovalido(Valor1.Text) then
begin
MuestraMensaje('Solo se Aceptan Valores Numéricos');
Valor1.SetFocus;
end;
end;

if T1.Caption='ftDate' then
begin
if not fechavalida(Valor1.Text) then
begin
MuestraMensaje('Solo se Aceptan Valores de Fecha');
Valor1.SetFocus;
end;
end;


end;

procedure TFormaFormatos.Valor2Exit(Sender: TObject);
begin
if T2.Caption='ftFloat' then
begin
if not flotantevalido(Valor2.Text) then
begin
MuestraMensaje('Solo se Aceptan Valores Numéricos');
Valor2.SetFocus;
end;
end;

if T2.Caption='ftInteger' then
begin
if not enterovalido(Valor2.Text) then
begin
MuestraMensaje('Solo se Aceptan Valores Numéricos Enteros');
Valor2.SetFocus;
end;
end;

if T2.Caption='ftDate' then
begin
if not fechavalida(Valor2.Text) then
begin
MuestraMensaje('Solo se Aceptan Valores de Fecha');
Valor2.SetFocus;
end;
end;


end;

procedure TFormaFormatos.Valor3Exit(Sender: TObject);
begin
if T3.Caption='ftFloat' then
begin
if not flotantevalido(Valor3.Text) then
begin
MuestraMensaje('Solo se Aceptan Valores Numéricos');
Valor3.SetFocus;
end;
end;

if T3.Caption='ftInteger' then
begin

if not enterovalido(Valor3.Text) then
begin
MuestraMensaje('Solo se Aceptan Valores Numéricos Enteros');
Valor3.SetFocus;
end;
end;

if T3.Caption='ftDate' then
begin
if not fechavalida(Valor3.Text) then
begin
MuestraMensaje('Solo se Aceptan Valores de Fecha');
Valor3.SetFocus;
end;
end;


end;








procedure TFormaFormatos.ArchivoListaDblClick(Sender: TObject);
begin
Rutas.Text:=ArchivoLista.FileName;
end;

procedure TFormaFormatos.BotonAceptarMouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
describir(Button,FormaFormatos.Left+BotonAceptar.Left,FormaFormatos.Top+BotonAceptar.Top+BotonAceptar.Height,88);
end;

procedure TFormaFormatos.Condicion1KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
if Key=112 then
describir(mbRight,FormaFormatos.Left+Condicion1.Left,FormaFormatos.Top+Condicion1.Top+Condicion1.Height,102);
end;

procedure TFormaFormatos.Operador1KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
if Key=112 then
describir(mbRight,FormaFormatos.Left+Operador1.Left,FormaFormatos.Top+Operador1.Top+Operador1.Height,103);
end;

procedure TFormaFormatos.Valor1KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
if Key=112 then
describir(mbRight,FormaFormatos.Left+Valor1.Left,FormaFormatos.Top+Valor1.Top+Valor1.Height,104);
end;

procedure TFormaFormatos.InicialKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
if Key=112 then
describir(mbRight,FormaFormatos.Left+Inicial.Left,FormaFormatos.Top+Inicial.Top+Inicial.Height,105);
end;

procedure TFormaFormatos.FinalKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
if Key=112 then
describir(mbRight,FormaFormatos.Left+Condicion1.Left,FormaFormatos.Top+Condicion1.Top+Condicion1.Height,106);
end;

procedure TFormaFormatos.DeKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
if Key=112 then
describir(mbRight,FormaFormatos.Left+De.Left,FormaFormatos.Top+De.Top+De.Height,107);
end;

procedure TFormaFormatos.HastaKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
if Key=112 then
describir(mbRight,FormaFormatos.Left+Hasta.Left,FormaFormatos.Top+Hasta.Top+Hasta.Height,108);
end;

procedure TFormaFormatos.CalendarioKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
if Key=112 then
describir(mbRight,FormaFormatos.Left+Calendario.Left,FormaFormatos.Top+Calendario.Top+Calendario.Height,109);
end;

procedure TFormaFormatos.Panel1MouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
ReleaseCapture;
SendMessage(FormaFormatos.Handle, WM_SYSCOMMAND, $F012, 0);

end;

procedure TFormaFormatos.Label7MouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
ReleaseCapture;
SendMessage(FormaFormatos.Handle, WM_SYSCOMMAND, $F012, 0);
end;

end.
