예제 #1
0
        protected override void btnModificar_Click(object sender, EventArgs e)
        {
            frmPersona frm = new frmPersona(/*params*/);

            frm.StartPosition = FormStartPosition.CenterScreen;
            try
            {
                int j = this.lstVisor.SelectedIndex;
                frm.txtNombre.Text   = dataTable.Rows[j][1].ToString();
                frm.txtApellido.Text = dataTable.Rows[j][2].ToString();
                frm.txtEdad.Text     = dataTable.Rows[j][3].ToString();
                frm.ShowDialog();
                if (frm.DialogResult == DialogResult.OK)
                {
                    dataTable.Rows[j][1] = frm.txtNombre.Text;
                    dataTable.Rows[j][2] = frm.txtApellido.Text;
                    dataTable.Rows[j][3] = frm.txtEdad.Text;
                    this.lstVisor.Items.Clear();
                    for (int i = 0; i < dataTable.Rows.Count; i++)
                    {
                        lstVisor.Items.Add(dataTable.Rows[i][0].ToString() + dataTable.Rows[i][1].ToString() + dataTable.Rows[i][2].ToString() + dataTable.Rows[i][3].ToString());
                    }
                }
            }
            catch
            {
                btnModificar.Enabled = false;
            }

            //implementar
        }
        protected virtual void btnModificar_Click(object sender, EventArgs e)
        {
            int        indice = this.lstVisor.SelectedIndex;
            frmPersona frm    = new frmPersona(this.lista[indice]);

            frm.StartPosition = FormStartPosition.CenterScreen;
            frm.ShowDialog();
            if (frm.DialogResult == DialogResult.OK)
            {
                this.lista[indice] = frm.Persona;
                try
                {
                    SqlConnection conexion = new SqlConnection(Properties.Settings.Default.conexion);
                    conexion.Open();
                    SqlCommand cmb = new SqlCommand();
                    cmb.Connection  = conexion;
                    cmb.CommandType = CommandType.Text;
                    cmb.CommandText = "UPDATE Personas SET nombre='" + frm.Persona.nombre + "',apellido='" + frm.Persona.apellido + "',edad=" + frm.Persona.edad + "WHERE id=" + (indice + 1);
                    cmb.ExecuteNonQuery();
                    conexion.Close();
                }
                catch (Exception exp)
                {
                    MessageBox.Show(exp.Message);
                }
            }
            ActualizarLista();
        }
예제 #3
0
        protected virtual void btnModificar_Click(object sender, EventArgs e)
        {
            frmPersona frm = new frmPersona(this.lista[this.lstVisor.SelectedIndex]);
            int        id;

            id = this.GetId(frm.Persona);
            frm.StartPosition = FormStartPosition.CenterScreen;
            frm.ShowDialog();
            if (frm.DialogResult == DialogResult.OK)
            {
                this.lista[this.lstVisor.SelectedIndex] = frm.Persona;
                try
                {
                    conexion.Open();
                    System.Data.SqlClient.SqlCommand comando = new System.Data.SqlClient.SqlCommand();
                    comando.Connection  = conexion;
                    comando.CommandType = CommandType.Text;
                    comando.CommandText = "Update Personas set nombre='" + frm.Persona.nombre + "',apellido='" + frm.Persona.apellido + "',edad=" + frm.Persona.edad + "where id=" + id;
                    comando.ExecuteNonQuery();
                    conexion.Close();
                }
                catch (Exception f)
                {
                    throw f;
                }
                this.ActualizarLista();

                //implementar
            }
        }
        protected virtual void btnEliminar_Click(object sender, EventArgs e)
        {
            frmPersona frm = new frmPersona();

            frm.StartPosition = FormStartPosition.CenterScreen;
            try
            {
                int j = this.lstVisor.SelectedIndex;
                frm.txtNombre.Text      = this.lista[j].nombre;
                frm.txtApellido.Text    = this.lista[j].apellido;
                frm.txtEdad.Text        = this.lista[j].edad.ToString();
                frm.txtNombre.Enabled   = false;
                frm.txtApellido.Enabled = false;
                frm.txtEdad.Enabled     = false;
                frm.ShowDialog();
                if (frm.DialogResult == DialogResult.OK)
                {
                    this.lista.RemoveAt(j);
                    this.lstVisor.Items.Clear();
                    for (int i = 0; i < lista.Count; i++)
                    {
                        this.lstVisor.Items.Add(lista[i].ToString());
                    }
                }
            }
            catch
            {
                btnEliminar.Enabled = false;
            }
            //implementar
        }
