private void txProntuario_KeyDown(object sender, KeyEventArgs e) { try { if (e.KeyCode == Keys.Enter) { if (txProntuario.Text.Equals("")) { txNome.ReadOnly = false; this.ActiveControl = txNome; } else { if (PesquisaProntuarioUsuarioFireBird(txProntuario.Text.PadLeft(7,'0'))) { string prontuario = txProntuario.Text.PadLeft(7, '0'); txProntuario.Clear(); txProntuario.Text = prontuario; PreencheCamposProntuarioFireBird(txProntuario.Text); PreencheCamposNomeSqlServer(txNome.Text); } else if (PesquisaProntuarioUsuarioSQLServer(txProntuario.Text)) { USUARIOTableAdapter user = new USUARIOTableAdapter(); DataTable tabela = user.RetornaDataTableUsuarioPorProntuario(txProntuario.Text); if (tabela.Rows.Count > 1) { MessageBox.Show("Mais de um usuario com o mesmo prontuario, procure pelo nome!"); this.ActiveControl = txNome; txNome.ReadOnly = false; } else if (tabela.Rows.Count == 1) { txNome.Text = tabela.Rows[0]["NOME"].ToString(); PreencheCamposNomeSqlServer(txNome.Text); } else { MessageBox.Show("Prontuario não localizado, procure pelo nome"); this.ActiveControl = txNome; } } else { txNome.ReadOnly = false; this.ActiveControl = txNome; MessageBox.Show("Prontuario não encontrado procure pelo nome ou cadastre novo!"); } } } } catch (Exception err) { MessageBox.Show(err.Message); } }
private void PreencheCamposNomeSqlServer(string nome) { USUARIOTableAdapter user = new USUARIOTableAdapter(); DataTable _tabela = new DataTable(); //string nome = "%" + txNome.Text.Substring(0, (int)(txNome.Text.Length / 2)) + "%"; if (txNome.Text.Equals("")) _tabela = user.RetornaDataTableUsuarioPorProntuario(txProntuario.Text); else _tabela = user.RetornaDataTableUsuarioPorNome(nome); if (_tabela.Rows.Count < 1) { MessageBox.Show("Nome não encontrado no sistema. Por favor confirme os dados."); LiberaCampos(); this.ActiveControl = DataNascimento; btnConfirmar.Text = "Incluir - F10"; btnConfirmar.Enabled = true; } else if (_tabela.Rows.Count == 1) { DataRow linha = _tabela.Rows[0]; if (!linha["NOME"].ToString().Equals("") && txNome.Text.Equals("")) txNome.Text = linha["NOME"].ToString(); if (!linha["CPF"].ToString().Equals("")) txCPF.Text = linha["CPF"].ToString(); if (!linha["CARTAOSUS"].ToString().Equals("")) txCartaoSus.Text = linha["CARTAOSUS"].ToString(); if (!linha["CEP"].ToString().Equals("")) txCep.Text = linha["CEP"].ToString(); if (!linha["ENDNUMERO"].ToString().Equals("")) txNumero.Text = linha["ENDNUMERO"].ToString(); if (!linha["ENDCOMPLEMENTO"].ToString().Equals("")) txComplemento.Text = linha["ENDCOMPLEMENTO"].ToString(); if (!linha["DTNASCIMENTO"].ToString().Equals("")) DataNascimento.Value = (DateTime)linha["DTNASCIMENTO"]; if (!txCep.Text.Equals("")) PreencheCamposPorCEP(int.Parse(txCep.Text)); if (!linha["NOMEMAE"].ToString().Equals("")) txNomeMae.Text = linha["NOMEMAE"].ToString(); if (!linha["TELFIXO"].ToString().Equals("")) txTelFixo.Text = linha["TELFIXO"].ToString(); if (!linha["TELCEL"].ToString().Equals("")) txTelCelular.Text = linha["TELCEL"].ToString(); if (linha["TIPOUSUARIO"].ToString().Equals("1")) RadioAgudo.Checked = true; else if (linha["TIPOUSUARIO"].ToString().Equals("2")) RadioCronico.Checked = true; txIDUsuario.Text = linha["IDUSUARIO"].ToString(); BloqueiaItens(); LiberaCamposAlteracao(); btnConfirmar.Text = "Confirmar - F10"; this.btnConfirmar.Image = global::SISHOMEROGIL.Properties.Resources.confirmar; btnConfirmar.Enabled = true; MessageBox.Show("Por favor confirme os dados!"); this.ActiveControl = btnConfirmar; } else { MessageBox.Show("Mais de um prontuário localizado, verifique pelo nome"); LimpaFormulario(); txNome.ReadOnly = false; this.ActiveControl = txNome; } }