Exemplo n.º 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();
        }
Exemplo n.º 2
0
        private void ExportProfile(object o)
        {
            var profile = o as Profile;
            var finalDictionary = new EDataTableDictionary();

            if (profile != null)
                foreach (var query in profile.Queries)
                {

                    var table = QueryBuilder.GetDataTable(query);
                    if(table.Rows.Count == 0)
                        continue;

                    table.TableName = query.QueryName;
                    var periods = query.TimeSlice.ExtractedPeriods;

                    var tdays = from items in query.TimeSlice.SelectedDays
                                where items.Value
                                select items.Key;

                    var queryId = query.QueryId;

                    var tfinalBuilder = new EDataTableBuilder(table, queryId);
                    var selectedColumns = query.SelectedCols;
                    var dtype = query.TimeFrame == "Tick" ? EDataTableBuilder.DataType.Tick : EDataTableBuilder.DataType.Bar;
                    tfinalBuilder.CreateTimeSliceTables(tdays.ToList(), periods.ToList(), dtype,selectedColumns);

                    foreach(var tableTs in tfinalBuilder.GetTimeSliceTable())
                    {
                        CustomFormulaManager.Initialize(query, tableTs,
                                                        new EDataTable(1, true, false),
                                                        table);

                        CustomFormulaManager.CalculateTimeSliceTable();

                        finalDictionary.AddRange(tfinalBuilder.ETableDictionary);
                    }

                    var sdays = from items in query.SnapShoot.SelectedDays
                                where items.Value
                                select items.Key;
                    var stimeFrames = from items in query.SnapShoot.ExtrTimes
                                      select TimeSpan.Parse(items);
                    tfinalBuilder.CreateSnapShotTables(sdays.ToList(), stimeFrames.ToList());
                    foreach (var tableSS in tfinalBuilder.GetSnapShotTable())
                    {
                        CustomFormulaManager.Initialize(query, tableSS,
                                                        tableSS,
                                                        table);
                        CustomFormulaManager.CalculateSnapShootTable();

                        finalDictionary.AddRange(tfinalBuilder.ETableDictionary);
                    }
                    finalDictionary.AddRange(tfinalBuilder.ETableDictionary);

                }
            var oldThread = Thread.CurrentThread.CurrentCulture;
            Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
            var excel = new ExportManager();
            var formatStyle = new EStyleManager();
            excel.ExcelFormattingStyle = formatStyle;
            finalDictionary.Normalize();
            excel.ExportRowProgress += ExportProgress;
            CheckDictionaryForEmptyData(finalDictionary);

               if(CheckDictionaryForEmptyData(finalDictionary))
               {
               Invoke((Action) delegate
                                   {
                                       ui_Exprot_button.Enabled = false;
                                   });

               if (profile != null)
                   excel.ExportDataToExcel(finalDictionary, ExportStyle.ColumnWise,profile.Parameters.ProfileName);
               }
               else
               {
               Invoke((Action)delegate
               {
                   ToastNotification.Show(this, @"The profile's queries are not found any data.", 2000, eToastPosition.MiddleCenter);
               });
               }

            Thread.CurrentThread.CurrentCulture = oldThread;

            if(Thread.CurrentThread.IsAlive)
                Thread.CurrentThread.Abort();
        }
Exemplo n.º 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();

            }
        }
Exemplo n.º 4
0
 private bool CheckDictionaryForEmptyData(EDataTableDictionary finalDictionary)
 {
     var resultList = from tables in finalDictionary
                      let table = tables.Value
                      where table.SnapshotRelationID > 0 || table.TimeSliceRelationID > 0
                      select
                          tables.Value;
     return resultList.Any();
 }