public new void Load(XmlElement xml) { m_loading = true; this.LoadPropertiesCore(xml); foreach (XmlElement xtbl in xml.SelectNodes("Table")) { var tbl = new QueryDesignTableFrame(xtbl, this); m_tables.Add(tbl); panel1.Controls.Add(tbl); } foreach (XmlElement xjoin in xml.SelectNodes("Join")) { var join = new QueryDesignJoinControl(xjoin, this); m_joins.Add(join); panel1.Controls.Add(join); } foreach (XmlElement xcol in xml.SelectNodes("Column")) { int newrow = dataGridColumns.Rows.Add(); var col = new DesignedColumn(this, dataGridColumns.Rows[newrow], xcol); col.Table.m_table.CheckColumn(col.ColumnName); } foreach (XmlElement xord in xml.SelectNodes("OrderBy")) { var ord = new DesignedOrder(xord, this); lbxSortedColumns.Items.Add(ord); } var cx = xml.FindElement("Filter"); if (cx != null) { m_condDesign.LoadFromXml(cx); } m_loading = false; ReloadAll(); Redraw(); }
private void RemoveInvalidSortColumns() { var remove = new List <DesignedOrder>(); foreach (DesignedOrder o in lbxSortedColumns.Items) { var crow = FindColumn(o.m_column.Table.m_table, o.m_column.ColumnName); if (crow == null) { remove.Add(o); continue; } var col = new DesignedColumn(this, crow); if (!col.Output) { remove.Add(o); continue; } } foreach (var o in remove) { lbxSortedColumns.Items.Remove(o); } }
public string GenerateSql() { if (m_queryFrame == null) { return(""); } var dialect = m_queryFrame.Connection.GetAnyDialect(); var sw = new StringWriter(); var dmp = dialect.CreateDumper(sw); dmp.Put("^select"); if (IsUniqueRows) { dmp.Put(" ^distinct"); } //StringBuilder sb = new StringBuilder(); //sb.Append("SELECT"); //if (IsUniqueRows) sb.Append(" DISTINCT"); bool wascol = false; var groupBy = new List <DesignedColumn>(); dmp.Put("&>"); foreach (DesignedColumn col in Columns) { if (col.GroupBy) { groupBy.Add(col); } if (!col.Output) { continue; } if (wascol) { dmp.Put(",&n"); } else { dmp.Put("&n"); } if (col.Aggregate != null) { dmp.Put(col.Aggregate + "("); } col.WriteExpression(dmp); if (col.Aggregate != null) { dmp.Put(")"); } if (col.Alias != "") { dmp.Put(" ^as %s", col.Alias); } wascol = true; } dmp.Put("&<"); RenderFrom(dmp); if (m_condDesign != null) { m_condDesign.RenderSql(dmp); } if (groupBy.Count > 0) { bool wasg = false; dmp.Put("&n^group ^by"); foreach (DesignedColumn col in groupBy) { if (wasg) { dmp.Put(", "); } col.WriteExpression(dmp); wasg = true; } } if (lbxSortedColumns.Items.Count > 0) { dmp.Put("&n^order ^by "); bool waso = false; foreach (DesignedOrder o in lbxSortedColumns.Items) { if (waso) { dmp.Put(", "); } var col = new DesignedColumn(this, FindColumn(o.m_column.Table.m_table, o.m_column.ColumnName)); if (col.Aggregate != null) { dmp.Put(col.Aggregate + "("); } o.m_column.WriteExpression(dmp); if (col.Aggregate != null) { dmp.Put(")"); } if (o.Desc) { dmp.Put(" ^desc"); } waso = true; } } return(sw.ToString()); }