예제 #1
0
        private void RunQueryBtn_Click(object sender, RoutedEventArgs e)
        {
            MainWindow mainWindow = (MainWindow)GetTopLevelControl(this.ShortCutsToolBar);
            isAllTabValidated = mainWindow.ValidateAllTabCntrls(this);

            SelectQueryBuilder queryBuilder = mainWindow.LoadSelectQueryBuilderNew(this);
            string queryString;
            if (queryBuilder != null)
            {
                queryString = queryBuilder.BuildQuery();
            }
            XmlSerializer SerializerObj = new XmlSerializer(typeof(SelectQueryBuilder));
            StringWriter writer = new StringWriter();
            SerializerObj.Serialize(writer, queryBuilder);
            DateTime startTime = DateTime.Now;
            TabItem rvctabItem = RVCTAbControl.SelectedItem as TabItem;
            if (XmlSQLTabTxt.Text != null && rvctabItem.Name == "XmlSQLTab")
            {
                try
                {
                    connectionString = ConfigurationManager.AppSettings["DefaultDBConn"];
                    CurrentDatabaseName = ConfigurationManager.AppSettings["DefaultDatabase"];

                    connectionString = connectionString + "Database=" + CurrentDatabaseName + ";";
                    DataTable dataTable = new DataTable();
                    string sqldata = "";
                    dataTable = (MySQLData.DataAccess.ADODataBridge.getData(connectionString, XmlSQLTabTxt.Text));
                    DataView dataView = new DataView(dataTable);
                    ResultViewModel rvm = new ResultViewModel(dataView);
                    MainGirdViewControl mainGridView1 = new MainGirdViewControl(queryBuilder, mainWindow.CurrentDatabaseName, sqldata);

                    CloseableTabItem tabItem = (CloseableTabItem)this.ResultTab;

                    rvm.isModified = true;
                    rvm.isNew = true;

                    mainGridView1.DataContext = rvm;
                    tabItem.Content = mainGridView1;
                    mainGridView1.MainDataGrid.Width = dataTable.Columns.Count * 160;
                    mainGridView1.MainDataGrid.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;

                    this.DataContext = rvm;
                    this.ResultTab.IsSelected = true;
                    lblXmlSQLTabErrorMessage.Visibility = System.Windows.Visibility.Hidden;

                }
                catch (MySql.Data.MySqlClient.MySqlException ex)
                {
                    if (isErrorLoggingOn)
                    {
                        lblXmlSQLTabErrorMessage.Visibility = System.Windows.Visibility.Visible;
                        lblXmlSQLTabErrorMessage.Height = 20;
                        lblXmlSQLTabErrorMessage.Content = ex.Message;
                        LogError.Log_Err("btnRunQuery_Click", ex);
                    }
                }
                catch (Exception ex)
                {
                    if (isErrorLoggingOn)
                    {
                        LogError.Log_Err("btnRunQuery_Click", ex);
                    }
                }
                Mouse.OverrideCursor = null;
            }
            else if (isAllTabValidated)
            {
                if (mainWindow.queryString != String.Empty)
                {
                    if (queryBuilder != null)
                    {
                        CloseableTabItem tabItem = (CloseableTabItem)this.ResultTab;

                        if (tabItem.Content == null)
                        {
                            Mouse.OverrideCursor = Cursors.Wait;
                            try
                            {
                                if (queryBuilder.CrossTabClause != null)
                                {
                                    if (queryBuilder.CrossTabClause.Col == null)
                                    {
                                        MainGirdViewControl mainGridView1 = new MainGirdViewControl(queryBuilder, mainWindow.CurrentDatabaseName);
                                        result = mainGridView1.result;

                                        result.isModified = true;
                                        result.isNew = true;

                                        mainGridView1.DataContext = result;
                                        tabItem.Content = mainGridView1;

                                        mainGridView1.MainDataGrid.Width = result.EndColumn * 160;
                                        mainGridView1.MainDataGrid.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;

                                        this.DataContext = result;
                                        this.ResultTab.IsSelected = true;
                                    }
                                    else
                                    {
                                        if (this.StackPanelResultViewControl.Children.Count == 1)
                                        {
                                            if ((MainGirdViewControl)this.StackPanelResultViewControl.Children[0] != null)
                                            {
                                                this.StackPanelResultViewControl.Children.RemoveAt(0);
                                            }
                                        }
                                        CrossTabulationViewControl crossTabViewControl = new CrossTabulationViewControl(queryBuilder, mainWindow.CurrentDatabaseName);
                                        result = crossTabViewControl.result;
                                        this.StackPanelResultViewControl.Children.Add(crossTabViewControl);
                                    }
                                }
                            }
                            catch (MySql.Data.MySqlClient.MySqlException ex)
                            {
                                if (isErrorLoggingOn)
                                {
                                    LogError.Log_Err("btnRunQuery_Click", ex);
                                }
                            }
                            catch (Exception ex)
                            {
                                if (isErrorLoggingOn)
                                {
                                    LogError.Log_Err("btnRunQuery_Click", ex);
                                }
                            }
                            Mouse.OverrideCursor = null;
                        }
                        else
                        {

                            ResultViewModel rv = (ResultViewModel)this.result;
                            if (rv.isNew)
                            {
                                // we still let user run the query, query still new and modified= true
                                Mouse.OverrideCursor = Cursors.Wait;
                                try
                                {
                                    if (queryBuilder.CrossTabClause != null)
                                    {
                                        if (queryBuilder.CrossTabClause.Col == null)
                                        {
                                            if (queryBuilder.GroupByColumns.Count == 0 && queryBuilder.SelectedColumns.Count == 0)
                                            {
                                                foreach (SQLBuilder.Clauses.Column col in this.SelectTabCntrl.lstToSelecteColFrom.Items)
                                                {
                                                    queryBuilder.SelectColumn(col);
                                                }
                                            }
                                            MainGirdViewControl mainGridView1 = new MainGirdViewControl(queryBuilder, mainWindow.CurrentDatabaseName);
                                            result = mainGridView1.result;

                                            result.isModified = true;
                                            result.isNew = true;

                                            mainGridView1.DataContext = result;
                                            tabItem.Content = mainGridView1;

                                            mainGridView1.MainDataGrid.Width = result.EndColumn * 160;
                                            mainGridView1.MainDataGrid.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
                                            CloseableTabItem ti = (CloseableTabItem)mainWindow.tabControl1.SelectedItem;
                                            ti.labelStar.Content = "*";
                                            this.DataContext = result;
                                            this.ResultTab.IsSelected = true;
                                        }
                                        else
                                        {
                                            if (this.StackPanelResultViewControl.Children.Count == 1)
                                            {
                                                if (this.StackPanelResultViewControl.Children[0] != null)
                                                {
                                                    this.StackPanelResultViewControl.Children.RemoveAt(0);
                                                }
                                            }
                                            CrossTabulationViewControl crossTabViewControl = new CrossTabulationViewControl(queryBuilder, mainWindow.CurrentDatabaseName);
                                            result = crossTabViewControl.result;
                                            this.StackPanelResultViewControl.Children.Add(crossTabViewControl);
                                            this.ResultTab.IsSelected = true;
                                        }
                                    }
                                }
                                catch (MySql.Data.MySqlClient.MySqlException ex)
                                {
                                    if (isErrorLoggingOn)
                                    {
                                        LogError.Log_Err("btnRunQuery_Click", ex);
                                    }
                                }
                                catch (Exception ex)
                                {
                                    if (isErrorLoggingOn)
                                    {
                                        LogError.Log_Err("btnRunQuery_Click", ex);
                                    }
                                }
                                Mouse.OverrideCursor = null;
                            }
                            else
                            {
                                // it is old
                                //check to see if old querybuilder and new querybuilder is same, if different CompairQueryBuilder retuns true
                                if (mainWindow.CompairQueryBuilder(rv.QueryBulder, queryBuilder))
                                {
                                    Mouse.OverrideCursor = Cursors.Wait;
                                    try
                                    {
                                        string directoryPath = String.Empty;
                                        if (result != null)
                                        {
                                            if (result.directoryPath != null)
                                            {
                                                directoryPath = result.directoryPath;
                                            }
                                        }

                                        if (queryBuilder.CrossTabClause != null && queryBuilder.CrossTabClause.Col != null)
                                        {
                                            if (this.StackPanelResultViewControl.Children.Count == 1)
                                            {
                                                if (this.StackPanelResultViewControl.Children[0] != null)
                                                {
                                                    this.StackPanelResultViewControl.Children.RemoveAt(0);
                                                }
                                            }
                                            CrossTabulationViewControl crossTabViewControl = new CrossTabulationViewControl(queryBuilder, mainWindow.CurrentDatabaseName);
                                            result = crossTabViewControl.result;
                                            this.StackPanelResultViewControl.Children.Add(crossTabViewControl);
                                            this.ResultTab.IsSelected = true;
                                            CloseableTabItem ti = (CloseableTabItem)mainWindow.tabControl1.SelectedItem;
                                            ti.labelStar.Content = "*";
                                        }
                                        else
                                        {
                                            MainGirdViewControl mainGridView1 = new MainGirdViewControl(queryBuilder, mainWindow.CurrentDatabaseName);
                                            result = mainGridView1.result;
                                            mainGridView1.DataContext = result;
                                            tabItem.Content = mainGridView1;

                                            mainGridView1.MainDataGrid.Width = result.EndColumn * 160;
                                            mainGridView1.MainDataGrid.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
                                            CloseableTabItem ti = (CloseableTabItem)mainWindow.tabControl1.SelectedItem;
                                            ti.labelStar.Content = "*";
                                        }

                                        if (directoryPath != String.Empty)
                                        {
                                            result.directoryPath = directoryPath;
                                        }

                                        result.isModified = true;
                                        result.isNew = false;

                                        this.DataContext = result;
                                        this.ResultTab.IsSelected = true;
                                    }
                                    catch (MySql.Data.MySqlClient.MySqlException ex)
                                    {
                                        if (isErrorLoggingOn)
                                        {
                                            LogError.Log_Err("btnRunQuery_Click", ex);
                                        }
                                    }
                                    catch (Exception ex)
                                    {
                                        if (isErrorLoggingOn)
                                        {
                                            LogError.Log_Err("btnRunQuery_Click", ex);
                                        }
                                    }
                                    Mouse.OverrideCursor = null;
                                }
                                this.ResultTab.IsSelected = true;
                            }
                        }
                    }
                }
                XmlSQLTabTxt.Text = queryBuilder.BuildQuery();
            }
            
            Console.WriteLine("Cross Tabulation View Control execution time: " + (DateTime.Now - startTime));
        }
