Click here to Skip to main content
12,078,489 members (44,571 online)
Click here to Skip to main content

Stats

41.5K views
1.3K downloads
106 bookmarked
Posted

Plug-in Framework

, 14 Sep 2010 CPOL
Basic framework for building desktop plug-in applications.
PluginFramework.zip
PluginFramework
Demo
bin
Debug
Plugins
Release
Plugins
Forms
Properties
Settings.settings
DemoFormPlugin
Properties
Settings.settings
DemoUserControlPlugin
Properties
Settings.settings
MBG.Extensions
Collections
Controls
Core
Data
Math
Properties
Xml
MBG.IO
Properties
PluginFramework.Attributes
Properties
PluginFramework.Controls
Properties
Resources
Icons
SettingsIcon.ico
TreeIcon.ico
Images
SettingsImage.png
TreeImage.png
PluginFramework.Interface
Properties
PluginFramework.Utilities
Properties
using System;
using System.Collections.Generic;
using System.Data;
using System.Text;
using MBG.Extensions.Core;

namespace MBG.Extensions.Data
{
    public static class DataExtensions
    {
        public static void AddRange(this DataColumnCollection dataColumns, params string[] columnNames)
        {
            foreach (string columnName in columnNames)
            {
                dataColumns.Add(columnName);
            }
        }
        public static void AddRange(this DataColumnCollection dataColumns, params DataColumn[] columns)
        {
            foreach (DataColumn column in columns)
            {
                dataColumns.Add(column);
            }
        }
        public static void AddRange<T>(this DataColumnCollection dataColumns, IEnumerable<string> enumerable)
        {
            foreach (string item in enumerable)
            {
                dataColumns.Add(item);
            }
        }

        public static bool TryAdd(this DataColumnCollection dataColumns, string columnName)
        {
            if (!dataColumns.Contains(columnName))
            {
                dataColumns.Add(columnName);
                return true;
            }
            return false;
        }

        public static bool SaveToCsv(this DataSet dataSet, string filePath)
        {
            return dataSet.SaveToCsv(filePath, true);
        }
        public static bool SaveToCsv(this DataSet dataSet, string filePath, bool outputColumnNames)
        {
            bool ok = false;
            StringBuilder sb = new StringBuilder(2000);
            if (dataSet.Tables.Count > 0)
            {
                foreach (DataTable table in dataSet.Tables)
                {
                    #region Column Names
                    if (outputColumnNames)
                    {
                        foreach (DataColumn column in table.Columns)
                        {
                            sb.Append(column.ColumnName);
                            sb.Append(',');
                        }
                        sb.Remove(sb.Length - 1, 1);
                        sb.Append(Environment.NewLine);
                    }
                    #endregion

                    #region Rows (Data)
                    foreach (DataRow row in table.Rows)
                    {
                        foreach (DataColumn column in table.Columns)
                        {
                            sb.Append(row[column].ToString());
                            sb.Append(',');
                        }
                        //Remove Last ','
                        sb.Remove(sb.Length - 1, 1);
                        sb.Append(Environment.NewLine);
                    }
                    #endregion
                }

                ok = sb.ToString().ToFile(filePath);
            }

            return ok;
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

vnmatt
Software Developer (Senior) Freelancer
Vietnam Vietnam
No Biography provided

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.160212.1 | Last Updated 14 Sep 2010
Article Copyright 2010 by vnmatt
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid