Changeset 465

User picture

Author: nrymanov@gmail.com

(2010/03/02 11:21) Almost 2 years ago

see #29 - Редизайн и унификация пользовательского интерфейса
* форматирование текста
* очень мелкие правки

Affected files

Updated trunk/DataModules/dm_collection.pas Download diff

464465
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
  ****************************************************************************** *)
13
1
unit dm_collection;
14
unit dm_collection;
2
15
3
interface
16
interface
...
...
3
17
4
uses
18
uses
5
  SysUtils, Classes, ABSMain, DB, unit_globals;
19
  SysUtils,
20
  Classes,
21
  ABSMain,
22
  DB,
23
  unit_Globals;
6
24
7
type
25
type
...
...
18
    tblBooksS: TABSTable;
36
    tblBooksS: TABSTable;
19
    dsSeries: TDataSource;
37
    dsSeries: TDataSource;
20
    dsAuthorsS: TDataSource;
38
    dsAuthorsS: TDataSource;
21
    dsBooksS: TDataSource;        
39
    dsBooksS: TDataSource;
22
    tblAuthorsSID: TAutoIncField;
40
    tblAuthorsSID: TAutoIncField;
23
    tblAuthorsSFamily: TWideStringField;
41
    tblAuthorsSFamily: TWideStringField;
24
    tblAuthorsSName: TWideStringField;
42
    tblAuthorsSName: TWideStringField;
...
...
219
    tblExtraE_Review: TWideMemoField;
237
    tblExtraE_Review: TWideMemoField;
220
    tblExtraE_Cover: TBlobField;
238
    tblExtraE_Cover: TBlobField;
221
    tblExtraE_Data: TWideMemoField;
239
    tblExtraE_Data: TWideMemoField;
240
222
  private
241
  private
223
    FIsFavorites: boolean;
242
    FIsFavorites: Boolean;
224
    FActiveTable: TAbsTable;
243
    FActiveTable: TABSTable;
225
244
226
    { Private declarations }
227
  public
245
  public
228
    procedure GetBookFileName(ID: integer; out AFile, AFolder, AExt: string;
246
    procedure GetBookFileName(ID: Integer; out AFile, AFolder, AExt: string; out ANo: Integer);
229
      out ANo: integer);
230
247
231
    procedure SetActiveTable(Tag: integer);
248
    procedure SetActiveTable(Tag: Integer);
232
    procedure GetCurrentBook(var R: TBookRecord);
249
    procedure GetCurrentBook(var R: TBookRecord);
233
    function GetBookGenres(BookID: Integer; FirstOnly: boolean): String;
250
    function GetBookGenres(BookID: Integer; FirstOnly: Boolean): string;
234
    function GetRootGenre(BookID: Integer): string;
251
    function GetRootGenre(BookID: Integer): string;
235
    function GetGenreCode(BookID: Integer): String;
252
    function GetGenreCode(BookID: Integer): string;
236
253
237
    procedure FieldByName(AID: integer; AField: String; out ARes: String); overload;
254
    procedure FieldByName(AID: Integer; AField: string; out ARes: string); overload;
238
    procedure FieldByName(AID: integer; AField: String; out ARes: integer); overload;
255
    procedure FieldByName(AID: Integer; AField: string; out ARes: Integer); overload;
239
    procedure FieldByName(AID: integer; AField: String; out Ares: boolean); overload;
256
    procedure FieldByName(AID: Integer; AField: string; out ARes: Boolean); overload;
240
257
241
    procedure GetBookFolder(ID: integer; out AFolder: String);
258
    procedure GetBookFolder(ID: Integer; out AFolder: string);
242
    procedure SetLocalStatus(AId: integer; AState: boolean);
259
    procedure SetLocalStatus(AID: Integer; AState: Boolean);
243
260
244
    procedure GetStatistics(out AuthorsCount: Integer; out BooksCount: Integer; out SeriesCount: Integer);
261
    procedure GetStatistics(out AuthorsCount: Integer; out BooksCount: Integer; out SeriesCount: Integer);
245
    property ActiveTable: TabsTable read FActiveTable;
262
    property ActiveTable: TABSTable read FActiveTable;
246
263
247
    procedure Clear;
264
    procedure Clear;
248
    procedure SetTableState(State: boolean);
265
    procedure SetTableState(State: Boolean);
249
    function FullName(BookID: Integer): string;
266
    function FullName(BookID: Integer): string;
250
    function AuthorID(BookID: Integer): integer;
267
    function AuthorID(BookID: Integer): Integer;
251
    function FullAuthorsString(BookID: Integer): string;
268
    function FullAuthorsString(BookID: Integer): string;
252
253
  end;
269
  end;
254
270
255
var
271
var
...
...
278
  tblAuthor_Master.Locate('AL_BookID', BookID, []);
294
  tblAuthor_Master.Locate('AL_BookID', BookID, []);
279
  while (not tblAuthor_Master.Eof) and (tblAuthor_MasterAL_BookID.Value = BookID) do
295
  while (not tblAuthor_Master.Eof) and (tblAuthor_MasterAL_BookID.Value = BookID) do
280
  begin
296
  begin
281
    S := trim(tblAuthor_DetailA_Family.Value + ' ' +
297
    { TODO -oNickR :   TAuthorRecord }
282
                 tblAuthor_DetailA_Name.Value +  ' ' +
298
    S := Trim(tblAuthor_DetailA_Family.Value + ' ' + tblAuthor_DetailA_Name.Value + ' ' + tblAuthor_DetailA_Middle.Value);
283
                 tblAuthor_DetailA_Middle.Value);
284
299
285
    Result := IfThen(Result = '', S, Result + ', ' + S);
300
    Result := IfThen(Result = '', S, Result + ', ' + S);
286
    tblAuthor_Master.Next;
301
    tblAuthor_Master.Next;
...
...
289
304
290
function TDMCollection.FullName(BookID: Integer): string;
305
function TDMCollection.FullName(BookID: Integer): string;
291
begin
306
begin
292
  if BookID <> 0 then tblAuthor_Master.Locate('AL_BookID', BookID, []);
307
  if BookID <> 0 then
293
  Result := trim(tblAuthor_DetailA_Family.Value + ' ' +
308
    tblAuthor_Master.Locate('AL_BookID', BookID, []);
294
                 tblAuthor_DetailA_Name.Value +  ' ' +
309
  { TODO -oNickR :   TAuthorRecord }
295
                 tblAuthor_DetailA_Middle.Value);
310
  Result := Trim(tblAuthor_DetailA_Family.Value + ' ' + tblAuthor_DetailA_Name.Value + ' ' + tblAuthor_DetailA_Middle.Value);
296
end;
311
end;
297
312
298
procedure TDMCollection.FieldByName(AID: integer; AField: String; out ARes: String);
313
procedure TDMCollection.FieldByName(AID: Integer; AField: String; out ARes: String);
299
begin
314
begin
300
  if AID<> 0 then FActiveTable.Locate('ID', AID, []);
315
  if AID <> 0 then
316
    FActiveTable.Locate('ID', AID, []);
301
  ARes := FActiveTable.FieldByName(AField).AsString;
317
  ARes := FActiveTable.FieldByName(AField).AsString;
302
end;
318
end;
303
319
304
procedure TDMCollection.FieldByName(AID: integer; AField: String; out ARes: integer);
320
procedure TDMCollection.FieldByName(AID: Integer; AField: String; out ARes: Integer);
305
begin
321
begin
306
  if AID<> 0 then FActiveTable.Locate('ID', AID, []);
322
  if AID <> 0 then
323
    FActiveTable.Locate('ID', AID, []);
307
  ARes := FActiveTable.FieldByName(AField).AsInteger;
324
  ARes := FActiveTable.FieldByName(AField).AsInteger;
308
end;
325
end;
309
326
310
function TDMCollection.AuthorID(BookID: Integer): integer;
327
function TDMCollection.AuthorID(BookID: Integer): Integer;
311
begin
328
begin
312
  if BookID <> 0 then tblAuthor_Master.Locate('AL_BookID', BookID, []);
329
  if BookID <> 0 then
330
    tblAuthor_Master.Locate('AL_BookID', BookID, []);
313
  Result := tblAuthor_MasterAL_AuthID.Value;
331
  Result := tblAuthor_MasterAL_AuthID.Value;
314
end;
332
end;
315
333
...
...
317
begin
335
begin
318
  SetTableState(False);
336
  SetTableState(False);
319
337
320
//  tblAuthors.EmptyTable;
338
  // tblAuthors.EmptyTable;
321
  tblAuthor_List.EmptyTable;
339
  tblAuthor_List.EmptyTable;
322
//  tblSeries.EmptyTable;
340
  // tblSeries.EmptyTable;
323
  tblBooksA.EmptyTable;
341
  tblBooksA.EmptyTable;
324
  tblBooksS.EmptyTable;
342
  tblBooksS.EmptyTable;
325
  tblGenres.EmptyTable;
343
  tblGenres.EmptyTable;
...
...
334
  SetTableState(True);
352
  SetTableState(True);
335
end;
353
end;
336
354
337
procedure TDMCollection.FieldByName(AID: integer; AField: String; out Ares: boolean);
355
procedure TDMCollection.FieldByName(AID: Integer; AField: String; out ARes: Boolean);
338
begin
356
begin
339
  if AID <> 0 then FActiveTable.Locate('ID', AID, []);
357
  if AID <> 0 then
358
    FActiveTable.Locate('ID', AID, []);
340
  ARes := FActiveTable.FieldByName(AField).AsBoolean;
359
  ARes := FActiveTable.FieldByName(AField).AsBoolean;
341
end;
360
end;
342
361
343
procedure TDMCollection.GetBookFileName(ID: integer; out AFile:string;
362
procedure TDMCollection.GetBookFileName(ID: Integer; out AFile: string; out AFolder: string; out AExt: string; out ANo: Integer);
344
                                  out AFolder: string; out AExt: string;
345
                                  out ANo:integer);
346
begin
363
begin
347
  FActiveTable.Locate('ID', ID, []);
364
  FActiveTable.Locate('ID', ID, []);
348
  AExt := FActiveTable.FieldByName('Ext').AsString;
365
  AExt := FActiveTable.FieldByName('Ext').AsString;
349
  AFile := FActiveTable.FieldByName('FileName').AsString;
366
  AFile := FActiveTable.FieldByName('FileName').AsString;
350
367
351
  if ExtractFileExt(AFile) <> ZIP_EXTENSION   then  //   !
368
  if ExtractFileExt(AFile) <> ZIP_EXTENSION then //   !
352
     AFile := AFile + AExt;
369
    AFile := AFile + AExt;
353
370
354
  AFolder := FActiveTable.FieldByName('Folder').AsString;
371
  AFolder := FActiveTable.FieldByName('Folder').AsString;
355
  ANo := FActiveTable.FieldByName('InsideNo').AsInteger;
372
  ANo := FActiveTable.FieldByName('InsideNo').AsInteger;
356
end;
373
end;
357
374
358
function TDMCollection.GetBookGenres(BookID: Integer; FirstOnly: boolean): String;
375
function TDMCollection.GetBookGenres(BookID: Integer; FirstOnly: Boolean): String;
359
var
376
var
360
  s: String;
377
  S: String;
361
  i: integer;
378
  i: Integer;
362
begin
379
begin
363
  i := 0;
380
  i := 0;
364
  tblBooks_Genre_List.Locate('GL_BookID', BookID, []);
381
  tblBooks_Genre_List.Locate('GL_BookID', BookID, []);
365
  while (not tblBooks_Genre_List.Eof) and (tblBooks_Genre_ListGL_BookID.Value = BookID) do
382
  while (not tblBooks_Genre_List.Eof) and (tblBooks_Genre_ListGL_BookID.Value = BookID) do
366
  begin
383
  begin
367
    if FirstOnly and (i > 0) then Break;
384
    if FirstOnly and (i > 0) then
385
      Break;
368
    if not tblBooks_GenresG_Alias.IsNull then
386
    if not tblBooks_GenresG_Alias.IsNull then
369
      s := s + tblBooks_GenresG_Alias.Value + ' / ';
387
      S := S + tblBooks_GenresG_Alias.Value + ' / ';
370
    tblBooks_Genre_List.Next;
388
    tblBooks_Genre_List.Next;
371
    inc(i);
389
    inc(i);
372
  end;
390
  end;
373
  Delete(S, Length(S) - 2, 3);
391
  Delete(S, Length(S) - 2, 3);
374
  Result := s;
392
  Result := S;
375
end;
393
end;
376
394
377
procedure TDMCollection.GetCurrentBook(var R: TBookRecord);
395
procedure TDMCollection.GetCurrentBook(var R: TBookRecord);
378
var
396
var
379
  BookID: Integer;
397
  BookID: Integer;
380
begin
398
begin
381
  BookID := ActiveTable.FieldByname('ID').Value;
399
  BookID := ActiveTable.FieldByName('ID').Value;
400
382
  R.Clear;
401
  R.Clear;
383
  R.Title := ActiveTable.FieldByname('Title').AsWideString;
402
  R.Title := ActiveTable.FieldByName('Title').AsWideString;
384
  R.Series := IfThen(ActiveTable.FieldByname('SerID').IsNull,
403
  R.Series := IfThen(ActiveTable.FieldByName('SerID').IsNull, NO_SERIES_TITLE, ActiveTable.FieldByName('Series').AsWideString);
385
                     NO_SERIES_TITLE,
404
  R.SeqNumber := ActiveTable.FieldByName('SeqNumber').AsInteger;
386
                     ActiveTable.FieldByname('Series').AsWideString);
405
  R.Folder := ActiveTable.FieldByName('Folder').AsWideString;
387
  R.SeqNumber := ActiveTable.FieldByname('SeqNumber').AsInteger;
406
  R.FileName := ActiveTable.FieldByName('FileName').AsWideString;
388
  R.Folder := ActiveTable.FieldByname('Folder').AsWideString;
407
  R.FileExt := ActiveTable.FieldByName('Ext').AsWideString;
389
  R.FileName := ActiveTable.FieldByname('FileName').AsWideString;
408
  R.Size := ActiveTable.FieldByName('Size').AsInteger;
390
  R.FileExt := ActiveTable.FieldByname('Ext').AsWideString;
409
  R.InsideNo := ActiveTable.FieldByName('InsideNo').AsInteger;
391
  R.Size := ActiveTable.FieldByname('Size').AsInteger;
410
  R.Local := ActiveTable.FieldByName('Local').AsBoolean;
392
  R.InsideNo := ActiveTable.FieldByname('InsideNo').AsInteger;
411
  R.Date := ActiveTable.FieldByName('Date').AsDateTime;
393
  R.Date := ActiveTable.FieldByname('Date').AsDateTime;
412
  R.Lang := ActiveTable.FieldByName('Lang').AsWideString;
394
  R.Lang := ActiveTable.FieldByname('Lang').AsWideString;
413
  if not FIsFavorites then
395
  R.KeyWords := ActiveTable.FieldByname('KeyWords').AsWideString;
414
    R.KeyWords := ActiveTable.FieldByName('KeyWords').AsWideString;
396
  R.Code := ActiveTable.FieldByname('Code').AsInteger;
415
  R.Code := ActiveTable.FieldByName('Code').AsInteger;
397
416
398
  if tblExtra.Locate('E_BookID', BookID, []) then
417
  if tblExtra.Locate('E_BookID', BookID, []) then
399
    R.Annotation := tblExtraE_Annotation.Value;
418
    R.Annotation := tblExtraE_Annotation.Value;
400
419
401
  if ActiveTable.FieldByname('LibID').AsInteger <> 0 then
420
  if ActiveTable.FieldByName('LibID').AsInteger <> 0 then
402
    R.LibID := ActiveTable.FieldByname('LibID').AsInteger
421
    R.LibID := ActiveTable.FieldByName('LibID').AsInteger
403
  else
422
  else
404
    R.LibID := BookID;
423
    R.LibID := BookID;
405
424
406
  if not FIsFavorites  then
425
  if not FIsFavorites then
407
  begin
426
  begin
408
    tblBooks_Genre_List.Locate('GL_BookID', BookID, []);
427
    tblBooks_Genre_List.Locate('GL_BookID', BookID, []);
428
    tblGenres.Locate('G_Code', tblBooks_GenresG_ParentCode.Value, []);
