//zahed public SelectQueryBuilder LoadSelectQueryBuilderNew(ResultViewControl rc) //made public zahed { SelectQueryBuilder query = new SelectQueryBuilder(); bool isSelecteTabColumnsOrGroupbyColumns = false; if (rc.SelectTabCntrl.lstSelectedCol.ItemsSource != null) { //****Geting select columns***** ObservableCollection<SQLBuilder.Clauses.Column> ListOfSelectColumn = ((ObservableCollection<SQLBuilder.Clauses.Column>)rc.SelectTabCntrl.lstSelectedCol.ItemsSource); query.SelectedColumns = ListOfSelectColumn.ToList(); //foreach (SQLBuilder.Clauses.Column Col in ListOfSelectColumn) //{ // SQLBuilder.Clauses.Column column = new SQLBuilder.Clauses.Column(); // column.Name = Col.Name; // column.AliasName = Col.AliasName; // column.Format = Col.Format; // query.SelectColumn(column); //} isSelecteTabColumnsOrGroupbyColumns = true; } if (rc.TabulationTabCntrl.isTabulation) { //group by column for (int i = 0; i < rc.TabulationTabCntrl.StackPanelTabuLationTabGroupBy.Children.Count; i++) { TabulationTabStackPanelGroupByControl tg = (TabulationTabStackPanelGroupByControl)rc.TabulationTabCntrl.StackPanelTabuLationTabGroupBy.Children[i]; if (tg.cmbTabulationTabGroupByColumnsName.SelectedIndex != -1) { SQLBuilder.Clauses.Column column = new SQLBuilder.Clauses.Column(); column.Name = tg.cmbTabulationTabGroupByColumnsName.Text; column.Format = tg.txtTabulationTabGroupByColFormat.Text; column.AliasName = tg.txtTabulationTabGroupByAlias.Text; query.AddGroupBy(column); if (tg.cmbTabulationSort.SelectedIndex != -1) { query.AddOrderBy(tg.cmbTabulationTabGroupByColumnsName.Text, GetSortingEnum(tg.cmbTabulationSort.Text)); } } } //summarize column for (int i = 0; i < rc.TabulationTabCntrl.StackPanelTabuLationTabSummary.Children.Count; i++) { TabulationTabStackPanelSummaryControl ts = (TabulationTabStackPanelSummaryControl)rc.TabulationTabCntrl.StackPanelTabuLationTabSummary.Children[i]; if (ts.cmbTabulationTabSummaryColumnsName.SelectedIndex != -1) { SQLBuilder.Clauses.Column column = new SQLBuilder.Clauses.Column(); column.Name = ts.cmbTabulationTypeOfSummary.Text + "(" + ts.cmbTabulationTabSummaryColumnsName.Text + ")"; column.Format = ts.txtTabulationTabSummaryColFormat.Text; column.AliasName = ts.txtTabulationTabSummaryAlias.Text; query.AddSummarize(column); } } isSelecteTabColumnsOrGroupbyColumns = true; } else if (rc.CrossTabulationTabCntrl.isCrossTabulation) { //group by column for (int i = 0; i < rc.CrossTabulationTabCntrl.StackPanelCrossTabuLationTabGroupBy.Children.Count; i++) { CrossTabulationTabStackPanelGroupByControl ctg = (CrossTabulationTabStackPanelGroupByControl)rc.CrossTabulationTabCntrl.StackPanelCrossTabuLationTabGroupBy.Children[i]; if (ctg.cmbCrossTabulationTabGroupByColumnsName.SelectedIndex != -1) { SQLBuilder.Clauses.Column column = new SQLBuilder.Clauses.Column(); //modified on 11/18/11 //column.Name = ctg.cmbCrossTabulationTabGroupByColumnsName.Text; column.Name = ctg.cmbCrossTabulationTabGroupByColumnsName.Text;//((SQLBuilder.Clauses.Column)ctg.cmbCrossTabulationTabGroupByColumnsName.SelectionBoxItem).Name; column.Format = ctg.txtCrossTabulationTabGroupByColFormat.Text; //((SQLBuilder.Clauses.Column)ctg.cmbCrossTabulationTabGroupByColumnsName.SelectionBoxItem).Format; column.AliasName = ctg.txtCrossTabulationTabGroupByAlias.Text; //query.SelectColumn(column); query.AddGroupBy(column); if (ctg.cmbCrossTabulationSort.SelectedIndex != -1) { // SQLBuilder.Clauses.OrderByClause orderBy = new SQLBuilder.Clauses.OrderByClause(tg.cmbTabulationTabGroupByColumnsName.Text,GetSortingEnum(tg.cmbTabulationSort.Text)); // modified on 11/18/11 query.AddOrderBy(ctg.cmbCrossTabulationTabGroupByColumnsName.Text, GetSortingEnum(ctg.cmbCrossTabulationSort.Text)); //query.AddOrderBy(((SQLBuilder.Clauses.Column)ctg.cmbCrossTabulationTabGroupByColumnsName.SelectionBoxItem).Name, GetSortingEnum(ctg.cmbCrossTabulationSort.Text)); } } } //summarize column for (int i = 0; i < rc.CrossTabulationTabCntrl.StackPanelCrossTabuLationTabSummary.Children.Count; i++) { CrossTabulationTabStackPanelSummaryControl ts = (CrossTabulationTabStackPanelSummaryControl)rc.CrossTabulationTabCntrl.StackPanelCrossTabuLationTabSummary.Children[i]; if (ts.cmbCrossTabulationTabSummaryColumnsName.SelectedIndex != -1) { SQLBuilder.Clauses.Column column = new SQLBuilder.Clauses.Column(); //modified on 11/18/11 column.Name = ts.cmbCrossTabulationTypeOfSummary.Text + "(" + ts.cmbCrossTabulationTabSummaryColumnsName.Text + ")"; column.Format = ts.txtCrossTabulationTabSummaryColFormat.Text; //column.Name = ts.cmbCrossTabulationTypeOfSummary.Text + "(" + ((SQLBuilder.Clauses.Column)ts.cmbCrossTabulationTabSummaryColumnsName.SelectionBoxItem).Name + ")"; //column.Format = ((SQLBuilder.Clauses.Column)ts.cmbCrossTabulationTabSummaryColumnsName.SelectionBoxItem).Format; column.AliasName = ts.txtCrossTabulationTabSummaryAlias.Text; //query.SelectColumn(column); query.AddSummarize(column); } } //summary first row SQLBuilder.Clauses.Column column1 = new SQLBuilder.Clauses.Column(); //modified on 11/18/11 column1.Name = rc.CrossTabulationTabCntrl.cmbCrossTabulationTabSummaryFirstRowColumnsName.Text; //column1.Name = ((SQLBuilder.Clauses.Column)this.CrossTabulationTabUC.cmbCrossTabulationTabSummaryFirstRowColumnsName.SelectionBoxItem).Name; if (rc.CrossTabulationTabCntrl.cmbCrossTabulationTabSummaryFristRowSort.SelectedIndex == -1) { query.CrossTabClause = new SQLBuilder.Clauses.CrossTabulationClause(column1); isSelecteTabColumnsOrGroupbyColumns = true; } else { query.CrossTabClause = new SQLBuilder.Clauses.CrossTabulationClause(column1, GetSortingEnum(rc.CrossTabulationTabCntrl.cmbCrossTabulationTabSummaryFristRowSort.Text)); isSelecteTabColumnsOrGroupbyColumns = true; } } if (isSelecteTabColumnsOrGroupbyColumns) { //Geting from table SQLBuilder.Clauses.Table fromTable = null; MySQLData.Table table = this.listOfTable[rc.FromTabCntrl.cmbFromTable.SelectedIndex]; if (table is MySQLData.DerivedTable) { fromTable = new SQLBuilder.Clauses.DerivedTable((MySQLData.DerivedTable)table, rc.FromTabCntrl.txtFromAlias.Text); } else if (table is MySQLData.Table) { fromTable = new SQLBuilder.Clauses.Table(table, rc.FromTabCntrl.txtFromAlias.Text); } //fromTable.Name = rc.FromTabCntrl.cmbFromTable.Text; //fromTable.AliasName = rc.FromTabCntrl.txtFromAlias.Text; query.SelectFromTable(fromTable); //Geting join table and join colums for (int i = 0; i < rc.FromTabCntrl.StackPanelFromTab.Children.Count; i++) { FromTabStackPanelControl fs = (FromTabStackPanelControl)rc.FromTabCntrl.StackPanelFromTab.Children[i]; SQLBuilder.Clauses.Table joinTable = null; MySQLData.Table jTable = null; if (fs.cmbFromTabJoinTable.SelectedIndex != -1) { jTable = this.listOfTable[fs.cmbFromTabJoinTable.SelectedIndex]; if (jTable is MySQLData.DerivedTable) { joinTable = new SQLBuilder.Clauses.DerivedTable((MySQLData.DerivedTable)jTable, fs.txtJoinTableAlias.Text); } else if (jTable is MySQLData.Table) { joinTable = new SQLBuilder.Clauses.Table(jTable, fs.txtJoinTableAlias.Text); } //joinTable.Name = fs.cmbFromTabJoinTable.Text; //joinTable.AliasName = fs.txtJoinTableAlias.Text; SQLBuilder.Clauses.JoinClause joinClause = query.AddJoin(GetJoinType(fs.cmbFromTabJoinType.Text), fromTable, fs.cmbFromTabFromColumns.Text, GetComparisonOpreator(fs.cmbFromTabQueryOpretor.Text), joinTable, fs.cmbFromTabJoinColumns.Text); for (int condIndex = 0; condIndex < fs.StackPanelFromTabMore.Children.Count; condIndex++) { FromTabStackPanelControlMore fsCondition = (FromTabStackPanelControlMore)fs.StackPanelFromTabMore.Children[condIndex]; joinClause.addJoinCondition(GetLogicalOpreator(fsCondition.cmbFromTabFromANDOR.Text), fromTable, fsCondition.cmbFromTabFromColumns.Text, GetComparisonOpreator(fsCondition.cmbFromTabQueryOpretor.Text), joinTable, fsCondition.cmbFromTabJoinColumns.Text); } } } //******Geting Wheree Clause******** for (int i = 0; i < rc.WhereTabCntrl.StackPanelWhereTab.Children.Count; i++) { string controlType = rc.WhereTabCntrl.StackPanelWhereTab.Children[i].GetType().ToString(); switch (controlType) { case "FastDB.Control.WhereTabRegularConditionControl": WhereTabRegularConditionControl ws = (WhereTabRegularConditionControl)rc.WhereTabCntrl.StackPanelWhereTab.Children[i]; if (i == 0) { query.AddWhere(SQLBuilder.Enums.LogicOperator.None, ws.cmbWhereTabLeftSideColumns.Text, GetComparisonOpreator(ws.cmbWhereTabQueryOpretor.Text), ws.cmbWhereTabRightSideColumns.Text, Convert.ToInt32(ws.cmbWhereTabQueryLevel.Text)); } else { query.AddWhere(GetLogicalOpreator(ws.cmbWhereTabQueryAndOr.Text), ws.cmbWhereTabLeftSideColumns.Text, GetComparisonOpreator(ws.cmbWhereTabQueryOpretor.Text), ws.cmbWhereTabRightSideColumns.Text, Convert.ToInt32(ws.cmbWhereTabQueryLevel.Text)); } break; case "FastDB.Control.WhereTabBetweenConditionControl": WhereTabBetweenConditionControl wsb = (WhereTabBetweenConditionControl)rc.WhereTabCntrl.StackPanelWhereTab.Children[i]; if (i == 0) { query.AddWhere(SQLBuilder.Enums.LogicOperator.None, wsb.cmbWhereTabBetweenColumns.Text, wsb.txtBetweenLeftValue.Text, wsb.txtBetweenRightValue.Text, Convert.ToInt32(wsb.cmbWhereTabQueryLevel.Text)); } else { query.AddWhere(GetLogicalOpreator(wsb.cmbWhereTabQueryAndOr.Text), wsb.cmbWhereTabBetweenColumns.Text, wsb.txtBetweenLeftValue.Text, wsb.txtBetweenRightValue.Text, Convert.ToInt32(wsb.cmbWhereTabQueryLevel.Text)); } break; case "FastDB.Control.WhereTabInNotInConditionControl": WhereTabInNotInConditionControl wInNotIn = (WhereTabInNotInConditionControl)rc.WhereTabCntrl.StackPanelWhereTab.Children[i]; if (i == 0) { query.AddWhere(SQLBuilder.Enums.LogicOperator.None, wInNotIn.cmbWhereTabInNotInColumns.Text, GetComparisonOpreator(wInNotIn.lblInNotIn.Content.ToString()), wInNotIn.txtInNotInValue.Text, Convert.ToInt32(wInNotIn.cmbWhereTabQueryLevel.Text)); } else { query.AddWhere(GetLogicalOpreator(wInNotIn.cmbWhereTabQueryAndOr.Text), wInNotIn.cmbWhereTabInNotInColumns.Text, GetComparisonOpreator(wInNotIn.lblInNotIn.Content.ToString()), wInNotIn.txtInNotInValue.Text, Convert.ToInt32(wInNotIn.cmbWhereTabQueryLevel.Text)); } break; case "FastDB.Control.WhereTabNullNotNullConditionControl": WhereTabNullNotNullConditionControl wNullNotNull = (WhereTabNullNotNullConditionControl)rc.WhereTabCntrl.StackPanelWhereTab.Children[i]; if (i == 0) { query.AddWhere(SQLBuilder.Enums.LogicOperator.None, wNullNotNull.cmbWhereTabNullNotNullColumns.Text, GetComparisonOpreator(wNullNotNull.lblNullNotNull.Content.ToString()), null, Convert.ToInt32(wNullNotNull.cmbWhereTabQueryLevel.Text)); } else { query.AddWhere(GetLogicalOpreator(wNullNotNull.cmbWhereTabQueryAndOr.Text), wNullNotNull.cmbWhereTabNullNotNullColumns.Text, GetComparisonOpreator(wNullNotNull.lblNullNotNull.Content.ToString()), null, Convert.ToInt32(wNullNotNull.cmbWhereTabQueryLevel.Text)); } break; } } } return query; }
public SelectQueryBuilder LoadSelectQueryBuilder() //made public zahed { SelectQueryBuilder query = new SelectQueryBuilder(); bool isSelecteTabColumnsOrGroupbyColumns = false; if (this.SelectTabUC.lstSelectedCol.ItemsSource != null) { //****Geting select columns***** //List<SQLBuilder.Clauses.Column> ListOfSelectColumn = ((List<SQLBuilder.Clauses.Column>)this.SelectTabUC.lstSelectedCol.ItemsSource); ObservableCollection<SQLBuilder.Clauses.Column> ListOfSelectColumn = ((ObservableCollection<SQLBuilder.Clauses.Column>)this.SelectTabUC.lstSelectedCol.ItemsSource); foreach (SQLBuilder.Clauses.Column Col in ListOfSelectColumn) { SQLBuilder.Clauses.Column column = new SQLBuilder.Clauses.Column(); column.Name = Col.Name; column.AliasName = Col.AliasName; column.Format = Col.Format; query.SelectColumn(column); } isSelecteTabColumnsOrGroupbyColumns = true; } if (this.TabulationTabUC.isTabulation) { //group by column for (int i = 0; i < this.TabulationTabUC.StackPanelTabuLationTabGroupBy.Children.Count; i++) { TabulationTabStackPanelGroupByControl tg = (TabulationTabStackPanelGroupByControl)this.TabulationTabUC.StackPanelTabuLationTabGroupBy.Children[i]; if (tg.cmbTabulationTabGroupByColumnsName.SelectedIndex != -1) { SQLBuilder.Clauses.Column column = new SQLBuilder.Clauses.Column(); //modified on 11/18/11 column.Name = tg.cmbTabulationTabGroupByColumnsName.Text; column.Format = tg.txtTabulationTabGroupByColFormat.Text; column.AliasName = tg.txtTabulationTabGroupByAlias.Text; //query.SelectColumn(column); query.AddGroupBy(column); if (tg.cmbTabulationSort.SelectedIndex != -1) { query.AddOrderBy(tg.cmbTabulationTabGroupByColumnsName.Text, GetSortingEnum(tg.cmbTabulationSort.Text)); } } } //summarize column for (int i = 0; i < this.TabulationTabUC.StackPanelTabuLationTabSummary.Children.Count; i++) { TabulationTabStackPanelSummaryControl ts = (TabulationTabStackPanelSummaryControl)this.TabulationTabUC.StackPanelTabuLationTabSummary.Children[i]; if (ts.cmbTabulationTabSummaryColumnsName.SelectedIndex != -1) { SQLBuilder.Clauses.Column column = new SQLBuilder.Clauses.Column(); column.Name = ts.cmbTabulationTypeOfSummary.Text + "(" + ts.cmbTabulationTabSummaryColumnsName.Text + ")"; column.Format = ts.txtTabulationTabSummaryColFormat.Text; column.AliasName = ts.txtTabulationTabSummaryAlias.Text; query.AddSummarize(column); } } isSelecteTabColumnsOrGroupbyColumns = true; } else if (this.CrossTabulationTabUC.isCrossTabulation) { //group by column for (int i = 0; i < this.CrossTabulationTabUC.StackPanelCrossTabuLationTabGroupBy.Children.Count; i++) { CrossTabulationTabStackPanelGroupByControl ctg = (CrossTabulationTabStackPanelGroupByControl)this.CrossTabulationTabUC.StackPanelCrossTabuLationTabGroupBy.Children[i]; if (ctg.cmbCrossTabulationTabGroupByColumnsName.SelectedIndex != -1) { SQLBuilder.Clauses.Column column = new SQLBuilder.Clauses.Column(); column.Name = ctg.cmbCrossTabulationTabGroupByColumnsName.Text; column.Format = ctg.txtCrossTabulationTabGroupByColFormat.Text; column.AliasName = ctg.txtCrossTabulationTabGroupByAlias.Text; query.AddGroupBy(column); if (ctg.cmbCrossTabulationSort.SelectedIndex != -1) { query.AddOrderBy(ctg.cmbCrossTabulationTabGroupByColumnsName.Text, GetSortingEnum(ctg.cmbCrossTabulationSort.Text)); } } } //summarize column for (int i = 0; i < this.CrossTabulationTabUC.StackPanelCrossTabuLationTabSummary.Children.Count; i++) { CrossTabulationTabStackPanelSummaryControl ts = (CrossTabulationTabStackPanelSummaryControl)this.CrossTabulationTabUC.StackPanelCrossTabuLationTabSummary.Children[i]; if (ts.cmbCrossTabulationTabSummaryColumnsName.SelectedIndex != -1) { SQLBuilder.Clauses.Column column = new SQLBuilder.Clauses.Column(); column.Name = ts.cmbCrossTabulationTypeOfSummary.Text + "(" + ts.cmbCrossTabulationTabSummaryColumnsName.Text + ")"; column.Format = ts.txtCrossTabulationTabSummaryColFormat.Text; column.AliasName = ts.txtCrossTabulationTabSummaryAlias.Text; query.AddSummarize(column); } } //summary first row SQLBuilder.Clauses.Column column1 = new SQLBuilder.Clauses.Column(); column1.Name = this.CrossTabulationTabUC.cmbCrossTabulationTabSummaryFirstRowColumnsName.Text; if (this.CrossTabulationTabUC.cmbCrossTabulationTabSummaryFristRowSort.SelectedIndex == -1) { query.CrossTabClause = new SQLBuilder.Clauses.CrossTabulationClause(column1); isSelecteTabColumnsOrGroupbyColumns = true; } else { query.CrossTabClause = new SQLBuilder.Clauses.CrossTabulationClause(column1, GetSortingEnum(this.CrossTabulationTabUC.cmbCrossTabulationTabSummaryFristRowSort.Text)); isSelecteTabColumnsOrGroupbyColumns = true; } } if (isSelecteTabColumnsOrGroupbyColumns) { //Geting from table SQLBuilder.Clauses.Table fromTable = new SQLBuilder.Clauses.Table(); fromTable.Name = this.FromTabUC.cmbFromTable.Text; fromTable.AliasName = this.FromTabUC.txtFromAlias.Text; query.SelectFromTable(fromTable); for (int i = 0; i < this.FromTabUC.StackPanelFromTab.Children.Count; i++) { FromTabStackPanelControl fs = (FromTabStackPanelControl)this.FromTabUC.StackPanelFromTab.Children[i]; SQLBuilder.Clauses.Table joinTable = new SQLBuilder.Clauses.Table(); joinTable.Name = fs.cmbFromTabJoinTable.Text; joinTable.AliasName = fs.txtJoinTableAlias.Text; query.AddJoin(GetJoinType(fs.cmbFromTabJoinType.Text), joinTable, fs.cmbFromTabJoinColumns.Text, GetComparisonOpreator(fs.cmbFromTabQueryOpretor.Text), fromTable, fs.cmbFromTabFromColumns.Text); } //******Geting Wheree Clause******** for (int i = 0; i < this.WhereTabUC.StackPanelWhereTab.Children.Count; i++) { string controlType = this.WhereTabUC.StackPanelWhereTab.Children[i].GetType().ToString(); switch (controlType) { case "FastDB.Control.WhereTabRegularConditionControl": WhereTabRegularConditionControl ws = (WhereTabRegularConditionControl)this.WhereTabUC.StackPanelWhereTab.Children[i]; if (i == 0) { query.AddWhere(SQLBuilder.Enums.LogicOperator.None, ws.cmbWhereTabLeftSideColumns.Text, GetComparisonOpreator(ws.cmbWhereTabQueryOpretor.Text), ws.cmbWhereTabRightSideColumns.Text, Convert.ToInt32(ws.cmbWhereTabQueryLevel.Text)); } else { query.AddWhere(GetLogicalOpreator(ws.cmbWhereTabQueryAndOr.Text), ws.cmbWhereTabLeftSideColumns.Text, GetComparisonOpreator(ws.cmbWhereTabQueryOpretor.Text), ws.cmbWhereTabRightSideColumns.Text, Convert.ToInt32(ws.cmbWhereTabQueryLevel.Text)); } break; case "FastDB.Control.WhereTabBetweenConditionControl": WhereTabBetweenConditionControl wsb = (WhereTabBetweenConditionControl)this.WhereTabUC.StackPanelWhereTab.Children[i]; if (i == 0) { query.AddWhere(SQLBuilder.Enums.LogicOperator.None, wsb.cmbWhereTabBetweenColumns.Text, wsb.txtBetweenLeftValue.Text, wsb.txtBetweenRightValue.Text, Convert.ToInt32(wsb.cmbWhereTabQueryLevel.Text)); } else { query.AddWhere(GetLogicalOpreator(wsb.cmbWhereTabQueryAndOr.Text), wsb.cmbWhereTabBetweenColumns.Text, wsb.txtBetweenLeftValue.Text, wsb.txtBetweenRightValue.Text, Convert.ToInt32(wsb.cmbWhereTabQueryLevel.Text)); } break; case "FastDB.Control.WhereTabInNotInConditionControl": WhereTabInNotInConditionControl wInNotIn = (WhereTabInNotInConditionControl)this.WhereTabUC.StackPanelWhereTab.Children[i]; if (i == 0) { query.AddWhere(SQLBuilder.Enums.LogicOperator.None, wInNotIn.cmbWhereTabInNotInColumns.Text, GetComparisonOpreator(wInNotIn.lblInNotIn.Content.ToString()), wInNotIn.txtInNotInValue.Text, Convert.ToInt32(wInNotIn.cmbWhereTabQueryLevel.Text)); } else { query.AddWhere(GetLogicalOpreator(wInNotIn.cmbWhereTabQueryAndOr.Text), wInNotIn.cmbWhereTabInNotInColumns.Text, GetComparisonOpreator(wInNotIn.lblInNotIn.Content.ToString()), wInNotIn.txtInNotInValue.Text, Convert.ToInt32(wInNotIn.cmbWhereTabQueryLevel.Text)); } break; case "FastDB.Control.WhereTabNullNotNullConditionControl": WhereTabNullNotNullConditionControl wNullNotNull = (WhereTabNullNotNullConditionControl)this.WhereTabUC.StackPanelWhereTab.Children[i]; if (i == 0) { query.AddWhere(SQLBuilder.Enums.LogicOperator.None, wNullNotNull.cmbWhereTabNullNotNullColumns.Text, GetComparisonOpreator(wNullNotNull.lblNullNotNull.Content.ToString()), null, Convert.ToInt32(wNullNotNull.cmbWhereTabQueryLevel.Text)); } else { query.AddWhere(GetLogicalOpreator(wNullNotNull.cmbWhereTabQueryAndOr.Text), wNullNotNull.cmbWhereTabNullNotNullColumns.Text, GetComparisonOpreator(wNullNotNull.lblNullNotNull.Content.ToString()), null, Convert.ToInt32(wNullNotNull.cmbWhereTabQueryLevel.Text)); } break; } } } return query; }