root/trunk/DataModules/dm_user.pas

401465
1
(* *****************************************************************************
2
  *
3
  * MyHomeLib
4
  *
5
  * Copyright (C) 2008-2010 Aleksey Penkov
6
  *
7
  * Authors Aleksey Penkov   alex.penkov@gmail.com
8
  *         Nick Rymanov     nrymanov@gmail.com
9
  *
10
  * History
11
  * NickR 02.03.2010    Код переформатирован
  *
12
  ****************************************************************************** *)
1
13
2
{******************************************************************************}
3
{                                                                              }
4
{                                 MyHomeLib                                    }
5
{                                                                              }
6
{                                Version 0.9                                   }
7
{                                20.08.2008                                    }
8
{                    Copyright (c) Aleksey Penkov  alex.penkov@gmail.com       }
9
{                                                                              }
10
{******************************************************************************}
11
12
13
unit dm_user;
14
unit dm_user;
14
15
15
interface
16
interface
16
17
17
uses
18
uses
18
  SysUtils, Classes, DB, ABSMain, unit_globals, ImgList, Controls, unit_Consts;
19
  SysUtils,
20
  Classes,
21
  DB,
22
  ABSMain,
23
  unit_globals,
24
  ImgList,
25
  Controls,
26
  unit_Consts;
19
27
20
type
28
type
21
  TCollectionProp = (cpDisplayName, cpFileName, cpRootFolder);
29
  TCollectionProp = (cpDisplayName, cpFileName, cpRootFolder);
...
...
102
111
103
  private
112
  private
104
    FCollection: TMHLCollection;
113
    FCollection: TMHLCollection;
105
  public
106
    const
107
      INVALID_COLLECTION_ID = -1;
108
114
115
  public const
116
    INVALID_COLLECTION_ID = -1;
117
109
  public
118
  public
110
    constructor Create(AOwner: TComponent); override;
119
    constructor Create(AOwner: TComponent); override;
111
    destructor Destroy; override;
120
    destructor Destroy; override;
...
...
143
      const Value: string;
152
      const Value: string;
144
      IgnoreID: Integer = INVALID_COLLECTION_ID
153
      IgnoreID: Integer = INVALID_COLLECTION_ID
145
    ): Boolean;
154
    ): Boolean;
146
    procedure SetUserTableState(Status: boolean);
147
155
156
    procedure SetUserTableState(Status: Boolean);
148
157
149
  public
158
  public
150
    //
159
    //
151
    // Active Collection
160
    // Active Collection
152
    //
161
    //
153
    property ActiveCollection: TMHLCollection read FCollection;
162
    property ActiveCollection: TMHLCollection read FCollection;
154
    procedure SetTableState(State: boolean);
163
    procedure SetTableState(State: Boolean);
155
164
156
    function FindFirstExternalCollection: Boolean;
165
    function FindFirstExternalCollection: Boolean;
157
    function FindNextExternalCollection: Boolean;
166
    function FindNextExternalCollection: Boolean;
...
...
159
    function FindFirstCollection: Boolean;
168
    function FindFirstCollection: Boolean;
160
    function FindNextCollection: Boolean;
169
    function FindNextCollection: Boolean;
161
170
162
    function ActivateGroup(const ID: integer):boolean;
171
    function ActivateGroup(const ID: Integer): Boolean;
163
172
164
    procedure SetRate(ID,Rate: integer);
173
    procedure SetRate(ID, Rate: Integer);
165
     procedure SetLocal(ID: integer; Value: boolean);
174
    procedure SetLocal(ID: Integer; Value: Boolean);
166
    procedure SetFinished(ID, Progress: integer; ADBID: integer = 0);
175
    procedure SetFinished(ID, Progress: Integer; ADBID: Integer = 0);
167
    procedure DeleteRate(AID: integer; ADBID: integer = 0);
176
    procedure DeleteRate(AID: Integer; ADBID: Integer = 0);