예제 #5
0
        protected void btnAgregar_Click(object sender, EventArgs e)
        {
            frmPersona frm = new frmPersona();

            frm.StartPosition = FormStartPosition.CenterScreen;


            //implementar
            frm.ShowDialog();
            lstVisor.Items.Clear();

            if (frm.DialogResult == DialogResult.OK)
            {
                listaAux.Add(frm.Persona);
                ActualizarLista();

                //bd
                SqlCommand    comando = new SqlCommand();
                SqlConnection sql     = new SqlConnection(Properties.Settings.Default.conexion);

                sql.Open();
                comando.Connection = sql;

                comando.CommandType = CommandType.Text;

                comando.CommandText = $"INSERT INTO Personas(nombre,apellido,edad) VALUES('{frm.Persona.nombre}','{frm.Persona.apellido}',{frm.Persona.edad})";
                comando.ExecuteNonQuery();
                //TEXTO Q SE LE PASA AL COMMAND TEXT values('COMILLAS SIMPLES EN LOS STRING','APELLIDO',31) // listado dentro de un try catch
                //PROBLEMA: CONCATENAR CADENA..

                comando.Connection.Close();
            }
        }
예제 #6
0
        protected virtual void btnAgregar_Click(object sender, EventArgs e)
        {
            frmPersona frm = new frmPersona();

            frm.StartPosition = FormStartPosition.CenterScreen;
            frm.ShowDialog();
            if (frm.DialogResult == DialogResult.OK)
            {
                try
                {
                    using (this.conexionSql = new SqlConnection(Properties.Settings.Default.Conexion))
                    {
                        conexionSql.Open();
                        SqlCommand command = new SqlCommand();
                        command.Connection  = this.conexionSql;
                        command.CommandType = CommandType.Text;
                        command.CommandText = "INSERT INTO personas([nombre], [apellido], [edad]) VALUES (@nombre, @apellido, @edad)";
                        command.Parameters.AddWithValue("@nombre", frm.Persona.nombre);
                        command.Parameters.AddWithValue("@apellido", frm.Persona.apellido);
                        command.Parameters.AddWithValue("@edad", frm.Persona.Edad);
                        command.ExecuteNonQuery();
                    }
                }
                catch (Exception excep)
                {
                    MessageBox.Show(excep.Message);
                }

                this.listaAux.Add(frm.Persona);
                this.cargarListBox();
            }
        }
예제 #7
0
        protected virtual void btnAgregar_Click(object sender, EventArgs e)
        {
            frmPersona frm = new frmPersona();

            frm.StartPosition = FormStartPosition.CenterScreen;

            //implementar
            frm.ShowDialog();
            if (frm.DialogResult == DialogResult.OK)
            {
                StringBuilder str      = new StringBuilder();
                SqlCommand    cmd      = new SqlCommand();
                SqlConnection conexion = new SqlConnection(Properties.Settings.Default.Conexion);
                conexion.Open();
                this.listaPersonas.Add(frm.Persona);
                this.lstVisor.Items.Add(frm.Persona);
                try
                {
                    str.AppendFormat("insert into Personas(nombre,apellido,edad) values ('{0}','{1}','{2}')", frm.Persona.nombre, frm.Persona.apellido, frm.Persona.edad);
                    cmd.Connection  = conexion;
                    cmd.CommandType = CommandType.Text;
                    cmd.CommandText = str.ToString();
                    cmd.ExecuteNonQuery();
                    conexion.Close();
                }
                catch (Exception x)
                {
                    conexion.Close();
                    MessageBox.Show(x.Message);
                }
            }
        }
