예제 #1
0
        public CampanaENT GetCampanaUsuario(CampanaENT UsuarioENTReq)
        {
            CampanaENT CampanaENTRes = new CampanaENT();

            try
            {
                EntidadesCampanasPPG.BDCampana.Campana Campana = UsuarioENTReq.ListCampana.FirstOrDefault();

                DataTable dtCampana = new DataTable();

                CampanaDAT campanaDAT = new CampanaDAT();

                dtCampana = campanaDAT.GetCampanaUsuario(Campana.PPG_ID);

                CampanaENTRes.ListCampana = dtCampana.AsEnumerable()
                                            .Select(row => new EntidadesCampanasPPG.BDCampana.Campana
                {
                    ID          = row.Field <int?>("ID").GetValueOrDefault(),
                    Camp_Number = row.Field <string>("Camp_Number"),
                    Nombre_Camp = row.Field <string>("Nombre_Camp")
                }).ToList();

                CampanaENTRes.OK      = 1;
                CampanaENTRes.Mensaje = "OK";
            }
            catch (Exception ex)
            {
                CampanaENTRes.OK      = 0;
                CampanaENTRes.Mensaje = "ERROR: Service: GetCampanaUsuario, Source: " + ex.Source + ", Message: " + ex.Message;

                ArchivoLog.EscribirLog(null, "ERROR: Service: GetCampanaUsuario, Source: " + ex.Source + ", Message: " + ex.Message);
            }

            return(CampanaENTRes);
        }
예제 #2
0
        public CampanaENT GetCampana(CampanaENT UsuarioENTReq)
        {
            CampanaENT CampanaENTRes = new CampanaENT();

            try
            {
                EntidadesCampanasPPG.BDCampana.Campana Campana = UsuarioENTReq.ListCampana.FirstOrDefault();

                DataTable dtCampana = new DataTable();

                CampanaDAT campanaDAT = new CampanaDAT();

                dtCampana = campanaDAT.GetCampana(Campana.ID, Campana.Camp_Number, Campana.Nombre_Camp, Campana.Lider_Campania);

                CampanaENTRes.ListCampana = dtCampana.AsEnumerable()
                                            .Select(row => new EntidadesCampanasPPG.BDCampana.Campana
                {
                    ID                   = row.Field <int?>("ID").GetValueOrDefault(),
                    Camp_Number          = row.Field <string>("Camp_Number"),
                    Nombre_Camp          = row.Field <string>("Nombre_Camp"),
                    Nombre_Usuario       = row.Field <string>("Nombre_Usuario"),
                    PPG_ID               = row.Field <string>("PPGID"),
                    Lider_Campania       = row.Field <string>("Lider_Campania"),
                    PPGID_Lider          = row.Field <string>("PPGID_Lider"),
                    Fecha_Inicio_Publico = row.Field <DateTime?>("Fecha_Inicio_Publico").GetValueOrDefault().ToString("dd/MM/yyyy") == "01/01/0001" ? "--/--/----": row.Field <DateTime?>("Fecha_Inicio_Publico").GetValueOrDefault().ToString("dd/MM/yyyy"),
                    Fecha_Fin_Publico    = row.Field <DateTime?>("Fecha_Fin_Publico").GetValueOrDefault().ToString("dd/MM/yyyy") == "01/01/0001" ? "--/--/----": row.Field <DateTime?>("Fecha_Fin_Publico").GetValueOrDefault().ToString("dd/MM/yyyy"),
                    Fecha_Creacion       = row.Field <DateTime?>("Fecha_Creacion").GetValueOrDefault().ToString("dd/MM/yyyy") == "01/01/0001" ? "--/--/----": row.Field <DateTime?>("Fecha_Creacion").GetValueOrDefault().ToString("dd/MM/yyyy"),
                    ID_Moneda            = row.Field <int?>("ID_Moneda").GetValueOrDefault(),
                    Moneda               = row.Field <string>("Moneda"),
                    ID_TipoCamp          = row.Field <int?>("ID_TipoCamp").GetValueOrDefault(),
                    TipoCamp             = row.Field <string>("TipoCamp"),
                    ID_Alcance           = row.Field <int?>("ID_Alcance").GetValueOrDefault(),
                    Alcance              = row.Field <string>("Alcance"),
                    ID_TipoSell          = row.Field <int?>("ID_TipoSell").GetValueOrDefault(),
                    TipoSell             = row.Field <string>("TipoSell"),
                    Express              = row.Field <bool?>("Express").GetValueOrDefault(),
                    ID_Estatus           = row.Field <int?>("ID_Estatus").GetValueOrDefault(),
                    Estatus              = row.Field <string>("Estatus"),
                    EstatusCat           = row.Field <string>("EstatusCat"),
                    TipoSubCanal         = row.Field <string>("TipoSubCanal")
                }).ToList();

                CampanaENTRes.ListCampana.Where(n => n.Express != null).ToList().ForEach(m =>
                {
                    m.strExpress = m.Express == true ? "Si" : "No";
                });

                CampanaENTRes.OK      = 1;
                CampanaENTRes.Mensaje = "OK";
            }
            catch (Exception ex)
            {
                CampanaENTRes.OK      = 0;
                CampanaENTRes.Mensaje = "ERROR: Service: GetCampana, Source: " + ex.Source + ", Message: " + ex.Message;

                ArchivoLog.EscribirLog(null, "ERROR: Service: GetCampana, Source: " + ex.Source + ", Message: " + ex.Message);
            }

            return(CampanaENTRes);
        }
예제 #3
0
        public CampanaENT GetCampanaCronograma(CampanaENT UsuarioENTReq)
        {
            CampanaENT CampanaENTRes = new CampanaENT();

            try
            {
                EntidadesCampanasPPG.BDCampana.Campana Campana = UsuarioENTReq.ListCampana.FirstOrDefault();

                DataTable dtCampana = new DataTable();

                CampanaDAT campanaDAT = new CampanaDAT();

                dtCampana = campanaDAT.GetCampanaCronograma(Campana.ID, Campana.Camp_Number, Campana.Nombre_Camp, Campana.Lider_Campania);

                CampanaENTRes.ListCampana = dtCampana.AsEnumerable()
                                            .Select(row => new EntidadesCampanasPPG.BDCampana.Campana
                {
                    ID                   = row.Field <int?>("ID").GetValueOrDefault(),
                    Camp_Number          = row.Field <string>("Camp_Number"),
                    Nombre_Camp          = row.Field <string>("Nombre_Camp"),
                    Nombre_Usuario       = row.Field <string>("Nombre_Usuario"),
                    PPG_ID               = row.Field <string>("PPGID"),
                    Lider_Campania       = row.Field <string>("Lider_Campania"),
                    PPGID_Lider          = row.Field <string>("PPGID_Lider"),
                    Fecha_Inicio_Publico = row.Field <DateTime?>("Fecha_Inicio_Publico").GetValueOrDefault().ToString("dd/MM/yyyy"),
                    Fecha_Fin_Publico    = row.Field <DateTime?>("Fecha_Fin_Publico").GetValueOrDefault().ToString("dd/MM/yyyy"),
                    Fecha_Creacion       = row.Field <DateTime?>("Fecha_Creacion").GetValueOrDefault().ToString("dd/MM/yyyy"),
                    Fecha_Inicio         = row.Field <DateTime?>("FechaInicio").GetValueOrDefault().ToString("dd/MM/yyyy"),
                    Fecha_Inicio_Real    = row.Field <DateTime?>("FechaInicioReal").GetValueOrDefault().ToString("dd/MM/yyyy"),
                    Fecha_Fin            = row.Field <DateTime?>("FechaFin").GetValueOrDefault().ToString("dd/MM/yyyy"),
                    Fecha_Fin_Real       = row.Field <DateTime?>("FechaFinReal").GetValueOrDefault().ToString("dd/MM/yyyy"),
                    PorcUsuario          = row.Field <decimal?>("PorcentajeUsuario").GetValueOrDefault(),
                    PorcSistema          = row.Field <decimal?>("PorcentajeSistema").GetValueOrDefault(),
                    PorcSistemaReal      = row.Field <decimal?>("PorcentajeSistemaReal").GetValueOrDefault(),
                    ID_Moneda            = row.Field <int?>("ID_Moneda").GetValueOrDefault(),
                    ID_TipoCamp          = row.Field <int?>("ID_TipoCamp").GetValueOrDefault(),
                    ID_Alcance           = row.Field <int?>("ID_Alcance").GetValueOrDefault(),
                    Alcance              = row.Field <string>("Alcance"),
                    Express              = row.Field <bool?>("Express").GetValueOrDefault(),
                    Estatus              = row.Field <string>("Estatus"),
                    ID_Estatus           = row.Field <int?>("ID_Estatus").GetValueOrDefault(),
                    EstatusCat           = row.Field <string>("EstatusCat")
                }).ToList();

                CampanaENTRes.OK      = 1;
                CampanaENTRes.Mensaje = "OK";
            }
            catch (Exception ex)
            {
                CampanaENTRes.OK      = 0;
                CampanaENTRes.Mensaje = "ERROR: Service: GetCampanaCronograma, Source: " + ex.Source + ", Message: " + ex.Message;

                ArchivoLog.EscribirLog(null, "ERROR: Service: GetCampanaCronograma, Source: " + ex.Source + ", Message: " + ex.Message);
            }

            return(CampanaENTRes);
        }
