Skip to main content
deleted 56 characters in body; edited tags; edited title
Source Link
200_success
  • 144.2k
  • 22
  • 188
  • 473

C# Class Design Mastering OOP App to manage a football tournament database

Could Youyou help me learn iswhether this this is good, and if I'm designing my class in the proper way?

So here is my current version. (Sorry if it's too big)

// Main class that i'm trying to model in such way to be a conceptual model of my real SQL Database (FootballProject Database).
public class fp_Database
{
    // Virtual DB.
    public static DataSet DS = new DataSet();    

    // Construtor.
    public fp_Database()
    {
        DS.Tables.Add("Seassons");
        DS.Tables.Add("Countries");
        DS.Tables.Add("Tournaments");
        DS.Tables.Add("TeamsAllowed");
        DS.Tables.Add("Matches");

        Tables = new fp_Tables();
    }


    // Public Object fp_Tables containing the fp_Database tables.
    public fp_Tables Tables;

    // fp_Tables Class definition.
    public class fp_Tables
    {

        // Instantiating all the Databases tables.
        public tableMatches Matches = new tableMatches();
        public tableSeassons Seassons = new tableSeassons();
        public tableCountries Countries = new tableCountries();
        public tableTournaments Tournaments = new tableTournaments();


        // Definition of all the fp_Tables Classes.
        public class tableSeassons
        {
            public DataTable Get_Table
            {
                get
                {
                    return DS.Tables["Seassons"];
                }
            }

            public tableSeassons()
            {
                DatabaseInterface DBInterface = new DatabaseInterface();
                SqlCommand CMD = new SqlCommand("SELECT * FROM fp.Seassons");

                DBInterface.GetTable(DS.Tables["Seassons"], CMD);
            }
        }
        public class tableCountries
        {
            public DataTable Get_Table
            {
                get
                {
                    return DS.Tables["Countries"];
                }
            }

            public tableCountries()
            {
                DatabaseInterface DBInterface = new DatabaseInterface();
                SqlCommand CMD = new SqlCommand("SELECT * FROM fp.Countries");

                DBInterface.GetTable(DS.Tables["Countries"], CMD);
            }
        }
        public class tableTournaments
        {
            public DataTable Get_Table
            {
                get
                {
                    return DS.Tables["Tournaments"];
                }
            }

            public void Set_Filters(int Seasson, int Country)
            {
                DS.Tables["Tournaments"].DefaultView.RowFilter = "Seasson = " + Seasson + " AND Country = " + Country;
            }

            public tableTournaments()
            {
                DatabaseInterface DBInterface = new DatabaseInterface();
                SqlCommand CMD = new SqlCommand("SELECT * FROM fp.Tournaments ORDER BY Tournament");

                DBInterface.GetTable(DS.Tables["Tournaments"], CMD);
            }
        }
        public class tableMatches
        {
            public DataTable Get_Table
            {
                get
                {
                    return DS.Tables["Matches"];
                }
            }

            public void Load_Table_By_Tournament(int TournamentID)
            {
                DatabaseInterface DBInterface = new DatabaseInterface();
                SqlCommand CMD = new SqlCommand("SELECT * FROM fp.Matches WHERE Tournament = " + TournamentID);

                DS.Tables["Matches"].Clear();
                DBInterface.GetTable(DS.Tables["Matches"], CMD);
            }
        }
    }
}


  
// DATA ACCESS LAYER. (SELECT - INSERT - UPDATE - DELETE)
class DatabaseInterface
{
    // Latter i will learn how to save the connection string into app.config file and read from int too.    
    private SqlConnection Conn = new SqlConnection("Data Source=DESKTOP-8MGVKID\\MSSQLSERVER2016;Initial Catalog=FootballProject;Integrated Security=True");


    // Select Method.
    public void GetTable (DataTable Table, SqlCommand SQLCommand)
    {
        SqlDataAdapter DA = new SqlDataAdapter(SQLCommand.CommandText, Conn);

        Conn.Open();
        DA.Fill(Table);
        Conn.Close();
    }

    // Here will be Insert Method

    // Here will be Update Method.

    // Here will be Delete Method
}

C# Class Design Mastering OOP

Could You help me learn is this is good, and if I'm designing my class in the proper way?

So here is my current version. (Sorry if it's too big)

// Main class that i'm trying to model in such way to be a conceptual model of my real SQL Database (FootballProject Database).
public class fp_Database
{
    // Virtual DB.
    public static DataSet DS = new DataSet();    

    // Construtor.
    public fp_Database()
    {
        DS.Tables.Add("Seassons");
        DS.Tables.Add("Countries");
        DS.Tables.Add("Tournaments");
        DS.Tables.Add("TeamsAllowed");
        DS.Tables.Add("Matches");

        Tables = new fp_Tables();
    }


    // Public Object fp_Tables containing the fp_Database tables.
    public fp_Tables Tables;

    // fp_Tables Class definition.
    public class fp_Tables
    {

        // Instantiating all the Databases tables.
        public tableMatches Matches = new tableMatches();
        public tableSeassons Seassons = new tableSeassons();
        public tableCountries Countries = new tableCountries();
        public tableTournaments Tournaments = new tableTournaments();


        // Definition of all the fp_Tables Classes.
        public class tableSeassons
        {
            public DataTable Get_Table
            {
                get
                {
                    return DS.Tables["Seassons"];
                }
            }

            public tableSeassons()
            {
                DatabaseInterface DBInterface = new DatabaseInterface();
                SqlCommand CMD = new SqlCommand("SELECT * FROM fp.Seassons");

                DBInterface.GetTable(DS.Tables["Seassons"], CMD);
            }
        }
        public class tableCountries
        {
            public DataTable Get_Table
            {
                get
                {
                    return DS.Tables["Countries"];
                }
            }

            public tableCountries()
            {
                DatabaseInterface DBInterface = new DatabaseInterface();
                SqlCommand CMD = new SqlCommand("SELECT * FROM fp.Countries");

                DBInterface.GetTable(DS.Tables["Countries"], CMD);
            }
        }
        public class tableTournaments
        {
            public DataTable Get_Table
            {
                get
                {
                    return DS.Tables["Tournaments"];
                }
            }

            public void Set_Filters(int Seasson, int Country)
            {
                DS.Tables["Tournaments"].DefaultView.RowFilter = "Seasson = " + Seasson + " AND Country = " + Country;
            }

            public tableTournaments()
            {
                DatabaseInterface DBInterface = new DatabaseInterface();
                SqlCommand CMD = new SqlCommand("SELECT * FROM fp.Tournaments ORDER BY Tournament");

                DBInterface.GetTable(DS.Tables["Tournaments"], CMD);
            }
        }
        public class tableMatches
        {
            public DataTable Get_Table
            {
                get
                {
                    return DS.Tables["Matches"];
                }
            }

            public void Load_Table_By_Tournament(int TournamentID)
            {
                DatabaseInterface DBInterface = new DatabaseInterface();
                SqlCommand CMD = new SqlCommand("SELECT * FROM fp.Matches WHERE Tournament = " + TournamentID);

                DS.Tables["Matches"].Clear();
                DBInterface.GetTable(DS.Tables["Matches"], CMD);
            }
        }
    }
}


 // DATA ACCESS LAYER. (SELECT - INSERT - UPDATE - DELETE)
class DatabaseInterface
{
    // Latter i will learn how to save the connection string into app.config file and read from int too.    
    private SqlConnection Conn = new SqlConnection("Data Source=DESKTOP-8MGVKID\\MSSQLSERVER2016;Initial Catalog=FootballProject;Integrated Security=True");


    // Select Method.
    public void GetTable (DataTable Table, SqlCommand SQLCommand)
    {
        SqlDataAdapter DA = new SqlDataAdapter(SQLCommand.CommandText, Conn);

        Conn.Open();
        DA.Fill(Table);
        Conn.Close();
    }

    // Here will be Insert Method

    // Here will be Update Method.

    // Here will be Delete Method
}

App to manage a football tournament database

Could you help me learn whether this this is good, and if I'm designing my class in the proper way?

// Main class that i'm trying to model in such way to be a conceptual model of my real SQL Database (FootballProject Database).
public class fp_Database
{
    // Virtual DB.
    public static DataSet DS = new DataSet();    

    // Construtor.
    public fp_Database()
    {
        DS.Tables.Add("Seassons");
        DS.Tables.Add("Countries");
        DS.Tables.Add("Tournaments");
        DS.Tables.Add("TeamsAllowed");
        DS.Tables.Add("Matches");

        Tables = new fp_Tables();
    }


    // Public Object fp_Tables containing the fp_Database tables.
    public fp_Tables Tables;

    // fp_Tables Class definition.
    public class fp_Tables
    {

        // Instantiating all the Databases tables.
        public tableMatches Matches = new tableMatches();
        public tableSeassons Seassons = new tableSeassons();
        public tableCountries Countries = new tableCountries();
        public tableTournaments Tournaments = new tableTournaments();


        // Definition of all the fp_Tables Classes.
        public class tableSeassons
        {
            public DataTable Get_Table
            {
                get
                {
                    return DS.Tables["Seassons"];
                }
            }

            public tableSeassons()
            {
                DatabaseInterface DBInterface = new DatabaseInterface();
                SqlCommand CMD = new SqlCommand("SELECT * FROM fp.Seassons");

                DBInterface.GetTable(DS.Tables["Seassons"], CMD);
            }
        }
        public class tableCountries
        {
            public DataTable Get_Table
            {
                get
                {
                    return DS.Tables["Countries"];
                }
            }

            public tableCountries()
            {
                DatabaseInterface DBInterface = new DatabaseInterface();
                SqlCommand CMD = new SqlCommand("SELECT * FROM fp.Countries");

                DBInterface.GetTable(DS.Tables["Countries"], CMD);
            }
        }
        public class tableTournaments
        {
            public DataTable Get_Table
            {
                get
                {
                    return DS.Tables["Tournaments"];
                }
            }

            public void Set_Filters(int Seasson, int Country)
            {
                DS.Tables["Tournaments"].DefaultView.RowFilter = "Seasson = " + Seasson + " AND Country = " + Country;
            }

            public tableTournaments()
            {
                DatabaseInterface DBInterface = new DatabaseInterface();
                SqlCommand CMD = new SqlCommand("SELECT * FROM fp.Tournaments ORDER BY Tournament");

                DBInterface.GetTable(DS.Tables["Tournaments"], CMD);
            }
        }
        public class tableMatches
        {
            public DataTable Get_Table
            {
                get
                {
                    return DS.Tables["Matches"];
                }
            }

            public void Load_Table_By_Tournament(int TournamentID)
            {
                DatabaseInterface DBInterface = new DatabaseInterface();
                SqlCommand CMD = new SqlCommand("SELECT * FROM fp.Matches WHERE Tournament = " + TournamentID);

                DS.Tables["Matches"].Clear();
                DBInterface.GetTable(DS.Tables["Matches"], CMD);
            }
        }
    }
}
 
// DATA ACCESS LAYER. (SELECT - INSERT - UPDATE - DELETE)
class DatabaseInterface
{
    // Latter i will learn how to save the connection string into app.config file and read from int too.    
    private SqlConnection Conn = new SqlConnection("Data Source=DESKTOP-8MGVKID\\MSSQLSERVER2016;Initial Catalog=FootballProject;Integrated Security=True");


    // Select Method.
    public void GetTable (DataTable Table, SqlCommand SQLCommand)
    {
        SqlDataAdapter DA = new SqlDataAdapter(SQLCommand.CommandText, Conn);

        Conn.Open();
        DA.Fill(Table);
        Conn.Close();
    }

    // Here will be Insert Method

    // Here will be Update Method.

    // Here will be Delete Method
}

Hollo my friends

I have this app that is connecting to a SQL server, retrieving some tables, the user works on the data, and then it updates the data basedatabase.

I should say that all that iI know iI learned on my own (youtube and reading) but there's still a lot of stuff that makes me confuseconfused though.

So for what iI have been seen, the best approach for my project is to create a class that encapsulates (nice word by the way) this model iI just discribeddescribed.

I allreadyalready have a version working very fine, but the code it'sis all mergemerged into the interface layer. (By working very fine iI mean. that I already can retrieve the data from the database, i then can work on the tables, and then i can update the database too.)

But i fell like i'm achevingI'm achieving this in a very rudimentarrudimentary way. Now i'mI'm trying to make it more harmonious and well disigneddesigned. Trying to master my code a bit more iI guess.

So here is what i achieve untillI am achieving now based on the "Class" theory and OOP.

Could You help me? Tell me if i'm doing it learn is this is good? I'm not sure, and if i'mI'm designing my class in the proper way.?

So here is the newmy current version that i'm making now. (Sorry if it's too big)

Hollo my friends

I have this app that is connecting to a SQL server, retrieving some tables, the user works on the data, and then it updates the data base.

I should say that all that i know i learned on my own (youtube and reading) but there's a lot of stuff that makes me confuse though.

So for what i have been seen, the best approach for my project is to create a class that encapsulates (nice word by the way) this model i just discribed.

I allready have a version working very fine, but the code it's all merge into the interface layer. (By working very fine i mean. I already can retrieve the data from the database, i then can work on the tables, and then i can update the database too)

But i fell like i'm acheving this in a very rudimentar way. Now i'm trying to make it more harmonious and well disigned. Trying to master my code a bit more i guess.

So here is what i achieve untill now based on the "Class" theory and OOP.

Could You help me? Tell me if i'm doing it good? I'm not sure if i'm designing my class in the proper way.

So here is the new version that i'm making now. (Sorry if it's too big)