168
    procedure DeleteFinished(AID: integer; ADBID: integer = 0);
177
    procedure DeleteFinished(AID: Integer; ADBID: Integer = 0);
169
    procedure InsertToGroupTable(ID : integer; Genre: string);
178
    procedure InsertToGroupTable(ID: Integer; Genre: string);
170
    procedure AddGroup(Name: string);
179
    procedure AddGroup(Name: string);
171
180
172
    procedure LoadRates(const SL: TStringList; var i: integer);
181
    procedure LoadRates(const SL: TStringList; var i: Integer);
173
    procedure LoadGroupedBooks(const SL: TStringList; var i: integer);
182
    procedure LoadGroupedBooks(const SL: TStringList; var i: Integer);
174
    procedure LoadFinished(const SL: TStringList; var i: integer);
183
    procedure LoadFinished(const SL: TStringList; var i: Integer);
175
    procedure LoadGroups(const SL: TStringList; var i: integer);
184
    procedure LoadGroups(const SL: TStringList; var i: Integer);
176
    procedure LoadReviews(const SL: TStringList; var i: integer);
185
    procedure LoadReviews(const SL: TStringList; var i: Integer);
177
    procedure CorrectExtra(OldID, NewID: integer);
186
    procedure CorrectExtra(OldID, NewID: Integer);
178
    procedure DeleteExtra(AID: integer);
187
    procedure DeleteExtra(AID: Integer);
179
  end;
188
  end;
180
189
181
  TMHLCollection = class
190
  TMHLCollection = class
...
...
244
implementation
253
implementation
245
254
246
uses
255
uses
247
   Variants,
256
  Variants,
248
   dm_Collection;
257
  dm_Collection;
249
258
250
251
resourcestring
259
resourcestring
252
  rstrNamelessColection = 'безымянная коллекция';
260
  rstrNamelessColection = 'безымянная коллекция';
253
261
...
...
255
263
256
{ TDMUser }
264
{ TDMUser }
257
265
258
function TDMUser.ActivateGroup(const ID: integer): boolean;
266
function TDMUser.ActivateGroup(const ID: Integer): Boolean;
259
begin
267
begin
260
  Result := tblGroupList.Locate('Id',ID,[]);
268
  Result := tblGroupList.Locate('Id', ID, []);
261
end;
269
end;
262
270
263
procedure TDMUser.AddGroup(Name: string);
271
procedure TDMUser.AddGroup(Name: string);
...
...
271
  end;
279
  end;
272
end;
280
end;
273
281
274
procedure TDMUser.CorrectExtra(OldID, NewID: integer);
282
procedure TDMUser.CorrectExtra(OldID, NewID: Integer);
275
begin
283
begin
276
  if tblRates.Locate('BookID; DatabaseID', VarArrayOf([OldID, ActiveCollection.GetID]),[]) then
284
  if tblRates.Locate('BookID; DatabaseID', VarArrayOf([OldID, ActiveCollection.GetID]), []) then
277
  begin
285
  begin
278
    tblRates.Edit;
286
    tblRates.Edit;
279
    tblratesBookID.Value := NewID;
287
    tblRatesBookID.Value := NewID;
280
    tblRates.Post;
288
    tblRates.Post;
281
  end;
289
  end;
282
290
283
  if tblFinished.Locate('BookID; DatabaseID', VarArrayOf([OldID, ActiveCollection.GetID]),[]) then
291
  if tblFinished.Locate('BookID; DatabaseID', VarArrayOf([OldID, ActiveCollection.GetID]), []) then
284
  begin
292
  begin
285
    tblFinished.Edit;
293
    tblFinished.Edit;
286
    tblFinishedBookID.Value := NewID;
294
    tblFinishedBookID.Value := NewID;
287
    tblFinished.Post;
295
    tblFinished.Post;
288
  end;
296
  end;
289
297
290
  if tblGrouppedBooks.Locate('OuterID; DatabaseID', VarArrayOf([OldID, ActiveCollection.GetID]),[]) then