예제 #4
0
        public BitacoraENT GuardarBitacora(BitacoraENT bitacoraENTReq)
        {
            int         respuesta      = 0;
            BitacoraENT bitacoraENTRes = new BitacoraENT();
            BitacoraDAT bitacoraDAT    = new BitacoraDAT();

            EntidadesCampanasPPG.Modelo.Bitacora bitacora = new EntidadesCampanasPPG.Modelo.Bitacora();

            CampanaDAT     campanaDAT     = new CampanaDAT();
            GrupoReporteGR grupoReporteGR = new GrupoReporteGR();

            DataSet   dsReporteGR  = new DataSet();
            DataTable dtReporteGR1 = new DataTable();
            DataTable dtReporteGR2 = new DataTable();

            DataTable        dtParametro   = new DataTable();
            ParametroDAT     parametroDAT  = new ParametroDAT();
            List <Parametro> ListParametro = new List <Parametro>();
            Parametro        parametro     = new Parametro();

            string estatusReporteGR    = string.Empty;
            string nombreArchivo       = string.Empty;
            string pathArchivoCompleto = string.Empty;
            string urlCompleto         = string.Empty;
            string pathArchivo         = string.Empty;
            string url = string.Empty;
            string usuarioSharePoint  = string.Empty;
            string passwordSharePoint = string.Empty;
            string nombreReporte      = string.Empty;
            string nombreReporteFinal = string.Empty;

            string nombreHojaCircular   = string.Empty;
            string nombreTituloCircular = string.Empty;

            DataSet       dsReporteCircular    = new DataSet();
            DataTable     dtReporteCircular    = new DataTable();
            DataTable     dtReporteCircularRes = new DataTable();
            List <string> ListAlcance          = new List <string>();
            List <string> ListAlcanceTotal     = new List <string>();
            string        alcancePrimario      = string.Empty;
            bool          esAlcancePrimario    = false;

            EntidadesCampanasPPG.Modelo.Campana campana = new EntidadesCampanasPPG.Modelo.Campana();
            string claveCampana        = string.Empty;
            string nombreCampana       = string.Empty;
            string fechaInicioSubCanal = string.Empty;
            string fechaFinSubCanal    = string.Empty;
            string fechaInicioPublico  = string.Empty;
            string fechaFinPublico     = string.Empty;

            try
            {
                bitacora = bitacoraENTReq.ListBitacora.FirstOrDefault();

                if (bitacora == null)
                {
                    bitacoraENTRes.Mensaje = "ERROR: No se agregaron todos los datos necesarios para guardar informacion de la bitacora.";

                    return(bitacoraENTRes);
                }

                respuesta = bitacoraDAT.GuardarBitacora(bitacora);

                if (respuesta >= 1)
                {
                    //OBTENER PARAMETROS
                    dtParametro = parametroDAT.GetParametro(0, null);

                    ListParametro = dtParametro.AsEnumerable()
                                    .Select(n => new Parametro
                    {
                        Id     = n.Field <int?>("Id").GetValueOrDefault(),
                        Nombre = n.Field <string>("Nombre"),
                        Valor  = n.Field <string>("Valor")
                    }).ToList();

                    parametro = ListParametro.Where(n => n.Nombre.ToUpper() ==
                                                    ConfigurationManager.AppSettings["EstatusReporteGR"].ToString().ToUpper()).FirstOrDefault();
                    if (parametro != null)
                    {
                        estatusReporteGR = parametro.Valor;
                    }


                    if (bitacora.Estatus.ToUpper() == estatusReporteGR.ToUpper())
                    {
                        #region REPORTE GRAN RED

                        //////////////////
                        //REPORTE GRAN RED
                        grupoReporteGR = campanaDAT.MostrarReporteGR(bitacora.IDCampania);

                        if ((grupoReporteGR.ListCampana != null && grupoReporteGR.ListCampana.Count > 0) ||
                            (grupoReporteGR.ListReporteGR1 != null && grupoReporteGR.ListReporteGR1.Count > 0) ||
                            (grupoReporteGR.ListReporteGR2 != null && grupoReporteGR.ListReporteGR2.Count > 0))
                        {
                            parametro = ListParametro.Where(n => n.Nombre.ToUpper() ==
                                                            ConfigurationManager.AppSettings["DirectorioReporte"].ToString().ToUpper()).FirstOrDefault();
                            if (parametro != null)
                            {
                                pathArchivo = parametro.Valor;
                            }

                            url       = string.Empty;
                            parametro = ListParametro.Where(n => n.Nombre.ToUpper() ==
                                                            ConfigurationManager.AppSettings["UrlReporteGR"].ToString().ToUpper()).FirstOrDefault();
                            if (parametro != null)
                            {
                                url = HttpUtility.HtmlEncode(parametro.Valor);
                            }

                            parametro = ListParametro.Where(n => n.Nombre.ToUpper() ==
                                                            ConfigurationManager.AppSettings["NombreReporteGR"].ToString().ToUpper()).FirstOrDefault();
                            if (parametro != null)
                            {
                                nombreReporte = parametro.Valor + bitacora.ClaveCampania;
                            }

                            parametro = ListParametro.Where(n => n.Nombre.ToUpper() ==
                                                            ConfigurationManager.AppSettings["UsuarioSharePoint"].ToString().ToUpper()).FirstOrDefault();
                            if (parametro != null)
                            {
                                usuarioSharePoint = parametro.Valor;
                            }

                            parametro = ListParametro.Where(n => n.Nombre.ToUpper() ==
                                                            ConfigurationManager.AppSettings["PasswordSharePoint"].ToString().ToUpper()).FirstOrDefault();
                            if (parametro != null)
                            {
                                passwordSharePoint = parametro.Valor;
                            }


                            //DATOS CAMPAÑA
                            if (grupoReporteGR.ListCampana.Count > 0)
                            {
                                campana = grupoReporteGR.ListCampana.FirstOrDefault();

                                claveCampana        = campana.Title;
                                nombreCampana       = campana.NombreCampa;
                                fechaInicioSubCanal = campana.FechaInicioSubCanal;
                                fechaFinSubCanal    = campana.FechaFinSubCanal;
                                fechaInicioPublico  = campana.FechaInicioPublico;
                                fechaFinPublico     = campana.FechaFinPublico;
                            }

                            //AGREGAR PRIMER REPORTE
                            dtReporteGR1.Columns.Add("Id Tienda");
                            dtReporteGR1.Columns.Add("Bill To");
                            dtReporteGR1.Columns.Add("Descripcion Region");
                            dtReporteGR1.Columns.Add("Zona Territorial");
                            dtReporteGR1.Columns.Add("Customer Name");
                            dtReporteGR1.Columns.Add("Segmento");

                            grupoReporteGR.ListReporteGR1.ForEach(n =>
                            {
                                dtReporteGR1.Rows.Add(n.IdTienda, n.BillTo, n.DescripcionRegion,
                                                      n.ZonaTerritorial, n.CustomerName, n.Segmento);
                            });

                            //AGREGAR SEGUNDO REPORTE
                            dtReporteGR2.Columns.Add("Articulo");
                            dtReporteGR2.Columns.Add("Codigo EPR");
                            dtReporteGR2.Columns.Add("Descripcion");
                            dtReporteGR2.Columns.Add("Envase Descripcion");
                            dtReporteGR2.Columns.Add("Mecanica");
                            dtReporteGR2.Columns.Add("Estatus Producto");
                            dtReporteGR2.Columns.Add("Segmento");

                            grupoReporteGR.ListReporteGR2.ForEach(n =>
                            {
                                dtReporteGR2.Rows.Add(n.Articulo, n.CodigoEPR, n.Descripcion,
                                                      n.EnvaseDescripcion, n.Mecanica, n.EstatusProducto,
                                                      n.Segmento);
                            });

                            //CREAR ARCHIVO EXCEL
                            dtReporteGR1.TableName = "GranRed_1";
                            //dsReporteGR.Tables.Add(dtReporteGR1);

                            dtReporteGR2.TableName = "GranRed_2";
                            //dsReporteGR.Tables.Add(dtReporteGR2);


                            nombreArchivo       = Guid.NewGuid().ToString() + ".xlsx";
                            pathArchivoCompleto = Path.Combine(pathArchivo, nombreArchivo);

                            //ExcelLibrary.DataSetHelper.CreateWorkbook(pathArchivoCompleto, dsReporteGR);

                            using (ExcelPackage excel = new ExcelPackage())
                            {
                                excel.Workbook.Worksheets.Add("Reporte_GrandRed_1");
                                excel.Workbook.Worksheets.Add("Reporte_GrandRed_2");

                                var worksheetGranRed_1 = excel.Workbook.Worksheets["Reporte_GrandRed_1"];
                                var worksheetGranRed_2 = excel.Workbook.Worksheets["Reporte_GrandRed_2"];

                                //PAGINA 1
                                worksheetGranRed_1.SetValue("A1", "Reporte Gran Red 1");
                                worksheetGranRed_1.SetValue("A2", "Campaña:");
                                worksheetGranRed_1.SetValue("B2", nombreCampana);
                                worksheetGranRed_1.SetValue("A3", "Clave Campaña:");
                                worksheetGranRed_1.SetValue("B3", claveCampana);

                                worksheetGranRed_1.SetValue("A4", "Fecha Inicio Publico");
                                if (!string.IsNullOrEmpty(fechaInicioPublico) && fechaInicioPublico != "01/01/0001")
                                {
                                    worksheetGranRed_1.SetValue("B4", fechaInicioPublico);
                                }
                                worksheetGranRed_1.SetValue("A5", "Fecha Fin Publico");
                                if (!string.IsNullOrEmpty(fechaFinPublico) && fechaFinPublico != "01/01/0001")
                                {
                                    worksheetGranRed_1.SetValue("B5", fechaFinPublico);
                                }

                                worksheetGranRed_1.Cells["A1:B5"].Style.Font.Color.SetColor(1, 38, 130, 221);
                                worksheetGranRed_1.Cells["A1:B5"].Style.Font.Bold = true;
                                worksheetGranRed_1.Cells["A1:B5"].Style.Font.Size = 14;

                                worksheetGranRed_1.Cells["A7:" + Char.ConvertFromUtf32(dtReporteGR1.Columns.Count + 64) + "7"].LoadFromDataTable(dtReporteGR1, true, OfficeOpenXml.Table.TableStyles.Light2);

                                worksheetGranRed_1.Cells["A7:" + Char.ConvertFromUtf32(dtReporteGR1.Columns.Count + 64) + "7"].Style.Fill.PatternType = ExcelFillStyle.Solid;
                                worksheetGranRed_1.Cells["A7:" + Char.ConvertFromUtf32(dtReporteGR1.Columns.Count + 64) + "7"].Style.Fill.BackgroundColor.SetColor(1, 38, 130, 221);
                                worksheetGranRed_1.Cells["A7:" + Char.ConvertFromUtf32(dtReporteGR1.Columns.Count + 64) + "7"].Style.Font.Color.SetColor(Color.White);

                                //PAGINA 2
                                worksheetGranRed_2.SetValue("A1", "Reporte Gran Red 2");
                                worksheetGranRed_2.SetValue("A2", "Campaña:");
                                worksheetGranRed_2.SetValue("B2", nombreCampana);
                                worksheetGranRed_2.SetValue("A3", "Clave Campaña:");
                                worksheetGranRed_2.SetValue("B3", claveCampana);

                                worksheetGranRed_2.SetValue("A4", "Fecha Inicio Publico");
                                if (!string.IsNullOrEmpty(fechaInicioPublico) && fechaInicioPublico != "01/01/0001")
                                {
                                    worksheetGranRed_2.SetValue("B4", fechaInicioPublico);
                                }
                                worksheetGranRed_2.SetValue("A5", "Fecha Fin Publico");
                                if (!string.IsNullOrEmpty(fechaFinPublico) && fechaFinPublico != "01/01/0001")
                                {
                                    worksheetGranRed_2.SetValue("B5", fechaFinPublico);
                                }

                                worksheetGranRed_2.Cells["A1:B5"].Style.Font.Color.SetColor(1, 38, 130, 221);
                                worksheetGranRed_2.Cells["A1:B5"].Style.Font.Bold = true;
                                worksheetGranRed_2.Cells["A1:B5"].Style.Font.Size = 14;

                                worksheetGranRed_2.Cells["A7:" + Char.ConvertFromUtf32(dtReporteGR2.Columns.Count + 64) + "7"].LoadFromDataTable(dtReporteGR2, true, OfficeOpenXml.Table.TableStyles.Light2);

                                worksheetGranRed_2.Cells["A7:" + Char.ConvertFromUtf32(dtReporteGR2.Columns.Count + 64) + "7"].Style.Fill.PatternType = ExcelFillStyle.Solid;
                                worksheetGranRed_2.Cells["A7:" + Char.ConvertFromUtf32(dtReporteGR2.Columns.Count + 64) + "7"].Style.Fill.BackgroundColor.SetColor(1, 38, 130, 221);
                                worksheetGranRed_2.Cells["A7:" + Char.ConvertFromUtf32(dtReporteGR2.Columns.Count + 64) + "7"].Style.Font.Color.SetColor(Color.White);

                                FileInfo excelFile = new FileInfo(pathArchivoCompleto);
                                excel.SaveAs(excelFile);
                            }

                            urlCompleto = Path.Combine(url, nombreReporte + ".xlsx");

                            using (WebClient client = new WebClient())
                            {
                                System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;
                                client.Credentials = new NetworkCredential(usuarioSharePoint, passwordSharePoint);
                                client.UploadFile(urlCompleto, "PUT", pathArchivoCompleto);
                            }
                        }

                        #endregion

                        #region REPORTE CIRCULAR

                        ////////////////////////
                        //REPORTE CIRCULAR
                        ///////////////////////

                        parametro = ListParametro.Where(n => n.Nombre.ToUpper() ==
                                                        ConfigurationManager.AppSettings["AlcancePrimario"].ToString().ToUpper()).FirstOrDefault();
                        if (parametro != null)
                        {
                            alcancePrimario = parametro.Valor;
                        }

                        parametro = ListParametro.Where(n => n.Nombre.ToUpper() ==
                                                        ConfigurationManager.AppSettings["DirectorioReporte"].ToString().ToUpper()).FirstOrDefault();
                        if (parametro != null)
                        {
                            pathArchivo = parametro.Valor;
                        }

                        url       = string.Empty;
                        parametro = ListParametro.Where(n => n.Nombre.ToUpper() ==
                                                        ConfigurationManager.AppSettings["UrlReporteCircular"].ToString().ToUpper()).FirstOrDefault();
                        if (parametro != null)
                        {
                            url = HttpUtility.HtmlEncode(parametro.Valor);
                        }

                        parametro = ListParametro.Where(n => n.Nombre.ToUpper() ==
                                                        ConfigurationManager.AppSettings["NombreReporteCircular"].ToString().ToUpper()).FirstOrDefault();
                        if (parametro != null)
                        {
                            nombreReporte = parametro.Valor + bitacora.ClaveCampania;
                        }

                        parametro = ListParametro.Where(n => n.Nombre.ToUpper() ==
                                                        ConfigurationManager.AppSettings["UsuarioSharePoint"].ToString().ToUpper()).FirstOrDefault();
                        if (parametro != null)
                        {
                            usuarioSharePoint = parametro.Valor;
                        }

                        parametro = ListParametro.Where(n => n.Nombre.ToUpper() ==
                                                        ConfigurationManager.AppSettings["PasswordSharePoint"].ToString().ToUpper()).FirstOrDefault();
                        if (parametro != null)
                        {
                            passwordSharePoint = parametro.Valor;
                        }

                        //OBTENER REPORTE CIRCULAR
                        dsReporteCircular = campanaDAT.MostrarReporteCircular(bitacora.IDCampania);

                        if (dsReporteCircular != null && dsReporteCircular.Tables.Count > 0)
                        {
                            //OBTENER ALCANCES
                            foreach (DataTable dtAlcance in dsReporteCircular.Tables)
                            {
                                ListAlcance = dtAlcance.AsEnumerable().GroupBy(n => n["Alcance"]).Select(m => m.Key.ToString()).ToList();

                                if (ListAlcance.Count > 0)
                                {
                                    ListAlcanceTotal.AddRange(ListAlcance);
                                }
                            }

                            //CREAR ARCHIVO POR ALCANCE Y AGREGAR HOJAS POR MECANICA

                            foreach (string alcance in ListAlcanceTotal.Distinct())
                            {
                                using (ExcelPackage excel = new ExcelPackage())
                                {
                                    nombreReporteFinal = nombreReporte + "-" + alcance.ToUpper();

                                    nombreArchivo       = Guid.NewGuid().ToString() + ".xlsx";
                                    pathArchivoCompleto = Path.Combine(pathArchivo, nombreArchivo);

                                    esAlcancePrimario = false;

                                    //IDENTIFICA SI ES NACIONAL
                                    if (alcance.ToUpper().Trim() == alcancePrimario)
                                    {
                                        esAlcancePrimario = true;
                                    }

                                    dtReporteCircular    = new DataTable();
                                    dtReporteCircularRes = new DataTable();

                                    //REGALO
                                    if (dsReporteCircular.Tables.Count > 0 && dsReporteCircular.Tables[0].Rows.Count > 0)
                                    {
                                        dtReporteCircular = dsReporteCircular.Tables[0];

                                        dtReporteCircularRes = dtReporteCircular.Clone();

                                        //AGREGA DATOS NACIONAL
                                        if (dtReporteCircular.AsEnumerable().Where(n => n["Alcance"].ToString().ToUpper().Trim() == alcancePrimario.ToUpper().Trim()).ToList().Count > 0)
                                        {
                                            dtReporteCircularRes.Merge(dtReporteCircular.AsEnumerable().Where(n => n["Alcance"].ToString().ToUpper().Trim() == alcancePrimario.ToUpper().Trim()).CopyToDataTable());
                                        }

                                        //AGREGA DATOS DIFERENTE DE NACIONAL
                                        if (!esAlcancePrimario && dtReporteCircular.AsEnumerable().Where(n => n["Alcance"].ToString().ToUpper().Trim() == alcance.ToUpper().Trim()).ToList().Count > 0)
                                        {
                                            dtReporteCircularRes.Merge(dtReporteCircular.AsEnumerable().Where(n => n["Alcance"].ToString().ToUpper().Trim() == alcance.ToUpper().Trim()).CopyToDataTable());
                                        }

                                        nombreHojaCircular = "REGALO";

                                        excel.Workbook.Worksheets.Add(nombreHojaCircular);

                                        var worksheetCircular = excel.Workbook.Worksheets[nombreHojaCircular];

                                        worksheetCircular.SetValue("A1", "Padre");
                                        worksheetCircular.Cells["A1:B1"].Merge = true;
                                        worksheetCircular.SetValue("C1", "Hijo");
                                        worksheetCircular.Cells["C1:D1"].Merge = true;
                                        worksheetCircular.SetValue("E1", "Alcance");

                                        worksheetCircular.Cells["A1:E1"].Style.Font.Color.SetColor(1, 38, 130, 221);
                                        worksheetCircular.Cells["A1:E1"].Style.Font.Bold           = true;
                                        worksheetCircular.Cells["A1:E1"].Style.Font.Size           = 14;
                                        worksheetCircular.Cells["A1:E1"].Style.HorizontalAlignment = ExcelHorizontalAlignment.Center;

                                        worksheetCircular.Cells["A2:" + Char.ConvertFromUtf32(dtReporteCircularRes.Columns.Count + 64) + "2"].LoadFromDataTable(dtReporteCircularRes, true, OfficeOpenXml.Table.TableStyles.Light2);

                                        worksheetCircular.Cells["A2:" + Char.ConvertFromUtf32(dtReporteCircularRes.Columns.Count + 64) + "2"].Style.Fill.PatternType = ExcelFillStyle.Solid;
                                        worksheetCircular.Cells["A2:" + Char.ConvertFromUtf32(dtReporteCircularRes.Columns.Count + 64) + "2"].Style.Fill.BackgroundColor.SetColor(1, 38, 130, 221);
                                        worksheetCircular.Cells["A2:" + Char.ConvertFromUtf32(dtReporteCircularRes.Columns.Count + 64) + "2"].Style.Font.Color.SetColor(Color.White);
                                    }

                                    esAlcancePrimario = false;

                                    //IDENTIFICA SI ES NACIONAL
                                    if (alcance.ToUpper().Trim() == alcancePrimario)
                                    {
                                        esAlcancePrimario = true;
                                    }

                                    dtReporteCircular    = new DataTable();
                                    dtReporteCircularRes = new DataTable();

                                    //MULTIPLO
                                    if (dsReporteCircular.Tables.Count > 1 && dsReporteCircular.Tables[1].Rows.Count > 0)
                                    {
                                        dtReporteCircular = dsReporteCircular.Tables[1];

                                        dtReporteCircularRes = dtReporteCircular.Clone();

                                        //AGREGA DATOS NACIONAL
                                        if (dtReporteCircular.AsEnumerable().Where(n => n["Alcance"].ToString().ToUpper().Trim() == alcancePrimario.ToUpper().Trim()).ToList().Count > 0)
                                        {
                                            dtReporteCircularRes.Merge(dtReporteCircular.AsEnumerable().Where(n => n["Alcance"].ToString().ToUpper().Trim() == alcancePrimario.ToUpper().Trim()).CopyToDataTable());
                                        }

                                        //AGREGA DATOS DIFERENTE DE NACIONAL
                                        if (!esAlcancePrimario && dtReporteCircular.AsEnumerable().Where(n => n["Alcance"].ToString().ToUpper().Trim() == alcance.ToUpper().Trim()).ToList().Count > 0)
                                        {
                                            dtReporteCircularRes.Merge(dtReporteCircular.AsEnumerable().Where(n => n["Alcance"].ToString().ToUpper().Trim() == alcance.ToUpper().Trim()).CopyToDataTable());
                                        }

                                        nombreHojaCircular = "MULTIPLO";

                                        excel.Workbook.Worksheets.Add(nombreHojaCircular);

                                        var worksheetCircular = excel.Workbook.Worksheets[nombreHojaCircular];

                                        worksheetCircular.SetValue("A1", "Padre");
                                        worksheetCircular.Cells["A1:B1"].Merge = true;
                                        worksheetCircular.SetValue("C1", "Alcance");

                                        worksheetCircular.Cells["A1:C1"].Style.Font.Color.SetColor(1, 38, 130, 221);
                                        worksheetCircular.Cells["A1:C1"].Style.Font.Bold           = true;
                                        worksheetCircular.Cells["A1:C1"].Style.Font.Size           = 14;
                                        worksheetCircular.Cells["A1:C1"].Style.HorizontalAlignment = ExcelHorizontalAlignment.Center;

                                        worksheetCircular.Cells["A2:" + Char.ConvertFromUtf32(dtReporteCircularRes.Columns.Count + 64) + "2"].LoadFromDataTable(dtReporteCircularRes, true, OfficeOpenXml.Table.TableStyles.Light2);

                                        worksheetCircular.Cells["A2:" + Char.ConvertFromUtf32(dtReporteCircularRes.Columns.Count + 64) + "2"].Style.Fill.PatternType = ExcelFillStyle.Solid;
                                        worksheetCircular.Cells["A2:" + Char.ConvertFromUtf32(dtReporteCircularRes.Columns.Count + 64) + "2"].Style.Fill.BackgroundColor.SetColor(1, 38, 130, 221);
                                        worksheetCircular.Cells["A2:" + Char.ConvertFromUtf32(dtReporteCircularRes.Columns.Count + 64) + "2"].Style.Font.Color.SetColor(Color.White);
                                    }

                                    esAlcancePrimario = false;

                                    //IDENTIFICA SI ES NACIONAL
                                    if (alcance.ToUpper().Trim() == alcancePrimario)
                                    {
                                        esAlcancePrimario = true;
                                    }

                                    dtReporteCircular    = new DataTable();
                                    dtReporteCircularRes = new DataTable();

                                    //DESCUENTO
                                    if (dsReporteCircular.Tables.Count > 2 && dsReporteCircular.Tables[2].Rows.Count > 0)
                                    {
                                        dtReporteCircular = dsReporteCircular.Tables[2];

                                        dtReporteCircularRes = dtReporteCircular.Clone();

                                        //AGREGA DATOS NACIONAL
                                        if (dtReporteCircular.AsEnumerable().Where(n => n["Alcance"].ToString().ToUpper().Trim() == alcancePrimario.ToUpper().Trim()).ToList().Count > 0)
                                        {
                                            dtReporteCircularRes.Merge(dtReporteCircular.AsEnumerable().Where(n => n["Alcance"].ToString().ToUpper().Trim() == alcancePrimario.ToUpper().Trim()).CopyToDataTable());
                                        }

                                        //AGREGA DATOS DIFERENTE DE NACIONAL
                                        if (!esAlcancePrimario && dtReporteCircular.AsEnumerable().Where(n => n["Alcance"].ToString().ToUpper().Trim() == alcance.ToUpper().Trim()).ToList().Count > 0)
                                        {
                                            dtReporteCircularRes.Merge(dtReporteCircular.AsEnumerable().Where(n => n["Alcance"].ToString().ToUpper().Trim() == alcance.ToUpper().Trim()).CopyToDataTable());
                                        }

                                        nombreHojaCircular = "DESCUENTO";

                                        excel.Workbook.Worksheets.Add(nombreHojaCircular);

                                        var worksheetCircular = excel.Workbook.Worksheets[nombreHojaCircular];

                                        worksheetCircular.SetValue("A1", "Padre");
                                        worksheetCircular.Cells["A1:B1"].Merge = true;
                                        worksheetCircular.SetValue("C1", "Alcance");

                                        worksheetCircular.Cells["A1:C1"].Style.Font.Color.SetColor(1, 38, 130, 221);
                                        worksheetCircular.Cells["A1:C1"].Style.Font.Bold           = true;
                                        worksheetCircular.Cells["A1:C1"].Style.Font.Size           = 14;
                                        worksheetCircular.Cells["A1:C1"].Style.HorizontalAlignment = ExcelHorizontalAlignment.Center;

                                        worksheetCircular.Cells["A2:" + Char.ConvertFromUtf32(dtReporteCircularRes.Columns.Count + 64) + "2"].LoadFromDataTable(dtReporteCircularRes, true, OfficeOpenXml.Table.TableStyles.Light2);

                                        worksheetCircular.Cells["A2:" + Char.ConvertFromUtf32(dtReporteCircularRes.Columns.Count + 64) + "2"].Style.Fill.PatternType = ExcelFillStyle.Solid;
                                        worksheetCircular.Cells["A2:" + Char.ConvertFromUtf32(dtReporteCircularRes.Columns.Count + 64) + "2"].Style.Fill.BackgroundColor.SetColor(1, 38, 130, 221);
                                        worksheetCircular.Cells["A2:" + Char.ConvertFromUtf32(dtReporteCircularRes.Columns.Count + 64) + "2"].Style.Font.Color.SetColor(Color.White);
                                    }

                                    esAlcancePrimario = false;

                                    //IDENTIFICA SI ES NACIONAL
                                    if (alcance.ToUpper().Trim() == alcancePrimario)
                                    {
                                        esAlcancePrimario = true;
                                    }

                                    dtReporteCircular    = new DataTable();
                                    dtReporteCircularRes = new DataTable();

                                    //VOLUMEN
                                    if (dsReporteCircular.Tables.Count > 3 && dsReporteCircular.Tables[3].Rows.Count > 0)
                                    {
                                        dtReporteCircular = dsReporteCircular.Tables[3];

                                        dtReporteCircularRes = dtReporteCircular.Clone();

                                        //AGREGA DATOS NACIONAL
                                        if (dtReporteCircular.AsEnumerable().Where(n => n["Alcance"].ToString().ToUpper().Trim() == alcancePrimario.ToUpper().Trim()).ToList().Count > 0)
                                        {
                                            dtReporteCircularRes.Merge(dtReporteCircular.AsEnumerable().Where(n => n["Alcance"].ToString().ToUpper().Trim() == alcancePrimario.ToUpper().Trim()).CopyToDataTable());
                                        }

                                        //AGREGA DATOS DIFERENTE DE NACIONAL
                                        if (!esAlcancePrimario && dtReporteCircular.AsEnumerable().Where(n => n["Alcance"].ToString().ToUpper().Trim() == alcance.ToUpper().Trim()).ToList().Count > 0)
                                        {
                                            dtReporteCircularRes.Merge(dtReporteCircular.AsEnumerable().Where(n => n["Alcance"].ToString().ToUpper().Trim() == alcance.ToUpper().Trim()).CopyToDataTable());
                                        }

                                        nombreHojaCircular = "VOLUMEN";

                                        excel.Workbook.Worksheets.Add(nombreHojaCircular);

                                        var worksheetCircular = excel.Workbook.Worksheets[nombreHojaCircular];

                                        worksheetCircular.SetValue("A1", "Padre");
                                        worksheetCircular.Cells["A1:B1"].Merge = true;
                                        worksheetCircular.SetValue("C1", "De");
                                        worksheetCircular.SetValue("D1", "Hasta");
                                        worksheetCircular.SetValue("E1", "Descuento");
                                        worksheetCircular.SetValue("F1", "Alcance");

                                        worksheetCircular.Cells["A1:F1"].Style.Font.Color.SetColor(1, 38, 130, 221);
                                        worksheetCircular.Cells["A1:F1"].Style.Font.Bold           = true;
                                        worksheetCircular.Cells["A1:F1"].Style.Font.Size           = 14;
                                        worksheetCircular.Cells["A1:F1"].Style.HorizontalAlignment = ExcelHorizontalAlignment.Center;

                                        worksheetCircular.Cells["A2:" + Char.ConvertFromUtf32(dtReporteCircularRes.Columns.Count + 64) + "2"].LoadFromDataTable(dtReporteCircularRes, true, OfficeOpenXml.Table.TableStyles.Light2);

                                        worksheetCircular.Cells["A2:" + Char.ConvertFromUtf32(dtReporteCircularRes.Columns.Count + 64) + "2"].Style.Fill.PatternType = ExcelFillStyle.Solid;
                                        worksheetCircular.Cells["A2:" + Char.ConvertFromUtf32(dtReporteCircularRes.Columns.Count + 64) + "2"].Style.Fill.BackgroundColor.SetColor(1, 38, 130, 221);
                                        worksheetCircular.Cells["A2:" + Char.ConvertFromUtf32(dtReporteCircularRes.Columns.Count + 64) + "2"].Style.Font.Color.SetColor(Color.White);
                                    }

                                    esAlcancePrimario = false;

                                    //IDENTIFICA SI ES NACIONAL
                                    if (alcance.ToUpper().Trim() == alcancePrimario)
                                    {
                                        esAlcancePrimario = true;
                                    }

                                    dtReporteCircular    = new DataTable();
                                    dtReporteCircularRes = new DataTable();

                                    //KIT
                                    if (dsReporteCircular.Tables.Count > 4 && dsReporteCircular.Tables[4].Rows.Count > 0)
                                    {
                                        dtReporteCircular = dsReporteCircular.Tables[4];

                                        dtReporteCircularRes = dtReporteCircular.Clone();

                                        //AGREGA DATOS NACIONAL
                                        if (dtReporteCircular.AsEnumerable().Where(n => n["Alcance"].ToString().ToUpper().Trim() == alcancePrimario.ToUpper().Trim()).ToList().Count > 0)
                                        {
                                            dtReporteCircularRes.Merge(dtReporteCircular.AsEnumerable().Where(n => n["Alcance"].ToString().ToUpper().Trim() == alcancePrimario.ToUpper().Trim()).CopyToDataTable());
                                        }

                                        //AGREGA DATOS DIFERENTE DE NACIONAL
                                        if (!esAlcancePrimario && dtReporteCircular.AsEnumerable().Where(n => n["Alcance"].ToString().ToUpper().Trim() == alcance.ToUpper().Trim()).ToList().Count > 0)
                                        {
                                            dtReporteCircularRes.Merge(dtReporteCircular.AsEnumerable().Where(n => n["Alcance"].ToString().ToUpper().Trim() == alcance.ToUpper().Trim()).CopyToDataTable());
                                        }

                                        nombreHojaCircular = "KIT";

                                        excel.Workbook.Worksheets.Add(nombreHojaCircular);

                                        var worksheetCircular = excel.Workbook.Worksheets[nombreHojaCircular];

                                        worksheetCircular.SetValue("A1", "Padre");
                                        worksheetCircular.Cells["A1:B1"].Merge = true;
                                        worksheetCircular.SetValue("C1", "Hijo");
                                        worksheetCircular.Cells["C1:D1"].Merge = true;
                                        worksheetCircular.SetValue("E1", "Descuento");
                                        worksheetCircular.SetValue("F1", "Importe");
                                        worksheetCircular.SetValue("G1", "Alcance");

                                        worksheetCircular.Cells["A1:G1"].Style.Font.Color.SetColor(1, 38, 130, 221);
                                        worksheetCircular.Cells["A1:G1"].Style.Font.Bold           = true;
                                        worksheetCircular.Cells["A1:G1"].Style.Font.Size           = 14;
                                        worksheetCircular.Cells["A1:G1"].Style.HorizontalAlignment = ExcelHorizontalAlignment.Center;

                                        worksheetCircular.Cells["A2:" + Char.ConvertFromUtf32(dtReporteCircularRes.Columns.Count + 64) + "2"].LoadFromDataTable(dtReporteCircularRes, true, OfficeOpenXml.Table.TableStyles.Light2);

                                        worksheetCircular.Cells["A2:" + Char.ConvertFromUtf32(dtReporteCircularRes.Columns.Count + 64) + "2"].Style.Fill.PatternType = ExcelFillStyle.Solid;
                                        worksheetCircular.Cells["A2:" + Char.ConvertFromUtf32(dtReporteCircularRes.Columns.Count + 64) + "2"].Style.Fill.BackgroundColor.SetColor(1, 38, 130, 221);
                                        worksheetCircular.Cells["A2:" + Char.ConvertFromUtf32(dtReporteCircularRes.Columns.Count + 64) + "2"].Style.Font.Color.SetColor(Color.White);
                                    }

                                    esAlcancePrimario = false;

                                    //IDENTIFICA SI ES NACIONAL
                                    if (alcance.ToUpper().Trim() == alcancePrimario)
                                    {
                                        esAlcancePrimario = true;
                                    }

                                    dtReporteCircular    = new DataTable();
                                    dtReporteCircularRes = new DataTable();

                                    //COMBO
                                    if (dsReporteCircular.Tables.Count > 5 && dsReporteCircular.Tables[5].Rows.Count > 0)
                                    {
                                        dtReporteCircular = dsReporteCircular.Tables[5];

                                        dtReporteCircularRes = dtReporteCircular.Clone();

                                        //AGREGA DATOS NACIONAL
                                        if (dtReporteCircular.AsEnumerable().Where(n => n["Alcance"].ToString().ToUpper().Trim() == alcancePrimario.ToUpper().Trim()).ToList().Count > 0)
                                        {
                                            dtReporteCircularRes.Merge(dtReporteCircular.AsEnumerable().Where(n => n["Alcance"].ToString().ToUpper().Trim() == alcancePrimario.ToUpper().Trim()).CopyToDataTable());
                                        }

                                        //AGREGA DATOS DIFERENTE DE NACIONAL
                                        if (!esAlcancePrimario && dtReporteCircular.AsEnumerable().Where(n => n["Alcance"].ToString().ToUpper().Trim() == alcance.ToUpper().Trim()).ToList().Count > 0)
                                        {
                                            dtReporteCircularRes.Merge(dtReporteCircular.AsEnumerable().Where(n => n["Alcance"].ToString().ToUpper().Trim() == alcance.ToUpper().Trim()).CopyToDataTable());
                                        }

                                        nombreHojaCircular = "COMBO";

                                        excel.Workbook.Worksheets.Add(nombreHojaCircular);

                                        var worksheetCircular = excel.Workbook.Worksheets[nombreHojaCircular];

                                        worksheetCircular.SetValue("A1", "Padre");
                                        worksheetCircular.Cells["A1:B1"].Merge = true;
                                        worksheetCircular.SetValue("C1", "Madre");
                                        worksheetCircular.Cells["C1:D1"].Merge = true;
                                        worksheetCircular.SetValue("E1", "Hijo");
                                        worksheetCircular.Cells["E1:F1"].Merge = true;
                                        worksheetCircular.SetValue("G1", "Alcance");

                                        worksheetCircular.Cells["A1:G1"].Style.Font.Color.SetColor(1, 38, 130, 221);
                                        worksheetCircular.Cells["A1:G1"].Style.Font.Bold           = true;
                                        worksheetCircular.Cells["A1:G1"].Style.Font.Size           = 14;
                                        worksheetCircular.Cells["A1:G1"].Style.HorizontalAlignment = ExcelHorizontalAlignment.Center;

                                        worksheetCircular.Cells["A2:" + Char.ConvertFromUtf32(dtReporteCircularRes.Columns.Count + 64) + "2"].LoadFromDataTable(dtReporteCircularRes, true, OfficeOpenXml.Table.TableStyles.Light2);

                                        worksheetCircular.Cells["A2:" + Char.ConvertFromUtf32(dtReporteCircularRes.Columns.Count + 64) + "2"].Style.Fill.PatternType = ExcelFillStyle.Solid;
                                        worksheetCircular.Cells["A2:" + Char.ConvertFromUtf32(dtReporteCircularRes.Columns.Count + 64) + "2"].Style.Fill.BackgroundColor.SetColor(1, 38, 130, 221);
                                        worksheetCircular.Cells["A2:" + Char.ConvertFromUtf32(dtReporteCircularRes.Columns.Count + 64) + "2"].Style.Font.Color.SetColor(Color.White);
                                    }

                                    FileInfo excelFile = new FileInfo(pathArchivoCompleto);
                                    excel.SaveAs(excelFile);
                                }

                                urlCompleto = Path.Combine(url, nombreReporteFinal + ".xlsx");

                                using (WebClient client = new WebClient())
                                {
                                    System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;
                                    client.Credentials = new NetworkCredential(usuarioSharePoint, passwordSharePoint);
                                    client.UploadFile(urlCompleto, "PUT", pathArchivoCompleto);
                                }
                            }
                        }

                        #endregion
                    }

                    bitacoraENTRes.Mensaje = "OK";
                }
                else
                {
                    bitacoraENTRes.Mensaje = "ERROR: Ocurrio un problema inesperado, identifique si se guardo correctamente la informacion, o consulte al administrador de sistemas.";

                    ArchivoLog.EscribirLog(null, "ERROR: Service - MostrarRentabilidad, Ocurrio un problema en el SP de Guardar Bitacora. ");
                }
            }
            catch (Exception ex)
            {
                bitacoraENTRes.Mensaje = "ERROR: " + ex.Message;

                ArchivoLog.EscribirLog(null, "ERROR: Service - MostrarRentabilidad, Source:" + ex.Source + ", Message:" + ex.Message);
            }

            return(bitacoraENTRes);
        }
예제 #5
0
        public MecanicaENT GetCampanaMecanica(MecanicaENT mecanicaENTReq)
        {
            MecanicaENT mecanicaENTRes = new MecanicaENT();
            DataSet     dsMecanicas    = new DataSet();

            try
            {
                if (mecanicaENTReq == null)
                {
                    return(mecanicaENTRes);
                }

                CampanaDAT campanaDAT = new CampanaDAT();

                dsMecanicas = campanaDAT.GetCampanaMecanica(mecanicaENTReq.IdCampana);

                //REGALO
                mecanicaENTRes.ListMecanicaRegalo = dsMecanicas.Tables[0].AsEnumerable()
                                                    .Select(row => new MecanicaRegalo
                {
                    ClaveCampana   = mecanicaENTReq.ClaveCampana,
                    IdCampana      = row.Field <int?>("ID_Campania").GetValueOrDefault(),
                    Familia        = row.Field <string>("Familia"),
                    SKU            = row.Field <string>("Articulo"),
                    Descripcion    = row.Field <string>("Descripcion"),
                    Tipo           = row.Field <string>("Tipo"),
                    Grupo_Regalo   = row.Field <int?>("Grupo_Regalo").GetValueOrDefault(),
                    NumeroHijo     = row.Field <int?>("Numero_Hijo").GetValueOrDefault(),
                    Alcance        = row.Field <string>("Alcance"),
                    Capacidad      = row.Field <string>("Capacidad"),
                    Dinamica       = row.Field <string>("Dinamica"),
                    VLitrosAnioAnt = row.Field <decimal?>("Ventas_Litros_Anio_Anterior").GetValueOrDefault(),
                    PLitrosSinCamp = row.Field <decimal?>("Presupuesto_Litros_Sin_Campania").GetValueOrDefault(),
                    PLitrosConCamp = row.Field <decimal?>("Presupuesto_Litros_Con_Campania").GetValueOrDefault()
                }).ToList();

                //MULTIPLO
                mecanicaENTRes.ListMecanicaMultiplo = dsMecanicas.Tables[1].AsEnumerable()
                                                      .Select(row => new MecanicaMultiplo
                {
                    ClaveCampana   = mecanicaENTReq.ClaveCampana,
                    IdCampana      = row.Field <int?>("ID_Campania").GetValueOrDefault(),
                    Familia        = row.Field <string>("Familia"),
                    SKU            = row.Field <string>("SKU"),
                    Descripcion    = row.Field <string>("Descripcion"),
                    Alcance        = row.Field <string>("Alcance"),
                    Capacidad      = row.Field <string>("Capacidad"),
                    Dinamica       = row.Field <string>("Dinamica"),
                    Multiplo_Padre = row.Field <int?>("MultiploPadre").GetValueOrDefault(),
                    Multiplo_Hijo  = row.Field <int?>("MultiploHijo").GetValueOrDefault(),
                    Punto_Venta    = row.Field <string>("Punto_Venta"),
                    VLitrosAnioAnt = row.Field <decimal?>("Venta_Anio_Anterior").GetValueOrDefault(),
                    PLitrosSinCamp = row.Field <decimal?>("Presupuesto_Sin_Campania").GetValueOrDefault(),
                    PLitrosConCamp = row.Field <decimal?>("Presupuesto_Con_Campania").GetValueOrDefault()
                }).ToList();

                //DESCUENTO
                mecanicaENTRes.ListMecanicaDescuento = dsMecanicas.Tables[2].AsEnumerable()
                                                       .Select(row => new MecanicaDescuento
                {
                    ClaveCampana   = mecanicaENTReq.ClaveCampana,
                    IdCampana      = row.Field <int?>("ID_Campania").GetValueOrDefault(),
                    Familia        = row.Field <string>("Familia"),
                    SKU            = row.Field <string>("Articulo"),
                    Descripcion    = row.Field <string>("Descripcion"),
                    Alcance        = row.Field <string>("Alcance"),
                    Capacidad      = row.Field <string>("Capacidad"),
                    Dinamica       = row.Field <string>("Dinamica"),
                    Porcentaje     = row.Field <decimal?>("Porcentaje").GetValueOrDefault(),
                    Importe        = row.Field <decimal?>("Importe").GetValueOrDefault(),
                    VLitrosAnioAnt = row.Field <decimal?>("VentaAñoAnterior").GetValueOrDefault(),
                    PLitrosSinCamp = row.Field <decimal?>("PresupuestoSinCampaña").GetValueOrDefault(),
                    PLitrosConCamp = row.Field <decimal?>("PresupuestoConCampaña").GetValueOrDefault()
                }).ToList();

                //VOLUMEN
                mecanicaENTRes.ListMecanicaVolumen = dsMecanicas.Tables[3].AsEnumerable()
                                                     .Select(row => new MecanicaVolumen
                {
                    ClaveCampana   = mecanicaENTReq.ClaveCampana,
                    IdCampana      = row.Field <int?>("ID_Campania").GetValueOrDefault(),
                    Familia        = row.Field <string>("Familia"),
                    SKU            = row.Field <string>("Articulo"),
                    Descripcion    = row.Field <string>("Descripcion"),
                    Bloque         = row.Field <int?>("Bloque").GetValueOrDefault(),
                    Alcance        = row.Field <string>("Alcance"),
                    Capacidad      = row.Field <string>("Capacidad"),
                    Dinamica       = row.Field <string>("Dinamica"),
                    De             = row.Field <decimal?>("VentaDesde").GetValueOrDefault(),
                    Hasta          = row.Field <decimal?>("VentaHasta").GetValueOrDefault(),
                    Descuento      = row.Field <decimal?>("PorcentajeDescuento").GetValueOrDefault(),
                    VLitrosAnioAnt = row.Field <decimal?>("VentaAnioAnterior").GetValueOrDefault(),
                    PLitrosSinCamp = row.Field <decimal?>("PresupuestoSinCampania").GetValueOrDefault(),
                    PLitrosConCamp = row.Field <decimal?>("PresupuestoConCampania").GetValueOrDefault()
                }).ToList();

                //KIT
                mecanicaENTRes.ListMecanicaKit = dsMecanicas.Tables[4].AsEnumerable()
                                                 .Select(row => new MecanicaKit
                {
                    ClaveCampana   = mecanicaENTReq.ClaveCampana,
                    IdCampana      = row.Field <int?>("ID_Campania").GetValueOrDefault(),
                    Familia        = row.Field <string>("Familia"),
                    SKU            = row.Field <string>("Articulo"),
                    Descripcion    = row.Field <string>("Descripcion"),
                    Alcance        = row.Field <string>("Alcance"),
                    Capacidad      = row.Field <string>("Capacidad"),
                    Dinamica       = row.Field <string>("Dinamica"),
                    Porcentaje     = row.Field <decimal?>("Porcentaje").GetValueOrDefault(),
                    Importe        = row.Field <decimal?>("Importe").GetValueOrDefault(),
                    VLitrosAnioAnt = row.Field <decimal?>("VentaAnioAnterior").GetValueOrDefault(),
                    PLitrosSinCamp = row.Field <decimal?>("PresupuestoSinCampania").GetValueOrDefault(),
                    PLitrosConCamp = row.Field <decimal?>("PresupuestoConCampania").GetValueOrDefault()
                }).ToList();

                //COMBO
                mecanicaENTRes.ListMecanicaCombo = dsMecanicas.Tables[5].AsEnumerable()
                                                   .Select(row => new MecanicaCombo
                {
                    ClaveCampana   = mecanicaENTReq.ClaveCampana,
                    IdCampana      = row.Field <int?>("ID_Campania").GetValueOrDefault(),
                    Familia        = row.Field <string>("Familia"),
                    SKU            = row.Field <string>("Articulo"),
                    Descripcion    = row.Field <string>("Descripcion"),
                    Tipo           = row.Field <string>("TipoArticulo"),
                    GrupoCombo     = row.Field <int?>("Grupo_Combo").GetValueOrDefault(),
                    NumeroPadre    = row.Field <int?>("Numero_Padre").GetValueOrDefault(),
                    NumeroHijo     = row.Field <int?>("Numero_Hijo").GetValueOrDefault(),
                    Alcance        = row.Field <string>("Alcance"),
                    Capacidad      = row.Field <string>("Capacidad"),
                    Dinamica       = row.Field <string>("Dinamica"),
                    VLitrosAnioAnt = row.Field <decimal?>("VentaAnioAnterior").GetValueOrDefault(),
                    PLitrosSinCamp = row.Field <decimal?>("PresupuestoSinCampania").GetValueOrDefault(),
                    PLitrosConCamp = row.Field <decimal?>("PresupuestoConCampania").GetValueOrDefault()
                }).ToList();

                //TIENDAS
                mecanicaENTRes.ListMecanicaTiendas = dsMecanicas.Tables[6].AsEnumerable()
                                                     .Select(row => new MecanicaTiendas
                {
                    ClaveCampania      = mecanicaENTReq.ClaveCampana,
                    IdCampania         = row.Field <int?>("ID_Campania").GetValueOrDefault(),
                    Id_Tienda          = row.Field <int?>("ID_Tienda").GetValueOrDefault(),
                    Bill_To            = row.Field <string>("Bill_To"),
                    Customer_Name      = row.Field <string>("Customer_Name"),
                    Region             = row.Field <string>("Region"),
                    Descripcion_Region = row.Field <string>("Descripcion_Region"),
                    Descripcion_Zona   = row.Field <string>("Descripcion_Zona"),
                    Segmento           = row.Field <string>("Segmento"),
                    Clave_Sobrepecio   = row.Field <string>("Clave_Sobreprecio"),
                }).ToList();

                mecanicaENTRes.OK      = 1;
                mecanicaENTRes.Mensaje = "OK";
            }
            catch (Exception ex)
            {
                mecanicaENTRes.OK      = 0;
                mecanicaENTRes.Mensaje = "ERROR: Service: GetCampanaMecanica, Source: " + ex.Source + ", Message: " + ex.Message;

                ArchivoLog.EscribirLog(null, "ERROR: Service: GetCampanaMecanica, Source: " + ex.Source + ", Message: " + ex.Message);
            }

            return(mecanicaENTRes);
        }