public frmDetalleFacturaProveedor(Empleado empleado, FacturaProveedor factura)
        {
            this.empleado = empleado;

            InitializeComponent();
            // validaciones
            this.txtNroFact.KeyPress += new System.Windows.Forms.KeyPressEventHandler(Utils.Utils.ValidaNumerico);
            this.txtNroFact.KeyUp += new System.Windows.Forms.KeyEventHandler(Utils.Utils.ValidaBlancos);

            if (factura != null)
            {
                this.factura = factura;
                MostrarFactura();
                bloquearCampos();
                btnRegistrar.Text = "Eliminar";
                lblTipoCambio.Visible = false;
            }
            else
            {
                this.factura = new FacturaProveedor();
                this.factura.Id = 0;
                factLineas = new List<FacturaProveedorLinea>();
            }
            load = 0;
        }
        private void btnSeleccionar_Click(object sender, EventArgs e)
        {
            int row = -1;
            FacturaProveedor factura = null;

            if (dgvFacturas.CurrentRow != null)
            {
                row = dgvFacturas.CurrentRow.Index;
                if (dgvFacturas.CurrentRow.Cells["Nro"].Value != null)
                {
                    if ((row >= 0) && ((row - 1) <= facturas.Count))
                    {
                        factura = facturas[row];
                        facturaSeleccionada = factura;

                    }
                }
            }
            if (factura == null)
            {
                Utils.Utils.Error(null, "Debe seleccionar una orden de compra");
            }
        }
        public void Update(FacturaProveedor factura)
        {
            ISession hisession = null;
            try
            {
                hisession = NHibernateHelper.GetCurrentSession();
                hisession.BeginTransaction();
                hisession.Merge(factura);
                hisession.Transaction.Commit();
                hisession.Close();
            }
            catch (Exception ex)
            {
                if (hisession != null)
                {
                    if (hisession.IsOpen)
                    {
                        hisession.Close();
                    }
                }
                if (log.IsErrorEnabled)
                {
                    log.Error("No se pudo actualizar  la factura: " + ex.Message);
                }

            }
        }
 public Boolean Save(FacturaProveedor factura)
 {
     ISession hisession = null;
     try
     {
         hisession = NHibernateHelper.GetCurrentSession();
         hisession.BeginTransaction();
         if (factura.Id == 0)
         {
             factura.Estado = "Activo";
             hisession.Save(factura);
         }
         else
         {
             hisession.Merge(factura);
         }
         hisession.Transaction.Commit();
         hisession.Close();
         return true;
     }
     catch (Exception ex)
     {
         if (hisession != null)
         {
             if (hisession.IsOpen)
             {
                 hisession.Close();
             }
         }
         if (log.IsErrorEnabled)
         {
             log.Error("No se pudo registrar o modificar : " + ex.Message);
         }
         return false;
     }
 }