429
    R.RootGenre.Alias := tblGenresG_Alias.Value;
430
409
    while (not tblBooks_Genre_List.Eof) and (tblBooks_Genre_ListGL_BookID.AsInteger = BookID) do
431
    while (not tblBooks_Genre_List.Eof) and (tblBooks_Genre_ListGL_BookID.AsInteger = BookID) do
410
    begin
432
    begin
411
      R.AddGenreFB2(
433
      R.AddGenreFB2(
412
        tblBooks_GenresG_Code.AsWideString,
434
        tblBooks_GenresG_Code.AsWideString,
413
        tblBooks_GenresG_FB2Code.AsWideString,
435
        tblBooks_GenresG_FB2Code.AsWideString,
414
        tblBooks_GenresG_Alias.AsWideString
436
        tblBooks_GenresG_Alias.AsWideString
415
        );
437
      );
416
438
417
      tblBooks_Genre_List.Next;
439
      tblBooks_Genre_List.Next;
418
    end;
440
    end;
419
441
420
  (****************************************************************************
442
    (* ***************************************************************************
421
   *   Query      .
443
      *   Query      .
422
   *          .
444
      *          .
423
   * ,     .
445
      * ,     .
424
   *
446
      *
425
   * select A1."Family", A1."Name", A1."Middle"
447
      * select A1."Family", A1."Name", A1."Middle"
426
   * from "Author_List" A2 inner join "Authors" A1 on (A2."AuthID" = A1."ID")
448
      * from "Author_List" A2 inner join "Authors" A1 on (A2."AuthID" = A1."ID")
427
   * where (A2."BookID" = :BookID)
449
      * where (A2."BookID" = :BookID)
428
   *
450
      *
429
   *)
451
      *)
430
452
431
    tblAuthor_Master.Locate('AL_BookID', BookID, []);
453
    tblAuthor_Master.Locate('AL_BookID', BookID, []);
432
    while (not tblAuthor_Master.Eof) and (tblAuthor_MasterAL_BookID.Value = BookID) do
454
    while (not tblAuthor_Master.Eof) and (tblAuthor_MasterAL_BookID.Value = BookID) do
...
...
435
        tblAuthor_DetailA_Family.AsWideString,
457
        tblAuthor_DetailA_Family.AsWideString,
436
        tblAuthor_DetailA_Name.AsWideString,
458
        tblAuthor_DetailA_Name.AsWideString,
437
        tblAuthor_DetailA_Middle.AsWideString
459
        tblAuthor_DetailA_Middle.AsWideString
438
        );
460
      );
439
461
440
      tblAuthor_Master.Next;
462
      tblAuthor_Master.Next;
441
    end
463
    end
442
  end // not Favorites
464
  end // not Favorites
443
  else
465
  else
444
  begin
466
  begin
445
    R.AddGenreFB2('','',ActiveTable.FieldByname('Genres').AsWideString);
467
    R.AddGenreFB2('', '', ActiveTable.FieldByName('Genres').AsWideString);
446
    R.AddAuthor(ActiveTable.FieldByname('FullName').AsWideString,'','');
468
    R.AddAuthor(ActiveTable.FieldByName('FullName').AsWideString, '', '');
447
  end;
469
  end;
448
end;
470
end;
449
471
...
...
454
end;
476
end;
455
477
456
function TDMCollection.GetRootGenre(BookID: Integer): string;
478
function TDMCollection.GetRootGenre(BookID: Integer): string;
457
var
458
  Code: integer;
459
begin
479
begin
460
  tblBooks_Genre_List.Locate('GL_BookID', BookID, []);
480
  tblBooks_Genre_List.Locate('GL_BookID', BookID, []);
461
  tblGenres.Locate('G_Code', tblBooks_GenresG_ParentCode.Value, []);
481
  tblGenres.Locate('G_Code', tblBooks_GenresG_ParentCode.Value, []);
...
...
464
484
465
procedure TDMCollection.GetStatistics(out AuthorsCount: Integer; out BooksCount: Integer; out SeriesCount: Integer);
485
procedure TDMCollection.GetStatistics(out AuthorsCount: Integer; out BooksCount: Integer; out SeriesCount: Integer);
466
var
486
var
467
  FilterStateA: boolean;
487
  FilterStateA: Boolean;
468
  FilterStringA: string;
488
  FilterStringA: string;
469
  FilterStateS: boolean;
489
  FilterStateS: Boolean;
470
490
471
  BM1: TBookMark;
491
  BM1: TBookMark;
472
begin
492
begin
473
  (****************************************************************************
493
  (* ***************************************************************************
474
   *
494
    *
475
   *    3  ,
495
    *    3  ,
476
   *     
   *
496
    *     
    *
477
   ****************************************************************************)
497
    *************************************************************************** *)
478
498
479
  BM1 := DMCollection.tblAuthors.GetBookmark;
499
  BM1 := DMCollection.tblAuthors.GetBookmark;
480
  try
500
  try
...
...
484
504
485
    FilterStateS := DMCollection.tblSeries.Filtered;
505
    FilterStateS := DMCollection.tblSeries.Filtered;
486
506
487
488
    DMCollection.tblAuthors.Filtered := False;
507
    DMCollection.tblAuthors.Filtered := False;
489
    DMCollection.tblSeries.Filtered  := False;
508
    DMCollection.tblSeries.Filtered := False;
490
509
491
    AuthorsCount := DMCollection.tblAuthors.RecordCount;
510
    AuthorsCount := DMCollection.tblAuthors.RecordCount;
492
    BooksCount := DMCollection.tblBooks.RecordCount;
511
    BooksCount := DMCollection.tblBooks.RecordCount;
...
...
494
513
495
    DMCollection.tblAuthors.Filter := FilterStringA;
514
    DMCollection.tblAuthors.Filter := FilterStringA;
496
    DMCollection.tblAuthors.Filtered := FilterStateA;
515
    DMCollection.tblAuthors.Filtered := FilterStateA;
497
    DMCollection.tblSeries.Filtered  := FilterStateS;
516
    DMCollection.tblSeries.Filtered := FilterStateS;
498
517
499
    DMCollection.tblAuthors.GotoBookmark(BM1);
518
    DMCollection.tblAuthors.GotoBookmark(BM1);
500
  finally
519
  finally
...
...
502
  end;
521
  end;
503
end;
522
end;
504
523
505
procedure TDMCollection.SetActiveTable(Tag: integer);
524
procedure TDMCollection.SetActiveTable(Tag: Integer);
506
begin
525
begin
507
  if Tag = PAGE_FAVORITES then
526
  if Tag = PAGE_FAVORITES then
508
  begin
527
  begin
...
...
516
  end;
535
  end;
517
end;
536
end;
518
537
519
procedure TDMCollection.GetBookFolder(ID: integer; out AFolder: String);
538
procedure TDMCollection.GetBookFolder(ID: Integer; out AFolder: String);
520
begin
539
begin
521
  FActiveTable.Locate('ID', ID, []);
540
  FActiveTable.Locate('ID', ID, []);
522
  if FActiveTable.Name = 'tblBooks' then
541
  if FActiveTable.Name = 'tblBooks' then
...
...
525
    AFolder := FActiveTable.FieldByName('Folder').AsString;
544
    AFolder := FActiveTable.FieldByName('Folder').AsString;
526
end;
545
end;
527
546
528
procedure TDMCollection.SetLocalStatus(AId: integer; AState: boolean);
547
procedure TDMCollection.SetLocalStatus(AID: Integer; AState: Boolean);
529
begin
548
begin
530
  if Aid <> 0 then
549
  if AID <> 0 then
531
  if  FActiveTable.Locate('ID',AId,[]) then
550
    if FActiveTable.Locate('ID', AID, []) then
532
  begin
551
    begin
533
    FActiveTable.Edit;
552
      FActiveTable.Edit;
534
    FActiveTable.FieldByName('Local').AsBoolean := AState;
553
      FActiveTable.FieldByName('Local').AsBoolean := AState;
535
    FActiveTable.Post;
554
      FActiveTable.Post;
536
555
537
    if FActiveTable.Name = 'tblGrouppedBooks' then
556
      if FActiveTable.Name = 'tblGrouppedBooks' then
538
      if dmCollection.tblBooks.Locate('ID', FActiveTable.FieldByName('OuterID').AsInteger,[]) then
