public Pedidos(Modelo.Ventas.Pedido p) : this() { if (p == null) { return; } this.CurrentPedido = p; txtIdPedido.EditValue = p.IdPedido; cmbIdCliente.EditValue = p.Cliente.IdCliente; dtpFecha.EditValue = p.FechaPedido; foreach (Modelo.Ventas.DetallePedido d in p.DetallePedido) { DataRow row = DetallePedido.NewRow(); row["Material"] = d.Base.IdMaterial; row["Design"] = d.Design.IdDesign; row["Cantidad"] = d.Cantidad; row["Precio"] = d.Precio; DetallePedido.Rows.Add(row); } GcDetallePedido.DataSource = DetallePedido; dtpFecha.ReadOnly = true; cmbIdCliente.ReadOnly = true; LciCliente.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always; GvDetallePedido.OptionsBehavior.Editable = false; }
public Pedido getById(int idPedido) { SqlConnection connection = null; SqlCommand cmd = null; SqlDataReader reader = null; Modelo.Ventas.Pedido p = null; try { connection = GetConnection(); connection.Open(); cmd = connection.CreateCommand(); cmd.CommandText = "SELECT * FROM [Ventas].[Pedidos] WHERE IdPedido = @idPedido"; cmd.Parameters.AddWithValue("@idPedido", idPedido); reader = cmd.ExecuteReader(); if (reader.Read()) { p = new Pedido(); p.IdPedido = (int)reader["IdPedido"]; p.Cliente = new Controlador.Ventas.ControladorCliente().GetById((int)reader["Cliente"]); p.Vendedor = new Controlador.Usuarios.ControladorUsuario().GetById((int)reader["Vendedor"]); p.FechaPedido = (DateTime)reader["FechaPedido"]; p.DetallePedido = new List <DetallePedido>(); reader.Close(); cmd.CommandText = "SELECT IdDetalle FROM Ventas.DetallesPedido WHERE Pedido = @Pedido"; cmd.Parameters.AddWithValue("@Pedido", p.IdPedido); reader = cmd.ExecuteReader(); while (reader.Read()) { p.DetallePedido.Add(new Controlador.Ventas.ControladorDetallePedido().GetById((int)reader["IdDetalle"])); } } return(p); } catch (Exception ex) { throw ex; } finally { if (connection != null) { connection.Close(); connection.Dispose(); } } }
public Pedidos() { InitializeComponent(); ctrlPedido = new Controlador.Ventas.ControladorPedido(); ctrlBases = new Controlador.Produccion.ControladorMaterial(); ctrlDesigns = new Controlador.Produccion.ControladorDesign(); ctrlCliente = new Controlador.Ventas.ControladorCliente(); this.CurrentPedido = null; Limpiar(); }
private void Limpiar() { this.CurrentPedido = null; txtIdPedido.EditValue = null; cmbIdCliente.EditValue = null; cmbIdCliente.ReadOnly = false; dtpFecha.ReadOnly = false; dtpFecha.Properties.MinValue = DateTime.Today; LciCliente.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always; dtpFecha.EditValue = DateTime.Today; InitGrid(); }
private Modelo.Ventas.Pedido GenerarPedido() { Modelo.Ventas.Pedido p = new Modelo.Ventas.Pedido() { Cliente = ctrlCliente.GetById((int)cmbIdCliente.EditValue), Vendedor = Session.UsuarioEnCurso, DetallePedido = new List <Modelo.Ventas.DetallePedido>(), FechaPedido = DateTime.Today }; foreach (DataRow row in DetallePedido.Rows) { Modelo.Ventas.DetallePedido d = new Modelo.Ventas.DetallePedido(); d.Base = ctrlBases.GetById((int)row["Material"]); d.Design = ctrlDesigns.GetById((int)row["Design"]); d.Cantidad = (double)(int)row["Cantidad"]; d.Precio = (double)row["Precio"]; p.DetallePedido.Add(d); } return(p); }
public void GuardarVenta() { Modelo.Ventas.Pedido p = GenerarPedido(); ctrlPedido.insert(p); }