Ejemplo n.º 1
0
        private void btnDownloadData_Click(object sender, EventArgs e)
        {
            if (tbnSQLitePath.Text == "")
            {
                CommonHandler.ShowMessage(MessageType.Information, "请选择\"数据路径\"");
                tbnSQLitePath.Focus();
                return;
            }

            string sqlConnString = GetSqlServerConnectionString("123.57.229.128", "Toyota", "sa", "mxT1@mfb");
            string sqlitePath    = Path.Combine(tbnSQLitePath.Text.Trim(), "readonly.db");

            this.Cursor = Cursors.WaitCursor;
            SqlConversionHandler handler = new SqlConversionHandler(delegate(bool done,
                                                                             bool success, int percent, string msg)
            {
                Invoke(new MethodInvoker(delegate()
                {
                    pbrProgress.Value = percent;

                    if (done)
                    {
                        this.Cursor = Cursors.Default;

                        if (success)
                        {
                            File.Copy(sqlitePath, Path.Combine(Path.GetDirectoryName(sqlitePath), "writeable.db"), true);
                            CommonHandler.ShowMessage(MessageType.Information, "下载成功");
                            pbrProgress.Value = 0;
                        }
                        else
                        {
                            CommonHandler.ShowMessage(MessageType.Information, "下载失败\r\n" + msg);
                            pbrProgress.Value = 0;
                        }
                    }
                }));
            });
            SqlTableSelectionHandler selectionHandler = new SqlTableSelectionHandler(delegate(List <TableSchema> schema)
            {
                return(schema);
            });

            FailedViewDefinitionHandler viewFailureHandler = new FailedViewDefinitionHandler(delegate(ViewSchema vs)
            {
                return(null);
            });

            string password = null;

            SqlServerToSQLite.ConvertSqlServerToSQLiteDatabase(sqlConnString, sqlitePath, password, handler,
                                                               selectionHandler, viewFailureHandler, false, false);
        }
Ejemplo n.º 2
0
        private void btnStart_Click(object sender, EventArgs e)
        {
            ConversionConfiguration config = _manager.CurrentConfiguration;
            string sqlConnString           = config.ConnectionString;

            this.Cursor = Cursors.WaitCursor;
            SqlConversionHandler        handler            = this.OnSqlConversionHandler;
            SqlTableSelectionHandler    selectionHandler   = this.OnSqlTableSelectionHandler;
            FailedViewDefinitionHandler viewFailureHandler = this.OnFailedViewDefinitionHandler;

            SqlServerToSQLite.ConvertSqlServerToSQLiteDatabase(sqlConnString, config.SqLiteDatabaseFilePath, config.EncryptionPassword, handler, selectionHandler, viewFailureHandler, config.CreateTriggersEnforcingForeignKeys, config.TryToCreateViews);
        }
Ejemplo n.º 3
0
        private void btnDownloadDataForUpdate_Click(object sender, EventArgs e)
        {
            if (tbnSQLitePathForUpdate.Text == "")
            {
                CommonHandler.ShowMessage(MessageType.Information, "请选择\"数据路径\"");
                tbnSQLitePathForUpdate.Focus();
                return;
            }

            string sqlConnString = GetSqlServerConnectionString("192.168.1.99", "XinHuaXin_YQ", "DSAT", "DSAT");
            string sqlitePath    = Path.Combine(tbnSQLitePathForUpdate.Text.Trim(), "readonly.db");

            this.Cursor = Cursors.WaitCursor;
            SqlConversionHandler handler = new SqlConversionHandler(delegate(bool done,
                                                                             bool success, int percent, string msg)
            {
                Invoke(new MethodInvoker(delegate()
                {
                    pbrProgressForUpdate.Value = percent;

                    if (done)
                    {
                        this.Cursor = Cursors.Default;

                        if (success)
                        {
                            CommonHandler.ShowMessage(MessageType.Information, "下载成功");
                            pbrProgressForUpdate.Value = 0;
                        }
                        else
                        {
                            CommonHandler.ShowMessage(MessageType.Information, "下载失败\r\n" + msg);
                            pbrProgressForUpdate.Value = 0;
                        }
                    }
                }));
            });
            SqlTableSelectionHandler selectionHandler = new SqlTableSelectionHandler(delegate(List <TableSchema> schema)
            {
                return(schema);
            });

            FailedViewDefinitionHandler viewFailureHandler = new FailedViewDefinitionHandler(delegate(ViewSchema vs)
            {
                return(null);
            });

            string password = null;

            SqlServerToSQLite.ConvertSqlServerToSQLiteDatabase(sqlConnString, sqlitePath, password, handler,
                                                               selectionHandler, viewFailureHandler, false, false);
        }
