Topic: Пожалуйста помогите script
нужен сценарий для сценария в 1, 2, оба работают в сценарии
script 1
procedure DBLog_TableGrid1_OnChange (Sender: string);
var
i,c: integer;
begin
c := DBLog.TableGrid1.RowCount - 1;
for i := 0 to c do
begin
if DBLog.TableGrid1.Cells[2,i] = 'on' then DBLog.TableGrid1.Cell[2,i].Color := clRed;
if DBLog.TableGrid1.Cells[2,i] = 'off' then DBLog.TableGrid1.Cell[2,i].Color := clGreen;
end;
end;
begin
end.
script 2
var
sUser: string = '';
procedure frmAddUser_edPassword_OnKeyUp (Sender: string; var Key: Word; Shift, Alt, Ctrl: boolean);
begin
frmAddUser.Edit1.Text:= StrToMD5(frmAddUser.edPassword.Text);
end;
procedure Form1_OnClose (Sender: string; Action: string);
begin
SQLExecute('INSERT INTO logs (user, action, datetime) VALUES ("'+sUser+'", "Exit", "'+ FormatDateTime('yyyy-MM-DD hh:mm:ss.000', now) +'"); ');
end;
// event OnShow
procedure Form1_OnShow (Sender: string; Action: string);
begin
frmLogin.edPassword.PasswordChar := '*';
frmLogin.ShowModal; // show windows for login
end;
procedure frmLogin_bLogin_OnClick (Sender: string; var Cancel: boolean);
var
sHash: string;
s: string;
begin
//
// SQL query get hash of password
sHash := VarToStr( SQLExecute('SELECT password FROM users WHERE (login = ''' + frmLogin.edUser.Text + ''');') );
// if the hash in the database = hash of entered a password
if sHash = StrToMD5(frmLogin.edPassword.Text) then//
begin
sUser := frmLogin.edUser.Text; // remember username
// check admin rights
s := VarToStr( SQLExecute('SELECT administrator FROM users WHERE (login = ''' + sUser + ''');') );
if s='0' then Form1.bUsers.Enabled := False; // if the user does not have administrator privileges, deactivate the button to create other users
// check permissions to read
s := VarToStr( SQLExecute('SELECT read FROM users WHERE (login = ''' + sUser + ''');') );
if s='0' then Form1.bEdit.Enabled := False; // deactivate the button to edit the record
// check write permissions
s := VarToStr( SQLExecute('SELECT write FROM users WHERE (login = ''' + sUser + ''');') );
if s='0' then
begin
DBadd.bEquip.Enabled := False; // deactivate the button to add the record
DBadd.bModel.Enabled := False; // deactivate the button to add the record
DBadd.bSerial.Enabled := False; // deactivate the button to add the record
DBadd.binv.Enabled := False; // deactivate the button to add the record
DBadd.bOK.Enabled := False; // deactivate the button to save the record
end;
// check permission to delete
s := VarToStr( SQLExecute('SELECT remove FROM users WHERE (login = ''' + sUser + ''');') );
if s='0' then Form1.bDelete.Enabled := False; // deactivate the button to delete the record
// check permission to delete
s := VarToStr( SQLExecute('SELECT remove FROM users WHERE (login = ''' + sUser + ''');') );
if s='0' then DBadd.bDelete.Enabled := False; // deactivate the button to delete the record
// check permission to search
s := VarToStr( SQLExecute('SELECT search FROM users WHERE (login = ''' + sUser + ''');') );
if s='0' then Form1.bSearch.Enabled := False; // deactivate the button to search the records
// logs
SQLExecute('INSERT INTO logs (user, action, datetime) VALUES ("'+sUser+'", "Enter", "'+ FormatDateTime('yyyy-MM-DD hh:mm:ss.000', now) +'"); ');
Logs.TableGrid1.dbUpdate;
frmLogin.Close; // close login form
end else MessageDlg('password is incorrect', mtError, mbOk, 0); // message if the password is incorrect
end;
// window closing event for login
procedure frmLogin_OnClose (Sender: string; Action: string);
begin
// if the user has not been defined, and the user closes the login window, then close the main form
if sUser='' then Form1.Close;
end;
begin
// Initial check whether there is a database administrator user
// if not, create an administrator with username admin and password admin
if VarToStr( SQLExecute('SELECT count(id) FROM users WHERE administrator=1;') ) = '0' then
begin
SQLExecute('INSERT INTO users (login, password, read, write, remove, search, administrator) VALUES ("admin", "21232F297A57A5A743894A0E4A801FC3", 1, 1, 1, 1, 1);');
frmLogin.edUser.Text := 'admin';
frmLogin.edPassword.Text := 'admin';
end;
frmLogin.bLogin.Default:= True;
end.