557
        if DMCollection.tblBooks.Locate('ID', FActiveTable.FieldByName('OuterID').AsInteger, []) then
539
      begin
558
        begin
540
        dmCollection.tblBooks.Edit;
559
          DMCollection.tblBooks.Edit;
541
        dmCollection.tblBooksLocal.Value := AState;
560
          DMCollection.tblBooksLocal.Value := AState;
542
        dmCollection.tblBooks.Post;
561
          DMCollection.tblBooks.Post;
543
      end;
562
        end;
544
563
545
    //
564
      //
546
    //        
565
      //        
547
    //
566
      //
548
    PostMessage(
567
      PostMessage(Application.MainFormHandle, WM_MHL_DOWNLOAD_COMPLETE, AID, Integer(LongBool(AState)));
549
      Application.MainFormHandle,
568
    end;
550
      WM_MHL_DOWNLOAD_COMPLETE,
551
      AId,
552
      Integer(LongBool(AState))
553
      );
554
555
  end;
556
end;
569
end;
557
570
558
procedure TDMCollection.SetTableState(State: boolean);
571
procedure TDMCollection.SetTableState(State: Boolean);
559
begin
572
begin
560
  tblAuthors.Active := State;
573
  tblAuthors.Active := State;
561
  tblAuthor_List.Active := State;
574
  tblAuthor_List.Active := State;
...
...
573
  tblExtra.Active := State;
586
  tblExtra.Active := State;
574
  tblAuthor_Master.Active := State;
587
  tblAuthor_Master.Active := State;
575
  tblAuthor_Detail.Active := State;
588
  tblAuthor_Detail.Active := State;
576
577
end;
589
end;
578
590
579
end.
591
end.

Updated trunk/DataModules/dm_user.pas Download diff

464465
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.

Updated trunk/Forms/frm_add_nonfb2.pas Download diff

464465
1
(* *****************************************************************************
2
  *
3
  * MyHomeLib
4
  *
5
  * Copyright (C) 2008-2010 Aleksey Penkov
6
  *
7
  * Created             22.02.2010
8
  * Description
9
  * Author(s)           Aleksey Penkov  alex.penkov@gmail.com
10
  *
11
  * History
12
  * NickR 02.03.2010     
  *
13
  ****************************************************************************** *)
1
14
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
unit frm_add_nonfb2;
15
unit frm_add_nonfb2;
13
16
14
interface
17
interface
...
...
46
  RzLabel,
50
  RzLabel,
47
  RzRadChk,
51
  RzRadChk,
48
  FBDDocument,
52
  FBDDocument,
49
  FBDAuthorTable, XPMan;
53
  FBDAuthorTable;
50
54
51
type
55
type
52
  TfrmAddnonfb2 = class(TForm)
56
  TfrmAddnonfb2 = class(TForm)
...
...
115
    btnOpenBook: TRzBitBtn;
119
    btnOpenBook: TRzBitBtn;
116
    FBD: TFBDDocument;
120
    FBD: TFBDDocument;
117
    alBookAuthors: TFBDAuthorTable;
121
    alBookAuthors: TFBDAuthorTable;
118
    XPManifest1: TXPManifest;
119
    alFBDAuthors: TFBDAuthorTable;
122
    alFBDAuthors: TFBDAuthorTable;
120
    btnAddAuthorFromList: TRzBitBtn;
123
    btnAddAuthorFromList: TRzBitBtn;
121
    procedure RzButton3Click(Sender: TObject);
124
    procedure RzButton3Click(Sender: TObject);
122
    procedure TreeGetText(Sender: TBaseVirtualTree; Node: PVirtualNode;
125
    procedure TreeGetText(Sender: TBaseVirtualTree; Node: PVirtualNode; Column: TColumnIndex; TextType: TVSTTextType; var CellText: String);
123
      Column: TColumnIndex; TextType: TVSTTextType; var CellText: String);
124
    procedure TreeDblClick(Sender: TObject);
126
    procedure TreeDblClick(Sender: TObject);
125
    procedure TreeChange(Sender: TBaseVirtualTree; Node: PVirtualNode);
127
    procedure TreeChange(Sender: TBaseVirtualTree; Node: PVirtualNode);
126
    procedure btnAddClick(Sender: TObject);
128
    procedure btnAddClick(Sender: TObject);
127
    procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
129
    procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
128
    procedure TreePaintText(Sender: TBaseVirtualTree;
130
    procedure TreePaintText(Sender: TBaseVirtualTree; const TargetCanvas: TCanvas; Node: PVirtualNode; Column: TColumnIndex; TextType: TVSTTextType);
129
      const TargetCanvas: TCanvas; Node: PVirtualNode; Column: TColumnIndex;
130
      TextType: TVSTTextType);
131
    procedure btnShowGenresClick(Sender: TObject);
131
    procedure btnShowGenresClick(Sender: TObject);
132
    procedure FormShow(Sender: TObject);
132
    procedure FormShow(Sender: TObject);
133
    procedure btnCopyToTitleClick(Sender: TObject);
133
    procedure btnCopyToTitleClick(Sender: TObject);
...
...
139
    procedure miOpenExplorerClick(Sender: TObject);
139
    procedure miOpenExplorerClick(Sender: TObject);
140
    procedure miRenameFileClick(Sender: TObject);
140
    procedure miRenameFileClick(Sender: TObject);
141
    procedure flFilesDirectory(Sender: TObject; const Dir: string);
141
    procedure flFilesDirectory(Sender: TObject; const Dir: string);
142
    procedure TreeCompareNodes(Sender: TBaseVirtualTree; Node1,
142
    procedure TreeCompareNodes(Sender: TBaseVirtualTree; Node1, Node2: PVirtualNode; Column: TColumnIndex; var Result: Integer);
143
      Node2: PVirtualNode; Column: TColumnIndex; var Result: Integer);
144
    procedure TreeClick(Sender: TObject);
143
    procedure TreeClick(Sender: TObject);
145
    procedure btnLoadClick(Sender: TObject);
144
    procedure btnLoadClick(Sender: TObject);
146
    procedure btnPasteCoverClick(Sender: TObject);
145
    procedure btnPasteCoverClick(Sender: TObject);
...
...
152
  private
151
  private
153
    FBookRecord: TBookRecord;
152
    FBookRecord: TBookRecord;
154
    FFolder: string;
153
    FFolder: string;
155
    
154
156
    procedure PrepareBookRecord;
155
    procedure PrepareBookRecord;
157
    procedure CommitData;
156
    procedure CommitData;
158
157
159
    procedure ScanFolder;
158
    procedure ScanFolder;
160
    procedure FillLists;
159
    procedure FillLists;
161
    procedure SortTree;
160
    procedure SortTree;
162
    function FillFBDData: boolean;
161
    function FillFBDData: Boolean;
163
  public
162
  public
164
163
165
  private
164
  private
166
    FLibrary: TMHLLibrary;
165
    FLibrary: TMHLLibrary;
167
    FRootPath: string;
166
    FRootPath: string;
168
    function CheckEmptyFields(Data: PFileData): boolean;
167
    function CheckEmptyFields(Data: PFileData): Boolean;
169
  end;
168
  end;
170
169
171
var
170
var
...
...
180
  unit_TreeUtils,
179
  unit_TreeUtils,
181
  unit_Consts,
180
  unit_Consts,
182
  unit_Settings,
181
  unit_Settings,
182
  unit_MHLHelpers,
183
  unit_Helpers,
183
  unit_Helpers,
184
  frm_author_list;
184
  frm_author_list;
185
186
{$R *.dfm}
185
{$R *.dfm}
187
186
188
procedure TfrmAddnonfb2.FillLists;
187
procedure TfrmAddnonfb2.FillLists;
...
...
212
211
213
procedure TfrmAddnonfb2.btnCopyToFamilyClick(Sender: TObject);
212
procedure TfrmAddnonfb2.btnCopyToFamilyClick(Sender: TObject);
214
var
213
var
215
  Author : TAuthorRecord;
214
  Author: TAuthorRecord;
216
begin
215
begin
217
  Author.Last := trim(edFileName.SelText);
216
  Author.Last := trim(edFileName.SelText);
218
  alBookAuthors.AddRow(Author);
