public List<Pedido> selectAll_Pedido() { try { List<Pedido> pedidos = new List<Pedido>(); Pedido p = new Pedido(); 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 pedidos; } SqlCommand sqlCmd = new SqlCommand("PEDIDO_SELECT_ALL", SqlConn); sqlCmd.CommandType = CommandType.StoredProcedure; sqlCmd.Parameters.Add("@ipsAccion", SqlDbType.VarChar).Value = Constantes.LOG_LISTAR; sqlCmd.Parameters.Add("@ipsClase", SqlDbType.VarChar).Value = p.GetType().Name; sqlCmd.Parameters.Add("@ipnIdUsuario", SqlDbType.Int).Value = 1; 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.pedido_parse(rows[i]); pedidos.Add(p); } return pedidos; } catch (Exception ex) { Pedido p = new Pedido(); LogBarabares b = new LogBarabares() { Accion = Constantes.LOG_LISTAR, Servicio = Constantes.SelectAll_Pedido, 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<Pedido>(); } }
public static Pedido pedido_parse(DataRow r) { Pedido p = new Pedido(); p.IdPedido = Int32.Parse(r["idPedido"].ToString()); p.FechaEntrega = DateTime.ParseExact(r["fechaEntrega"].ToString(), "M/d/yyyy h:mm:ss ttt", null); p.FechaCreacion = DateTime.ParseExact(r["fechaCreacion"].ToString(), "M/d/yyyy h:mm:ss ttt", null); p.FechaPago = DateTime.ParseExact(r["fechaPago"].ToString(), "M/d/yyyy h:mm:ss ttt", null); p.Total = Double.Parse(r["total"].ToString()); p.CuantoPaga = Double.Parse(r["cuantoPaga"].ToString()); p.Vuelto = Double.Parse(r["vuelto"].ToString()); p.IdPersona = Int32.Parse(r["idPersona"].ToString()); p.IdEstadoPedido = Int32.Parse(r["idEstadoPedido"].ToString()); p.IdMotivoCancelacion = Int32.Parse(r["idMotivoCancelacion"].ToString()); p.IdDireccion = Int32.Parse(r["idDireccion"].ToString()); p.IdTienda = Int32.Parse(r["idTienda"].ToString()); p.IdAlmacen = Int32.Parse(r["idAlmacen"].ToString()); p.IdMoneda = Int32.Parse(r["idMoneda"].ToString()); p.IdMedioPago = Int32.Parse(r["idMedioPago"].ToString()); p.IdCarrito = Int32.Parse(r["idCarrito"].ToString()); return p; }
public ResponseBD add_Pedido(Pedido 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("PEDIDO_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("@ipdFechaEntrega", SqlDbType.DateTime).Value = p.FechaEntrega; sqlCmd.Parameters.Add("@ipdFechaCreacion", SqlDbType.DateTime).Value = p.FechaCreacion; sqlCmd.Parameters.Add("@ipdFechaPago", SqlDbType.DateTime).Value = p.FechaPago; sqlCmd.Parameters.Add("@ipnTotal", SqlDbType.Real).Value = p.Total; sqlCmd.Parameters.Add("@ipnCuantoPaga", SqlDbType.Real).Value = p.CuantoPaga; sqlCmd.Parameters.Add("@ipnIdPersona", SqlDbType.Int).Value = p.IdPersona; sqlCmd.Parameters.Add("@ipnIdEstadoPedido", SqlDbType.Int).Value = p.IdEstadoPedido; sqlCmd.Parameters.Add("@ipnIdMotivoCancelacion", SqlDbType.Int).Value = p.IdMotivoCancelacion; sqlCmd.Parameters.Add("@ipnIdDireccion", SqlDbType.Int).Value = p.IdDireccion; sqlCmd.Parameters.Add("@ipnIdTienda", SqlDbType.Int).Value = p.IdTienda; sqlCmd.Parameters.Add("@ipnIdAlmacen", SqlDbType.Int).Value = p.IdAlmacen; sqlCmd.Parameters.Add("@ipnIdMoneda", SqlDbType.Int).Value = p.IdMoneda; sqlCmd.Parameters.Add("@ipnIdMedioPago", SqlDbType.Int).Value = p.IdMedioPago; sqlCmd.Parameters.Add("@ipnIdCarrito", SqlDbType.Int).Value = p.IdCarrito; sqlCmd.Parameters.Add("@ipnVuelto", SqlDbType.Real).Value = p.Vuelto; sqlCmd.Parameters.Add("@ipsAccion", SqlDbType.VarChar).Value = Constantes.LOG_LISTAR; sqlCmd.Parameters.Add("@ipsClase", SqlDbType.VarChar).Value = p.GetType().Name; sqlCmd.Parameters.Add("@ipnIdUsuario", SqlDbType.Int).Value = 1; 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_Pedido, Input = "", //TODO 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; } }