示例#1
0
        public static DataTable FindD(int _id)
        {
            DataTable dt = new DataTable();
            SqlConnectionStringBuilder builder = DBconnector.GetBuilder();

            try
            {
                using (SqlConnection connection = new SqlConnection(builder.ConnectionString))
                {
                    connection.Open();

                    string sql = "SELECT * FROM Zapasy z WHERE z.z_id = @p_z_id";
                    using (SqlCommand command = new SqlCommand(sql, connection))
                    {
                        command.Parameters.AddWithValue("@p_z_id", _id);
                        using (SqlDataReader reader = command.ExecuteReader())
                        {
                            dt.Load(reader);
                        }
                    }
                }
            }

            catch { }
            return(dt);
        }
示例#2
0
        public static int getLastID()
        {
            DataTable dt = new DataTable();
            SqlConnectionStringBuilder builder = DBconnector.GetBuilder();

            try
            {
                using (SqlConnection connection = new SqlConnection(builder.ConnectionString))
                {
                    connection.Open();

                    string sql = "SELECT MAX(h_id) FROM Hraci";
                    using (SqlCommand command = new SqlCommand(sql, connection))
                    {
                        using (SqlDataReader reader = command.ExecuteReader())
                        {
                            dt.Load(reader);
                        }
                    }
                }
                return(Convert.ToInt32(dt.Rows[0][0].ToString()));
            }

            catch { return(-1); }
        }
示例#3
0
        public DataTable FindD()
        {
            DataTable dt = new DataTable();
            SqlConnectionStringBuilder builder = DBconnector.GetBuilder();

            try
            {
                using (SqlConnection connection = new SqlConnection(builder.ConnectionString))
                {
                    connection.Open();

                    string sql = "SELECT * FROM Zapasy";
                    using (SqlCommand command = new SqlCommand(sql, connection))
                    {
                        using (SqlDataReader reader = command.ExecuteReader())
                        {
                            dt.Load(reader);
                        }
                    }
                }
            }

            catch { }
            return(dt);
        }
示例#4
0
        public void Upravit()
        {
            SqlConnectionStringBuilder builder = DBconnector.GetBuilder();

            try
            {
                using (SqlConnection connection = new SqlConnection(builder.ConnectionString))
                {
                    connection.Open();

                    string sql = "UPDATE Hraci SET jmeno = @p_jmeno, prijmeno = @p_prijmeni, datumZalozeni = @p_datum, zeme = @p_zeme, tym_id = @p_tym_id WHERE h_id = @p_id";
                    using (SqlCommand command = new SqlCommand(sql, connection))
                    {
                        command.Parameters.AddWithValue("@p_id", this.ID);
                        command.Parameters.AddWithValue("@p_jmeno", this.jmeno);
                        command.Parameters.AddWithValue("@p_prijmeni", this.prijmeni);
                        command.Parameters.AddWithValue("@p_datum", this.datumZalozeni);
                        command.Parameters.AddWithValue("@p_zeme", this.zeme);
                        command.Parameters.AddWithValue("@p_tym_id", this.tym.ID);
                        command.ExecuteNonQuery();
                    }
                }
            }

            catch (Exception e) {
                ;
            }
        }
示例#5
0
        public void Pridat()
        {
            this.ID = Hrac.getLastID() + 1;
            SqlConnectionStringBuilder builder = DBconnector.GetBuilder();

            try
            {
                using (SqlConnection connection = new SqlConnection(builder.ConnectionString))
                {
                    connection.Open();

                    string sql = "INSERT INTO Hraci VALUES(@p_id, @p_jmeno, @p_prijmeni, @p_datum, @p_zeme, @p_tym_id)";
                    using (SqlCommand command = new SqlCommand(sql, connection))
                    {
                        command.Parameters.AddWithValue("@p_id", this.ID);
                        command.Parameters.AddWithValue("@p_jmeno", this.jmeno);
                        command.Parameters.AddWithValue("@p_prijmeni", this.prijmeni);
                        command.Parameters.AddWithValue("@p_datum", this.datumZalozeni);
                        command.Parameters.AddWithValue("@p_zeme", this.zeme);
                        command.Parameters.AddWithValue("@p_tym_id", this.tym.ID);
                        command.ExecuteNonQuery();
                    }
                }
            }

            catch (Exception e) {; }
        }
