public static string add_Persona(Persona p) { return "{" + '"' + "Activo" + '"' + ": " + (p.Activo ? "true" : "false") + ',' + '"' + "ApellidoMaterno" + '"' + ": " + '"' + p.ApellidoMaterno + '"' + ',' + '"' + "ApellidoPaterno" + '"' + ": " + '"' + p.ApellidoPaterno + '"' + ',' + '"' + "Celular" + '"' + ": " + p.Celular.ToString() + ',' + '"' + "Email" + '"' + ": " + '"' + p.Email + '"' + ',' + '"' + "FechaNacimiento" + '"' + ": " + '"' + Utils.dateToJson(p.FechaNacimiento) + '"' + ',' + '"' + "IdDireccion" + '"' + ": " + p.IdDireccion.ToString() + ',' + '"' + "IdPersona" + '"' + ": " + p.IdPersona.ToString() + ',' + '"' + "IdTipoDocumento" + '"' + ": " + p.IdTipoDocumento.ToString() + ',' + '"' + "IdTipoPersona" + '"' + ": " + p.IdTipoPersona.ToString() + ',' + '"' + "IdUsuario" + '"' + ": " + p.IdUsuario.ToString() + ',' + '"' + "Nombres" + '"' + ": " + '"' + p.Nombres + '"' + ',' + '"' + "NumeroDocumento" + '"' + ": " + p.NumeroDocumento.ToString() + ',' + '"' + "Sexo" + '"' + ": " + '"' + p.Sexo + '"' + ',' + '"' + "Telefono" + '"' + ": " + p.Telefono.ToString() + "}"; }
public List<Persona> selectAll_Persona() { try { List<Persona> personas = new List<Persona>(); Persona p; DataTable dt = new DataTable(); SqlDataAdapter sda = new SqlDataAdapter(); string ConnString = ConfigurationManager.ConnectionStrings["barabaresConnectionString"].ConnectionString; using (SqlConnection SqlConn = new SqlConnection(ConnString)) { try { SqlConn.Open(); } catch (Exception ex) { Debug.WriteLine(ex.ToString()); return personas; } SqlCommand sqlCmd = new SqlCommand("PERSONA_SELECT_ALL", SqlConn); sqlCmd.CommandType = CommandType.StoredProcedure; sda.SelectCommand = sqlCmd; sda.Fill(dt); SqlConn.Close(); sqlCmd.Dispose(); sda.Dispose(); } DataRow[] rows = dt.Select(); for (int i = 0; i < rows.Length; i++) { p = Utils.persona_parse(rows[i]); personas.Add(p); } return personas; } catch (Exception ex) { Persona p = new Persona(); LogBarabares b = new LogBarabares() { Accion = Constantes.LOG_LISTAR, Servicio = Constantes.SelectAll_Persona, Input = "", Descripcion = ex.ToString(), Clase = p.GetType().Name, Aplicacion = Constantes.ENTORNO_SERVICIOS, Estado = Constantes.FALLA, Ip = "", IdUsuario = 1 //TODO: obtener usuario de la sesión }; Utils.add_LogBarabares(b); return new List<Persona>(); } }
public static Persona persona_parse(DataRow r) { Persona p = new Persona(); p.IdPersona = Int32.Parse(r["idPersona"].ToString()); p.Nombres = r["nombres"].ToString(); p.ApellidoPaterno = r["apellidoPaterno"].ToString(); p.ApellidoMaterno = r["apellidoMaterno"].ToString(); p.Telefono = Int32.Parse(r["telefono"].ToString()); p.Celular = Int32.Parse(r["celular"].ToString()); p.Email = r["email"].ToString(); p.NumeroDocumento = Int32.Parse(r["numeroDocumento"].ToString()); p.FechaNacimiento = DateTime.ParseExact(r["fechaNacimiento"].ToString(), "M/d/yyyy h:mm:ss ttt", null); p.Sexo = r["sexo"].ToString()[0]; p.IdTipoDocumento = Int32.Parse(r["idTipoDocumento"].ToString()); p.IdTipoPersona = Int32.Parse(r["idTipoPersona"].ToString()); p.IdDireccion = Int32.Parse(r["idDireccion"].ToString()); p.Activo = Boolean.Parse(r["activo"].ToString()); p.IdUsuario = Int32.Parse(r["idUsuario"].ToString()); p.Imagen = r["imagen"].ToString(); return p; }
public ResponseBD add_Persona(Persona p) { try { ResponseBD response = new ResponseBD(); string ConnString = ConfigurationManager.ConnectionStrings["barabaresConnectionString"].ConnectionString; using (SqlConnection SqlConn = new SqlConnection(ConnString)) { try { SqlConn.Open(); } catch (Exception ex) { Debug.WriteLine(ex.ToString()); response.Flujo = Constantes.FALLA; response.Mensaje = "Error al abrir la conexión a BD"; return response; } SqlCommand sqlCmd = new SqlCommand("PERSONA_INSERT", SqlConn); sqlCmd.CommandType = CommandType.StoredProcedure; SqlParameter flujo = new SqlParameter("@opsFlujo", SqlDbType.VarChar) { Direction = ParameterDirection.Output, Size = 10 }; SqlParameter mensaje = new SqlParameter("@opsMsj", SqlDbType.VarChar) { Direction = ParameterDirection.Output, Size = 100 }; sqlCmd.Parameters.Add("@ipsNombres", SqlDbType.VarChar).Value = p.Nombres; sqlCmd.Parameters.Add("@ipsApellidoPaterno", SqlDbType.VarChar).Value = p.ApellidoPaterno; sqlCmd.Parameters.Add("@ipsApellidoMaterno", SqlDbType.VarChar).Value = p.ApellidoMaterno; sqlCmd.Parameters.Add("@ipnTelefono", SqlDbType.Int).Value = p.Telefono; sqlCmd.Parameters.Add("@ipnCelular", SqlDbType.Int).Value = p.Celular; sqlCmd.Parameters.Add("@ipsEmail", SqlDbType.VarChar).Value = p.Email; sqlCmd.Parameters.Add("@ipnNumeroDocumento", SqlDbType.Int).Value = p.NumeroDocumento; sqlCmd.Parameters.Add("@ipdFechaNacimiento", SqlDbType.DateTime).Value = p.FechaNacimiento; sqlCmd.Parameters.Add("@ipcSexo", SqlDbType.Char).Value = p.Sexo; sqlCmd.Parameters.Add("@ipnIdTipoPersona", SqlDbType.Int).Value = p.IdTipoPersona; sqlCmd.Parameters.Add("@ipnIdTipoDocumento", SqlDbType.Int).Value = p.IdTipoDocumento; sqlCmd.Parameters.Add("@ipnIdDireccion", SqlDbType.Int).Value = p.IdDireccion; sqlCmd.Parameters.Add("@ipbActivo", SqlDbType.Bit).Value = p.Activo; sqlCmd.Parameters.Add("@ipnIdUsuario", SqlDbType.Int).Value = p.IdUsuario; sqlCmd.Parameters.Add(flujo); sqlCmd.Parameters.Add(mensaje); sqlCmd.ExecuteNonQuery(); response.Flujo = flujo.Value.ToString(); response.Mensaje = mensaje.Value.ToString(); SqlConn.Close(); } return response; } catch (Exception ex) { LogBarabares b = new LogBarabares() { Accion = Constantes.LOG_CREAR, Servicio = Constantes.Add_Persona, Input = JsonSerializer.add_Persona(p), Descripcion = ex.ToString(), Clase = (p == null) ? "null" : p.GetType().Name, Aplicacion = Constantes.ENTORNO_SERVICIOS, Estado = Constantes.FALLA, Ip = "", IdUsuario = 1 //TODO: obtener usuario de la sesión }; Utils.add_LogBarabares(b); ResponseBD response = new ResponseBD(); response.Flujo = Constantes.FALLA; response.Mensaje = "Error al abrir la conexión a BD"; return response; } }