public static void AddNewExercice(TypeOfExercicies Ex) { Conn.Open(); string query = String.Format("Insert into [dbo].[TypeOfExercices](Name) Values('{0}')", Ex.GetExName()); command = new SqlCommand(query, Conn); command.ExecuteNonQuery(); Conn.Close(); }
protected void AddExerciseButtonClick(object sender, EventArgs e) { if (NewExerciceName.Value.ToString() != "") { TypeOfExercicies Ex = new TypeOfExercicies(NewExerciceName.Value.ToString()); if (!ConnectionClass.ExerciceExists(Ex)) { ConnectionClass.AddNewExercice(Ex); } Response.Redirect(Request.RawUrl); } }
public static bool ExerciceExists(TypeOfExercicies ex) { bool Ok = true; Conn.Open(); string query = String.Format("Select count(*) from [dbo].[TypeOfExercices] where Name='{0}'", ex.GetExName()); command = new SqlCommand(query, Conn); if (Convert.ToInt32(command.ExecuteScalar()) >= 1) Ok = true; else Ok = false; Conn.Close(); return Ok; }
public static TypeOfExercicies GetExerciceById(int id) { TypeOfExercicies Ty = new TypeOfExercicies(); Conn.Open(); string query = String.Format("Select * from [Dbo].[TypeOfExercices] where Id={0}", id); command = new SqlCommand(query, Conn); SqlDataReader reader = command.ExecuteReader(); while(reader.Read()) { Ty = new TypeOfExercicies(Convert.ToInt32(reader["Id"]), reader["Name"].ToString()); } Conn.Close(); return Ty; }
public static List<TypeOfExercicies> GetTypeOfExercices() { List<TypeOfExercicies> List = new List<TypeOfExercicies>(); Conn.Open(); string query = "Select * from [dbo].[TypeOfExercices]"; command = new SqlCommand(query, Conn); SqlDataReader reader = command.ExecuteReader(); while(reader.Read()) { TypeOfExercicies Ex = new TypeOfExercicies(Convert.ToInt32(reader["Id"]), reader["Name"].ToString()); List.Add(Ex); } Conn.Close(); return List; }