1

在此处输入图像描述我在使用 TreeView 过滤器时遇到问题,因为所选国家/地区需要将 Discipline 列入他们可能未分配给国家和所有学科的事件列表。我正在考虑下载父节点,但我没有找到这样的选项。XAML 代码的一部分:

<TreeView X:Name="drzewo" Height="380" width="280" MouseDoubleClick="drzewo_MouseDoubleClick"/>

方法 drzewo_MouseDoubleClick C#:

private void drzewo_MouseDoubleClick ( object sender , MouseButtonEventArgs e)
        {
            TreeView v = e.Source as TreeView ;
            string str = v.SelectedValue.ToString ();
            drzewo_klik = str.Substring (46, str.IndexOf ( " Items.Count " ) -47 ) ;

            for (int i = 0; i < listadyscyplina.Count , i + + )
            {
                    if ( listadyscyplina.Contains ( drzewo_klik ) )
                    {
                        flagadyscyplina = true;
                        drzewo_dyscyplina = drzewo_klik ;
                        break;
                    }
            }
            
            for (int i = 0; i < listakontynent.Count , i + + )
            {
                if ( listakontynent.Contains ( drzewo_klik ) )
                {
                    flagakontynent = true;
                    drzewo_kontynent = drzewo_klik ;
                    break;
                }
            }

            for (int i = 0; i < listakraj.Count , i + + )
            {
                if ( listakraj.Contains ( drzewo_klik ) )
                {
                    flagakraj = true;
                    drzewo_kraj = drzewo_klik ;
                    break;
                }
            }


            for (int i = 0; i < listalig.Count , i + + )
            {
                if ( listalig.Contains ( drzewo_klik ) )
                {
                    flagaliga = true;
                    drzewo_liga = drzewo_klik ;
                    break;
                }
            }

            sort ();
        }
 

                    listadyscyplina、listakontynent、listakraj 和 listalig 是从数据库中提取的所有学科、大洲、国家和联赛的列表。

C#排序方法:

private void sort ( )
        {
            ZdarzeniaDataGrid.ItemsSource = null;
            dataSource3.Clear ();
            
            if ( flagaliga == true && flagasystem == true && flagakraj == true && flagadyscyplina == true && flagakontynent == true)
                sort1 ();
            else if ( flagasystem == true && flagakraj == true && flagadyscyplina == true && flagakontynent == true)
                sort2 ();
            else if ( flagakraj == true && flagadyscyplina == true && flagakontynent == true)
                sort3 ();
            else if ( flagadyscyplina == true && flagakontynent == true)
                sort4 ();
            else if ( flagadyscyplina == true)
                sort5 ();

            ZdarzeniaDataGrid.Items.Refresh ();
            ZdarzeniaDataGrid.ItemsSource = dataSource3 ;
        }

sort1 到 sort5 的方法 C#

  

