예제 #1
0
        void UpdateColumnLists()
        {
            if (!loaded)
            {
                return;
            }

            bool showAllColumns = workingColumns.Count == 0 || S.Get("NewQueryShowAllColumns", false);

            columns.Clear();
            foreach (int i in tablesList.SelectedIndices)
            {
                ListDbTable table = tablesList.Items[i] as ListDbTable;
                foreach (DbColumn column in table.dbTable.columns.Values)
                {
                    if (showAllColumns == false && !workingColumns.Contains(column))
                    {
                        continue;
                    }
                    columns.Add(new ListDbColumn(table.dbTable, column));
                }
            }
            foreach (ListBox list in columnListBoxes.Values)
            {
                list.SetDataSource(columns, "DisplayMember", "ValueMember");
            }
        }
예제 #2
0
        void UpdateEditor()
        {
            if (!loaded)
            {
                return;
            }

            if (!listsLoaded)
            {
                return;
            }

            if (innerJoin.Visible)
            {
                S.Set("NewQueryInnerJoin", innerJoin.Checked);
            }

            string        from   = "";
            List <string> tables = new List <string>();

            foreach (int i in tablesList.SelectedIndices)
            {
                ListDbTable item = tablesList.Items[i] as ListDbTable;
                if (innerJoin.Visible == false || innerJoin.Checked == false)
                {
                    from = from.AppendTo(item.DisplayMember, ", ");
                }
                else
                {
                    tables.Add(item.dbTable.name);
                }
            }

            if (tables.Count > 0)
            {
                from = A.db.MakeFrom(tables, includeAliases.Checked);
            }

            string sql = "";

            if (from != "")
            {
                if (queryType == "Select")
                {
                    sql += GetSelectedColumns("Select", ", ", "*");
                    sql += "from " + from + " ";
                    sql += GetSelectedColumns("Where", " and ", "", GetSelectedColumnsMode.Equals);
                    sql += GetSelectedColumns("Group by", ", ");
                    sql += GetSelectedColumns("Order by", ", ");
                }
                else if (queryType == "Insert")
                {
                    sql = "insert ";
                    if (S.Get("NewQueryInsertIgnore", false))
                    {
                        sql += "ignore ";
                    }
                    sql += "into " + from + " ";
                    sql += GetSelectedColumns("columns", ", ", "", GetSelectedColumnsMode.Insert);
                }
                else if (queryType == "Update")
                {
                    sql += GetSelectedColumns("columns", ", ", "", GetSelectedColumnsMode.Equals);
                    if (sql.Trim() != "")
                    {
                        sql  = "update " + from + " set " + sql;
                        sql += GetSelectedColumns("Where", " and ", "", GetSelectedColumnsMode.Equals);
                    }
                }
                else if (queryType == "Delete")
                {
                    sql  = "delete from " + from + " ";
                    sql += GetSelectedColumns("Where", " and ", "", GetSelectedColumnsMode.Equals);
                }
            }

            sqlEditor.Text = sql;
            bOK.Enabled    = sql != "";
        }