I have this app that is connecting to a SQL server, retrieving some tables, the user works on the data, and then it updates the database.

I should say that all that I know I learned on my own (youtube and reading) but there's still a lot of stuff that makes me confused though.

So for what I have seen, the best approach for my project is to create a class that encapsulates (nice word by the way) this model I just described.

I already have a version working very fine, but the code is all merged into the interface layer. (By working very fine I mean that I can retrieve the data from the database, work on the tables, and then update the database.)

But i fell like I'm achieving this in a very rudimentary way. Now I'm trying to make it more harmonious and well designed. Trying to master my code a bit more I guess.

So here is what I am achieving now based on the "Class" theory and OOP.

Could You help me learn is this is good, and if I'm designing my class in the proper way?

So here is my current version. (Sorry if it's too big)

Source Link

C# Class Design Mastering OOP

Hollo my friends

My question is all about class design.

I have this app that is connecting to a SQL server, retrieving some tables, the user works on the data, and then it updates the data base.

I should say that all that i know i learned on my own (youtube and reading) but there's a lot of stuff that makes me confuse though.

So for what i have been seen, the best approach for my project is to create a class that encapsulates (nice word by the way) this model i just discribed.

I allready have a version working very fine, but the code it's all merge into the interface layer. (By working very fine i mean. I already can retrieve the data from the database, i then can work on the tables, and then i can update the database too)

But i fell like i'm acheving this in a very rudimentar way. Now i'm trying to make it more harmonious and well disigned. Trying to master my code a bit more i guess.

So here is what i achieve untill now based on the "Class" theory and OOP.

Could You help me? Tell me if i'm doing it good? I'm not sure if i'm designing my class in the proper way.

So here is the new version that i'm making now. (Sorry if it's too big)

// Main class that i'm trying to model in such way to be a conceptual model of my real SQL Database (FootballProject Database).
public class fp_Database
{
    // Virtual DB.
    public static DataSet DS = new DataSet();    

    // Construtor.
    public fp_Database()
    {
        DS.Tables.Add("Seassons");
        DS.Tables.Add("Countries");
        DS.Tables.Add("Tournaments");
        DS.Tables.Add("TeamsAllowed");
        DS.Tables.Add("Matches");

        Tables = new fp_Tables();
    }


    // Public Object fp_Tables containing the fp_Database tables.
    public fp_Tables Tables;

    // fp_Tables Class definition.
    public class fp_Tables
    {

        // Instantiating all the Databases tables.
        public tableMatches Matches = new tableMatches();
        public tableSeassons Seassons = new tableSeassons();
        public tableCountries Countries = new tableCountries();
        public tableTournaments Tournaments = new tableTournaments();


        // Definition of all the fp_Tables Classes.
        public class tableSeassons
        {
            public DataTable Get_Table
            {
                get
                {
                    return DS.Tables["Seassons"];
                }
            }

            public tableSeassons()
            {
                DatabaseInterface DBInterface = new DatabaseInterface();
                SqlCommand CMD = new SqlCommand("SELECT * FROM fp.Seassons");

                DBInterface.GetTable(DS.Tables["Seassons"], CMD);
            }
        }
        public class tableCountries
        {
            public DataTable Get_Table
            {
                get
                {
                    return DS.Tables["Countries"];
                }
            }

