예제 #1
0
        private async void LoadData()
        {
            wb = new WaitBox();
            wb.Show();
            wb.Owner = Window.GetWindow(this);
            wb.Show();
            await Task.Run(() =>
            {
                ChartDTO = dashboardComercialBLL.LoadCharts();
            });

            chart.Series      = ChartDTO.SeriesCollection;
            chartlabel.Labels = ChartDTO.Labels;
            txtMedia.Text     = ChartDTO.Media.ToString("N2").Replace(",", ".");
            await Task.Run(() =>
            {
                Dispatcher.Invoke(new Action(() =>
                {
                    listaComercial = dashboardComercialBLL.Load();
                }));
            });

            grdComercial.DataContext = listaComercial;
            listaNegocios            = listaComercial.First().ListaNegocios;
            Formatter   = value => value.ToString("P");
            DataContext = this;
            Find        = "1";
            Commit();
            wb.Close();
        }
예제 #2
0
        public DashboardChartDTO LoadCharts()
        {
            var    chart         = new DashboardChartDTO();
            var    dt            = new DataTable();
            var    abertos       = new ChartValues <int>();
            var    feitos        = new ChartValues <int>();
            var    produtividade = new ChartValues <double>();
            var    labels        = new List <string>();
            double soma_feitos   = 0;

            try
            {
                var query = "SELECT t1.month as month, COUNT(t2.id) as abertos, COUNT(t3.id) as feitos FROM (SELECT 1 AS mnum, 'Jan' AS month UNION ALL SELECT 2, 'Feb'  UNION ALL SELECT 3, 'Mar'  UNION ALL SELECT 4, 'Apr'  UNION ALL SELECT 5, 'May'  UNION ALL SELECT 6, 'Jun'  UNION ALL SELECT 7, 'Jul'  UNION ALL SELECT 8, 'Aug'  UNION ALL SELECT 9, 'Sep'  UNION ALL SELECT 10, 'Oct'  UNION ALL SELECT 11, 'Nov'  UNION ALL SELECT 12, 'Dec') t1 CROSS JOIN (SELECT DISTINCT YEAR(data) AS year FROM negocio) y LEFT JOIN negocio t2 ON t1.mnum = MONTH(t2.data) AND y.year = YEAR(t2.data) AND t2.data BETWEEN CURDATE() - INTERVAL 3 MONTH AND CURDATE() LEFT JOIN negocio t3 ON t2.id = t3.id AND t3.data_envio is not null WHERE STR_TO_DATE(CONCAT_WS('-', y.year, t1.month, DAY(CURDATE())), '%Y-%b-%d') BETWEEN CURDATE() -INTERVAL 3 MONTH AND CURDATE() GROUP BY y.year, t1.month, t1.mnum ORDER BY y.year, t1.mnum";
                bd.Conectar();
                dt = bd.RetDataTable(query);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            finally
            {
                foreach (DataRow dr in dt.Rows)
                {
                    abertos.Add(Convert.ToInt32(dr["abertos"]));
                    feitos.Add(Convert.ToInt32(dr["feitos"]));
                    if (Convert.ToInt32(dr["abertos"]) == 0)
                    {
                        produtividade.Add(0);
                    }
                    else
                    {
                        produtividade.Add(Math.Round(Convert.ToDouble(dr["feitos"]) / Convert.ToDouble(dr["abertos"]), 2));
                    }
                    soma_feitos = soma_feitos + Convert.ToDouble(dr["feitos"]);
                    labels.Add(ParseMonth(dr["month"].ToString()));
                }

                Application.Current.Dispatcher.Invoke(new Action(() =>
                {
                    chart.SeriesCollection = new SeriesCollection
                    {
                        new LineSeries
                        {
                            Title         = "Executados",
                            Values        = feitos,
                            Fill          = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#907A2932")),
                            Stroke        = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#7A2932")),
                            PointGeometry = null
                        },
                        new LineSeries
                        {
                            Title         = "Solicitados",
                            Values        = abertos,
                            Fill          = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#77000000")),
                            Stroke        = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#000000")),
                            PointGeometry = null
                        },
                        new LineSeries
                        {
                            Title     = "Produtividade",
                            Values    = produtividade,
                            Fill      = new SolidColorBrush(Colors.Transparent),
                            ScalesYAt = 1,
                            Stroke    = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#404040")),
                        }
                    };
                }));


                chart.Labels = labels;
                chart.Media  = soma_feitos / 4;
            }
            return(chart);
        }