Ejemplo n.º 1
0
        private void btnLogin_Click(object sender, EventArgs e)
        {
            try
            {
                FuncionarioDTO Funcionario = new FuncionarioDTO();
                Funcionario.Nome               = textBox1.Text;
                Funcionario.Login              = textBox2.Text;
                Funcionario.Senha              = textBox3.Text;
                Funcionario.PermissaoADM       = false;
                Funcionario.PermissaoEvento    = true;
                Funcionario.PermissaoRelatorio = true;

                FuncionarioBusiness business = new FuncionarioBusiness();
                int a = business.Salvar(Funcionario);

                MessageBox.Show("Funcionario Salvo com sucesso.", "Best Moments",
                                MessageBoxButtons.OK, MessageBoxIcon.Information);



                frmFolhaPagamento tela = new frmFolhaPagamento();
                tela.Show();
                this.Hide();
            }
            catch (ArgumentException ex)
            {
                MessageBox.Show(ex.Message, "Best Moments",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        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();
            }
        }