            public tableCountries()
            {
                DatabaseInterface DBInterface = new DatabaseInterface();
                SqlCommand CMD = new SqlCommand("SELECT * FROM fp.Countries");

                DBInterface.GetTable(DS.Tables["Countries"], CMD);
            }
        }
        public class tableTournaments
        {
            public DataTable Get_Table
            {
                get
                {
                    return DS.Tables["Tournaments"];
                }
            }

            public void Set_Filters(int Seasson, int Country)
            {
                DS.Tables["Tournaments"].DefaultView.RowFilter = "Seasson = " + Seasson + " AND Country = " + Country;
            }

            public tableTournaments()
            {
                DatabaseInterface DBInterface = new DatabaseInterface();
                SqlCommand CMD = new SqlCommand("SELECT * FROM fp.Tournaments ORDER BY Tournament");

                DBInterface.GetTable(DS.Tables["Tournaments"], CMD);
            }
        }
        public class tableMatches
        {
            public DataTable Get_Table
            {
                get
                {
                    return DS.Tables["Matches"];
                }
            }

            public void Load_Table_By_Tournament(int TournamentID)
            {
                DatabaseInterface DBInterface = new DatabaseInterface();
                SqlCommand CMD = new SqlCommand("SELECT * FROM fp.Matches WHERE Tournament = " + TournamentID);

                DS.Tables["Matches"].Clear();
                DBInterface.GetTable(DS.Tables["Matches"], CMD);
            }
        }
    }
}


// DATA ACCESS LAYER. (SELECT - INSERT - UPDATE - DELETE)
class DatabaseInterface
{
    // Latter i will learn how to save the connection string into app.config file and read from int too.    
    private SqlConnection Conn = new SqlConnection("Data Source=DESKTOP-8MGVKID\\MSSQLSERVER2016;Initial Catalog=FootballProject;Integrated Security=True");


    // Select Method.
    public void GetTable (DataTable Table, SqlCommand SQLCommand)
    {
        SqlDataAdapter DA = new SqlDataAdapter(SQLCommand.CommandText, Conn);

        Conn.Open();
        DA.Fill(Table);
        Conn.Close();
    }

    // Here will be Insert Method

    // Here will be Update Method.

    // Here will be Delete Method
}