How to: Implement File Data Properties How to: Implement a data file attributes

This topic demonstrates how to implement a business class with a file data property and a file collection property. For this purpose, the Resume class, which is used to store and manage an employee's resume information, is implemented. It has three properties: File, Contact and Portfolio. The File property provides a file, the Contact property contains a reference to the Contact class, and the Portfolio property returns a collection of the employee's files.

This topic demonstrates how to implement the business class has the file attributes and data collection of files attributes. To this end, we will achieve "resume" class used to store and manage employee resume information. It has three attributes: documents, contacts and combinations. File property provides a file, contact property contains a reference to human contact and portfolio property returns a collection of employee files.

 

To add a file data type property and a file collection property to a business object, you should use a type that implements the IFileData interface and one that applies the FileAttachment attribute. In this instance, the FileAttachmentsWindowsFormsModule, FileAttachmentsAspNetModule and/or FileAttachmentMobileModule modules should be added to your WinForms, ASP.NET Web and/or Mobile module projects respectively. These modules contain Property Editors for IFileData type properties, and Controllers with Actions that are necessary for file manipulation. Note that the Mobile Property Editor for a IFileData property supports only the file download. For details, refer to the File Attachments Module Overview topic.

To file a collection of files and data type attributes attribute to the business object, the type of property types and applications File attachments to achieve IFileData interface should be used. In this case, file attachments WindowsForms module, file attachments AspNet modules and / or mobile module module file attachments should be added separately to your WinForms, ASP.NET Web and / or mobile module project. These modules include the type of property editor IFileData property, and the controller of the desired file operation. Please note, IFileData properties of mobile property editor only supports file downloads. For more information, see the file attachment module overview topic.

 

To add the FileAttachmentsWindowsFormsModule, FileAttachmentsAspNetModule and (or) FileAttachmentMobileModule module(s) to the application, invoke the Module Designer for the WinForms, ASP.NET and (or) Mobile module project(s), drag the corresponding item from the Toolbox to the Designer's Required Modules section, and rebuild the solution.

To add a file attachment WindowsForms application module, file attachments AspNet module and (or) file attachment module Mobile module, the module call WinForms designer, ASP.NET and (or) mobile module project, drag the appropriate items from the tool tank to the "desired design module" section, and then rebuild the solution.

 

The following code demonstrates a Resume business object.

The following code demonstrates the "restore" business objects.

[DefaultClassOptions]
public class Resume : BaseObject {
   public Resume(Session session) : base(session) {}
   private Contact contact;
   private FileData file;
   [Aggregated, ExpandObjectMembers(ExpandObjectMembers.Never)]
   public FileData File {
      get { return file; }
      set {
         SetPropertyValue(nameof(File), ref file, value);
      }
   }
   public Contact Contact {
      get { 
         return contact;
      }
      set {
         SetPropertyValue(nameof(Contact), ref contact, value);
      }
   }
  [Aggregated, Association("Resume-PortfolioFileData")]
  public XPCollection<PortfolioFileData> Portfolio {
     get { return GetCollection<PortfolioFileData>(nameof(Portfolio)); }
  }
}
public class PortfolioFileData : FileAttachmentBase {
   public PortfolioFileData(Session session) : base(session) {}
   private DocumentType documentType;
   protected Resume resume;
   [Persistent, Association("Resume-PortfolioFileData")]
   public Resume Resume {
      get { return resume; }
      set { 
         SetPropertyValue(nameof(Resume), ref resume, value); 
      }
   }
   public override void AfterConstruction() {
      base.AfterConstruction();
      documentType = DocumentType.Unknown;
   }
   public DocumentType DocumentType {
      get { return documentType; }
      set { SetPropertyValue(nameof(DocumentType), ref documentType, value);}
   }
}
public enum DocumentType { SourceCode = 1, Tests = 2, Documentation = 3, 
   Diagrams = 4, ScreenShots = 5, Unknown = 6 };

 

To create a collection of an employee's files, the Resume class has the Portfolio property of the XPCollection<PortfolioFileData> type. The PortfolioFileData class is inherited from the FileAttachmentBase class, which in turn, uses the FileAttachment interface. The FileAttachmentBase class, as well as the FileAttachment attribute, is from the Business Objects Library.

To create a collection of files of employees, "resume" class has XPCollection <PortfolioFileData> type "portfolio" properties. Library package data classes are inherited from the class library file attachments, which in turn use the accessory interface file. Class library file attachments and file attachments attributes from the business object library.

 

The PortfolioFileData class has the DocumentType property that specifies the portfolio file type. This property is initialized in the AfterConstruction method override. The PortfolioFileData class also stores a reference to a Resume object in its Resume property.

Bag class file data having the document type attribute that specifies the type of file combination. This property "after build" initialization method override. Bag class file data is still stored in reference to its Resume property to "resume" object.

 

The following images show the Resume Detail View in WinForms, ASP.NET Web and Mobile applications.

The following figure shows the "resume details" WinForms is, ASP.NET Web and mobile applications.

ResumeInWin

ResumeInWeb

ResumeInMobile

 

Guess you like

Origin www.cnblogs.com/foreachlife/p/How-to-Implement-File-Data-Properties.html