예제 #1
0
파일: FormMain.cs 프로젝트: ronluo/General
        private void toSQLiteDatabaseToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // TODO:
            SaveFileDialog saveFileDialog = new SaveFileDialog();
            saveFileDialog.Filter = "SQLite3 DB (*.db)|*.db";
            if (saveFileDialog.ShowDialog() == DialogResult.OK)
            {
                string fileName = saveFileDialog.FileName;
                try
                {
                    System.IO.FileInfo fileInfo = new System.IO.FileInfo(fileName);
                    //fileInfo.Create();
                    SQLiteConnection.CreateFile(fileInfo.FullName);

                    string connectionString = string.Format("Data Source={0};Pooling=true;FailIfMissing=false", fileInfo.FullName);
                    var connection = new System.Data.SQLite.SQLiteConnection(connectionString);
                    connection.Open();
                    int count = 0;
                    SqlGenerator sqlGenerator = new SqlGenerator();
                    foreach (EntitiesGenerator.Definitions.DataTable table in this.definition.Tables)
                    {
                        string sqlText = sqlGenerator.GenerateForSQLite(table);

                        var command = connection.CreateCommand();
                        command.CommandText = sqlText;
                        count += command.ExecuteNonQuery();
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Export", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
예제 #2
0
파일: FormMain.cs 프로젝트: ronluo/General
 private void toolStripMenuItem18_Click(object sender, EventArgs e)
 {
     SaveFileDialog saveFileDialog = new SaveFileDialog();
     saveFileDialog.Filter = "sql files (*.sql)|*.sql";
     if (saveFileDialog.ShowDialog() == DialogResult.OK)
     {
         string fileName = saveFileDialog.FileName;
         try
         {
             System.IO.FileInfo fileInfo = new System.IO.FileInfo(fileName);
             SqlGenerator sqlGenerator = new SqlGenerator();
             System.IO.StreamWriter streamWriter = fileInfo.CreateText();
             foreach (EntitiesGenerator.Definitions.DataTable table in this.definition.Tables)
             {
                 string sqlText = sqlGenerator.GenerateForSQLite(table);
                 streamWriter.Write(sqlText);
                 streamWriter.WriteLine(SQLITE_SQLSEPARATINGCHARACTER);
                 streamWriter.WriteLine();
             }
             streamWriter.Flush();
             streamWriter.Close();
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message, "Export", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
     }
 }
예제 #3
0
파일: FormMain.cs 프로젝트: ronluo/General
        private void toSqlCeDatabaseToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // TODO:
            SaveFileDialog saveFileDialog = new SaveFileDialog();
            saveFileDialog.Filter = "SQL Server Compact 4.0 Local Database (*.sdf)|*.sdf";
            if (saveFileDialog.ShowDialog() == DialogResult.OK)
            {
                string fileName = saveFileDialog.FileName;
                try
                {
                    string templateDatabaseFileName  =  Path.Combine(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Templates"), "sqlce.sdf");
                    File.Copy(templateDatabaseFileName, fileName, true);

                    System.IO.FileInfo fileInfo = new System.IO.FileInfo(fileName);
                    string connectionString = string.Format("Data Source={0}", fileInfo.FullName);
                    var connection = new SqlCeConnection(connectionString);
                    connection.Open();
                    int count = 0;
                    SqlGenerator sqlGenerator = new SqlGenerator();
                    foreach (EntitiesGenerator.Definitions.DataTable table in this.definition.Tables)
                    {
                        string sqlText = sqlGenerator.GenerateForMSSQL(table);

                        var command = connection.CreateCommand();
                        command.CommandText = sqlText;
                        count += command.ExecuteNonQuery();
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Export", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
예제 #4
0
파일: FormMain.cs 프로젝트: ronluo/General
        private void SaveSqlFile(System.IO.FileInfo fileInfo)
        {
            try
            {
                SqlGenerator sqlGenerator = new SqlGenerator();
                System.IO.StreamWriter streamWriter = fileInfo.CreateText();
                foreach (EntitiesGenerator.Definitions.DataTable table in this.definition.Tables)
                {
                    string sqlText = sqlGenerator.GenerateForMSSQL(table);
                    streamWriter.Write(sqlText);
                    streamWriter.WriteLine(SQLSEPARATINGCHARACTER);
                }
                streamWriter.Flush();
                streamWriter.Close();

                UpdateCurrentFile(fileInfo);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Save", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }