This commit is contained in:
2018-06-29 19:47:36 +00:00
commit be7f501333
3769 changed files with 1425961 additions and 0 deletions

View File

@@ -0,0 +1,139 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>9.0.30729</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{42EE07F1-2AD8-4717-A85B-7E2DB97A625E}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>AyaNova.Plugin.ExportToExcel</RootNamespace>
<AssemblyName>AyaNova.Plugin.ExportToXls</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>..\..\..\keys\AyaNova.snk</AssemblyOriginatorKeyFile>
<FileUpgradeFlags>
</FileUpgradeFlags>
<OldToolsVersion>3.5</OldToolsVersion>
<UpgradeBackupLocation />
<TargetFrameworkProfile>
</TargetFrameworkProfile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>..\..\WinFormApp\bin\debug\plugins\ExportToXls\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>..\..\..\release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Infragistics4.Documents.Core.v11.2, Version=11.2.20112.2135, Culture=neutral, PublicKeyToken=7dd5c3163f2cd0cb, processorArchitecture=MSIL">
<HintPath>C:\Program Files\Infragistics\NetAdvantage 2011.2\Windows Forms\CLR4.0\Bin\Infragistics4.Documents.Core.v11.2.dll</HintPath>
<Name>Infragistics4.Documents.Core.v11.2</Name>
</Reference>
<Reference Include="Infragistics4.Documents.Excel.v11.2, Version=11.2.20112.2135, Culture=neutral, PublicKeyToken=7dd5c3163f2cd0cb, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>C:\Program Files\Infragistics\NetAdvantage 2011.2\Windows Forms\CLR4.0\Bin\Infragistics4.Documents.Excel.v11.2.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml.Linq">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Data.DataSetExtensions">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="ExportDataSetAdapter.cs" />
<Compile Include="ExportToExcel.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Resource.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>Resource.resx</DependentUpon>
</Compile>
<Compile Include="Timestamp.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\AyaNova.PlugIn\AyaNova.PlugIn.csproj">
<Project>{674BC3C9-4F74-4304-91ED-2EAFFFEB09A7}</Project>
<Name>AyaNova.PlugIn</Name>
<Private>False</Private>
</ProjectReference>
<ProjectReference Include="..\..\bizobjects\AyaLib\GZTW.AyaNova.BLL.csproj">
<Project>{50B807B6-FC35-4CC3-B54D-91C78426A943}</Project>
<Name>GZTW.AyaNova.BLL</Name>
<Private>False</Private>
</ProjectReference>
<ProjectReference Include="..\..\csla10\CSLA.Core.Bindablebase\CSLA.Core.Bindablebase.csproj">
<Project>{C2392355-12A9-4197-A1D3-603C390B1E62}</Project>
<Name>CSLA.Core.Bindablebase</Name>
<Private>False</Private>
</ProjectReference>
<ProjectReference Include="..\..\csla10\CSLA.Server.DataPortal\CSLA.Server.DataPortal.vbproj">
<Project>{80828E2C-E9FB-4E73-A27C-7F9CDB96FCDE}</Project>
<Name>CSLA.Server.DataPortal</Name>
<Private>False</Private>
</ProjectReference>
<ProjectReference Include="..\..\csla10\CSLA\CSLA.vbproj">
<Project>{1B9A38BB-461A-47A4-AD72-099C694138A0}</Project>
<Name>CSLA</Name>
<Private>False</Private>
</ProjectReference>
<ProjectReference Include="..\..\Data\Data\GZTW.Data.csproj">
<Project>{701893AA-C042-4FB2-8643-E139372C1117}</Project>
<Name>GZTW.Data</Name>
<Private>False</Private>
</ProjectReference>
<ProjectReference Include="..\..\Profile\GZTW.Profile\GZTW.Profile.csproj">
<Project>{EDE897E2-E2E6-441D-9F83-0B973AE09670}</Project>
<Name>GZTW.Profile</Name>
<Private>False</Private>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="Resources\ExportToExcel16.png" />
</ItemGroup>
<ItemGroup>
<None Include="Resources\ExportToExcel32.png" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Resource.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resource.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<None Include="Resources\ExportToExcel.ico" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PreBuildEvent>"C:\data\AyaNova\utils\TimeStamp\bin\Release\TimeStamp.exe" "$(ProjectDir)Timestamp.cs" "/N:AyaNova.PlugIn.ExportToExcel"</PreBuildEvent>
</PropertyGroup>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