298
  if tblGrouppedBooks.Locate('OuterID; DatabaseID', VarArrayOf([OldID, ActiveCollection.GetID]), []) then
291
  begin
299
  begin
292
    tblGrouppedBooks.Edit;
300
    tblGrouppedBooks.Edit;
293
    tblGrouppedBooksOuterID.Value := NewID;
301
    tblGrouppedBooksOuterID.Value := NewID;
294
    tblGrouppedBooks.Post;
302
    tblGrouppedBooks.Post;
295
  end;
303
  end;
296
297
end;
304
end;
298
305
299
constructor TDMUser.Create(AOwner: TComponent);
306
constructor TDMUser.Create(AOwner: TComponent);
...
...
303
  FCollection.FSysDataModule := Self;
310
  FCollection.FSysDataModule := Self;
304
end;
311
end;
305
312
306
procedure TDMUser.DeleteExtra(AID: integer);
313
procedure TDMUser.DeleteExtra(AID: Integer);
307
begin
314
begin
308
  DeleteFinished(AID);
315
  DeleteFinished(AID);
309
  DeleteRate(AID);
316
  DeleteRate(AID);
...
...
311
318
312
procedure TDMUser.DeleteFinished;
319
procedure TDMUser.DeleteFinished;
313
var
320
var
314
  DbId: integer;
321
  DbId: Integer;
315
begin
322
begin
316
  if ADBID = 0 then
323
  if ADBID = 0 then
317
    DBid := ActiveCollection.ID
324
    DbId := ActiveCollection.ID
318
  else
325
  else
319
    DBid := ADbId;
326
    DbId := ADBID;
320
327
321
 if tblFinished.Locate('DataBaseID;BookID',
328
  if tblFinished.Locate('DataBaseID;BookID', VarArrayOf([DbId, AID]), []) then
322
           VarArrayOf([DbId, AID]), []) then
329
    tblFinished.Delete;
323
  tblFinished.Delete;
324
end;
330
end;
325
331
326
procedure TDMUser.DeleteRate;
332
procedure TDMUser.DeleteRate;
327
var
333
var
328
  DBID: integer;
334
  DbId: Integer;
329
begin
335
begin
330
  if ADBID = 0 then
336
  if ADBID = 0 then
331
    DBid := ActiveCollection.ID
337
    DbId := ActiveCollection.ID
332
  else
338
  else
333
    DBid := ADbId;
339
    DbId := ADBID;
334
340
335
 if tblRates.Locate('DataBaseID;BookID',
341
  if tblRates.Locate('DataBaseID;BookID', VarArrayOf([DbId, AID]), []) then
336
           VarArrayOf([DbId, AID]), []) then
342
    tblRates.Delete;
337
  tblRates.Delete;
338
end;
343
end;
339
344
340
destructor TDMUser.Destroy;
345
destructor TDMUser.Destroy;
...
...
351
  Notes, URL, Script, User, Password: string
356
  Notes, URL, Script, User, Password: string
352
  );
357
  );
353
var
358
var
354
  ID : integer;
359
  ID: Integer;
355
begin
360
begin
356
  case CollectionType of    // предопределенные типы
361
  { TODO -oNickR -cRefactoring : магические числа!!! }
357
        65536: ID := 10001; // либрусек fb2
362
  case CollectionType of // предопределенные типы
358
        65537: ID := 10002; // либрусек не-fb2
363
    65536: ID := 10001; // либрусек fb2
364
    65537: ID := 10002; // либрусек не-fb2
359
    134283264: ID := 10003; // либрусек on-line
365
    134283264: ID := 10003; // либрусек on-line
360
    else
366
  else
361
      begin
367
    begin
362
        Randomize;
368
      Randomize;
363
        ID := random(10000);
369
      ID := Random(10000);
364
      end;
370
    end;
365
  end;
371
  end;
366
  while tblBases.Locate('Id',ID,[]) do  // проверяем уникальность
          ID := random(10000);
