Ejemplo n.º 1
0
        //Remove a SINGLE Viewer Windows data from Flags & gv[]
        public static bool DeleteViewerAndFlags(int index = -1, string currentDb = "")
        {
            int         x = index;
            SqlDbViewer sqlv;                                    // x = GridView[] index if received

            if (Flags.CurrentSqlViewer == null)
            {
                return(false);
            }
            Guid        tag = ( Guid )Flags.CurrentSqlViewer?.Tag;
            ListBoxItem lbi = new ListBoxItem( );

            if (x == -1)
            {             // Delete all
                for (int z = 0; z < MainWindow.gv.MaxViewers; z++)
                {
                    DbSelector.UpdateControlFlags(null, null, MainWindow.gv.PrettyDetails);
                    MainWindow.gv.CurrentDb [z] = "";
                    MainWindow.gv.ListBoxId [z] = Guid.Empty;
                    MainWindow.gv.Datagrid [z]  = null;
                    MainWindow.gv.window [z]    = null;
                }
                MainWindow.gv.ViewerCount     = 0;
                MainWindow.gv.PrettyDetails   = "";
                MainWindow.gv.SqlBankViewer   = null;
                MainWindow.gv.SqlCustViewer   = null;
                MainWindow.gv.SqlDetViewer    = null;
                MainWindow.gv.SqlViewerGuid   = Guid.Empty;
                MainWindow.gv.SqlViewerWindow = null;

                MainWindow.gv.Bankviewer = Guid.Empty;
                MainWindow.gv.Custviewer = Guid.Empty;
                MainWindow.gv.Detviewer  = Guid.Empty;

                Flags.ActiveSqlGrid = null;
                Flags.SqlBankViewer = null;
                Flags.SqlCustViewer = null;
                Flags.SqlDetViewer  = null;
//				Flags . CurrentSqlViewer = null;

                // ALL entries in our GridView structure are now cleared  ** totally **
                return(true);
            }
            else
            {
                int GridViewerArrayIndex = 0;
                // we may have NOT received the index of the viewer in the list
                // so  get the index for the correct Entry
                if (x == 99)
                {
                    // got to find it ourselves - iterate thruMainWindow.gv[] array  (Range  is 0 - 3)
                    for (int i = 0; i < 3; i++)
                    {
                        if (MainWindow.gv.CurrentDb [i] == currentDb)
                        {
                            x = i; break;
                        }
                    }
                    GridViewerArrayIndex = x;
                    // we have got the index in "x"  of the viewer in the Mainindow.gv[] array
                    // so  get the Tag of that selected Entry vin the ViewersList
                    for (int i = 1; i < 4; i++)
                    {
                        lbi = Flags.DbSelectorOpen.ViewersList.Items [i] as ListBoxItem;
                        if (MainWindow.gv.ListBoxId [GridViewerArrayIndex] == ( Guid )lbi.Tag)
                        {
                            //lbi = Flags . DbSelectorOpen . ViewersList . Items [ i ] as ListBoxItem;
                            Flags.DbSelectorOpen.ViewersList.Items.RemoveAt(i);
                            Flags.DbSelectorOpen.ViewersList.Refresh( );
                            break;
                        }
                    }
                }
                else
                {
                    // we have the ViewersList index given to us, so use it
                    lbi = Flags.DbSelectorOpen.ViewersList.Items [index] as ListBoxItem;
                    Flags.DbSelectorOpen.ViewersList.Items.RemoveAt(index);
                    Flags.DbSelectorOpen.ViewersList.Refresh( );
                    // got to findit in thruMainWindow.gv[] array  (Range  is 0 - 3)
                    for (int i = 0; i < 4; i++)
                    {
                        if (MainWindow.gv.ListBoxId [i] == ( Guid )lbi.Tag)
                        {
                            GridViewerArrayIndex = i;
                            break;
                        }
                    }
                }
                sqlv = Flags.CurrentSqlViewer as SqlDbViewer;
                sqlv.Close( );

                // We know which gv[] entry  we need to clear, so do it and return
                MainWindow.gv.CurrentDb [GridViewerArrayIndex] = "";
                MainWindow.gv.ListBoxId [GridViewerArrayIndex] = Guid.Empty;
                MainWindow.gv.Datagrid [GridViewerArrayIndex]  = null;
                MainWindow.gv.window [GridViewerArrayIndex]    = null;
                MainWindow.gv.PrettyDetails = "";
                MainWindow.gv.SqlViewerGuid = Guid.Empty;
                MainWindow.gv.ViewerCount--;
                // Reposition selected viewer if we have one
                if (Flags.DbSelectorOpen.ViewersList.Items.Count > GridViewerArrayIndex + 1)
                {
                    Flags.DbSelectorOpen.ViewersList.SelectedIndex = GridViewerArrayIndex + 1;
                    Flags.DbSelectorOpen.ViewersList.SelectedItem  = GridViewerArrayIndex + 1;
                }
                else if (Flags.DbSelectorOpen.ViewersList.Items.Count == GridViewerArrayIndex + 1)
                {
                    Flags.DbSelectorOpen.ViewersList.SelectedIndex = GridViewerArrayIndex - 1;
                    Flags.DbSelectorOpen.ViewersList.SelectedItem  = GridViewerArrayIndex - 1;
                }
                return(true);
            }

            // Unreachable code ...

            // Now sort out the  global gv[] flags
            for (int y = 1; y < Flags.DbSelectorOpen.ViewersList.Items.Count; y++)
            {
                // Get the Tag of eaxch Viewer in the list
                lbi = Flags.DbSelectorOpen.ViewersList.Items [y] as ListBoxItem;
                Guid lbtag = ( Guid )lbi.Tag;
                //See if it matches the one we are closing down
                if (( Guid )lbtag == ( Guid )tag)
                {
                    //Yes, we have got a match, so go ahead and remove its gv[] entries first
                    for (int z = 0; z < MainWindow.gv.MaxViewers; z++)
                    {
                        if (MainWindow.gv.ListBoxId [z] == lbtag)
                        {
                            MainWindow.gv.ViewerCount--;
                            MainWindow.gv.CurrentDb [z] = "";
                            MainWindow.gv.ListBoxId [z] = Guid.Empty;
                            MainWindow.gv.Datagrid [z]  = null;
                            MainWindow.gv.window [z]    = null;
                            break;
                        }
                    }
                    MainWindow.gv.PrettyDetails = "";
                    //Finally we can remove this entry from ViewersList
                    lbi         = Flags.DbSelectorOpen.ViewersList.Items [y] as ListBoxItem;
                    lbi.Content = "";
                    Flags.DbSelectorOpen.ViewersList.Items.RemoveAt(y);
                    // Set selectedIndex pointer to current position in list
                    int currentIndex = y - 1;
                    if (y <= 1)                                   // List is basically empty (No viewers in  the list)
                    {
                        return(true);
                    }
                    if (Flags.DbSelectorOpen.ViewersList.Items.Count > currentIndex)
                    {
                        Flags.DbSelectorOpen.ViewersList.SelectedIndex = currentIndex;
                        Flags.DbSelectorOpen.ViewersList.SelectedItem  = currentIndex;
                    }
                    else if (Flags.DbSelectorOpen.ViewersList.Items.Count == currentIndex)
                    {
                        Flags.DbSelectorOpen.ViewersList.SelectedIndex = currentIndex - 1;
                        Flags.DbSelectorOpen.ViewersList.SelectedItem  = currentIndex - 1;
                    }
                    return(true);
                }
            }
            MainWindow.gv.SqlViewerGuid = Guid.Empty;

            return(false);
        }