Beispiel #1
0
        private void btModificar_Click(object sender, EventArgs e)
        {
            //definir una variable para el DNI ojo deberia estar controlado
            //to do:

            try
            {
                string TextoDNI = txtDNI.Text;

                //mediante LINQ obtenemos el cliente
                CLIENTES MyCliente = (from c in ClientesEntity.CLIENTES
                                      where c.DNI == txtDNI.Text
                                      select c).Single();
                //definimos los atributos del objeto myCliente
                MyCliente.NOMBRE = txtNombres.Text;
                // MyCliente.DNI = txtDNI.Text;
                MyCliente.APELLIDOS        = txtApellidos.Text;
                MyCliente.ESTADO_CIVIL     = cbEstadocivil.Text;
                MyCliente.E_MAIL           = txtEmail.Text;
                MyCliente.TELEFONO         = txtTelefono.Text;
                MyCliente.FECHA_NACIMIENTO = dateTimePicker1.Value;

                //permanencia en base de datos salvado
                ClientesEntity.SaveChanges();
                cargarGrid();
                MessageBox.Show("Datos modificados correctamente");
            }
            catch
            {
                if (txtDNI.Text == "")
                {
                    MessageBox.Show("Introduzca el DNI para modificar ");
                }
            }
        }
Beispiel #2
0
        private void btagregar_Click(object sender, EventArgs e)
        {
            try
            {
                //boton para agregar registro
                //creamos un nuevo cliente con los contenidos de los textbox
                CLIENTES Misclientes = new CLIENTES()
                {
                    DNI              = txtDNI.Text,
                    NOMBRE           = txtNombres.Text,
                    APELLIDOS        = txtApellidos.Text,
                    ESTADO_CIVIL     = cbEstadocivil.Text,
                    E_MAIL           = txtEmail.Text,
                    TELEFONO         = txtTelefono.Text,
                    FECHA_NACIMIENTO = dateTimePicker1.Value
                };

                //llamamos al contexto de entidades y añadimos el objeto cliente
                ClientesEntity.CLIENTES.Add(Misclientes);

                //guardar el nuevo registro en la base de datos
                ClientesEntity.SaveChanges();

                //refrescamos datagrid
                cargarGrid();
                MessageBox.Show("Datos introducidos correctamente");
            }
            catch
            {
                if (txtDNI.Text == "" || txtNombres.Text == "" || txtApellidos.Text == "" || cbEstadocivil.Text == "" ||
                    txtEmail.Text == "" || txtTelefono.Text == "" || dateTimePicker1.Value.ToString() == "")
                {
                    MessageBox.Show("te falta algún dato por rellenar");
                }
                else
                {
                    MessageBox.Show("DNI duplicado");
                }
            }
        }