367
372
368
  // регистрируем коллекцию
373
  while tblBases.Locate('Id', ID, []) do // проверяем уникальность
    ID := Random(10000);
369
374
375
  //
376
  // регистрируем коллекцию
377
  //
370
  tblBases.Insert;
378
  tblBases.Insert;
371
  tblBasesId.Value := ID;
379
  tblBasesID.Value := ID;                           // хм... это автоинкрементное поле, зачем его заполнять?
372
  tblBasesName.Value := DisplayName;
380
  tblBasesName.Value := DisplayName;
373
  tblBasesRootFolder.Value := RootFolder;
381
  tblBasesRootFolder.Value := RootFolder;
374
  tblBasesDBFileName.Value := DBFileName;
382
  tblBasesDBFileName.Value := DBFileName;
...
...
411
419
412
function TDMUser.FindCollectionWithProp(PropID: TCollectionProp; const Value: string; IgnoreID: Integer): Boolean;
420
function TDMUser.FindCollectionWithProp(PropID: TCollectionProp; const Value: string; IgnoreID: Integer): Boolean;
413
const
421
const
414
  Fields: array [TCollectionProp] of string = (
422
  Fields: array [TCollectionProp] of string = ('Name', 'DBFileName', 'RootFolder');
415
    'Name',
416
    'DBFileName',
417
    'RootFolder'
418
  );
419
begin
423
begin
420
  Result := False;
424
  Result := False;
421
  if tblBases.IsEmpty then
425
  if tblBases.IsEmpty then
...
...
497
  begin
501
  begin
498
    tblGrouppedBooks.Insert;
502
    tblGrouppedBooks.Insert;
499
    tblGrouppedBooksOuterID.Value := ID;
503
    tblGrouppedBooksOuterID.Value := ID;
500
    tblGrouppedBooksDataBaseID.Value := ActiveCollection.ID;
504
    tblGrouppedBooksDatabaseID.Value := ActiveCollection.ID;
501
    tblGrouppedBooksTitle.Value := dmCollection.tblBooksTitle.Value;
505
    tblGrouppedBooksTitle.Value := dmCollection.tblBooksTitle.Value;
502
506
503
    tblGrouppedBooksSerID.Value := dmCollection.tblBooksSerID.Value;
507
    tblGrouppedBooksSerID.Value := dmCollection.tblBooksSerID.Value;
504
508
505
    if dmCollection.tblBooksSeries.IsNull then
509
    if dmCollection.tblBooksSeries.IsNull then
506
          tblGrouppedBooksSeries.Value := NO_SERIES_TITLE
510
      tblGrouppedBooksSeries.Value := NO_SERIES_TITLE
507
        else
511
    else
508
          tblGrouppedBooksSeries.Value := dmCollection.tblBooksSeries.Value;
512
      tblGrouppedBooksSeries.Value := dmCollection.tblBooksSeries.Value;
509
513
510
    tblGrouppedBooksFullName.Value := dmCollection.FullAuthorsString(ID);
514
    tblGrouppedBooksFullName.Value := dmCollection.FullAuthorsString(ID);
511
515
...
...
516
    tblGrouppedBooksLocal.Value := dmCollection.tblBooksLocal.Value;
520
    tblGrouppedBooksLocal.Value := dmCollection.tblBooksLocal.Value;
517
521
518
    if not dmCollection.tblBooksFolder.IsNull then
522
    if not dmCollection.tblBooksFolder.IsNull then
519
          tblGrouppedBooksFolder.Value := IncludeTrailingPathDelimiter(ActiveCollection.RootFolder) + CheckSymbols(dmCollection.tblBooksFolder.Value)
523
      tblGrouppedBooksFolder.Value := IncludeTrailingPathDelimiter(ActiveCollection.RootFolder) + CheckSymbols(dmCollection.tblBooksFolder.Value)
520
        else
524
    else
