Exemplo n.º 1
0
 public DataBlock(int APIversion, EventHandler handler, DataType typeCode, ushort repCode, SoundProperty id, IEnumerable <TypedData> items)
     : this(APIversion, handler)
 {
     mTypeCode = typeCode;
     mRepCode  = repCode;
     mId       = id;
     mItems.AddRange(items.Select(x => x.Clone(handler)).Cast <TypedData>());
 }
Exemplo n.º 2
0
        /// <summary>
        /// Import POI data from external file to datalist
        /// </summary>
        /// <param name="filename"></param>
        /// <returns>record count</returns>
        public int Import(string filename)
        {
            if (!(filename.EndsWith(".txt") || filename.EndsWith(".csv") || filename.EndsWith(".xlsx")))
            {
                throw new Exception("Target type not supported");
            }

            List <POI> imported = new List <POI>();
            DataTable  dataTable;

            if (filename.EndsWith(".txt") || filename.EndsWith(".csv"))
            { // .txt or .csv
                dataTable = PlainTextToTable(filename, filename.EndsWith(".csv") ? "," : "\t\t", filename.EndsWith(".csv"));
            }
            else // .xlsx
            {
                dataTable = ExcelToTable(filename);
            }

            foreach (DataRow row in dataTable.Rows)
            {
                POI poi = new POI();
                foreach (DataColumn column in dataTable.Columns)
                {
                    var property = typeof(POI).GetProperty(column.ColumnName);
                    if (column.DataType.Equals(typeof(string)))
                    {
                        if (row[column] != null && row[column].GetType() == typeof(string))
                        {
                            property.SetValue(poi, row[column].Equals("null") ? null : row[column], null);
                        }
                    }
                }

                imported.Add(poi);
            }
            DataList.AddRange(imported);

            CurrentList = DataList;
            RefreshPagination();

            return(imported == null ? 0 : imported.Count);
        }