View File

@@ -0,0 +1,581 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.ComponentModel;
using System.Collections;
using System.Reflection;
using GZTW.AyaNova.BLL;
namespace AyaNova.Plugin.ExportToExcel
{
/// <summary>
/// An ExportDatasetAdapter is used to convert data in an object
/// or collection into a DataSet
/// </summary>
public class ExportDatasetAdapter
{
List<ColumnInfo> _columns = new List<ColumnInfo>();
public struct ColumnInfo
{
internal string name;
internal System.Type type;
public string ColumnName
{
get
{
return name;
}
}
public System.Type ColumnType
{
get { return type; }
}
}
/// <summary>
/// Given a data source
/// returns an arraylist containing
/// ColumnInfo structures
/// for each column found
/// </summary>
/// <param name="source"></param>
/// <returns></returns>
public List<ColumnInfo> GetDataSourceColumns(object source)
{
AutoDiscover(source);
return _columns;
}
/// <summary>
/// Fills the DataSet with data from an object or collection.
/// </summary>
/// <remarks>
/// The name of the DataTable being filled is will be the class name of
/// the object acting as the data source. The
/// DataTable will be inserted if it doesn't already exist in the DataSet.
/// </remarks>
/// <param name="ds">A reference to the DataSet to be filled.</param>
/// <param name="source">A reference to the object or collection acting as a data source.</param>
public void Fill(DataSet ds, object source,List<Guid> SelectedItems,LocalizedTextTable LocaleText, string IDField)
{
mLocaleText = LocaleText;
mSelectedItems = SelectedItems;
mIDField = IDField;
string className = source.GetType().Name;
Fill(ds, className, source);
}
private string mIDField;
private LocalizedTextTable mLocaleText = null;
private List<Guid> mSelectedItems = null;
/// <summary>
/// Fills the DataSet with data from an object or collection.
///
/// </summary>
/// <remarks>
/// The name of the DataTable being filled is specified as a parameter. The
/// DataTable will be inserted if it doesn't already exist in the DataSet.
/// </remarks>
/// <param name="ds">A reference to the DataSet to be filled.</param>
/// <param name="tableName"></param>
/// <param name="source">A reference to the object or collection acting as a data source.</param>
public void Fill(DataSet ds, string tableName, object source)
{
DataTable dt = ds.Tables[tableName];
bool exists = (dt != null);
if (!exists)
dt = new DataTable(tableName);
Fill(dt, source);
if (!exists)
ds.Tables.Add(dt);
}
/// <summary>
/// Fills a DataTable with data values from an object or collection.
/// </summary>
/// <param name="dt">A reference to the DataTable to be filled.</param>
/// <param name="source">A reference to the object or collection acting as a data source.</param>
public void Fill(DataTable dt, object source)
{
AutoDiscover(source);
DataCopy(dt, source);
}
#region Data Copy
void DataCopy(DataTable dt, object source)
{
if (source == null) return;
if (_columns.Count < 1) return;
if (source is IListSource)
{
System.Diagnostics.Debugger.Break();//unexpected and not coded for
DataCopyIList(dt, ((IListSource)source).GetList());
}
else
{
if (source is IList)
{
DataCopyIList(dt, (IList)source);
}
else
{
System.Diagnostics.Debugger.Break();//unexpected and not coded for
// they gave us a regular object - create a list
ArrayList col = new ArrayList();
col.Add(source);
DataCopyIList(dt, (IList)col);
}
}
}
void DataCopyIList(DataTable dt, IList ds)
{
// create columns if needed
foreach (ColumnInfo column in _columns)
{
if (!dt.Columns.Contains(column.name))
dt.Columns.Add(column.name, column.type);
}
// load the data into the control
dt.BeginLoadData();
object o = null;
for (int index = 0; index < ds.Count; index++)
{
bool bFilteredOut=false;
DataRow dr = dt.NewRow();
foreach (ColumnInfo column in _columns)
{
try
{
if (column.name == "LISTIDFIELD")
{
//do this instead
o = GetFieldObject(ds[index], mIDField);
if (o is Guid)
{
dr[column.name] = (Guid)o;
}
else if (o is GridNameValueCellItem)
{
dr[column.name] = ((GridNameValueCellItem)o).Value;
}
else
{
System.Diagnostics.Debugger.Break();//should never get here in theory
dr[column.name] = Guid.Empty;
}
if (mSelectedItems.Count() > 0 && (!mSelectedItems.Contains((Guid)dr[column.name])))
{
bFilteredOut = true;
break;
}
}
else
{
o = GetFieldObject(ds[index], column.name);
if (o == null)
{
dr[column.name] = o;
}
else
{
Type t = o.GetType();
//Make columninfo of the same type with only a few exceptions
if (t == typeof(GridNameValueCellItem))
{
dr[column.name] = ((GridNameValueCellItem)o).Display;
}
else if (t == typeof(object))
{
//Almost certainly a date time or smartdate object
dr[column.name] = o.ToString();
// i.type = typeof(object);//what to do? Emtpy dates can't be used here
}
else if (t == typeof(GridRelativeTimeCellItem))
{
//it's a relative datetime, make it an object
dr[column.name] = ((GridRelativeTimeCellItem)o).Display;
}
else if (t == typeof(Guid))
{
//we don't want guid's in the exported stuff so ditch it
System.Diagnostics.Debugger.Break();//should never get here in theory
continue;
}
else if (t == typeof(PartSerialPickList))
{
System.Text.StringBuilder sb = new StringBuilder();
PartSerialPickList psp = (PartSerialPickList)o;
if (psp.Count > 0)
{
foreach (PartSerialPickList.PartSerialPickListInfo i in psp)
{
sb.Append(i.SerialNumber);
sb.Append("\r\n");
}
sb.Length = sb.Length - 2;
dr[column.name] = sb.ToString();
}
else
dr[column.name] = "";
}
else
dr[column.name] = o;
}
}
}
catch (Exception ex)
{
dr[column.name] = ex.Message;
}
}
if(!bFilteredOut)
dt.Rows.Add(dr);
}
dt.EndLoadData();
}
#endregion
#region AutoDiscover
void AutoDiscover(object source)
{
object innerSource;
if (source is IListSource)
{
innerSource = ((IListSource)source).GetList();
}
else
{
innerSource = source;
}
_columns.Clear();
if (innerSource is DataView)
{
ScanDataView((DataView)innerSource);
}
else
{
if (innerSource is IList)
{
ScanIList((IList)innerSource);
}
else
{
// they gave us a regular object
ScanObject(innerSource);
}
}
}
void ScanDataView(DataView ds)
{
for (int field = 0; field < ds.Table.Columns.Count; field++)
{
ColumnInfo i = new ColumnInfo();
i.name = ds.Table.Columns[field].ColumnName;
i.type = ds.Table.Columns[field].DataType;
_columns.Add(i);
}
}
void ScanIList(IList ds)
{
if (ds.Count > 0)
{
// retrieve the first item from the list
object obj = ds[0];
if (obj is ValueType && obj.GetType().IsPrimitive)
{
System.Diagnostics.Debugger.Break();//WHATS UP?
// the value is a primitive value type
ColumnInfo i = new ColumnInfo();
i.name = "Value";
i.type = obj.GetType();
_columns.Add(i);
}
else
{
if (obj is string)
{
System.Diagnostics.Debugger.Break();//WHATS UP?
// the value is a simple string
ColumnInfo i = new ColumnInfo();
i.name = "Text";
i.type = typeof(string);
_columns.Add(i);
}
else
{
// we have a complex Structure or object
ScanObject(obj);
}
}
}
}
void ScanObject(object source)
{
Type sourceType = source.GetType();
// retrieve a list of all public properties
PropertyInfo[] props = sourceType.GetProperties();
for (int column = 0; column < props.Length; column++)
if (props[column].CanRead)
{
ColumnInfo i = new ColumnInfo();
i.name = props[column].Name;
if (i.name == mIDField)
{
//add a new column for the IDField
ColumnInfo iID = new ColumnInfo();
iID.name = "LISTIDFIELD";
iID.type = typeof(Guid);
_columns.Add(iID);
}
Type tColumn=props[column].PropertyType;
//Make columninfo of the same type with only a few exceptions
if (tColumn == typeof(GridNameValueCellItem))
{
i.type = typeof(string);
}
else if (tColumn == typeof(object))
{
i.type = typeof(object);//what to do? Emtpy dates can't be used here
}
else if (tColumn == typeof(GridRelativeTimeCellItem))
{
//it's a relative datetime, make it an object
i.type = typeof(object);
}
else if (tColumn == typeof(Guid))
{
//we don't want guid's in the exported stuff so ditch it
continue;
}
else if (tColumn == typeof(PartSerialPickList))
{
//add a new column for the SerialNumber
ColumnInfo iID = new ColumnInfo();
iID.name = i.name;
iID.type = typeof(string);
_columns.Add(iID);
continue;
}
else
i.type = tColumn;
_columns.Add(i);
}
// retrieve a list of all public fields
FieldInfo[] fields = sourceType.GetFields();
for (int column = 0; column < fields.Length; column++)
{
System.Diagnostics.Debugger.Break();//WHATS UP?
ColumnInfo i = new ColumnInfo();
i.name = fields[column].Name;
i.type = fields[column].FieldType;
_columns.Add(i);
}
}
#endregion
#region GetFieldObject
object GetFieldObject(object obj, string fieldName)
{
if (obj is DataRowView)
{
System.Diagnostics.Debugger.Break();//unexpected and not coded for
// this is a DataRowView from a DataView
return ((DataRowView)obj)[fieldName].ToString();
}
else
{
if (obj is ValueType && obj.GetType().IsPrimitive)
{
System.Diagnostics.Debugger.Break();//unexpected and not coded for
// this is a primitive value type
if (obj == null)
return string.Empty;
else
return obj.ToString();
}
else
{
if (obj is string)
{
System.Diagnostics.Debugger.Break();//unexpected and not coded for
// this is a simple string
if (obj == null)
return string.Empty;
else
return obj.ToString();
}
else
{
// this is an object or Structure
try
{
Type sourcetype = obj.GetType();
// see if the field is a property
PropertyInfo prop = sourcetype.GetProperty(fieldName);
if (prop == null || !prop.CanRead)
{
// no readable property of that name exists - check for a field
FieldInfo field = sourcetype.GetField(fieldName);
if (field == null)
{
// no field exists either, throw an exception
throw new System.Data.DataException(
"NoSuchValueExistsException" + fieldName);
}
else
{
// got a field, return its value
return field.GetValue(obj);
}
}
else
{
// found a property, return its value
object o = prop.GetValue(obj, null);
if (o == null)
return null;
else
return o;
}
}
catch (Exception ex)
{
throw new System.Data.DataException(
"ErrorReadingValueException" + fieldName, ex);
}
}
}
}
}
#endregion
#region GetField Original String only version
string GetField(object obj, string fieldName)
{
if (obj is DataRowView)
{
System.Diagnostics.Debugger.Break();//unexpected and not coded for
// this is a DataRowView from a DataView
return ((DataRowView)obj)[fieldName].ToString();
}
else
{
if (obj is ValueType && obj.GetType().IsPrimitive)
{
System.Diagnostics.Debugger.Break();//unexpected and not coded for
// this is a primitive value type
if (obj == null)
return string.Empty;
else
return obj.ToString();
}
else
{
if (obj is string)
{
System.Diagnostics.Debugger.Break();//unexpected and not coded for
// this is a simple string
if (obj == null)
return string.Empty;
else
return obj.ToString();
}
else
{
// this is an object or Structure
try
{
Type sourcetype = obj.GetType();
// see if the field is a property
PropertyInfo prop = sourcetype.GetProperty(fieldName);
if (prop == null || !prop.CanRead)
{
// no readable property of that name exists - check for a field
FieldInfo field = sourcetype.GetField(fieldName);
if (field == null)
{
// no field exists either, throw an exception
throw new System.Data.DataException(
"NoSuchValueExistsException" + fieldName);
}
else
{
// got a field, return its value
return field.GetValue(obj).ToString();
}
}
else
{
// found a property, return its value
object o= prop.GetValue(obj, null);
if(o==null)
return "";
else
return o.ToString();
}
}
catch (Exception ex)
{
throw new System.Data.DataException(
"ErrorReadingValueException" + fieldName, ex);
}
}
}
}
}
#endregion
}
}

