Esempio n. 1
0
        private void OKButton_Click(object sender, RoutedEventArgs e)
        {
            try {
                using (var connection = new VfpConnection(txtDataPath.Text)) {
                    connection.Open();
                    connection.Close();
                }
            }
            catch (Exception) {
                MessageBox.Show("Invalid connection string.", Title, MessageBoxButton.OK, MessageBoxImage.Error);

                e.Handled = true;
            }

            if (e.Handled)
            {
                return;
            }

            _connectionInfo.DynamicSchemaOptions.NoPluralization  = !Pluralization.IsChecked.Value;
            _connectionInfo.DynamicSchemaOptions.NoCapitalization = !Capitalize.IsChecked.Value;

            var singularizeElement = _connectionInfo.DriverData.Element("Singularize");

            if (singularizeElement == null)
            {
                _connectionInfo.DriverData.Add(new XElement("Singularize", Singularize.IsChecked.Value));
            }
            else
            {
                singularizeElement.Value = Singularize.IsChecked.Value.ToString();
            }

            DialogResult = true;
        }
Esempio n. 2
0
        public void PackTest()
        {
            var dbc     = CreateTempDbc();
            var builder = new VfpConnectionStringBuilder(dbc);

            builder.Deleted = false;

            using (var connection = new VfpConnection(builder.ConnectionString)) {
                connection.Open();

                using (var command = connection.CreateCommand()) {
                    command.CommandText = "select count(*) from temp";

                    Assert.AreEqual(13, Convert.ToInt32(command.ExecuteScalar()));

                    command.CommandText = "delete from temp where upper(allt(TableName)) == 'CUSTOMERS'";
                    command.ExecuteNonQuery();

                    command.CommandText = "select count(*) from temp";

                    Assert.AreEqual(13, Convert.ToInt32(command.ExecuteScalar()));

                    connection.Pack("temp");

                    command.CommandText = "select count(*) from temp";

                    Assert.AreEqual(12, Convert.ToInt32(command.ExecuteScalar()));
                }

                connection.Close();
            }
        }
Esempio n. 3
0
        protected virtual void Dispose(bool disposing)
        {
            if (_disposed || !disposing)
            {
                return;
            }

            _connection.Close();
            _connection.Dispose();
            ((IDisposable)_dbcCreator).Dispose();

            try {
                if (!string.IsNullOrEmpty(_dbcCreator.DbcPath) && File.Exists(_dbcCreator.DbcPath))
                {
#if !DEBUG
                    Directory.Delete(Path.GetDirectoryName(_dbcCreator.DbcPath), true);
#endif
                }
            }
            catch (IOException ex) {
                VfpClientTracing.Tracer.TraceError(ex);
            }

            _disposed = true;
        }
Esempio n. 4
0
        private void DoConnected(Action action)
        {
            if (action == null)
            {
                return;
            }

            var closeConnection = false;

            if (_connection.State == ConnectionState.Closed)
            {
                _connection.Open();
                closeConnection = true;
            }

            try {
                action();
            }
            finally {
                if (closeConnection)
                {
                    _connection.Close();
                }
            }
        }
Esempio n. 5
0
        static void Main(string[] args)
        {
            // Get the Northwind OrderDetails data.
            var orderDetails = GetDataTable("OrderDetails");

            // Convert the DataTable to an XmlToCursor formatted xml string.
            // ToXmlToCursorFormattedXml is an DataTable extension method in the VfpClient namespace.
            var xml = orderDetails.ToXmlToCursorFormattedXml();

            using (var connection = new VfpConnection(ConfigurationManager.ConnectionStrings["FreeTables"].ConnectionString)) {
                connection.Open();

                // Create cursor using XmlToCursor with the DataTable xml.
                using (var command = connection.CreateCommand()) {
                    command.CommandType = CommandType.StoredProcedure;
                    command.CommandText = "XmlToCursor";
                    command.Parameters.Add(new VfpParameter("xml", xml));
                    command.Parameters.Add(new VfpParameter("cursor", "curXmlTemp"));
                    command.ExecuteNonQuery();
                }

                // Use the cursor to insert records into the destination table.
                using (var command = connection.CreateCommand()) {
                    command.CommandText = "INSERT INTO 'OrderDetailsArchive' SELECT * FROM curXmlTemp";
                    command.ExecuteNonQuery();
                }

                connection.Close();
            }
        }
Esempio n. 6
0
        private void OKButton_Click(object sender, RoutedEventArgs e)
        {
            try {
                using (var connection = new VfpConnection(txtDataPath.Text)) {
                    connection.Open();
                    connection.Close();
                }
            }
            catch (Exception) {
                MessageBox.Show("Invalid connection string.", Title, MessageBoxButton.OK, MessageBoxImage.Error);

                e.Handled = true;
            }

            if (e.Handled) {
                return;
            }

            _connectionInfo.DynamicSchemaOptions.NoPluralization = !Pluralization.IsChecked.Value;
            _connectionInfo.DynamicSchemaOptions.NoCapitalization = !Capitalize.IsChecked.Value;

            var singularizeElement = _connectionInfo.DriverData.Element("Singularize");

            if (singularizeElement == null) {
                _connectionInfo.DriverData.Add(new XElement("Singularize", Singularize.IsChecked.Value));
            }
            else {
                singularizeElement.Value = Singularize.IsChecked.Value.ToString();
            }

            DialogResult = true;
        }
Esempio n. 7
0
        public IEnumerable <string> GetTableNames()
        {
            using (var connection = new VfpConnection(ConfigurationManager.ConnectionStrings["Northwind"].ConnectionString)) {
                connection.Open();

                var tableNames = connection.GetSchema(VfpConnection.SchemaNames.Tables)
                                 .AsEnumerable()
                                 .Select(x => x.Field <string>(VfpConnection.SchemaColumnNames.Table.TableName))
                                 .OrderBy(x => x)
                                 .ToArray();

                connection.Close();

                return(tableNames);
            }
        }
Esempio n. 8
0
        private static void Main(string[] args)
        {
            using (var connection = new VfpConnection(ConfigurationManager.ConnectionStrings["Northwind"].ConnectionString)) {
                connection.Open();

                var tables = connection.GetSchema(VfpConnection.SchemaNames.Tables);
                var fields = connection.GetSchema(VfpConnection.SchemaNames.TableFields);

                connection.Close();

                var dbc        = GetNewDbcFullPath();
                var dbcCreator = new DataTableDbcCreator(dbc);

                dbcCreator.Add(tables);
                dbcCreator.Add(fields);
            }
        }
Esempio n. 9
0
        public void ZapTest()
        {
            var dbc = CreateTempDbc();

            using (var connection = new VfpConnection(dbc)) {
                connection.Open();

                using (var command = connection.CreateCommand()) {
                    command.CommandText = "select count(*) from temp";

                    Assert.AreNotEqual(0, Convert.ToInt32(command.ExecuteScalar()));

                    connection.Zap("temp");

                    Assert.AreEqual(0, Convert.ToInt32(command.ExecuteScalar()));
                }

                connection.Close();
            }
        }
Esempio n. 10
0
        protected virtual void Dispose(bool disposing)
        {
            if (_disposed)
            {
                return;
            }

            _disposed = true;

            if (!disposing || _connection == null)
            {
                return;
            }

            if (_connection.State == ConnectionState.Open)
            {
                _connection.Close();
            }

            _connection.Dispose();
        }