/// <summary>
 /// Create a new DevolucionDet object.
 /// </summary>
 /// <param name="idEmpresa">Initial value of the IdEmpresa property.</param>
 /// <param name="idUsuario">Initial value of the idUsuario property.</param>
 /// <param name="linea">Initial value of the Linea property.</param>
 /// <param name="idNumeroDevolucion">Initial value of the IdNumeroDevolucion property.</param>
 /// <param name="idEstado">Initial value of the idEstado property.</param>
 public static DevolucionDet CreateDevolucionDet(global::System.Int32 idEmpresa, global::System.Int32 idUsuario, global::System.Int32 linea, global::System.Int32 idNumeroDevolucion, global::System.Int32 idEstado)
 {
     DevolucionDet devolucionDet = new DevolucionDet();
     devolucionDet.IdEmpresa = idEmpresa;
     devolucionDet.idUsuario = idUsuario;
     devolucionDet.Linea = linea;
     devolucionDet.IdNumeroDevolucion = idNumeroDevolucion;
     devolucionDet.idEstado = idEstado;
     return devolucionDet;
 }
 /// <summary>
 /// Deprecated Method for adding a new object to the DevolucionDet EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToDevolucionDet(DevolucionDet devolucionDet)
 {
     base.AddObject("DevolucionDet", devolucionDet);
 }
        private void btnGenerar_Click(object sender, EventArgs e)
        {
            try
            {
                if (this.txtNumeroFactura.Text == "")
                {
                    MessageBox.Show("Ingrese Numero Factura.", "Modulo de Facturacion",
                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                if (this.txtcodarticulo.Text == "")
                {
                    MessageBox.Show("Ingrese Numero Factura.", "Modulo de Facturacion",
                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                if (cmbestado.SelectedValue == "")
                {
                    MessageBox.Show("Seleccione un Estado.", "Modulo de Facturacion",
                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                if (this.tbldetalle.Rows.Count == 0)
                {
                    MessageBox.Show("Favor ingrese datos para su devolucion.", "Modulo de Facturacion",
                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                DevolucionVenta  obj = new DevolucionVenta();
               // obj.cabecera_comprobante = Int32.Parse(txtNumeroDevolucion.Text);
                obj.IdNumeroDevolucion  = Int32.Parse(txtNumeroDevolucion.Text);
                obj.IdNumeroFactura = Int32.Parse(txtNumeroFactura.Text);
                obj.Fecha = this.dtpFecha.Value;

                obj.IdEmpresa = Seguridad.empresa;
                obj.idUsuario = Seguridad.usuario;
                obj.idEstado = Int32.Parse(cmbestado.SelectedValue.ToString());
                da.AddToDevolucionVenta(obj);
                int respuesta = da.SaveChanges();
                if (respuesta > 0)
                {
                    int i = 0;
                    while (i < tbldetalle.Rows.Count)
                    {
                        DevolucionDet objdet = new DevolucionDet();
                        objdet.IdEmpresa = Seguridad.empresa;
                        objdet.idUsuario = Seguridad.usuario;
                        objdet.idEstado = Int32.Parse(cmbestado.SelectedValue.ToString());

                        objdet.Linea = i + 1;
                        objdet.IdNumeroDevolucion = Int32.Parse(txtNumeroDevolucion.Text);
                        objdet.IdArticulo = Int32.Parse(tbldetalle.Rows[i][0].ToString());
                        objdet.Observacion =(tbldetalle.Rows[i][2].ToString());
                        objdet.cantidad =Int32.Parse(tbldetalle.Rows[i][3].ToString());

                        da.AddToDevolucionDet (objdet);
                        // Incrementar inventario

                        da.SaveChanges();
                        i++;

                    }

                    MessageBox.Show("Registro Ingresado con exito.", "Modulo de Facturacion",
                    MessageBoxButtons.OK, MessageBoxIcon.Information);
                    //cargarpromociones();
                    ImprimirReporte();

                    limpiar();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Ingrese Correctamente los valores. " + ex.Message, "Modulo de Facturacion",
                MessageBoxButtons.OK, MessageBoxIcon.Error);

            }
        }