Esempio n. 1
0
        private void export_clients_status_data_grid_click(object sender, RoutedEventArgs e)
        {
            try
            {
                ExportCSV exportCSV = new ExportCSV(new ConfigMgr(),
                                                    $"{(long)(DateTime.Now - new DateTime(1970, 1, 1, 0, 0, 0, 0)).TotalMilliseconds}",
                                                    CSVExportType.CLIENTS_STATUS);

                clients_status_DataGrid.SelectAllCells();

                clients_status_DataGrid.ClipboardCopyMode = DataGridClipboardCopyMode.IncludeHeader;
                ApplicationCommands.Copy.Execute(null, clients_status_DataGrid);
                string result = (string)Clipboard.GetData(DataFormats.UnicodeText);
                exportCSV.ExportDataTableToCSV(result);

                clients_status_DataGrid.UnselectAllCells();

                snack_bar_with_action.IsActive = true;
                snack_bar_with_action.MessageQueue.Enqueue("ייצוא הטבלה הסתיים בהצלחה",
                                                           "פתח",
                                                           export_csv_snack_barAction,
                                                           exportCSV);
            }
            catch (FileNotFoundException)
            {
                DisplaySnackbar("התקיית קבצים לא קיימת, בדוק בהגדרות מערכת את ההגדרות שלך");
            }
            catch (Exception ex)
            {
                DisplaySnackbar("שגיאה כללית במערכת, אנא נסה שוב");
                Logger log = new Logger(new ConfigMgr());
                log.Error("general error on load tab", ex);
            }
        }
Esempio n. 2
0
        public override void work()
        {
            try
            {
                r.ReportDatabase.Connect();
                r.ReportDatabase.RunSQLReader(r.query);
                String path = Path.GetDirectoryName(r.QueryPath);

                ExportCSV export = new ExportCSV();

                export.exportPath    = path + "\\" + this.r.Name + DateTime.Now.ToString(" dd_M_yyyy HH_m_s") + ".csv";
                export.append        = true;
                export.quotedStrings = true;
                export.openStream();
                export.addRow(r.ReportDatabase.GetColumnNames());
                while (r.ReportDatabase.Read())
                {
                    export.addRow(r.ReportDatabase.GetNextRow());
                }
                export.export();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message + " " + r.Name);
            }
        }