521
          tblGrouppedBooksFolder.Value := IncludeTrailingPathDelimiter(ActiveCollection.RootFolder);
525
      tblGrouppedBooksFolder.Value := IncludeTrailingPathDelimiter(ActiveCollection.RootFolder);
522
526
523
    tblGrouppedBooksFileName.Value := dmCollection.tblBooksFileName.Value;
527
    tblGrouppedBooksFileName.Value := dmCollection.tblBooksFileName.Value;
524
    tblGrouppedBooksExt.Value := dmCollection.tblBooksExt.Value;
528
    tblGrouppedBooksExt.Value := dmCollection.tblBooksExt.Value;
...
...
528
    tblGrouppedBooksDate.Value := dmCollection.tblBooksDate.Value;
532
    tblGrouppedBooksDate.Value := dmCollection.tblBooksDate.Value;
529
    tblGrouppedBooksProgress.Value := dmCollection.tblBooksProgress.Value;
533
    tblGrouppedBooksProgress.Value := dmCollection.tblBooksProgress.Value;
530
    tblGrouppedBooksCode.Value := dmCollection.tblBooksCode.Value;
534
    tblGrouppedBooksCode.Value := dmCollection.tblBooksCode.Value;
531
//    tblGrouppedBooksKeyWords.Value := dmCollection.tblBooksKeyWords.Value;
535
    // tblGrouppedBooksKeyWords.Value := dmCollection.tblBooksKeyWords.Value;
532
    tblGrouppedBooks.Post;
536
    tblGrouppedBooks.Post;
533
537
534
    if tblGrouppedBooksCode.Value = 1 then
538
    if tblGrouppedBooksCode.Value = 1 then
...
...
537
      tblExtraE_Review.Value := dmCollection.tblExtraE_Review.Value;
541
      tblExtraE_Review.Value := dmCollection.tblExtraE_Review.Value;
538
      tblExtra.Post;
542
      tblExtra.Post;
539
    end;
543
    end;
540
541
  end;
544
  end;
542
543
end;
545
end;
544
546
545
procedure TDMUser.LoadFinished;
547
procedure TDMUser.LoadFinished;
546
var
548
var
547
  p, ID, Progress: integer;
549
  p, ID, Progress: Integer;
548
begin
550
begin
549
  // Прочитаное
  inc(i);
551
  // Прочитаное
  inc(i);
550
  while (i < SL.Count) and (pos('#',SL[i]) = 0) do
552
  Inc(i);
553
  while (i < SL.Count) and (Pos('#', SL[i]) = 0) do
551
  begin
554
  begin
552
    p := pos(' ',SL[i]);
555
    p := Pos(' ', SL[i]);
553
    ID := StrToInt(copy(SL[i],1, p - 1));
556
    ID := StrToInt(Copy(SL[i], 1, p - 1));
554
    Progress := StrToInt(copy(SL[i],p + 1));
557
    Progress := StrToInt(Copy(SL[i], p + 1));
555
558
556
    DMCollection.tblBooks.Locate('LibID', ID, []);
559
    dmCollection.tblBooks.Locate('LibID', ID, []);
557
    ID := DMCollection.tblBooksID.Value;
560
    ID := dmCollection.tblBooksID.Value;
558
561
559
    if not tblFinished.Locate('DataBaseID; ID',
562
    if not tblFinished.Locate('DataBaseID; ID', VarArrayOf([ActiveCollection.ID, ID]), []) then
560
                                      VarArrayOf([ActiveCollection.ID,ID]), [])
561
    then
562
    begin
563
    begin
563
      tblFinished.Insert;
564
      tblFinished.Insert;
564
      tblFinishedBookID.Value := ID;
565
      tblFinishedBookID.Value := ID;
...
...
574
      tblFinishedProgress.Value := Progress;
574
      tblFinishedProgress.Value := Progress;
575
      tblFinished.Post;
575
      tblFinished.Post;
576
    end;
576
    end;
577
    inc(i);
