public DataSet ProcesarImportacionLote(ImportacionLoteBE BE)
        {
            DataSet dsResult;

            try
            {
                cmd = db.GetStoredProcCommand("ImportacionLote_Val");
                db.AddInParameter(cmd, "USUARIO", DbType.Int32, BE.USUARIO);
                db.AddInParameter(cmd, "vcRuc", DbType.String, BE.RucPagadora);
                db.AddInParameter(cmd, "IdSocio", DbType.String, BE.IdSocio);
                db.AddInParameter(cmd, "IdLinea", DbType.String, BE.IdLinea);
                db.AddInParameter(cmd, "IdDocumento", DbType.String, BE.IdDocumento);
                db.AddInParameter(cmd, "IdMoneda_tt", DbType.String, BE.IdMoneda_tt);
                db.AddInParameter(cmd, "cNumDoc", DbType.String, BE.cNumDoc);
                db.AddInParameter(cmd, "Pagadora_Dsc", DbType.String, BE.Pagadora_Dsc);
                db.AddInParameter(cmd, "RucGiradorOriginal", DbType.String, BE.RucGiradorOriginal);
                dsResult = db.ExecuteDataSet(cmd);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            return(dsResult);
        }
        private void btnAceptar_Click(object sender, EventArgs e)
        {
            try
            {
                if (LstEntityFE.Count == 0)
                {
                    MessageBox.Show("No hay documentos para enviar a operaciones, por favor verifique.", "Mensaje", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }

                int  Index      = 0;
                bool IsProcesar = true;
                List <DetaLoteBE> LstDetaLote = new List <DetaLoteBE>();
                foreach (FEXMLBE oEntityFE in LstEntityFE)
                {
                    ImportacionLoteBE oEntity = new ImportacionLoteBE()
                    {
                        RucPagadora = oEntityFE.RUC,
                        IdSocio     = txtIdSocio.Text.Trim(),
                        IdLinea     = IdLinea,
                        IdDocumento = oEntityFE.IdDocumento,
                        IdMoneda_tt = IdMoneda_tt,
                        cNumDoc     = oEntityFE.cNumDoc
                    };
                    DataSet ds = new DataSet();
                    ds = new ImportacionLoteBL().ProcesarImportacionLote(oEntity);
                    if (!ds.Tables[0].Rows[0]["Result"].Equals("OK"))
                    {
                        IsProcesar = false;
                        LstEntityFE[Index].Mensaje = ds.Tables[0].Rows[0]["MsgResult"].ToString();
                        Index++;
                        continue;
                    }
                    else
                    {
                        if (oEntityFE.nvNegociable == 0)
                        {
                            LstEntityFE[Index].Mensaje = "El importe de pago no puede ser 0.";
                            IsProcesar = false;
                            Index++;
                            continue;
                        }

                        if (oEntityFE.sdVencimiento == DateTime.MinValue)
                        {
                            LstEntityFE[Index].Mensaje = "Ingresar la fecha de vencimiento válida.";
                            IsProcesar = false;
                            Index++;
                            continue;
                        }

                        if (oEntityFE.sdVencimiento <= GeneralXML.FechaOperacion)
                        {
                            LstEntityFE[Index].Mensaje = "Fecha de vencimiento no puede ser menor a la fecha de recepción.";
                            IsProcesar = false;
                            Index++;
                            continue;
                        }

                        LstEntityFE[Index].Mensaje = "OK";

                        TimeSpan   ts             = Convert.ToDateTime(oEntityFE.sdVencimiento) - GeneralXML.FechaOperacion;
                        DetaLoteBE oEntityDetLote = new DetaLoteBE();
                        oEntityDetLote.USUARIO                 = GeneralXML.CodUsuario;
                        oEntityDetLote.OPCION                  = 2;
                        oEntityDetLote.IdLote                  = string.Empty;
                        oEntityDetLote.cItem                   = "";
                        oEntityDetLote.IdPagadora              = oEntityFE.IdPagadora;
                        oEntityDetLote.IdDocumento             = oEntityFE.IdDocumento;
                        oEntityDetLote.cNumDoc                 = oEntityFE.cNumDoc;
                        oEntityDetLote.sdRecepcion             = GeneralXML.FechaOperacion;
                        oEntityDetLote.iPlazo                  = ts.Days;
                        oEntityDetLote.sdVencimiento           = Convert.ToDateTime(oEntityFE.sdVencimiento);
                        oEntityDetLote.nvNominal               = Convert.ToDecimal(oEntityFE.nvNegociable);
                        oEntityDetLote.cNotaCredito            = string.Empty;
                        oEntityDetLote.nNotaCredito            = 0;
                        oEntityDetLote.nPorRetencion           = 0;
                        oEntityDetLote.nvRetencion             = 0;
                        oEntityDetLote.Descuento               = 0;
                        oEntityDetLote.dtRenovacion            = DateTime.MinValue;
                        oEntityDetLote.IdSocio_Beneficiario    = string.Empty;                      //_IdSocio_Beneficiario;
                        oEntityDetLote.IdSocio_BeneficiarioRuc = oEntityFE.IdSocio_BeneficiarioRuc; //_IdSocio_BeneficiarioRuc;
                        LstDetaLote.Add(oEntityDetLote);

                        Index++;
                    }
                }

                if (IsProcesar)
                {
                    LoteBE LoteBE = new LoteBE()
                    {
                        USUARIO           = GeneralXML.CodUsuario,
                        OPCION            = 2,
                        IdLote            = string.Empty,
                        IdSocio           = txtIdSocio.Text,
                        sdDesembolso      = GeneralXML.FechaOperacion,
                        IdLinea           = IdLinea,
                        IdMoneda_tt       = IdMoneda_tt,
                        nImporte          = LstDetaLote.Sum(f => f.nvNominal),
                        sdAprobacion      = DateTime.MinValue,
                        nDesembolso       = 0,
                        IdOperacion_tt    = "00080", // Email*******
                        IdFormaDesembolso = IdFormaDesembolso,
                        jComunCuentaID    = string.Empty,
                        jImporteAho       = LstDetaLote.Sum(f => f.nvNominal)
                    };
                    string Result = new LoteBL().ProcesarLote(LoteBE, LstDetaLote);

                    if (!string.IsNullOrEmpty(Result))
                    {
                        DetaLoteBE oEntity = new DetaLoteBE();
                        oEntity.OPCION  = 11;
                        oEntity.USUARIO = GeneralXML.CodUsuario;
                        oEntity.IdLote  = Result;
                        oEntity.IdSocio_Beneficiario = txtCarpetaXML.Text.ToString();
                        oEntity.iPlazo = OrigenLote;
                        DataSet ds = new DetaLoteBL().ProcesarDetaLote(oEntity);

                        if (OrigenLote == 0)
                        {
                            DetaLoteBE oEntityCorrelativo = new DetaLoteBE();
                            oEntityCorrelativo.OPCION  = 12;
                            oEntityCorrelativo.USUARIO = GeneralXML.CodUsuario;
                            DataSet dsCorr = new DetaLoteBL().ProcesarDetaLote(oEntityCorrelativo);

                            string Directorio = ConfigurationManager.AppSettings["RutaDirectorioFEXML"].ToString() + txtCarpetaXML.Text.ToString() + "\\RM-IA-" + DateTime.Now.ToString("ddMMyyyy") + "-" + dsCorr.Tables[0].Rows[0]["Correlativo"].ToString() + "-FTPLA$OVM";
                            ExportToExcel(ds.Tables[0], Directorio, "Hoja1");
                        }

                        MessageBox.Show("Se Proceso Correctamente", "Mensaje", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        IdLinea     = string.Empty;
                        IdMoneda_tt = string.Empty;
                        txtIdSocio.Clear();
                        txtIdSocio_Dsc.Clear();
                        txtIdLinea_Dsc.Clear();
                        txtIdMoneda_tt_Dsc.Clear();
                        txtFecha.Clear();
                        txtIdTipoLinea_tt_Dsc.Clear();
                        txtCarpetaXML.Clear();
                        LstDetaLote             = new List <DetaLoteBE>();
                        LstEntityFE             = new List <FEXMLBE>();
                        dgvFEDetalle.DataSource = LstEntityFE.ToList();
                    }
                    else
                    {
                        MessageBox.Show("Ocurrio un error al procesar", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }

                dgvFEDetalle.DataSource = LstEntityFE.ToList();
                GridFormating();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
 public DataSet ProcesarImportacionLote(ImportacionLoteBE BE)
 {
     return(ImportacionLoteDA.ProcesarImportacionLote(BE));
 }