Ejemplo n.º 4
0
        private static void ExecuteCommand()
        {
            if (!CommandLine.TryGetOptionValue("sqlConnString", out string sqlConnString))
            {
                throw new Exception("option \"-sqlConnString\" is require.");
            }
            if (!CommandLine.TryGetOptionValue("sqlitePath", out string sqlitePath))
            {
                throw new Exception("option \"-sqlitePath\" is require.");
            }

            var selected_tables = CommandLine.ValueOptions.Where(x => x.Name == "table").Select(x => x.Value.Trim()).ToArray();

            CommandLine.TryGetOptionValue("password", out string password);

            var allTable = CommandLine.ContainSwitchOption("allTable");

            if (!CommandLine.TryGetOptionValue("createTriggers", out bool createTriggers))
            {
                createTriggers = false;
            }

            if (!CommandLine.TryGetOptionValue("createViews", out bool createViews))
            {
                createViews = false;
            }

            if (!CommandLine.TryGetOptionValue("onlyMigrateTableStruct", out bool onlyMigrateTableStruct))
            {
                onlyMigrateTableStruct = false;
            }

            SqlServerToSQLite.ConvertSqlServerToSQLiteDatabase(sqlConnString, sqlitePath, password, (done, success, percent, msg) =>
            {
                if (done)
                {
                    Console.WriteLine("Done.");
                    Environment.Exit(0);
                }
                else
                {
                    Console.WriteLine($"{percent} : {msg}");
                }
            }, schema => schema.Where(x => selected_tables.Any(y => allTable || y.Equals(x.TableName, StringComparison.InvariantCultureIgnoreCase))).ToList()
                                                               , null, createTriggers, createViews, onlyMigrateTableStruct
                                                               );
        }
Ejemplo n.º 5
0
        private static void RunConversion(string sqlConnString)
        {
            if (string.IsNullOrEmpty(sqlConnString))
            {
                sqlConnString = Configuration.SqlServer;
            }
            var sqlitePath       = Configuration.Sqlite;
            var password         = Configuration.Password;
            var generateTriggers = Configuration.ExportTriggers;
            var tableRegex       = new Regex(Configuration.Tables, RegexOptions.IgnoreCase);
            SqlTableSelectionHandler selectionHandler = allTables =>
            {
                var tables = new List <TableSchema>();
                foreach (var table in allTables)
                {
                    if (tableRegex.IsMatch(table.TableName))
                    {
                        Console.WriteLine("Exporting table " + table.TableName);

                        tables.Add(table);
                    }
                }
                return(tables);
            };

            SqlConversionHandler handler = (done, success, percent, msg) =>
            {
                Console.WriteLine(percent + "% " + msg + (success ? "" : " - ERROR"));

                if (done)
                {
                    Console.WriteLine("Conversion done");
                }
            };

            FailedViewDefinitionHandler viewFailureHandler = vs =>
            {
                Console.WriteLine("Error on view " + vs.ViewName);

                return(null);
            };

            SqlServerToSQLite.ConvertSqlServerToSQLiteDatabase(sqlConnString, sqlitePath, password, handler,
                                                               selectionHandler, viewFailureHandler, generateTriggers, false);
        }
