private void btnSalvar_Click(object sender, EventArgs e)
        {
            try
            {
                DeptoDTO  depto  = cboDepto.SelectedItem as DeptoDTO;
                EstadoDTO estado = cboUF.SelectedItem as EstadoDTO;

                FuncionarioDTO dto = new FuncionarioDTO();
                dto.Nome        = txtNome.Text;
                dto.Rg          = mkbRG.Text;
                dto.Salario     = nudSalario.Value;
                dto.Cpf         = mkbCPF.Text;
                dto.Telefone    = mkbTelefone.Text;
                dto.Email       = txtEmail.Text;
                dto.IdDepto     = depto.Id;
                dto.Cidade      = txtCidade.Text;
                dto.IdEstado    = estado.Id;
                dto.Cep         = mkbCEP.Text;
                dto.Rua         = txtEndereco.Text;
                dto.Complemento = txtComplemento.Text;
                dto.Numero      = txtNum.Text;

                dto.Imagem = ImagemPlugIn.ConverterParaString(pbxFoto.Image);

                FuncionarioBusiness buss = new FuncionarioBusiness();
                buss.Salvar(dto);

                frmMessage tela = new frmMessage();
                tela.LoadScreen("Funcionário cadastrado com sucesso!");
                tela.ShowDialog();
            }
            catch (MySqlException mex)
            {
                if (mex.Number == 1062)
                {
                    string msg = "Funcionario já está cadastrado. Verifique se o CPF está corretamente preenchido ou se ele já esta no sistema.";

                    frmAlert tela = new frmAlert();
                    tela.LoadScreen(msg);
                    tela.ShowDialog();
                }
            }
            catch (ValidacaoException vex)
            {
                string msg = vex.Message;

                frmAlert tela = new frmAlert();
                tela.LoadScreen(msg);
                tela.ShowDialog();
            }
            catch (Exception ex)
            {
                string msg = "Ocorreu um erro: " + ex.Message;

                frmException tela = new frmException();
                tela.LoadScreen(msg);
                tela.ShowDialog();
            }
        }
        private void btnSalvar_Click(object sender, EventArgs e)
        {
            try
            {
                DeptoDTO  depto  = cboDepto.SelectedItem as DeptoDTO;
                EstadoDTO estado = cboUF.SelectedItem as EstadoDTO;

                int funcio = this.dto.Id;

                FuncionarioDTO dto = new FuncionarioDTO();
                dto.Id = funcio;

                dto.Nome        = txtNome.Text;
                dto.Rg          = mkbRG.Text;
                dto.Salario     = nudSalario.Value;
                dto.Cpf         = mkbCPF.Text;
                dto.Telefone    = mkbTelefone.Text;
                dto.Email       = txtEmail.Text;
                dto.IdDepto     = depto.Id;
                dto.Cidade      = txtCidade.Text;
                dto.IdEstado    = estado.Id;
                dto.Cep         = mkbCEP.Text;
                dto.Rua         = txtEndereco.Text;
                dto.Numero      = txtNum.Text;
                dto.Imagem      = ImagemPlugIn.ConverterParaString(pbxFoto.Image);
                dto.Complemento = txtComplemento.Text;

                FuncionarioBusiness buss = new FuncionarioBusiness();
                buss.Alterar(dto);

                string msg = "Funcionário alterado com sucesso!";

                frmMessage tela = new frmMessage();
                tela.LoadScreen(msg);
                tela.ShowDialog();

                this.Close();
            }
            catch (ValidacaoException vex)
            {
                string msg = vex.Message;

                frmAlert tela = new frmAlert();
                tela.LoadScreen(msg);
                tela.ShowDialog();
            }
            catch (Exception ex)
            {
                string msg = "Ocorreu um erro: " + ex.Message;

                frmException tela = new frmException();
                tela.LoadScreen(msg);
                tela.ShowDialog();
            }
        }
Exemplo n.º 3
0
        private void dgvDepto_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex == 2)
            {
                DeptoDTO dto = new DeptoDTO();

                DialogResult resposta = MessageBox.Show("Quer mesmo apagar este registro?", "NerdT", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

                if (resposta == DialogResult.Yes)
                {
                    DeptoBusiness business = new DeptoBusiness();
                    business.Remover(dto.Id);
                    MessageBox.Show("Registro removido com sucesso!", "NerdT", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation);
                }
            }
        }
Exemplo n.º 4
0
        private void dgvDepto_CellContentClick_1(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                if (e.ColumnIndex == 3)
                {
                    DeptoDTO dto = dgvDepto.Rows[e.RowIndex].DataBoundItem as DeptoDTO;

                    string msg = "Quer mesmo apagar o registro " + dto.Id + "?" +
                                 "\n" + "obs: Ao apagar um departamento, todos os funcionários nele vinculados serão deletados.";

                    frmQuestion tela = new frmQuestion();
                    tela.LoadScreen(msg);
                    tela.ShowDialog();

                    bool botaoYes = tela.BotaoYes;

                    if (botaoYes == true)
                    {
                        DeptoBusiness buss = new DeptoBusiness();

                        int IdDepto = dto.Id;
                        buss.Remover(IdDepto);

                        string msgm = "Registo removido com sucesso!";

                        frmMessage message = new frmMessage();
                        message.LoadScreen(msgm);
                        message.ShowDialog();

                        CarregarGrid();
                    }
                }
            }
            catch (Exception ex)
            {
                string msg = "Ocorreu um erro: " + ex.Message;

                frmException tela = new frmException();
                tela.LoadScreen(msg);
                tela.ShowDialog();
            }
        }
Exemplo n.º 5
0
        private void btnCadastrar_Click(object sender, EventArgs e)
        {
            try
            {
                string nome = txtNome.Text;
                nome = nome.Trim();
                int qtdNome = nome.Count();

                if (qtdNome > 50)
                {
                    throw new Exception("O campo 'Nome' não pode ter mais de 50 caracteres.");
                }
                else if (qtdNome == 0)
                {
                    throw new Exception("Nome inválido.");
                }

                string cidade = txtCidade.Text;
                cidade = cidade.Trim();
                int qtdCidade = cidade.Count();

                if (qtdCidade > 50)
                {
                    throw new Exception("O campo 'Cidade' não pode ter mais de 50 caracteres.");
                }
                else if (qtdCidade == 0)
                {
                    throw new Exception("Cidade inválida.");
                }

                string bairro = txtBairro.Text;
                bairro = bairro.Trim();
                int qtdBairro = bairro.Count();

                if (qtdBairro > 45)
                {
                    throw new Exception("O campo 'Bairro' não pode ter mais de 45 caracteres.");
                }
                else if (qtdBairro == 0)
                {
                    throw new Exception("Bairro inválido.");
                }

                string rua = txtRua.Text;
                rua = rua.Trim();
                int qtdRua = rua.Count();

                if (qtdRua > 50)
                {
                    throw new Exception("O campo 'Rua' não pode passar de 50 caracteres");
                }
                else if (qtdRua == 0)
                {
                    throw new Exception("Rua inválida.");
                }

                string email = txtEmail.Text;
                email = email.Trim();
                int qtdEmail = email.Count();

                if (qtdEmail > 100)
                {
                    throw new Exception("O campo 'Email' não pode ter mais de 100 caracteres.");
                }
                else if (qtdEmail == 0)
                {
                    throw new Exception("Email inválido.");
                }


                DeptoDTO depto = cboDepto.SelectedItem as DeptoDTO;

                Classes.ClassesFuncionarios.FuncionarioDTO dto = new Classes.ClassesFuncionarios.FuncionarioDTO();
                dto.Nome       = txtNome.Text;
                dto.Nascimento = mtbNasc.Text;
                dto.RG         = mtbRg.Text;
                dto.CPF        = mtbCpf.Text;
                dto.Telefone   = mtbTelefone.Text;
                dto.Email      = txtEmail.Text;

                dto.DeptoId = depto.Id;

                dto.Cidade      = txtCidade.Text;
                dto.Estado      = mkbEstado.Text;
                dto.Bairro      = txtBairro.Text;
                dto.Rua         = txtRua.Text;
                dto.CEP         = txtCep.Text;
                dto.COmplemento = txtComplemento.Text;

                Classes.ClassesFuncionarios.FuncionarioBusiness business = new Classes.ClassesFuncionarios.FuncionarioBusiness();
                business.Salvar(dto);

                MessageBox.Show("Funcionário cadastrado com suceso!!", "SIGMA", MessageBoxButtons.OK);
            }
            catch (MySqlException ex)
            {
                if (ex.Number == 1062)
                {
                    MessageBox.Show("Funcionario já está cadastrado. Verifique se o RG ou CPF estão corretamento preenchidos ou se ele já esta no sistema.",
                                    "SIGMA", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "SIGMA", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }