Skip to content

Commit

Permalink
small fix and improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
my-ijet committed Jan 16, 2023
1 parent 6126a73 commit 00350bc
Show file tree
Hide file tree
Showing 10 changed files with 123 additions and 54 deletions.
2 changes: 1 addition & 1 deletion Script/script.dcu

Large diffs are not rendered by default.

10 changes: 3 additions & 7 deletions Script/service.pas
Original file line number Diff line number Diff line change
Expand Up @@ -190,21 +190,17 @@ procedure Tarifikation_BtnDeleteUser_OnClick (Sender: TObject; var Cancel: boole
rowIndex : Integer;
DeleteSQL : String;
begin

for rowIndex:=0 to Tarifikation.TableUsers.RowCount - 1 do begin
tmpRow := Tarifikation.TableUsers.Row[rowIndex];
if tmpRow.Selected then
ShouldLogin := tmpRow.ID = Application.User.Id;
if tmpRow.Selected and (tmpRow.ID = Application.User.Id) then
ShouldLogin := True;
end;

DeleteRecordFromTable(Tarifikation.TableUsers);

DeleteSQL := 'delete from _user where id = '+IntToStr(Application.User.Id);
SQLExecute(DeleteSQL);

if ShouldLogin then begin
Application.User.Id := -1;
UserLogin;
UserLogin(False);
end;
end;

Expand Down
88 changes: 54 additions & 34 deletions Script/tarifikation.pas
Original file line number Diff line number Diff line change
Expand Up @@ -218,65 +218,85 @@ procedure Tarifikation_BtnDeleteTarJobDoplata_OnClick (Sender: TObject; var Canc
// Кнопки удаления на главной


// Показ кнопок добавления, редактирования и удаления на главной
procedure Tarifikation_TableTarOrganizations_OnMouseEnter (Sender: TObject);
// Логика показа кнопок добавления, редактирования и удаления
procedure Tarifikation_HideGroupsEditButtons;
begin
Tarifikation.GroupBtnTarOrganizations.Visible := True;

Tarifikation.GroupBtnTarOrganizations.Visible := False;
Tarifikation.GroupBtnTarifikaciya.Visible := False;
Tarifikation.GroupBtnTarJobs.Visible := False;
Tarifikation.GroupBtnTarNadbavky.Visible := False;
Tarifikation.GroupBtnTarJobDoblaty.Visible := False;

Tarifikation.GroupBtnUsers.Visible := False;
end;

procedure Tarifikation_TableTarifikaciya_OnMouseEnter (Sender: TObject);
procedure Tarifikation_BtnShowGroupBtnTarOrganizations_OnMouseEnter (Sender: TObject);
begin
Tarifikation.GroupBtnTarifikaciya.Visible := True;
Tarifikation_HideGroupsEditButtons;
Tarifikation.GroupBtnTarOrganizations.Visible := True;
end;

Tarifikation.GroupBtnTarOrganizations.Visible := False;
Tarifikation.GroupBtnTarJobs.Visible := False;
Tarifikation.GroupBtnTarNadbavky.Visible := False;
Tarifikation.GroupBtnTarJobDoblaty.Visible := False;
procedure Tarifikation_BtnShowGroupBtnTarifikaciya_OnMouseEnter (Sender: TObject);
begin
Tarifikation_HideGroupsEditButtons;
Tarifikation.GroupBtnTarifikaciya.Visible := True;
end;

procedure Tarifikation_TableTarJobs_OnMouseEnter (Sender: TObject);
procedure Tarifikation_BtnShowGroupBtnTarJobs_OnMouseEnter (Sender: TObject);
begin
Tarifikation_HideGroupsEditButtons;
Tarifikation.GroupBtnTarJobs.Visible := True;

Tarifikation.GroupBtnTarOrganizations.Visible := False;
Tarifikation.GroupBtnTarifikaciya.Visible := False;
Tarifikation.GroupBtnTarNadbavky.Visible := False;
Tarifikation.GroupBtnTarJobDoblaty.Visible := False;
end;

procedure Tarifikation_TableTarNadbavky_OnMouseEnter (Sender: TObject);
procedure Tarifikation_BtnShowGroupBtnTarNadbavky_OnMouseEnter (Sender: TObject);
begin
Tarifikation_HideGroupsEditButtons;
Tarifikation.GroupBtnTarNadbavky.Visible := True;

Tarifikation.GroupBtnTarOrganizations.Visible := False;
Tarifikation.GroupBtnTarifikaciya.Visible := False;
Tarifikation.GroupBtnTarJobs.Visible := False;
Tarifikation.GroupBtnTarJobDoblaty.Visible := False;
end;

procedure Tarifikation_TableTarJobDoblaty_OnMouseEnter (Sender: TObject);
procedure Tarifikation_BtnShowGroupBtnTarJobDoblaty_OnMouseEnter (Sender: TObject);
begin
Tarifikation_HideGroupsEditButtons;
Tarifikation.GroupBtnTarJobDoblaty.Visible := True;
end;

Tarifikation.GroupBtnTarOrganizations.Visible := False;
Tarifikation.GroupBtnTarifikaciya.Visible := False;
Tarifikation.GroupBtnTarJobs.Visible := False;
Tarifikation.GroupBtnTarNadbavky.Visible := False;
procedure Tarifikation_BtnShowGroupBtnUsers_OnMouseEnter (Sender: TObject);
begin
Tarifikation_HideGroupsEditButtons;
Tarifikation.GroupBtnUsers.Visible := True;
end;

procedure Tarifikation_OnMouseLeave (Sender: TObject);

procedure Tarifikation_TableTarOrganizations_OnMouseEnter (Sender: TObject);
begin
Tarifikation.GroupBtnTarOrganizations.Visible := False;
Tarifikation.GroupBtnTarifikaciya.Visible := False;
Tarifikation.GroupBtnTarJobs.Visible := False;
Tarifikation.GroupBtnTarNadbavky.Visible := False;
Tarifikation.GroupBtnTarJobDoblaty.Visible := False;
Tarifikation_HideGroupsEditButtons;
end;

procedure Tarifikation_TableTarifikaciya_OnMouseEnter (Sender: TObject);
begin
Tarifikation_HideGroupsEditButtons;
end;

procedure Tarifikation_TableTarJobs_OnMouseEnter (Sender: TObject);
begin
Tarifikation_HideGroupsEditButtons;
end;

procedure Tarifikation_TableTarNadbavky_OnMouseEnter (Sender: TObject);
begin
Tarifikation_HideGroupsEditButtons;
end;

procedure Tarifikation_TableTarJobDoblaty_OnMouseEnter (Sender: TObject);
begin
Tarifikation_HideGroupsEditButtons;
end;

procedure Tarifikation_TableUsers_OnMouseEnter (Sender: TObject);
begin
Tarifikation_HideGroupsEditButtons;
end;
// Логика показа кнопок добавления, редактирования и удаления

// Запуск всех фильтров на главной
procedure Tarifikation_FilterTarTables;
Expand Down Expand Up @@ -308,7 +328,7 @@ procedure Tarifikation_OnShow (Sender: TObject; Action: string);
Tarifikation.MainTabs.ActivePageIndex := 0;
Tarifikation_PrepareTarTables;

UserLogin;
UserLogin(True);

Tarifikation.Menu.Items.Remove(Tarifikation.mniAbout);
end;
Expand Down
47 changes: 40 additions & 7 deletions Script/users.pas
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,52 @@
mniUser: TMenuItem;
UserChanged : Boolean;

procedure SaveCurrentAppUser;
var
ini: TIniFile;
begin
ini := TiniFile.Create(Application.SettingsFile);
ini.WriteString('Settings', 'CurrentAppUserID', IntToStr(Application.User.Id));
ini.Free;
end;

function LoadCurrentAppUser: Integer;
var
ini: TIniFile;
UserID: String;
begin
ini := TiniFile.Create(Application.SettingsFile);
UserID := ini.ReadString('Settings', 'CurrentAppUserID', '-1');
Result := StrToInt(UserID);
ini.Free;
end;

// Переключение пользователя
procedure UserLogin;
procedure UserLogin(FromSettings: Boolean);
var
NumOfUsers : String;
SettingsUserID : Integer;
SettingsUserName : String;
begin
// TODO Загрузка из конфига пользователя
frmUserLogin.ListUsers.dbItemID := Application.User.Id;

// Если нет пользователей создаём стандартного и выходим
NumOfUsers := SQLExecute('select count(*) from _user');

if NumOfUsers = '0' then begin
ApplyFixesOnNewDatabase;
CreateDefaultUser;
UpdateDatabase('_user');
Exit;
end;

// Загрузка из конфига пользователя
if FromSettings then begin
SettingsUserID := LoadCurrentAppUser;
SettingsUserName := SQLExecute('select username from _user where id = '+IntToStr(SettingsUserID));
if SettingsUserName <> '' then begin
UpdateCurrentAppUser(SettingsUserID, SettingsUserName);
Exit;
end;
end;

// frmDbCoreLogin.ShowModal;
frmUserLogin.ShowModal;
end;
Expand All @@ -36,6 +65,9 @@ procedure UpdateCurrentAppUser(id: Integer; username: String);
mniUser.Caption := 'Пользователь: '+Application.User.Username;

FillRequisites;
UpdateDatabase('_user');

SaveCurrentAppUser;
end;

function GenerateUserPassword(username, password : String) : String;
Expand Down Expand Up @@ -64,13 +96,15 @@ procedure CreateDefaultUser;

procedure mniUser_OnClick (sender: string);
begin
UserLogin;
UserLogin(False);
end;

// Форма входа
procedure frmUserLogin_OnShow (Sender: TObject; Action: string);
begin
frmUserLogin.ListUsers.dbSQLExecute('select id, username from _user;');

frmUserLogin.ListUsers.dbItemID := Application.User.ID;
end;

procedure frmUserLogin_BtnOK_OnClick (Sender: TObject; var Cancel: boolean);
Expand Down Expand Up @@ -118,7 +152,6 @@ procedure frmEditUser_OnClose (Sender: TObject; Action: string);
// Редактирование пользователя

begin
// MessageDlg('Пользователь: '+IntToStr(Application.User.Id), mtInformation, mbOK, 0);
mniUser := TMenuItem.Create (Tarifikation);
mniUser.OnClick := @mniUser_OnClick;

Expand Down
Binary file modified forms.xml
Binary file not shown.
7 changes: 3 additions & 4 deletions import_from_foxpro/foxpro_tarifikation.pas
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ procedure ImportDbf(DbfFilePath : String);
i: Integer;
DbfFileName: String;
begin
Form1.MainConnection.ExecuteDirect('PRAGMA foreign_keys=OFF;');

DbfFileName := ExtractFileName(DbfFilePath);
Form1.FoxProDbf.FilePath := ExtractFileDir(DbfFilePath);
Form1.FoxProDbf.TableName := DbfFileName;
Expand All @@ -66,10 +64,11 @@ procedure ImportDbf(DbfFilePath : String);
'STAVKI.DBF': ImportStavka;
'SPRKAT.DBF': ImportKategories;

'T1_0109.DBF': ImportTarifikaciya; // TODOT Исправить, не универсально!
'T1_0109.DBF': ImportTarifikaciya; // TODOT Исправить
// Добавить для каждого T1_* импорт тарификации и
// для каждого T2_* импорт доп тар таблицы
end;

Form1.MainConnection.ExecuteDirect('PRAGMA foreign_keys=ON;');
Form1.FoxProDbf.Active := False;
end;

Expand Down
1 change: 1 addition & 0 deletions import_from_foxpro/main.lfm
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ object Form1: TForm1
OnDestroy = FormDestroy
OnShow = FormShow
Position = poDesktopCenter
LCLVersion = '2.3.0.0'
Visible = True
object Status: TLabel
AnchorSideLeft.Control = Owner
Expand Down
2 changes: 2 additions & 0 deletions import_from_foxpro/main.pas
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ procedure TForm1.Start;
if numOfFoundedFiles > 0 then begin
sql_commands.PrepareTables;

//MainConnection.ExecuteDirect('PRAGMA foreign_keys=OFF;');
for DbfFilePath in FoundDbfFiles do
begin
DbfFileName := ExtractFileName(DbfFilePath);
Expand All @@ -115,6 +116,7 @@ procedure TForm1.Start;

Dec(numOfFoundedFiles);
end;
//MainConnection.ExecuteDirect('PRAGMA foreign_keys=ON;');
Caption := 'Импорт данных FoxPro';

sql_commands.UpdateTables;
Expand Down
18 changes: 17 additions & 1 deletion import_from_foxpro/sql_commands.pas
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
interface

uses
Classes, SysUtils;
Classes, SysUtils, Dialogs;

procedure PrepareTables;
procedure UpdateTables;
Expand Down Expand Up @@ -89,7 +89,22 @@ procedure UpdateTables;
end;

procedure ClearTables;
var
numMissedTarOrgs: String;
begin
with Form1.QInsertFromFoxPro do begin
SQL.Text := '';
SQL.Append('select count(*) as num ');
SQL.Append('from tarifikaciya where id_organization = 0;');
Open;
numMissedTarOrgs := FieldByName('num').AsString;
Close;
end;
if numMissedTarOrgs <> '0' then
ShowMessage('Для '+numMissedTarOrgs+
' записей, организации в справочнике не найдены,'+LineEnding+
'они не будут импортированны!');

with Form1.SQL.Script do begin
Text := '';
AddText('alter table organization drop column FOXPRO_KOD;');
Expand Down Expand Up @@ -129,6 +144,7 @@ procedure ClearTables;
AddText('alter table tarifikaciya drop column FOXPRO_TABN;');
AddText('alter table tarifikaciya drop column FOXPRO_OBR;');

AddText('delete from tarifikaciya where id_organization = 0;');
end;
Form1.SQL.Execute;
end;
Expand Down
2 changes: 2 additions & 0 deletions settings.ini
Original file line number Diff line number Diff line change
Expand Up @@ -187,3 +187,5 @@ port=3306
username=
database=
savepassword=0
[Settings]
CurrentAppUserID=1

0 comments on commit 00350bc

Please sign in to comment.