Esempio n. 1
0
        private static void GenerarArchivoGanadores(beIncentivoPDVGanadorLista incentivoGanadorLista, StringBuilder log)
        {
            if (incentivoGanadorLista == null || incentivoGanadorLista.IncentivoGanador == null ||
                incentivoGanadorLista.ListaIncentivoGanador.Count == 0)
            {
                return;
            }

            int    x          = 0;
            string rutaSalida = ConfigurationManager.AppSettings["rutaSalida"];
            beIncentivoPDVGanador obeIncentivoPDVGanador;
            string             idDistribuidor      = incentivoGanadorLista.ListaIncentivoGanador[0].DistribuidorId.Substring(0, 3);
            StringBuilder      sb                  = new StringBuilder();
            beIncentivoGanador obeIncentivoGanador = incentivoGanadorLista.IncentivoGanador;

            sb.AppendLine(String.Format("{0},{1},{2},{3},{4}", idDistribuidor, obeIncentivoGanador.IncentivoId, obeIncentivoGanador.Descripcion, obeIncentivoGanador.FechaInicio, obeIncentivoGanador.FechaFin));
            string nombre;
            string archivo;
            string nombreZip;
            string archivoZip;

            for (int i = 0; i < incentivoGanadorLista.ListaIncentivoGanador.Count; i++)
            {
                obeIncentivoPDVGanador = incentivoGanadorLista.ListaIncentivoGanador[i];
                if (obeIncentivoPDVGanador.DistribuidorId.Substring(0, 3).Equals(idDistribuidor))
                {
                    sb.AppendLine(String.Format("{0},{1},{2},{3},{4:n2}", obeIncentivoPDVGanador.IncentivoId, obeIncentivoPDVGanador.DistribuidorId, obeIncentivoPDVGanador.PuntoVentaId, obeIncentivoPDVGanador.NumeroCelular, obeIncentivoPDVGanador.MontoIncentivo));
                }
                //else
                if (!obeIncentivoPDVGanador.DistribuidorId.Substring(0, 3).Equals(idDistribuidor) || (i == incentivoGanadorLista.ListaIncentivoGanador.Count - 1))
                {
                    nombre  = String.Format("G{0}_{1}_{2}.csv", incentivoGanadorLista.FechaCorrelativo, obeIncentivoGanador.IncentivoId, idDistribuidor);
                    archivo = Path.Combine(rutaSalida, nombre);
                    File.WriteAllText(archivo, sb.ToString());
                    log.AppendLine("Archivo generado " + archivo);
                    idDistribuidor = obeIncentivoPDVGanador.DistribuidorId.Substring(0, 3);
                    sb.Clear();
                    sb.AppendLine(String.Format("{0},{1},{2},{3},{4}", idDistribuidor, obeIncentivoGanador.IncentivoId, obeIncentivoGanador.Descripcion, obeIncentivoGanador.FechaInicio, obeIncentivoGanador.FechaFin));
                    sb.AppendLine(String.Format("{0},{1},{2},{3},{4:n2}", obeIncentivoPDVGanador.IncentivoId, obeIncentivoPDVGanador.DistribuidorId, obeIncentivoPDVGanador.PuntoVentaId, obeIncentivoPDVGanador.NumeroCelular, obeIncentivoPDVGanador.MontoIncentivo));
                    x++;
                }
            }
        }
Esempio n. 2
0
        private static beIncentivoPDVGanadorLista LlamarUspCargarPagaDiario(DateTime fecha, StringBuilder log)
        {
            string cadenaConexion = ConfigurationManager.ConnectionStrings["con"].ConnectionString;

            using (SqlConnection con = new SqlConnection(cadenaConexion))
            {
                beIncentivoPDVGanadorLista obeIncentivoPDVGanadorLista = new beIncentivoPDVGanadorLista();
                SqlCommand cmd = new SqlCommand("uspCargarPagaDiario", con);
                cmd.CommandType = CommandType.StoredProcedure;

                SqlParameter par1 = cmd.Parameters.Add("@FechaProceso", SqlDbType.DateTime);
                par1.Direction = ParameterDirection.Input;
                par1.Value     = fecha;

                con.Open();
                SqlDataReader                drd = cmd.ExecuteReader();
                beIncentivoGanador           obeIncentivoGanador    = null;
                List <beIncentivoPDVGanador> lbeIncentivoPDVGanador = null;

                if (drd != null)
                {
                    if (drd.HasRows)
                    {
                        drd.Read();
                        int posIncentivoId = drd.GetOrdinal("IncentivoId");
                        int posDescripcion = drd.GetOrdinal("Descripcion");
                        int posFechaInicio = drd.GetOrdinal("FechaInicio");
                        int posFechaFin    = drd.GetOrdinal("FechaFin");
                        obeIncentivoGanador             = new beIncentivoGanador();
                        obeIncentivoGanador.IncentivoId = drd.GetInt32(posIncentivoId);
                        obeIncentivoGanador.Descripcion = drd.GetString(posDescripcion);
                        obeIncentivoGanador.FechaInicio = drd.GetDateTime(posFechaInicio);
                        obeIncentivoGanador.FechaFin    = drd.GetDateTime(posFechaFin);
                        if (drd.NextResult())
                        {
                            int posIncentId       = drd.GetOrdinal("IncentivoId");
                            int posDistribuidorId = drd.GetOrdinal("DistribuidorId");
                            int posPuntoVentaId   = drd.GetOrdinal("PuntoVentaId");
                            int posNumeroCelular  = drd.GetOrdinal("NumeroCelular");
                            int posMontoIncentivo = drd.GetOrdinal("MontoIncentivo");
                            lbeIncentivoPDVGanador = new List <beIncentivoPDVGanador>();
                            beIncentivoPDVGanador obeIncentivoPDVGanador;
                            while (drd.Read())
                            {
                                obeIncentivoPDVGanador                = new beIncentivoPDVGanador();
                                obeIncentivoPDVGanador.IncentivoId    = drd.GetInt32(posIncentId);
                                obeIncentivoPDVGanador.DistribuidorId = drd.GetString(posDistribuidorId);
                                obeIncentivoPDVGanador.PuntoVentaId   = drd.GetString(posPuntoVentaId);
                                obeIncentivoPDVGanador.NumeroCelular  = drd.GetString(posNumeroCelular);
                                obeIncentivoPDVGanador.MontoIncentivo = drd.GetDecimal(posMontoIncentivo);
                                lbeIncentivoPDVGanador.Add(obeIncentivoPDVGanador);
                            }
                        }
                    }
                    drd.Close();
                    obeIncentivoPDVGanadorLista.FechaCorrelativo = fecha.ToString("yyyyMMdd");
                }
                obeIncentivoPDVGanadorLista.IncentivoGanador      = obeIncentivoGanador;
                obeIncentivoPDVGanadorLista.ListaIncentivoGanador = lbeIncentivoPDVGanador;
                log.AppendLine("Llamada a uspCargarPagaDiario, registros obtenidos: " + lbeIncentivoPDVGanador.Count);
                return(obeIncentivoPDVGanadorLista);
            }
        }