View File

@@ -0,0 +1,476 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AyaNova.PlugIn;
using GZTW.AyaNova.BLL;
using System.ComponentModel;
using System.Windows.Forms;
using System.Reflection;
using System.Data;
using Infragistics.Documents.Excel;
namespace AyaNova.Plugin.ExportToExcel
{
class ExportToExcel : IAyaNovaPlugin
{
//Keep all the object types we want to deal with in a collection
//so that we can quickly check it when asked
private static List<RootObjectTypes> ObjectsWeCanDealWith = null;
private static bool bLicensed = false;
//Holds the image resources from AyaNova
//so we can display the correct icons in our plugin
System.Resources.ResourceManager resman = null;
//Holds the current logged in user's localized text
//lookup object
LocalizedTextTable LocaleText = null;
#region IAyaNovaPlugin Members
#region interface properties
public string PluginName
{
get { return "ExportToXls"; }
}
public string PluginVersion
{
get { return "7.5"; }
}
public string About
{
get
{
return "AyaNova ExportToXls plugin\r\n" +
"Built " + AyaNova.PlugIn.ExportToExcel.Timestamp.BuildAt.ToString() + "\r\n" +
"Copyright 2009-2018 Ground Zero Tech-Works Inc.";
}
}
public Guid PluginID
{
get { return new Guid("{76912765-A95F-49ce-B1B1-1A6CECD1497D}"); }
}
public System.Drawing.Image PluginSmallIcon
{
get { return Resource.ExportToExcel16; }
}
public System.Drawing.Image PluginLargeIcon
{
get { return Resource.ExportToExcel32; }
}
public System.Resources.ResourceManager AyaNovaResourceManager
{
set { resman = value; }
get { return resman; }
}
#endregion interface properties
#region Initialization and Close
public bool Initialize(Version AyaNovaVersion, LocalizedTextTable localizedText)
{
LocaleText = localizedText;
//bLicensed = (!string.IsNullOrEmpty(AyaBizUtils.PluginLicensedVersion("ExportToXls")));
//case 2094
bLicensed = AyaBizUtils.PluginAllowed("ExportToXls", AyaNova.PlugIn.ExportToExcel.Timestamp.BuildAt);
if (!bLicensed && AyaBizUtils.PluginTooNew("ExportToXls", AyaNova.PlugIn.ExportToExcel.Timestamp.BuildAt))
{
MessageBox.Show(
"NOT LICENSED!\r\n\r\nThis ExportToXls plugin was built " +
AyaNova.PlugIn.ExportToExcel.Timestamp.BuildAt.ToString() + "\r\n" +
"but your license subscription for it ended " +
AyaBizUtils.PluginSubscriptionDate("ExportToXls").ToString() + "\r\n" +
"\r\nDowngrade back to your previous version or purchase a subscription to use this plugin.");
return false;
}
if (AyaNovaVersion.Major < 7)
{
MessageBox.Show("This ExportToXls plugin requires AyaNova version 7 or newer");
return false;
}
ObjectsWeCanDealWith = new List<RootObjectTypes>();
//ObjectsWeCanDealWith.Add(RootObjectTypes.Nothing);
ObjectsWeCanDealWith.Add(RootObjectTypes.User);
ObjectsWeCanDealWith.Add(RootObjectTypes.Schedule);
ObjectsWeCanDealWith.Add(RootObjectTypes.WorkorderService);
ObjectsWeCanDealWith.Add(RootObjectTypes.Workorder);
ObjectsWeCanDealWith.Add(RootObjectTypes.Memo);
return true;
}
public void Close()
{
;
}
#endregion Initialization and close
#region ShowMenu?
public bool SingleObjectMenuShow(RootObjectTypes objectType)
{
return false;
// return (ObjectsWeCanDealWith.Contains(objectType));
}
public bool MultipleObjectsMenuShow(RootObjectTypes objectType)
{
if (objectType != RootObjectTypes.Schedule) return true;
return false;
//return (ObjectsWeCanDealWith.Contains(objectType));
}
#endregion show menu?
#region Menu options
public List<AyaNovaPluginMenuItem> SingleObjectMenuOptions(RootObjectTypes objectType, object ayaNovaObject)
{
return null;//stick to lists for now
//if (!ObjectsWeCanDealWith.Contains(objectType)) return null;
//if (!PFC()) return null;
//List<AyaNovaPluginMenuItem> list = new List<AyaNovaPluginMenuItem>();
//switch (objectType)
//{
// default:
// //If it's not nothing and we already know it's something we can deal with
// //then present the export
// list.Add(new AyaNovaPluginMenuItem("EXCELEXPORT_SELECTED", "Export to Excel", null, null));
// break;
//}
//return list;
}
public List<AyaNovaPluginMenuItem> MultipleObjectsMenuOptions(RootObjectTypes objectType)
{
//if (!ObjectsWeCanDealWith.Contains(objectType)) return null;
if (!PFC()) return null;
if (objectType == RootObjectTypes.Nothing) return null;
List<AyaNovaPluginMenuItem> list = new List<AyaNovaPluginMenuItem>();
list.Add(new AyaNovaPluginMenuItem("XlsEXPORT_SELECTED", "Export to Xls", null, null));
return list;
}
/// <summary>
/// pre flight check
/// </summary>
/// <returns></returns>
private bool PFC()
{
if (!bLicensed)
{
ShowWarning("An AyaNova ExportToXls plugin license is required to use this plugin.", "Not licensed");
return false;
}
return true;
}
private void ShowWarning(string swarn, string scaption)
{
MessageBox.Show(swarn, scaption, MessageBoxButtons.OK, MessageBoxIcon.Stop);
}
#endregion
#region Menu Commands
#region LIST OBJECT COMMAND
/// <summary>
/// LIST OBJECT
/// </summary>
/// <param name="commandKey"></param>
/// <param name="objectType"></param>
/// <param name="objectIDList"></param>
/// <param name="listObject"></param>
/// <returns></returns>
public bool CommandSelectedForList(string commandKey, RootObjectTypes objectType, List<Guid> objectIDList, object listObject)
{
//bool bAllItemsInGridWereSelected = objectIDList.Count == 0;
//if (commandKey == "EXCELEXPORT_SELECTED")
//{
// switch (objectType)
// {
// case RootObjectTypes.Schedule:
// {
// }
// break;
// case RootObjectTypes.User:
// {
// }
// break;
// case RootObjectTypes.WorkorderService:
// {
// }
// break;
// case RootObjectTypes.Memo:
// {
// }
// break;
// default:
// return false;
// }
//}
DoExport(listObject, objectIDList);
return false;
}
#endregion list object command
#region SINGLE OBJECT COMMAND
/// <summary>
/// SINGLE OBJECT
/// </summary>
/// <param name="commandKey"></param>
/// <param name="objectType"></param>
/// <param name="ayaNovaObject"></param>
public void CommandSelectedForSingleObject(string commandKey, RootObjectTypes objectType, object ayaNovaObject)
{
switch (commandKey)
{
case "XlsEXPORT_SELECTED":
{
switch (objectType)
{
case RootObjectTypes.User:
{
}
break;
case RootObjectTypes.Nothing:
{
}
break;
case RootObjectTypes.Workorder:
{
}
break;
case RootObjectTypes.Memo:
{
}
break;
default:
return;
}
}
break;
}
}
#endregion single object command
#endregion menu commands
#region DoExport
/// <summary>
/// Export to xls
/// </summary>
/// <param name="listObject"></param>
/// <param name="SelectedItems"></param>
private void DoExport(object listObject, List<Guid> SelectedItems)
{
#region Convert object to dataset
DataSet listData = new DataSet();
ExportDatasetAdapter edsa = new ExportDatasetAdapter();
object o = AyaBizUtils.GetBizObjectStaticPropertyValue(listObject, "IDField");
if (o == null)
{
System.Diagnostics.Debugger.Break();//Unexpected, all lists should have one
o = "Unknown";
}
edsa.Fill(listData, listObject, SelectedItems, LocaleText, o.ToString());//every list object should have an IDField
#endregion convert object to dataset
#region Fixup names of columns
foreach (DataTable dt in listData.Tables)
foreach (DataColumn dc in dt.Columns)
{
string skey = dc.ColumnName;
skey = skey.Replace("LT_", "");
skey = skey.Replace("O_", "");
skey = skey.Replace("_Label_", "");
dc.ColumnName = skey;
}
#endregion fixup names
#region Selected rows only?
//if(SelectedItems.Count>0)
//{
// bool bSomethingToExport = false;
// //remove any row that doesn't contain any guids that are in the list of selected ids
// foreach (DataTable dt in listData.Tables)
// {
// int stopat = dt.Rows.Count;
// int nColumns=dt.Columns.Count;
// for(int x = 0; x < stopat; x++)
// {
// bool bRowMatchedSelected = false;
// DataRow dr = dt.Rows[x];
// for (int y = 0; y < nColumns; y++)
// {
// string sGuid = AyaBizUtils.rxGuid.Match(dr[y].ToString()).Value;
// if(!string.IsNullOrEmpty(sGuid))
// {
// Guid gid=new Guid(sGuid);
// if (SelectedItems.Contains(gid))
// {
// bRowMatchedSelected = true;
// break;
// }
// }
// }//end columns loop
// if (!bRowMatchedSelected)
// {
// //remove the row, decrement stopat
// dt.Rows.RemoveAt(x);
// stopat--;
// x--;
// }
// }//end rows loop
// if(dt.Rows.Count>0) bSomethingToExport=true;
// }//end tables loop
// if (!bSomethingToExport)
// {
// MessageBox.Show("Nothing to export");
// return;
// }
//}
#endregion selected rows only
//drop the listidfield column
foreach (DataTable dt in listData.Tables)
if (dt.Columns.Contains("LISTIDFIELD")) dt.Columns.Remove("LISTIDFIELD");
#region Export to Excel workbook
Workbook workbook = new Infragistics.Documents.Excel.Workbook();
workbook.SetCurrentFormat(WorkbookFormat.Excel97To2003);
foreach (DataTable table in listData.Tables)
{
// Create the worksheet to represent this data table
string swsName = table.TableName;
if (swsName.Length > 31) swsName = swsName.Substring(0, 31);//worksheet name must be no more than 31 chs
Infragistics.Documents.Excel.Worksheet worksheet = workbook.Worksheets.Add(swsName);
// Create column headers for each column
for (int columnIndex = 0; columnIndex < table.Columns.Count; columnIndex++)
{
worksheet.Rows[0].Cells[columnIndex].Value = table.Columns[columnIndex].ColumnName;
}
// Starting at row index 1, copy all data rows in
// the data table to the worksheet
int rowIndex = 1;
foreach (DataRow dataRow in table.Rows)
{
Infragistics.Documents.Excel.WorksheetRow row = worksheet.Rows[rowIndex++];
for (int columnIndex = 0; columnIndex < dataRow.ItemArray.Length; columnIndex++)
{
//case 1698
object ob = dataRow.ItemArray[columnIndex];
if (ob is byte[])
row.Cells[columnIndex].Value = "BINARY DATA";
else if (ob is CSLA.SmartDate)
{
row.Cells[columnIndex].Value = ((CSLA.SmartDate)ob).Date;
}
else
row.Cells[columnIndex].Value = ob;
}
}
}
SaveFileDialog saveFileDialog1 = new SaveFileDialog();
//save the file to location of users choosing
string sFileName = LocaleText.GetLocalizedText(GetBizObjectLocaleKey(listObject));
if (string.IsNullOrEmpty(sFileName))
sFileName = listObject.ToString().Replace("GZTW.AyaNova.BLL.", "");
saveFileDialog1.FileName = sFileName + ".xls";
if (saveFileDialog1.ShowDialog() == DialogResult.Cancel) return;
if (!string.IsNullOrEmpty(saveFileDialog1.FileName))
{
workbook.Save(saveFileDialog1.FileName);
}
#endregion Export to excel
}
/// <summary>
/// Use reflection to find the locale key for a biz object
/// (if the biz object doesn't have a LocaleKey property it returns
/// the name of the biz object instead)
/// </summary>
/// <param name="BizObject"></param>
public static string GetBizObjectLocaleKey(object BizObject)
{
try
{
PropertyInfo pi = BizObject.GetType().GetProperty("LocaleKey");
if (pi == null) return BizObject.ToString();
object propvalue = pi.GetValue(BizObject, null).ToString();
if (propvalue != null)
return propvalue.ToString();
else
return BizObject.ToString();
}
catch
{
//log.Error("GetBizObjectLocaleKey", e);
//MessageBox.Show("GetBizObjectLocaleKey:" + e.Message);
return "";
}
//return BizObject.ToString();
}
#endregion do export
#endregion
}
}

