public static ClienteModificar Instance() { if (frm == null) { frm = new ClienteModificar(); } return(frm); }
private void dgvClientes_KeyDown(object sender, KeyEventArgs e) { //Si el usuario presiona tecla enter... if (e.KeyCode == Keys.Enter) { //Aparecerá una ventana de confirmación DialogResult rs = MessageBox.Show("¿Desea modificar?", "MENSAJE", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation); { if (rs == DialogResult.Yes) { p = (Padre)this.MdiParent; ClienteModificar am = null; am = ClienteModificar.Instance(); am.MdiParent = p; am.StartPosition = FormStartPosition.CenterScreen; am.Show(); string rut = dgvClientes.CurrentRow.Cells[0].Value.ToString(); string rutsindv = null; string dv = null; string razon = null; string giro = null; string direccion = null; if (rut.Length == 12) { rutsindv = rut.Substring(0, 10).Replace(".", string.Empty).Trim(); dv = rut.Substring(11, 1).Trim(); } else if (rut.Length == 11) { rutsindv = rut.Substring(0, 9).Replace(".", string.Empty).Trim(); dv = rut.Substring(10, 1).Trim(); } SqlConnection miconexion = Consultas.conectarPrincipal(); miconexion.Open(); SqlCommand consulta = new SqlCommand("SELECT RAZON, GIRO, DIRECCION FROM CLIENTES WHERE RUT = @rut AND DIG = @dv", miconexion); consulta.Parameters.Add(new SqlParameter("@rut", rutsindv)); consulta.Parameters.Add(new SqlParameter("@dv", dv)); SqlDataReader reader = consulta.ExecuteReader(); if (reader.Read()) { razon = reader.GetString(0); giro = reader.GetString(1); direccion = reader.GetString(2); } am.lblMRut.Text = rut; am.txtMRazon.Text = razon.Trim(); am.txtMGiro.Text = giro.Trim(); am.txtMDireccion.Text = direccion.Trim(); am.WindowState = FormWindowState.Normal; am.Activate(); this.Dispose(); } } } }