public object Clone()
        {
            TableAliasList obj = new TableAliasList();
            int            n   = this.Count;

            for (int i = 0; i < n; i++)
            {
                obj.AddTable((TableAlias)tables[i].Clone());
            }
            return(obj);
        }
        private void btQueryBuilder_Click(object sender, System.EventArgs e)
        {
            acceptByMouse();
            EasyQuery qry = objRet.SourceQuery;

            if (qry == null)
            {
                qry = new EasyQuery();
                qry.DatabaseConnection = dbConn;
                if (_tables == null)
                {
                    _tables = new TableAliasList();
                    for (int i = 0; i < lstTable.Items.Count; i++)
                    {
                        TableAlias t = new TableAlias((string)(lstTable.Items[i]), string.Empty);
                        _tables.AddTable(t);
                    }
                }
                qry.T = _tables;
                FieldList lst = objRet.GetFields();
                if (lst != null)
                {
                    FieldList fl = (FieldList)lst.Clone();
                    for (int i = 0; i < fl.Count; i++)
                    {
                        fl[i].FieldText = fl[i].Name;
                        if (lst[i].FromTableName != null)
                        {
                            if (lst[i].FromTableName.Length > 0)
                            {
                                if (!qry.T.IsTableIncluded(lst[i].FromTableName))
                                {
                                    TableAlias t = new TableAlias(lst[i].FromTableName, "");
                                    t.srcType = enumRecSource.Table;
                                    qry.T.AddTable(t);
                                }
                            }
                        }
                    }
                    qry.Fields = fl;
                }
                string sl = objRet.Filter;
                if (sl == null)
                {
                    sl = "";
                }
                if (sl.Length > 0)
                {
                    if (sl.StartsWith("FROM ", StringComparison.OrdinalIgnoreCase))
                    {
                        sl       = sl.Substring(5);
                        sl       = sl.Trim();
                        qry.From = sl;
                    }
                    else
                    {
                        qry.From = objRet.TableName;
                        if (sl.StartsWith("WHERE ", StringComparison.OrdinalIgnoreCase))
                        {
                            sl = sl.Substring(6);
                            sl = sl.Trim();
                        }
                        qry.Where = sl;
                    }
                }
                else
                {
                    qry.From = objRet.TableName;
                }
            }
            qry.DatabaseConnection = dbConn;
            QueryParser qp = new QueryParser();

            if (qp.BuildQuery(qry, this))
            {
                string filter = "";
                bool   bOK    = false;
                objRet.SourceQuery = qp.query;
                qry = qp.query;
                if (!qry.Fields.FromSingleTable() || objRet.CommandType == enmNonQueryType.Delete)
                {
                    filter = qry.From;
                    if (filter.Length > 0)
                    {
                        filter = string.Format(CultureInfo.InvariantCulture, "{0}{1}", QueryParser.SQL_From(), filter);
                    }
                }
                if (qry.Where.Length > 0)
                {
                    filter = string.Format(CultureInfo.InvariantCulture, "{0}{1}{2}", filter, QueryParser.SQL_Where(), qry.Where);
                }
                if (objRet.CommandType == enmNonQueryType.Delete)
                {
                    if (qry.From.IndexOf(objRet.TableName, StringComparison.OrdinalIgnoreCase) < 0)
                    {
                        MessageBox.Show(this, string.Format(System.Globalization.CultureInfo.InvariantCulture, "Table [{0}] not found in [{1}]", objRet.TableName, qry.From), this.Text, System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Exclamation);
                    }
                    else
                    {
                        objRet.MultiRow = true;
                        txtWhere.Text   = filter;
                        objRet.SetFilter(filter);
                        bOK = true;
                    }
                }
                else
                {
                    filter        = adjustFilter(filter);
                    txtWhere.Text = filter;
                    objRet.SetFilter(filter);
                    objRet.ResetSQL();
                    bOK = true;
                }
                if (bOK)
                {
                    showSQL();
                }
            }
        }