⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 preximclasses.pas

📁 一个很好的学习例子,有需要的请下载研究,
💻 PAS
📖 第 1 页 / 共 5 页
字号:
{
********************************************************************************
*                                                                              * 
*             (c) China Systems 1999 - 2003                                    *   
*                                                                              *
*               Prexim Imaging development team.                               * 
*                                                                              * 
********************************************************************************
*
* Unit Name: PrEximClasses.pas
* Author:    Licwing
* Purpose:   Provides several inherited relationship objects depend on E-paper
             stored model under buniess mode.
********************************************************************************
}
unit PrEximClasses;
//=============================================================================
{* |<PRE>
 Unit name: PrEximClasses.pas
 Author:    Licwing
 Purpose:   Provides several inherited relationship objects depend on E-page
            stored model under buniess mode. See below:
            
  TFolderList: Only a object list, contains one or more folder instances
    |_ Folder: contains own information in Keys, and maintains revelant transactions dependent it
        |_ Transaction: contains own information in Keys, and maintains revelant documents dependent it
            |_ Document: contains own information in Keys, and maintains revelant pages dependent it
                |_ Page: contains own information in Keys, contains page's data if property KeepPageInStream is true

  TPageList: Only a objectList, contains one or more page instances
     |_ Pages
     
 Develop Platform:  Win2K pro & sp3 + delphi6 & patch2
 Test Platform: 
 History:
   08-12-2003  V1.0  by Licwing
     -> first version
   08-18-2003  V1.1  by Licwing
     -> Implement two methods: LoadFromStream and SaveToStream, in class named
        TCustomStorageObject. All descendants of TCustomStorageObject must
        implement ReadData nad WriteData methods to manipulate how to load data
        from stream of save data to stream.
     -> Notice that the name of key is Case-Sensitive
     -> It is default that read data of a file associated by property: Filename
        and save to a stream while method WriteData called. You can set property:
        KeepPageInStream to false if you want only save page's information.

        On the other hand, you must specify a path on your local system if you
        want to Call method LoadFromPage or ReadData and KeepPageInStream is true.

        TCustomStorageObject has a property named PageStoredPath, you can set it
        to avoid to manual manipulate every instance of TPage in where savee file.
        But you must notice this is only available when you called method New,
        not method Add. You must manual set the property of TPage: StoredPath if
        you called method Add not method New.
   09-18-2003 V1.2 by Licwing
     -> Add two classes: TNote and THistory
     -> Add a property: BusinessState at TCustomStorageObject
|</PRE>}         
//==============================================================================

interface

uses
  Classes, SysUtils, Contnrs, SyncObjs,
  // PrExim Module
  PrEximFileUtils;

