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

📄 jcleditranslators.pas

📁 East make Tray Icon in delphi
💻 PAS
📖 第 1 页 / 共 2 页
字号:
{**************************************************************************************************}
{                                                                                                  }
{ Project JEDI Code Library (JCL)                                                                  }
{                                                                                                  }
{ The contents of this file are subject to the Mozilla Public License Version 1.1 (the "License"); }
{ you may not use this file except in compliance with the License. You may obtain a copy of the    }
{ License at http://www.mozilla.org/MPL/                                                           }
{                                                                                                  }
{ Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF   }
{ ANY KIND, either express or implied. See the License for the specific language governing rights  }
{ and limitations under the License.                                                               }
{                                                                                                  }
{ The Original Code is JclEDITranslators.pas.                                                      }
{                                                                                                  }
{ The Initial Developer of the Original Code is Raymond Alexander.                                 }
{ Portions created by Raymond Alexander are Copyright Raymond Alexander. All rights reserved.      }
{                                                                                                  }
{ Contributor(s):                                                                                  }
{   Raymond Alexander, Robert Marquardt, Robert Rossmair                                           }
{                                                                                                  }
{**************************************************************************************************}
{                                                                                                  }
{ EDI Translators Unit for classes that translate EDI objects from one format to another.          }
{                                                                                                  }
{ This unit is still in development                                                                }
{                                                                                                  }
{ Unit owner: Raymond Alexander                                                                    }
{ Last created: October 2, 2003                                                                    }
{ Additional Info:                                                                                 }
{   E-Mail at RaysDelphiBox3 att hotmail dott com                                                  }
{   For latest EDI specific demos see http://sourceforge.net/projects/edisdk                       }
{   See home page for latest news & events and online help.                                        }
{                                                                                                  }
{**************************************************************************************************}

// $Id: JclEDITranslators.pas,v 1.14 2005/02/24 16:34:39 marquardt Exp $

unit JclEDITranslators;

{$I jcl.inc}

{$IFDEF SUPPORTS_WEAKPACKAGEUNIT}
  {$WEAKPACKAGEUNIT ON}
{$ENDIF SUPPORTS_WEAKPACKAGEUNIT}

interface

uses
  SysUtils, 
  JclEDI, JclEDI_ANSIX12, JclEDISEF;

type
  TEDISpecToSEFTranslator = class(TEDIObject)
  public
    constructor Create;
    destructor Destroy; override;
    function TranslateToSEFElement(ElementSpec: TEDIElementSpec;
      Parent: TEDISEFFile): TEDISEFElement; overload;
    function TranslateToSEFElement(ElementSpec: TEDIElementSpec;
      Parent: TEDISEFSegment): TEDISEFElement; overload;
    procedure TranslateToSEFElementTEXTSETS(ElementSpec: TEDIElementSpec;
      SEFElement: TEDISEFElement);
    function TranslateToSEFSegment(SegmentSpec: TEDISegmentSpec;
      Parent: TEDISEFFile): TEDISEFSegment; overload;
    function TranslateToSEFSegment(SegmentSpec: TEDISegmentSpec;
      Parent: TEDISEFTable): TEDISEFSegment; overload;
    function TranslateToSEFSegment(SegmentSpec: TEDISegmentSpec;
      Parent: TEDISEFLoop): TEDISEFSegment; overload;
    procedure TranslateToSEFSegmentTEXTSETS(SegmentSpec: TEDISegmentSpec;
      SEFSegment: TEDISEFSegment);
    function TranslateToSEFSet(TransactionSetSpec: TEDITransactionSetSpec;
      Parent: TEDISEFFile): TEDISEFSet;
    procedure TranslateLoopToSEFSet(StackRecord: TEDILoopStackRecord;
      SegmentId, OwnerLoopId, ParentLoopId: string; var EDIObject: TEDIObject);
    function TranslateToSEFFile(ICSpec: TEDIInterchangeControlSpec): TEDISEFFile;
  end;

  TEDISEFToSpecTranslator = class(TEDIObject)
  public
    constructor Create;
    destructor Destroy; override;
  end;

implementation

uses
  JclStrings;

//=== { TEDISpecToSEFTranslator } ============================================

constructor TEDISpecToSEFTranslator.Create;
begin
  inherited Create;
end;

destructor TEDISpecToSEFTranslator.Destroy;
begin
  inherited Destroy;
end;

function TEDISpecToSEFTranslator.TranslateToSEFElement(ElementSpec: TEDIElementSpec;
  Parent: TEDISEFFile): TEDISEFElement;
begin
  Result := TEDISEFElement.Create(Parent);
  Result.Id := ElementSpec.Id;
  Result.ElementType := ElementSpec.ElementType;
  Result.MinimumLength := ElementSpec.MinimumLength;
  Result.MaximumLength := ElementSpec.MaximumLength;
end;

function TEDISpecToSEFTranslator.TranslateToSEFElement(ElementSpec: TEDIElementSpec;
  Parent: TEDISEFSegment): TEDISEFElement;
var
  ListItem: TEDISEFDataObjectListItem;
begin
  Result := TEDISEFElement.Create(Parent);
  Result.Id := ElementSpec.Id;
  ListItem := Parent.SEFFile.ELMS.FindItemByName(ElementSpec.Id);
  if ListItem <> nil then
    Result.Assign(TEDISEFElement(ListItem.EDISEFDataObject))
  else
  begin
    Result.ElementType := ElementSpec.ElementType;
    Result.MinimumLength := ElementSpec.MinimumLength;
    Result.MaximumLength := ElementSpec.MaximumLength;
    Result.RequirementDesignator := ElementSpec.RequirementDesignator;
  end;
end;

function TEDISpecToSEFTranslator.TranslateToSEFSegment(SegmentSpec: TEDISegmentSpec;
  Parent: TEDISEFFile): TEDISEFSegment;
var
  E: Integer;
  ElementSpec: TEDIElementSpec;
  SEFElement: TEDISEFElement;
begin
  Result := TEDISEFSegment.Create(Parent);
  Result.Id := SegmentSpec.Id;
  Result.RequirementDesignator := SegmentSpec.RequirementDesignator;
  Result.MaximumUse := SegmentSpec.MaximumUsage;
  for E := 0 to SegmentSpec.ElementCount - 1 do
  begin
    ElementSpec := TEDIElementSpec(SegmentSpec[E]);
    SEFElement := TranslateToSEFElement(ElementSpec, Result);
    Result.Elements.Add(SEFElement);
  end;
end;

function TEDISpecToSEFTranslator.TranslateToSEFSegment(SegmentSpec: TEDISegmentSpec;
  Parent: TEDISEFTable): TEDISEFSegment;
var
  ListItem: TEDISEFDataObjectListItem;
begin
  Result := TEDISEFSegment.Create(Parent);
  Result.Id := SegmentSpec.Id;
  ListItem := Parent.SEFFile.SEGS.FindItemByName(SegmentSpec.Id);
  if ListItem <> nil then
    Result.Assign(TEDISEFSegment(ListItem.EDISEFDataObject))
  else
  begin
    Result.RequirementDesignator := SegmentSpec.RequirementDesignator;
    Result.MaximumUse := SegmentSpec.MaximumUsage;
  end;
end;

function TEDISpecToSEFTranslator.TranslateToSEFSegment(SegmentSpec: TEDISegmentSpec;
  Parent: TEDISEFLoop): TEDISEFSegment;
var
  ListItem: TEDISEFDataObjectListItem;
begin
  Result := TEDISEFSegment.Create(Parent);
  Result.Id := SegmentSpec.Id;
  ListItem := Parent.SEFFile.SEGS.FindItemByName(SegmentSpec.Id);
  if ListItem <> nil then
    Result.Assign(TEDISEFSegment(ListItem.EDISEFDataObject))
  else
  begin
    Result.RequirementDesignator := SegmentSpec.RequirementDesignator;
    Result.MaximumUse := SegmentSpec.MaximumUsage;
  end;
end;

procedure TEDISpecToSEFTranslator.TranslateLoopToSEFSet(StackRecord: TEDILoopStackRecord;
  SegmentId, OwnerLoopId, ParentLoopId: string; var EDIObject: TEDIObject);
var
  SEFLoop: TEDISEFLoop;
begin
  if StackRecord.EDIObject is TEDISEFDataObjectGroup then
  begin
    SEFLoop := TEDISEFLoop.Create(TEDISEFDataObject(StackRecord.EDIObject));
    SEFLoop.Id := SegmentId;
    TEDISEFDataObjectGroup(StackRecord.EDIObject).EDISEFDataObjects.Add(SEFLoop);
    EDIObject := SEFLoop;
  end;
end;

function TEDISpecToSEFTranslator.TranslateToSEFSet(TransactionSetSpec: TEDITransactionSetSpec;
  Parent: TEDISEFFile): TEDISEFSet;
var

⌨️ 快捷键说明

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