예제 #8
0
        protected virtual void btnModificar_Click(object sender, EventArgs e)
        {
            int        selectedIndex;
            Persona    auxPersona = this.listaAux[this.lstVisor.SelectedIndex];
            frmPersona frm        = new frmPersona(auxPersona);

            frm.StartPosition = FormStartPosition.CenterScreen;
            frm.ShowDialog();
            if (frm.DialogResult == DialogResult.OK)
            {
                selectedIndex = this.lstVisor.SelectedIndex;
                auxPersona    = this.listaAux[this.lstVisor.SelectedIndex];

                this.conexion = new SqlConnection(Properties.Settings.Default.Conexion);
                this.conexion.Open();
                this.comando             = new SqlCommand();
                this.comando.Connection  = this.conexion;
                this.comando.CommandType = CommandType.Text;

                this.comando.CommandText = "UPDATE personas SET [nombre] = @nombre, [apellido] = @apellido, [edad] = @edad WHERE nombre = @nombre2 AND [apellido] = @apellido2 AND [edad] = @edad2";
                this.comando.Parameters.AddWithValue("@nombre", frm.Persona.nombre);
                this.comando.Parameters.AddWithValue("@apellido", frm.Persona.apellido);
                this.comando.Parameters.AddWithValue("@edad", frm.Persona.edad);
                this.comando.Parameters.AddWithValue("@nombre2", auxPersona.nombre);
                this.comando.Parameters.AddWithValue("@apellido2", auxPersona.apellido);
                this.comando.Parameters.AddWithValue("@edad2", auxPersona.edad);
                this.comando.ExecuteNonQuery();
                this.listaAux[selectedIndex] = frm.Persona;
                this.cargarListBox();
            }
        }
예제 #9
0
        protected virtual void btnEliminar_Click(object sender, EventArgs e)
        {
            this.btnModificar.Click -= new System.EventHandler(this.btnModificar_Click);
            this.btnEliminar.Click  -= new System.EventHandler(this.btnEliminar_Click);

            Persona    aux = listaAux[this.lstVisor.SelectedIndex];
            frmPersona frm = new frmPersona(aux.apellido, aux.nombre, aux.Edad);

            frm.StartPosition = FormStartPosition.CenterScreen;
            frm.ShowDialog();
            if (frm.DialogResult == DialogResult.OK)
            {
                try
                {
                    using (this.conexionSql = new SqlConnection(Properties.Settings.Default.Conexion))
                    {
                        conexionSql.Open();
                        SqlCommand command = new SqlCommand();
                        command.Connection  = this.conexionSql;
                        command.CommandType = CommandType.Text;
                        command.CommandText = "DELETE FROM personas WHERE id = " + aux.id + "";
                        command.ExecuteNonQuery();
                    }
                }
                catch (Exception excep)
                {
                    MessageBox.Show(excep.Message);
                }

                listaAux.Remove(aux);
            }
            this.cargarListBox();
        }
        protected virtual void btnAgregar_Click(object sender, EventArgs e)
        {
            try
            {
                frmPersona frm = new frmPersona();
                frm.StartPosition = FormStartPosition.CenterScreen;
                frm.ShowDialog();
                //implementar

                if (frm.DialogResult == DialogResult.OK)
                {
                    this.listaPersonas.Add(frm.Persona);
                    this.lstVisor.Items.Add(frm.Persona.ToString());
                }

                SqlConnection sqlC = new SqlConnection(Properties.Settings.Default.conexion);
                sqlC.Open();

                SqlCommand command = new SqlCommand();

                command.Connection  = sqlC;
                command.CommandType = CommandType.Text;
                command.CommandText = "INSERT INTO [personas_bd].[dbo].[personas] ([nombre],[apellido],[edad]) VALUES (@param1,@param2,@param3)";
                command.Parameters.AddWithValue("@param1", frm.Persona.nombre);
                command.Parameters.AddWithValue("@param2", frm.Persona.apellido);
                command.Parameters.AddWithValue("@param3", frm.Persona.edad);
                command.ExecuteNonQuery();

                sqlC.Close();
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message);
            }
        }
예제 #11
0
        protected virtual void btnAgregar_Click(object sender, EventArgs e)
        {
            frmPersona frm = new frmPersona();

            frm.StartPosition = FormStartPosition.CenterScreen;
            frm.ShowDialog();
            if (frm.DialogResult == DialogResult.OK)
            {
                this.listaAux.Add(frm.Persona);
                this.cargarListBox();

                this.conexion = new SqlConnection(Properties.Settings.Default.Conexion);
                this.conexion.Open();
                this.comando             = new SqlCommand();
                this.comando.Connection  = this.conexion;
                this.comando.CommandType = CommandType.Text;

                this.comando.CommandText = "INSERT INTO personas ([nombre],[apellido],[edad]) VALUES(@nombre,@apellido,@edad)";
                this.comando.Parameters.AddWithValue("@nombre", frm.Persona.nombre);
                this.comando.Parameters.AddWithValue("@apellido", frm.Persona.apellido);
                this.comando.Parameters.AddWithValue("@edad", Convert.ToInt32(frm.Persona.edad));
                this.comando.ExecuteNonQuery();
                this.conexion.Close();
            }
        }
예제 #12
0
 protected override void btnModificar_Click(object sender, EventArgs e)
 {
     try
     {
         int        personaListIndex = this.lstVisor.SelectedIndex;
         int        dataRowIndex     = this.GetPersonRowIndex(personaListIndex);
         DataRow    fila             = this.tabla.Rows[dataRowIndex];
         frmPersona frmPersona       = new frmPersona(this.misPersonas[personaListIndex]);
         frmPersona.ShowDialog();
         if (frmPersona.DialogResult == DialogResult.OK)
         {
             fila[1] = frmPersona.Persona.nombre;
             fila[2] = frmPersona.Persona.apellido;
             fila[3] = frmPersona.Persona.edad.ToString();
             this.misPersonas[personaListIndex].nombre   = frmPersona.Persona.nombre;
             this.misPersonas[personaListIndex].apellido = frmPersona.Persona.apellido;
             this.misPersonas[personaListIndex].edad     = frmPersona.Persona.edad;
             this.ActualizarLista();
         }
     }
     catch (Exception x)
     {
         MessageBox.Show(x.Message + "\nEn metodo btnModificar_Click.");
     }
 }
예제 #13
0
        protected virtual void btnModificar_Click(object sender, EventArgs e)
        {
            frmPersona frm = new frmPersona((Persona)lstVisor.SelectedItem);

            frm.StartPosition = FormStartPosition.CenterScreen;
            this.sql.Open();
            frm.ShowDialog();

            if (frm.DialogResult == DialogResult.OK)
            {
                this.lstVisor.SelectedItem = frm.Persona;

                try
                {
                    StringBuilder sb = new StringBuilder();
                    sb.AppendFormat("update Personas set nombre='{0}',apellido='{1}',edad={2} where id={3}", frm.Persona.nombre, frm.Persona.apellido, frm.Persona.edad, this.lstVisor.SelectedIndex + 1);
                    SqlCommand com = new SqlCommand();
                    com.Connection  = this.sql;
                    com.CommandType = CommandType.Text;
                    com.CommandText = sb.ToString();
                    com.ExecuteNonQuery();
                }
                catch (Exception x)
                {
                    MessageBox.Show(x.ToString());
                }
            }

            this.sql.Close();
            this.ActualizarLista();
        }