View File

@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("AyaNova.Plugin.ExportToXls")]
[assembly: AssemblyDescription("ExportToXls plugin for AyaNova")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Ground Zero Tech-Works Inc.")]
[assembly: AssemblyProduct("AyaNova.Plugin.ExportToXls")]
[assembly: AssemblyCopyright("Copyright © 2009-2018 Ground Zero Tech-Works Inc.")]
[assembly: AssemblyTrademark("AyaNova is a registered trademark of Ground Zero Tech-Works Inc.")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("76912765-A95F-49ce-B1B1-1A6CECD1497D")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("7.5.0.0")]
[assembly: AssemblyFileVersion("7.5.0.0")]

View File

@@ -0,0 +1,84 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.1
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace AyaNova.Plugin.ExportToExcel {
using System;
/// <summary>
/// A strongly-typed resource class, for looking up localized strings, etc.
/// </summary>
// This class was auto-generated by the StronglyTypedResourceBuilder
// class via a tool like ResGen or Visual Studio.
// To add or remove a member, edit your .ResX file then rerun ResGen
// with the /str option, or rebuild your VS project.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resource {
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal Resource() {
}
/// <summary>
/// Returns the cached ResourceManager instance used by this class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("AyaNova.Plugin.ExportToExcel.Resource", typeof(Resource).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// Overrides the current thread's CurrentUICulture property for all
/// resource lookups using this strongly typed resource class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture {
get {
return resourceCulture;
}
set {
resourceCulture = value;
}
}
internal static System.Drawing.Icon ExportToExcel {
get {
object obj = ResourceManager.GetObject("ExportToExcel", resourceCulture);
return ((System.Drawing.Icon)(obj));
}
}
internal static System.Drawing.Bitmap ExportToExcel16 {
get {
object obj = ResourceManager.GetObject("ExportToExcel16", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
internal static System.Drawing.Bitmap ExportToExcel32 {
get {
object obj = ResourceManager.GetObject("ExportToExcel32", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
}
}

View File

@@ -0,0 +1,130 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="ExportToExcel" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>Resources\ExportToExcel.ico;System.Drawing.Icon, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="ExportToExcel16" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>Resources\ExportToExcel16.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="ExportToExcel32" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>Resources\ExportToExcel32.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
</root>

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 797 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB