using System; using System.Collections.Generic; using System.Linq; using System.Text; using Sleis.Models ; using System.Reflection; using System.ComponentModel; using Sleis.Utility; namespace Sleis.Export { public class ReleasePointExport : ExportBase { private enum ReleasePointLookup { [Description("EpaReleasePointType")] TypeCode, [Description("EpaReleasePointStatus")] StatusCode, [Description("EpaReleasePointGasFlowRate")] GasFlowRateUomCode, [Description("EpaReleasePointGasVel")] GasVelUomCode, [Description("EpaFacilityCollectionMethod")] CollectionMethodCode, [Description("EpaFacilityGeoReferencePoint")] ReferencePointCode, [Description("EpaFacilityGeodeticRefSystem")] ReferenceSystemCode, StackHeightMeasurement, StackDiameterMeasurement, FugitiveHeight, FugitiveWidth, FugitiveLength, FugitiveAngle, } private List m_ReleasePoints = new List(); public ReleasePointExport() { m_FileName = "_Emissions_Report_Release_Points.CSV"; propertyInfos = typeof(ReleasePoint).GetProperties(BindingFlags.Public | BindingFlags.Static); } public override object Entity { set { m_ReleasePoints = value as List; } } protected override void CreateColumns() { foreach (FieldPropertyMapping fpm in FieldPropertyMapping.Values.OrderBy(x => x.SortOrder)) { string key = GetFieldKey(fpm); if (Fields[key].PublicStyle != CustomFieldDataStyleType.Hidden) { sb.AppendFormat("{0}, ", fpm.ColumnName); //if (m_ReleasePoints[0].TypeCode != "1") //{ // //create column heads for stack // if (fpm.PropertyName.Contains(ReleasePointLookup.FugitiveWidth.ToString()) || fpm.PropertyName.Contains(ReleasePointLookup.FugitiveHeight.ToString()) || fpm.PropertyName.Contains(ReleasePointLookup.FugitiveLength.ToString()) || fpm.PropertyName.Contains(ReleasePointLookup.FugitiveAngle.ToString())) // { // continue; // } // sb.AppendFormat("{0}, ", fpm.ColumnName); //} //else //{ // if (fpm.PropertyName.Contains(ReleasePointLookup.StackDiameterMeasurement.ToString()) || fpm.PropertyName.Contains(ReleasePointLookup.StackHeightMeasurement.ToString())) // { // continue; // } // sb.AppendFormat("{0}, ", fpm.ColumnName); //} } } base.CreateColumns(); } protected override void PopulateData() { foreach (ReleasePoint model in m_ReleasePoints) { foreach (FieldPropertyMapping fpm in FieldPropertyMapping.Values.OrderBy(x => x.SortOrder)) { string key = GetFieldKey(fpm); if (Fields[key].PublicStyle != CustomFieldDataStyleType.Hidden) { PopulateData(model, fpm.PropertyName, sb); } } base.PopulateCustomFieldValue(model.Id); base.PopulateData(); } } protected override void WriteMultipleObjectValue(object root, string propertyName, StringBuilder sb) { string[] propertyNames = propertyName.Split(':'); //usually in terms of code and lookup object obj = null; bool noVal = false; if (root.GetType().GetProperty(propertyNames[0]).CanRead) { obj = root.GetType().GetProperty(propertyNames[0]).GetValue(root, null); noVal = obj == null; sb.AppendFormat("{0} ", obj==null? string.Empty:obj.ToString()); } obj = root.GetType().GetProperty(propertyNames[1]).GetValue(root, null); if (propertyNames[1] == ReleasePointLookup.GasFlowRateUomCode.ToString()) { sb.AppendFormat("{0},", obj == null ? string.Empty : LookupUtility.Get(obj.ToString()).Value); }else if(propertyNames[1] == ReleasePointLookup.GasVelUomCode.ToString()) { sb.AppendFormat("{0},", obj == null ? string.Empty : LookupUtility.Get(obj.ToString()).Value); } else { if (noVal) { sb.AppendFormat("{0},", string.Empty); }else { sb.AppendFormat("{0},", obj == null ? string.Empty : obj.ToString()); } } } protected override void WriteObjectValue(object root, string propertyName, StringBuilder sb) { object obj = root.GetType().GetProperty(propertyName).GetValue(root, null); if (propertyName == ReleasePointLookup.ReferencePointCode.ToString()) { sb.AppendFormat("{0},", obj == null ? string.Empty : LookupUtility.Get(obj.ToString()).Value.Replace(',','-')); } else if (propertyName == ReleasePointLookup.ReferenceSystemCode.ToString()) { sb.AppendFormat("{0},", obj == null ? string.Empty : LookupUtility.Get(obj.ToString()).Value); } else if (propertyName == ReleasePointLookup.TypeCode.ToString()) { sb.AppendFormat("{0},", obj == null ? string.Empty : LookupUtility.Get(obj.ToString()).Value); } else if (propertyName == ReleasePointLookup.StatusCode.ToString()) { sb.AppendFormat("{0},", obj == null ? string.Empty : LookupUtility.Get(obj.ToString()).Value); } else if (propertyName == ReleasePointLookup.CollectionMethodCode.ToString()) { sb.AppendFormat("{0},", obj == null ? string.Empty : LookupUtility.Get(obj.ToString()).Value); } else { base.WriteObjectValue(root, propertyName, sb); } } } }