Exemplo n.º 1
0
        /// <summary>
        /// Allows programmatic addition to the Collection
        /// </summary>
        /// <param name="element">Element to add to collection</param>
        public void Add(SyncTableConfigElement element)
        {
            if (element == null)
            {
                throw new ArgumentNullException("element");
            }

            base.BaseAdd(element, true);
        }
        /// <summary>
        ///     Allows programmatic addition to the Collection at the specified index
        /// </summary>
        /// <param name="index">Index at which to add the element</param>
        /// <param name="element">Element to add to collection</param>
        public void Add(int index, SyncTableConfigElement element)
        {
            if (element == null)
            {
                throw new ArgumentNullException("element");
            }

            BaseAdd(index, element);
        }
        /// <summary>
        ///     Allows programmatic addition to the Collection
        /// </summary>
        /// <param name="element">Element to add to collection</param>
        public void Add(SyncTableConfigElement element)
        {
            if (element == null)
            {
                throw new ArgumentNullException("element");
            }

            BaseAdd(element, true);
        }
        /// <summary>
        ///     Returns a clone of the existing Config section
        /// </summary>
        /// <returns>Cloned object</returns>
        public object Clone()
        {
            var table = new SyncTableConfigElement
            {
                Name              = Name,
                FilterClause      = FilterClause,
                IncludeAllColumns = IncludeAllColumns
            };

            if (!string.IsNullOrEmpty((string)this["GlobalName"]))
            {
                table.GlobalName = (string)this["GlobalName"];
            }
            if (!string.IsNullOrEmpty(SchemaName))
            {
                table.GlobalName = SchemaName;
            }

            //Clone columns
            foreach (SyncColumnConfigElement column in SyncColumns)
            {
                table.SyncColumns.Add((SyncColumnConfigElement)column.Clone());
            }

            // Clone filter columns
            foreach (FilterColumnConfigElement column in FilterColumns)
            {
                table.FilterColumns.Add((FilterColumnConfigElement)column.Clone());
            }

            // Clone filter parameters
            foreach (FilterParameterConfigElement column in FilterParameters)
            {
                table.FilterParameters.Add((FilterParameterConfigElement)column.Clone());
            }

            return(table);
        }
        /// <summary>
        /// Returns a clone of the existing Config section
        /// </summary>
        /// <returns>Cloned object</returns>
        public object Clone()
        {
            SyncTableConfigElement table = new SyncTableConfigElement()
            {
                Name = this.Name,
                FilterClause = this.FilterClause,
                IncludeAllColumns = this.IncludeAllColumns,
            };

            if(!string.IsNullOrEmpty((string)this["GlobalName"]))
            {
                table.GlobalName = (string)this["GlobalName"];
            }
            if (!string.IsNullOrEmpty(this.SchemaName))
            {
                table.GlobalName = this.SchemaName;
            }

            //Clone columns
            foreach (SyncColumnConfigElement column in SyncColumns)
            {
                table.SyncColumns.Add((SyncColumnConfigElement)column.Clone());
            }

            // Clone filter columns
            foreach (FilterColumnConfigElement column in FilterColumns)
            {
                table.FilterColumns.Add((FilterColumnConfigElement)column.Clone());
            }

            // Clone filter parameters
            foreach (FilterParameterConfigElement column in FilterParameters)
            {
                table.FilterParameters.Add((FilterParameterConfigElement)column.Clone());
            }

            return table;
        }
        /// <summary>
        /// Called whenever a FilterColumn is unchecked from the UI. Removed the particular filter from the uber filter clause.
        /// Does the following
        /// 1. Remove from FilterColumns
        /// 2. Remove from FilterParameters
        /// 3. Remove text from FilterClause
        /// </summary>
        /// <param name="table">Table for which the filter param applies to</param>
        /// <param name="colConfig">The actual column being unchecked</param>
        private void RemoveFilterColumnInfo(SyncTableConfigElement table, SyncColumnConfigElement colConfig)
        {
            string filterParamName = "@" + WizardHelper.SanitizeName(colConfig.Name);
            string andFilterClause = string.Format(AndFilterClauseFormat, colConfig.Name, filterParamName);
            string FilterClause = string.Format(FilterClauseFormat, colConfig.Name, filterParamName);

            // Remove from Filter columns
            table.FilterColumns.Remove(colConfig.Name);


            //Remove from Filter parameters
            table.FilterParameters.Remove(filterParamName);

            // Check to see if you can remove the filter clause

            table.FilterClause = table.FilterClause.Replace(andFilterClause, string.Empty);
            table.FilterClause = table.FilterClause.Replace(FilterClause, string.Empty);

            if (table.FilterClause.StartsWith(" AND "))
            {
                table.FilterClause = table.FilterClause.Substring(5);
            }
        }
        private void DisplaySyncTableDetails(SyncTableConfigElement table)
        {
            foreach (DbSyncColumnDescription colDesc in tableDesc.Columns)
            {
                SyncColumnConfigElement colConfig = table.SyncColumns.GetElement(colDesc.UnquotedName);
                if (colConfig == null)
                {
                    colsView.Rows.Add(colDesc.UnquotedName, false, false);
                }
                else
                {
                    colsView.Rows.Add(colConfig.Name, true, // IsSync
                        table.FilterColumns.GetElement(colConfig.Name) != null); // IsFilterCol
                }

                DataGridViewRow row = colsView.Rows[colsView.Rows.Count - 1];
                if (colConfig != null && colConfig.IsPrimaryKey)
                {
                    // Freeze the row if its a primary key
                    row.ReadOnly = true;
                }

                row.Cells[2].ReadOnly = colConfig == null;
            }
            this.filterClauseTxtBox.Text = table.FilterClause;
        }
        private void tablesBox_ItemCheck(object sender, ItemCheckEventArgs e)
        {
            if (tablesBox.SelectedIndex > -1)
            {
                this.colsView.Rows.Clear();
                string tableName = this.tablesBox.SelectedItem.ToString();

                if (e.NewValue == CheckState.Unchecked)
                {
                    // Remove it from the SyncTables collection
                    selectedScope.SyncTables.Remove(tableName);

                    this.filterClauseTxtBox.Text = string.Empty;
                }
                else if (e.NewValue == CheckState.Checked)
                {
                    SyncTableConfigElement table = new SyncTableConfigElement();
                    table.Name = tableName;
                    table.IncludeAllColumns = true;

                    TargetDatabaseConfigElement db = WizardHelper.Instance.SyncConfigSection.Databases.GetElementAt(this.dbsComboBox.SelectedIndex);
                    statusLbl.Visible = true;

                    try
                    {
                        tableDesc = SqlSyncDescriptionBuilder.GetDescriptionForTable(tableName, new SqlConnection(db.GetConnectionString()));

                        // Issue a query to get list of all tables
                        foreach (DbSyncColumnDescription col in tableDesc.Columns)
                        {
                            SyncColumnConfigElement colConfig = new SyncColumnConfigElement()
                            {
                                Name = col.UnquotedName,
                                IsPrimaryKey = col.IsPrimaryKey,
                                IsNullable = col.IsNullable,
                                SqlType = col.Type,
                            };
                            table.SyncColumns.Add(colConfig);
                        }
                        this.DisplaySyncTableDetails(table);
                    }
                    catch (SqlException exp)
                    {
                        MessageBox.Show("Error in querying database. " + exp.Message, "Target Database Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    finally
                    {
                        statusLbl.Visible = false;
                    }
                    // Add it to the sync table list
                    selectedScope.SyncTables.Add(table);
                }
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// Allows programmatic addition to the Collection at the specified index
        /// </summary>
        /// <param name="index">Index at which to add the element</param>
        /// <param name="element">Element to add to collection</param>
        public void Add(int index, SyncTableConfigElement element)
        {
            if (element == null)
            {
                throw new ArgumentNullException("element");
            }

            base.BaseAdd(index, element);
        }