Beruflich Dokumente
Kultur Dokumente
WEB SERVICE
RESTFUL EN
.NET
Cndor Xavier, Muentes Andrs
BASE DE DATOS
1. Para el problema propuesto se ha planteado el siguiente modelo.
DETALLE_FACTURA
DET_CODIGO
FAC_CODIGO
PROV_CODIGO
PRO_CODIGO
PRO_NOMBRE
PRO_PRECIO_UNITARIO
DET_CANTIDAD
DET_SUBTOTAL
...
int
<pk>
int
<fk1>
int
<fk2>
int
int
numeric(8,2)
int
numeric(8,2)
PROVEEDOR
PROV_CODIGO
PROV_NOMBRE
PROV_DIRECCION
PROV_TELEFONO
PROV_RUC
PROV_CORREO
...
FACTURA
FAC_CODIGO
CLIEN_CODIGO
FAC_FECHA
FAC_IVA
FAC_TOTAL
...
int
<pk>
int
<fk>
datetime
numeric(8,2)
numeric(8,2)
CLIENTE
CLIEN_CODIGO
CLIEN_CEDULA
CLI_NOMBRE
CLI_APELLIDO
CLI_DIRECCION
...
PRODUCTO
PRO_CODIGO
EMP_RUC
PRO_NOMBRE
PRO_DESCRIPCION
PRO_PRECIO_UNITARIO
PRO_STOCK
...
int
<pk>
varchar(50)
varchar(100)
varchar(10)
varchar(13)
varchar(50)
int
<pk>
varchar(13) <fk>
varchar(50)
varchar(150)
numeric(8,2)
int
int
<pk>
varchar(13)
varchar(50)
varchar(50)
varchar(50)
EMPRESA
EMP_RUC
EMP_NOMBRE
EMP_DIRECCION
EMP_TELEFONO
EMP_CORREO
...
varchar(13) <pk>
varchar(50)
varchar(100)
varchar(10)
varchar(50)
if exists (select 1
from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and
o.type = 'F')
where r.fkeyid = object_id('DETALLE_FACTURA') and o.name =
'FK_DETALLE__REFERENCE_PROVEEDO')
alter table DETALLE_FACTURA
drop constraint FK_DETALLE__REFERENCE_PROVEEDO
go
if exists (select 1
from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and
o.type = 'F')
where r.fkeyid = object_id('FACTURA') and o.name =
'FK_FACTURA_REFERENCE_CLIENTE')
alter table FACTURA
drop constraint FK_FACTURA_REFERENCE_CLIENTE
go
if exists (select 1
from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and
o.type = 'F')
where r.fkeyid = object_id('PRODUCTO') and o.name =
'FK_PRODUCTO_REFERENCE_EMPRESA')
alter table PRODUCTO
drop constraint FK_PRODUCTO_REFERENCE_EMPRESA
go
if exists (select 1
from sysobjects
where id = object_id('CLIENTE')
and type = 'U')
drop table CLIENTE
go
if exists (select 1
from sysobjects
where id = object_id('DETALLE_FACTURA')
and type = 'U')
drop table DETALLE_FACTURA
go
if exists (select 1
from sysobjects
where id = object_id('EMPRESA')
and type = 'U')
drop table EMPRESA
go
if exists (select 1
from sysobjects
where id = object_id('FACTURA')
and type = 'U')
drop table FACTURA
go
3
if exists (select 1
from sysobjects
where id = object_id('PRODUCTO')
and type = 'U')
drop table PRODUCTO
go
if exists (select 1
from sysobjects
where id = object_id('PROVEEDOR')
and type = 'U')
drop table PROVEEDOR
go
/
*=============================================
=================*/
/* Table: CLIENTE
*/
/
*=============================================
=================*/
create table CLIENTE (
CLIEN_CODIGO
int
identity,
CLIEN_CEDULA
varchar(13)
null,
CLI_NOMBRE
varchar(50)
null,
CLI_APELLIDO
varchar(50)
null,
CLI_DIRECCION
varchar(50)
null,
constraint PK_CLIENTE primary key (CLIEN_CODIGO)
)
go
/
*=============================================
=================*/
/* Table: DETALLE_FACTURA
*/
/
*=============================================
=================*/
create table DETALLE_FACTURA (
DET_CODIGO
int
identity,
FAC_CODIGO
int
null,
PROV_CODIGO
int
null,
PRO_CODIGO
int
null,
PRO_NOMBRE
int
null,
PRO_PRECIO_UNITARIO numeric(8,2)
null,
DET_CANTIDAD
int
null,
DET_SUBTOTAL
numeric(8,2)
null,
constraint PK_DETALLE_FACTURA primary key (DET_CODIGO)
)
go
/
*=============================================
=================*/
/* Table: EMPRESA
*/
/
*=============================================
=================*/
create table EMPRESA (
EMP_RUC
varchar(13)
not null,
EMP_NOMBRE
varchar(50)
null,
EMP_DIRECCION
varchar(100)
null,
EMP_TELEFONO
varchar(10)
null,
EMP_CORREO
varchar(50)
null,
constraint PK_EMPRESA primary key (EMP_RUC)
)
go
/
*=============================================
=================*/
/* Table: FACTURA
*/
/
*=============================================
=================*/
create table FACTURA (
FAC_CODIGO
int
identity,
CLIEN_CODIGO
int
null,
FAC_FECHA
datetime
null,
FAC_IVA
numeric(8,2)
null,
FAC_TOTAL
numeric(8,2)
null,
constraint PK_FACTURA primary key (FAC_CODIGO)
)
go
/
*=============================================
=================*/
/* Table: PRODUCTO
*/
/
*=============================================
=================*/
create table PRODUCTO (
PRO_CODIGO
int
identity,
EMP_RUC
varchar(13)
null,
PRO_NOMBRE
varchar(50)
null,
PRO_DESCRIPCION
varchar(150)
null,
PRO_PRECIO_UNITARIO numeric(8,2)
null,
PRO_STOCK
int
null,
constraint PK_PRODUCTO primary key (PRO_CODIGO)
)
go
/
*=============================================
=================*/
/* Table: PROVEEDOR
*/
/
*=============================================
=================*/
create table PROVEEDOR (
PROV_CODIGO
int
identity,
PROV_NOMBRE
varchar(50)
null,
PROV_DIRECCION
varchar(100)
null,
PROV_TELEFONO
varchar(10)
null,
PROV_RUC
varchar(13)
null,
PROV_CORREO
varchar(50)
null,
constraint PK_PROVEEDOR primary key (PROV_CODIGO)
)
go
alter table DETALLE_FACTURA
add constraint FK_DETALLE__REFERENCE_FACTURA foreign key
(FAC_CODIGO)
references FACTURA (FAC_CODIGO)
go
alter table DETALLE_FACTURA
add constraint FK_DETALLE__REFERENCE_PROVEEDO foreign key
(PROV_CODIGO)
references PROVEEDOR (PROV_CODIGO)
go
alter table FACTURA
add constraint FK_FACTURA_REFERENCE_CLIENTE foreign key
(CLIEN_CODIGO)
references CLIENTE (CLIEN_CODIGO)
go
alter table PRODUCTO
add constraint FK_PRODUCTO_REFERENCE_EMPRESA foreign key
(EMP_RUC)
references EMPRESA (EMP_RUC)
go
2. Abrimos el SQLServer 2014
9. Se nos abre el archivo sql, con los comandos necesarios para crear
las tablas que necesitamos. En el lado superior izquierdo verificamos
que la base de datos en la que nos encontramos sea la correcta y
luego damos clic en ejecutar.
10
13.En producto, que sern los productos que ofrece la empresa LOS
ALPES
APLICACIN SERVIDOR
En este caso para la empresa LOS ALPES que ser la que tenga los
WebServices, se ha decidido crear una aplicacin en ASP.NET, con c#. Por lo
que procedemos haciendo lo siguiente:
1. Abrimos VisualStudio, en nuestro caso utilizaremos VisualStudio 2015
11
12
13
14
15
11.Se nos abre una nueva ventana en donde, para el caso de la capa de
datos, le va a hacer referencia a la capa de Entidades, por lo que solo
seleccionamos Entidades y damos clic en Aceptar.
16
14.El cdigo dentro de la clase ser el siguiente, para este caso, la lnea
de conexin es por la autenticacin de Windows como usuario local.
DalConexion.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Datos
{
public class DalConexion
{
public static String obtenerConexion()
{
return "Server=DESKTOP-1207RI9\\SQLEXPRESS;Initial
Catalog=db_complexivo_b;Trusted_Connection=Yes;";
}
}
}
17
System;
System.Collections.Generic;
System.Linq;
System.Text;
System.Threading.Tasks;
namespace Entidades
{
public class Empresa
{
public string ruc { get; set; }
public string nombre { get; set; }
public string direccion { get; set; }
public string telefono { get; set; }
public string correo { get; set; }
}
}
Producto.cs
using
using
using
using
using
System;
System.Collections.Generic;
System.Linq;
System.Text;
System.Threading.Tasks;
namespace Entidades
{
public class Producto
{
public Int32 codigo { get; set; }
public string rucEmpresa { get; set; }
public string nombre { get; set; }
public string descripcion { get; set; }
public double precioUnitario { get; set; }
public int stock { get; set; }
}
}
System;
System.Collections.Generic;
System.Data;
System.Data.SqlClient;
System.Linq;
System.Text;
System.Threading.Tasks;
Entidades;
18
namespace Datos
{
public class DalProducto
{
SqlConnection cnn;
SqlDataAdapter cmd2;
SqlCommand cmd;
DataSet ds;
public bool insertarProducto(Producto objetoProducto)
{
String sql = "insert into PRODUCTO (EMP_RUC, PRO_NOMBRE,
PRO_DESCRIPCION, PRO_PRECIO_UNITARIO) values ('" + objetoProducto.rucEmpresa +
"','" + objetoProducto.nombre + "', '" + objetoProducto.descripcion + "', " +
objetoProducto.precioUnitario + ")";
cnn = new SqlConnection(DalConexion.obtenerConexion());
cnn.Open();
cmd = new SqlCommand(sql, cnn);
cmd.ExecuteNonQuery();
return true;
}
public DataSet buscarProductoPorCodigoYRucEmpresa(Int32 codigo, string
rucEmpresa)
{
String sql = "select * from PRODUCTO where PRO_CODIGO=" + codigo + " and
EMP_RUC = '" + rucEmpresa + "'";
cnn = new SqlConnection(DalConexion.obtenerConexion());
cnn.Open();
cmd = new SqlCommand(sql, cnn);
SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
sda.Fill(ds);
cmd.ExecuteNonQuery();
cnn.Close();
return ds;
}
public bool actualizarProducto(Producto objetoProducto)
{
String sql = "update PRODUCTO Set PRO_NOMBRE_='" + objetoProducto.nombre
+ "',PRO_DESCRIPCION='" + objetoProducto.descripcion + "',PRO_PRECIO_UNITARIO="
+ objetoProducto.precioUnitario + ",PRO_STOCK=" + objetoProducto.stock + " where
PRO_CODIGO=" + objetoProducto.codigo + " and EMP_RUC = '" +
objetoProducto.rucEmpresa + "'";
cnn = new SqlConnection(DalConexion.obtenerConexion());
cnn.Open();
cmd = new SqlCommand(sql, cnn);
cmd.ExecuteNonQuery();
return true;
}
public bool eliminarProducto(Int32 codigo, string rucEmpresa)
{
String sql = "delete PRODUCTO where PRO_CODIGO=" + codigo + " and
EMP_RUC = '" + rucEmpresa + "'";
cnn = new SqlConnection(DalConexion.obtenerConexion());
cnn.Open();
cmd = new SqlCommand(sql, cnn);
cmd.ExecuteNonQuery();
return true;
19
}
public DataSet listarProductosConStockMayorACero()
{
String sql = "SELECT * FROM PRODUCTO where PRO_STOCK > 0";
cnn = new SqlConnection(DalConexion.obtenerConexion());
cnn.Open();
cmd = new SqlCommand(sql, cnn);
SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
sda.Fill(ds);
cmd.ExecuteNonQuery();
cnn.Close();
return ds;
}
public List<Producto> listarProductos2()
{
List<Producto> lista = new List<Producto>();
String sql = "SELECT * FROM PRODUCTO";
cnn = new SqlConnection(DalConexion.obtenerConexion());
cnn.Open();
cmd2 = new SqlDataAdapter(sql, cnn);
ds = new DataSet();
cmd2.Fill(ds, "DATOS");
20
}
cnn.Close();
return p;
}
public DataSet listarProductos()
{
String sql = "select * from PRODUCTO";
cnn = new SqlConnection(DalConexion.obtenerConexion());
cnn.Open();
cmd = new SqlCommand(sql, cnn);
SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
sda.Fill(ds);
cmd.ExecuteNonQuery();
cnn.Close();
return ds;
}
public bool actualizarStockProducto(Producto objetoProducto)
{
String sql = "update PRODUCTO Set PRO_STOCK=" + objetoProducto.stock + "
where PRO_CODIGO=" + objetoProducto.codigo + " and EMP_RUC = '" +
objetoProducto.rucEmpresa + "'";
cnn = new SqlConnection(DalConexion.obtenerConexion());
cnn.Open();
cmd = new SqlCommand(sql, cnn);
cmd.ExecuteNonQuery();
return true;
}
}
}
System;
System.Collections.Generic;
System.Data;
System.Linq;
System.Text;
System.Threading.Tasks;
Datos;
Entidades;
namespace Negocio
{
public class AdministracionProducto
{
public DataSet listarProductosConStock()
{
DalProducto dp = new Datos.DalProducto();
return dp.listarProductosConStockMayorACero();
}
public DataSet listarProductos()
{
DalProducto dp = new Datos.DalProducto();
21
return dp.listarProductos();
}
public bool insertarProducto(Producto producto)
{
DalProducto dp = new Datos.DalProducto();
return dp.insertarProducto(producto);
}
public bool actualizarProducto(Producto producto)
{
DalProducto dp = new Datos.DalProducto();
return dp.actualizarProducto(producto);
}
public bool actualizarStockProducto(Int32 codigoProduco, string rucEmpresa, int
cantidadComprada)
{
bool respuesta = false;
DalProducto dp = new Datos.DalProducto();
Producto producto = buscarProductoLocal(codigoProduco, rucEmpresa);
if(producto!=null)
{
producto.stock-=cantidadComprada;
respuesta = dp.actualizarStockProducto(producto);
}
return respuesta;
}
public bool eiminarProducto(Producto producto)
{
DalProducto dp = new Datos.DalProducto();
return dp.eliminarProducto(producto.codigo, producto.rucEmpresa);
}
public List<Producto> listarProductos2()
{
DalProducto dp = new Datos.DalProducto();
return dp.listarProductos2();
}
public DataSet buscarProducto(Int32 codigoProducto, string rucEmpresa)
{
DalProducto dp = new Datos.DalProducto();
return dp.buscarProductoPorCodigoYRucEmpresa(codigoProducto, rucEmpresa);
}
18.Ahora vamos a crear una vista para visualizar los productos. Para esto
vamos a crear un controlador. Para lo cual vamos al rbol del
proyecto,
damos
clic
derecho
sobre
la
carpeta
controller/Agregar/contolador
22
20.Al dar clic en aceptar, nos pedir que le demos un nombre a nuestro
controlador, en este caso le hemos puesto ProductoController y le
damos agregar.
23
23.Agregamos una
vistas/Producto.
vista
dando
clic
derecho
sobre
la
carpeta
24
25
System;
System.Collections.Generic;
System.Linq;
System.Web;
System.Web.Mvc;
Negocio;
namespace LosAlpes.Controllers
{
public class ProductoController : Controller
{
// GET: Producto
public ActionResult Index()
{
AdministracionProducto ap = new AdministracionProducto();
ViewBag.listadoProductos = ap.listarProductos2();
return View("Producto");
}
}
}
26
en la base
27
31.En
el
WebService
aadimos
IWebServiceConsultaREST.cs
using
using
using
using
using
using
using
using
el
siguiente
Cdigo
en
Entidades;
System;
System.Collections.Generic;
System.Data;
System.Linq;
System.Runtime.Serialization;
System.ServiceModel;
System.Text;
namespace ServicioRest
{
// NOTA: puede usar el comando "Rename" del men "Refactorizar" para cambiar el
nombre de interfaz "IWebServiceConsultaREST" en el cdigo y en el archivo de
configuracin a la vez.
[ServiceContract]
public interface IWebServiceConsultaREST
{
[OperationContract]
DataSet obtenerProductosConStock();
}
[DataContract]
public class ProductoService
{
[DataMember]
public Producto producto
{
get { return producto; }
set { producto = value; }
}
}
}
Negocio;
System;
System.Collections.Generic;
System.Data;
System.Linq;
System.Runtime.Serialization;
System.ServiceModel;
28
using System.Text;
namespace ServicioRest
{
// NOTA: puede usar el comando "Rename" del men "Refactorizar" para cambiar el
nombre de clase "WebServiceConsultaREST" en el cdigo, en svc y en el archivo de
configuracin a la vez.
// NOTA: para iniciar el Cliente de prueba WCF para probar este servicio, seleccione
WebServiceConsultaREST.svc o WebServiceConsultaREST.svc.cs en el Explorador de
soluciones e inicie la depuracin.
public class WebServiceConsultaREST : IWebServiceConsultaREST
{
public DataSet obtenerProductosConStock()
{
AdministracionProducto admin = new AdministracionProducto();
DataSet ds = admin.listarProductosConStock();
return ds;
}
}
}
29
33.Aadimos
otro
Web
Service
WebServicePedidosREST.
Aadimos
IWebServicePedidos REST.cs
using
using
using
using
using
using
using
WCF
al
que
llamamos
el
siguiente
Cdigo
en
Entidades;
System;
System.Collections.Generic;
System.Linq;
System.Runtime.Serialization;
System.ServiceModel;
System.Text;
namespace ServicioRest
{
// NOTA: puede usar el comando "Rename" del men "Refactorizar" para cambiar el
nombre de interfaz "IWebServicePedidosREST" en el cdigo y en el archivo de
configuracin a la vez.
[ServiceContract]
public interface IWebServicePedidosREST
{
[OperationContract]
bool actualizarStockProducto(Int32 codigoProducto, string rucEmpresa, int
cantidadComprada);
}
[DataContract]
public class ProductoService2
{
[DataMember]
public Producto producto
{
get { return producto; }
set { producto = value; }
}
}
}
using
using
using
using
using
using
using
Negocio;
System;
System.Collections.Generic;
System.Linq;
System.Runtime.Serialization;
System.ServiceModel;
System.Text;
namespace ServicioRest
{
// NOTA: puede usar el comando "Rename" del men "Refactorizar" para cambiar el
nombre de clase "WebServicePedidosREST" en el cdigo, en svc y en el archivo de
configuracin a la vez.
// NOTA: para iniciar el Cliente de prueba WCF para probar este servicio, seleccione
WebServicePedidosREST.svc o WebServicePedidosREST.svc.cs en el Explorador de
soluciones e inicie la depuracin.
public class WebServicePedidosREST : IWebServicePedidosREST
{
public bool actualizarStockProducto(Int32 codigoProducto, string rucEmpresa, int
cantidadComprada)
{
bool respuesta = false;
AdministracionProducto admin = new AdministracionProducto();
respuesta = admin.actualizarStockProducto(codigoProducto, rucEmpresa,
cantidadComprada);
return respuesta;
}
}
}
31
APLICACIN CLIENTE
Una vez creado el servidor, crearemos un cliente que consuma los
WebServices propuestos. Para lo cual crearemos un proyecto similar al
anterior llamado Imporquito.
1. Abrimos otra ventana de Visual Studio y creams un nuevo proyecto.
Cliente
using
using
using
using
using
System;
System.Collections.Generic;
System.Linq;
System.Text;
System.Threading.Tasks;
namespace Entidades
{
public class Cliente
{
public Int32 codigo { get; set; }
public string cedula { get; set; }
public string nombre { get; set; }
public string apellido{ get; set; }
public string direccion { get; set; }
}
}
Proveedor
using
using
using
using
using
System;
System.Collections.Generic;
System.Linq;
System.Text;
System.Threading.Tasks;
namespace Entidades
{
public class Proveedor
{
public Int32 codigo { get; set; }
public string nombre { get; set; }
public string direccion { get; set; }
public string telefono { get; set; }
public string ruc { get; set; }
public string correo { get; set; }
}
}
Factura
using
using
using
using
using
System;
System.Collections.Generic;
System.Linq;
System.Text;
System.Threading.Tasks;
namespace Entidades
{
public class Factura
{
public Int32 codigo { get; set; }
public Int32 codigoCliente{ get; set; }
public DateTime fecha { get; set; }
public double iva { get; set; }
public double total { get; set; }
}
}
DetalleFactura
using System;
using System.Collections.Generic;
34
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Entidades
{
public class DetalleFactura
{
public Int32 codigoFactura { get; set; }
public Int32 codigoProducto { get; set; }
public Int32 codigoProveedor { get; set; }
public string nombre { get; set; }
public double precioUnitario { get; set; }
public int cantidad { get; set; }
public double subtotal { get; set; }
}
}
Producto
using
using
using
using
using
System;
System.Collections.Generic;
System.Linq;
System.Text;
System.Threading.Tasks;
namespace Entidades
{
public class Producto
{
public Int32 codigo { get; set; }
public string rucEmpresa { get; set; }
public string nombre { get; set; }
public string descripcion { get; set; }
public double precioUnitario { get; set; }
public int stock { get; set; }
}
}
35
8.
36
37
38
</td>
<td>
<asp:Label ID="Label4" runat="server" Text="Nombre:"></asp:Label>
<asp:TextBox ID="txtNombre" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label5" runat="server" Text="Apellido:"></asp:Label>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</td>
<td>
<asp:Label ID="Label6" runat="server" Text="Direccin:"></asp:Label>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
</td>
</tr>
</table>
<br />
<div>
<h4>Pedido</h4>
</div>
<div>
<asp:Label ID="Label1" runat="server" Text="ID-Producto:"></asp:Label>
<asp:TextBox ID="txtProducto" runat="server"></asp:TextBox>
<asp:Label ID="Label2" runat="server" Text="Cantidad:"></asp:Label>
<asp:TextBox ID="txtCantidad" runat="server"></asp:TextBox>
<asp:Button ID="btnAgregar" runat="server" OnClick="btnAgregar_Click"
Text="Realizar Pedido" />
</div>
<div>
<asp:Label ID="lblMensaje" runat="server" Text=""></asp:Label>
</div>
</form>
</body>
</html>
Producto.aspx.cs
using
using
using
using
using
using
System;
System.Collections.Generic;
System.Linq;
System.Web;
System.Web.UI;
System.Web.UI.WebControls;
39
using
using
using
using
Entidades;
System.Data;
Imporquito.ServicioConsulta;
Imporquito.ServicioPedidos;
namespace Imporquito
{
public partial class Productos : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
llenarTabla();
}
protected void btnAgregar_Click(object sender, EventArgs e)
{
bool respuesta = false;
ServicioPedidosREST.WebServicePedidosRESTClient servicio = new
ServicioPedidosREST.WebServicePedidosRESTClient();
respuesta = servicio.actualizarStockProducto(Convert.ToInt32(txtProducto.Text),
"9999999999999", Convert.ToInt32(txtCantidad.Text));
if (respuesta == true)
{
lblMensaje.Text = "Pedido Realizado";
txtProducto.Text = "";
txtCantidad.Text = "";
llenarTabla();
}
else
{
lblMensaje.Text = "NO se pudo realizar el pedido";
}
}
public void llenarTabla()
{
DataSet ds = new DataSet();
ServicioConsultaREST.WebServiceConsultaRESTClient consultaREST = new
ServicioConsultaREST.WebServiceConsultaRESTClient();
ds = consultaREST.obtenerProductosConStock();
tblProductos.DataSource = ds.Tables[0];
tblProductos.DataBind();
}
public List<Producto> obtenerProductosDeServidor()
{
List<Producto> lista = new List<Producto>();
WebServiceConsultaSoapClient servicioConsulta = new
WebServiceConsultaSoapClient();
DataSet ds = servicioConsulta.ObtenerProductosConStock();
DataTable tabla = ds.Tables[0];
foreach (DataRow row in tabla.Rows)
{
Producto p = new Producto();
p.codigo = Convert.ToInt32(row["PRO_CODIGO"]);
p.rucEmpresa = row["EMP_RUC"].ToString();
p.nombre = row["PRO_NOMBRE"].ToString();
p.descripcion = row["PRO_DESCRIPCION"].ToString();
p.precioUnitario = Convert.ToDouble(row["PRO_PRECIO_UNITARIO"]);
40
p.stock = Convert.ToInt32(row["PRO_STOCK"]);
lista.Add(p);
return lista;
}
41
42
43
45