Example #1
0
        private void AddGridRow(Model.ScriptObject scriptObject)
        {
            if (!scriptObject.Enabled)
            {
                return;
            }

            bool aliasIsDifferent = !Slyce.Common.Utility.StringsAreEqual(scriptObject.Alias, scriptObject.Name, false);

            if (!IsFilteredOut(scriptObject.Alias) || (aliasIsDifferent && !IsFilteredOut(scriptObject.Name)))
            {
                string text;

                if (!aliasIsDifferent)
                {
                    text = scriptObject.Alias;
                }
                else
                {
                    text = string.Format("{0} [{1}]", scriptObject.Alias, scriptObject.Name);
                }
                int newIndex = gridListObjects.Rows.Add(new object[] { text });
                gridListObjects.Rows[newIndex].Tag = scriptObject;
            }
        }
Example #2
0
        private void btnFetchValuesFromOtherTable_Click(object sender, EventArgs e)
        {
            Cursor = Cursors.WaitCursor;

            try
            {
                if (ddlLookupIdColumns.SelectedItem == null)
                {
                    MessageBox.Show("Please select an ID column.", "Missing Data", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return;
                }
                Model.Column idColumn = (Model.Column)ddlLookupIdColumns.SelectedItem;

                string sql = string.Format("SELECT DISTINCT [{0}]", idColumn.Name);

                if (ddlLookupNameColumns.SelectedItem != null &&
                    ddlLookupNameColumns.SelectedItem is Model.Column)
                {
                    sql += string.Format(", [{0}]", ((Model.Column)ddlLookupNameColumns.SelectedItem).Name);
                }
                Model.ScriptObject table = (Model.ScriptObject)ddlLookupTables.SelectedItem;
                sql += string.Format(" FROM [{0}].[{1}] ORDER BY [{2}]", table.Schema, table.Name, idColumn.Name);
                System.Data.DataTable results = null;

                try
                {
                    Providers.Database.Helper.Utility.ResetAllConnections();
                    results = table.Database.RunQuerySQL(sql);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                System.Data.DataRow[] rows = results.Select();

                if (results.Rows.Count > 100)
                {
                    if (MessageBox.Show(string.Format("{0} rows were returned. Are you sure you want to import this many?", results.Rows.Count), "Many Results", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
                    {
                        return;
                    }
                }
                foreach (System.Data.DataRow row in rows)
                {
                    string id   = row[0].ToString();
                    string name = row.ItemArray.Length == 1 ? "" : row[1].ToString();

                    // Check if already exists
                    bool exists = false;

                    foreach (System.Windows.Forms.DataGridViewRow dataGridRow in dataGridViewX1.Rows)
                    {
                        if (dataGridRow.IsNewRow)
                        {
                            continue;
                        }
                        if (dataGridRow.Cells[(int)ColumnNames.Id].Value != null && Slyce.Common.Utility.StringsAreEqual(dataGridRow.Cells[(int)ColumnNames.Id].Value.ToString(), id, false))
                        {
                            if (!Slyce.Common.Utility.StringsAreEqual(dataGridRow.Cells[(int)ColumnNames.Name].Value.ToString(), name, false) &&
                                string.IsNullOrEmpty(dataGridRow.Cells[(int)ColumnNames.Name].Value.ToString()))
                            {
                                dataGridRow.Cells[(int)ColumnNames.Name].Value = name;
                                ((LookupValue)dataGridRow.Tag).Name            = name;
                            }
                            exists = true;
                            break;
                        }
                    }
                    if (exists)
                    {
                        continue;
                    }
                    LookupValue lookupValue = new LookupValue(name, false, Lookup);
                    lookupValue.Id   = id;
                    lookupValue.Name = name;
                    Lookup.LookupValues.Add(lookupValue);
                    AddLookupValueToGrid(lookupValue);
                }
                HighlightDuplicates();
            }
            finally
            {
                Cursor = Cursors.Default;
            }
        }