private void CarregaComboFuncionarios() { try { FuncionarioNegocios oNegocios = new FuncionarioNegocios(); List <FuncionarioModel> oListModel = new List <FuncionarioModel>(); oListModel = oNegocios.Listar(new FuncionarioModel() { Cargo = 3 }); oListModel.Insert(0, new FuncionarioModel() { Codigo = null, Nome = "Selecione", Cargo = 3 }); var obj = oListModel.Where(p => p.Cargo == 3); cmbFuncionario.DataSource = obj; cmbFuncionario.DataTextField = "Nome"; cmbFuncionario.DataValueField = "Codigo"; cmbFuncionario.DataBind(); } catch (Exception ex) { ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "ERROR", "$(document).MensagemModal(3,'Ocorreu um erro inesperado! Mensagem = " + new JavaScriptSerializer().Serialize(ex.Message.ToString()) + "');", true); } }
protected void btEsqueceuSenha_Click(object sender, EventArgs e) { try { ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "FechaModal", "$('#ModalReenviarSenha').modal('hide');", true); FuncionarioNegocios oNegocios = new FuncionarioNegocios(); List <FuncionarioModel> oList = new List <FuncionarioModel>(); FuncionarioModel oModel = new FuncionarioModel(); oModel.Email = txUser.Text.Trim(); if (oNegocios.AlterarSenha(oModel)) { ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "SenhaAlterada", "$(document).MensagemModal(1,'Uma nova senha foi enviada para seu e-mail.');", true); } else { ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "EmailNaoExiste", "$(document).MensagemModal(3,'E-mail não cadastrado!');", true); } } catch (Exception ex) { ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "EROOR", "$(document).MensagemModal(3,'Ocorreu um erro inesperado! Mensagem = " + new JavaScriptSerializer().Serialize(ex.Message.ToString()) + "');", true); } }
//Criando um método atualizar grid private void AtualizarGrid() { FuncionarioNegocios funcionarioNegocios = new FuncionarioNegocios(); FuncionarioColecao funcionarioColecao = new FuncionarioColecao(); funcionarioColecao = funcionarioNegocios.ConsultarPorNome(textBoxPesquisa.Text); dataGridViewPrincipal.DataSource = null; dataGridViewPrincipal.DataSource = funcionarioColecao; dataGridViewPrincipal.Update(); dataGridViewPrincipal.Refresh(); }
private void DetalharObj(int Id) { FuncionarioModel oModel = new FuncionarioModel(); List <FuncionarioModel> oListModel = new List <FuncionarioModel>(); FuncionarioNegocios oNegocios = new FuncionarioNegocios(); oModel.Codigo = Id; oListModel = oNegocios.Listar(oModel); if (oListModel.Count > 0) { oModel = oListModel[0]; Funcionario_Id.Value = oModel.Codigo.ToString(); txtNome.Text = oModel.Nome; txtCPF.Text = oModel.CPF; if (oModel.DataNascimento != null) { txtDataNascimento.Text = ((DateTime)oModel.DataNascimento).ToString("dd/MM/yyyy"); } txtCEP.Text = oModel.CEP; txtUF.Text = oModel.UF; txtCidade.Text = oModel.Municipio; txtBairro.Text = oModel.Bairro; txtEndereco.Text = oModel.Endereco; txtNumEndereco.Text = oModel.Numero; txtComplemento.Text = oModel.Complemento; txtTelefone.Text = oModel.Telefone; txtCelular.Text = oModel.Celular; txtEmail.Text = oModel.Email; txtEmail_Original.Text = oModel.Email; txSalario.Text = oModel.Salario.ToString(); txDataAdmissao.Text = ((DateTime)oModel.DataAdmissao).ToString("dd/MM/yyyy"); cbStatus.SelectedValue = ((bool)oModel.Ativo).ToString(); cbCargo.SelectedValue = oModel.Cargo.ToString(); FuncionarioModel oFuncionario = (FuncionarioModel)Session["objFuncionario"]; if (oFuncionario.Codigo == oModel.Codigo) { btnAlterarSenhaModal.Visible = true; } else { btnAlterarSenhaModal.Visible = false; } } }
protected void btLogar_Click(object sender, EventArgs e) { try { txAviso.Visible = false; txAviso.InnerHtml = ""; if ((string.IsNullOrEmpty(txUser.Text.Trim())) || (string.IsNullOrEmpty(txPass.Text.Trim()))) { ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "CamposObrigatorios", "$(document).MensagemModal(3,'<strong> Informações obrigatórias:</strong><br/> -E-mail <br/> -Senha');", true); } else { FuncionarioNegocios oNegocios = new FuncionarioNegocios(); FuncionarioModel oModel = new FuncionarioModel(); oModel.Email = txUser.Text.Trim(); oModel.Senha = txPass.Text.Trim(); oModel = oNegocios.Validar(oModel); if (oModel.Codigo.HasValue) { if (oModel.Ativo == true) { Session.Add("objFuncionario", oModel); Response.Redirect("~/Shared/Modulos.aspx", false); Context.ApplicationInstance.CompleteRequest(); //Response.Redirect("~/Shared/ShopAtendimento.aspx"); } else { txAviso.Visible = true; ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "Inativo", "$(document).MensagemModal(3,'<strong>Funcionário inativo no sistema.</ strong >');", true); } } else { txAviso.Visible = true; ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "UserInvalid", "$(document).MensagemModal(3,'<strong>E-mail e/ou Senha Inválido(s).</ strong >');", true); } } } catch (Exception ex) { ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "EROOR", "$(document).MensagemModal(3,'Ocorreu um erro inesperado! Mensagem = " + new JavaScriptSerializer().Serialize(ex.Message.ToString()) + "');", true); } }
private void buttonExcluir_Click(object sender, EventArgs e) { //Verificar se tem algum registro selecionado if (dataGridViewPrincipal.SelectedRows.Count == 0) { MessageBox.Show("Nenhum funcionário selecionado."); return; } //Perguntar se realmente quer excluir DialogResult resultado = MessageBox.Show("Tem certeza que deseja excluir?", "Pergunta", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (resultado == DialogResult.No) { return; } //Pegar o cliente selecionado no grid Funcionario funcionarioSelecionado = (dataGridViewPrincipal.SelectedRows[0].DataBoundItem as Funcionario); //Instânciar a regra de negócio FuncionarioNegocios funcionarioNegocios = new FuncionarioNegocios(); //Chamar o método para excluir string retorno = funcionarioNegocios.Excluir(funcionarioSelecionado); //Verificar se excluiu com sucesso //Se o retorno for um número é porque deu certo, senão é a mensagem de erro try { int idFuncionario = Convert.ToInt32(retorno); MessageBox.Show("Funcionário excluído com sucesso.", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Information); AtualizarGrid(); } catch { MessageBox.Show("Não foi possível excluir. Detalhes: " + retorno, "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void CarregaComboFuncionarios() { try { FuncionarioNegocios oNegocios = new FuncionarioNegocios(); List <FuncionarioModel> oListModel = new List <FuncionarioModel>(); oListModel = oNegocios.ListarComboFuncionario(new FuncionarioModel()); oListModel.Insert(0, new FuncionarioModel() { Codigo = 0, Nome = "Selecione" }); ddlFuncionario.DataSource = oListModel; ddlFuncionario.DataBind(); } catch (Exception ex) { string msg = "Ocorreu um erro preencher os funcionários!"; ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "ERROR", "$(document).MensagemModal(3,'" + msg + "');", true); } }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { try { FuncionarioNegocios oNegocios = new FuncionarioNegocios(); List <FuncionarioModel> oList = new List <FuncionarioModel>(); oList = oNegocios.Listar(new FuncionarioModel()); if (oList.Count > 0) { Rpt.DataSource = oList; Rpt.DataBind(); } } catch (Exception ex) { ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "EROOR", "$(document).MensagemModal(3,'Ocorreu um erro inesperado! Mensagem = " + new JavaScriptSerializer().Serialize(ex.Message.ToString()) + "');", true); } } }
private void btPesquisarFunc_Click(object sender, EventArgs e) { FuncionarioNegocios funcionarioNegocios = new FuncionarioNegocios(); FuncionarioColecao funcionarioColecao = new FuncionarioColecao(); int cod; if (int.TryParse(txPesqFun.Text, out cod) == true) { funcionarioColecao = funcionarioNegocios.consultarPorCodigo(cod); } else { funcionarioColecao = funcionarioNegocios.consultarPorNome(txPesqFun.Text); } dgPesqFun.DataSource = null; dgPesqFun.DataSource = funcionarioColecao; dgPesqFun.Update(); dgPesqFun.Refresh(); }
protected void btnAlterarSenha_Click(object sender, EventArgs e) { try { ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "FechaModal", "$('#ModalAlterarSenha').modal('hide');", true); if (string.IsNullOrEmpty(txPass.Text)) { ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "CamposObrigatorios", "$(document).MensagemModal(3,'Digite a senha e a confirmação da senha!');", true); return; } else if ((string.IsNullOrEmpty(txPass.Text)) != (string.IsNullOrEmpty(txPassConfirm.Text))) { ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "CamposObrigatorios", "$(document).MensagemModal(3,'A senha está diferente da confirmação da senha!');", true); return; } else { FuncionarioModel oModel = new FuncionarioModel(); FuncionarioNegocios oNegocios = new FuncionarioNegocios(); oModel.Email = txtEmail_Original.Text; oModel.Senha = txPass.Text; if (oNegocios.AlterarSenha(oModel)) { ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "SenhaAltrada", "$(document).MensagemModal(1,'Senha alterada com sucesso!');", true); } else { ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "ErroAlterarSenha", "$(document).MensagemModal(3,'Ocorreu um erro ao alterar sua senha!');", true); } } } catch (Exception ex) { ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "ERROR", "$(document).MensagemModal(3,'Ocorreu um erro inesperado! Mensagem = " + new JavaScriptSerializer().Serialize(ex.Message.ToString()) + "');", true); } }
private void buttonSalvar_Click(object sender, EventArgs e) { //Verificar se é inserção ou alteração if (acaoNaTelaSelecionada == AcaoNaTela.Inserir) { Funcionario funcionario = new Funcionario(); funcionario.CADNOMEFUNCIONARIO = textBoxNome.Text; funcionario.CADENDFUNCIONARIO = textBoxEndereco.Text; funcionario.CADTELFUNCIONARIO = textBoxTelefone.Text; funcionario.CADCPFFUNCIONARIO = textBoxCPF.Text; funcionario.CADRGFUNCIONARIO = textBoxRG.Text; funcionario.CADDATANASCFUNCIONARIO = dateNascimento.Value; funcionario.CADCARGOFUNCIONARIO = comboBoxCargo.Text; funcionario.CADDATACADASTROFUNCIONARIO = dateDataCadastro.Value; FuncionarioNegocios funcionarioNegocios = new FuncionarioNegocios(); string retorno = funcionarioNegocios.Inserir(funcionario); //Tentar converter para inteiro //Se der tudo certo é porque devolveu o código do cliente //Se der errado tem a mensagem de erro try { int idFuncionario = Convert.ToInt32(retorno); MessageBox.Show("Inserido com sucesso." + idFuncionario.ToString()); this.DialogResult = DialogResult.Yes; } catch { MessageBox.Show("Não foi possível inserir. Detalhes: " + retorno, "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error); this.DialogResult = DialogResult.No; } } else if (acaoNaTelaSelecionada == AcaoNaTela.Alterar) { // Crio um cliente Funcionario funcionario = new Funcionario(); //Coloco os campos da tela no objeto clliente, e envio para alterar no banco funcionario.IDCADFUNCIONARIO = Convert.ToInt32(textBoxCodigo.Text); funcionario.CADNOMEFUNCIONARIO = textBoxNome.Text; funcionario.CADENDFUNCIONARIO = textBoxEndereco.Text; funcionario.CADTELFUNCIONARIO = textBoxTelefone.Text; funcionario.CADCPFFUNCIONARIO = textBoxCPF.Text; funcionario.CADRGFUNCIONARIO = textBoxRG.Text; funcionario.CADDATANASCFUNCIONARIO = dateNascimento.Value; funcionario.CADCARGOFUNCIONARIO = comboBoxCargo.Text; funcionario.CADDATACADASTROFUNCIONARIO = dateDataCadastro.Value; FuncionarioNegocios funcionarioNegocios = new FuncionarioNegocios(); string retorno = funcionarioNegocios.Alterar(funcionario); //Tentar converter para inteiro //Se der tudo certo é porque devolveu o código do cliente //Se der errado tem a mensagem de erro try { int idFuncionario = Convert.ToInt32(retorno); MessageBox.Show("Alterado com sucesso." + idFuncionario.ToString()); this.DialogResult = DialogResult.Yes; } catch { MessageBox.Show("Não foi possível alterar. Detalhes: " + retorno, "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error); this.DialogResult = DialogResult.No; } } }
private bool ValidarCampos() { Boolean Valido = true; String MSG_ERROR = String.Empty; FuncionarioModel oModel = new FuncionarioModel(); List <FuncionarioModel> oListModel = new List <FuncionarioModel>(); FuncionarioNegocios oNegocios = new FuncionarioNegocios(); if (string.IsNullOrEmpty(txtNome.Text.Trim())) { MSG_ERROR += "- Nome. <br />"; } if (string.IsNullOrEmpty(txtCPF.Text.Trim())) { MSG_ERROR += "- CPF. <br />"; } else { if (!UTIL.UTIL.IsCpf(txtCPF.Text.Trim())) { MSG_ERROR += "- CPF inválido. <br />"; } else if (string.IsNullOrEmpty(Funcionario_Id.Value)) { //Valida se CPF já cadastrado oModel = new FuncionarioModel(); oListModel = new List <FuncionarioModel>(); oNegocios = new FuncionarioNegocios(); oModel.CPF = UTIL.UTIL.RetiraFormatacao(txtCPF.Text, new string[] { ".", "-" }); oListModel = oNegocios.Listar(oModel); if (oListModel.Count > 0) { MSG_ERROR += "- CPF já cadastrado. <br />"; } } } if (string.IsNullOrEmpty(txtDataNascimento.Text.Trim())) { MSG_ERROR += "- Data de Nascimento. <br />"; } if (string.IsNullOrEmpty(txtEndereco.Text.Trim())) { MSG_ERROR += "- Endereço. <br />"; } if (!UTIL.UTIL.ValidarEmail(txtEmail.Text.Trim())) { MSG_ERROR += "- Email não preenchido ou inválido. <br />"; } else if (string.IsNullOrEmpty(Funcionario_Id.Value)) { //Valida se email já cadastrado oModel.Email = txtEmail.Text.Trim(); oListModel = oNegocios.Listar(oModel); if (oListModel.Count > 0) { MSG_ERROR += "- Email já cadastrado. <br />"; } } if ((string.IsNullOrEmpty(txtTelefone.Text.Trim())) && (string.IsNullOrEmpty(txtCelular.Text.Trim()))) { MSG_ERROR += "- Telefone e/ou Celular. <br />"; } if (MSG_ERROR.Length > 0) { ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "CamposObrigatorios", "$(document).MensagemModal(3,'<strong>Informações obrigatórias:</strong><br/>" + MSG_ERROR + "');", true); Valido = false; } return(Valido); }
protected void btnSalvar_Click(object sender, EventArgs e) { try { if (ValidarCampos()) { FuncionarioModel oModel = new FuncionarioModel(); FuncionarioNegocios oNegocios = new FuncionarioNegocios(); if (!string.IsNullOrEmpty(Funcionario_Id.Value)) { oModel.Codigo = UTIL.UTIL.Parse <int>(Funcionario_Id.Value); } else { oModel.DataCadastro = DateTime.Now; } oModel.Nome = UTIL.UTIL.Parse <string>(txtNome.Text); oModel.CPF = UTIL.UTIL.RetiraFormatacao(txtCPF.Text, new string[] { ".", "-" }); oModel.DataNascimento = UTIL.UTIL.Parse <DateTime>(txtDataNascimento.Text); if (!string.IsNullOrEmpty(txtCEP.Text)) { oModel.CEP = UTIL.UTIL.Parse <string>(txtCEP.Text); } if (!string.IsNullOrEmpty(txtUF.Text)) { oModel.UF = UTIL.UTIL.Parse <string>(txtUF.Text); } if (!string.IsNullOrEmpty(txtCidade.Text)) { oModel.Municipio = UTIL.UTIL.Parse <string>(txtCidade.Text); } if (!string.IsNullOrEmpty(txtBairro.Text)) { oModel.Bairro = UTIL.UTIL.Parse <string>(txtBairro.Text); } if (!string.IsNullOrEmpty(txtEndereco.Text)) { oModel.Endereco = UTIL.UTIL.Parse <string>(txtEndereco.Text); } if (!string.IsNullOrEmpty(txtNumEndereco.Text)) { oModel.Numero = UTIL.UTIL.Parse <string>(txtNumEndereco.Text); } if (!string.IsNullOrEmpty(txtComplemento.Text)) { oModel.Complemento = UTIL.UTIL.Parse <string>(txtComplemento.Text); } if (!string.IsNullOrEmpty(txtTelefone.Text)) { oModel.Telefone = UTIL.UTIL.RetiraFormatacao(UTIL.UTIL.Parse <string>(txtTelefone.Text), new string[] { "(", ")", " ", "-" }); } if (!string.IsNullOrEmpty(txtCelular.Text)) { oModel.Celular = UTIL.UTIL.RetiraFormatacao(UTIL.UTIL.Parse <string>(txtCelular.Text), new string[] { "(", ")", " ", "-" }); } if (!string.IsNullOrEmpty(txtEmail.Text)) { oModel.Email = UTIL.UTIL.Parse <string>(txtEmail.Text); } if (!string.IsNullOrEmpty(txSalario.Text)) { oModel.Salario = UTIL.UTIL.Parse <Decimal>(txSalario.Text); } if (!string.IsNullOrEmpty(txDataAdmissao.Text)) { oModel.DataAdmissao = UTIL.UTIL.Parse <DateTime>(txDataAdmissao.Text); } oModel.Ativo = Boolean.Parse(cbStatus.SelectedValue); if (!string.IsNullOrEmpty(cbCargo.SelectedValue)) { oModel.Cargo = int.Parse(cbCargo.SelectedValue); } oModel = oNegocios.Salvar(oModel); Funcionario_Id.Value = oModel.Codigo.ToString(); ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "SUCESSbtnSalvar_Click", "$(document).MensagemModal(1,'Registro salvo com <strong>sucesso</strong>!');", true); } } catch (Exception ex) { ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "ERROR", "$(document).MensagemModal(3,'Ocorreu um erro inesperado! Mensagem = " + new JavaScriptSerializer().Serialize(ex.Message.ToString()) + "');", true); } }