예제 #14
0
        protected virtual void btnAgregar_Click(object sender, EventArgs e)
        {
            frmPersona frm = new frmPersona();

            frm.StartPosition = FormStartPosition.CenterScreen;
            frm.ShowDialog();
            if (frm.DialogResult == DialogResult.OK)
            {
                listaPersonas.Add(frm.Persona);
                // lstVisor.Items.Add(frm.Persona);
                SqlConnection sql = new SqlConnection(Properties.Settings.Default.Conexion);
                sql.Open();

                SqlCommand com = new SqlCommand();
                com.Connection  = sql;
                com.CommandType = CommandType.Text;
                StringBuilder sb = new StringBuilder();
                sb.AppendFormat("Insert into Personas(nombre,apellido,edad) values('{0}','{1}','{2}')", frm.Persona.nombre, frm.Persona.apellido, frm.Persona.edad);
                com.CommandText = sb.ToString();
                com.ExecuteNonQuery();

                sql.Close();
            }
            this.ActualizarLista();
        }
예제 #15
0
        protected virtual void btnAgregar_Click(object sender, EventArgs e)
        {
            frmPersona frm = new frmPersona();

            frm.StartPosition = FormStartPosition.CenterScreen;
            frm.ShowDialog();
            if (frm.DialogResult == DialogResult.OK)
            {
                this.lista.Add(frm.Persona);
                ActualizarLista();

                try
                {
                    conexion.Open();
                    System.Data.SqlClient.SqlCommand comando = new System.Data.SqlClient.SqlCommand();
                    comando.Connection  = conexion;
                    comando.CommandType = CommandType.Text;
                    comando.CommandText = "Insert into Personas(nombre,apellido,edad) values('" + frm.Persona.nombre + "','" + frm.Persona.apellido + "'," + frm.Persona.edad + ')';
                    comando.ExecuteNonQuery();
                    conexion.Close();
                }
                catch (Exception f)
                {
                    throw f;
                }
            }
        }
        protected virtual void btnAgregar_Click(object sender, EventArgs e)
        {
            frmPersona frm = new frmPersona();

            frm.StartPosition = FormStartPosition.CenterScreen;
            frm.ShowDialog();
            if (frm.DialogResult == DialogResult.OK)
            {
                this.lista.Add(frm.Persona);
                try
                {
                    SqlConnection conexion = new SqlConnection(Properties.Settings.Default.conexion);
                    conexion.Open();
                    SqlCommand cmb = new SqlCommand();
                    cmb.Connection  = conexion;
                    cmb.CommandType = CommandType.Text;
                    cmb.CommandText = "INSERT INTO Personas(nombre,apellido,edad)VALUES('" + frm.Persona.nombre + "','" + frm.Persona.apellido + "'," + frm.Persona.edad + ")";
                    cmb.ExecuteNonQuery();
                    conexion.Close();
                }
                catch (Exception exp)
                {
                    MessageBox.Show(exp.Message);
                }
            }
            ActualizarLista();
        }
예제 #17
0
        private void btnAgregar_Click(object sender, EventArgs e)
        {
            frmPersona frm = new frmPersona();

            frm.StartPosition = FormStartPosition.CenterScreen;

            frm.ShowDialog();
            if (frm.DialogResult == DialogResult.OK)
            {
                this.lista.Add(frm.Persona);
                this.ActualizarLista();
            }
        }
예제 #18
0
        protected virtual void btnModificar_Click(object sender, EventArgs e)
        {
            int        index = this.lstVisor.SelectedIndex;
            frmPersona frm   = new frmPersona(this.misPersonas.ElementAt(index));

            frm.Conexion      = this.Conexion;
            frm.StartPosition = FormStartPosition.CenterScreen;
            frm.ShowDialog();
            if (frm.DialogResult == DialogResult.OK)
            {
                this.misPersonas[index]    = frm.Persona;
                this.lstVisor.Items[index] = frm.Persona.ToString();
            }
        }
