I'm trying to use the DBGrid to show and add records to my table. In my table I store the information: (the data is in an AS400/iSeries DB2 database. When the court first started using this back in the day, there wasn't (or they didn't use) the date/time field types. The date is a string and the times are integers. I have a routines that convert the string to a date format and the times from integers to time formats)
JURNUM SERVDAT TIMETYPE TIMEIN TIMEOUT
12345 20040601 ORIENT 830 1230
12345 20040602 DLYPNL 930 1100
12345 20040603 DLYPNL 1400 0
(the 0 in time out indicates that there is no time out for that day yet)
My query has a calculated field to determine the amount of time worked. If there is no time out for the day it enters ' - ' for the time out and '??' for the TotalTime. If there is a time out for the day it shows the time.
Here's the calculated field code:
In my DBGrid I have GetText functions that convert the date and time:
So now in my DBGrid I have:
Works marvelously!
Here's the problem. When I arrow down to a new record, even if I don't enter anything, the record is posted to the database with the JURNUM, a blank SERVDAT and 0 for the times. How do I prevent the new record from being posted if it doesn't have all the information in it? When I arrow down I get:
and the last entry gets posted to the database! How can I stop it?
Also, how can I default the new record's SERVDAT field to today's date?
Leslie
JURNUM SERVDAT TIMETYPE TIMEIN TIMEOUT
12345 20040601 ORIENT 830 1230
12345 20040602 DLYPNL 930 1100
12345 20040603 DLYPNL 1400 0
(the 0 in time out indicates that there is no time out for that day yet)
My query has a calculated field to determine the amount of time worked. If there is no time out for the day it enters ' - ' for the time out and '??' for the TotalTime. If there is a time out for the day it shows the time.
Here's the calculated field code:
Code:
procedure TfrmJurorInformation.qryJurorHoursCalcFields(DataSet: TDataSet);
begin
if qryJurorHours.FieldByName('TIMEOUT').AsInteger <> 0 then
qryJurorHours.FieldByName('TotalTime').Value := FloatToStr((MinuteSpan(IntToTime(qryJurorHours.FieldByName('TimeIn').AsInteger), IntToTime(qryJurorHours.FIeldByName('TimeOut').AsInteger)))/60)
else
qryJurorHours.FieldByName('TotalTime').Value := '??';
end;
In my DBGrid I have GetText functions that convert the date and time:
Code:
procedure TfrmJurorInformation.qryJurorHoursSERVDATGetText(Sender: TField;
var Text: String; DisplayText: Boolean);
begin
if not VarIsNull(sender.Value) then
Text := convertdate(Sender.Value);
end;
procedure TfrmJurorInformation.qryJurorHoursTIMEINGetText(Sender: TField;
var Text: String; DisplayText: Boolean);
begin
if not VarIsNull(sender.Value) then
if sender.Value <> 0 then
Text := FormatDateTime('h:mm AM/PM', IntToTime(StrToInt(Sender.Value)))
else
Text := '-';
end;
So now in my DBGrid I have:
Code:
06/01/2004 ORIENT 8:30 am 12:30 am 4.0
06/02/2004 DLYPNL 9:30 am 11:00 am 1.5
06/03/2004 DLYPNL 2:00 pm - ??
Works marvelously!
Here's the problem. When I arrow down to a new record, even if I don't enter anything, the record is posted to the database with the JURNUM, a blank SERVDAT and 0 for the times. How do I prevent the new record from being posted if it doesn't have all the information in it? When I arrow down I get:
Code:
06/01/2004 ORIENT 8:30 am 12:30 am 4.0
06/02/2004 DLYPNL 9:30 am 11:00 am 1.5
06/03/2004 DLYPNL 2:00 pm - ??
// - - ??
and the last entry gets posted to the database! How can I stop it?
Also, how can I default the new record's SERVDAT field to today's date?
Leslie