void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target)
        {
            switch (connectionId)
            {
            case 1:
                this.ShortCutsToolBar = ((System.Windows.Controls.ToolBar)(target));

            #line 99 "..\..\..\..\Control\ResultViewControl.xaml"
                this.ShortCutsToolBar.Loaded += new System.Windows.RoutedEventHandler(this.ToolBar_Loaded);

            #line default
            #line hidden
                return;

            case 2:
                this.ExecuteQueryBtn = ((System.Windows.Controls.Button)(target));

            #line 101 "..\..\..\..\Control\ResultViewControl.xaml"
                this.ExecuteQueryBtn.Click += new System.Windows.RoutedEventHandler(this.RunQueryBtn_Click);

            #line default
            #line hidden
                return;

            case 3:
                this.StopExecutionBtn = ((System.Windows.Controls.Button)(target));

            #line 104 "..\..\..\..\Control\ResultViewControl.xaml"
                this.StopExecutionBtn.Click += new System.Windows.RoutedEventHandler(this.StopExecutionBtn_Click);

            #line default
            #line hidden
                return;

            case 4:
                this.SaveQueryBtn = ((System.Windows.Controls.Button)(target));

            #line 107 "..\..\..\..\Control\ResultViewControl.xaml"
                this.SaveQueryBtn.Click += new System.Windows.RoutedEventHandler(this.SaveQueryBtn_Click);

            #line default
            #line hidden
                return;

            case 5:
                this.SaveQueryAsBtn = ((System.Windows.Controls.Button)(target));

            #line 110 "..\..\..\..\Control\ResultViewControl.xaml"
                this.SaveQueryAsBtn.Click += new System.Windows.RoutedEventHandler(this.SaveQueryAsBtn_Click);

            #line default
            #line hidden
                return;

            case 6:
                this.ExportToExcel = ((System.Windows.Controls.Button)(target));

            #line 113 "..\..\..\..\Control\ResultViewControl.xaml"
                this.ExportToExcel.Click += new System.Windows.RoutedEventHandler(this.ExportToExcel_Click);

            #line default
            #line hidden
                return;

            case 7:
                this.ExportToFolder = ((System.Windows.Controls.Button)(target));

            #line 116 "..\..\..\..\Control\ResultViewControl.xaml"
                this.ExportToFolder.Click += new System.Windows.RoutedEventHandler(this.SaveXML_Click);

            #line default
            #line hidden
                return;

            case 8:
                this.RVCTAbControl = ((System.Windows.Controls.TabControl)(target));

            #line 122 "..\..\..\..\Control\ResultViewControl.xaml"
                this.RVCTAbControl.SelectionChanged += new System.Windows.Controls.SelectionChangedEventHandler(this.RVCTAbControl_SelectionChanged);

            #line default
            #line hidden
                return;

            case 9:
                this.QueryTab = ((FastDB.CloseableTabItem)(target));
                return;

            case 10:
                this.CustomQueryAccordion = ((System.Windows.Controls.Accordion)(target));

            #line 133 "..\..\..\..\Control\ResultViewControl.xaml"
                this.CustomQueryAccordion.SelectedItemsChanged += new System.Collections.Specialized.NotifyCollectionChangedEventHandler(this.CustomQueryAccordion_SelectedItemsChanged);

            #line default
            #line hidden
                return;

            case 11:
                this.FromAccordionItem = ((System.Windows.Controls.AccordionItem)(target));
                return;

            case 12:
                this.FromAccItemDummyGrid = ((System.Windows.Controls.Grid)(target));
                return;

            case 13:
                this.FromTabCntrl = ((FastDB.Control.FromTabControl)(target));
                return;

            case 14:
                this.SelectAccordionItem = ((System.Windows.Controls.AccordionItem)(target));
                return;

            case 15:
                this.SelectGrid = ((System.Windows.Controls.Grid)(target));
                return;

            case 16:
                this.SelectTabCntrl = ((FastDB.Control.SelectTabControl)(target));
                return;

            case 17:
                this.WhereAccordionItem = ((System.Windows.Controls.AccordionItem)(target));
                return;

            case 18:
                this.WhereGrid = ((System.Windows.Controls.Grid)(target));

            #line 168 "..\..\..\..\Control\ResultViewControl.xaml"
                this.WhereGrid.SizeChanged += new System.Windows.SizeChangedEventHandler(this.WhereGrid_SizeChanged);

            #line default
            #line hidden
                return;

            case 19:
                this.WhereTabCntrl = ((FastDB.Control.WhereTabControl)(target));
                return;

            case 20:
                this.TabulationAccordionItem = ((System.Windows.Controls.AccordionItem)(target));
                return;

            case 21:
                this.TabulationTabCntrl = ((FastDB.Control.TabulationTabControl)(target));
                return;

            case 22:
                this.CrossTabulationAccordionItem = ((System.Windows.Controls.AccordionItem)(target));
                return;

            case 23:
                this.CrossTabulationTabCntrl = ((FastDB.Control.CrossTabulationTabControl)(target));
                return;

            case 24:
                this.ResultTab = ((FastDB.CloseableTabItem)(target));
                return;

            case 25:
                this.StackPanelResultViewControl = ((System.Windows.Controls.StackPanel)(target));
                return;

            case 26:
                this.XmlQueryTab = ((FastDB.CloseableTabItem)(target));
                return;

            case 27:
                this.lblXmlQueryTabErrorMessage = ((System.Windows.Controls.Label)(target));
                return;

            case 28:
                this.XmlQueryTabTxt = ((System.Windows.Controls.TextBox)(target));
                return;

            case 29:
                this.XmlSQLTab = ((FastDB.CloseableTabItem)(target));
                return;

            case 30:
                this.lblXmlSQLTabErrorMessage = ((System.Windows.Controls.Label)(target));
                return;

            case 31:
                this.chkSQL = ((System.Windows.Controls.CheckBox)(target));

            #line 229 "..\..\..\..\Control\ResultViewControl.xaml"
                this.chkSQL.Checked += new System.Windows.RoutedEventHandler(this.OnChecked_chkSSQL);

            #line default
            #line hidden

            #line 229 "..\..\..\..\Control\ResultViewControl.xaml"
                this.chkSQL.Unchecked += new System.Windows.RoutedEventHandler(this.OnUnChecked_chkSSQL);

            #line default
            #line hidden
                return;

            case 32:
                this.XmlSQLTabTxt = ((System.Windows.Controls.TextBox)(target));
                return;
            }
            this._contentLoaded = true;
        }
 void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target) {
     switch (connectionId)
     {
     case 1:
     this.ShortCutsToolBar = ((System.Windows.Controls.ToolBar)(target));
     
     #line 99 "..\..\..\..\Control\ResultViewControl.xaml"
     this.ShortCutsToolBar.Loaded += new System.Windows.RoutedEventHandler(this.ToolBar_Loaded);
     
     #line default
     #line hidden
     return;
     case 2:
     this.ExecuteQueryBtn = ((System.Windows.Controls.Button)(target));
     
     #line 101 "..\..\..\..\Control\ResultViewControl.xaml"
     this.ExecuteQueryBtn.Click += new System.Windows.RoutedEventHandler(this.RunQueryBtn_Click);
     
     #line default
     #line hidden
     return;
     case 3:
     this.StopExecutionBtn = ((System.Windows.Controls.Button)(target));
     
     #line 104 "..\..\..\..\Control\ResultViewControl.xaml"
     this.StopExecutionBtn.Click += new System.Windows.RoutedEventHandler(this.StopExecutionBtn_Click);
     
     #line default
     #line hidden
     return;
     case 4:
     this.SaveQueryBtn = ((System.Windows.Controls.Button)(target));
     
     #line 107 "..\..\..\..\Control\ResultViewControl.xaml"
     this.SaveQueryBtn.Click += new System.Windows.RoutedEventHandler(this.SaveQueryBtn_Click);
     
     #line default
     #line hidden
     return;
     case 5:
     this.SaveQueryAsBtn = ((System.Windows.Controls.Button)(target));
     
     #line 110 "..\..\..\..\Control\ResultViewControl.xaml"
     this.SaveQueryAsBtn.Click += new System.Windows.RoutedEventHandler(this.SaveQueryAsBtn_Click);
     
     #line default
     #line hidden
     return;
     case 6:
     this.ExportToExcel = ((System.Windows.Controls.Button)(target));
     
     #line 113 "..\..\..\..\Control\ResultViewControl.xaml"
     this.ExportToExcel.Click += new System.Windows.RoutedEventHandler(this.ExportToExcel_Click);
     
     #line default
     #line hidden
     return;
     case 7:
     this.ExportToFolder = ((System.Windows.Controls.Button)(target));
     
     #line 116 "..\..\..\..\Control\ResultViewControl.xaml"
     this.ExportToFolder.Click += new System.Windows.RoutedEventHandler(this.SaveXML_Click);
     
     #line default
     #line hidden
     return;
     case 8:
     this.RVCTAbControl = ((System.Windows.Controls.TabControl)(target));
     
     #line 122 "..\..\..\..\Control\ResultViewControl.xaml"
     this.RVCTAbControl.SelectionChanged += new System.Windows.Controls.SelectionChangedEventHandler(this.RVCTAbControl_SelectionChanged);
     
     #line default
     #line hidden
     return;
     case 9:
     this.QueryTab = ((FastDB.CloseableTabItem)(target));
     return;
     case 10:
     this.CustomQueryAccordion = ((System.Windows.Controls.Accordion)(target));
     
     #line 133 "..\..\..\..\Control\ResultViewControl.xaml"
     this.CustomQueryAccordion.SelectedItemsChanged += new System.Collections.Specialized.NotifyCollectionChangedEventHandler(this.CustomQueryAccordion_SelectedItemsChanged);
     
     #line default
     #line hidden
     return;
     case 11:
     this.FromAccordionItem = ((System.Windows.Controls.AccordionItem)(target));
     return;
     case 12:
     this.FromAccItemDummyGrid = ((System.Windows.Controls.Grid)(target));
     return;
     case 13:
     this.FromTabCntrl = ((FastDB.Control.FromTabControl)(target));
     return;
     case 14:
     this.SelectAccordionItem = ((System.Windows.Controls.AccordionItem)(target));
     return;
     case 15:
     this.SelectGrid = ((System.Windows.Controls.Grid)(target));
     return;
     case 16:
     this.SelectTabCntrl = ((FastDB.Control.SelectTabControl)(target));
     return;
     case 17:
     this.WhereAccordionItem = ((System.Windows.Controls.AccordionItem)(target));
     return;
     case 18:
     this.WhereGrid = ((System.Windows.Controls.Grid)(target));
     
     #line 168 "..\..\..\..\Control\ResultViewControl.xaml"
     this.WhereGrid.SizeChanged += new System.Windows.SizeChangedEventHandler(this.WhereGrid_SizeChanged);
     
     #line default
     #line hidden
     return;
     case 19:
     this.WhereTabCntrl = ((FastDB.Control.WhereTabControl)(target));
     return;
     case 20:
     this.TabulationAccordionItem = ((System.Windows.Controls.AccordionItem)(target));
     return;
     case 21:
     this.TabulationTabCntrl = ((FastDB.Control.TabulationTabControl)(target));
     return;
     case 22:
     this.CrossTabulationAccordionItem = ((System.Windows.Controls.AccordionItem)(target));
     return;
     case 23:
     this.CrossTabulationTabCntrl = ((FastDB.Control.CrossTabulationTabControl)(target));
     return;
     case 24:
     this.ResultTab = ((FastDB.CloseableTabItem)(target));
     return;
     case 25:
     this.StackPanelResultViewControl = ((System.Windows.Controls.StackPanel)(target));
     return;
     case 26:
     this.XmlQueryTab = ((FastDB.CloseableTabItem)(target));
     return;
     case 27:
     this.lblXmlQueryTabErrorMessage = ((System.Windows.Controls.Label)(target));
     return;
     case 28:
     this.XmlQueryTabTxt = ((System.Windows.Controls.TextBox)(target));
     return;
     case 29:
     this.XmlSQLTab = ((FastDB.CloseableTabItem)(target));
     return;
     case 30:
     this.lblXmlSQLTabErrorMessage = ((System.Windows.Controls.Label)(target));
     return;
     case 31:
     this.chkSQL = ((System.Windows.Controls.CheckBox)(target));
     
     #line 229 "..\..\..\..\Control\ResultViewControl.xaml"
     this.chkSQL.Checked += new System.Windows.RoutedEventHandler(this.OnChecked_chkSSQL);
     
     #line default
     #line hidden
     
     #line 229 "..\..\..\..\Control\ResultViewControl.xaml"
     this.chkSQL.Unchecked += new System.Windows.RoutedEventHandler(this.OnUnChecked_chkSSQL);
     
     #line default
     #line hidden
     return;
     case 32:
     this.XmlSQLTabTxt = ((System.Windows.Controls.TextBox)(target));
     return;
     }
     this._contentLoaded = true;
 }
        private void MainTreeView_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
        {
            TreeView tv = (TreeView)sender;
            count = 0;                      //zahed          

            if (tv.SelectedItem.GetType().Name == "tableViewModel")
            {

                tableViewModel tvm = (tableViewModel)tv.SelectedItem;

                currentTableViewModel = tvm;
                CurrentDatabaseName = tvm._ParentSchemaName;
                // display path at the top of the screen
                //txtBlockDisplayPath.Text = "All Databases/" + ((schemaViewModel)tvm.Parent).schemaName + "/" + tvm.tableName;
                int tabNumber = this.tabControl1.Items.Count + 1;
                CloseableTabItem tabItem = new CloseableTabItem();
                tabItem.Name = tvm.tableName + tabNumber;
                nameOfTabitemAssoWithCustomQuery = tabItem.Name;                
                tabItem.Header = GetTabHeaderName(tvm.tableName, tabNumber);                                

                //add ResultViewerControl
                Mouse.OverrideCursor = Cursors.Wait;
                try
                {
                    Control.ResultViewControl resultControl = new Control.ResultViewControl(tvm, true);

                    ResultViewModel rv = (ResultViewModel)resultControl.DataContext;
                    if (rv.Results.Count != 0)
                    {
                        rv.isNew = true;
                        rv.isModified = true;
                        tabItem.Part_Label_Content = "*";
                    }

                    tabItem.Content = resultControl;
                    /******************************/
                    this.Logo.Visibility = Visibility.Hidden;
                    this.LogoTxt.Visibility = Visibility.Hidden;
                    this.tabControl1.Visibility = Visibility.Visible;
                    /******************************/
                }
                catch (MySql.Data.MySqlClient.MySqlException ex)
                {
                    if (isErrorLoggingOn)
                    {
                        LogError.Log_Err("MainTreeView_SelectedItemChanged", ex);
                        DisplayErrorMessage();
                    }
                }
                catch (Exception ex)
                {
                    if (isErrorLoggingOn)
                    {
                        LogError.Log_Err("MainTreeView_SelectedItemChanged", ex);
                        DisplayErrorMessage();
                    }
                }
                Mouse.OverrideCursor = null;
                //add tab to tabcontrol
                this.tabControl1.Items.Add(tabItem);
                //Get focus on new tab
                ((TabItem)(this.tabControl1.Items[tabNumber - 1])).Focus();


                this.adornedControl.IsAdornerVisible = false;
                //this.BtnHideCustomQueryWindow.Visibility = System.Windows.Visibility.Visible;



            }

        }
        public void CheckQueryNeededToBeSaved(CloseableTabItem tabItem, string caller) //zahed
        {
            ResultViewControl rc = (ResultViewControl)tabItem.Content;

            //ResultViewModel rv = (ResultViewModel)rc.DataContext;               //moved this from here from inside if
            ResultViewModel rv = (ResultViewModel)rc.result;//mainGV.DataContext;
            if (rc != null && currentTableViewModel != null && rv != null)     //zahed
            {
                //ResultViewModel rv = (ResultViewModel)rc.DataContext;         
                if (rv.isModified)
                {
                    if (rv.isNew == false)
                    {
                        //over write
                        switch (caller)
                        {
                            case "Save":
                                string FileName = rv.directoryPath + tabItem.Header.ToString() + ".xml";
                                if (FileName != System.String.Empty)
                                {
                                    XmlSerializer SerializerObj = new XmlSerializer(typeof(SelectQueryBuilder));
                                    StreamWriter swriter = new StreamWriter(FileName);
                                    SerializerObj.Serialize(swriter, rv.QueryBulder);

                                    swriter.Flush();
                                    swriter.Close();
                                    tabItem.Header = tabItem.Header.ToString();
                                    this.CustomQueryTxTBlk.Text = "Custom query for " + tabItem.Header;
                                    //we saved the query change isModified to false
                                    rv.isModified = false;
                                    tabItem.labelStar.Content = "";
                                    MessageBox.Show("query saved successfully");
                                }
                                break;
                            case "SaveAs":
                                //save save as the query
                                string FileName1 = OpenSaveDialog(tabItem.Name);

                                if (FileName1 != System.String.Empty)
                                {
                                    XmlSerializer SerializerObj = new XmlSerializer(typeof(SelectQueryBuilder));
                                    StreamWriter swriter = new StreamWriter(FileName1);
                                    SerializerObj.Serialize(swriter, rv.QueryBulder);

                                    swriter.Flush();
                                    swriter.Close();
                                    string[] splitedArray = FileName1.Split('\\');
                                    string tabItemHeader = splitedArray[splitedArray.Length - 1].Remove((splitedArray[splitedArray.Length - 1]).Length - 4, 4);
                                    tabItem.Header = tabItemHeader;
                                    this.CustomQueryTxTBlk.Text = "Custom query for " + tabItemHeader;
                                    //we saved the query change isModified to false
                                    rv.isModified = false;
                                    tabItem.labelStar.Content = "";
                                    MessageBox.Show("query saved successfully");
                                }
                                break;
                            case "CloseTab":
                                SaveNewQuery(tabItem, rv.QueryBulder);
                                break;

                        }

                    }
                    else
                    {

                        //it is new ****

                        switch (caller)
                        {

                            case "SaveAs":
                                if (rv.TotalIRows != 0)
                                {
                                    //save save as the query
                                    string FileName = OpenSaveDialog(tabItem.Name);

                                    if (FileName != System.String.Empty)
                                    {
                                        XmlSerializer SerializerObj = new XmlSerializer(typeof(SelectQueryBuilder));
                                        StreamWriter swriter = new StreamWriter(FileName);
                                        SerializerObj.Serialize(swriter, rv.QueryBulder);

                                        swriter.Flush();
                                        swriter.Close();
                                        string[] splitedArray = FileName.Split('\\');
                                        string tabItemHeader = splitedArray[splitedArray.Length - 1].Remove((splitedArray[splitedArray.Length - 1]).Length - 4, 4);
                                        tabItem.Header = tabItemHeader;
                                        this.CustomQueryTxTBlk.Text = "Custom query for " + tabItemHeader;
                                        //we saved the query change isModified to false
                                        rv.isModified = false;
                                        tabItem.labelStar.Content = "";
                                        MessageBox.Show("query saved successfully");
                                    }
                                }
                                break;

                            case "Save":
                                if (rv.TotalIRows != 0)
                                {
                                    SaveNewQuery(tabItem, rv.QueryBulder);
                                }
                                break;
                            case "CloseTab":
                                if (rv.TotalIRows != 0)
                                {
                                    SaveNewQuery(tabItem, rv.QueryBulder);
                                }
                                else
                                {
                                    TabControl tabControl = tabItem.Parent as TabControl;
                                    if (tabControl != null)
                                        tabControl.Items.Remove(tabItem);
                                }
                                break;
                        }

                    }
                }
                else
                {
                    switch (caller)
                    {
                        case "Save":

                            break;
                        case "SaveAs":

                            break;
                        case "SaveXML":

                            break;
                        case "CloseTab":
                            TabControl tabControl = tabItem.Parent as TabControl;
                            if (tabControl != null)
                                tabControl.Items.Remove(tabItem);

                            /******************************/
                            if (tabControl.Items.Count == 0)
                            {
                                this.Logo.Visibility = Visibility.Visible;
                                this.LogoTxt.Visibility = Visibility.Visible;
                                this.tabControl1.Visibility = Visibility.Hidden;
                            }
                            /******************************/
                            break;
                    }

                }
            }
            else
            {
                if (caller == "CloseTab")
                {
                    TabControl tabControl = tabItem.Parent as TabControl;
                    if (tabControl != null)
                        tabControl.Items.Remove(tabItem);

                    /******************************/
                    if (tabControl.Items.Count == 0)
                    {
                        this.Logo.Visibility = Visibility.Visible;
                        this.LogoTxt.Visibility = Visibility.Visible;
                        this.tabControl1.Visibility = Visibility.Hidden;
                    }
                    /******************************/
                }
            }
        }
        private void SaveNewQuery(CloseableTabItem tabItem, SelectQueryBuilder QueryBulder)
        {
            //prompt the user
            // Configure the message box to be displayed
            string messageBoxText = "Do you want to save current query?";
            string caption = "Current Query";
            MessageBoxButton button = MessageBoxButton.YesNoCancel;
            MessageBoxImage icon = MessageBoxImage.Question;
            // Display message box
            MessageBoxResult result = MessageBox.Show(messageBoxText, caption, button, icon);
            // Process message box results
            switch (result)
            {

                case MessageBoxResult.Yes:
                    // User pressed Yes button
                    //save save query                     
                    ResultViewControl rc = (ResultViewControl)tabItem.Content;
                    //ResultViewModel rv = (ResultViewModel)rc.DataContext;
                    /******************/
                    ResultViewModel rv = rc.result;
                    /******************/
                    string FileName1 = System.String.Empty;
                    if (rv.isNew == false)
                    {
                        FileName1 = rv.directoryPath + tabItem.Header.ToString() + ".xml";
                    }
                    else
                    {
                        FileName1 = OpenSaveDialog(tabItem.Name);
                    }
                    if (FileName1 != System.String.Empty)
                    {
                        XmlSerializer SerializerObj = new XmlSerializer(typeof(SelectQueryBuilder));
                        StreamWriter swriter = new StreamWriter(FileName1);
                        SerializerObj.Serialize(swriter, QueryBulder);

                        swriter.Flush();
                        swriter.Close();
                        string[] splitedArray = FileName1.Split('\\');
                        string tabItemHeader = splitedArray[splitedArray.Length - 1].Remove((splitedArray[splitedArray.Length - 1]).Length - 4, 4);
                        tabItem.Header = tabItemHeader;
                        this.CustomQueryTxTBlk.Text = "Custom query for " + tabItemHeader;
                        //we saved the query change isModified to false
                        rv.isModified = false;
                        tabItem.labelStar.Content = "";
                        MessageBox.Show("query saved successfully");

                        /**************************/
                        rc.result.directoryPath = FileName1.Replace(splitedArray[splitedArray.Length - 1], "");
                        /**************************/

                        /******************************/
                        TabControl tabControl = tabItem.Parent as TabControl;
                        if (tabControl.Items.Count == 0)
                        {
                            this.Logo.Visibility = Visibility.Visible;
                            this.LogoTxt.Visibility = Visibility.Visible;
                            this.tabControl1.Visibility = Visibility.Hidden;
                        }
                        /******************************/
                    }

                    break;
                case MessageBoxResult.No:
                    // User pressed No button
                    TabControl tabControl1 = tabItem.Parent as TabControl; //zahed
                    if (tabControl1 != null)
                        tabControl1.Items.Remove(tabItem);
                    /******************************/
                    if (tabControl1.Items.Count == 0)
                    {
                        this.Logo.Visibility = Visibility.Visible;
                        this.LogoTxt.Visibility = Visibility.Visible;
                        this.tabControl1.Visibility = Visibility.Hidden;
                    }
                    /******************************/

                    break;
                case MessageBoxResult.Cancel:
                    // User pressed Cancel button
                    // ...
                    break;
            }
        }
        private void Open_Click()
        {
            string FileName = OpenFileDialog();
            if (FileName != System.String.Empty)
            {
                XmlSerializer SerializerObj = new XmlSerializer(typeof(SelectQueryBuilder));
                SelectQueryBuilder loadedQuery = (SelectQueryBuilder)SerializerObj.Deserialize(new StreamReader(FileName));
                string[] splitedArray = FileName.Split('\\');
                string tabItemName = splitedArray[splitedArray.Length - 1].Remove((splitedArray[splitedArray.Length - 1]).Length - 4, 4);
                if (loadedQuery != null)
                {
                    //addd new tab
                    CloseableTabItem tabItem = new CloseableTabItem();
                    tabItem.Name = "CustomQuery" + (this.tabControl1.Items.Count + 1).ToString();
                    tabItem.Header = tabItemName;

                    /******************************/
                    this.Logo.Visibility = Visibility.Hidden;
                    this.LogoTxt.Visibility = Visibility.Hidden;
                    this.tabControl1.Visibility = Visibility.Visible;
                    /******************************/

                    //add tab to tabcontrol
                    this.tabControl1.Items.Add(tabItem);
                    //Clear Custom QueryTabs

                    //Modified 11/10/11 clearing tab with common method ClearAllCustomeQueryTabs
                    //ClearAllCustomeQueryTabs();
                    ////Clear from tab
                    //this.FromTabUC.cmbFromTable.SelectedIndex = -1;
                    //this.FromTabUC.txtFromAlias.Text = System.String.Empty;
                    //this.FromTabUC.StackPanelFromTab.Children.Clear();

                    //////Clear where tab
                    //this.WhereTabUC.StackPanelWhereTab.Children.Clear();

                    ////clear Select Tab
                    //this.SelectTabUC.dgSelectTab.ItemsSource = null;

                    //Get focus on new tab
                    ((TabItem)(this.tabControl1.Items[this.tabControl1.Items.Count - 1])).Focus();
                    string queryString = loadedQuery.BuildQuery();
                    if (queryString != System.String.Empty)
                    {
                        CloseableTabItem tbItem = (CloseableTabItem)this.tabControl1.SelectedItem;
                        Mouse.OverrideCursor = Cursors.Wait;
                        Control.ResultViewControl resultControl = new Control.ResultViewControl(loadedQuery, CurrentDatabaseName);

                        //*****
                        directoryPath = FileName.Replace(splitedArray[splitedArray.Length - 1], "");//Directory.GetCurrentDirectory();
                        ResultViewModel rv = (ResultViewModel)resultControl.result;//DataContext;
                        rv.directoryPath = directoryPath;
                        //*********

                        tabItem.Content = resultControl;
                        //LoadAllCustomQueryTabs(loadedQuery, rv._getResultByTreeView);
                        LoadAllCustomQueryCntrls(rv.QueryBulder, rv._getResultByTreeView, resultControl);
                        Mouse.OverrideCursor = null;
                        //if (DocPanelCustomQuery.HorizontalAlignment != HorizontalAlignment.Right)
                        //{
                        //    MiniMizeCustomeQyeryWindow();
                        //}
                    }
                }
            }
        }
        private void New_Click()
        {
            /******************************/
            this.Logo.Visibility = Visibility.Hidden;
            this.LogoTxt.Visibility = Visibility.Hidden;
            this.tabControl1.Visibility = Visibility.Visible;
            /******************************/

            count = 0;
            //addd new tab
            CloseableTabItem tabItem = new CloseableTabItem();
            tabItem.Name = "CustomQuery" + (this.tabControl1.Items.Count + 1).ToString();
            tabItem.Header = "SQLQuery" + (this.tabControl1.Items.Count + 1).ToString();
            tabItem.Part_Label_Content = "";
            //tableViewModel tvm = null;
            currentTableViewModel = null;
            Control.ResultViewControl rvCntrl = new ResultViewControl(currentTableViewModel, false);
            tabItem.Content = rvCntrl;

            //add tab to tabcontrol
            this.tabControl1.Items.Add(tabItem);
            //Clear Custom QueryTabs

            //ClearAllCustomeQueryTabs();

            //Get focus on new tab
            ((TabItem)(this.tabControl1.Items[this.tabControl1.Items.Count - 1])).Focus();

            //this.adornedControl.IsAdornerVisible = true;

            //Display Custom query window
            //DocPanelCustomQuery.HorizontalAlignment = HorizontalAlignment.Right;
            //DocPanelCustomQuery.HorizontalAlignment = HorizontalAlignment.Stretch;
            //DocPanelCustomQuery.Margin = new Thickness(0, 60, 0, 0);
            //DocPanelCustomQuery.Width = Double.NaN;
            //this.BtnHideCustomQueryWindow.Visibility = System.Windows.Visibility.Hidden;
            //Hide if tree view window open
            //if (this.TreeViewDocPanel.Width != 0)
            //{
            //    this.TreeViewDocPanel.Width = 0;
            //    TreeViewHideStackPanel.Width = 20;
            //}
        }