private void btnOk_Click(object sender, EventArgs e) { if (dgvClientes.CurrentRow != null) { int escolhido_id = Convert.ToInt32(dgvClientes.CurrentRow.Cells["id"].Value.ToString()); using (hotelEntities ef = new hotelEntities()) { this.escolhido = ef.cliente.Find(escolhido_id); } this.DialogResult = DialogResult.OK; } else { MessageBox.Show( "Nenhum cliente foi selecionado!", "Pesquisar Cliente", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private bool checarCampos(out cliente c) { string primeiroNome = "", ultimoNome = "", DocRg = "", DocCpf = ""; DateTime dtNasc = DateTime.MinValue; string mensagem = ""; if (txtPrimeiroNome.Text.Equals("")) { mensagem += "Primeiro Nome\n"; } else { primeiroNome = txtPrimeiroNome.Text; } if (txtUltimoNome.Text.Equals("")) { mensagem += "Último Nome\n"; } else { ultimoNome = txtUltimoNome.Text; } if (txtRG.Text.Length < 12) { mensagem += "RG\n"; } else { DocRg = txtRG.Text; } if (txtCPF.Text.Length < 14) { mensagem += "CPF\n"; } else { DocCpf = txtCPF.Text; } if (!txtDtNasc.Text.Equals("")) { if (!DateTime.TryParse(txtDtNasc.Text, out dtNasc)) { mensagem += "Data de Nascimento"; } } //Mostrar Mensagem de Erro if (!mensagem.Equals("")) { MessageBox.Show( "As seguintes informações estão inválidas: " + mensagem, "Salvar Novo Cliente", MessageBoxButtons.OK, MessageBoxIcon.Error); c = null; return(false); } else { c = new cliente(); c.primeiro_nome = primeiroNome; c.ultimo_nome = ultimoNome; c.doc_rg = DocRg; c.doc_cpf = DocCpf; c.dt_nasc = dtNasc; c.ativo = true; return(true); } }