577
    Inc(i);
578
  end;
578
  end;
579
end;
579
end;
580
580
581
procedure TDMUser.LoadGroupedBooks;
581
procedure TDMUser.LoadGroupedBooks;
582
var
582
var
583
  p, ID, GroupID: integer;
583
  p, ID, GroupID: Integer;
584
  Name: string;
584
  Name: string;
585
begin
585
begin
586
  // Избранное
  inc(i);
586
  // Избранное
  inc(i);
587
  while (i < SL.Count) and (pos('#',SL[i]) = 0) do
587
  Inc(i);
588
  while (i < SL.Count) and (Pos('#', SL[i]) = 0) do
588
  begin
589
  begin
589
    p := pos(' ',SL[i]);
590
    p := Pos(' ', SL[i]);
590
    if p <> 0 then
591
    if p <> 0 then
591
    begin
592
    begin
592
      ID := StrToInt(copy(SL[i],1, p - 1));
593
      ID := StrToInt(Copy(SL[i], 1, p - 1));
593
      Name := copy(SL[i], p + 1);
594
      Name := Copy(SL[i], p + 1);
594
    end
595
    end
595
    else
596
    else
596
    begin
597
    begin
...
...
600
      Name := '';
600
      Name := '';
601
    end;
601
    end;
602
602
603
    if not tblGroupList.Locate('Name', Name,[]) then
603
    if not tblGroupList.Locate('Name', Name, []) then
604
        tblGroupList.Locate('ID',GroupID,[]);
604
      tblGroupList.Locate('ID', GroupID, []);
605
605
606
    if DMCollection.tblBooks.Locate('LibID', ID, []) then
606
    if dmCollection.tblBooks.Locate('LibID', ID, []) then
607
        InsertToGroupTable(DMCollection.tblBooksID.Value,
607
      InsertToGroupTable(dmCollection.tblBooksID.Value, dmCollection.GetBookGenres(dmCollection.tblBooksID.Value, False));
608
                            dmCollection.GetBookGenres(DMCollection.tblBooksID.Value, false));
608
    Inc(i);
609
    inc(i);
610
  end;
609
  end;
611
end;
610
end;
612
611
613
procedure TDMUser.LoadReviews;
612
procedure TDMUser.LoadReviews;
614
var
613
var
615
  ID, p: integer;
614
  ID, p: Integer;
616
   S: string;
615
  S: string;
617
begin
616
begin
618
  //  Рецензии
617
  // Рецензии
619
  inc(i);
618
  Inc(i);
620
  while (i < SL.Count) and (pos('#',SL[i]) = 0) do
619
  while (i < SL.Count) and (Pos('#', SL[i]) = 0) do
621
  begin
620
  begin
622
    p := pos(' ',SL[i]);
621
    p := Pos(' ', SL[i]);
623
    ID := StrToInt(copy(SL[i],1, p - 1));
622
    ID := StrToInt(Copy(SL[i], 1, p - 1));
624
    S := copy(SL[i],p + 1);
623
    S := Copy(SL[i], p + 1);