Esempio n. 3
0
        private void export_working_schedule_data_grid_click(object sender, RoutedEventArgs e)
        {
            try
            {
                ExportCSV exportCSV = new ExportCSV(new ConfigMgr(),
                                                    $"{currentClientInWorkScheduleTab.ContactForm.Person_1.Id}-{currentClientInWorkScheduleTab.ContactForm.Person_2.Id}",
                                                    CSVExportType.SCHEDULE_WORKING);
                exportCSV.ExportScheduleWorkingToCSV(currentClientInWorkScheduleTab.WorkingScheduleTime.WorkProperties);

                snack_bar_with_action.IsActive = true;
                snack_bar_with_action.MessageQueue.Enqueue("ייצוא הטבלה הסתיים בהצלחה",
                                                           "פתח",
                                                           export_csv_snack_barAction,
                                                           exportCSV);
            }
            catch (FileNotFoundException)
            {
                DisplaySnackbar("התקיית קבצים לא קיימת, בדוק בהגדרות מערכת את ההגדרות שלך");
            }
            catch (Exception ex)
            {
                DisplaySnackbar("שגיאה כללית במערכת, אנא נסה שוב");
                Logger log = new Logger(new ConfigMgr());
                log.Error("general error on load tab", ex);
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Handles the Click event of the ExportCSVOne control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="RoutedEventArgs"/> instance containing the event data.</param>
        private void ExportCSVOne_Click(object sender, RoutedEventArgs e)
        {
            MessageBoxResult result = MessageBox.Show("Do you want to export selected movie data to CSV file?", "Choose one option", MessageBoxButton.YesNo, MessageBoxImage.Question);

            switch (result)
            {
            case MessageBoxResult.Yes:
            {
                var movie = dbMovies?.Where(x => !string.IsNullOrEmpty(exportId.Text) && x.MovieId == Convert.ToInt32(exportId.Text));

                if (movie == null || movie.Count() == 0)
                {
                    MessageBox.Show("Movie not found !! \nTry again");
                    break;
                }

                ExportCSV.Serialize(movie, exportId.Text);
                MessageBox.Show($"Completed - file MovieId-{exportId.Text}.csv created");
                break;
            }

            case MessageBoxResult.No:
                break;
            }
        }
Esempio n. 5
0
        private void btnexport_Click(object sender, EventArgs e)
        {
            SaveFileDialog savefileDialog = new SaveFileDialog();

            savefileDialog.Filter = "Excel files (*.csv)|*.csv;";

            if (savefileDialog.ShowDialog() == DialogResult.OK)
            {
                string selectedFileName = savefileDialog.FileName;

                DataTable dt = new DataTable();
                foreach (DataGridViewColumn col in dataGridView1.Columns)
                {
                    dt.Columns.Add(col.Name);
                }

                foreach (DataGridViewRow row in dataGridView1.Rows)
                {
                    DataRow dRow = dt.NewRow();
                    foreach (DataGridViewCell cell in row.Cells)
                    {
                        dRow[cell.ColumnIndex] = cell.Value;
                    }
                    dt.Rows.Add(dRow);
                }

                ExportCSV.CreateCSVFile(ref dt, selectedFileName);

                MessageBox.Show("Succefully Exported", "Export", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
        protected void btnExportData_Click(object sender, EventArgs e)
        {
            DataTable dt          = ((DataView)gvADAdminCountReportDataSource.Select(DataSourceSelectArguments.Empty)).Table;
            string    pageName    = Path.GetFileNameWithoutExtension(Page.AppRelativeVirtualPath);
            ExportCSV exportmyCSV = new ExportCSV();

            exportmyCSV.GetFile(dt, pageName);
        }
Esempio n. 7
0
 private void View_SaveCSV(object sender, PriceEventArgs args)
 {
     var export = new ExportCSV(args.FilePath, args.Models);
     if (!String.IsNullOrEmpty(export.WarningMessage))
     {
         View.WarningMessage(export.WarningMessage);
     }
 }
Esempio n. 8
0
        /// <summary>
        /// Handles the Click event of the ExportCSV control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="RoutedEventArgs"/> instance containing the event data.</param>
        private void ExportCSV_Click(object sender, RoutedEventArgs e)
        {
            MessageBoxResult result = MessageBox.Show("Do you want to export all data to CSV file?", "Choose one option", MessageBoxButton.YesNo, MessageBoxImage.Question);

            switch (result)
            {
            case MessageBoxResult.Yes:
            {
                if (dbMovies == null || dbMovies.Count() == 0)
                {
                    MessageBox.Show("No movies found !! \nTry again");
                    break;
                }

                ExportCSV.Serialize(dbMovies);
                MessageBox.Show($"Completed - file db.csv created");
                break;
            }

            case MessageBoxResult.No:
                break;
            }
        }
    protected void ExportTable_Click(object sender, EventArgs e)
    {
        string tableName = ReportTableList.SelectedValue;
        SqlDataSource dataSource;

        switch (tableName) {
            case "data_account":
                dataSource = accountDataSource;
                break;
            case "data_cardsale":
                dataSource = cardsaleDataSource;
                break;
            case "data_notice":
                dataSource = noticeDataSource;
                break;
            case "data_prestore":
                dataSource = prestoreDataSource;
                break;
            case "data_settlement":
                dataSource = settlementDataSource;
                break;
            default:
                dataSource = accountDataSource;
                break;
        }

        DataView dv = (DataView)dataSource.Select(DataSourceSelectArguments.Empty);
        ExportCSV csv = new ExportCSV(dv.Table, tableName);
        csv.run();
    }
Esempio n. 10
0
        public (Dictionary <int, List <double> > ramDetailBalTable, Dictionary <int, Dictionary <double, string> > remKey2ValueBalTable) calcBalance(ConcurrentDictionary <string, clientMachine.userPreference> userPreference, string outputFolder, char csvWriteSeparator, decimal requestID, ConcurrentDictionary <string, clientMachine.clientSession> clientSessionVariable, ConcurrentDictionary <decimal, clientMachine.request> requestDict, ConcurrentDictionary <decimal, clientMachine.response> responseDict, Dictionary <int, Dictionary <double, string> > distinctRamKey2Value, Dictionary <int, List <double> > distinctList)
        {
            //UNDER DEVELOPMENT
            Dictionary <double, string> retainedDimensionCriteria = new Dictionary <double, string>(); // selected code range of particular dimension
            //Transfer: Account(6100~8900) to Account(5100)
            string retainedAccountDimension = "Account";
            string retainedAccount          = "5200";
            double retainedAccountKey       = 0;
            string startPLaccount           = "6100";
            string endPLaccount             = "8900";

            int accountDimension = -1; // false

            for (int i = 0; i < distinctRamKey2Value.Count; i++)
            {
                if (distinctRamKey2Value[i][0].ToString().ToUpper() == retainedAccountDimension.ToUpper())
                {
                    accountDimension = i;
                }
            }

            if (distinctRamKey2Value.ContainsKey(accountDimension))
            {
                if (distinctRamKey2Value[accountDimension].Count > 1) // dimension
                {
                    for (double j = 1; j < distinctRamKey2Value[accountDimension].Count; j++)
                    {
                        if (string.Compare(distinctRamKey2Value[accountDimension][j].ToString().Replace(" ", ""), startPLaccount) >= 0 && string.Compare(distinctRamKey2Value[accountDimension][j].ToString().Replace(" ", ""), endPLaccount) <= 0)
                        {
                            retainedDimensionCriteria.Add(j, distinctRamKey2Value[accountDimension][j]); // output criteria dictionary for filtering data
                        }
                    }
                }

                foreach (var account in distinctRamKey2Value[accountDimension])
                {
                    if (account.Value.ToString() == retainedAccount)
                    {
                        retainedAccountKey = account.Key;
                    }
                }
            }

            if (requestDict[requestID].debugOutput == "Y")
            {
                for (int j = 0; j < distinctRamKey2Value[responseDict[requestID].periodChangeColumn].Count; j++)
                {
                    Console.WriteLine("periodChangeColumn " + responseDict[requestID].periodChangeColumn + " periodRow " + distinctRamKey2Value[responseDict[requestID].periodChangeColumn][j]);
                }
            }


            Dictionary <double, Dictionary <int, List <double> > > distinctListMovement = new Dictionary <double, Dictionary <int, List <double> > >();
            Dictionary <double, Dictionary <int, List <double> > > distinctListBalance  = new Dictionary <double, Dictionary <int, List <double> > >();
            ConcurrentQueue <int> checkThreadCompleted1 = new ConcurrentQueue <int>();
            ConcurrentDictionary <int, ComputeRow> writeMovementThread = new ConcurrentDictionary <int, ComputeRow>();

            int maxPeriod = distinctRamKey2Value[responseDict[requestID].periodChangeColumn].Count;
            int maxColumn = distinctRamKey2Value.Count;

            for (int currentPeriod = 0; currentPeriod < maxPeriod; currentPeriod++)
            {
                distinctListMovement.Add(currentPeriod, new Dictionary <int, List <double> >());
                distinctListBalance.Add(currentPeriod, new Dictionary <int, List <double> >());

                for (int column = 0; column < distinctRamKey2Value.Count; column++)
                {
                    distinctListMovement[currentPeriod].Add(column, new List <double>());
                    distinctListBalance[currentPeriod].Add(column, new List <double>());
                }
            }

            for (int worker = 0; worker < maxColumn; worker++)
            {
                writeMovementThread.TryAdd(worker, new ComputeRow());
            }

            var options = new ParallelOptions()
            {
                MaxDegreeOfParallelism = userPreference["system"].maxColumnThread
            };

            Parallel.For(0, maxColumn, options, column =>
            {
                writeMovementThread[column].writeMovementOneColumn(column, checkThreadCompleted1, distinctList, distinctListMovement, requestID, responseDict);
            });

            do
            {
                Thread.Sleep(2);
            } while (checkThreadCompleted1.Count < maxColumn);

            ConcurrentQueue <int> checkThreadCompleted2 = new ConcurrentQueue <int>();

            if (distinctRamKey2Value.ContainsKey(accountDimension))
            {
                ComputeRow accountCol = new ComputeRow();
                accountCol.writePreBalTableOneColumn(accountDimension, checkThreadCompleted2, maxPeriod, distinctListMovement, distinctListBalance, distinctRamKey2Value, requestID, responseDict, retainedAccountDimension, retainedDimensionCriteria, retainedAccount, accountDimension, retainedAccountKey);
            }

            ConcurrentDictionary <int, ComputeRow> writeColumnThread = new ConcurrentDictionary <int, ComputeRow>();

            for (int worker = 0; worker < maxColumn; worker++)
            {
                writeColumnThread.TryAdd(worker, new ComputeRow());
            }

            Parallel.For(0, maxColumn, options, column =>
            {
                if (column != accountDimension)
                {
                    writeColumnThread[column].writePreBalTableOneColumn(column, checkThreadCompleted2, maxPeriod, distinctListMovement, distinctListBalance, distinctRamKey2Value, requestID, responseDict, retainedAccountDimension, retainedDimensionCriteria, retainedAccount, accountDimension, retainedAccountKey);
                }
            });

            do
            {
                Thread.Sleep(2);
            } while (checkThreadCompleted2.Count < maxColumn);

            ConcurrentQueue <int> checkThreadCompleted3 = new ConcurrentQueue <int>();

            Dictionary <int, List <double> > ramDetailBalTable = new Dictionary <int, List <double> >();
            Dictionary <int, Dictionary <double, string> > remKey2ValueBalTable             = new Dictionary <int, Dictionary <double, string> >();
            ConcurrentDictionary <int, ComputeRow>         writeBalanceTableOneColumnThread = new ConcurrentDictionary <int, ComputeRow>();

            for (int column = 0; column <= maxColumn; column++)
            {
                ramDetailBalTable.Add(column, new List <double>());
            }

            remKey2ValueBalTable.Add(0, new Dictionary <double, string>());
            remKey2ValueBalTable[0].Add(0, "Period End");

            for (int i = 1; i < distinctRamKey2Value[responseDict[requestID].periodChangeColumn].Count; i++)
            {
                remKey2ValueBalTable[0].Add(i, distinctRamKey2Value[responseDict[requestID].periodChangeColumn][i]);
            }

            for (int i = 1; i <= distinctRamKey2Value.Count; i++)
            {
                remKey2ValueBalTable.Add(i, distinctRamKey2Value[i - 1]);
            }

            for (int i = 1; i < remKey2ValueBalTable.Count; i++)
            {
                if (remKey2ValueBalTable[i][0] == "Period End")
                {
                    remKey2ValueBalTable[i][0] = "Period Change";
                }
            }

            for (int i = 0; i < remKey2ValueBalTable.Count; i++)
            {
                ramDetailBalTable[i].Add(0);
            }

            for (int worker = 0; worker <= maxColumn; worker++)
            {
                writeBalanceTableOneColumnThread.TryAdd(worker, new ComputeRow());
            }

            maxColumn = maxColumn + 1;

            Parallel.For(0, maxColumn, options, column =>
            {
                writeBalanceTableOneColumnThread[column].writeBalTableOneColumn(column, checkThreadCompleted3, maxPeriod, distinctListBalance, ramDetailBalTable);
            });

            do
            {
                Thread.Sleep(2);
            } while (checkThreadCompleted3.Count < maxColumn);

            if (requestDict[requestID].debugOutput == "Y")
            {
                Console.WriteLine("ramDetailBalTable.Count " + ramDetailBalTable.Count + " " + "ramDetailBalTable[0].Count " + ramDetailBalTable[0].Count + " " + ramDetailBalTable[1].Count + " " + "remKey2ValueBalTable.Count " + remKey2ValueBalTable.Count + " " + remKey2ValueBalTable[0].Count + " " + remKey2ValueBalTable[0].Count);
            }

            int sumMovement = 0;

            foreach (var pair in distinctListMovement)
            {
                for (int j = 0; j < distinctListMovement[0].Count; j++)
                {
                    if (j == 0)
                    {
                        sumMovement = sumMovement + distinctListMovement[pair.Key][j].Count;
                    }
                }
            }

            int sumBalance = 0;

            foreach (var pair in distinctListBalance)
            {
                for (int j = 0; j < distinctListBalance[0].Count; j++)
                {
                    if (j == 0)
                    {
                        sumBalance = sumBalance + distinctListBalance[pair.Key][j].Count;
                    }
                }
            }

            if (requestDict[requestID].debugOutput == "Y")
            {
                Console.WriteLine("sumMovement " + sumMovement + " " + "sumBalance " + sumBalance);
            }

            if (requestDict[requestID].debugOutput == "Y")
            {
                if (!Directory.Exists(outputFolder + "debug"))
                {
                    Directory.CreateDirectory(outputFolder + "debug");
                }

                ExportCSV currentExport = new ExportCSV();
                currentExport.ramDistinct2CSV(userPreference, ramDetailBalTable, remKey2ValueBalTable, csvWriteSeparator, outputFolder + userPreference["system"].slash + "debug", "BalanceTable-numberOnly" + ".csv");
                currentExport.ramDistinct2CSVymTable(userPreference, ramDetailBalTable, remKey2ValueBalTable, csvWriteSeparator, outputFolder, userPreference["system"].slash + "debug" + userPreference["system"].slash + "BalanceTable" + ".csv");
            }
            return(ramDetailBalTable, remKey2ValueBalTable);
        }
Esempio n. 11
0
        public void mapColumn(ConcurrentDictionary <string, clientMachine.userPreference> userPreference, Dictionary <string, Dictionary <int, Dictionary <double, double> > > ramMapping, Dictionary <string, Dictionary <int, List <double> > > ramDetail, Dictionary <string, Dictionary <int, Dictionary <double, string> > > ramK2V, string outputFolder, char csvWriteSeparator, decimal requestID, ConcurrentDictionary <decimal, clientMachine.request> requestDict, ConcurrentDictionary <decimal, clientMachine.response> responseDict, Dictionary <int, List <double> > _ramDetailgz, Dictionary <int, Dictionary <double, string> > _ramKey2Valuegz)
        {
            Dictionary <int, List <double> > ramDetailgz = new Dictionary <int, List <double> >();
            Dictionary <int, Dictionary <double, string> > ramKey2Valuegz = new Dictionary <int, Dictionary <double, string> >();

            for (int i = 0; i < _ramKey2Valuegz.Count; i++)
            {
                ramDetailgz.Add(i, _ramDetailgz[i]);
                ramKey2Valuegz.Add(i, _ramKey2Valuegz[i]);
            }

            string joinKey;
            Dictionary <int, string> sourceColumnID2MappingFileName = new Dictionary <int, string>();

            responseDict[requestID].isMappingKeyFound = false;
            foreach (var file in ramK2V)
            {
                for (int i = 0; i < ramK2V[file.Key].Count; i++)
                {
                    if (ramK2V[file.Key][i][0].ToUpper().Contains("@KEY"))
                    {
                        responseDict[requestID].isMappingKeyFound = true;

                        joinKey = ramK2V[file.Key][i][0].ToUpper().Substring(0, ramK2V[file.Key][i][0].Length - 4);

                        for (int j = 0; j < _ramKey2Valuegz.Count; j++)
                        {
                            if (_ramKey2Valuegz[j][0].ToUpper() == joinKey)
                            {
                                sourceColumnID2MappingFileName.Add(j, file.Key); // link data source column to target table name
                            }
                        }
                    }
                }
            }

            if (sourceColumnID2MappingFileName.Count == 0)
            {
                responseDict[requestID].isMappingKeyFound = false;
            }

            if (sourceColumnID2MappingFileName.Count > 0)
            {
                if (requestDict[requestID].debugOutput == "Y")
                {
                    foreach (var pair in sourceColumnID2MappingFileName)
                    {
                        Console.WriteLine("sourceColumnID2MappingFileName " + pair.Key + "  " + pair.Value);

                        foreach (var mapping in ramMapping[pair.Value])
                        {
                            Console.WriteLine("mapping " + mapping.Key + "  " + mapping.Value);

                            foreach (var mappingRow in mapping.Value)
                            {
                                Console.WriteLine("mappingRow " + mappingRow.Key + "  " + mappingRow.Value);
                            }
                        }
                    }
                }

                Dictionary <string, Dictionary <string, double> > mapKeyV2K = new Dictionary <string, Dictionary <string, double> >();

                int line = 0;;
                foreach (var i in sourceColumnID2MappingFileName)
                {
                    mapKeyV2K.Add(i.Value, new Dictionary <string, double>());

                    foreach (var j in ramK2V[i.Value][0])
                    {
                        if (line == 0) // mark matched key e.g. ACCOUNT
                        {
                            mapKeyV2K[i.Value].Add(_ramKey2Valuegz[i.Key][0], j.Key);
                        }
                        else
                        {
                            mapKeyV2K[i.Value].Add(j.Value, j.Key);
                        }

                        // Console.WriteLine("zz mapKeyV2K Count " + j.Value + " " + j.Key);
                        line++;
                    }

                    // Console.WriteLine("mapKeyV2K Count " + mapKeyV2K[i.Value].Count);
                }

                Dictionary <string, Dictionary <double, double> > sourceK2MapK = new Dictionary <string, Dictionary <double, double> >();

                foreach (var i in sourceColumnID2MappingFileName)
                {
                    sourceK2MapK.Add(i.Value, new Dictionary <double, double>());

                    foreach (var j in _ramKey2Valuegz[i.Key])
                    {
                        sourceK2MapK[i.Value].Add(j.Key, mapKeyV2K[i.Value][j.Value]);
                    }
                }

                int g             = 0;
                int currentColumn = _ramKey2Valuegz.Count;

                if (responseDict[requestID].isMappingKeyFound == true && responseDict[requestID].isMapping == false)
                {
                    _ramDetailgz.Clear();
                    _ramKey2Valuegz.Clear();
                }

                foreach (var i in sourceColumnID2MappingFileName) // i is source column id of ramDetail
                {
                    for (int c = 0; c < (currentColumn + ramMapping[i.Value].Count); c++)
                    {
                        _ramDetailgz.Add(c, new List <double>());
                        _ramKey2Valuegz.Add(c, new Dictionary <double, string>());
                    }

                    do
                    {
                        if (g < i.Key + 1)
                        {
                            _ramDetailgz[g]    = ramDetailgz[g];
                            _ramKey2Valuegz[g] = ramKey2Valuegz[g];
                        }

                        if (g >= i.Key + 1 && g <= i.Key + ramMapping[i.Value].Count)
                        {
                            foreach (var k in ramMapping[i.Value])
                            {
                                for (int row = 0; row < _ramDetailgz[i.Key].Count; row++)
                                {
                                    _ramDetailgz[g].Add(ramMapping[i.Value][k.Key][sourceK2MapK[i.Value][_ramDetailgz[i.Key][row]]]);
                                }

                                _ramKey2Valuegz[g] = ramK2V[i.Value][k.Key];

                                g++;
                            }
                        }

                        if (g > i.Key + ramMapping[i.Value].Count)
                        {
                            _ramDetailgz[g]    = ramDetailgz[g - ramMapping[i.Value].Count];
                            _ramKey2Valuegz[g] = ramKey2Valuegz[g - ramMapping[i.Value].Count];
                        }

                        g++;
                    } while (g < ramKey2Valuegz.Count + ramMapping[i.Value].Count);
                }

                if (requestDict[requestID].debugOutput == "Y")
                {
                    foreach (var i in sourceColumnID2MappingFileName)
                    {
                        Console.WriteLine(_ramKey2Valuegz[i.Key][0]);
                        foreach (var k in ramMapping[i.Value])
                        {
                            for (int row = 0; row < _ramDetailgz[i.Key].Count; row++)
                            {
                                Console.WriteLine("zz " + ramMapping[i.Value].Count + " " + k.Key + " " + ramK2V[i.Value][k.Key][ramMapping[i.Value][k.Key][0]] + " " + ramMapping[i.Value][k.Key][sourceK2MapK[i.Value][_ramDetailgz[i.Key][row]]]);
                            }
                        }
                    }

                    ExportCSV currentExport = new ExportCSV();
                    currentExport.ramDistinct2CSV(userPreference, _ramDetailgz, _ramKey2Valuegz, csvWriteSeparator, outputFolder + userPreference["system"].slash + "debug", "mapping-numberOnly" + ".csv");
                    currentExport.ramDistinct2CSVymTable(userPreference, _ramDetailgz, _ramKey2Valuegz, csvWriteSeparator, outputFolder, userPreference["system"].slash + "debug" + userPreference["system"].slash + "mapping" + ".csv");
                }
            }
        }
Esempio n. 12
0
        private void SaveAsButton_Click(object sender, EventArgs e)
        {
            CheckOutputType();

            SaveFileDialog saveFile = new SaveFileDialog
            {
                Filter = $"{outputFileType} (*.{outputFileType})|*.{outputFileType}",
                Title  = $"Save as {outputFileType} File"
            };

            if (saveFile.ShowDialog() == DialogResult.OK)
            {
                outputFilePath = saveFile.FileName;

                if (sourceComboBox.SelectedIndex == 0)
                {
                    List <GFModel> modelsGF = new List <GFModel>();

                    try
                    {
                        modelsGF = ImportGF.ParseHTML(inputFilePath);
                    }
                    catch (Exception)
                    {
                        MessageBox.Show("Invalid file");

                        return;
                    }

                    if (outputFileType == "txt")
                    {
                        ExportTXT exportTXT = new ExportTXT(modelsGF, outputFilePath);
                    }
                    else if (outputFileType == "csv")
                    {
                        ExportCSV exportCSV = new ExportCSV(modelsGF, outputFilePath);
                    }
                }
                else if (sourceComboBox.SelectedIndex == 1)
                {
                    List <MALModel> modelsMAL = new List <MALModel>();

                    try
                    {
                        modelsMAL = ImportMAL.ParseXML(inputFilePath);
                    }
                    catch (Exception)
                    {
                        MessageBox.Show("Invalid file");

                        return;
                    }

                    if (outputFileType == "txt")
                    {
                        ExportTXT exportTXT = new ExportTXT(modelsMAL, outputFilePath);
                    }
                    else if (outputFileType == "csv")
                    {
                        ExportCSV exportCSV = new ExportCSV(modelsMAL, outputFilePath);
                    }
                }
            }
        }
Esempio n. 13
0
        public async Task ExportImg(int i)
        {
            int _cateLogId = (MyListView.SelectedItem as NewsListItemModel).CateLogId;
            List <IamgeSaveInfo> IamgeSaveInfoList = await SqliteUtil.Current.QueryIamgeSaveInfoByCateLogId(_cateLogId);

            var imageIdGroupList = IamgeSaveInfoList
                                   .GroupBy(x => new { x.ImageID, x.CateLogId, x.Imagebuffer })
                                   .Select(group => new
            {
                Keys = group.Key
            }).ToList();

            List <CataLogInfo> cataloginfo = await SqliteUtil.Current.QueryCataLogInfoByCateLogId(imageIdGroupList[0].Keys.CateLogId);

            List <ImageColorInfo> ImageColorInfoList = await SqliteUtil.Current.QueryImageColorInfoByImageID(imageIdGroupList[0].Keys.ImageID);

            ExportCSV exportinof = new ExportCSV();

            exportinof.Title     = cataloginfo[0].Title;
            exportinof.Folder    = cataloginfo[0].Folder;
            exportinof.ImagePath = IamgeSaveInfoList[0].ImagePath;

            exportinof.ColorList = new List <ExportColor>();

            foreach (ImageColorInfo color in ImageColorInfoList)
            {
                ExportColor exportcolor = new ExportColor();

                exportcolor.XValue       = color.XValue;
                exportcolor.YValue       = color.YValue;
                exportcolor.RGBValue     = color.RGBValue;
                exportcolor.HEXValue     = color.HEXValue;
                exportcolor.HSLValue     = color.HSLValue;
                exportcolor.HSVValue     = color.HSVValue;
                exportcolor.CMYKValue    = color.CMYKValue;
                exportcolor.LABValue     = color.LABValue;
                exportcolor.MUNSELLValue = color.MUNSELLValue;
                exportcolor.PCCSValue    = color.PCCSValue;
                exportcolor.JISValue     = color.JISValue;
                exportcolor.ScaledRatio  = color.ScaledRatio;
                exportcolor.XPis         = color.XPis;
                exportcolor.YPis         = color.YPis;
                exportcolor.DefX         = color.DefX;
                exportcolor.DefY         = color.DefY;

                exportinof.ColorList.Add(exportcolor);
            }

            var json = JsonConvert.SerializeObject(exportinof);

            string strreturnpath = string.Empty;

            if (i == 2)
            {
                await DependencyService.Get <IPhotoLibrary>().ShareAsync(exportinof.Title, json, System.Convert.FromBase64String(imageIdGroupList[0].Keys.Imagebuffer));
            }
            else
            {
                int result = await DependencyService.Get <IPhotoLibrary>().SaveAsync(exportinof.Title, json, System.Convert.FromBase64String(imageIdGroupList[0].Keys.Imagebuffer));
            }
        }
Esempio n. 14
0
        public void crosstabByCopyZero(ConcurrentDictionary <string, clientMachine.userPreference> userPreference, Dictionary <int, List <double> > YXMdistinctDrillKey, Dictionary <decimal, int> distinctDimensionChecksumList, Dictionary <double, decimal> crosstabAddress2DrillSetDict, char csvWriteSeparator, string outputFolder, decimal requestID, ConcurrentDictionary <string, clientMachine.clientSession> clientSessionVariable, ConcurrentDictionary <decimal, clientMachine.request> requestDict, List <int> measure, Dictionary <int, List <double> > distinctList, Dictionary <int, List <double> > XdistinctList, Dictionary <int, List <double> > YdistinctList, Dictionary <int, string> sortedRevisedXY, Dictionary <int, Dictionary <double, string> > distinctXramKey2Value, Dictionary <int, Dictionary <double, string> > distinctYramKey2Value, List <int> sortedXdimension, List <int> sortedYdimension, Dictionary <int, List <double> > YXMdistinctList, StringBuilder debug, int xAddressCol, int yAddressCol)
        {
            Dictionary <int, List <double> > XofSummarisedList = new Dictionary <int, List <double> >();   // X dimensions of SummarisedFullList
            Dictionary <int, List <double> > YofSummarisedList = new Dictionary <int, List <double> >();   // Y dimensions of SummarisedFullList
            List <decimal> XdimensionChecksumList = new List <decimal>();                                  // ChecksumList for X dimensions
            List <decimal> YdimensionChecksumList = new List <decimal>();                                  // ChecksumList for Y dimensions
            Dictionary <decimal, double> XdimensionChecksum2RecordNo = new Dictionary <decimal, double>(); // ChecksumList for X dimensions --> RecordNo mapping
            Dictionary <decimal, double> YdimensionChecksum2RecordNo = new Dictionary <decimal, double>(); // ChecksumList for Y dimensions --> RecordNo mapping
            List <decimal> XofSummarisedListChecksumList             = new List <decimal>();               // ChecksumList for X dimensions of SummarisedFullList
            List <decimal> YofSummarisedListChecksumList             = new List <decimal>();               // ChecksumList for Y dimensions of SummarisedFullList

            int x = 0; int y = 0;

            for (int i = 0; i < sortedRevisedXY.Count; i++)
            {
                if (sortedRevisedXY[i] == "X")
                {
                    XofSummarisedList.Add(x, new List <double>());
                    if (requestDict[requestID].debugOutput == "Y")
                    {
                        debug.Append("x " + x + " " + i);
                        debug.Append(Environment.NewLine);
                    }

                    for (int j = 0; j < distinctList[0].Count; j++)
                    {
                        XofSummarisedList[x].Add(distinctList[i][j]);
                    }

                    x++;
                }

                if (sortedRevisedXY[i] == "Y")
                {
                    YofSummarisedList.Add(y, new List <double>());
                    if (requestDict[requestID].debugOutput == "Y")
                    {
                        debug.Append("y " + y + " " + i);
                        debug.Append(Environment.NewLine);
                    }

                    for (int j = 0; j < distinctList[0].Count; j++)
                    {
                        YofSummarisedList[y].Add(distinctList[i][j]);
                    }
                    y++;
                }
            }

            Distinct getXY = new Distinct();

            XdimensionChecksumList        = getXY.getXYcheckSumList(XdistinctList, distinctXramKey2Value, sortedXdimension);
            YdimensionChecksumList        = getXY.getXYcheckSumList(YdistinctList, distinctYramKey2Value, sortedYdimension);
            XofSummarisedListChecksumList = getXY.getXYcheckSumList(XofSummarisedList, distinctXramKey2Value, sortedXdimension);
            YofSummarisedListChecksumList = getXY.getXYcheckSumList(YofSummarisedList, distinctYramKey2Value, sortedYdimension);

            ExportCSV currentExport = new ExportCSV();

            if (requestDict[requestID].debugOutput == "Y")
            {
                currentExport.ramTable2CSV(userPreference, XdistinctList, csvWriteSeparator, outputFolder, userPreference["system"].slash + "Debug" + userPreference["system"].slash + "XdistinctList" + ".csv");
                currentExport.ramTable2CSV(userPreference, YdistinctList, csvWriteSeparator, outputFolder, userPreference["system"].slash + "Debug" + userPreference["system"].slash + "YdistinctList" + ".csv");
                currentExport.ramTable2CSV(userPreference, XofSummarisedList, csvWriteSeparator, outputFolder, userPreference["system"].slash + "Debug" + userPreference["system"].slash + "XofSummarisedList" + ".csv");
                currentExport.ramTable2CSV(userPreference, YofSummarisedList, csvWriteSeparator, outputFolder, userPreference["system"].slash + "Debug" + userPreference["system"].slash + "YofSummarisedList" + ".csv");
            }

            for (int i = 0; i < XdimensionChecksumList.Count; i++)
            {
                XdimensionChecksum2RecordNo.Add(XdimensionChecksumList[i], i);
            }

            for (int i = 0; i < YdimensionChecksumList.Count; i++)
            {
                YdimensionChecksum2RecordNo.Add(YdimensionChecksumList[i], i);
            }

            if (requestDict[requestID].debugOutput == "Y")
            {
                debug.Append("distinctList: " + distinctList.Count + " distinctList[0]: " + distinctList[0].Count);
                debug.Append(Environment.NewLine);
            }

            if (distinctList.ContainsKey(xAddressCol))
            {
                distinctList.Remove(xAddressCol);
                distinctList.Add(xAddressCol, new List <double>());
                distinctList[xAddressCol].Add(0);
            }

            if (!distinctList.ContainsKey(xAddressCol))
            {
                distinctList.Add(xAddressCol, new List <double>());
                distinctList[xAddressCol].Add(0);
            }

            if (distinctList.ContainsKey(yAddressCol))
            {
                distinctList.Remove(yAddressCol);
                distinctList.Add(yAddressCol, new List <double>());
                distinctList[yAddressCol].Add(0);
            }

            if (!distinctList.ContainsKey(yAddressCol))
            {
                distinctList.Add(yAddressCol, new List <double>());
                distinctList[yAddressCol].Add(0);
            }

            for (int i = 1; i < distinctList[0].Count; i++)
            {
                distinctList[xAddressCol].Add(XdimensionChecksum2RecordNo[XofSummarisedListChecksumList[i]]);
                distinctList[yAddressCol].Add(YdimensionChecksum2RecordNo[YofSummarisedListChecksumList[i]]);
            }

            List <decimal> _distinctDimensionChecksumList = new List <decimal>();

            foreach (var pair in distinctDimensionChecksumList)
            {
                _distinctDimensionChecksumList.Add(pair.Key);
            }

            for (int i = 1; i < distinctList[0].Count; i++)
            {
                var key = distinctList[xAddressCol][i] * 100000 + distinctList[yAddressCol][i];
                crosstabAddress2DrillSetDict.Add(key, _distinctDimensionChecksumList[i - 1]);
            }

            if (requestDict[requestID].debugOutput == "Y")
            {
                currentExport.ramTable2CSV(userPreference, distinctList, csvWriteSeparator, outputFolder, userPreference["system"].slash + "Debug" + userPreference["system"].slash + "SummarisedListwithX&Yaddress" + ".csv");
            }

            // fill all cell of the final output by zero

            int start0Col = YdistinctList.Count;
            int end0Col   = YdistinctList.Count + ((XdistinctList[0].Count - 1) * measure.Count);

            for (int i = 0; i < YdistinctList.Count; i++)
            {
                YXMdistinctList[i]     = YdistinctList[i];
                YXMdistinctDrillKey[i] = YdistinctList[i];
            }

            List <double> source = new List <double>();

            for (int j = 0; j < YdistinctList[0].Count; j++)
            {
                source.Add(0);
            }

            for (int i = start0Col; i < end0Col; i++) // add zero for X and M column
            {
                YXMdistinctList.Add(i, new List <double>());
                YXMdistinctList[i].AddRange(source);
                YXMdistinctDrillKey.Add(i, new List <double>());
                YXMdistinctDrillKey[i].AddRange(source);
            }

            if (requestDict[requestID].debugOutput == "Y")
            {
                currentExport.ramTable2CSV(userPreference, YXMdistinctList, csvWriteSeparator, outputFolder, userPreference["system"].slash + "Debug" + userPreference["system"].slash + "YXMdistinctListwithZeroValue" + ".csv");
                currentExport.ramTable2CSV(userPreference, YXMdistinctList, csvWriteSeparator, outputFolder, userPreference["system"].slash + "Debug" + userPreference["system"].slash + "YXMdistinctDrillKeywithZeroValue" + ".csv");
            }

            int targetCol;
            int targetRow;

            for (int xValue = 1; xValue < XdistinctList[0].Count; xValue++) // fill number if target cell is not zero
            {
                for (int m = 0; m < measure.Count; m++)                     // read distinctList number and write to YXMdistinctList Table Header
                {
                    targetCol = start0Col + ((xValue - 1) * measure.Count) + m;
                    YXMdistinctList[targetCol][0]     = xValue;
                    YXMdistinctDrillKey[targetCol][0] = xValue;
                }
            }


            for (int m = measure.Count; m >= 1; m--) // read distinctList number and write to YXMdistinctList Table Body
            {
                for (int YXMrow = 1; YXMrow < distinctList[0].Count; YXMrow++)
                {
                    targetCol = start0Col + (Convert.ToInt32(distinctList[xAddressCol][YXMrow]) * measure.Count) - m;
                    targetRow = Convert.ToInt32(distinctList[yAddressCol][YXMrow]);
                    YXMdistinctList[targetCol][targetRow]     = distinctList[xAddressCol - m][YXMrow];
                    YXMdistinctDrillKey[targetCol][targetRow] = Convert.ToDouble(crosstabAddress2DrillSetDict[distinctList[xAddressCol][YXMrow] * 100000 + distinctList[yAddressCol][YXMrow]]);
                }
            }

            if (requestDict[requestID].debugOutput == "Y")
            {
                currentExport.ramTable2CSV(userPreference, YXMdistinctList, csvWriteSeparator, outputFolder, userPreference["system"].slash + "Debug" + userPreference["system"].slash + "fastYXMdistinctList" + ".csv");
                currentExport.ramTable2CSV(userPreference, YXMdistinctDrillKey, csvWriteSeparator, outputFolder, userPreference["system"].slash + "Debug" + userPreference["system"].slash + "fastYXMdistinctDrillKey" + ".csv");
                debug.Append("XdimensionChecksumList.Count " + XdimensionChecksumList.Count); debug.Append(Environment.NewLine);
                debug.Append("YdimensionChecksumList.Count " + YdimensionChecksumList.Count); debug.Append(Environment.NewLine);
                debug.Append("");
            }
        }
Esempio n. 15
0
        /// <summary>
        /// Запуск потока
        /// </summary>
        /// <param name="script"></param>
        private void runThread(object script)
        {
            // проверка принадлежности объекта script к классу Script
            Script scriptCurrent = script as Script;

            if (scriptCurrent == null)
            {
                log("Объект script не является классом Script");
                return;
            }

            // флаг, для возможности повторного выполнения SQL, в случае возникновения ошибок
            bool flagErrorSQL = false;

            // выполнение скрипта, в случае успешного выполнения
            for (int i = 0; i < _countErrorInterval; i++)
            {
                flagErrorSQL = false;
                try
                {
                    setStatusListResult(scriptCurrent.Tag, "Выполняется....", IMAGE_STATUS_PROCESS);

                    // Получение имени файла для сохранения
                    string outputFile = resultFile(scriptCurrent.Ifns, scriptCurrent.FileNameScript);

                    // Инициализация MS Excel
                    IExport csv = new ExportCSV(outputFile);
                    csv.initialize();
                    csv.useQuotes = checkBoxQuote.Checked;

                    // MS SQL запуск
                    SQL sqlModel = new SQL("Data Source=" + scriptCurrent.Server + ";Initial Catalog=" + scriptCurrent.Database + ";Integrated Security=SSPI;");
                    if (sqlModel.RunSQL(scriptCurrent.SQL, csv))
                    {
                        if (!csv.export())
                        {
                            log("Не удалось выполнить экспорт в Excel " + scriptCurrent.Ifns + " / "
                                + scriptCurrent.FileNameScript + " / " + csv.getLastError.Message + " / "
                                + csv.getLastError.StackTrace);
                            throw new Exception("Не удалось выполнить экспорт в Excel. " + csv.getLastError.Message);
                        }
                        else
                        {
                            log("Выполнен экспорт " + scriptCurrent.Ifns + " в " + outputFile);
                        }
                    }
                    else
                    {
                        log("Не удалось выполнить скрипт " + scriptCurrent.Ifns + " / "
                            + scriptCurrent.FileNameScript + " / " + sqlModel.lastError.Message);
                        flagErrorSQL = true; // только, если ошибка подключения или выполнения
                        throw new Exception("Не удалось выполнить скрипт. " + sqlModel.lastError.Message);
                    }
                }
                catch (Exception ex)
                {
                    log(ex.Message);
                    setStatusListResult(scriptCurrent.Tag, ex.Message, IMAGE_STATUS_ERROR);
                }


                if (flagErrorSQL)
                {
                    if (i < _countErrorInterval - 1) // если еще есть попытки
                    {
                        setStatusListResult(scriptCurrent.Tag, null, IMAGE_STATUS_WARNING);
                        Thread.Sleep(_countErrorIntervalMin * 60 * 1000);
                    }
                    else // если больше попыток нет
                    {
                        setStatusListResult(scriptCurrent.Tag, null, IMAGE_STATUS_STOP);
                    }
                }
                else
                {
                    setStatusListResult(scriptCurrent.Tag, "Завершено", IMAGE_STATUS_SUCCESS);
                    break;
                }
            }

            countFinishThread++;
        }
Esempio n. 16
0
        private async Task importPhoto()
        {
            try
            {
                string[] fileType = { "application/zip" };
                SmartApp.FilePicker.Abstractions.FileData fileData = await SmartApp.FilePicker.CrossFilePicker.Current.PickFile(fileType);

                if (fileData == null)
                {
                    return; // user canceled file picking
                }
                DependencyService.Get <IAdInterstitial>().ShowAd();
                // do import
                // 1. get json and png(byte[])
                string       pickedData = "";
                MemoryStream imageData  = new MemoryStream();
                using (ZipArchive archive = new ZipArchive(fileData.GetStream(), ZipArchiveMode.Read))
                {
                    var entry1 = archive.GetEntry("data.json");
                    using (StreamReader reader = new StreamReader(entry1.Open()))
                    {
                        pickedData = reader.ReadLine();
                    }

                    var entry2 = archive.GetEntry("image.png");
                    using (Stream reader = entry2.Open())
                    {
                        await entry2.Open().CopyToAsync(imageData);

                        //await reader.CopyToAsync(imageData);
                    }
                }
                //2. json -> colorList
                ExportCSV importInfo = new ExportCSV();
                importInfo = JsonConvert.DeserializeObject <ExportCSV>(pickedData);
                List <ImageColorInfo> ImageColorInfoList = new List <ImageColorInfo>();
                foreach (ExportColor color in importInfo.ColorList)
                {
                    ImageColorInfo inColor = new ImageColorInfo();

                    inColor.XValue       = color.XValue;
                    inColor.YValue       = color.YValue;
                    inColor.RGBValue     = color.RGBValue;
                    inColor.HEXValue     = color.HEXValue;
                    inColor.HSLValue     = color.HSLValue;
                    inColor.HSVValue     = color.HSVValue;
                    inColor.CMYKValue    = color.CMYKValue;
                    inColor.LABValue     = color.LABValue;
                    inColor.MUNSELLValue = color.MUNSELLValue;
                    inColor.PCCSValue    = color.PCCSValue;
                    inColor.JISValue     = color.JISValue;
                    inColor.ScaledRatio  = color.ScaledRatio;
                    inColor.XPis         = color.XPis;
                    inColor.YPis         = color.YPis;
                    inColor.DefX         = color.DefX;
                    inColor.DefY         = color.DefY;
                    ImageColorInfoList.Add(inColor);
                }

                //3. move to imagedetail page
                using (UserDialogs.Instance.Loading("Loading", null, null, true, MaskType.Black))
                {
                    ImageDetail imageDetail;
                    if (App.srcPage != null)
                    {
                        imageDetail = (ImageDetail)App.srcPage;
                        imageDetail.setImageDetail(imageData.ToArray(), ImageColorInfoList, "", "");
                        imageDetail.reload();
                    }
                    else
                    {
                        imageDetail = new ImageDetail(imageData.ToArray(), ImageColorInfoList, "", "");
                    }

                    App.Current.MainPage = imageDetail;
                }
            }
            catch (Exception ex)
            {
                System.Console.WriteLine("Exception choosing file: " + ex.ToString());
            }
        }