martes, 29 de diciembre de 2009

comprobar que un textbox sea numero isnum

function IsStrANumber(NumStr : string) : bool;


//***********************
function IsStrANumber(NumStr : string) : bool;
begin
result := true;

try
StrToInt(NumStr);
except
result := false;
end;

end;
//****



if IsStrANumber(edit2.Text)=false then
begin
showmessage('El campo UNIDADES debe de ser un número.');
exit;
end;




.

crear un TDBText dinamico dinamicamente

var
fechaSalida: TDBText;

(...)

fechaSalida:= TDBText.Create(Self);
fechaSalida.DataField:='fechaSalida';
fechaSalida.DataSource:=DataSource3;

domingo, 27 de diciembre de 2009

sumar tiempo sumar horas en SQL Paradox 7

(...)

var
resumen: Tform1;
function sumahoras(hora1: ttime; hora2: ttime): string;

implementation

{$R *.dfm}

(...)


//

function sumahoras(hora1: ttime; hora2: ttime): string;
var
h1,h2,m1,m2,s1,s2: integer;
h,m,s: integer;
aux, horaFinal: string;
begin


//**** hora 1
aux:= timetostr(hora1);

if (length(timetostr(hora1))=7) then
begin
aux:='0';
aux:=aux + timetostr(hora1);
end;

h1:= strtoint(aux[1]+aux[2]);
m1:= strtoint(aux[4]+aux[5]);
s1:= strtoint(aux[7]+aux[8]);

//**** hora 2
aux:= timetostr(hora2);

if (length(timetostr(hora2))=7) then
begin
aux:='0';
aux:=aux + timetostr(hora2);
end;


h2:= strtoint(aux[1]+aux[2]);
m2:= strtoint(aux[4]+aux[5]);
s2:= strtoint(aux[7]+aux[8]);

//

if ((s1+s2) > 59) then
begin
m1:=m1+1;
s:= (s1+s2) - 60;
end
else
begin
s:= (s1+s2);
end;


//

if ((m1+m2) > 59) then
begin
h1:=h1+1;
m:= (m1+m2) - 60;
end
else
begin
m:= (m1+m2);
end;

//

h:=h1+h2;


horaFinal:='00:00:00';
aux:=inttostr(s);

if (length(aux)<2) then
begin
horaFinal[7]:='0';
horaFinal[8]:=aux[1];
end
else
begin
horaFinal[7]:=aux[1];
horaFinal[8]:=aux[2];
end;

aux:=inttostr(m);

if (length(aux)<2) then
begin
horaFinal[4]:='0';
horaFinal[5]:=aux[1];
end
else
begin
horaFinal[4]:=aux[1];
horaFinal[5]:=aux[2];
end;


aux:=inttostr(h);

if (length(aux)<2) then
begin
horaFinal[1]:='0';
horaFinal[2]:=aux[1];
end
else
begin
horaFinal[1]:=aux[1];
horaFinal[2]:=aux[2];
end;

sumahoras:= horaFinal;

end;


//

//** ejemplo de llamada en una QUERY
//


(...)

aux:='select * from almuerzos where almuerzoFechaEntrada is not null and almuerzoFechaSalida >= :fechaD and almuerzoFechaSalida<= :fechaH and almuerzoEmpleado = ' + empleadoID ;

qAlmuerzos.close;
qAlmuerzos.SQL.Clear;
qAlmuerzos.SQL.add(aux);

qAlmuerzos.ParamByName('fechaD').DataType:= ftDate;
qAlmuerzos.ParamByName('fechaD').Value:= DateTimePicker1.Date;

qAlmuerzos.ParamByName('fechaH').DataType:= ftDate;
qAlmuerzos.ParamByName('fechaH').Value:= DateTimePicker2.Date;

qAlmuerzos.Active:=true;

qAlmuerzos.First;
totalTiempoAlmuerzo:= '00:00:00';
for i:=0 to qAlmuerzos.RecordCount-1 do
begin
totalTiempoAlmuerzo:= (sumahoras(strtotime(totalTiempoAlmuerzo), qAlmuerzos.Fieldvalues['almuerzoTotalTiempo']));
qAlmuerzos.next;
end;

(...)

Mensaje YES NO por defecto el NO

if Application.MessageBox(PChar(‘¿Te vas a casa?’), PChar(‘Confirmar’), MB_YESNO or MB_DEFBUTTON2 or MB_ICONQUESTION) = IDNO then
begin
// lo que sea
end;