private void sort2 ( )
        {
            licznikz int = 0;
            using ( SqlConnection conn = new SqlConnection ( "Data Source = ADAM_LAPTOP ; Integrated Security = true; Database = astruzik " ) )
            {
                SqlCommand command = new SqlCommand ( "select IdKlubu , IdKlubu2 from event where IdLigi = (select IdLigi from League where ( Name = ' " + drzewo_liga + " ' AND IdDyscypliny = (select IdDyscypliny from discipline where name = ' " + drzewo_dyscyplina + "' ) AND IdKraju = (SELECT IdKraju FROM Country WHERE Name = ' "+ drzewo_kraj + " ') AND SystemRozgrywek = ' "+ drzewo_system +"' AND ( Season = '2013 'OR Season = '2013 / 2014 ' ) )) " conn) ;
                SqlDataAdapter adapter = new SqlDataAdapter ( command ) ;
                dss5 = new DataSet ();
                adapter.Fill ( dss5 , "Event" ) ;
            }
            licznikz = dss5.Tables [ "Event" ] . Rows.Count ;
            DataRow napis6 = null;
            DataRow napis1 = null;
            DataRow napis2 = null;
            DataSet DSSS = null;
            for ( int n = 0, n < licznikz n + + )
            {
                napis6 = dss5.Tables [ "Event" ] . Rows [n ] ;
                using ( SqlConnection conn = new SqlConnection ( "Data Source = ADAM_LAPTOP ; Integrated Security = true; Database = astruzik " ) )
                {
                    SqlCommand command = new SqlCommand ( "select name from Club where IdKlubu = ' " + napis6.ItemArray.GetValue (0) . ToString ( ) + "' ", conn) ;
                    SqlDataAdapter adapter = new SqlDataAdapter ( command ) ;
                    DSSS = new DataSet ();
                    adapter.Fill ( DSSS , " Club ");
                }
                napis1 = dsss.Tables [" Club "] . Rows [0] ;
                using ( SqlConnection conn = new SqlConnection ( "Data Source = ADAM_LAPTOP ; Integrated Security = true; Database = astruzik " ) )
                {
                    SqlCommand command = new SqlCommand ( "select name from Club where IdKlubu = ' " + napis6.ItemArray.GetValue ( 1). ToString ( ) + "' ", conn) ;
                    SqlDataAdapter adapter = new SqlDataAdapter ( command ) ;
                    DSSS = new DataSet ();
                    adapter.Fill ( DSSS , " Club ");
                }
                napis2 = dsss.Tables [" Club "] . Rows [0] ;


                for (int i = 0; i < dataSource.Count , i + + )
                {
                    if ( dataSource [i] . NazwaLigi.Contains ( napis.ItemArray.GetValue (0) . ToString ( ) ) && dataSource [i] . Gospodarze.Contains ( napis1.ItemArray.GetValue (0) . ToString ( ) ) && dataSource [ i] . Goście.Contains ( napis2.ItemArray.GetValue (0) . ToString ( )))
                    {
                        dataSource3.Add ( dataSource [i] ) ;
                    }
                }

            }
        }

        private void sort1 ( )
        {
            licznikz int = 0;
            using ( SqlConnection conn = new SqlConnection ( "Data Source = ADAM_LAPTOP ; Integrated Security = true; Database = astruzik " ) )
            {
                SqlCommand command = new SqlCommand ( "select IdKlubu , IdKlubu2 from event where IdLigi = (select IdLigi from League where ( Name = ' " + drzewo_liga + " ' AND IdDyscypliny = (select IdDyscypliny from discipline where name = ' " + drzewo_dyscyplina + "' ) AND IdKraju = (SELECT IdKraju FROM Country WHERE Name = ' "+ drzewo_kraj + " ') AND (Season = '2013 'OR Season = '2013 / 2014 ' ))) " , conn) ;
                SqlDataAdapter adapter = new SqlDataAdapter ( command ) ;
                dss5 = new DataSet ();
                adapter.Fill ( dss5 , "Event" ) ;
            }
            licznikz = dss5.Tables [ "Event" ] . Rows.Count ;
            DataRow napis6 = null;
            DataRow napis1 = null;
            DataRow napis2 = null;
            DataSet DSSS = null;
            for ( int n = 0, n < licznikz n + + )
            {
                napis6 = dss5.Tables [ "Event" ] . Rows [n ] ;
                using ( SqlConnection conn = new SqlConnection ( "Data Source = ADAM_LAPTOP ; Integrated Security = true; Database = astruzik " ) )
                {
                    SqlCommand command = new SqlCommand ( "select name from Club where IdKlubu = ' " + napis6.ItemArray.GetValue (0) . ToString ( ) + "' ", conn) ;
                    SqlDataAdapter adapter = new SqlDataAdapter ( command ) ;
                    DSSS = new DataSet ();
                    adapter.Fill ( DSSS , " Club ");
                }
                napis1 = dsss.Tables [" Club "] . Rows [0] ;
                using ( SqlConnection conn = new SqlConnection ( "Data Source = ADAM_LAPTOP ; Integrated Security = true; Database = astruzik " ) )
                {
                    SqlCommand command = new SqlCommand ( "select name from Club where IdKlubu = ' " + napis6.ItemArray.GetValue ( 1). ToString ( ) + "' ", conn) ;
                    SqlDataAdapter adapter = new SqlDataAdapter ( command ) ;
                    DSSS = new DataSet ();
                    adapter.Fill ( DSSS , " Club ");
                }
                napis2 = dsss.Tables [" Club "] . Rows [0] ;


                for (int i = 0; i < dataSource.Count , i + + )
                {
                    if ( dataSource [i] . NazwaLigi.Contains ( napis.ItemArray.GetValue (0) . ToString ( ) ) && dataSource [i] . Gospodarze.Contains ( napis1.ItemArray.GetValue (0) . ToString ( ) ) && dataSource [ i] . Goście.Contains ( napis2.ItemArray.GetValue (0) . ToString ( )))
                    {
                        dataSource3.Add ( dataSource [i] ) ;
                    }
                }

            }
        }
        private void sort3 ( )
        {
                int count = 0 ;

                using ( SqlConnection conn = new SqlConnection ( "Data Source = ADAM_LAPTOP ; Integrated Security = true; Database = astruzik " ) )
                {
                    SqlCommand command = new SqlCommand ( "select name from League where ( IdDyscypliny = (select IdDyscypliny from discipline where name = ' " + drzewo_dyscyplina + " ') AND IdKraju = (SELECT IdKraju FROM Country WHERE Name = ' " + drzewo_kraj + "' ) ) ", conn) ;
                    SqlDataAdapter adapter = new SqlDataAdapter ( command ) ;
                    ds = new DataSet ();
                    adapter.Fill (ds , "The League ");
                }
                count = ds.Tables [ "The League "] . Rows.Count ;
                DataRow caption = null;
                for (int k = 0 , k < count; k + + )
                {
                    caption = ds.Tables [ "The League "] . Rows [ k] ;
                    licznikz int = 0;
                    using ( SqlConnection conn = new SqlConnection ( "Data Source = ADAM_LAPTOP ; Integrated Security = true; Database = astruzik " ) )
                    {
                        SqlCommand command = new SqlCommand ( "select IdKlubu , IdKlubu2 from event where IdLigi = (select IdLigi from League where ( Name = ' " + napis.ItemArray.GetValue (0) . ToString ( ) + " ' AND IdDyscypliny = (select IdDyscypliny from discipline WHERE name = ' "+ drzewo_dyscyplina + " ') AND IdKraju = (SELECT IdKraju FROM Country WHERE Name = ' "+ drzewo_kraj + " ') AND (Season = '2013 'OR Season = '2013 / 2014 ' ))) " , conn) ;
                        SqlDataAdapter adapter = new SqlDataAdapter ( command ) ;
                        dss5 = new DataSet ();
                        adapter.Fill ( dss5 , "Event" ) ;
                    }
                    licznikz = dss5.Tables [ "Event" ] . Rows.Count ;
                    DataRow napis6 = null;
                    DataRow napis1 = null;
                    DataRow napis2 = null;
                    DataSet DSSS = null;
                    for ( int n = 0, n < licznikz n + + )
                    {
                        napis6 = dss5.Tables [ "Event" ] . Rows [n ] ;
                        using ( SqlConnection conn = new SqlConnection ( "Data Source = ADAM_LAPTOP ; Integrated Security = true; Database = astruzik " ) )
                        {
                            SqlCommand command = new SqlCommand ( "select name from Club where IdKlubu = ' " + napis6.ItemArray.GetValue (0) . ToString ( ) + "' ", conn) ;
                            SqlDataAdapter adapter = new SqlDataAdapter ( command ) ;
                            DSSS = new DataSet ();
                            adapter.Fill ( DSSS , " Club ");
                        }
                        napis1 = dsss.Tables [" Club "] . Rows [0] ;
                        using ( SqlConnection conn = new SqlConnection ( "Data Source = ADAM_LAPTOP ; Integrated Security = true; Database = astruzik " ) )
                        {
                            SqlCommand command = new SqlCommand ( "select name from Club where IdKlubu = ' " + napis6.ItemArray.GetValue ( 1). ToString ( ) + "' ", conn) ;
                            SqlDataAdapter adapter = new SqlDataAdapter ( command ) ;
                            DSSS = new DataSet ();
                            adapter.Fill ( DSSS , " Club ");
                        }
                        napis2 = dsss.Tables [" Club "] . Rows [0] ;


                        for (int i = 0; i < dataSource.Count , i + + )
                        {
                            if ( dataSource [i] . NazwaLigi.Contains ( napis.ItemArray.GetValue (0) . ToString ( ) ) && dataSource [i] . Gospodarze.Contains ( napis1.ItemArray.GetValue (0) . ToString ( ) ) && dataSource [ i] . Goście.Contains ( napis2.ItemArray.GetValue (0) . ToString ( )))
                            {
                                dataSource3.Add ( dataSource [i] ) ;
                            }
                        }

                    }
                }
            }

        private void sort4 ( )
        {
            DataSet dsx = null;
            licznikx int = 0;
            using ( SqlConnection CONNX = new SqlConnection ( "Data Source = ADAM_LAPTOP ; Integrated Security = true; Database = astruzik " ) )
            {
                Poleceniex SqlCommand = new SqlCommand ( "select name from country where IdKontynentu = (select IdKontynentu from Continent where name = ' " + drzewo_kontynent + "' ) ", CONNX ) ;
                Adapterx SqlDataAdapter = new SqlDataAdapter ( poleceniex ) ;
                dsx = new DataSet ();
                adapterx.Fill ( dsx , "Country ");
            }
            licznikx = dsx.Tables [ "Country "] . Rows.Count ;
            DataRow napisx = null;
            for (int j = 0; j < licznikx j + + )
            {
                napisx = dsx.Tables [ "Country "] . Rows [i ] ;
                int count = 0 ;

                using ( SqlConnection conn = new SqlConnection ( "Data Source = ADAM_LAPTOP ; Integrated Security = true; Database = astruzik " ) )
                {
                    SqlCommand command = new SqlCommand ( "select name from League where ( IdDyscypliny = (select IdDyscypliny from discipline where name = ' " + drzewo_dyscyplina + " ') AND IdKraju = (SELECT IdKraju FROM Country WHERE Name = ' " + napisx.ItemArray.GetValue (0) . ToString ( ) + " ')) ", conn) ;
                    SqlDataAdapter adapter = new SqlDataAdapter ( command ) ;
                    ds = new DataSet ();
                    adapter.Fill (ds , "The League ");
                }
                count = ds.Tables [ "The League "] . Rows.Count ;
                DataRow caption = null;
                for (int k = 0 , k < count; k + + )
                {
                    caption = ds.Tables [ "The League "] . Rows [ k] ;
                    licznikz int = 0;
                    using ( SqlConnection conn = new SqlConnection ( "Data Source = ADAM_LAPTOP ; Integrated Security = true; Database = astruzik " ) )
                    {
                        SqlCommand command = new SqlCommand ( "select IdKlubu , IdKlubu2 from event where IdLigi = (select IdLigi from League where ( Name = ' " + napis.ItemArray.GetValue (0) . ToString ( ) + " ' AND IdDyscypliny = (select IdDyscypliny from discipline WHERE name = ' "+ drzewo_dyscyplina + " ') AND IdKraju = (SELECT IdKraju FROM Country WHERE Name = ' "+ napisx.ItemArray.GetValue (0) . ToString ( ) +" ') AND (Season = '2013 'OR season = '2013 / 2014 ' ))) " , conn) ;
                        SqlDataAdapter adapter = new SqlDataAdapter ( command ) ;
                        dss5 = new DataSet ();
                        adapter.Fill ( dss5 , "Event" ) ;
                    }
                    licznikz = dss5.Tables [ "Event" ] . Rows.Count ;
                    DataRow napis6 = null;
                    DataRow napis1 = null;
                    DataRow napis2 = null;
                    DataSet DSSS = null;
                    for ( int n = 0, n < licznikz n + + )
                    {
                        napis6 = dss5.Tables [ "Event" ] . Rows [n ] ;
                        using ( SqlConnection conn = new SqlConnection ( "Data Source = ADAM_LAPTOP ; Integrated Security = true; Database = astruzik " ) )
                        {
                            SqlCommand command = new SqlCommand ( "select name from Club where IdKlubu = ' " + napis6.ItemArray.GetValue (0) . ToString ( ) + "' ", conn) ;
                            SqlDataAdapter adapter = new SqlDataAdapter ( command ) ;
                            DSSS = new DataSet ();
                            adapter.Fill ( DSSS , " Club ");
                        }
                        napis1 = dsss.Tables [" Club "] . Rows [0] ;
                        using ( SqlConnection conn = new SqlConnection ( "Data Source = ADAM_LAPTOP ; Integrated Security = true; Database = astruzik " ) )
                        {
                            SqlCommand command = new SqlCommand ( "select name from Club where IdKlubu = ' " + napis6.ItemArray.GetValue ( 1). ToString ( ) + "' ", conn) ;
                            SqlDataAdapter adapter = new SqlDataAdapter ( command ) ;
                            DSSS = new DataSet ();
                            adapter.Fill ( DSSS , " Club ");
                        }
                        napis2 = dsss.Tables [" Club "] . Rows [0] ;


                        for (int i = 0; i < dataSource.Count , i + + )
                        {
                            if ( dataSource [i] . NazwaLigi.Contains ( napis.ItemArray.GetValue (0) . ToString ( ) ) && dataSource [i] . Gospodarze.Contains ( napis1.ItemArray.GetValue (0) . ToString ( ) ) && dataSource [ i] . Goście.Contains ( napis2.ItemArray.GetValue (0) . ToString ( )))
                            {
                                dataSource3.Add ( dataSource [i] ) ;
                            }
                        }

                    }
                }
            }
        }

        private void sort5 ( )
        {
            DataSet dsy = null;
            liczniky int = 0;
            using ( SqlConnection conny = new SqlConnection ( "Data Source = ADAM_LAPTOP ; Integrated Security = true; Database = astruzik " ) )
            {
                Poleceniey SqlCommand = new SqlCommand ( "select name from Continent ", conny ) ;
                SqlDataAdapter adapter = new SqlDataAdapter ( poleceniey ) ;
                dsy = new DataSet ();
                adaptery.Fill ( dsy , " Continent ");
            }
            liczniky = dsy.Tables [" Continent "] . Rows.Count ;
            DataRow subtitle = null;

            for ( int l = 0, l < liczniky , l + + )
            {
                Subtitles = dsy.Tables [" Continent "] . Rows [l] ;

                DataSet dsx = null;
                licznikx int = 0;
                using ( SqlConnection CONNX = new SqlConnection ( "Data Source = ADAM_LAPTOP ; Integrated Security = true; Database = astruzik " ) )
                {
                    Poleceniex SqlCommand = new SqlCommand ( "select name from country where IdKontynentu = (select IdKontynentu from Continent where name = ' " + napisy.ItemArray.GetValue (0) . ToString ( ) + " ')" , CONNX ) ;
                    Adapterx SqlDataAdapter = new SqlDataAdapter ( poleceniex ) ;
                    dsx = new DataSet ();
                    adapterx.Fill ( dsx , "Country ");
                }
                licznikx = dsx.Tables [ "Country "] . Rows.Count ;
                DataRow napisx = null;
                for (int j = 0; j < licznikx j + + )
                {
                    napisx = dsx.Tables [ "Country "] . Rows [i ] ;
                    int count = 0 ;

                    using ( SqlConnection conn = new SqlConnection ( "Data Source = ADAM_LAPTOP ; Integrated Security = true; Database = astruzik " ) )
                    {
                        SqlCommand command = new SqlCommand ( "select name from League where ( IdDyscypliny = (select IdDyscypliny from discipline where name = ' " + drzewo_dyscyplina + " ') AND IdKraju = (SELECT IdKraju FROM Country WHERE Name = ' " + napisx.ItemArray.GetValue (0) . ToString ( ) + " ')) ", conn) ;
                        SqlDataAdapter adapter = new SqlDataAdapter ( command ) ;
                        ds = new DataSet ();
                        adapter.Fill (ds , "The League ");
                    }
                    count = ds.Tables [ "The League "] . Rows.Count ;

                    DataRow caption = null;
                    for (int k = 0 , k < count; k + + )
                    {
                        caption = ds.Tables [ "The League "] . Rows [ k] ;
                        licznikz int = 0;
                        using ( SqlConnection conn = new SqlConnection ( "Data Source = ADAM_LAPTOP ; Integrated Security = true; Database = astruzik " ) )
                        {
                            SqlCommand command = new SqlCommand ( "select IdKlubu , IdKlubu2 from event where IdLigi = (select IdLigi from League where ( Name = ' " + napis.ItemArray.GetValue (0) . ToString ( ) + " ' AND IdDyscypliny = (select IdDyscypliny from discipline WHERE name = ' "+ drzewo_dyscyplina + " ') AND IdKraju = (SELECT IdKraju FROM Country WHERE Name = ' "+ napisx.ItemArray.GetValue (0) . ToString ( ) +" ') AND (Season = '2013 'OR season = '2013 / 2014 ' ))) " , conn) ;
                            SqlDataAdapter adapter = new SqlDataAdapter ( command ) ;
                            dss5 = new DataSet ();
                            adapter.Fill ( dss5 , "Event" ) ;
                        }
                        licznikz = dss5.Tables [ "Event" ] . Rows.Count ;
                        DataRow napis6 = null;
                        DataRow napis1 = null;
                        DataRow napis2 = null;
                        DataSet DSSS = null;
                        for ( int n = 0, n < licznikz n + + )
                        {
                            napis6 = dss5.Tables [ "Event" ] . Rows [n ] ;
                            using ( SqlConnection conn = new SqlConnection ( "Data Source = ADAM_LAPTOP ; Integrated Security = true; Database = astruzik " ) )
                            {
                                SqlCommand command = new SqlCommand ( "select name from Club where IdKlubu = ' " + napis6.ItemArray.GetValue (0) . ToString ( ) + "' ", conn) ;
                                SqlDataAdapter adapter = new SqlDataAdapter ( command ) ;
                                DSSS = new DataSet ();
                                adapter.Fill ( DSSS , " Club ");
                            }
                            napis1 = dsss.Tables [" Club "] . Rows [0] ;
                            using ( SqlConnection conn = new SqlConnection ( "Data Source = ADAM_LAPTOP ; Integrated Security = true; Database = astruzik " ) )
                            {
                                SqlCommand command = new SqlCommand ( "select name from Club where IdKlubu = ' " + napis6.ItemArray.GetValue ( 1). ToString ( ) + "' ", conn) ;
                                SqlDataAdapter adapter = new SqlDataAdapter ( command ) ;
                                DSSS = new DataSet ();
                                adapter.Fill ( DSSS , " Club ");
                            }
                            napis2 = dsss.Tables [" Club "] . Rows [0] ;
                        
                        
                        for (int i = 0; i < dataSource.Count , i + + )
                        {
                            if ( dataSource [i] . NazwaLigi.Contains ( napis.ItemArray.GetValue (0) . ToString ( ) ) && dataSource [i] . Gospodarze.Contains ( napis1.ItemArray.GetValue (0) . ToString ( ) ) && dataSource [ i] . Goście.Contains ( napis2.ItemArray.GetValue (0) . ToString ( )))
                            {
                                dataSource3.Add ( dataSource [i] ) ;
                            }
                        }

                        }
                    }
                }
            }
        }

dataSource3 是显示在 ZdarzeniaDataGrid 的列表 DataSource 是子列表

4

0 回答 0