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

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

            base.BaseAdd(element, true);
        }
        /// <summary>
        ///     Returns a clone of the existing Config section
        /// </summary>
        /// <returns>Cloned object</returns>
        public object Clone()
        {
            var syncCol = new SyncColumnConfigElement
            {
                Name         = Name,
                IsNullable   = IsNullable,
                IsPrimaryKey = IsPrimaryKey,
                SqlType      = SqlType
            };

            if (!string.IsNullOrEmpty(GlobalName))
            {
                syncCol.GlobalName = GlobalName;
            }
            return(syncCol);
        }
Example #4
0
        /// <summary>
        /// Returns a clone of the existing Config section
        /// </summary>
        /// <returns>Cloned object</returns>
        public object Clone()
        {
            SyncColumnConfigElement syncCol = new SyncColumnConfigElement()
            {
                Name         = this.Name,
                IsNullable   = this.IsNullable,
                IsPrimaryKey = this.IsPrimaryKey,
                SqlType      = this.SqlType
            };

            if (!string.IsNullOrEmpty(this.GlobalName))
            {
                syncCol.GlobalName = this.GlobalName;
            }
            return(syncCol);
        }
        /// <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);
            }
        }
        /// <summary>
        /// Called whenever a checkbox from the list of columns (sync/filter) is checked or unchecked
        /// If Column index is 1 then its a sync column
        ///     If column is removed then remove from sync columns collection. Also disable the column if it was a filter column.
        ///         Disable the filter col checkbox so it cannot be added as a filter without adding it as a sync column first
        ///     If column is enabled then add it to sync columns collection. Enable filter col checkbox so it can be clicked
        /// If Column index is 2 then its a filter column.
        ///     If filter col is disabled then remove the column from filter params/clause/columns collection
        ///     If filter col is enabled then add the column to the filter params/clause/columns collection
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void colsView_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            SyncTableConfigElement table = selectedScope.SyncTables.GetElement(this.tablesBox.SelectedItem.ToString());

            if (e.ColumnIndex > 0)
            {
                // Check to see if its a column being added/removed from sync
                DataGridViewCheckBoxCell cell = this.colsView.Rows[e.RowIndex].Cells[e.ColumnIndex] as DataGridViewCheckBoxCell;
                DbSyncColumnDescription col = tableDesc.Columns[e.RowIndex];

                if (e.ColumnIndex == 1)
                {
                    if (cell.Value == null || !(bool)cell.Value)
                    {
                        // Sync column unchecked
                        SyncColumnConfigElement colConfig = table.SyncColumns.GetElement(this.colsView.Rows[e.RowIndex].Cells[0].Value.ToString());
                        if (colConfig != null)
                        {
                            table.SyncColumns.Remove(colConfig.Name);
                            this.RemoveFilterColumnInfo(table, colConfig);
                            this.colsView.Rows[e.RowIndex].Cells[2].Value = false;
                            // Make filter col readonly
                            this.colsView.Rows[e.RowIndex].Cells[2].ReadOnly = true;
                        }
                    }
                    else if (table.SyncColumns.GetElement(col.UnquotedName) == null)
                    {
                        // Sync column is checked. Add it back to the SyncColumn list
                        SyncColumnConfigElement colConfig = new SyncColumnConfigElement()
                        {
                            Name = col.UnquotedName,
                            IsPrimaryKey = false,
                            IsNullable = col.IsNullable,
                            SqlType = col.Type,
                        };
                        table.SyncColumns.Add(colConfig);
                        // Set the filter col to enabled.
                        this.colsView.Rows[e.RowIndex].Cells[2].ReadOnly = false;
                    }
                    table.IncludeAllColumns = table.SyncColumns.Count == colsView.Rows.Count;
                }
                else
                {
                    // Its a filter column
                    SyncColumnConfigElement colConfig = table.SyncColumns.GetElement(colsView.Rows[e.RowIndex].Cells[0].Value.ToString());
                    if (colConfig != null)
                    {
                        string filterParamName = "@" + WizardHelper.SanitizeName(colConfig.Name);
                        string andFilterClause = string.Format(AndFilterClauseFormat, colConfig.Name, filterParamName);
                        string FilterClause = string.Format(FilterClauseFormat, colConfig.Name, filterParamName);

                        if (cell.Value != null && !(bool)cell.Value)
                        {
                            // Filter column unchecked
                            this.RemoveFilterColumnInfo(table, colConfig);
                        }
                        else if(table.FilterColumns.GetElement(colConfig.Name) == null)
                        {
                            // Add Filter column
                            table.FilterColumns.Add(new FilterColumnConfigElement()
                            {
                                Name = colConfig.Name
                            });

                            // Add Filter parameter
                            table.FilterParameters.Add(new FilterParameterConfigElement()
                            {
                                Name = filterParamName,
                                SqlType = tableDesc.Columns[e.RowIndex].Type,
                            });

                            if ((tableDesc.Columns[e.RowIndex].SizeSpecified))
                            {
                                // Set size
                                table.FilterParameters.GetElementAt(table.FilterParameters.Count - 1).DataSize = int.Parse(tableDesc.Columns[e.RowIndex].Size);
                            }

                            if (string.IsNullOrEmpty(table.FilterClause))
                            {
                                table.FilterClause = string.Format(FilterClauseFormat, colConfig.Name, filterParamName);
                            }
                            else
                            {
                                table.FilterClause += string.Format(AndFilterClauseFormat, colConfig.Name, filterParamName);
                            }
                        }
                    }

                    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);
                }
            }
        }
        /// <summary>
        /// Returns a clone of the existing Config section
        /// </summary>
        /// <returns>Cloned object</returns>
        public object Clone()
        {
            SyncColumnConfigElement syncCol = new SyncColumnConfigElement()
            {
                Name = this.Name,
                IsNullable = this.IsNullable,
                IsPrimaryKey = this.IsPrimaryKey,
                SqlType = this.SqlType
            };

            if(!string.IsNullOrEmpty(this.GlobalName))
            {
                syncCol.GlobalName = this.GlobalName;
            }
            return syncCol;
        }