Ejemplo n.º 6
0
        private void dbConvert_Load(object sender, EventArgs e)
        {
            string text        = "";
            string appSettings = ConfigOperation.GetAppSettings("OLD_POS_DATABASE_NAME");

            text = ((!bool.Parse(ConfigOperation.GetAppSettings("OLD_POS_DATABASE_SSPI"))) ? string.Format("Data Source=(local)\\SQLExpress;Initial Catalog={0};User ID=sa;Password=1031", appSettings) : string.Format("Data Source=(local)\\SQLExpress;Initial Catalog={0};Integrated Security=SSPI;", appSettings));
            string sqlitePath = Program.DataPath + "\\Old_db.db3";

            Cursor = Cursors.WaitCursor;
            SqlConversionHandler        handler            = new SqlConversionHandler(_003CdbConvert_Load_003Eb__1_0);
            SqlTableSelectionHandler    selectionHandler   = null;
            FailedViewDefinitionHandler viewFailureHandler = new FailedViewDefinitionHandler(_003CdbConvert_Load_003Eb__1_2);
            string password       = "******";
            bool   createViews    = false;
            bool   createTriggers = false;

            SqlServerToSQLite.ConvertSqlServerToSQLiteDatabase(text, sqlitePath, password, handler, selectionHandler, viewFailureHandler, createTriggers, createViews);
        }
