private void btnTodo_Click(object sender, EventArgs e) { using (var ctx = new FacturadorDBContext()) { var todosConDatarelacionada = ctx.ProveedorProductos.Include(x => x.Proveedor).Include(x => x.Producto).ToList(); dgvTodo.DataSource = todosConDatarelacionada; } }
private void ObtenerProveedorProductos() { using (var ctx = new FacturadorDBContext()) { proveedorProductos = ctx.ProveedorProductos.ToList(); BindingSource bsProvProductos = new BindingSource(); bsProvProductos.DataSource = proveedorProductos; dgvProvProductos.DataSource = bsProvProductos; } }
private void btnProProveedor_Click(object sender, EventArgs e) { DataGridViewRow filaProveedor = dgvProveedores.CurrentRow; int idProveedor = Convert.ToInt32(filaProveedor.Cells["Id"].Value); using (var ctx = new FacturadorDBContext()) { var porproveedor = ctx.ProveedorProductos.Where(x => x.ProveedorId == idProveedor).Include(x => x.Producto).ToList(); dgvPorProveedor.DataSource = porproveedor; } }
private void ObtenerFacturas() { using (var ctxFacturas = new FacturadorDBContext()) { facturas = ctxFacturas.Facturas.Include(x => x.Detalle).ToList(); } BindingSource bsFacturas = new BindingSource(); bsFacturas.DataSource = facturas; dgvFacturas.DataSource = bsFacturas; }
private void ObtenerProductos() { using (var ctxProductos = new FacturadorDBContext()) { productos = ctxProductos.Productos.ToList(); } //BindingSource bsProductos = new BindingSource(); bsProductos.DataSource = productos; cboProductos.DataSource = bsProductos; cboProductos.DisplayMember = "Nombre"; }
private void btnAsignar_Click(object sender, EventArgs e) { int idCliente = Convert.ToInt32(txtCodigo.Text); using (var ctx = new FacturadorDBContext()) { var credito = new ClienteCredito(); credito.ClienteId = idCliente; credito.Credito = Convert.ToDecimal(txtMonto.Text); ctx.Creditos.Add(credito); ctx.SaveChanges(); } }
private void ObtenerDatos() { List <Producto> productos; using (var ctx = new FacturadorDBContext()) { productos = ctx.Productos.ToList(); } bindingSource1.DataSource = productos; dgvDatos.DataSource = bindingSource1; txtCodigo.DataBindings.Add("Text", bindingSource1, "Id"); txtProducto.DataBindings.Add("Text", bindingSource1, "Nombre"); txtDescripcion.DataBindings.Add("Text", bindingSource1, "Descripcion"); txtPrecio.DataBindings.Add("Text", bindingSource1, "Precio"); }
private void btnAsignar_Click(object sender, EventArgs e) { DataGridViewRow filaProveedor = dgvProveedores.CurrentRow; DataGridViewRow filaProducto = dgvProductos.CurrentRow; int idProveedor = Convert.ToInt32(filaProveedor.Cells["Id"].Value); int idProducto = Convert.ToInt32(filaProducto.Cells["Id"].Value); using (var ctx = new FacturadorDBContext()) { ProveedorProducto provprod = new ProveedorProducto(); provprod.ProveedorId = idProveedor; provprod.ProductoId = idProducto; ctx.ProveedorProductos.Add(provprod); ctx.SaveChanges(); } }
private void ObtenerClientes() { using (var ctxClientes = new FacturadorDBContext()) { clientes = ctxClientes.Clientes.ToList(); } //BindingSource bsClientes = new BindingSource(); bsClientes.DataSource = clientes; cboClientes.DataSource = bsClientes; cboClientes.DisplayMember = "Nombre"; cboClientes.ValueMember = "Id"; txtDocumentoF.DataBindings.Add("Tag", bsClientes, "Id"); txtDocumentoF.DataBindings.Add("Text", bsClientes, "Documento"); txtDireccionF.DataBindings.Add("Text", bsClientes, "Direccion"); txtTelefonoF.DataBindings.Add("Text", bsClientes, "Telefonos"); txtCorreoF.DataBindings.Add("Text", bsClientes, "Correo"); }
private void ObtenerRegistros() { using (var ctx = new FacturadorDBContext()) { clientes = ctx.Clientes.Include(x => x.Credito).ToList(); var monto = clientes.Select(x => x.Credito).First(); BindingSource bsDatos = new BindingSource(); bsDatos.DataSource = clientes; dgvDatos.DataSource = bsDatos; txtCodigo.DataBindings.Add("Text", bsDatos, "Id"); txtCliente.DataBindings.Add("Text", bsDatos, "Nombre"); txtDocumento.DataBindings.Add("Text", bsDatos, "Documento"); txtDireccion.DataBindings.Add("Text", bsDatos, "Direccion"); txtTelefonos.DataBindings.Add("Text", bsDatos, "Telefonos"); txtCorreo.DataBindings.Add("Text", bsDatos, "Correo"); txtMonto.Text = monto.Credito.ToString(); idCliente = Convert.ToInt32(txtCodigo.Text); } }
private void btnOrigen_Click(object sender, EventArgs e) { using (var ctx = new FacturadorDBContext()) { switch (cboOrigen2.Text) { case "Proveedor": var proveedor = ctx.Proveedores.ToList(); dgvOrigen.DataSource = proveedor; break; case "Proveedor Interno": var provInterno = ctx.Proveedores.OfType <ProveedorInterno>().ToList(); dgvOrigen.DataSource = provInterno; break; default: var provExterno = ctx.Proveedores.OfType <ProveedorExterno>().ToList(); dgvOrigen.DataSource = provExterno; break; } } }
private void Grabar() { // Declaramos la lista de detalles de la factura List <FacturaDetalle> detalles = new List <FacturaDetalle>(); // Recorremos el DataGridView y llenamos el objeto de tipo FacturaDetalle foreach (DataGridViewRow fila in dgvDetalle.Rows) { // Declaramos una variable de tipo FacturaDetalle FacturaDetalle detalle = new FacturaDetalle(); // Llenamos el objeto detalle con los datos del DataGridView if (fila.Cells[0].Value != null) { detalle.ProductoId = Convert.ToInt32(fila.Cells[0].Value); detalle.Cantidad = Convert.ToInt32(fila.Cells[3].Value); detalle.Precio = Convert.ToDecimal(fila.Cells[2].Value); // Adicionamos el objeto detalle a la lista FacturaDetalle detalles.Add(detalle); } } // Grabamos la factura (encabezado y detalle) using (var context = new FacturadorDBContext()) { var factura = new Factura(); factura.ClienteId = Convert.ToInt32(cboClientes.SelectedValue.ToString()); factura.FchEmision = Convert.ToDateTime(txtFecha.Text); //DateTime.Now; factura.Detalle = detalles; factura.Total = detalles.Sum(x => x.Precio * x.Cantidad); context.Add(factura); context.SaveChanges(); } }
private void btnCrear_Click(object sender, EventArgs e) { ; object nvoProv; switch (cboOrigen.Text) { case "": Proveedor proveedor = new Proveedor(); proveedor.Nombre = txtNombre.Text; proveedor.Correo = txtCorreo.Text; nvoProv = proveedor; break; case "Nacional": ProveedorInterno proveedorInterno = new ProveedorInterno(); proveedorInterno.Nombre = txtNombre.Text; proveedorInterno.Correo = txtCorreo.Text; nvoProv = proveedorInterno; break; default: ProveedorExterno proveedorExterno = new ProveedorExterno(); proveedorExterno.Nombre = txtNombre.Text; proveedorExterno.Correo = txtCorreo.Text; proveedorExterno.Pais = cboOrigen.Text; nvoProv = proveedorExterno; break; } using (var ctx = new FacturadorDBContext()) { ctx.Add(nvoProv); ctx.SaveChanges(); } }