예제 #19
0
        private void btnModificar_Click(object sender, EventArgs e)
        {
            DataRow    row = this.dataTable.Rows[this.lstVisor.SelectedIndex];
            frmPersona frm = new frmPersona(new Entidades.Persona(row["nombre"].ToString(), row["apellido"].ToString(), int.Parse(row["edad"].ToString())));

            frm.ShowDialog();
            if (frm.DialogResult == DialogResult.OK)
            {
                row["nombre"]   = frm.Persona.nombre;
                row["apellido"] = frm.Persona.nombre;
                row["edad"]     = frm.Persona.nombre;
            }
            this.ActualizarLista();
        }
예제 #20
0
        protected override void btnModificar_Click(object sender, EventArgs e)
        {
            DataRow    fila       = this.tabla.Rows[this.lstVisor.SelectedIndex];
            frmPersona frmPersona = new frmPersona(new Persona(fila[1].ToString(), fila[2].ToString(), Convert.ToInt32(fila[3])));

            frmPersona.ShowDialog();
            if (frmPersona.DialogResult == DialogResult.OK)
            {
                fila["nombre"]   = frmPersona.Persona.nombre;
                fila["apellido"] = frmPersona.Persona.apellido;
                fila["edad"]     = frmPersona.Persona.edad;
                this.actualizarListBox();
            }
        }
예제 #21
0
        protected override void btnAgregar_Click(object sender, EventArgs e)
        {
            frmPersona frmPersona = new frmPersona();

            frmPersona.ShowDialog();
            if (frmPersona.DialogResult == DialogResult.OK)
            {
                DataRow fila = this.tabla.NewRow();
                fila["nombre"]   = frmPersona.Persona.nombre;
                fila["apellido"] = frmPersona.Persona.apellido;
                fila["edad"]     = frmPersona.Persona.edad;
                this.tabla.Rows.Add(fila);
                this.actualizarListBox();
            }
        }
        private void btnAgregar_Click(object sender, EventArgs e)
        {
            frmPersona frm = new frmPersona();

            frm.StartPosition = FormStartPosition.CenterScreen;
            frm.ShowDialog();

            if (frm.DialogResult == DialogResult.OK)
            {
                this.lstVisor.Items.Clear();
                this.listaAux.Add(frm.Persona);
                this.lstVisor.Items.Clear();
                this.MostrarLista(this.listaAux);
            }
        }
        protected override void btnModificar_Click(object sender, EventArgs e)
        {
            DataRow    datafile = this.datatable.Rows[this.lstVisor.SelectedIndex];
            frmPersona frm      = new frmPersona(new Entidades.Persona(datafile["nombre"].ToString(), datafile["apellido"].ToString(), int.Parse(datafile["edad"].ToString())));

            frm.ShowDialog();
            if (frm.DialogResult == DialogResult.OK)
            {
                datafile["nombre"]   = frm.Persona.nombre;
                datafile["apellido"] = frm.Persona.apellido;
                datafile["edad"]     = frm.Persona.edad;
            }

            this.ActualizarLista();
        }
        protected override void btnEliminar_Click(object sender, EventArgs e)
        {
            this.btnModificar.Click -= new EventHandler(btnModificar_Click);
            this.btnEliminar.Click  -= new EventHandler(btnEliminar_Click);
            int        indice = this.lstVisor.SelectedIndex;
            DataRow    fila   = this.data.Rows[indice];
            frmPersona frm    = new frmPersona(new Entidades.Persona(fila["nombre"].ToString(), fila["apellido"].ToString(), int.Parse(fila["edad"].ToString())));

            frm.ShowDialog();
            if (frm.DialogResult == DialogResult.OK)
            {
                fila.Delete();
            }
            ActualizarLista();
        }
        protected override void btnAgregar_Click(object sender, EventArgs e)
        {
            frmPersona frm = new frmPersona();

            frm.ShowDialog();
            if (frm.DialogResult == DialogResult.OK)
            {
                DataColumnCollection columnas = datatable.Columns;
                DataRow           fila        = datatable.NewRow();
                DataRowCollection datrow      = datatable.Rows;
                fila[columnas[1]] = frm.Persona.nombre;
                fila[columnas[2]] = frm.Persona.apellido;
                fila[columnas[3]] = frm.Persona.edad;
                this.ActualizarLista();
            }
        }