625
624
626
    StrReplace('~',#13#10,S);
625
    StrReplace('~', #13#10, S);
627
626
628
    DMCollection.tblBooks.Locate('LibID', ID, []); //получаем реальный ID
627
    dmCollection.tblBooks.Locate('LibID', ID, []); // получаем реальный ID
629
    ID := DMCollection.tblBooksID.Value;
628
    ID := dmCollection.tblBooksID.Value;
630
629
631
    if dmCollection.tblBooks.Locate('ID',ID,[]) then
630
    if dmCollection.tblBooks.Locate('ID', ID, []) then
632
    begin
631
    begin
633
      dmCollection.tblExtra.Insert;
632
      dmCollection.tblExtra.Insert;
634
      dmCollection.tblExtraE_Review.Value := S;
633
      dmCollection.tblExtraE_Review.Value := S;
...
...
639
      dmCollection.tblBooks.Post;
638
      dmCollection.tblBooks.Post;
640
    end;
639
    end;
641
640
642
    inc(i);
641
    Inc(i);
643
  end;
642
  end;
644
end;
643
end;
645
644
646
645
procedure TDMUser.LoadGroups(const SL: TStringList; var i: Integer);
647
procedure TDMUser.LoadGroups(const SL: TStringList; var i: integer);
648
var
646
var
649
  k: integer;
647
  k: Integer;
650
begin
648
begin
651
  inc(i);
649
  Inc(i);
652
  k := 1;
650
  k := 1;
653
  while pos('#',SL[i]) = 0 do
651
  while Pos('#', SL[i]) = 0 do
654
  begin
652
  begin
655
    if k > 2 then
653
    if k > 2 then
656
      AddGroup(SL[i]);
654
      AddGroup(SL[i]);
657
    inc(k);
655
    Inc(k);
658
    inc(i);
656
    Inc(i);
659
  end;
657
  end;
660
end;
658
end;
661
659
662
procedure TDMUser.LoadRates;
660
procedure TDMUser.LoadRates;
663
var
661
var
664
  p, ID, LibID, Rate: integer;
662
  p, ID, LibID, Rate: Integer;
665
begin
663
begin
666
  // Рейтинги
664
  // Рейтинги
667
  inc(i);
665
  Inc(i);
668
  while pos('#',SL[i]) = 0 do
666
  while Pos('#', SL[i]) = 0 do
669
  begin
667
  begin
670
    p := pos(' ',SL[i]);
668
    p := Pos(' ', SL[i]);
671
    LibID := StrToInt(copy(SL[i],1, p - 1));
669
    LibID := StrToInt(Copy(SL[i], 1, p - 1));
672
    Rate := StrToInt(copy(SL[i],p + 1));
670
    Rate := StrToInt(Copy(SL[i], p + 1));
673
671
674
    DMCollection.tblBooks.Locate('LibID', LibID, []); //получаем реальный ID
672
    dmCollection.tblBooks.Locate('LibID', LibID, []); // получаем реальный ID
675
    ID := DMCollection.tblBooksID.Value;
673
    ID := dmCollection.tblBooksID.Value;
676
674
677
    if not tblRates.Locate('DataBaseID; BookID', VarArrayOf([ActiveCollection.ID,ID]), []) then
675
    if not tblRates.Locate('DataBaseID; BookID', VarArrayOf([ActiveCollection.ID, ID]), []) then
678
    begin
676
    begin
679
      tblRates.Insert;
677
      tblRates.Insert;
680
      tblRatesBookID.Value := ID;
678
      tblRatesBookID.Value := ID;
...
...
689
      tblRatesRate.Value := Rate;
687
      tblRatesRate.Value := Rate;
690
      tblRates.Post;
688
      tblRates.Post;
691
    end;
689
    end;
692
    inc(i);
690
    Inc(i);
693
  end;
691
  end;
694
end;
692
end;
695
693
696
procedure TDMUser.SetFinished;
694
procedure TDMUser.SetFinished;
697
var
695
var
698
  DBID: integer;
696
  DbId: Integer;
699
begin
697
begin
700
  if ADBID = 0 then
698
  if ADBID = 0 then
701
    DBid := ActiveCollection.ID
699
    DbId := ActiveCollection.ID
702
  else
700
  else
703
    DBid := ADbId;
701
    DbId := ADBID;
704
702
705
  if not tblFinished.Locate('DataBaseID;BookID',
703
  if not tblFinished.Locate('DataBaseID;BookID', VarArrayOf([DbId, ID]), []) then
706
           VarArrayOf([DBID, ID]), []) then
707
  begin
704
  begin
708
    tblFinished.Insert;
705
    tblFinished.Insert;
709
    tblFinishedBookId.Value := ID;
706
    tblFinishedBookID.Value := ID;
710
    tblFinishedProgress.Value := Progress;
707
    tblFinishedProgress.Value := Progress;
711
    tblFinishedDataBaseID.Value := DBID;
708
    tblFinishedDataBaseID.Value := DbId;
712
    tblFinishedDate.Value := Now;
709
    tblFinishedDate.Value := Now;
713
    tblFinished.Post;
710
    tblFinished.Post;
714
  end
711
  end
...
...
720
  end;
717
  end;
721
end;
718
end;
722
719
723
procedure TDMUser.SetLocal(ID: integer; Value: boolean);
720
procedure TDMUser.SetLocal(ID: Integer; Value: Boolean);
724
begin
721
begin
725
  if tblGrouppedBooks.Locate('DataBaseID;OuterID',
722
  if tblGrouppedBooks.Locate('DataBaseID;OuterID', VarArrayOf([ActiveCollection.ID, ID]), []) then
726
           VarArrayOf([ActiveCollection.ID, ID]), []) then
727
  begin
723
  begin
728
    tblGrouppedBooks.Edit;
724
    tblGrouppedBooks.Edit;
729
    tblGrouppedBooksLocal.Value := Value;
725
    tblGrouppedBooksLocal.Value := Value;
...
...
731
  end;
727
  end;
732
end;
728
end;
733
729
734
procedure TDMUser.SetRate(ID, Rate: integer);
730
procedure TDMUser.SetRate(ID, Rate: Integer);
735
begin
731
begin
736
  if not tblRates.Locate('DataBaseID;BookID',
732
  if not tblRates.Locate('DataBaseID;BookID', VarArrayOf([ActiveCollection.ID, ID]), []) then
737
           VarArrayOf([ActiveCollection.ID, ID]), []) then
738
  begin
733
  begin
739
    tblRates.Insert;
734
    tblRates.Insert;
740
    tblRatesBookId.Value := ID;
735
    tblRatesBookID.Value := ID;
741
    tblRatesRate.Value := Rate;
736
    tblRatesRate.Value := Rate;
742
    tblRatesDataBaseID.Value := ActiveCollection.ID;
737
    tblRatesDataBaseID.Value := ActiveCollection.ID;
743
    tblRatesDate.Value := Now;
738
    tblRatesDate.Value := Now;
...
...
751
  end;
746
  end;
752
end;
747
end;
753
748
754
procedure TDMUser.SetTableState(State: boolean);
749
procedure TDMUser.SetTableState(State: Boolean);
755
begin
750
begin
756
  tblGroupList.Active := State;
751
  tblGroupList.Active := State;
757
  tblGrouppedBooks.Active := State;
752
  tblGrouppedBooks.Active := State;
...
...
760
  tblFinished.Active := State;
755
  tblFinished.Active := State;
761
end;
756
end;
762
757
763
procedure TDMUser.SetUserTableState(Status: boolean);
758
procedure TDMUser.SetUserTableState(Status: Boolean);
764
begin
759
begin
765
  tblGroupList.Active := Status;
760
  tblGroupList.Active := Status;
766
  tblGrouppedBooks.Active := Status;
761
  tblGrouppedBooks.Active := Status;
...
...
775
function TMHLCollection.GetActive: Boolean;
770
function TMHLCollection.GetActive: Boolean;
776
begin
771
begin
777
  Assert(Assigned(FSysDataModule));
772
  Assert(Assigned(FSysDataModule));
778
  Result :=
773
  Result := FSysDataModule.tblBases.Active and not FSysDataModule.tblBasesID.IsNull;
779
    FSysDataModule.tblBases.Active and
780
    not FSysDataModule.tblBasesID.IsNull;
781
end;
774
end;
782
775
783
function TMHLCollection.GetID: Integer;
776
function TMHLCollection.GetID: Integer;
...
...
943
  FSysDataModule.tblBasesAllowDelete.Value := Value;
936
  FSysDataModule.tblBasesAllowDelete.Value := Value;
944
end;
937
end;
945
938
946
947
948
949
end.
939
end.