1 (edited by prahousefamily 2016-07-06 03:36:10)

Topic: Show PNG In TableGrid And Text Color Fix

Example Easy Code

-Create Table By Script SQLITE
-Add Time Auto Insert Data into table
-Even Table Grid Change Text Color And Add image .PNG
-IF Else Syntax

https://i.imgsafe.org/c78a172a66.png
Show Code

var
Timer: TTimer;
iSeconds: integer;

procedure Form1_Button1_OnClick (Sender: string; var Cancel: boolean);
begin
    Form1.TableGrid1.dbSQL := (
    ' SELECT update_log.pc_id,update_log.serial_id,update_log.date_login, '+
    ' update_log.count_in_date,update_log.status_id,update_log.log_datetime '+
    ' FROM update_log GROUP BY update_log.pc_id,update_log.serial_id, '+
    ' update_log.date_login,update_log.count_in_date,update_log.status_id '+
    ' ORDER BY update_log.pc_id,update_log.serial_id,update_log.date_login, '+
    ' update_log.count_in_date,update_log.log_datetime '
    );
    Form1.TableGrid1.dbSQLExecute ;
end;

//TableGrid Color
procedure Form1_TableGrid1_OnChange (Sender: string);
var
i,c: integer;
G: TGraphic;
sExt: string;
sFile: string;
begin
    Form1.TableGrid1.Columns.InsertGraphicColumn(6);
    c := Form1.TableGrid1.RowCount - 1;
    for i := 0 to c do
    if Form1.TableGrid1.Cells[4,i] = 'Start' then
    begin
        Form1.TableGrid1.Cell[4,i].TextColor := clNavy;
        begin
            sFile := ExtractFileDir(Application.ExeName) + '\Status\bullet_blue.png';
            sExt := ExtractFileExt(sFile);
            sExt := LowerCase(sExt);
            G := TPngImage.Create;
            G.LoadFromFile(sFile);
            Form1.TableGrid1.Cell[6, i].ObjectReference := G; //Graphic Column, index of column is 1
        end;
    end
    else if Form1.TableGrid1.Cells[4,i] = 'Process' then
    begin
        Form1.TableGrid1.Cell[4,i].TextColor := clGreen;
        begin
            sFile := ExtractFileDir(Application.ExeName) + '\Status\bullet_green.png';
            sExt := ExtractFileExt(sFile);
            sExt := LowerCase(sExt);
            G := TPngImage.Create;
            G.LoadFromFile(sFile);
            Form1.TableGrid1.Cell[6, i].ObjectReference := G; //Graphic Column, index of column is 1
        end;
    end
    else if Form1.TableGrid1.Cells[4,i] = 'Close' then
    begin
        Form1.TableGrid1.Cell[4,i].TextColor := clRed;
        begin
            sFile := ExtractFileDir(Application.ExeName) + '\Status\bullet_red.png';
            sExt := ExtractFileExt(sFile);
            sExt := LowerCase(sExt);
            G := TPngImage.Create;
            G.LoadFromFile(sFile);
            Form1.TableGrid1.Cell[6, i].ObjectReference := G; //Graphic Column, index of column is 1
        end;
    end ;
end;
//Form1 Close insert data
procedure Form1_OnClose (Sender: string; Action: string);
var
pc_id,serial_id,date_login,status_id : string ;
count_in_date,log_datetime :string ;
begin
    pc_id := Form1.Edit1.Text ;
    serial_id := Form1.Edit2.Text ;
    date_login  := Form1.Edit3.Text ;
    count_in_date := Form1.Edit4.Text ;
    status_id := 'Close';
    log_datetime := SQLExecute('select datetime("now")||".000"');
    SQLExecute(
    ' insert into update_log (pc_id,serial_id,date_login,count_in_date,status_id,log_datetime)'+
    ' values("'+pc_id+'","'+serial_id+'","'+date_login+'","'+count_in_date+'","'+status_id+'","'+log_datetime+'")');
    Timer.Free;