217
  alBookAuthors.AddRow(Author);
...
...
220
219
221
procedure TfrmAddnonfb2.btnCopyToNameClick(Sender: TObject);
220
procedure TfrmAddnonfb2.btnCopyToNameClick(Sender: TObject);
222
var
221
var
223
  Author : TAuthorRecord;
222
  Author: TAuthorRecord;
224
begin
223
begin
225
  if alBookAuthors.Count > 0 then
224
  if alBookAuthors.Count > 0 then
226
  begin
225
  begin
227
    Author :=alBookAuthors.ActiveRecord;
226
    Author := alBookAuthors.ActiveRecord;
228
    Author.First := (trim(edFileName.SelText));
227
    Author.First := (trim(edFileName.SelText));
229
    alBookAuthors.ActiveRecord:= Author;
228
    alBookAuthors.ActiveRecord := Author;
230
  end;
229
  end;
231
end;
230
end;
232
231
...
...
246
  FreeAndNil(FLibrary);
245
  FreeAndNil(FLibrary);
247
  frmMain.DisableControls(True);
246
  frmMain.DisableControls(True);
248
  Settings.ForceConvertToFBD := cbForceConvertToFBD.Checked;
247
  Settings.ForceConvertToFBD := cbForceConvertToFBD.Checked;
249
  CanClose := true;
248
  CanClose := True;
250
end;
249
end;
251
250
252
procedure TfrmAddnonfb2.FormShow(Sender: TObject);
251
procedure TfrmAddnonfb2.FormShow(Sender: TObject);
...
...
269
  FBD.CoverSizeCode := 4;
268
  FBD.CoverSizeCode := 4;
270
end;
269
end;
271
270
272
function TfrmAddnonfb2.FillFBDData:boolean;
271
function TfrmAddnonfb2.FillFBDData: Boolean;
273
var
272
var
274
  I: Integer;
273
  I: Integer;
275
begin
274
begin
...
...
284
    FBD.AddSeries(sltBook, cbSeries.Text, Round(edSN.Value));
283
    FBD.AddSeries(sltBook, cbSeries.Text, Round(edSN.Value));
285
    Genre.Clear;
284
    Genre.Clear;
286
    for I := 0 to High(FBookRecord.Genres) do
285
    for I := 0 to High(FBookRecord.Genres) do
287
      Genre.Add(FBookRecord.Genres[i].GenreFb2Code);
286
      Genre.Add(FBookRecord.Genres[I].GenreFb2Code);
288
  end;
287
  end;
289
288
290
  FBD.SetAuthors(alFBDAuthors.Items, atlFBD);
289
  FBD.SetAuthors(alFBDAuthors.Items, atlFBD);
...
...
311
  edSN.Value := 0;
310
  edSN.Value := 0;
312
  edKeyWords.Text := '';
311
  edKeyWords.Text := '';
313
312
314
315
  edPublisher.Clear;
313
  edPublisher.Clear;
316
  edCity.Clear;
314
  edCity.Clear;
317
  edISBN.Clear;
315
  edISBN.Clear;
...
...
325
var
323
var
326
  Data: PFileData;
324
  Data: PFileData;
327
begin
325
begin
328
  Data := Tree.GetNodedata(Tree.GetFirstSelected);
326
  Data := Tree.GetNodeData(Tree.GetFirstSelected);
329
  if (Data = nil) or (Data.DataType = dtFolder) then
327
  if (Data = nil) or (Data.DataType = dtFolder) then
330
    Exit;
328
    Exit;
331
  ShellExecute(Handle, 'explore', PChar(AnsiLowercase(ExtractFilePath(Data.FullPath))), '', nil, SW_SHOWNORMAL);
329
  ShellExecute(Handle, 'explore', PChar(AnsiLowercase(ExtractFilePath(Data.FullPath))), '', nil, SW_SHOWNORMAL);
332
end;
330
end;
333
331
334
function TfrmAddnonfb2.CheckEmptyFields(Data: PFileData):boolean;
332
function TfrmAddnonfb2.CheckEmptyFields(Data: PFileData): Boolean;
335
begin
333
begin
336
  Result := False;
334
  Result := False;
337
  try
335
  try
...
...
351
349
352
procedure TfrmAddnonfb2.CommitData;
350
procedure TfrmAddnonfb2.CommitData;
353
var
351
var
354
  Next: PvirtualNode;
352
  Next: PVirtualNode;
355
  Data: PFileData;
353
  Data: PFileData;
356
begin
354
begin
357
  FLibrary.InsertBook(FBookRecord, True, True);
355
  FLibrary.InsertBook(FBookRecord, True, True);
...
...
363
  if Next <> nil then
361
  if Next <> nil then
364
    Tree.Selected[Next] := True;
362
    Tree.Selected[Next] := True;
365
  case cbClearOptions.ItemIndex of
363
  case cbClearOptions.ItemIndex of
366
    0: miClearAllClick(nil);
364
    0:
367
    1: alBookAuthors.Clear;
365
      miClearAllClick(nil);
366
    1:
367
      alBookAuthors.Clear;
368
    2:
368
    2:
369
      begin
369
      begin
370
        edT.Text := '';
370
        edT.Text := '';
...
...
376
  TreeChange(Tree, Next);
376
  TreeChange(Tree, Next);
377
377
378
  Data := Tree.GetNodeData(Next);
378
  Data := Tree.GetNodeData(Next);
379
  if (Data <> nil) and (Data.DataType = dtFile)  then
379
  if (Data <> nil) and (Data.DataType = dtFile) then
380
    pcPages.ActivePage := tsBookInfo
380
    pcPages.ActivePage := tsBookInfo
381
  else
381
  else
382
    pcPages.ActivePage := tsFiles;
382
    pcPages.ActivePage := tsFiles;
...
...
388
388
389
begin
389
begin
390
  Screen.Cursor := crHourGlass;
390
  Screen.Cursor := crHourGlass;
391
  frmAddNonFB2.Enabled := False;
391
  frmAddnonfb2.Enabled := False;
392
  try
392
  try
393
    PrepareBookRecord;
393
    PrepareBookRecord;
394
    if cbForceConvertToFBD.Checked then
394
    if cbForceConvertToFBD.Checked then
395
    begin
395
    begin
396
      FBD.New(FRootPath + FBookrecord.Folder, FBookrecord.FileName, FBookrecord.FileExt);
396
      FBD.New(FRootPath + FBookRecord.Folder, FBookRecord.FileName, FBookRecord.FileExt);
397
      if FillFBDData then
397
      if FillFBDData then
398
      begin
398
      begin
399
        FBD.Save(False);
399
        FBD.Save(False);
400
        FBookrecord.FileName := FBookrecord.FileName + ZIP_EXTENSION;
400
        FBookRecord.FileName := FBookRecord.FileName + ZIP_EXTENSION;
401
        CommitData;
401
        CommitData;
402
      end;
402
      end;
403
    end
403
    end
404
      else CommitData;
404
    else
405
      CommitData;
405
  finally
406
  finally
406
    frmAddNonFB2.Enabled := True;
407
    frmAddnonfb2.Enabled := True;
407
    Screen.Cursor := crDefault;
408
    Screen.Cursor := crDefault;
408
  end;
409
  end;
409
end;
410
end;
410
411
411
procedure TfrmAddnonfb2.miRenameFileClick(Sender: TObject);
412
procedure TfrmAddnonfb2.miRenameFileClick(Sender: TObject);
412
var
413
var
413
   NewName: string;
414
  NewName: string;
414
   Data: PFileData;
415
  Data: PFileData;
415
begin
416
begin
416
  btnRenameFile.Enabled := False;
417
  btnRenameFile.Enabled := False;
417
  try
418
  try
418
    Data := Tree.GetNodeData(Tree.GetFirstSelected);
419
    Data := Tree.GetNodeData(Tree.GetFirstSelected);
419
    if CheckEmptyFields(Data) then
420
    if CheckEmptyFields(Data) then
420
    begin
421
    begin
421
      NewName := CheckSymbols(alBookAuthors.ActiveRecord.Last + ' ' +  alBookAuthors.ActiveRecord.First +
422
      NewName := CheckSymbols(alBookAuthors.ActiveRecord.Last + ' ' + alBookAuthors.ActiveRecord.First + ' ' + edT.Text);
422
             ' ' + edT.Text);
