Esempio n. 1
0
 public List<CedForecastEntidades.RFoPA> Lista(CedForecastEntidades.RFoPA Forecast, string TipoReporte, string ListaArticulos, string ListaClientes, string ListaVendedores)
 {
     cantidadFilas = 0;
     System.Text.StringBuilder a = new StringBuilder();
     a.Append("select Forecast.IdTipoPlanilla, Forecast.IdCuenta, Forecast.IdCliente, Forecast.IdPeriodo, Forecast.IdArticulo, Forecast.Cantidad, isnull(FamiliaArticulo.IdFamiliaArticulo, '') as IdFamiliaArticulo, isnull(FamiliaArticulo.DescrFamiliaArticulo, '') as DescrFamiliaArticulo ");
     //Articulo.DescrArticulo, Articulo.IdGrupoArticulo, GrupoArticulo.DescrGrupoArticulo, Division.IdDivision, Division.DescrDivision,
     a.Append("from Forecast left outer join FamiliaArticuloXArticulo on Forecast.IdArticulo = FamiliaArticuloXArticulo.IdArticulo ");
     a.Append("left outer join FamiliaArticulo on FamiliaArticuloXArticulo.IdFamiliaArticulo = FamiliaArticulo.IdFamiliaArticulo ");
     //, Articulo, GrupoArticulo, Division ");
     a.Append("where Forecast.IdTipoPlanilla='" + Forecast.IdTipoPlanilla + "' ");
     //Forecast.IdArticulo=Articulo.IdArticulo and Articulo.IdGrupoArticulo=GrupoArticulo.IdGrupoArticulo and GrupoArticulo.IdDivision=Division.IdDivision
     if (ListaArticulos != "")
     {
         a.Append("and Forecast.IdArticulo in (" + ListaArticulos + ") "); 
     }
     if (ListaClientes != "")
     {
         a.Append("and Forecast.IdCliente in (" + ListaClientes + ") ");
     }
     if (ListaVendedores != "")
     {
         a.Append("and Forecast.IdCuenta in (" + ListaVendedores + ") ");
     }
     if (Forecast.IdCliente != null && Forecast.IdCliente != "")
     {
         a.Append("and Forecast.IdCliente='" + Forecast.IdCliente + "' ");
     }
     string periodo = "";
     periodo = UltimoMesForecast(Forecast.IdPeriodo);
     if (Forecast.IdTipoPlanilla == "Proyectado" && Forecast.IdPeriodo.Substring(0, 4) == periodo.Substring(0, 4))
     {
         periodo = Forecast.IdPeriodo.Substring(0, 4) + "99";
     }
     a.Append("and IdPeriodo >= '" + Forecast.IdPeriodo + "' ");
     a.Append("and IdPeriodo <= '" + periodo + "' ");
     switch (TipoReporte)
     {
         case "FamArtCliVen":
         case "FamArtCli":
         case "FamArt":
             a.Append("order by IdArticulo asc, IdCliente asc, IdCuenta asc, IdPeriodo asc ");
             break;
         case "FamArtVen":
             a.Append("order by IdArticulo asc, IdCuenta asc, IdCliente asc, IdPeriodo asc ");
             break;
         case "Fam":
             a.Append("order by IdFamiliaArticulo asc, IdArticulo asc, IdCuenta asc, IdCliente asc, IdPeriodo asc ");
             break;
     }
     DataTable dt = new DataTable();  
     dt = (DataTable)Ejecutar(a.ToString(), TipoRetorno.TB, Transaccion.NoAcepta, sesion.CnnStr);
     List<CedForecastEntidades.RFoPA> lista = new List<CedForecastEntidades.RFoPA>();
     if (dt.Rows.Count != 0)
     {
         CedForecastEntidades.RFoPA forecast = new CedForecastEntidades.RFoPA();
         string idClave = "";
         idClave = ObtenerClaveXTipoReporte(dt.Rows[0], TipoReporte);
         CopiarCab(dt.Rows[0], forecast, Forecast.IdPeriodo);
         //Lista de ventas para Rolling Forecast
         List<CedForecastEntidades.Bejerman.Ventas> ventas = new List<CedForecastEntidades.Bejerman.Ventas>();
         List<CedForecastEntidades.RFoPA> totalProyectadoLista = new List<CedForecastEntidades.RFoPA>();
         if (Forecast.IdTipoPlanilla == "RollingForecast")
         {
             CedForecastDB.Bejerman.Ventas db = new CedForecastDB.Bejerman.Ventas(sesion);
             ventas = db.LeerParaRF(Forecast.IdPeriodo, TipoReporte);
             CedForecastEntidades.Bejerman.Ventas venta = new CedForecastEntidades.Bejerman.Ventas();
             switch (TipoReporte)
             {
                 case "FamArtCli":
                     venta = ventas.Find((delegate(CedForecastEntidades.Bejerman.Ventas e) { return e.Cve_CodCli == dt.Rows[0]["IdCliente"].ToString() && e.Sdvart_CodGen == dt.Rows[0]["IdArticulo"].ToString(); }));
                     break;
                 case "FamArt":
                     venta = ventas.Find((delegate(CedForecastEntidades.Bejerman.Ventas e) { return e.Sdvart_CodGen == dt.Rows[0]["IdArticulo"].ToString(); }));
                     break;
             }
             if (venta != null)
             {
                 forecast.Ventas = venta.Sdv_CantUM1;
             }
             //Lista de totales proyectados por articulo
             totalProyectadoLista = TotalProyectado(Forecast);
             ////Buscar total proyectado
             CedForecastEntidades.RFoPA totalProyectado = new CedForecastEntidades.RFoPA();
             totalProyectado = totalProyectadoLista.Find((delegate(CedForecastEntidades.RFoPA e) { return e.IdCliente == dt.Rows[0]["IdCliente"].ToString() && e.Articulo.Art_CodGen == dt.Rows[0]["IdArticulo"].ToString(); }));
             if (totalProyectado != null)
             {
                 forecast.Proyectado = totalProyectado.Proyectado;
             }
         }
         for (int i = 0; i < dt.Rows.Count; i++)
         {
             string periodoInicial = Forecast.IdPeriodo;
             //if (Forecast.IdTipoPlanilla == "Proyectado")
             //{
             //    periodoInicial = periodoInicial + "01";
             //}
             int mes = 0;
             if (Forecast.IdTipoPlanilla == "Proyectado" && (dt.Rows[i]["IdPeriodo"].ToString().Substring(4, 2) == "13" || dt.Rows[i]["IdPeriodo"].ToString().Substring(4, 2) == "14"))
             {
                 mes = Convert.ToInt32(dt.Rows[i]["IdPeriodo"].ToString().Substring(4, 2));
             }
             else
             {
                 mes = MesAProcesar(dt.Rows[i]["IdPeriodo"].ToString(), periodoInicial);
             }
             //Clave para armado de info según agrupamiento
             string claveAux = ObtenerClaveXTipoReporte(dt.Rows[i], TipoReporte);
             if (idClave != claveAux)
             {
                 idClave = claveAux;
                 lista.Add(forecast);
                 forecast = new CedForecastEntidades.RFoPA();
                 CopiarCab(dt.Rows[i], forecast, Forecast.IdPeriodo);
                 if (Forecast.IdTipoPlanilla == "RollingForecast")
                 {
                     //Buscar ventas reales
                     //CedForecastDB.Bejerman.Ventas db = new CedForecastDB.Bejerman.Ventas(sesion);
                     //ventas = db.LeerParaRF(Forecast.IdPeriodo, TipoReporte);
                     CedForecastEntidades.Bejerman.Ventas venta = new CedForecastEntidades.Bejerman.Ventas();
                     switch (TipoReporte)
                     {
                         case "FamArtCli":
                             venta = ventas.Find((delegate(CedForecastEntidades.Bejerman.Ventas e) { return e.Cve_CodCli == dt.Rows[i]["IdCliente"].ToString() && e.Sdvart_CodGen == dt.Rows[i]["IdArticulo"].ToString(); }));
                             break;
                         case "FamArt":
                             venta = ventas.Find((delegate(CedForecastEntidades.Bejerman.Ventas e) { return e.Sdvart_CodGen == dt.Rows[i]["IdArticulo"].ToString(); }));
                             break;
                     }
                     if (venta != null)
                     {
                         forecast.Ventas = venta.Sdv_CantUM1;
                     }
                     //Buscar total proyectado
                     CedForecastEntidades.RFoPA totalProyectado = new CedForecastEntidades.RFoPA();
                     totalProyectado = totalProyectadoLista.Find((delegate(CedForecastEntidades.RFoPA e) { return e.IdCliente == dt.Rows[i]["IdCliente"].ToString() && e.Articulo.Art_CodGen == dt.Rows[i]["IdArticulo"].ToString(); }));
                     if (totalProyectado != null)
                     {
                         forecast.Proyectado = totalProyectado.Proyectado;
                     }
                 }
             }
             CopiarDet(dt.Rows[i], forecast, mes);
          }
          lista.Add(forecast);
     }
     cantidadFilas = lista.Count;
     return lista;
 }
