예제 #1
0
        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();
            }
        }
예제 #2
0
        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();
            }
        }
예제 #3
0
        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();
            }
        }
예제 #4
0
        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();
            }
        }