public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            string name = string.Empty;
            MsSqlTableDataRepositoryItem   item            = value as MsSqlTableDataRepositoryItem;
            PostgreTableDataRepositoryItem postgreItem     = value as PostgreTableDataRepositoryItem;
            PostgreViewDataRepositoryItem  postgreViewItem = value as PostgreViewDataRepositoryItem;

            if (item != null)
            {
                string database = item.DatabaseName;
                name = string.Format(CultureInfo.InvariantCulture, "{0}: {1}.{2}", database, item.SchemaName, item.Name);
            }
            else if (postgreItem != null)
            {
                string database = postgreItem.DatabaseName;
                string schema   = postgreItem.SchemaName;
                name = string.Format(CultureInfo.InvariantCulture, "{0}: {1}.{2}", database, schema, postgreItem.Name);
            }
            else if (postgreViewItem != null)
            {
                string database = postgreItem.DatabaseName;
                string schema   = postgreItem.SchemaName;
                name = string.Format(CultureInfo.InvariantCulture, "{0}: {1}.{2}", database, schema, postgreItem.Name);
            }

            return(name);
        }
Ejemplo n.º 2
0
        private string GetToDatabaseConnectionString(MsSqlTableDataRepositoryItem msSqlTableDataRepositoryItem)
        {
            StringBuilder connectionBuilder = new StringBuilder();

            connectionBuilder.AppendFormat(CultureInfo.InvariantCulture, "{0}Initial Catalog={1};", GetToServerConnectionString(msSqlTableDataRepositoryItem), msSqlTableDataRepositoryItem.DatabaseName);
            return(connectionBuilder.ToString());
        }
Ejemplo n.º 3
0
        private static void AddChildrens(DataRepositoryItem dbItem, List <string> itemNames, string iconUri, string name, MsSql2008FeatureLayerInfo layerInfo, string databaseName)
        {
            if (itemNames.Count == 0)
            {
                return;
            }

            DataRepositoryItem tablesItem = new DataRepositoryItem();

            tablesItem.Name = String.Format(CultureInfo.InvariantCulture, "{0} ({1})", name, itemNames.Count);
            tablesItem.Icon = new BitmapImage(new Uri(iconUri, UriKind.RelativeOrAbsolute));
            dbItem.Children.Add(tablesItem);

            foreach (var itemName in itemNames)
            {
                MsSqlTableDataRepositoryItem tableItem = new MsSqlTableDataRepositoryItem();
                tableItem.LayerInfo    = layerInfo;
                tableItem.TableName    = itemName;
                tableItem.SchemaName   = dbItem.Name;
                tableItem.DatabaseName = databaseName;
                tableItem.Name         = itemName;

                int index = itemName.IndexOf(".", StringComparison.Ordinal);
                if (index != -1)
                {
                    tableItem.Name      = itemName.Substring(index + 1);
                    tableItem.TableName = tableItem.Name;
                }

                tablesItem.Children.Add(tableItem);
            }
        }
Ejemplo n.º 4
0
        private SqlCommand GetSqlCommand(string sqlStatement, MsSqlTableDataRepositoryItem msSqlTableDataRepositoryItem)
        {
            SqlConnection connection = new SqlConnection(GetToDatabaseConnectionString(msSqlTableDataRepositoryItem));

            connection.Open();
            SqlCommand command = new SqlCommand(sqlStatement, connection);

            command.CommandTimeout = 60;

            return(command);
        }
Ejemplo n.º 5
0
        private string GetFullTableName(MsSqlTableDataRepositoryItem msSqlTableDataRepositoryItem)
        {
            string tempTableName = msSqlTableDataRepositoryItem.TableName;

            if (!string.IsNullOrEmpty(msSqlTableDataRepositoryItem.SchemaName))
            {
                tempTableName = string.Format(CultureInfo.InvariantCulture, "[{0}].[{1}]", msSqlTableDataRepositoryItem.SchemaName, msSqlTableDataRepositoryItem.TableName);
            }

            return(tempTableName);
        }
