Пример #1
0
        private void btnGravar_Click(object sender, EventArgs e)
        {
            try
            {
                Types.DepartamentoType type = new Types.DepartamentoType();
                type.Descricao = txtDescricao.Text;

                DepartamentoBLL itemBLL = new DepartamentoBLL();
                if (txtID.Text == "")
                {
                    txtID.Text = Convert.ToString(itemBLL.insert(type));
                }
                else
                {
                    type.IdDepartamento = Convert.ToInt32(txtID.Text);
                    itemBLL.alterar(type);
                }
            }
            catch (Exception erro)
            {
                MessageBox.Show("Erro ao gravar. Mensagem: " +
                    erro.Message, "Erro", MessageBoxButtons.OK,
                    MessageBoxIcon.Error);
            }
            findAll();
        }
Пример #2
0
        private void btnGravar_Click(object sender, EventArgs e)
        {
            try
            {
                Types.DepartamentoType type = new Types.DepartamentoType();
                type.Descricao = txtDescricao.Text;

                DepartamentoBLL itemBLL = new DepartamentoBLL();
                if (txtID.Text == "")
                {
                    txtID.Text = Convert.ToString(itemBLL.insert(type));
                }
                else
                {
                    type.IdDepartamento = Convert.ToInt32(txtID.Text);
                    itemBLL.alterar(type);
                }
            }
            catch (Exception erro)
            {
                MessageBox.Show("Erro ao gravar. Mensagem: " +
                    erro.Message, "Erro", MessageBoxButtons.OK,
                    MessageBoxIcon.Error);
            }
            findAll();
        }
Пример #3
0
 public Types.DepartamentosType select()
 {
     MySqlConnection con = new MySqlConnection(Dados.StringConexao);
     string SQL = "SELECT * FROM DEPARTAMENTO";
     MySqlCommand cmd = new MySqlCommand(SQL, con);
     con.Open();
     MySqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
     Types.DepartamentosType types = new Types.DepartamentosType();
     while (dr.Read())
     {
         Types.DepartamentoType type = new Types.DepartamentoType();
         type.Descricao = dr["DESCRICAO"].ToString();
         type.IdDepartamento = Int32.Parse(dr["ID_DEPARTAMENTO"].ToString());
         types.Add(type);
     }
     return types;
 }
Пример #4
0
        public void delete(Types.DepartamentoType type)
        {
            MySqlConnection con = new MySqlConnection(Dados.StringConexao);
            string          SQL = "DELETE FROM DEPARTAMENTO " +
                                  "WHERE ID_DEPARTAMENTO = @id";
            MySqlCommand cmd = new MySqlCommand(SQL, con);

            cmd.Parameters.AddWithValue("@id", type.IdDepartamento);
            try
            {
                con.Open();
                cmd.ExecuteNonQuery();
            }
            finally
            {
                con.Close();
            }
        }
Пример #5
0
        public Types.DepartamentoType selectRecord(Types.DepartamentoType type)
        {
            MySqlConnection con = new MySqlConnection(Dados.StringConexao);
            string          SQL = "SELECT U.* FROM DEPARTAMENTO U  " +
                                  "WHERE ID_DEPARTAMENTO = @id";
            MySqlCommand cmd = new MySqlCommand(SQL, con);

            cmd.Parameters.AddWithValue("@id", type.IdDepartamento);
            con.Open();
            MySqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);

            if (dr.Read())
            {
                type.Descricao      = dr["DESCRICAO"].ToString();
                type.IdDepartamento = Int32.Parse(dr["ID_DEPARTAMENTO"].ToString());
            }
            return(type);
        }
Пример #6
0
        public Types.DepartamentosType select()
        {
            MySqlConnection con = new MySqlConnection(Dados.StringConexao);
            string          SQL = "SELECT * FROM DEPARTAMENTO";
            MySqlCommand    cmd = new MySqlCommand(SQL, con);

            con.Open();
            MySqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);

            Types.DepartamentosType types = new Types.DepartamentosType();
            while (dr.Read())
            {
                Types.DepartamentoType type = new Types.DepartamentoType();
                type.Descricao      = dr["DESCRICAO"].ToString();
                type.IdDepartamento = Int32.Parse(dr["ID_DEPARTAMENTO"].ToString());
                types.Add(type);
            }
            return(types);
        }
Пример #7
0
        public void update(Types.DepartamentoType type)
        {
            MySqlConnection con = new MySqlConnection(Dados.StringConexao);
            string          SQL = "UPDATE DEPARTAMENTO " +
                                  "SET DESCRICAO = @descricao " +
                                  "WHERE ID_DEPARTAMENTO = @id";
            MySqlCommand cmd = new MySqlCommand(SQL, con);

            cmd.Parameters.AddWithValue("@id", type.IdDepartamento);
            cmd.Parameters.AddWithValue("@descricao", type.Descricao);
            try
            {
                con.Open();
                cmd.ExecuteNonQuery();
            }
            finally
            {
                con.Close();
            }
        }
Пример #8
0
        public int insert(Types.DepartamentoType type)
        {
            MySqlConnection con = new MySqlConnection(Dados.StringConexao);
            string          SQL = "INSERT INTO DEPARTAMENTO (descricao) " +
                                  "VALUES(@descricao)";
            MySqlCommand cmd = new MySqlCommand(SQL, con);

            cmd.Parameters.AddWithValue("@descricao", type.Descricao);
            try
            {
                con.Open();
                cmd.ExecuteNonQuery();
            }
            finally
            {
                con.Close();
            }

            return(int.Parse(cmd.LastInsertedId.ToString()));
        }
Пример #9
0
        private void btnExcluir_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Tem certeza que deseja excluir?", "Exclusão", MessageBoxButtons.YesNo, MessageBoxIcon.Error) == System.Windows.Forms.DialogResult.Yes)
            {
                try
                {
                    Types.DepartamentoType type = new Types.DepartamentoType();
                    type.IdDepartamento = Convert.ToInt32(txtID.Text);

                    DepartamentoBLL itemBLL = new DepartamentoBLL();
                    itemBLL.excluir(type);
                }
                catch (Exception erro)
                {
                    MessageBox.Show("Erro ao excluir. Mensagem: " +
                        erro.Message, "Erro", MessageBoxButtons.OK,
                        MessageBoxIcon.Error);
                }
                findAll();
                LimparCampos();
            }
        }
Пример #10
0
        private void btnExcluir_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Tem certeza que deseja excluir?", "Exclusão", MessageBoxButtons.YesNo, MessageBoxIcon.Error) == System.Windows.Forms.DialogResult.Yes)
            {
                try
                {
                    Types.DepartamentoType type = new Types.DepartamentoType();
                    type.IdDepartamento = Convert.ToInt32(txtID.Text);

                    DepartamentoBLL itemBLL = new DepartamentoBLL();
                    itemBLL.excluir(type);
                }
                catch (Exception erro)
                {
                    MessageBox.Show("Erro ao excluir. Mensagem: " +
                        erro.Message, "Erro", MessageBoxButtons.OK,
                        MessageBoxIcon.Error);
                }
                findAll();
                LimparCampos();
            }
        }
Пример #11
0
 public void alterar(Types.DepartamentoType usuario)
 {
     DAL_MYSQL.DepartamentoDAL DepartamentoDAL = new DAL_MYSQL.DepartamentoDAL();
     DepartamentoDAL.update(usuario);
 }
Пример #12
0
 public void excluir(Types.DepartamentoType usuario)
 {
     DAL_MYSQL.DepartamentoDAL DepartamentoDAL = new DAL_MYSQL.DepartamentoDAL();
     DepartamentoDAL.delete(usuario);
 }
Пример #13
0
        public int insert(Types.DepartamentoType usuario)
        {
            DepartamentoDAL DepartamentoDAL = new DepartamentoDAL();

            return(DepartamentoDAL.insert(usuario));
        }
Пример #14
0
 public Types.DepartamentoType selectRecord(Types.DepartamentoType usuario)
 {
     DAL_MYSQL.DepartamentoDAL DepartamentoDAL = new DAL_MYSQL.DepartamentoDAL();
     return(DepartamentoDAL.selectRecord(usuario));
 }