示例#6
0
        public static string PrihlasitDoTurnaje(int _id_turnaje)
        {
            SqlConnectionStringBuilder builder = DBconnector.GetBuilder();

            try
            {
                using (SqlConnection connection = new SqlConnection(builder.ConnectionString))
                {
                    connection.Open();

                    SqlCommand cmd = new SqlCommand("PrihlasitDoTurnaje", connection);
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.AddWithValue("@p_trener_id", Global.IdTrener);
                    cmd.Parameters.AddWithValue("@p_turnaj_id", _id_turnaje);
                    var error     = cmd.Parameters.Add("@o_error", SqlDbType.Bit);
                    var error_msg = cmd.Parameters.Add("@o_error_msg", SqlDbType.VarChar, 50);
                    error.Direction     = ParameterDirection.Output;
                    error_msg.Direction = ParameterDirection.Output;
                    cmd.ExecuteNonQuery();

                    if (Convert.ToBoolean(error.Value))
                    {
                        return(error_msg.Value.ToString());
                    }
                }
                return(null);
            }
            catch (Exception e) {
                return(e.Message);
            }
        }
示例#7
0
        public static DataTable FindByCoachD(int _id)
        {
            DataTable dt = new DataTable();
            SqlConnectionStringBuilder builder = DBconnector.GetBuilder();

            try
            {
                using (SqlConnection connection = new SqlConnection(builder.ConnectionString))
                {
                    connection.Open();

                    string sql = "SELECT * FROM Tymy t JOIN treneri tr on tr.ty_id = t.tym_id WHERE tr.ty_id = @p_tr_id";
                    using (SqlCommand command = new SqlCommand(sql, connection))
                    {
                        command.Parameters.AddWithValue("@p_tr_id", _id);
                        using (SqlDataReader reader = command.ExecuteReader())
                        {
                            dt.Load(reader);
                        }
                    }
                }
            }

            catch { }
            return(dt);
        }
示例#8
0
        public static string getTymSnejviceBody()
        {
            try
            {
                SqlConnectionStringBuilder builder = DBconnector.GetBuilder();
                string tym;
                using (SqlConnection connection = new SqlConnection(builder.ConnectionString))
                {
                    connection.Open();

                    using (SqlCommand command = new SqlCommand("getTymSnejviceBody", connection))
                    {
                        command.CommandType = CommandType.StoredProcedure;
                        var returnTym = command.Parameters.Add("@tym", SqlDbType.VarChar, 20);
                        returnTym.Direction = ParameterDirection.Output;
                        command.ExecuteNonQuery();
                        tym = returnTym.Value.ToString();
                    }
                }
                return(tym);
            }
            catch (Exception e)
            {
                return("chyba");
            }
        }
示例#9
0
        public static void PripsatBody()
        {
            SqlConnectionStringBuilder builder = DBconnector.GetBuilder();

            try
            {
                using (SqlConnection connection = new SqlConnection(builder.ConnectionString))
                {
                    connection.Open();

                    SqlCommand cmd = new SqlCommand("PripsatBody", connection);
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.ExecuteNonQuery();
                }
            }
            catch (Exception e)
            {
            }
        }
示例#10
0
        public void Smazat()
        {
            SqlConnectionStringBuilder builder = DBconnector.GetBuilder();

            try
            {
                using (SqlConnection connection = new SqlConnection(builder.ConnectionString))
                {
                    connection.Open();

                    string sql = "DELETE FROM Hraci WHERE h_id = @p_id";
                    using (SqlCommand command = new SqlCommand(sql, connection))
                    {
                        command.Parameters.AddWithValue("@p_id", this.ID);
                        command.ExecuteNonQuery();
                    }
                }
            }

            catch (Exception e)
            {
                ;
            }
        }