コード例 #1
0
        public DetallesForm(IUnityContainer _container, DetalleFacturaNegocio _detalle)
        {
            InitializeComponent();

            container = _container;
            detalle   = _detalle;

            productoNegocio = container.Resolve <ProductoNegocio>();

            detallesBindingSource.DataSource = detalle;
            detallesBindingSource.ResetBindings(false);

            Load += (s, e) =>
            {
                productoBindingSource.DataSource = productoNegocio.Listar();
                productoBindingSource.ResetBindings(false);
            };

            productoComboBox.SelectedValueChanged += (s, e) =>
            {
                var lista = productoBindingSource.DataSource as List <Producto>;
                if (lista == null)
                {
                    return;
                }

                var seleccionado = lista[productoComboBox.SelectedIndex];
                if (seleccionado == null)
                {
                    return;
                }

                detalle.IdProducto          = seleccionado.IdProducto;
                detalle.DescripcionProducto = seleccionado.Descripcion;
                detalle.PrecioUnitario      = seleccionado.PrecioUnitario;
                detallesBindingSource.ResetBindings(false);
            };
        }
コード例 #2
0
 private void btmAgregar_Click(object sender, EventArgs e)
 {
     try
     {
         Cursor.Current = Cursors.WaitCursor;
         var detalle = new DetalleFacturaNegocio();
         using (var frm = new DetallesForm(container, detalle))
         {
             if (frm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
             {
                 target.Detalles.Add(frm.detalle);
                 facturaNegocioBindingSource.ResetBindings(false);
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
     }
     finally
     {
         Cursor.Current = Cursors.Default;
     }
 }