예제 #2
0
 public ResultViewControl(SQLBuilder.SelectQueryBuilder QuerryBuilder, string CurrentDatabaseName)
 {
     InitializeComponent();
     if (QuerryBuilder.CrossTabClause != null)
     {
         if (QuerryBuilder.CrossTabClause.Col == null)
         {
             if (this.StackPanelResultViewControl.Children.Count == 0)
             {
                 MainGirdViewControl mainGridView = new MainGirdViewControl(QuerryBuilder, CurrentDatabaseName);
                 result = mainGridView.result;
                 this.StackPanelResultViewControl.Children.Add(mainGridView);
                 this.ResultTab.IsSelected = true;
                 this.CustomQueryAccordion.SelectionMode = AccordionSelectionMode.ZeroOrMore;
                 int mainGridWidth = (((FastDB.ResultViewModel)(mainGridView.MainDataGrid.DataContext)).EndColumn * 160);
                 {
                     mainGridView.MainDataGrid.Width = mainGridWidth;
                 }
                 mainGridView.MainDataGrid.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;    //zahed
             }
         }
         else
         {
             if (this.StackPanelResultViewControl.Children.Count == 1)
             {
                 if ((MainGirdViewControl)this.StackPanelResultViewControl.Children[0] != null)
                 {
                     this.StackPanelResultViewControl.Children.RemoveAt(0);
                 }
             }
             CrossTabulationViewControl crossTabViewControl = new CrossTabulationViewControl(QuerryBuilder, CurrentDatabaseName);
             result = crossTabViewControl.result;
             this.ResultTab.IsSelected = true;
             this.CustomQueryAccordion.SelectionMode = AccordionSelectionMode.ZeroOrMore;
             this.StackPanelResultViewControl.Children.Add(crossTabViewControl);
         }
     }
     this.DataContext = result;
 }