private void TraerDiagnosticos() { try { var _listObj = (from M in _Mod.MED_Diagnosticos select M).OrderBy(x => x.Diagnostico).ToList(); MED_Diagnosticos _itemSeleccion = new MED_Diagnosticos(); //Limpia el combo comboBoxDiagnostico.SuspendLayout(); comboBoxDiagnostico.DataSource = null; comboBoxDiagnostico.Items.Clear(); // Carga el item de Seleccion _itemSeleccion.Diagnostico = "<Seleccione un Diagnóstico>"; _itemSeleccion.diagnostico_id = 0; _listObj.Insert(0, _itemSeleccion); //Carga el combo comboBoxDiagnostico.DisplayMember = "Diagnostico"; comboBoxDiagnostico.ValueMember = "diagnostico_id"; comboBoxDiagnostico.DataSource = _listObj.ToArray(); comboBoxDiagnostico.SelectedIndex = 0; comboBoxDiagnostico.ResumeLayout(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void btnGuardar_Click(object sender, EventArgs e) { try { if (txtDiagnostico.Text == string.Empty) { MessageBox.Show("Debe ingresar un diagnostico", "Alerta", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { SISTMEDEntities E = new SISTMEDEntities(); MED_Diagnosticos _item = new MED_Diagnosticos(); _item.Diagnostico = txtDiagnostico.Text; E.Entry(_item).State = System.Data.Entity.EntityState.Added; E.SaveChanges(); Opener.ActualizaDiagnosticos(); this.Close(); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }