Esempio n. 1
0
 public ClientResponse InsertGrupoCorreo(GrupoCorreo objeto)
 {
     try
     {
         using (conexion = new SqlConnection(ConexionDAO.cnx))
         {
             using (comando = new SqlCommand("usp_ins_grupocorreo", conexion))
             {
                 comando.Parameters.AddWithValue("@descripcion", objeto.descripcion);
                 comando.Parameters.AddWithValue("@estado", objeto.estado);
                 comando.Parameters.AddWithValue("@origen", objeto.origen);
                 comando.Parameters.Add("@id", SqlDbType.Int).Direction = ParameterDirection.Output;
                 comando.CommandType = CommandType.StoredProcedure;
                 conexion.Open();
                 comando.ExecuteNonQuery();
                 int id = Convert.ToInt32(comando.Parameters["@id"].Value);
                 clientResponse.Id      = id;
                 clientResponse.Mensaje = "Se registro de grupo de correo satisfactoriamente";
                 clientResponse.Status  = "OK";
             }
         }
     }
     catch (Exception ex)
     {
         clientResponse.Mensaje = ex.Message;
         clientResponse.Status  = "ERROR";
     }
     finally
     {
         conexion.Close();
         conexion.Dispose();
         comando.Dispose();
     }
     return(clientResponse);
 }
Esempio n. 2
0
 public ClientResponse EliminarGrupoCorreo(GrupoCorreo objeto)
 {
     try
     {
         using (conexion = new SqlConnection(ConexionDAO.cnx))
         {
             using (comando = new SqlCommand("usp_del_grupocorreo", conexion))
             {
                 comando.Parameters.AddWithValue("@id", objeto.id);
                 comando.Parameters.AddWithValue("@estado", objeto.estado);
                 comando.CommandType = CommandType.StoredProcedure;
                 conexion.Open();
                 comando.ExecuteNonQuery();
                 clientResponse.Mensaje = "Se elimino satisfactoriamente el registro";
                 clientResponse.Status  = "OK";
             }
         }
     }
     catch (Exception ex)
     {
         clientResponse.Mensaje = ex.Message;
         clientResponse.Status  = "ERROR";
     }
     finally
     {
         conexion.Close();
         conexion.Dispose();
         comando.Dispose();
     }
     return(clientResponse);
 }
Esempio n. 3
0
        public ClientResponse getLstGrupoCorreo(int origen, string grupo, int estado, int paginaActual, int RegistroXPagina)
        {
            try
            {
                int recordCount = 0;
                using (conexion = new SqlConnection(ConexionDAO.cnx))
                {
                    using (comando = new SqlCommand("usp_sel_grupocorreo", conexion))
                    {
                        //cmd.Parameters.AddWithValue("@skey", skey);
                        comando.Parameters.AddWithValue("@origen", origen);
                        comando.Parameters.AddWithValue("@grupo", grupo);
                        comando.Parameters.AddWithValue("@estado", estado);
                        comando.Parameters.AddWithValue("@vi_Pagina", paginaActual);
                        comando.Parameters.AddWithValue("@vi_RegistrosporPagina", RegistroXPagina);
                        comando.Parameters.Add("@vi_RecordCount", SqlDbType.Int).Direction = ParameterDirection.Output;
                        comando.CommandType = CommandType.StoredProcedure;
                        conexion.Open();
                        using (reader = comando.ExecuteReader())
                        {
                            while (reader.Read())
                            {
                                entidad             = new GrupoCorreo();
                                entidad.id          = Convert.ToInt32(reader["id"] == DBNull.Value ? 0 : reader["id"]);
                                entidad.descripcion = Convert.ToString(reader["descripcion"] == DBNull.Value ? "" : reader["descripcion"]);
                                entidad.descestado  = Convert.ToString(reader["desestado"] == DBNull.Value ? "" : reader["desestado"]);
                                entidad.descorigen  = Convert.ToString(reader["desorigen"] == DBNull.Value ? "" : reader["desorigen"]);
                                entidad.estado      = Convert.ToInt32(reader["estado"] == DBNull.Value ? 0 : reader["estado"]);
                                entidad.origen      = Convert.ToInt32(reader["origen"] == DBNull.Value ? 0 : reader["origen"]);
                                list_grupocorreo.Add(entidad);
                            }
                        }

                        recordCount = Convert.ToInt32(comando.Parameters["@vi_RecordCount"].Value);
                        Pagination responsepaginacion = new Pagination()
                        {
                            TotalItems = recordCount,
                            TotalPages = (int)Math.Ceiling((double)recordCount / 10)
                        };
                        clientResponse.paginacion = JsonConvert.SerializeObject(responsepaginacion).ToString();
                        clientResponse.DataJson   = JsonConvert.SerializeObject(list_grupocorreo).ToString();
                    }
                }
            }
            catch (Exception ex)
            {
                clientResponse.Mensaje = ex.Message;
                clientResponse.Status  = "ERROR";
            }
            finally
            {
                conexion.Close();
                conexion.Dispose();
                comando.Dispose();
                reader.Dispose();
            }

            return(clientResponse);
        }
Esempio n. 4
0
 public GrupoCorreoDAO()
 {
     list_grupocorreo      = new List <GrupoCorreo>();
     entidad               = null;
     reader                = null;
     clientResponse        = new ClientResponse();
     clientResponse.Status = "OK";
 }
        public ClientResponse getExportarCorreos(int id_cbo_origenfil, int id_cbo_grupo_consultar)
        {
            try
            {
                using (conexion = new SqlConnection(ConexionDAO.cnx))
                {
                    using (comando = new SqlCommand("usp_sel_gestioncorreo_exportar", conexion))
                    {
                        comando.Parameters.AddWithValue("@id_cbo_origenfil", id_cbo_origenfil);
                        comando.Parameters.AddWithValue("@id_grupo_correo", id_cbo_grupo_consultar);
                        comando.CommandType = CommandType.StoredProcedure;
                        conexion.Open();
                        using (reader = comando.ExecuteReader())
                        {
                            while (reader.Read())
                            {
                                entidad            = new GestionCorreo();
                                entidad.id         = Convert.ToInt32(reader["id"] == DBNull.Value ? 0 : reader["id"]);
                                entidad.Nombre1    = Convert.ToString(reader["Nombre1"] == DBNull.Value ? "" : reader["Nombre1"]);
                                entidad.Nombre2    = Convert.ToString(reader["Nombre2"] == DBNull.Value ? "" : reader["Nombre2"]);
                                entidad.ApePaterno = Convert.ToString(reader["apePaterno"] == DBNull.Value ? "" : reader["apePaterno"]);
                                entidad.ApeMaterno = Convert.ToString(reader["apeMaterno"] == DBNull.Value ? "" : reader["apeMaterno"]);
                                entidad.Email      = Convert.ToString(reader["email"] == DBNull.Value ? "" : reader["email"]);

                                entidad.id_estado  = Convert.ToInt32(reader["id_estado"] == DBNull.Value ? 0 : reader["id_estado"]);
                                entidad.descestado = Convert.ToString(reader["desestado"] == DBNull.Value ? "" : reader["desestado"]);
                                GrupoCorreo grupocorreo = new GrupoCorreo();
                                grupocorreo.id          = Convert.ToInt32(reader["id_grupo_correo"] == DBNull.Value ? 0 : reader["id_grupo_correo"]);
                                grupocorreo.descripcion = Convert.ToString(reader["descgrupo_correo"] == DBNull.Value ? "" : reader["descgrupo_correo"]);
                                entidad.grupocorreo     = grupocorreo;
                                entidad.fechabaja       = Convert.ToString(reader["fechabaja"] == DBNull.Value ? "" : reader["fechabaja"]);
                                listgestioncorreo.Add(entidad);
                            }
                        }
                        clientResponse.DataJson = JsonConvert.SerializeObject(listgestioncorreo).ToString();
                    }
                }
            }
            catch (Exception ex)
            {
                clientResponse.Mensaje = ex.Message;
                clientResponse.Status  = "ERROR";
            }
            finally
            {
                conexion.Close();
                conexion.Dispose();
                comando.Dispose();
                reader.Dispose();
            }

            return(clientResponse);
        }
Esempio n. 6
0
        public static ClientResponse EliminarGrupoCorreo(GrupoCorreo objeto)
        {
            ClientResponse response;

            try
            {
                using (GrupoCorreoDAO dbGrupoCorreo = new GrupoCorreoDAO())
                {
                    response = dbGrupoCorreo.EliminarGrupoCorreo(objeto);
                }
            }
            catch (Exception exception)
            {
                throw exception;
            }
            return(response);
        }
Esempio n. 7
0
        public ClientResponse getGrupoCorreoNxOrigen(int origen)
        {
            try
            {
                using (conexion = new SqlConnection(ConexionDAO.cnx))
                {
                    using (comando = new SqlCommand("usp_sel_grupo_N_x_origen", conexion))
                    {
                        comando.CommandType = CommandType.StoredProcedure;
                        comando.Parameters.AddWithValue("@origen", origen);
                        conexion.Open();
                        using (reader = comando.ExecuteReader())
                        {
                            while (reader.Read())
                            {
                                entidad             = new GrupoCorreo();
                                entidad.id          = Convert.ToInt32(reader["id"] == DBNull.Value ? "" : reader["id"]);
                                entidad.descripcion = Convert.ToString(reader["descripcion"] == DBNull.Value ? "" : reader["descripcion"]);
                                list_grupocorreo.Add(entidad);
                            }
                        }
                        clientResponse.DataJson = JsonConvert.SerializeObject(list_grupocorreo).ToString();
                    }
                }
            }
            catch (Exception ex)
            {
                clientResponse.Mensaje = ex.Message;
                clientResponse.Status  = "ERROR";
            }
            finally
            {
                conexion.Close();
                conexion.Dispose();
                comando.Dispose();
                reader.Dispose();
            }

            return(clientResponse);
        }
Esempio n. 8
0
        public ClientResponse getLstLogPromo(string remitente, DateTime?FechaInicial, DateTime?FechaFinal, int paginaActual, int RegistroXPagina)
        {
            try
            {
                int recordCount = 0;
                using (conexion = new SqlConnection(ConexionDAO.cnx))
                {
                    using (comando = new SqlCommand("usp_lista_logpromo", conexion))
                    {
                        comando.Parameters.AddWithValue("@remitente", remitente);
                        comando.Parameters.AddWithValue("@StartDate", FechaInicial);
                        comando.Parameters.AddWithValue("@EndDate", FechaFinal);
                        comando.Parameters.AddWithValue("@vi_Pagina", paginaActual);
                        comando.Parameters.AddWithValue("@vi_RegistrosporPagina", RegistroXPagina);
                        comando.Parameters.Add("@vi_RecordCount", SqlDbType.Int).Direction = ParameterDirection.Output;
                        comando.CommandType = CommandType.StoredProcedure;
                        conexion.Open();
                        using (reader = comando.ExecuteReader())
                        {
                            while (reader.Read())
                            {
                                entidad = new LogPromoDet();
                                GrupoCorreo grupocorreo = new GrupoCorreo();
                                grupocorreo.id          = Convert.ToInt32(reader["id_grupo_correo"] == DBNull.Value ? 0 : reader["id_grupo_correo"]);
                                grupocorreo.descripcion = Convert.ToString(reader["ds_grupo_correo"] == DBNull.Value ? "" : reader["ds_grupo_correo"]);
                                entidad.Cantidad        = Convert.ToInt32(reader["cantidad"] == DBNull.Value ? 0 : reader["cantidad"]);

                                entidad.GrupoCorreo = grupocorreo;

                                LogPromo logpromo = new LogPromo();
                                logpromo.ID     = Convert.ToInt32(reader["logPromoId"] == DBNull.Value ? 0 : reader["logPromoId"]);
                                logpromo.asunto = Convert.ToString(reader["asunto"] == DBNull.Value ? "" : reader["asunto"]);
                                logpromo.fecha  = Convert.ToString(reader["fecha"] == DBNull.Value ? "" : reader["fecha"]);

                                Plantilla plantilla = new Plantilla();
                                plantilla.id          = Convert.ToInt32(reader["plantillaID"] == DBNull.Value ? 0 : reader["plantillaID"]);
                                plantilla.descripcion = Convert.ToString(reader["plantillads"] == DBNull.Value ? "" : reader["plantillads"]);
                                logpromo.Plantilla    = plantilla;

                                Users users = new Users();
                                users.UserName        = Convert.ToString(reader["remitente"] == DBNull.Value ? "" : reader["remitente"]);
                                users.Nombre          = Convert.ToString(reader["Nombre"] == DBNull.Value ? "" : reader["Nombre"]);
                                users.ApellidoPaterno = Convert.ToString(reader["apellidopaterno"] == DBNull.Value ? "" : reader["apellidopaterno"]);
                                users.ApellidoMaterno = Convert.ToString(reader["apellidoMaterno"] == DBNull.Value ? "" : reader["apellidoMaterno"]);
                                logpromo.Users        = users;

                                entidad.LogPromo = logpromo;

                                listLogPromoDet.Add(entidad);
                            }
                        }

                        recordCount = Convert.ToInt32(comando.Parameters["@vi_RecordCount"].Value);
                        Pagination responsepaginacion = new Pagination()
                        {
                            TotalItems = recordCount,
                            TotalPages = (int)Math.Ceiling((double)recordCount / 10)
                        };
                        clientResponse.paginacion = JsonConvert.SerializeObject(responsepaginacion).ToString();
                        clientResponse.DataJson   = JsonConvert.SerializeObject(listLogPromoDet).ToString();
                    }
                }
            }
            catch (Exception ex)
            {
                clientResponse.Mensaje = ex.Message;
                clientResponse.Status  = "ERROR";
            }
            finally
            {
                conexion.Close();
                conexion.Dispose();
                comando.Dispose();
                reader.Dispose();
            }

            return(clientResponse);
        }
        public ClientResponse getLstGestionCorreo(int paginaActual, int RegistroXPagina, int id_cbo_origenfil, int id_cbo_grupo_consultar)
        {
            try
            {
                int recordCount = 0;
                using (conexion = new SqlConnection(ConexionDAO.cnx))
                {
                    using (comando = new SqlCommand("usp_sel_gestioncorreo", conexion))
                    {
                        comando.Parameters.AddWithValue("@id_cbo_origenfil", id_cbo_origenfil);
                        comando.Parameters.AddWithValue("@id_grupo_correo", id_cbo_grupo_consultar);
                        comando.Parameters.AddWithValue("@vi_Pagina", paginaActual);
                        comando.Parameters.AddWithValue("@vi_RegistrosporPagina", RegistroXPagina);
                        comando.Parameters.Add("@vi_RecordCount", SqlDbType.Int).Direction = ParameterDirection.Output;
                        comando.CommandType = CommandType.StoredProcedure;
                        conexion.Open();
                        using (reader = comando.ExecuteReader())
                        {
                            while (reader.Read())
                            {
                                entidad            = new GestionCorreo();
                                entidad.id         = Convert.ToInt32(reader["id"] == DBNull.Value ? 0 : reader["id"]);
                                entidad.Nombre1    = Convert.ToString(reader["Nombre1"] == DBNull.Value ? "" : reader["Nombre1"]);
                                entidad.Nombre2    = Convert.ToString(reader["Nombre2"] == DBNull.Value ? "" : reader["Nombre2"]);
                                entidad.ApePaterno = Convert.ToString(reader["apePaterno"] == DBNull.Value ? "" : reader["apePaterno"]);
                                entidad.ApeMaterno = Convert.ToString(reader["apeMaterno"] == DBNull.Value ? "" : reader["apeMaterno"]);
                                entidad.Email      = Convert.ToString(reader["email"] == DBNull.Value ? "" : reader["email"]);

                                entidad.id_estado  = Convert.ToInt32(reader["id_estado"] == DBNull.Value ? 0 : reader["id_estado"]);
                                entidad.descestado = Convert.ToString(reader["desestado"] == DBNull.Value ? "" : reader["desestado"]);
                                GrupoCorreo grupocorreo = new GrupoCorreo();
                                grupocorreo.id          = Convert.ToInt32(reader["id_grupo_correo"] == DBNull.Value ? 0 : reader["id_grupo_correo"]);
                                grupocorreo.descripcion = Convert.ToString(reader["descgrupo_correo"] == DBNull.Value ? "" : reader["descgrupo_correo"]);
                                entidad.grupocorreo     = grupocorreo;
                                entidad.fechabaja       = Convert.ToString(reader["fechabaja"] == DBNull.Value ? "" : reader["fechabaja"]);
                                listgestioncorreo.Add(entidad);
                            }
                        }

                        recordCount = Convert.ToInt32(comando.Parameters["@vi_RecordCount"].Value);
                        Pagination responsepaginacion = new Pagination()
                        {
                            TotalItems = recordCount,
                            TotalPages = (int)Math.Ceiling((double)recordCount / 10)
                        };
                        clientResponse.paginacion = JsonConvert.SerializeObject(responsepaginacion).ToString();
                        clientResponse.DataJson   = JsonConvert.SerializeObject(listgestioncorreo).ToString();
                    }
                }
            }
            catch (Exception ex)
            {
                clientResponse.Mensaje = ex.Message;
                clientResponse.Status  = "ERROR";
            }
            finally
            {
                conexion.Close();
                conexion.Dispose();
                comando.Dispose();
                reader.Dispose();
            }

            return(clientResponse);
        }
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            context.Response.Expires     = -1;

            try
            {
                string         hora = DateTime.Now.ToString("yyyyMMddhhmmss");
                ClientResponse responseruta;
                using (ParametrosMaestrosDAO dbParametrosMaestro = new ParametrosMaestrosDAO())
                {
                    responseruta = dbParametrosMaestro.getObjParametroMaestro("RUTA_CARGAEXCELCORREOS");
                }
                ParametrosMaestros rutaexcel  = Newtonsoft.Json.JsonConvert.DeserializeObject <ParametrosMaestros>(responseruta.DataJson);
                HttpPostedFile     postedFile = context.Request.Files["Filedata"];
                listgestioncorreo = new List <GestionCorreo>();

                string savepath = "";
                string tempPath = "";

                tempPath = rutaexcel.valor + hora;
                savepath = tempPath;
                string filename = postedFile.FileName;

                if (!Directory.Exists(savepath))
                {
                    Directory.CreateDirectory(savepath);
                }
                string files = savepath + "/" + filename;
                postedFile.SaveAs(files);

                Excel.Application xlApp;
                Excel.Workbook    xlWorkBook;
                Excel.Worksheet   xlWorkSheet;
                Excel.Range       range;

                string str;
                int    rCnt;
                int    cCnt;
                int    rw = 0;
                int    cl = 0;

                xlApp       = new Excel.Application();
                xlWorkBook  = xlApp.Workbooks.Open(files, 0, true, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0);
                xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);

                range = xlWorkSheet.UsedRange;
                rw    = range.Rows.Count;
                cl    = 6;// range.Columns.Count; Leemos solo 6 columnas de cada fila

                ClientResponse response;
                using (GrupoCorreoDAO dbGrupoCorreo = new GrupoCorreoDAO())
                {
                    response = dbGrupoCorreo.getGrupoCorreoCombo(2);
                }

                List <GrupoCorreo> list = JsonConvert.DeserializeObject <List <GrupoCorreo> >(response.DataJson);

                for (rCnt = 1; rCnt <= rw; rCnt++)
                {
                    if (rCnt > 1)
                    {
                        entidad = new GestionCorreo();
                        for (cCnt = 1; cCnt <= cl; cCnt++)
                        {
                            if (cCnt == 1)
                            {
                                GrupoCorreo grupocorreo = new GrupoCorreo();
                                grupocorreo.descripcion = str = (string)(range.Cells[rCnt, cCnt] as Excel.Range).Value2;
                                entidad.grupocorreo     = grupocorreo;
                                //Validamos si el grupo de correo esta registrado en la base de datos
                                grupocorreo.origen = 2;//Carga de Correo externo
                                grupocorreo.estado = 1;
                                GrupoCorreo objeto = list.Where(i => i.descripcion.ToUpper() == grupocorreo.descripcion.ToUpper()).FirstOrDefault();
                                if (objeto != null)
                                {
                                    grupocorreo.id = objeto.id;
                                }
                            }
                            if (cCnt == 2)
                            {
                                entidad.Nombre1 = str = (string)(range.Cells[rCnt, cCnt] as Excel.Range).Value2;
                            }
                            if (cCnt == 3)
                            {
                                entidad.Nombre2 = str = (string)(range.Cells[rCnt, cCnt] as Excel.Range).Value2;
                            }
                            if (cCnt == 4)
                            {
                                entidad.ApePaterno = str = (string)(range.Cells[rCnt, cCnt] as Excel.Range).Value2;
                            }
                            if (cCnt == 5)
                            {
                                entidad.ApeMaterno = str = (string)(range.Cells[rCnt, cCnt] as Excel.Range).Value2;
                            }
                            if (cCnt == 6)
                            {
                                entidad.Email = str = (string)(range.Cells[rCnt, cCnt] as Excel.Range).Value2;
                            }
                        }
                        entidad.id_estado = 1;
                        listgestioncorreo.Add(entidad);
                    }
                }

                xlWorkBook.Close(true, null, null);
                xlApp.Quit();

                Marshal.ReleaseComObject(xlWorkSheet);
                Marshal.ReleaseComObject(xlWorkBook);
                Marshal.ReleaseComObject(xlApp);



                if ((System.IO.File.Exists(files)))
                {
                    System.IO.File.Delete(files);
                }

                if (listgestioncorreo.Count() > 0)
                {
                    ClientResponse response1;
                    using (GestionCorreoDAO dbGestionCorreo = new GestionCorreoDAO())
                    {
                        response1 = dbGestionCorreo.InsertGestionCorreoAutomatico(listgestioncorreo);
                    }
                }


                var wapper = new
                {
                    Result  = "Ok",
                    Mensaje = "Se cargaron correctaente la trama."
                };
                context.Response.Write(JsonConvert.SerializeObject(wapper));
            }

            catch (Exception ex)

            {
                var wapper = new
                {
                    Result  = "Error",
                    Mensaje = ex.Message
                };
                context.Response.Write(JsonConvert.SerializeObject(wapper));
            }
        }