Esempio n. 2
0
 public List<CedForecastEntidades.RFoPA> TotalProyectado(CedForecastEntidades.RFoPA Forecast)
 { 
     cantidadFilas = 0;
     System.Text.StringBuilder a = new StringBuilder();
     a.Append("select Forecast.IdTipoPlanilla, Forecast.IdCuenta, Forecast.IdCliente, Forecast.IdPeriodo, Forecast.IdArticulo, Forecast.Cantidad ");
     a.Append("from Forecast ");
     a.Append("where Forecast.IdTipoPlanilla='Proyectado' and Forecast.IdCuenta='" + Forecast.IdCuenta + "' ");
     if (Forecast.IdCliente != null && Forecast.IdCliente != "")
     {
         a.Append("and Forecast.IdCliente='" + Forecast.IdCliente + "' ");
     }
     try
     {
         string ProyectadoMesInicio = System.Configuration.ConfigurationManager.AppSettings["ProyectadoMesInicio"];
         DateTime FechaInicio = DateTime.Today;
         if (Convert.ToInt32(Forecast.IdPeriodo.Substring(4, 2)) < Convert.ToInt32(ProyectadoMesInicio))
         {
             FechaInicio = Convert.ToDateTime("01/" + ProyectadoMesInicio + "/" + Convert.ToDateTime("01/" + Forecast.IdPeriodo.Substring(4, 2) + "/" + Forecast.IdPeriodo.Substring(0, 4)).AddYears(-1).Year);
         }
         else
         {
             FechaInicio = Convert.ToDateTime("01/" + ProyectadoMesInicio + "/" + Forecast.IdPeriodo.Substring(0, 4));
         }
         string periodoDsd = FechaInicio.ToString("yyyyMM");
         string periodoHst = UltimoMesForecast(FechaInicio.ToString("yyyyMM"));
         if (periodoDsd.Substring(4, 2) == "01")
         {
             periodoHst = periodoHst.Substring(0, 4) + "99";
         }
         a.Append("and IdPeriodo >= '" + periodoDsd + "' ");
         a.Append("and IdPeriodo <= '" + periodoHst + "' ");
     }
     catch
     {
         a.Append("and IdPeriodo >= '" + Forecast.IdPeriodo.Substring(0, 4) + "01' ");
         a.Append("and IdPeriodo <= '" + Forecast.IdPeriodo.Substring(0, 4) + "99' ");
     }
     a.Append("order by IdArticulo asc, IdPeriodo asc");
     DataTable dt = new DataTable();
     dt = (DataTable)Ejecutar(a.ToString(), TipoRetorno.TB, Transaccion.NoAcepta, sesion.CnnStr);
     List<CedForecastEntidades.RFoPA> lista = new List<CedForecastEntidades.RFoPA>();
     if (dt.Rows.Count != 0)
     {
         CedForecastEntidades.RFoPA forecast = new CedForecastEntidades.RFoPA();
         string idArticulo = dt.Rows[0]["IdArticulo"].ToString();
         CopiarCab(dt.Rows[0], forecast, Forecast.IdPeriodo);
         for (int i = 0; i < dt.Rows.Count; i++)
         {
             if (!(dt.Rows[i]["IdPeriodo"].ToString().Substring(4, 2) == "13" || dt.Rows[i]["IdPeriodo"].ToString().Substring(4, 2) == "14"))
             {
                 if (idArticulo != dt.Rows[i]["IdArticulo"].ToString())
                 {
                     idArticulo = dt.Rows[i]["IdArticulo"].ToString();
                     lista.Add(forecast);
                     forecast = new CedForecastEntidades.RFoPA();
                     CopiarCab(dt.Rows[i], forecast, Forecast.IdPeriodo);
                 }
                 forecast.Proyectado += Convert.ToDecimal(dt.Rows[i]["Cantidad"]);
             }
         }
         lista.Add(forecast);
     }
     return lista;
 }
Esempio n. 3
0
 private void EjecutarSeleccionUiButton_Click(object sender, EventArgs e)
 {
     try
     {
         Cursor = Cursors.WaitCursor;
         List<CedForecastEntidades.Advertencia> advertencias;
         CedForecastEntidades.RFoPA forecast = new CedForecastEntidades.RFoPA();
         if (RFUiRadioButton.Checked)
         {
             forecast.IdTipoPlanilla = "RollingForecast";
             forecast.IdPeriodo = PeriodoRFCalendarCombo.Value.ToString("yyyyMM");
         }
         else
         {
             forecast.IdTipoPlanilla = "Proyectado";
             forecast.IdPeriodo = PeriodoPACalendarCombo.Value.ToString("yyyyMM");
         }
         List<CedForecastEntidades.RFoPA> l = CedForecastRN.RFoPA.Lista(forecast, TipoReporteNicePanel.Tag.ToString(), Cedeira.UI.Fun.ListaTreeView(ArticulosTreeView), Cedeira.UI.Fun.ListaTreeView(ClientesTreeView), Cedeira.UI.Fun.ListaTreeView(VendedoresTreeView), Aplicacion.Sesion, out advertencias);
         PersonalizarGrilla(l);
         BrowserGridEX.DataSource = l;
         BrowserUiTabPage.TabVisible = true; 
         MensajesUiTabPage.TabVisible = (advertencias.Count > 0);
         if (MensajesUiTabPage.TabVisible)
         {
             MensajesGridEX.DataSource = advertencias;
             CedForecastEntidades.Advertencia error = advertencias.Find(delegate(CedForecastEntidades.Advertencia a) { return a.Tipo == CedForecastEntidades.Advertencia.TipoSeveridad.Error.ToString(); });
             if (error != null)
             {
                 BrowserUiTab.SelectedTab = MensajesUiTabPage;
             }
             else
             {
                 BrowserUiTab.SelectedTab = BrowserUiTabPage;
             }
         }
         else
         {
             MensajesGridEX.DataSource = null;
             BrowserUiTab.SelectedTab = BrowserUiTabPage;
         }
         volverATabBrowser = true;
     }
     catch (Exception ex)
     {
         Microsoft.ApplicationBlocks.ExceptionManagement.ExceptionManager.Publish(ex);
     }
     finally
     {
         Cursor = Cursors.Default;
     }
 }