ExcelDataLink.cs :  » Persistence-Frameworks » FileHelpers-Library » FileHelpers » DataLink » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Persistence Frameworks » FileHelpers Library 
FileHelpers Library » FileHelpers » DataLink » ExcelDataLink.cs
#region "   Copyright 2005-07 to Marcos Meli - http://www.marcosmeli.com.ar" 

// Errors, suggestions, contributions, send a mail to: marcos@filehelpers.com.

#endregion

using System;

namespace FileHelpers.DataLink{
  /// <summary>
  /// This class has the responsability to enable the two directional
  /// transformation.
  /// <list type="bullet">
  /// <item> Excel &lt;-> DataStorage</item>
  /// </list>
  /// <para><b>WARNING you need to have installed Microsoft Excel 2000 or newer to use this feature.</b></para>
  /// <para><b>To use this class you need to reference the FileHelpers.ExcelStorage.dll file.</b></para>
  /// </summary>
  /// <remarks>
  /// <para>Uses an <see cref="DataStorage"/> to accomplish this task.</para>
  /// </remarks>
  /// <seealso href="quick_start.html">Quick Start Guide</seealso>
  /// <seealso href="class_diagram.html">Class Diagram</seealso>
  /// <seealso href="examples.html">Examples of Use</seealso>
  /// <seealso href="example_datalink.html">Example of the DataLink</seealso>
  /// <seealso href="attributes.html">Attributes List</seealso>
  public sealed class ExcelDataLink
  {
    #region "  Constructor  "

    /// <summary>Create a new instance of the class.</summary>
    /// <param name="provider">The <see cref="DataLink.DataStorage"/> used to performs the transformation.</param>
    public ExcelDataLink(DataStorage provider)
    {
      mProvider = provider;
      if (mProvider != null)
        mExcelStorage = new ExcelStorage(provider.RecordType);
      else
        throw new ArgumentException("provider cant be null", "provider");
    }

    #endregion

    #region "  ExcelStorage  "

    private ExcelStorage mExcelStorage;

    /// <summary> The internal <see cref="T:FileHelpers.FileHelperEngine"/> used to the file or stream ops. </summary>
    public ExcelStorage ExcelStorage
    {
      get { return mExcelStorage; }
    }

    #endregion

    #region "  DataLinkProvider  "

    DataStorage mProvider;

    /// <summary> The internal <see cref="T:FileHelpers.DataLink.DataStorage"/> used to the link ops. </summary>
    public DataStorage DataStorage
    {
      get { return mProvider; }
    }

    #endregion

    #region "  Last Records "

    private object[] mLastExtractedRecords;

    /// <summary>
    /// An array of the last records extracted from the data source to a file.
    /// </summary>
    public object[] LastExtractedRecords
    {
      get { return mLastExtractedRecords; }
    }

    private object[] mLastInsertedRecords;

    /// <summary>
    /// An array of the last records inserted in the data source that comes from a file.
    /// </summary>
    public object[] LastInsertedRecords
    {
      get { return mLastInsertedRecords; }
    }

    #endregion

    #region "  ExtractTo File/Stream   "

    /// <summary>
    /// Extract records from the data source and insert them to the specified file using the DataLinkProvider <see cref="DataLink.DataStorage.ExtractRecords"/> method.
    /// </summary>
    /// <param name="fileName">The files where the records be written.</param>
    /// <returns>True if the operation is successful. False otherwise.</returns>
    public bool ExtractToExcel(string fileName)
    {
      mLastExtractedRecords = mProvider.ExtractRecords();
      mExcelStorage.InsertRecords(mLastExtractedRecords);
      return true;
    }

    #endregion

    #region "  InsertFromFile  "

    /// <summary>Extract records from a file and insert them to the data source using the DataLinkProvider <see cref="DataLink.DataStorage.InsertRecords"/> method.</summary>
    /// <param name="excelFileName">The file with the source records.</param>
    /// <returns>True if the operation is successful. False otherwise.</returns>
    public bool InsertFromExcel(string excelFileName)
    {
      mLastInsertedRecords = mExcelStorage.ExtractRecords();
      mProvider.InsertRecords(mLastInsertedRecords);
      return true;
    }

    #endregion
  }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.