Ejemplo n.º 6
0
        private void TreeViewItem_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            MsSqlTableDataRepositoryItem currentItem = sender.GetDataContext <MsSqlTableDataRepositoryItem>();

            if (currentItem != null && currentItem.IsLeaf)
            {
                DataRepositoryItem databaseItem = currentItem.Parent.Parent.Parent.Parent as DataRepositoryItem;
                DatabaseLayerInfoViewModel <MsSqlFeatureLayer> viewModel = DataContext as DatabaseLayerInfoViewModel <MsSqlFeatureLayer>;
                viewModel.Model.DatabaseName = databaseItem.Name;
                viewModel.CurrentItem        = currentItem;
                DropdownButton.IsChecked     = false;
            }
        }
Ejemplo n.º 7
0
        private string GetToServerConnectionString(MsSqlTableDataRepositoryItem msSqlTableDataRepositoryItem)
        {
            DataRepositoryItem item = msSqlTableDataRepositoryItem.Parent;

            while (!(item is MsSqlServerDataRepositoryItem))
            {
                item = item.Parent;
            }

            MsSqlServerDataRepositoryItem serverItem = (MsSqlServerDataRepositoryItem)item;
            StringBuilder connectionBuilder          = new StringBuilder();

            connectionBuilder.AppendFormat(CultureInfo.InvariantCulture, "Data Source={0};Persist Security Info=True;", serverItem.Server);
            if (string.IsNullOrEmpty(serverItem.UserName) && string.IsNullOrEmpty(serverItem.Password))
            {
                connectionBuilder.Append("Trusted_Connection=Yes;");
            }
            else
            {
                connectionBuilder.AppendFormat(CultureInfo.InvariantCulture, "User ID={0};Password={1};", serverItem.UserName, serverItem.Password);
            }

            return(connectionBuilder.ToString());
        }
Ejemplo n.º 8
0
        private UserControl GetDataRepositoryContentUserControl()
        {
            DataRepositoryContentUserControl userControl = new DataRepositoryContentUserControl();

            string header1 = "Record Count";
            DataRepositoryGridColumn column1 = new DataRepositoryGridColumn(header1, 100, di =>
            {
                MsSqlTableDataRepositoryItem msSqlTableDataRepositoryItem = di as MsSqlTableDataRepositoryItem;
                if (msSqlTableDataRepositoryItem == null)
                {
                    return(string.Empty);
                }

                TextBlock textBlock = new TextBlock();
                if (recordCountCache.ContainsKey(msSqlTableDataRepositoryItem.Id))
                {
                    textBlock.Text = recordCountCache[msSqlTableDataRepositoryItem.Id];
                }
                else
                {
                    textBlock.Text = "Loading...";

                    Task task = Task.Factory.StartNew(() =>
                    {
                        string tempTableName = GetFullTableName(msSqlTableDataRepositoryItem);
                        string sqlStatement  = "SELECT COUNT(*) FROM " + tempTableName;

                        SqlCommand command       = null;
                        SqlDataReader dataReader = null;

                        try
                        {
                            command = GetSqlCommand(sqlStatement, msSqlTableDataRepositoryItem);

                            dataReader = command.ExecuteReader();

                            string text = "";
                            if (dataReader.Read())
                            {
                                text = Convert.ToInt32(dataReader[0], CultureInfo.InvariantCulture).ToString();
                                recordCountCache[msSqlTableDataRepositoryItem.Id] = text;
                            }
                            Application.Current.Dispatcher.BeginInvoke(() =>
                            {
                                textBlock.Text = text;
                            });
                        }
                        catch (Exception ex)
                        {
                            Application.Current.Dispatcher.BeginInvoke(() =>
                            {
                                textBlock.Text = "Timeout";
                            });
                        }
                        finally
                        {
                            if (dataReader != null)
                            {
                                dataReader.Dispose();
                            }
                            if (command != null)
                            {
                                command.Connection.Close();
                                command.Dispose();
                            }
                        }
                    });
                }

                return(textBlock);
            });

            userControl.Columns.Add(column1);
            return(userControl);
        }