Esempio n. 1
0
        public static Groups FindById(int id)
        {
            Groups groups = new Groups();

            MySqlConnection connection = Behaviors.ConnectionMysql.ReturnConnection();

            try
            {
                connection.Open();

                MySqlCommand cmd = connection.CreateCommand();
                cmd.CommandText = "SELECT * FROM groups WHERE id = @id";
                cmd.Parameters.AddWithValue("@id", id);
                MySqlDataReader data = cmd.ExecuteReader();

                while (data.Read())
                {
                    groups.Id = Convert.ToInt32(data["id"]);
                    groups.Name = data["name"].ToString();
                    groups.Type = Convert.ToInt32(data["type"]);
                }
            }
            catch (MySqlException e)
            {
                throw new ApplicationException(e.Message);
            }
            finally
            {
                connection.Close();
            }

            return groups;
        }
Esempio n. 2
0
        public static List<Groups> FindAll()
        {
            List<Groups> listGroups = new List<Groups>();

            MySqlConnection connection = Behaviors.ConnectionMysql.ReturnConnection();

            try
            {
                connection.Open();

                MySqlCommand cmd = connection.CreateCommand();
                cmd.CommandText = "SELECT * FROM groups";
                MySqlDataReader data = cmd.ExecuteReader();

                while (data.Read())
                {
                    Groups groups = new Groups();
                    groups.Id = Convert.ToInt32(data["id"]);
                    groups.Name = data["name"].ToString();
                    groups.Type = Convert.ToInt32(data["type"]);

                    listGroups.Add(groups);
                }
            }
            catch (MySqlException e)
            {
                throw new ApplicationException(e.Message);
            }
            finally
            {
                connection.Close();
            }

            return listGroups;
        }
Esempio n. 3
0
 public void Update(int id, string name, int type)
 {
     Groups groups = new Groups { Id = id, Name = name, Type = type };
     try
     {
         GroupsDal.Update(groups);
     }
     catch (ApplicationException e)
     {
         throw new ApplicationException(e.Message);
     }
 }
Esempio n. 4
0
 public void Save(string name, int type)
 {
     Groups groups = new Groups { Name = name, Type = type };
     try
     {
         GroupsDal.Save(groups);
     }
     catch (ApplicationException e)
     {
         throw new ApplicationException(e.Message);
     }
 }
Esempio n. 5
0
 public Groups FindById(int id)
 {
     Groups groups = new Groups();
     try
     {
         groups = GroupsDal.FindById(id);
     }
     catch (ApplicationException e)
     {
         throw new ApplicationException(e.Message);
     }
     return groups;
 }
Esempio n. 6
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (IsPostBack)
     {
         try
         {
             (new GroupsBll()).Update(Convert.ToInt32(Request.Form["id"]), Request.Form["name"], Convert.ToInt32(Request.Form["type"]));
             Response.Write("Atualizado com sucesso!");
         }
         catch (ApplicationException ex)
         {
             Response.Write(ex.Message);
         }
     }
     else
     {
         groups = (new GroupsBll()).FindById(Convert.ToInt32(Request.QueryString["id"]));
     }
 }
Esempio n. 7
0
        public static void Save(Groups groups)
        {
            MySqlConnection connection = Behaviors.ConnectionMysql.ReturnConnection();

            try
            {
                connection.Open();

                MySqlCommand cmd = connection.CreateCommand();
                cmd.CommandText = "INSERT INTO groups (name, type) VALUES (@name, @type)";
                cmd.Parameters.AddWithValue("@name", groups.Name);
                cmd.Parameters.AddWithValue("@type", groups.Type);
                cmd.ExecuteNonQuery();
            }
            catch (MySqlException e)
            {
                throw new ApplicationException(e.Message);
            }
            finally
            {
                connection.Close();
            }
        }
Esempio n. 8
0
        public static void Update(Groups groups)
        {
            MySqlConnection connection = Behaviors.ConnectionMysql.ReturnConnection();

            try
            {
                connection.Open();

                MySqlCommand cmd = connection.CreateCommand();
                cmd.CommandText = "UPDATE groups SET name = @name, type = @type WHERE id = @id";
                cmd.Parameters.AddWithValue("@id", groups.Id);
                cmd.Parameters.AddWithValue("@name", groups.Name);
                cmd.Parameters.AddWithValue("@type", groups.Type);
                cmd.ExecuteNonQuery();
            }
            catch (MySqlException e)
            {
                throw new ApplicationException(e.Message);
            }
            finally
            {
                connection.Close();
            }
        }
Esempio n. 9
0
 protected void Page_Load(object sender, EventArgs e)
 {
     groups = new GroupsBll().FindById(Convert.ToInt32(Request.QueryString["id"]));
 }