Пример #1
0
        private void SaveCategoryDictionaryFileBtn_Click(object sender, EventArgs e)
        {
            var dialogResult = saveFileDialog1.ShowDialog();

            if (dialogResult != DialogResult.OK)
            {
                if (dialogResult != DialogResult.OK)
                {
                    WriteLog("Target File Not OK: " + dialogResult.ToString());
                    return;
                }
            }

            WriteLog("Begin writing category dictionary to " + saveFileDialog1.FileName);

            var writer = new CSVFileOutputAgent(saveFileDialog1.FileName, false);

            List <string> headerRow = new List <string>();

            for (int i = 0; i < CategoryFilterDataGridView.Columns.Count; i++)
            {
                headerRow.Add(CategoryFilterDataGridView.Columns[i].HeaderText);
            }

            writer.WriteHeaderRow(headerRow);

            for (int i = 0; i < CategoryFilterDataGridView.Rows.Count; i++)
            {
                List <string> contentRow = new List <string>();

                bool hasContent = false;

                for (int j = 0; j < CategoryFilterDataGridView.Columns.Count; j++)
                {
                    string x = (string)CategoryFilterDataGridView.Rows[i].Cells[j].Value;
                    if (x != null && !x.Equals(""))
                    {
                        hasContent = true;
                    }
                    contentRow.Add(x);
                }

                if (hasContent)
                {
                    writer.WriteOneRowWithColumnIndex(contentRow);
                }
            }

            writer.FinishWrite();

            WriteLog("Finished writing category dictionary");
        }
Пример #2
0
        private void ExportSqlBtn_Click(object sender, EventArgs e)
        {
            if (TheSqliteAgent == null)
            {
                WriteLog("No SQLite Agent");
                return;
            }

            saveFileDialog1.DefaultExt = ".csv";
            DialogResult result = saveFileDialog1.ShowDialog();

            if (result != DialogResult.OK)
            {
                return;
            }

            var writer = new CSVFileOutputAgent(saveFileDialog1.FileName, false);

            WriteLog("Prepared output CSV file: " + saveFileDialog1.FileName);

            try
            {
                WriteLog("Querying sql: \n\r" + QuerySqlTextBox.Text);
                var reader = TheSqliteAgent.QueryResultRows(QuerySqlTextBox.Text);

                bool isFirstRow = true;

                while (reader.Read())
                {
                    if (isFirstRow)
                    {
                        List <string> headers = new List <string>();
                        for (int i = 0; i < reader.FieldCount; i++)
                        {
                            var header = reader.GetName(i);
                            headers.Add(header);
                        }
                        writer.WriteHeaderRow(headers);
                        isFirstRow = false;
                    }
                    List <string> oneRow = new List <string>();
                    for (int i = 0; i < reader.FieldCount; i++)
                    {
                        var    type = reader.GetDataTypeName(i).ToUpper();
                        string value;
                        switch (type)
                        {
                        case "INTEGER":
                            value = "" + reader.GetInt64(i);
                            break;

                        case "REAL":
                            value = "" + reader.GetDouble(i);
                            break;

                        case "TEXT":
                            value = reader.GetString(i);
                            break;

                        default:
                            value = "" + reader.GetValue(i);
                            break;
                        }
                        //WriteLog("Value: " + value, "DEBUG");

                        oneRow.Add(value);
                    }
                    //queryResultDataGridView.Rows.Add(oneRow.Values.ToArray<object>());
                    //allRows.Add(oneRow);

                    writer.WriteOneRowWithColumnIndex(oneRow);
                }

                writer.FinishWrite();
                WriteLog("Finished export!");
            }
            catch (Exception exception)
            {
                WriteLog("Exception: " + exception.Message, "ERROR");
                WriteLog("Stack: " + exception.StackTrace, "ERROR");
            }
        }