|
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using System.ComponentModel; |
| 4 | +using System.Data; |
| 5 | +using System.Drawing; |
| 6 | +using System.Linq; |
| 7 | +using System.Text; |
| 8 | +using System.Threading.Tasks; |
| 9 | +using System.Windows.Forms; |
| 10 | + |
| 11 | +namespace SqlCe2SQLite |
| 12 | +{ |
| 13 | + public partial class SqlCe2SQLiteDispData : Form |
| 14 | + { |
| 15 | + private string _SQLProvider; |
| 16 | + private string _SQLDB; |
| 17 | + |
| 18 | + public SqlCe2SQLiteDispData() |
| 19 | + { |
| 20 | + InitializeComponent(); |
| 21 | + |
| 22 | + this.toolStripStatusLabel1.Text = ""; |
| 23 | + this.textBoxTop.Text = "20"; |
| 24 | + |
| 25 | + this.radioButtonSQLite.Enabled = false; |
| 26 | + this.radioButtonSQLCe.Enabled = false; |
| 27 | + |
| 28 | + this.textBoxTableName.Enabled = false; |
| 29 | + |
| 30 | + this.splitContainer1.Dock = DockStyle.Fill; |
| 31 | + this.dataGridView1.Dock = DockStyle.Fill; |
| 32 | + this.textBoxAction.Dock = DockStyle.Fill; |
| 33 | + } |
| 34 | + |
| 35 | + private void SqlCe2SQLiteDispData_Load(object sender, EventArgs e) |
| 36 | + { |
| 37 | + // Load |
| 38 | + this.Top = 150; |
| 39 | + this.Left = 150; |
| 40 | + } |
| 41 | + |
| 42 | + public void SetData(string sqlCeOrSQLite, string tableName, string dBName) { |
| 43 | + if (sqlCeOrSQLite== "SQLCE") { |
| 44 | + this.radioButtonSQLCe.Checked = true; |
| 45 | + _SQLProvider = sqlCeOrSQLite; |
| 46 | + } |
| 47 | + if (sqlCeOrSQLite == "SQLITE") |
| 48 | + { |
| 49 | + this.radioButtonSQLite.Checked = true; |
| 50 | + _SQLProvider = sqlCeOrSQLite; |
| 51 | + } |
| 52 | + this.textBoxTableName.Text = tableName; |
| 53 | + _SQLDB = dBName; |
| 54 | + } |
| 55 | + |
| 56 | + private void buttonDisplayData_Click(object sender, EventArgs e) |
| 57 | + { |
| 58 | + // Display Data |
| 59 | + this.DisplayData(); |
| 60 | + } |
| 61 | + |
| 62 | + private bool DisplayData() |
| 63 | + { |
| 64 | + bool ret = false; |
| 65 | + |
| 66 | + this.toolStripStatusLabel1.Text = "Load Data..."; |
| 67 | + this.textBoxAction.Text = ""; |
| 68 | + //this.toolStripProgressBarTable.Value = 0; |
| 69 | + Application.DoEvents(); |
| 70 | + |
| 71 | + int maxRows = -1; |
| 72 | + try |
| 73 | + { |
| 74 | + maxRows = Convert.ToInt32(this.textBoxTop.Text); |
| 75 | + } |
| 76 | + catch (Exception) |
| 77 | + { |
| 78 | + } |
| 79 | + |
| 80 | + //int countTables = 0; |
| 81 | + int countRows = 0; |
| 82 | + |
| 83 | + StringBuilder sb = new StringBuilder(); |
| 84 | + |
| 85 | + KaJourDAL.KaJour_Global_LITE.SQLProvider = _SQLProvider; |
| 86 | + KaJourDAL.KaJour_Global_LITE.SQLConnStr = "Data Source='" + _SQLDB + "'"; |
| 87 | + |
| 88 | + // ############################################## |
| 89 | + sb.AppendLine(KaJourDAL.KaJour_Global_LITE.SQLProvider + ":"); |
| 90 | + |
| 91 | + var sqCEorLITE = new KaJourDAL.SQL(KaJourDAL.KaJour_Global_LITE.SQLProvider, KaJourDAL.KaJour_Global_LITE.SQLConnStr); |
| 92 | + DataTable tablesLITE = null; |
| 93 | + try |
| 94 | + { |
| 95 | + sqCEorLITE.Connect(); |
| 96 | + tablesLITE = sqCEorLITE.GetTableList("", false); |
| 97 | + sqCEorLITE.DisConnect(); |
| 98 | + } |
| 99 | + catch (Exception ex) |
| 100 | + { |
| 101 | + MessageBox.Show("Error: " + ex.Message); |
| 102 | + return ret; |
| 103 | + } |
| 104 | + |
| 105 | + var tableName = this.textBoxTableName.Text; |
| 106 | + sqCEorLITE.Connect(); |
| 107 | + var tableRec1 = sqCEorLITE.GetTableRecCount(tableName); |
| 108 | + sqCEorLITE.DisConnect(); |
| 109 | + |
| 110 | + //this.toolStripProgressBarTable.Value = ((iTable + 1) * 100) / tablesLITE.Rows.Count; |
| 111 | + Application.DoEvents(); |
| 112 | + |
| 113 | + sb.AppendLine(" " + tableName + " Rec:" + tableRec1.ToString()); |
| 114 | + |
| 115 | + //countRows += tableRec1; |
| 116 | + |
| 117 | + // Display |
| 118 | + var sel = "SELECT * FROM " + tableName; |
| 119 | + DataTable tableSelect = sqCEorLITE.Execute("SELECT", sel); |
| 120 | + for (int iRow = 0; iRow < tableSelect.Rows.Count; iRow++) |
| 121 | + { |
| 122 | + countRows++; |
| 123 | + |
| 124 | + for (int iCol = 0; iCol < tableSelect.Columns.Count; iCol++) |
| 125 | + { |
| 126 | + var colVal = tableSelect.Rows[iRow][iCol]; |
| 127 | + sb.Append(colVal); |
| 128 | + sb.Append(", "); |
| 129 | + } |
| 130 | + sb.AppendLine(""); |
| 131 | + |
| 132 | + if (iRow >= maxRows) |
| 133 | + { |
| 134 | + break; //====================> |
| 135 | + } |
| 136 | + } |
| 137 | + |
| 138 | + this.toolStripStatusLabel1.Text = "Load Data Ok."; |
| 139 | + this.textBoxAction.Text = sb.ToString(); |
| 140 | + //this.toolStripProgressBarTable.Value = 100; |
| 141 | + |
| 142 | + return ret; |
| 143 | + } |
| 144 | + |
| 145 | + } |
| 146 | +} |
0 commit comments