public int GetClientes(Entidades ENTI) { if (!Regex.IsMatch(ENTI.Cedula, "^[0-9]+[0-9]+[0-9]-[0-9]+[0-9]+[0-9]+[0-9]+[0-9]+[0-9]-[0-9]$")) { throw new Control("La cedula no cumple con el formato correcto"); } if (string.IsNullOrEmpty(ENTI.Nombre)) { throw new Control("El Nombre esta Vacio!!"); } if (string.IsNullOrEmpty(ENTI.Apellido)) { throw new Control("El Apellido esta Vacio!!"); } if (string.IsNullOrEmpty(ENTI.Telefono)) { throw new Control("El Telefono esta Vacio!!"); } if (string.IsNullOrEmpty(ENTI.Direccion)) { throw new Control("El Direccion esta Vacio!!"); } return new Datos().InsertarCli(ENTI); }
private void btn_Agregar_Click(object sender, EventArgs e) { Entidades ENTI = new Entidades() { Cedula = msk_Cedula.Text, Nombre = txt_Nombre.Text, Apellido = txt_Apellido.Text, Telefono = txt_Tel.Text, Direccion = txt_Direccion.Text }; try { if (edition == false) { if (new Logica().GetClientes(ENTI) != 0) { MessageBox.Show("Regiostro Exitoso"); Grid_Clientes.DataSource = new Logica().llenarDataGrid(); msk_Cedula.Clear(); txt_Nombre.Clear(); txt_Apellido.Clear(); txt_Tel.Clear(); txt_Direccion.Clear(); } } else { if(new Logica().actualizar(ID,ENTI) != 0) { MessageBox.Show("Registro Actualizado"); Grid_Clientes.DataSource = new Logica().llenarDataGrid(); msk_Cedula.Clear(); txt_Nombre.Clear(); txt_Apellido.Clear(); txt_Tel.Clear(); txt_Direccion.Clear(); edition = false; } } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public Entidades EditarCli(int id) { const string query = "SELECT * FROM CLIENTE WHERE ID_CLIENTE = @ID_CLIENTE"; var enti = new Entidades(); using (_comando = new SqlCommand()) { _comando.CommandType = CommandType.Text; _comando.CommandText = query; _comando.Connection = _conexion.ObtenerConexion(); _comando.Parameters.AddWithValue("@ID_CLIENTE", id); try { _conexion.ObtenerConexion().Open(); _reader = _comando.ExecuteReader(); while (_reader.Read()) { enti = new Entidades { Cedula = _reader["CEDULA"].ToString(), Nombre = _reader["NOMBRE"].ToString(), Apellido = _reader["APELLIDO"].ToString(), Telefono = _reader["TELEFONO"].ToString(), Direccion = _reader["DIRECCION"].ToString() }; } _reader.Close(); } finally { if (_conexion.ObtenerConexion().State == ConnectionState.Open) { _conexion.ObtenerConexion().Close(); } } return enti; } }
public int actualizar(int ID,Entidades ENTI) { return new Datos().Update(ID,ENTI); }
public int Update(int id,Entidades enti) { const string query = "UPDATE CLIENTE SET CEDULA=@CEDULA,NOMBRE=@NOMBRE,APELLIDO=@APELLIDO,TELEFONO=@TELEFONO,DIRECCION=@DIRECCION WHERE ID_CLIENTE=@ID_CLIENTE"; using (_comando = new SqlCommand()) { _comando.CommandType = CommandType.Text; _comando.CommandText = query; _comando.Connection = _conexion.ObtenerConexion(); //PARAMETROS _comando.Parameters.AddWithValue("@CEDULA", enti.Cedula); _comando.Parameters.AddWithValue("@NOMBRE", enti.Nombre); _comando.Parameters.AddWithValue("@APELLIDO", enti.Apellido); _comando.Parameters.AddWithValue("@TELEFONO", enti.Telefono); _comando.Parameters.AddWithValue("@DIRECCION", enti.Direccion); _comando.Parameters.AddWithValue("@ID_CLIENTE",id); int resultado; try { _conexion.ObtenerConexion().Open(); resultado = _comando.ExecuteNonQuery(); } finally { if (_conexion.ObtenerConexion().State == ConnectionState.Open) { _conexion.ObtenerConexion().Close(); } } return resultado; } }
public int InsertarCli(Entidades enti) { if (enti == null) throw new ArgumentNullException("enti"); using(_comando = new SqlCommand()) { const string query = "INSERT INTO CLIENTE(CEDULA,NOMBRE,APELLIDO,TELEFONO,DIRECCION) VALUES(@CEDULA,@NOMBRE,@APELLIDO,@TELEFONO,@DIRECCION)"; _comando.CommandText = query; _comando.CommandType = CommandType.Text; _comando.Connection = _conexion.ObtenerConexion(); _comando.Parameters.AddWithValue("@CEDULA",enti.Cedula); _comando.Parameters.AddWithValue("@NOMBRE", enti.Nombre); _comando.Parameters.AddWithValue("@APELLIDO", enti.Apellido); _comando.Parameters.AddWithValue("@TELEFONO", enti.Telefono); _comando.Parameters.AddWithValue("@DIRECCION", enti.Direccion); int result; try { _conexion.ObtenerConexion().Open(); result = _comando.ExecuteNonQuery(); } finally { if (_conexion.ObtenerConexion().State == ConnectionState.Open) { _conexion.ObtenerConexion().Close(); } } return result; } }