Hi sparrow,
.
Thanks for responding. Sorry for not being more specific in my last post.
.
There are two cases for creating attendance records:
1. A single employee with one or multiple dates
2. A group of employees with a single date (filtered by Department)
.
Everything is working fine so far. But I'm attempting to check for duplicates prior to creating any records when it applies to multiple employees.
.
This is declaration and field checking portion:
procedure frmAtt_Button2_OnClick (Sender: TObject; var Cancel: boolean);
var
i, j : integer;
isDuplicate : boolean;
begin
// Check that the attendance code has been selected
if frmAtt.ComboBox1.Text = '' then
begin
ShowHint(frmAtt.ComboBox1,'This field is required. Please enter a value for the field.');
Exit;
end;
Looping through each employee that has been filtered (in the tableGrid)
for i := 0 to frmmain.tablegrid1.rowcount -1 do
begin
isDuplicate := False;
Now I'm attempting to check all attendance records for each employee's for duplicate fields
for j := 0 to SQLExecute('SELECT count(*) FROM attendance WHERE id_employee = '+inttostr(frmmain.tablegrid1.dbindextoid(i))) do
begin
This is where I get lost because I'm not sure how to construct a query that will pull out the pieces for each attendance record. Because any query that I can come up with returns all the results at once. I don't know how to control this. And the ID's don't match the loop counter either, so it's hard to specify which record to use for testing. And I don't know how to control the flow from SQL.
// This doesn't work, but it's an example of the pieces that I need to test against on the entry form.
//if (SQLExecute('SELECT aDate, id_attCode FROM attendance WHERE id_employee = '+inttostr(frmmain.tablegrid1.dbindextoid(i))) = frmAtt.dtpDate.sqlDate) then
// How to check for duplicates on frmAtt.dtpDate, frmAtt.tbAttCode
// IF THEY EXIST, SIMPLY SKIP THEM...
// isDuplicate := True;
end;
After testing for duplicates, then insert the new fields ONLY if none of them were duplicated
if not isDuplicate then
//SQLExecute('INSERT INTO attendance (aDate, aTime, aTime2, attNote, id_attCode, id_employee) VALUES('+frmAtt.dtpDate.sqlDate+', '+frmAtt.dtpTime.sqlTime+', '+frmAtt.dtpTime2.sqlTime+', "'+frmAtt.Memo1.Text+'", "'+frmAtt.tbAttCode.Text+'", "'+inttostr(frmmain.tablegrid1.dbindextoid(i))+'")');
end;
frmAtt.Close;
frmEmp.TableGrid1.dbUpdate;
end;
.
I've created a loop inside a loop to filter (and test) each attendance record for each employee in the group (tableGrid list). At least that's the idea. It might not be the ideal way for doing this in MVD. So this is where I'm getting stuck.
.
This is a bit fragmented, but it's hard to highlight code sections unless I just rely on comments.
.
Many thanks!