예제 #26
0
        private void btnModificar_Click_1(object sender, EventArgs e)
        {
            DataRow datoFila = this.dataTable.Rows[this.lstVisor.SelectedIndex];

            frmPersona frmPers = new frmPersona(new Entidades.Persona(datoFila["nombre"].ToString(), datoFila["apellido"].ToString(), Convert.ToInt32(datoFila["edad"].ToString())));

            frmPers.ShowDialog();

            if (frmPers.DialogResult == DialogResult.OK)
            {
                datoFila["nombre"]   = frmPers.Persona.nombre;
                datoFila["apellido"] = frmPers.Persona.apellido;
                datoFila["edad"]     = frmPers.Persona.edad;
            }
            this.RefrescarLista();
        }
예제 #27
0
        private void btnAgregar_Click_1(object sender, EventArgs e)
        {
            frmPersona frmPers = new frmPersona();

            frmPers.ShowDialog();

            if (frmPers.DialogResult == DialogResult.OK)
            {
                DataRow row = dataTable.NewRow();

                row["nombre"]   = frmPers.Persona.nombre;
                row["apellido"] = frmPers.Persona.apellido;

                DataTable.Rows.Add(row);
            }
        }
예제 #28
0
        protected virtual void btnAgregar_Click(object sender, EventArgs e)
        {
            frmPersona frm = new frmPersona();

            if (this.conexion != null)
            {
                frm.Conexion = this.conexion;
            }
            frm.StartPosition = FormStartPosition.CenterScreen;
            frm.ShowDialog();
            if (frm.DialogResult == DialogResult.OK)
            {
                misPersonas.Add(frm.Persona);
                this.ActualizarLista();
            }
        }
        protected override void btnAgregar_Click(object sender, EventArgs e)
        {
            frmPersona frm = new frmPersona();

            frm.StartPosition = FormStartPosition.CenterScreen;
            frm.ShowDialog();
            if (frm.DialogResult == DialogResult.OK)
            {
                DataRow fila = this.data.NewRow();
                fila["nombre"]   = frm.Persona.nombre;
                fila["apellido"] = frm.Persona.apellido;
                fila["edad"]     = frm.Persona.edad;
                this.data.Rows.Add(fila);
            }
            ActualizarLista();
        }
예제 #30
0
        protected virtual void btnModificar_Click(object sender, EventArgs e)
        {
            //lo quito para q no lo repita por cada seleccion en la lista
            //this.btnModificar.Click -= new EventHandler(btnModificar_Click);



            if (!Object.Equals(this.lstVisor.SelectedItem, null))
            {
                StringBuilder str      = new StringBuilder();
                SqlCommand    cmd      = new SqlCommand();
                SqlConnection conexion = new SqlConnection(Properties.Settings.Default.Conexion);
                conexion.Open();

                frmPersona frm = new frmPersona((Persona)this.lstVisor.SelectedItem);
                frm.StartPosition = FormStartPosition.CenterScreen;

                //implementar
                frm.ShowDialog();
                if (frm.DialogResult == DialogResult.OK)
                {
                    this.lstVisor.SelectedItem = frm.Persona;
                    //this.ListaDePersonas.

                    try
                    {
                        str.AppendFormat("update Personas set nombre='{0}',apellido='{1}',edad={2} where id={3}", frm.Persona.nombre, frm.Persona.apellido, frm.Persona.edad, this.lstVisor.SelectedIndex + 1);
                        cmd.Connection  = conexion;
                        cmd.CommandType = CommandType.Text;
                        cmd.CommandText = str.ToString();
                        cmd.ExecuteNonQuery();
                        conexion.Close();
                    }
                    catch (Exception x)
                    {
                        conexion.Close();
                        MessageBox.Show(x.Message);
                    }
                }



                this.ActualizarLista();
            }
        }