end;
//TimeRun insert data
procedure OnTimer;
var
pc_id,serial_id,date_login,status_id : string ;
count_in_date,log_datetime :string ;
begin
    pc_id := Form1.Edit1.Text ;
    serial_id := Form1.Edit2.Text ;
    date_login  := Form1.Edit3.Text ;
    count_in_date := Form1.Edit4.Text ;
    status_id := 'Process';
    log_datetime := SQLExecute('select datetime("now")||".000"');
    iSeconds := iSeconds + 1;
    if
    iSeconds > 1
    then // Insert every 1 seconds
    begin
        iSeconds := 0;
        SQLExecute(
        ' insert into update_log (pc_id,serial_id,date_login,count_in_date,status_id,log_datetime)'+
        ' values("'+pc_id+'","'+serial_id+'","'+date_login+'","'+count_in_date+'","'+status_id+'","'+log_datetime+'")');
    end;
end;
//Form1 Show insert data
procedure Form1_OnShow (Sender: string; Action: string);
var
pc_id,serial_id,date_login,status_id : string ;
count_in_date,log_datetime :string ;
begin
    Form1.TableGrid1.HeaderSize := 30 ;
    Form1.TableGrid1.RowSize := 64;
    pc_id := GetUserName ;
    serial_id := GetHardDiskSerial('c');
    date_login := SQLExecute('select date("now")');
    count_in_date :=SQLExecute(
    ' SELECT (case when max(update_log.count_in_date) is null or max(update_log.count_in_date) ="" then 0 else max(update_log.count_in_date) end)+1'+
    ' FROM update_log WHERE update_log.pc_id ="'+pc_id+'"'+
    ' and  serial_id ="'+serial_id+'"'+
    ' and  date_login ="'+date_login+'"'
    );
    status_id := 'Start';
    log_datetime := SQLExecute('select datetime("now")||".000"');
    SQLExecute(
    ' insert into update_log (pc_id,serial_id,date_login,count_in_date,status_id,log_datetime)'+
    ' values("'+pc_id+'","'+serial_id+'","'+date_login+'","'+count_in_date+'","'+status_id+'","'+log_datetime+'")');
    Timer := TTimer.Create (Form1);
    Timer.Interval := 1000;
    Timer.Enabled := True;
    Timer.OnTimer := @OnTimer;
    Form1.Edit1.Text := pc_id ;
    Form1.Edit2.Text := serial_id ;
    Form1.Edit3.Text := date_login ;
    Form1.Edit4.Text := count_in_date ;
    Form1.TableGrid1.dbSQL :=(
    ' SELECT update_log.pc_id,update_log.serial_id,update_log.date_login, '+
    ' update_log.count_in_date,update_log.status_id,update_log.log_datetime '+
    ' FROM update_log GROUP BY update_log.pc_id,update_log.serial_id, '+
    ' update_log.date_login,update_log.count_in_date,update_log.status_id '+
    ' ORDER BY update_log.pc_id,update_log.serial_id,update_log.date_login, '+
    ' update_log.count_in_date,update_log.log_datetime '
    );
    Form1.TableGrid1.dbSQLExecute ;
end;
begin
    //create table IF NOT EXISTS
    SQLExecute(
    'CREATE TABLE' +
    ' IF NOT EXISTS "update_log" (' +
    '    "pc_id" TEXT NOT NULL,' +
    '    "serial_id" TEXT NOT NULL,' +
    '    "date_login" TEXT NOT NULL,' +
    '    "count_in_date" INTEGER NOT NULL,' +
    '    "status_id" TEXT NOT NULL,' +
    '    "log_datetime" TEXT,' +
    '    PRIMARY KEY (' +
    '        "pc_id",' +
    '        "serial_id",' +
    '        "date_login",' +
    '        "count_in_date",' +
    '        "status_id"' +
    '    ),' +
    '    CONSTRAINT "uniq_update_log_00" UNIQUE (' +
    '        "pc_id" ASC,' +
    '        "serial_id" ASC,' +
    '        "date_login" ASC,' +
    '        "count_in_date" ASC,' +
    '        "status_id" ASC' +
    '    ) ON CONFLICT REPLACE' +
    ')'
    ) ;
end.
Post's attachments

Attachment icon UpdateLogFixed.zip 11.52 kb, 583 downloads since 2016-07-06 

My Visual Database : I Love You
Easy For Beginner Student For Me