Example #1
0
        public EDataTableBuilder(DataTable table, int queryId)
        {
            _queryId       = queryId;
            _internalTable = new DataTable();
            _periodStructs = new List <PeriodStruct>();

            _internalTable        = table;
            ETableDictionary      = new EDataTableDictionary();
            _tempList             = new List <DataRow>();
            _sortedList           = new List <IEnumerable <DataRow> >(new[] { new List <DataRow>() });
            _days                 = new List <string>();
            _eDataTableDictionary = new EDataTableDictionary();
        }
Example #2
0
        public void AddRange(EDataTableDictionary collection)
        {
            if (collection == null)
            {
                throw new ArgumentNullException("Collection is null");
            }

            foreach (var item in collection)
            {
                if (!_internalDictionary.ContainsKey(item.Key))
                {
                    _internalDictionary.Add(item.Key, item.Value);
                }
                else
                {
                    // handle duplicate key issue here
                }
            }
        }
Example #3
0
        public void ExportDataToExcel(EDataTableDictionary dsData, ExportStyle style, string profileName)
        {
            _eventRow = 1;
            foreach (var item in dsData)
            {
                _progressRowCount += item.Value.Rows.Count;
            }

            string appPath = AppDomain.CurrentDomain.BaseDirectory;
            var    path    = Path.GetFullPath(appPath + @"\" + "DataExportFiles");
            var    iExists = Directory.Exists(path);

            if (!iExists)
            {
                Directory.CreateDirectory(path);
            }

            var fullPath = Path.GetFullPath(path + @"\" + profileName);

            var isExists = Directory.Exists(fullPath);

            if (!isExists)
            {
                Directory.CreateDirectory(fullPath);
            }
            var finko = new FileStream(fullPath + @"\" + profileName + " " + DateTime.Now.Month + "_" + DateTime.Now.Day + " " + DateTime.Now.Hour + "_" + DateTime.Now.Minute + "_" + DateTime.Now.Second + "_" + DateTime.Now.Millisecond + ".xlsx",
                                       FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite);


            using (var excel = new  ExcelPackage(finko))
            {
                var workbooks = excel.Workbook;
                workbooks.Worksheets.Add("Sheet");
                var myDataList = new List <EDataTable>();
                var myNameList = new List <string>();


                #region SnapShotExport

                var snapshots     = from items in dsData where items.Value.IsSnapShotTable select items;
                var keyValuePairs = snapshots as List <KeyValuePair <string, EDataTable> > ?? snapshots.ToList();


                //export snapsots
                foreach (var items in keyValuePairs)
                {
                    myDataList.Clear();
                    myNameList.Clear();
                    myDataList.Add(items.Value);
                    myNameList.Add(items.Key);
                    _tableCounter++;
                    var items1 = items;
                    var list   = dsData.Where(tbl => tbl.Value.SnapshotRelationID == items1.Value.SnapShotID);
                    foreach (var eDataTable in list)
                    {
                        myDataList.Add(eDataTable.Value);
                        myNameList.Add(eDataTable.Key);
                        _tableCounter++;
                    }

                    ExportCurrentData(excel, myDataList, style); //export the queries
                    FormatExcelSheet(excel, myDataList, myNameList);


                    excel.Workbook.Worksheets.Add("Sheet");
                }



                #endregion

                #region TimeSliceExport

                var timeslices = from items in dsData where items.Value.IsTimeSliceTable select items;

                var timslicevalues = timeslices as List <KeyValuePair <string, EDataTable> > ?? timeslices.ToList();

                foreach (var items in timslicevalues)
                {
                    myDataList.Clear();
                    myNameList.Clear();
                    myDataList.Add(items.Value);
                    myNameList.Add(items.Key);
                    _tableCounter++;
                    var items1 = items;
                    var list   = dsData.Where(tbl => tbl.Value.TimeSliceRelationID == items1.Value.TimeSliceID);
                    foreach (var eDataTable in list)
                    {
                        myDataList.Add(eDataTable.Value);
                        myNameList.Add(eDataTable.Key);
                        _tableCounter++;
                    }

                    ExportCurrentData(excel, myDataList, style); //export the queries
                    FormatExcelSheet(excel, myDataList, myNameList);

                    if (_tableCounter < dsData.Count())
                    {
                        excel.Workbook.Worksheets.Add("Sheet");
                    }
                }
                #endregion
                excel.Save();
                excel.Dispose();
            }
        }