423
      if RenameFile(Data.FullPath + Data.FileName + Data.Ext, Data.FullPath + NewName + Data.Ext) then
423
      if RenameFile(Data.FullPath + Data.FileName + Data.Ext, Data.FullPath + NewName + Data.Ext) then
424
      begin
424
      begin
425
        Data.FileName := NewName;
425
        Data.FileName := NewName;
426
        edFileName.Text := NewName;
426
        edFileName.Text := NewName;
427
        Tree.RepaintNode(Tree.GetFirstSelected);
427
        Tree.RepaintNode(Tree.GetFirstSelected);
428
      end
428
      end
429
      else MessageDlg('  !' + #13 +
429
      else
430
                    ',    .',
430
        MessageDlg('  !' + #13 + ',    .', mtError, [mbOk], 0);
431
                    mtError,[mbOk],0);
432
    end;
431
    end;
433
  finally
432
  finally
434
    btnRenameFile.Enabled := True;
433
    btnRenameFile.Enabled := True;
...
...
446
  Author: TAuthorRecord;
445
  Author: TAuthorRecord;
447
begin
446
begin
448
  Data := Tree.GetNodeData(Tree.GetFirstSelected);
447
  Data := Tree.GetNodeData(Tree.GetFirstSelected);
449
  if not CheckEmptyFields(Data) then Exit;
448
  if not CheckEmptyFields(Data) then
449
    Exit;
450
450
451
  if alBookAuthors.Count > 0 then
451
  if alBookAuthors.Count > 0 then
452
    for Author in alBookAuthors.Items do
452
    for Author in alBookAuthors.Items do
453
      FBookRecord.AddAuthor(Author.Last, Author.First, Author.Middle)
453
      FBookRecord.AddAuthor(Author.Last, Author.First, Author.Middle)
454
  else
454
    else
455
    FBookRecord.AddAuthor('','', '');
455
      FBookRecord.AddAuthor('', '', '');
456
456
457
  frmGenreTree.GetSelectedGenres(FBookRecord);
457
  frmGenreTree.GetSelectedGenres(FBookRecord);
458
  FBookRecord.Title := edT.Text;
458
  FBookRecord.Title := edT.Text;
...
...
465
  FBookRecord.FileExt := Data.Ext;
465
  FBookRecord.FileExt := Data.Ext;
466
  FBookRecord.Code := 0;
466
  FBookRecord.Code := 0;
467
  FBookRecord.InsideNo := 0;
467
  FBookRecord.InsideNo := 0;
468
  FBookRecord.SeqNumber := round(edSN.Value);
468
  FBookRecord.SeqNumber := Round(edSN.Value);
469
  FBookRecord.LibID := DMUser.ActiveCollection.ID;
469
  FBookRecord.LibID := DMUser.ActiveCollection.ID;
470
  FBookRecord.Deleted := False;
470
  FBookRecord.Deleted := False;
471
  FBookRecord.Size := Data.Size;
471
  FBookRecord.Size := Data.Size;
472
  FBookRecord.Date := Now;
472
  FBookRecord.Date := Now;
473
  FBookRecord.KeyWords := edKeyWords.Text;
473
  FBookRecord.Keywords := edKeyWords.Text;
474
  FBookRecord.Lang := cbLang.Text;
474
  FBookRecord.Lang := cbLang.Text;
475
end;
475
end;
476
476
477
procedure TfrmAddnonfb2.btnAddAuthorFromListClick(Sender: TObject);
477
procedure TfrmAddnonfb2.btnAddAuthorFromListClick(Sender: TObject);
478
var
478
var
479
  Row : TAuthorRecord;
479
  Row: TAuthorRecord;
480
  Data : PAuthorData;
480
  Data: PAuthorData;
481
  Node: PVirtualNode;
481
  Node: PVirtualNode;
482
begin
482
begin
483
  frmMain.FillAuthorTree(frmAuthorList.tvAuthorList, True);
483
  frmMain.FillAuthorTree(frmAuthorList.tvAuthorList, True);
484
  if frmAuthorList.ShowModal = mrOK then
484
  if frmAuthorList.ShowModal = mrOk then
485
  begin
485
  begin
486
    Node := frmAuthorList.tvAuthorList.GetFirstSelected;
486
    Node := frmAuthorList.tvAuthorList.GetFirstSelected;
487
    while node <> nil do
487
    while Node <> nil do
488
    begin
488
    begin
489
      Data := frmAuthorList.tvAuthorList.GetNodeData(Node);
489
      Data := frmAuthorList.tvAuthorList.GetNodeData(Node);
490
490
491
492
      Row.Last := Data.Last;
491
      Row.Last := Data.Last;
493
      Row.First := Data.First;
492
      Row.First := Data.First;
494
      Row.Middle := Data.Middle;
493
      Row.Middle := Data.Middle;
...
...
510
var
509
var
511
  FileName: string;
510
  FileName: string;
512
begin
511
begin
513
  if GetFileName(fnOpenCoverImage,FileName) then FBD.LoadCoverFromFile(FileName);
512
  if GetFileName(fnOpenCoverImage, FileName) then
513
    FBD.LoadCoverFromFile(FileName);
514
end;
514
end;
515
515
516
procedure TfrmAddnonfb2.btnNextClick(Sender: TObject);
516
procedure TfrmAddnonfb2.btnNextClick(Sender: TObject);
...
...
531
  ParentName: string;
531
  ParentName: string;
532
  Path: string;
532
  Path: string;
533
533
534
  procedure InsertNodeData(Node:PVirtualNode);
534
  procedure InsertNodeData(Node: PVirtualNode);
535
  begin
535
  begin
536
    Data := Tree.GetNodeData(Node);
536
    Data := Tree.GetNodeData(Node);
537
    Data.Title :=  ExtractFileName(ExcludeTrailingPathdelimiter(Path));
537
    Data.Title := ExtractFileName(ExcludeTrailingPathdelimiter(Path));
538
    Data.Folder := Path;
538
    Data.Folder := Path;
539
    Data.DataType := dtFolder;
539
    Data.DataType := dtFolder;
540
  end;
540
  end;
541
541
542
begin
542
begin
543
  Path := ExtractRelativePath(FRootPath, Dir);
543
  Path := ExtractRelativePath(FRootPath, Dir);
544
  if Path = '' then Exit;
544
  if Path = '' then
545
    Exit;
545
546
546
  ParentName := ExtractFilePath(ExcludeTrailingPathdelimiter(Path));
547
  ParentName := ExtractFilePath(ExcludeTrailingPathdelimiter(Path));
547
  ParentNode := FindParentInTree(Tree,ParentName);
548
  ParentNode := FindParentInTree(Tree, ParentName);
548
  if ParentNode <> nil then
549
  if ParentNode <> nil then
549
  begin
550
  begin
550
    CurrentNode := Tree.AddChild(ParentNode);
551
    CurrentNode := Tree.AddChild(ParentNode);
551
    InsertNodeData(CurrentNode);
552
    InsertNodeData(CurrentNode);
552
  end
553
  end
553
  else
554
  else if (FindParentInTree(Tree, Path) = nil) then
554
    if (FindParentInTree(Tree,Path) = nil) then
555
  begin
555
    begin
556
    CurrentNode := Tree.AddChild(Nil);
556
      CurrentNode := Tree.AddChild(Nil);
557
    InsertNodeData(CurrentNode);
557
      InsertNodeData(CurrentNode);
558
  end;
558
    end;
559
end;
559
end;
560
560
561
procedure TfrmAddnonfb2.flFilesFile(Sender: TObject; const F: TSearchRec);
561
procedure TfrmAddnonfb2.flFilesFile(Sender: TObject; const F: TSearchRec);
...
...
568
  CurrentNode: PVirtualNode;
568
  CurrentNode: PVirtualNode;
569
  Ext: string;
569
  Ext: string;
570
begin
570
begin
571
  if (F.Name = '.') or (F.Name = '..') then Exit;
571
  if (F.Name = '.') or (F.Name = '..') then
572
    Exit;
572
573
573
  Ext := ExtractFileExt(F.Name);
574
  Ext := ExtractFileExt(F.Name);
574
  if Ext = '' then Exit;
575
  if Ext = '' then
576
    Exit;
575
577
576
 //
578
  //
577
 //  fb2-  
 //
579
  //  fb2-  
  //
578
 if (CompareText(Ext, FB2_EXTENSION) = 0) or (CompareText(Ext, ZIP_EXTENSION) = 0) then
580
  if (CompareText(Ext, FB2_EXTENSION) = 0) or (CompareText(Ext, ZIP_EXTENSION) = 0) then
579
      Exit;
581
    Exit;
580
582
581
  //
583
  //
582
  // ,        
584
  // ,        
...
...
593
  FileName := ExtractShortFileName(F.Name);
595
  FileName := ExtractShortFileName(F.Name);
594
  Path := ExtractRelativePath(FRootPath, flFiles.LastDir);
596
  Path := ExtractRelativePath(FRootPath, flFiles.LastDir);
595
597
596
  ParentNode := FindParentInTree(Tree,Path);
598
  ParentNode := FindParentInTree(Tree, Path);
597
599
598
  CurrentNode := Tree.AddChild(ParentNode);
600
  CurrentNode := Tree.AddChild(ParentNode);
599
601
...
...
621
623
622
procedure TfrmAddnonfb2.SortTree;
624
procedure TfrmAddnonfb2.SortTree;
623
var
625
var
624
  A,B: PVirtualNode;
626
  A, B: PVirtualNode;
625
  Data,DataA,DataB: PFileData;
627
  Data, DataA, DataB: PFileData;
626
  Parent: PVirtualNode;
628
  Parent: PVirtualNode;
627
begin
629
begin
628
  Parent := Tree.GetFirst;
630
  Parent := Tree.GetFirst;
629
  Data := Tree.GetNodeData(Parent);
631
  Data := Tree.GetNodeData(Parent);
630
  while Parent <> nil do
632
  while Parent <> nil do
631
  begin
633
  begin
632
    if (Data.DataType = dtFolder) and
634
    if (Data.DataType = dtFolder) and (Tree.HasChildren[Parent]) then
633
       (Tree.HasChildren[Parent]) then
634
    begin
635
    begin
635
      A := Tree.GetFirstChild(Parent);
636
      A := Tree.GetFirstChild(Parent);
636
      while (A <> Parent.LastChild) do
637
      while (A <> Parent.LastChild) do
...
...
638
        DataA := Tree.GetNodeData(A);
639
        DataA := Tree.GetNodeData(A);
639
        B := Tree.GetNext(A);
640
        B := Tree.GetNext(A);
640
        DataB := Tree.GetNodeData(B);
641
        DataB := Tree.GetNodeData(B);
641
        if (A.Parent = B.Parent) and
642
        if (A.Parent = B.Parent) and (DataA.DataType = dtFile) and (DataB.DataType = dtFolder) then
642
           (DataA.DataType = dtFile) and
643
           (DataB.DataType = dtFolder) then
644
        begin
643
        begin
645
          Tree.MoveTo(B, A, amInsertBefore, false);
644
          Tree.MoveTo(B, A, amInsertBefore, False);
646
          A := Parent.FirstChild;
645
          A := Parent.FirstChild;
647
        end
646
        end
648
        else
647
        else
...
...
652
    end;
651
    end;
653
652
654
    if (Data.DataType = dtFolder) and (Parent.ChildCount = 0) then
653
    if (Data.DataType = dtFolder) and (Parent.ChildCount = 0) then
655
                  Tree.DeleteNode(Parent, True);
654
      Tree.DeleteNode(Parent, True);
656
655
657
    Parent := Tree.GetNext(Parent);
656
    Parent := Tree.GetNext(Parent);
658
    Data := Tree.GetNodeData(Parent);
657
    Data := Tree.GetNodeData(Parent);
...
...
664
  Data: PFileData;
663
  Data: PFileData;
665
  S: string;
664
  S: string;
666
begin
665
begin
667
  Data := Tree.GetNodedata(Tree.GetFirstSelected);
666
  Data := Tree.GetNodeData(Tree.GetFirstSelected);
668
  if Data <> nil then
667
  if Data <> nil then
669
  begin
668
  begin
670
    S := AnsiLowercase(Data.FullPath + Data.FileName + Data.Ext);
669
    S := AnsiLowercase(Data.FullPath + Data.FileName + Data.Ext);
671
    ShellExecute(Handle, 'open', PChar(s), '', nil, SW_SHOWNORMAL);
670
    ShellExecute(Handle, 'open', PChar(S), '', nil, SW_SHOWNORMAL);
672
  end;
671
  end;
673
end;
672
end;
674
673
...
...
677
  Close;
676
  Close;
678
end;
677
end;
679
678
680
procedure TfrmAddnonfb2.TreeChange(Sender: TBaseVirtualTree;
679
procedure TfrmAddnonfb2.TreeChange(Sender: TBaseVirtualTree; Node: PVirtualNode);
681
  Node: PVirtualNode);
682
680
683
begin
681
begin
684
  TreeClick(Sender);
682
  TreeClick(Sender);
...
...
686
684
687
procedure TfrmAddnonfb2.TreeClick(Sender: TObject);
685
procedure TfrmAddnonfb2.TreeClick(Sender: TObject);
688
var
686
var
689
  Data: PFiledata;
687
  Data: PFileData;
690
begin
688
begin
691
  Data := Tree.GetNodeData(Tree.GetFirstSelected);
689
  Data := Tree.GetNodeData(Tree.GetFirstSelected);
692
  if (Data = nil) or (Data.DataType = dtFolder) then
690
  if (Data = nil) or (Data.DataType = dtFolder) then
...
...
697
695
698
end;
696
end;
699
697
700
procedure TfrmAddnonfb2.TreeCompareNodes(Sender: TBaseVirtualTree; Node1,
698
procedure TfrmAddnonfb2.TreeCompareNodes(Sender: TBaseVirtualTree; Node1, Node2: PVirtualNode; Column: TColumnIndex; var Result: Integer);
701
  Node2: PVirtualNode; Column: TColumnIndex; var Result: Integer);
702
var
699
var
703
  Data1, Data2: PFileData;
700
  Data1, Data2: PFileData;
704
begin
701
begin
705
  Data1 := Sender.GetNodeData(Node1);
702
  Data1 := Sender.GetNodeData(Node1);
706
  Data2 := Sender.GetNodeData(Node2);
703
  Data2 := Sender.GetNodeData(Node2);
707
//  Result := CompareInt(Data1.DataType, Data1.DataType);
704
  // Result := CompareInt(Data1.DataType, Data1.DataType);
708
end;
705
end;
709
706
710
procedure TfrmAddnonfb2.TreeDblClick(Sender: TObject);
707
procedure TfrmAddnonfb2.TreeDblClick(Sender: TObject);
711
//var
708
// var
712
//  Data: PFileData;
709
// Data: PFileData;
713
//  S: string;
710
// S: string;
714
begin
711
begin
715
//  Data := Tree.GetNodedata(Tree.GetFirstSelected);
712
  // Data := Tree.GetNodedata(Tree.GetFirstSelected);
716
//  if Data <> nil then
713
  // if Data <> nil then
717
//  begin
714
  // begin
718
//    S := AnsiLowercase(Data.FullPath + Data.FileName + Data.Ext);
715
  // S := AnsiLowercase(Data.FullPath + Data.FileName + Data.Ext);
719
//    ShellExecute(Handle, 'open', PChar(s), '', nil, SW_SHOWNORMAL);
716
  // ShellExecute(Handle, 'open', PChar(s), '', nil, SW_SHOWNORMAL);
720
//  end;
717
  // end;
721
  pcPages.ActivePageIndex := 1;
718
  pcPages.ActivePageIndex := 1;
722
end;
719
end;
723
720
724
procedure TfrmAddnonfb2.TreeGetText(Sender: TBaseVirtualTree;
721
procedure TfrmAddnonfb2.TreeGetText(Sender: TBaseVirtualTree; Node: PVirtualNode; Column: TColumnIndex; TextType: TVSTTextType; var CellText: String);
725
  Node: PVirtualNode; Column: TColumnIndex; TextType: TVSTTextType;
726
  var CellText: String);
727
var
722
var
728
  Data: PFileData;
723
  Data: PFileData;
729
begin
724
begin
730
  Data := Sender.GetNodeData(Node);
725
  Data := Sender.GetNodeData(Node);
731
  case Data.DataType of
726
  case Data.DataType of
732
    dtFolder: if Column = 0 then CellText := Data.Title
727
    dtFolder:
733
                else  CellText := '';
728
      if Column = 0 then
734
    dtFile:  case Column of
729
        CellText := Data.Title
735
               0: CellText := Data.FileName;
730
      else
736
               1: CellText := CleanExtension(Data.Ext);
731
        CellText := '';
737
               2: CellText := IntToStr(Data.Size);
732
    dtFile:
738
               3: CellText := '';
733
      case Column of
739
             end;
734
        0: CellText := Data.FileName;
735
        1: CellText := CleanExtension(Data.Ext);
736
        2: CellText := GetFormattedSize(Data.Size);
737
        3: CellText := '';
738
      end;
740
  end;
739
  end;
741
end;
740
end;
742
741
743
procedure TfrmAddnonfb2.TreePaintText(Sender: TBaseVirtualTree;
742
procedure TfrmAddnonfb2.TreePaintText(Sender: TBaseVirtualTree; const TargetCanvas: TCanvas; Node: PVirtualNode; Column: TColumnIndex; TextType: TVSTTextType);
744
  const TargetCanvas: TCanvas; Node: PVirtualNode; Column: TColumnIndex;
745
  TextType: TVSTTextType);
746
var
743
var
747
  Data: PFileData;
744
  Data: PFileData;
748
begin
745
begin
...
...
752
end;
749
end;
753
750
754
end.
751
end.
755

Updated trunk/Forms/frm_bases.pas Download diff

464465
230
var
230
var
231
  AFolder: string;
231
  AFolder: string;
232
begin
232
begin
233
  AFolder := edCollectionRoot.Text;
233
  if GetFolderName(Handle, '    ', AFolder) then
234
  if GetFolderName(Handle, '    ', AFolder) then
234
    edCollectionRoot.Text := AFolder;
235
    edCollectionRoot.Text := AFolder;
235
end;
236
end;

Updated trunk/Forms/frm_book_info.dfm Download diff

464465
1
object frmBookDetails: TfrmBookDetails
1
object frmBookDetails: TfrmBookDetails
2
  Left = 0
2
  Left = 0
3
  Top = 0
3
  Top = 0
4
  ActiveControl = RzPageControl1
4
  ActiveControl = pcBookInfo
5
  Caption = #1048#1085#1092#1086#1088#1084#1072#1094#1080#1103' '#1086' '#1082#1085#1080#1075#1077
5
  Caption = #1048#1085#1092#1086#1088#1084#1072#1094#1080#1103' '#1086' '#1082#1085#1080#1075#1077
6
  ClientHeight = 481
6
  ClientHeight = 481
7
  ClientWidth = 628
7
  ClientWidth = 628
...
...
17
  OnShow = FormShow
17
  OnShow = FormShow
18
  PixelsPerInch = 96
18
  PixelsPerInch = 96
19
  TextHeight = 13
19
  TextHeight = 13
20
  object RzPageControl1: TPageControl
20
  object pcBookInfo: TPageControl
21
    AlignWithMargins = True
21
    AlignWithMargins = True
22
    Left = 3
22
    Left = 3
23
    Top = 53
23
    Top = 53
24
    Width = 622
24
    Width = 622
25
    Height = 388
25
    Height = 388
26
    ActivePage = tsInfo
26
    ActivePage = tsFileInfo
27
    Align = alClient
27
    Align = alClient
28
    DoubleBuffered = True
28
    DoubleBuffered = True
29
    ParentDoubleBuffered = False
29
    ParentDoubleBuffered = False
30
    TabOrder = 0
30
    TabOrder = 0
31
    object tsFileInfo: TTabSheet
32
      Caption = #1060#1072#1081#1083
33
      ImageIndex = 2
34
      object lvFileInfo: TListView
35
        AlignWithMargins = True
36
        Left = 3
37
        Top = 3
38
        Width = 608
39
        Height = 354
40
        Align = alClient
41
        Columns = <
42
          item
43
            Caption = #1055#1086#1083#1077
44
            Width = 175
45
          end
46
          item
47
            Caption = #1047#1085#1072#1095#1077#1085#1080#1077
48
            Width = 150
49
          end>
50
        ColumnClick = False
51
        GroupView = True
52
        ReadOnly = True
53
        RowSelect = True
54
        PopupMenu = pmBookInfo
55
        TabOrder = 0
56
        ViewStyle = vsReport
57
      end
58
    end
31
    object tsInfo: TTabSheet
59
    object tsInfo: TTabSheet
32
      Caption = 'Fb2 '#1080#1085#1092#1086
60
      Caption = 'Fb2 '#1080#1085#1092#1086
33
      ExplicitLeft = 0
61
      ExplicitLeft = 0
...
...
82
        GroupView = True
110
        GroupView = True
83
        ReadOnly = True
111
        ReadOnly = True
84
        RowSelect = True
112
        RowSelect = True
113
        PopupMenu = pmBookInfo
85
        TabOrder = 1
114
        TabOrder = 1
86
        ViewStyle = vsReport
115
        ViewStyle = vsReport
87
      end
116
      end
...
...
184
      AlignWithMargins = True
213
      AlignWithMargins = True
185
      Left = 9
214
      Left = 9
186
      Top = 28
215
      Top = 28
187
      Width = 47
216
      Width = 610
188
      Height = 13
217
      Height = 13
189
      Align = alTop
218
      Align = alTop
190
      Caption = #1040#1074#1090#1086#1088'('#1099')'
219
      Caption = #1040#1074#1090#1086#1088'('#1099')'
191
      ShowAccelChar = False
220
      ShowAccelChar = False
192
      Transparent = True
221
      Transparent = True
222
      ExplicitWidth = 47
193
    end
223
    end
194
    object lblTitle: TLabel
224
    object lblTitle: TLabel
195
      AlignWithMargins = True
225
      AlignWithMargins = True
196
      Left = 9
226
      Left = 9
197
      Top = 9
227
      Top = 9
198
      Width = 55
228
      Width = 610
199
      Height = 13
229
      Height = 13
200
      Align = alTop
230
      Align = alTop
201
      Caption = #1053#1072#1079#1074#1072#1085#1080#1077
231
      Caption = #1053#1072#1079#1074#1072#1085#1080#1077
...
...
206
      Font.Style = [fsBold]
236
      Font.Style = [fsBold]
207
      ParentFont = False
237
      ParentFont = False
208
      ShowAccelChar = False
238
      ShowAccelChar = False
239
      ExplicitWidth = 55
209
    end
240
    end
210
  end
241
  end
242
  object pmBookInfo: TPopupMenu
243
    Left = 64
244
    Top = 120
245
    object miCopyValue: TMenuItem
246
      Action = acCopyValue
247
    end
248
  end
249
  object alBookInfo: TActionList
250
    Left = 136
251
    Top = 120
252
    object acCopyValue: TAction
253
      Caption = #1050#1086#1087#1080#1088#1086#1074#1072#1090#1100
254
      Hint = #1050#1086#1087#1080#1088#1086#1074#1072#1090#1100' '#1079#1085#1072#1095#1077#1085#1080#1077' '#1074' '#1073#1091#1092#1092#1077#1088'
'#1086#1073#1084#1077#1085#1072
255
      ShortCut = 16451
256
      OnExecute = acCopyValueExecute
257
      OnUpdate = acCopyValueUpdate
258
    end
259
  end
211
end
260
end

Updated trunk/Forms/frm_book_info.pas Download diff

File was changed - ok, show the diff

Updated trunk/Forms/frm_create_mask.pas Download diff

File was changed - ok, show the diff

Updated trunk/Forms/frm_settings.pas Download diff

File was changed - ok, show the diff

Updated trunk/ImportImpl/unit_ImportFB2ThreadBase.pas Download diff

File was changed - ok, show the diff

Updated trunk/ImportImpl/unit_ImportInpxThread.pas Download diff

File was changed - ok, show the diff

Updated trunk/Units/unit_Globals.pas Download diff

File was changed - ok, show the diff

Updated trunk/Units/unit_Templater.pas Download diff

File was changed - ok, show the diff