Ejemplo n.º 7
0
        private void btnStart_Click(object sender, EventArgs e)
        {
            if (!EnsureSaveLocationExists())
            {
                MessageBox.Show("Specified save location is in a directory that does not exist!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            ConversionConfiguration config = _manager.CurrentConfiguration;
            string sqlConnString           = config.ConnectionString;

            Cursor = Cursors.WaitCursor;
            SqlConversionProgressReportingHandler progressReportingHandler = OnSqlConversionProgressReportingHandler;
            SqlTableSelectionHandler    selectionHandlerDefinition         = OnSqlTableDefinitionSelectionHandler;
            SqlTableSelectionHandler    selectionHandlerRecords            = OnSqlTableRecordSelectionHandler;
            FailedViewDefinitionHandler viewFailureHandler = OnFailedViewDefinitionHandler;

            var filePathWithReplacedEnvironmentValues = Environment.ExpandEnvironmentVariables(config.SqLiteDatabaseFilePath);

            SqlServerToSQLite.ConvertSqlServerToSQLiteDatabase(sqlConnString, filePathWithReplacedEnvironmentValues, config.EncryptionPassword, progressReportingHandler, selectionHandlerDefinition, selectionHandlerRecords, viewFailureHandler, config.CreateTriggersEnforcingForeignKeys, config.TryToCreateViews);
        }
Ejemplo n.º 8
0
        private void btnStart_Click(object sender, EventArgs e)
        {
            string sqlConnString;

            if (cbxIntegrated.Checked)
            {
                sqlConnString = GetSqlServerConnectionString(txtSqlAddress.Text, (string)cboDatabases.SelectedItem);
            }
            else
            {
                sqlConnString = GetSqlServerConnectionString(txtSqlAddress.Text, (string)cboDatabases.SelectedItem, txtUserDB.Text, txtPassDB.Text);
            }
            bool createViews = cbxCreateViews.Checked;

            string sqlitePath = txtSQLitePath.Text.Trim();

            this.Cursor = Cursors.WaitCursor;
            SqlConversionHandler handler = new SqlConversionHandler(delegate(bool done,
                                                                             bool success, int percent, string msg) {
                Invoke(new MethodInvoker(delegate() {
                    UpdateSensitivity();
                    lblMessage.Text   = msg;
                    pbrProgress.Value = percent;

                    if (done)
                    {
                        btnStart.Enabled = true;
                        this.Cursor      = Cursors.Default;
                        UpdateSensitivity();

                        if (success)
                        {
                            MessageBox.Show(this,
                                            msg,
                                            "Conversion Finished",
                                            MessageBoxButtons.OK,
                                            MessageBoxIcon.Information);
                            pbrProgress.Value = 0;
                            lblMessage.Text   = string.Empty;
                        }
                        else
                        {
                            if (!_shouldExit)
                            {
                                MessageBox.Show(this,
                                                msg,
                                                "Conversion Failed",
                                                MessageBoxButtons.OK,
                                                MessageBoxIcon.Error);
                                pbrProgress.Value = 0;
                                lblMessage.Text   = string.Empty;
                            }
                            else
                            {
                                Application.Exit();
                            }
                        }
                    }
                }));
            });
            SqlTableSelectionHandler selectionHandler = new SqlTableSelectionHandler(delegate(List <TableSchema> schema)
            {
                List <TableSchema> updated = null;
                Invoke(new MethodInvoker(delegate
                {
                    // Allow the user to select which tables to include by showing him the
                    // table selection dialog.
                    TableSelectionDialog dlg = new TableSelectionDialog();
                    DialogResult res         = dlg.ShowTables(schema, this);
                    if (res == DialogResult.OK)
                    {
                        updated = dlg.IncludedTables;
                    }
                }));
                return(updated);
            });

            FailedViewDefinitionHandler viewFailureHandler = new FailedViewDefinitionHandler(delegate(ViewSchema vs)
            {
                string updated = null;
                Invoke(new MethodInvoker(delegate
                {
                    ViewFailureDialog dlg = new ViewFailureDialog();
                    dlg.View         = vs;
                    DialogResult res = dlg.ShowDialog(this);
                    if (res == DialogResult.OK)
                    {
                        updated = dlg.ViewSQL;
                    }
                    else
                    {
                        updated = null;
                    }
                }));

                return(updated);
            });

            string password = txtPassword.Text.Trim();

            if (!cbxEncrypt.Checked)
            {
                password = null;
            }
            SqlServerToSQLite.ConvertSqlServerToSQLiteDatabase(sqlConnString, sqlitePath, password, handler,
                                                               selectionHandler, viewFailureHandler, cbxTriggers.Checked, createViews);
        }
Ejemplo n.º 9
0
    private void dbConvert_Load(object sender, EventArgs e)
    {
        string text        = "";
        string appSettings = ConfigOperation.GetAppSettings("OLD_POS_DATABASE_NAME");

        text = ((!bool.Parse(ConfigOperation.GetAppSettings("OLD_POS_DATABASE_SSPI"))) ? $"Data Source=(local)\\SQLExpress;Initial Catalog={appSettings};User ID=sa;Password=1031" : $"Data Source=(local)\\SQLExpress;Initial Catalog={appSettings};Integrated Security=SSPI;");
        string sqlitePath = Program.DataPath + "\\Old_db.db3";

        Cursor = Cursors.WaitCursor;
        SqlConversionHandler handler = delegate(bool done, bool success, int percent, string msg)
        {
            dbConvert dbConvert = this;
            Invoke((MethodInvoker) delegate
            {
                dbConvert.lblMessage.Text   = msg;
                dbConvert.pbrProgress.Value = percent;
                if (done)
                {
                    dbConvert.Cursor = Cursors.Default;
                    if (success)
                    {
                        MessageBox.Show(dbConvert, msg, "資料移轉成功", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                        dbConvert.Close();
                    }
                    else
                    {
                        MessageBox.Show(dbConvert, msg, "資料移轉失敗", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                        dbConvert.pbrProgress.Value = 0;
                        dbConvert.lblMessage.Text   = string.Empty;
                        Application.Exit();
                    }
                }
            });
        };
        SqlTableSelectionHandler    selectionHandler   = null;
        FailedViewDefinitionHandler viewFailureHandler = delegate(ViewSchema vs)
        {
            dbConvert owner   = this;
            string    updated = null;
            Invoke((MethodInvoker) delegate
            {
                ViewFailureDialog viewFailureDialog = new ViewFailureDialog
                {
                    View = vs
                };
                if (viewFailureDialog.ShowDialog(owner) == DialogResult.OK)
                {
                    updated = viewFailureDialog.ViewSQL;
                }
                else
                {
                    updated = null;
                }
            });
            return(updated);
        };
        string password       = "******";
        bool   createViews    = false;
        bool   createTriggers = false;

        SqlServerToSQLite.ConvertSqlServerToSQLiteDatabase(text, sqlitePath, password, handler, selectionHandler, viewFailureHandler, createTriggers, createViews);
    }
Ejemplo n.º 10
0
        static void Main(String[] args)
        {
            _options = new Options();
            var result = CommandLine.Parser.Default.ParseArguments(args, _options);

            if (!result)
            {
                AddMessage("Invalid Arguments");
                return;
            }

            String logFilePath = _options.LogFile;

            if (!String.IsNullOrWhiteSpace(logFilePath))
            {
                if (File.Exists(logFilePath))
                {
                    File.Delete(logFilePath);
                }
                _logFileStream = new StreamWriter(File.OpenWrite(logFilePath));
            }

            String  filename = _options.ConfigFile;
            Boolean success  = SerializationHelper.TryXmlDeserialize(filename, out _config);

            if (!success)
            {
                AddMessage("The selected file was not a valid configuration file for this application.");
                return;
            }

            if (!String.IsNullOrWhiteSpace(_options.DatabaseName))
            {
                // Allow user to override database name.
                AddMessage(String.Format("A database name was supplied as an argument.  Configured database will not be used."));
                _config.DatabaseName = _options.DatabaseName;
            }

            AddMessage(String.Format("Converting database: {0}", _config.DatabaseName));

            String sqlConnString = _config.ConnectionString;

            SqlConversionProgressReportingHandler progressReportingHandler = OnSqlConversionProgressReportingHandler;
            SqlTableSelectionHandler    selectionHandlerDefinition         = OnSqlTableDefinitionSelectionHandler;
            SqlTableSelectionHandler    selectionHandlerRecords            = OnSqlTableRecordSelectionHandler;
            FailedViewDefinitionHandler viewFailureHandler = OnFailedViewDefinitionHandler;

            var filePathWithReplacedEnvironmentValues = Environment.ExpandEnvironmentVariables(_config.SqLiteDatabaseFilePath);
            var task = SqlServerToSQLite.ConvertSqlServerToSQLiteDatabase(sqlConnString, filePathWithReplacedEnvironmentValues, _config.EncryptionPassword, progressReportingHandler, selectionHandlerDefinition, selectionHandlerRecords, viewFailureHandler, _config.CreateTriggersEnforcingForeignKeys, _config.TryToCreateViews);

            task.Wait();

            if (task.Exception != null)
            {
                AddMessage("An error has occurred.  Details:");
                var exception = task.Exception;

                AddMessage(exception.ToString(), false);

                foreach (var innerException in exception.InnerExceptions)
                {
                    AddMessage(innerException.ToString(), false);
                }
            }

            if (_logFileStream != null)
            {
                _logFileStream.Dispose();
            }
        }
Ejemplo n.º 11
0
        private void btnSqlServerSQLite_Click(object sender, EventArgs e)
        {
            string tempFilePath  = string.Empty;
            string SqlServerPath = string.Empty;
            string sqlConnString;
            string dbname;

            string tempDirPath = Path.GetTempPath() + @"\SqlConverter";

            if (Directory.Exists(tempDirPath))
            {
                Directory.Delete(tempDirPath, true);
            }
            System.IO.Directory.CreateDirectory(tempDirPath);
            DirectoryInfo     tempDirInfo     = new DirectoryInfo(tempDirPath);
            DirectorySecurity tempDirSecurity = tempDirInfo.GetAccessControl();

            tempDirSecurity.AddAccessRule(new FileSystemAccessRule("everyone", FileSystemRights.FullControl, AccessControlType.Allow));
            tempDirInfo.SetAccessControl(tempDirSecurity);

            string SQLitePath = Path.GetFullPath(txtSQLitePath.Text);

            if (cboWhatToCopy.SelectedIndex == 2)       //  ie if we are copying into an existing database
            {
                if (!File.Exists(SQLitePath))
                {
                    MessageBox.Show("Output file '" + SQLitePath + "' not found.", "File not found", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
            }
            else
            {
                if (File.Exists(SQLitePath))
                {
                    DialogResult result = MessageBox.Show("Replace existing file '" + SQLitePath + "'?", "Confirm replace file", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
                    if (result != DialogResult.OK)
                    {
                        return;
                    }
                }
            }

            if (txtSqlServerPath.Text != string.Empty)
            {
                SqlServerPath = Path.GetFullPath(txtSqlServerPath.Text);
                if (!File.Exists(SqlServerPath))
                {
                    MessageBox.Show("Input file " + SqlServerPath + " not found.", "File not found", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return;
                }

                tempFilePath = Path.GetFullPath(tempDirPath + @"\" + Path.GetFileName(txtSqlServerPath.Text));

                System.IO.File.Copy(SqlServerPath, tempFilePath);

                File.SetAttributes(tempFilePath, File.GetAttributes(tempFilePath) & ~FileAttributes.ReadOnly);

                string constr;
                if (cbxIntegrated.Checked)
                {
                    constr = GetSqlServerConnectionString(txtSqlAddress.Text, "master");
                }
                else
                {
                    constr = GetSqlServerConnectionString(txtSqlAddress.Text, "master", txtUserDB.Text, txtPassDB.Text);
                }
                using (SqlConnection conn = new SqlConnection(constr)) {
                    conn.Open();
                    SqlCommand query = new SqlCommand(@"CREATE DATABASE SqlConverter on (FILENAME=N'" + tempFilePath + "') FOR ATTACH", conn);
                    query.ExecuteNonQuery();
                    dbname = "SqlConverter";
                }
            }
            else
            {
                dbname = (string)cboDatabases.SelectedItem;
            }

            if (cbxIntegrated.Checked)
            {
                sqlConnString = GetSqlServerConnectionString(txtSqlAddress.Text, dbname);
            }
            else
            {
                sqlConnString = GetSqlServerConnectionString(txtSqlAddress.Text, dbname, txtUserDB.Text, txtPassDB.Text);
            }

            this.Cursor = Cursors.WaitCursor;
            SqlConversionHandler handler = new SqlConversionHandler(delegate(bool done,
                                                                             bool success, int percent, string msg) {
                Invoke(new MethodInvoker(delegate() {
                    UpdateSensitivity();
                    lblMessage.Text   = msg;
                    pbrProgress.Value = percent;

                    if (done)
                    {
                        if (txtSqlServerPath.Text != string.Empty)
                        {
                            dropSqlConverterDatabase();
                            Directory.Delete(tempDirPath, true);
                        }
                        btnSqlServerSQLite.Enabled = true;
                        this.Cursor = Cursors.Default;
                        UpdateSensitivity();

                        if (success)
                        {
                            MessageBox.Show(this,
                                            msg,
                                            "Conversion Finished",
                                            MessageBoxButtons.OK,
                                            MessageBoxIcon.Information);
                            pbrProgress.Value = 0;
                            lblMessage.Text   = string.Empty;
                        }
                        else
                        {
                            if (!_shouldExit)
                            {
                                MessageBox.Show(this,
                                                msg,
                                                "Conversion Failed",
                                                MessageBoxButtons.OK,
                                                MessageBoxIcon.Error);
                                pbrProgress.Value = 0;
                                lblMessage.Text   = string.Empty;
                            }
                            else
                            {
                                Application.Exit();
                            }
                        }
                    }
                }));
            });
            SqlTableSelectionHandler selectionHandler = new SqlTableSelectionHandler(delegate(List <TableSchema> schema)
            {
                List <TableSchema> updated = null;
                Invoke(new MethodInvoker(delegate
                {
                    // Allow the user to select which tables to include by showing him the
                    // table selection dialog.
                    TableSelectionDialog dlg = new TableSelectionDialog();
                    DialogResult res         = dlg.ShowTables(schema, this);
                    if (res == DialogResult.OK)
                    {
                        updated = dlg.IncludedTables;
                    }
                }));
                return(updated);
            });

            FailedViewDefinitionHandler viewFailureHandler = new FailedViewDefinitionHandler(delegate(ViewSchema vs)
            {
                string updated = null;
                Invoke(new MethodInvoker(delegate
                {
                    ViewFailureDialog dlg = new ViewFailureDialog();
                    dlg.View         = vs;
                    DialogResult res = dlg.ShowDialog(this);
                    if (res == DialogResult.OK)
                    {
                        updated = dlg.ViewSQL;
                    }
                    else
                    {
                        updated = null;
                    }
                }));

                return(updated);
            });

            string password = txtPassword.Text.Trim();

            if (!cbxEncrypt.Checked)
            {
                password = null;
            }

            bool copyStructure = (cboWhatToCopy.SelectedIndex != 2);
            bool copyData      = (cboWhatToCopy.SelectedIndex != 1);

            SqlServerToSQLite.ConvertSqlServerToSQLiteDatabase(sqlConnString, SQLitePath, password, handler,
                                                               selectionHandler, viewFailureHandler, cbxTriggers.Checked, cbxCreateViews.Checked, copyStructure, copyData);
        }