type
  TStorageObjectLevel = (solNone, solFolder, solTransaction, solDocument, solPage);
  TKeyStatus = (ksSystem, ksUser);
  TOperateStatus = (opNone, opMove, opMoveFax, opInsert, opDelete, opEdit);
  TBusinessState = (bsNone, bsSend, bsResend, bsRejected, bsRelease, bsSave);

  TCustomStorageObject = class;
  TPage = class;
  TDocument = class;
  TTransaction = class;
  TFolder = class;

  TKey = class(TCollectionItem)
  private
    FName: string;
    FValue: string;
    FStatus: TKeyStatus;
    FIsShow: boolean;
    procedure SetName(const Value: string);
    procedure SetValue(const Value: string);
    procedure SetStatus(const Value: TKeyStatus);
    procedure SetIsShow(const Value: boolean);
  protected
    procedure ReadData(Reader : TReader); dynamic;
    procedure WriteData(Writer : TWriter); dynamic;
  public
    constructor Create(ACollection: TCollection); override;
    destructor Destroy; override;
  published
    property Name: string read FName write SetName;
    property Value: string read FValue write SetValue;
    property Status: TKeyStatus read FStatus write SetStatus;
    property IsShow: boolean read FIsShow write SetIsShow;
  end;

  TKeys = class(TOwnedCollection)
  private
    FSync: TCriticalSection;
    function GetByKeyName(const AKeyName: string): TKey;
    function GetKey(const AIndex: Integer): TKey;
    procedure SetKey(const AIndex: Integer; const Value: TKey);
  protected
    FCaseSensitiveKeynames: Boolean;
    procedure NotifyChanged;
  public
    constructor Create(AOwner: TCustomStorageObject);
    destructor Destroy; override;

    function Add: TKey; reintroduce;

    procedure WriteData(Writer : TWriter);
    procedure ReadData(Reader : TReader);

    property Keys[const AKeyName: string]: TKey read GetByKeyName; default;
    property Items[const AIndex: Integer]: TKey read GetKey write SetKey;

  published
    property CaseSensitiveKeynames: Boolean read FCaseSensitiveKeynames
      write FCaseSensitiveKeynames;
  end;

  TNote = class(TCollectionItem)
  private
    FAuthor: string;
    FLocation: string;
    FNote: string;
    FWhen: TDateTime;
    FOperateStatus: TOperateStatus;
    procedure SetAuthor(const Value: string);
    procedure SetLocation(const Value: string);
    procedure SetNote(const Value: string);
    procedure SetWhen(const Value: TDateTime);
    procedure SetOperateStatus(const Value: TOperateStatus);
  protected
    procedure ReadData(Reader : TReader); dynamic;
    procedure WriteData(Writer : TWriter); dynamic;
  public
    constructor Create(ACollection: TCollection); override;
    destructor Destroy; override;
  published
    property Author: string read FAuthor write SetAuthor;
    property Location: string read FLocation write SetLocation;
    property Note: string read FNote write SetNote;
    property When: TDateTime read FWhen write SetWhen;
    property OperateStatus: TOperateStatus read FOperateStatus write SetOperateStatus;
  end;

  TNotes = class(TOwnedCollection)
  private
    function GetNote(const AIndex: Integer): TNote;
    procedure SetNote(const AIndex: Integer; const Value: TNote);
  protected
    procedure NotifyChanged;
  public
    function Add: TNote; reintroduce;
    constructor Create(AOwner: TCustomStorageObject);

    procedure WriteData(Writer : TWriter);
    procedure ReadData(Reader : TReader);

    procedure ResetOperateStatus;
    property Items[const AIndex: Integer]: TNote read GetNote write SetNote;
  end;

  THistory = class(TCollectionItem)
  private
    FLog: string;
    FOperator: string;
    FLocation: string;
    FWhen: TDateTime;
    procedure SetLocation(const Value: string);
    procedure SetLog(const Value: string);
    procedure SetOperator(const Value: string);
    procedure SetWhen(const Value: TDateTime);
  protected
    procedure ReadData(Reader : TReader); dynamic;
    procedure WriteData(Writer : TWriter); dynamic;
  public
    constructor Create(ACollection: TCollection); override;
    destructor Destroy; override;
  published
    property Operator: string read FOperator write SetOperator;
    property Location: string read FLocation write SetLocation;
    property Log: string read FLog write SetLog;
    property When: TDateTime read FWhen write SetWhen;
  end;

  THistorys = class(TOwnedCollection)
  private
    function GetHistory(const AIndex: Integer): THistory;
    procedure SetHistory(const AIndex: Integer; const Value: THistory);
  protected
    procedure NotifyChanged;
  public
    function Add: THistory; reintroduce;
    constructor Create(AOwner: TCustomStorageObject);

    procedure WriteData(Writer : TWriter);
    procedure ReadData(Reader : TReader);

    property Items[const AIndex: Integer]: THistory read GetHistory write SetHistory;
  end;


  TBaseStorageObject = class (TPersistent)
  protected
    procedure ReadData(Reader : TReader); dynamic; abstract;
    procedure WriteData(Writer : TWriter); dynamic; abstract;

    procedure SaveToStream(Stream : TStream); dynamic; abstract;
    procedure LoadFromStream(Stream : TStream); dynamic; abstract;
  public
    constructor Create; virtual; abstract;
  end;

  TCustomStorageObject = class (TBaseStorageObject)
  private
    FKeys: TKeys;                       // store parameters
    FPageStoredPath: string;
    FKeepPageInStream: boolean;
    FParent: TCustomStorageObject;
    FOperateStatus: TOperateStatus;
    FBusinessState: TBusinessState;
    FObjectLevel: TStorageObjectLevel;
    procedure SetKeys(const Value: TKeys);
    function GetCaseSensitiveKeynames: Boolean;
    procedure SetCaseSensitiveKeynames(const Value: Boolean);
    procedure SetKeepPageInStream(const Value: boolean); virtual;
  protected
    procedure ReadData(Reader : TReader); override;
    procedure WriteData(Writer : TWriter); override;

    procedure ChangeOperateStatus; virtual;
  public
    constructor Create; override;
    destructor Destroy; override;

    function Modified: boolean; virtual;
    procedure ResetOperateStatus; virtual;

    procedure SaveToStream(Stream : TStream); override;
    procedure LoadFromStream(Stream : TStream); override;
  published
    property Keys: TKeys read FKeys write SetKeys;
    {* Stored relevant parameters of a TCustomStorageObject instance}
    property CaseSensitiveKeynames: Boolean read GetCaseSensitiveKeynames
      write SetCaseSensitiveKeynames;
    property PageStoredPath: string read FPageStoredPath write FPageStoredPath;
    {* The path where pages saved. The page will not be saved if this property is
    unassigned}
    property OperateStatus: TOperateStatus read FOperateStatus write FOperateStatus;
    property BusinessState: TBusinessState read FBusinessState write FBusinessState;
    property Level: TStorageObjectLevel read FObjectLevel;
    {* Indicates the instance's level}
    property KeepPageInStream: boolean read fKeepPageInStream write SetKeepPageInStream;
  end;

  TPage = class(TCustomStorageObject)
  private
    FStoredPath: string;  // file stored path name
    FFileName: TFilename; // file name
    FCaption: string;  // the file name for displaying
//    FKeepPageInStream: boolean;
    procedure SetFilename(const Value: TFilename);
    procedure SetStoredPath(const Value: string);
    procedure SetParent(const Value: TDocument);
    function GetParent: TDocument;
    procedure SetCaption(const Value: string);
    function GetExisted: boolean;
  protected
    procedure ReadData(Reader : TReader); override;
    procedure WriteData(Writer : TWriter); override;
  public
    constructor Create; override;

    function Modified: boolean; override;

    // stored properties value and file to a stream
    procedure SaveToStream(Stream : TStream); override;
    // load properties value and file from a stream
    procedure LoadFromStream(Stream : TStream); override;
  published
    property StoredPath: string read FStoredPath write SetStoredPath;
    {* The path where the page saved}
    property Filename: TFilename read FFilename write SetFilename;
    {* Page's filename, not included path}
    property Caption: string read FCaption write SetCaption;
    //property KeepPageInStream: boolean read fKeepPageInStream write fKeepPageInStream;
    {* Indicates whether the page is kept in stream or not}
    property FileExisted: boolean read GetExisted;
    property Parent: TDocument read GetParent write SetParent;
  end;

  TDocument = class(TCustomStorageObject)
  {* Document object, contained all page items are belonged to it}
  private
    FPages:  TObjectList;
    function GetItem(Index: Integer): TPage;
    procedure SetItem(Index: Integer; const Value: TPage);
    procedure SetParent(const Value: TTransaction);
    function GetParent: TTransaction;
    procedure SetKeepPageInStream(const Value: boolean); override;
  protected
    procedure ReadData(Reader : TReader); override;
    procedure WriteData(Writer : TWriter); override;
  public
    constructor Create; override;
    destructor Destroy; override;

    function Modified: boolean; override;
    procedure ResetOperateStatus; override;

    function PagesCount: integer;
    function Add(APage: TPage): Integer;
    function Extract(Item: TPage): TPage;
    function New: TPage;
    function Remove(APage: TPage): Integer;
    function IndexOf(APage: TPage): Integer;
    procedure Insert(Index: Integer; APage: TPage);
    procedure Clear;
    property Items[Index: Integer]: TPage read GetItem write SetItem; default;

    //property KeepPageInStream: boolean read fKeepPageInStream write SetKeepPageInStream;
    property Parent: TTransaction read GetParent write SetParent;
  end;

  TTransaction = class(TCustomStorageObject)
  {* Transaction object, contained all document items are belonged to it}
  private
    FDocuments:  TObjectList;
    FNotes: TNotes;
    FHistorys: THistorys;
    function GetItem(Index: Integer): TDocument;
    procedure SetItem(Index: Integer; const Value: TDocument);
    procedure SetParent(const Value: TFolder);
    function GetParent: TFolder;
    procedure SetKeepPageInStream(const Value: boolean); override;
    procedure SetHistorys(const Value: THistorys);
    procedure SetNotes(const Value: TNotes);
  protected
    procedure ReadData(Reader : TReader); override;
    procedure WriteData(Writer : TWriter); override;
  public
    constructor Create; override;
    destructor Destroy; override;

    function Modified: boolean; override;
    procedure ResetOperateStatus; override;

    function DocumentsCount: integer;
    function Add(ADocument: TDocument): Integer;
    function Extract(Item: TDocument): TDocument;
    function New: TDocument;
    function Remove(ADocument: TDocument): Integer;
    function IndexOf(ADocument: TDocument): Integer;
    procedure Insert(Index: Integer; ADocument: TDocument);
    procedure Clear;
    property Items[Index: Integer]: TDocument read GetItem write SetItem; default;

    property Notes: TNotes read FNotes write SetNotes;
    property Histories: THistorys read FHistorys write SetHistorys;
    //property KeepPageInStream: boolean read fKeepPageInStream write SetKeepPageInStream;
    property Parent: TFolder read GetParent write SetParent;
  end;

  TFolder = class(TCustomStorageObject)
  {* Folder object, contained all transaction items are belonged to it}
  private
    FTransactions:  TObjectList;
    function GetItem(Index: Integer): TTransaction;
    procedure SetItem(Index: Integer; const Value: TTransaction);
    procedure SetKeepPageInStream(const Value: boolean); override;
  protected
    procedure ReadData(Reader : TReader); override;
    procedure WriteData(Writer : TWriter); override;
  public
    constructor Create; override;
    destructor Destroy; override;

    function Modified: boolean; override;
    procedure ResetOperateStatus; override;

    function TransactionsCount: integer;
    function Add(ATransaction: TTransaction): Integer;
    function Extract(Item: TTransaction): TTransaction;
    function New: TTransaction;
    function Remove(ATransaction: TTransaction): Integer;
    function IndexOf(ATransaction: TTransaction): Integer;
    procedure Insert(Index: Integer; ATransaction: TTransaction);
    procedure Clear;
    property Items[Index: Integer]: TTransaction read GetItem write SetItem; default;

    //property KeepPageInStream: boolean read fKeepPageInStream write SetKeepPageInStream;
  end;

  TStreamObjectList = class(TObjectList)
  private
    fPageStoredPath: string;
    fKeepPageInStream: boolean;
    procedure SetKeepPageInStream(const Value: boolean);
  protected
    procedure ReadData(Reader : TReader); dynamic; abstract;
    procedure WriteData(Writer : TWriter); dynamic; abstract;
  public
    constructor Create; overload;

    function Modified: boolean; virtual;
    procedure ResetOperateStatus; virtual;

    procedure SaveToStream(Stream : TStream);
    procedure LoadFromStream(Stream : TStream);
    property PageStoredPath: string read fPageStoredPath write fPageStoredPath; 
    property KeepPageInStream: boolean read fKeepPageInStream write SetKeepPageInStream;
  end;
  
  TFolderList = class(TStreamObjectList)
  {* A list contained folder items}
  private
    function GetItem(Index: Integer): TFolder;
    procedure SetItem(Index: Integer; const Value: TFolder);
  protected
    procedure ReadData(Reader : TReader); override;
    procedure WriteData(Writer : TWriter); override;
  public
    function Add(AFolder: TFolder): Integer;
    function Extract(Item: TFolder): TFolder;
    function Remove(AFolder: TFolder): Integer;
    function New: TFolder;
    function IndexOf(AFolder: TFolder): Integer;
    procedure Insert(Index: Integer; AFolder: TFolder);
    function First: TFolder;
    function Last: TFolder;
    property Items[Index: Integer]: TFolder read GetItem write SetItem; default;
  end;

  TTransactionList = class(TStreamObjectList)
  {* A list contained folder items}
  private
    function GetItem(Index: Integer): TTransaction;
    procedure SetItem(Index: Integer; const Value: TTransaction);
  protected
    procedure ReadData(Reader : TReader); override;
    procedure WriteData(Writer : TWriter); override;
  public
    function Add(ATransaction: TTransaction): Integer;
    function Extract(Item: TTransaction): TTransaction;
    function Remove(ATransaction: TTransaction): Integer;
    function New: TTransaction;
    function IndexOf(ATransaction: TTransaction): Integer;
    procedure Insert(Index: Integer; ATransaction: TTransaction);
    function First: TTransaction;
    function Last: TTransaction;
    property Items[Index: Integer]: TTransaction read GetItem write SetItem; default;
  end;

  TPageList = class(TStreamObjectList)
  {* A list contained Page items}
  private
    function GetItem(Index: Integer): TPage;
    procedure SetItem(Index: Integer; const Value: TPage);
  protected
    procedure ReadData(Reader : TReader); override;
    procedure WriteData(Writer : TWriter); override;
  public
    function Add(APage: TPage): Integer;
    function Extract(Item: TPage): TPage;
    function Remove(APage: TPage): Integer;
    function New: TPage;
    function IndexOf(APage: TPage): Integer;
    procedure Insert(Index: Integer; APage: TPage);
    function First: TPage;
    function Last: TPage;
    property Items[Index: Integer]: TPage read GetItem write SetItem; default;
  end;

  TDocumentList = class(TStreamObjectList)
  private
    function GetItem(Index: Integer): TDocument;
    procedure SetItem(Index: Integer; const Value: TDocument);
  protected
    procedure ReadData(Reader : TReader); override;
    procedure WriteData(Writer : TWriter); override;
  public
    function Add(ADocument: TDocument): Integer;
    function Extract(Item: TDocument): TDocument;
    function Remove(ADocument: TDocument): Integer;
    function New: TDocument;
    function IndexOf(ADocument: TDocument): Integer;
    procedure Insert(Index: Integer; ADocument: TDocument);
    function First: TDocument;
    function Last: TDocument;
    property Items[Index: Integer]: TDocument read GetItem write SetItem; default;
  end;


implementation

uses Windows;

{ TKey }

constructor TKey.Create(ACollection: TCollection);
begin
  inherited Create(ACollection);

  FName  := '';
  FValue := '';
  FStatus := ksSystem;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -