Exemple #1
0
        public static List <TrendingMonDTO> LayDanhSachTop10MonDaBan()
        {
            SqlConnection connection = DataProvider.GetConnection();
            string        query      = "SELECT TOP 10 ten_mon, SUM(so_luong) tong_so_luong FROM CTHoaDon INNER JOIN Mon ON mon=ma_mon INNER JOIN HoaDon ON HoaDon.ma_hoa_don=CTHoaDon.hoa_don WHERE HoaDon.trang_thai=1 GROUP BY ten_mon ORDER BY tong_so_luong DESC";
            SqlCommand    command    = new SqlCommand(query, connection);

            connection.Open();
            SqlDataReader reader = command.ExecuteReader();

            List <TrendingMonDTO> result = new List <TrendingMonDTO>();

            if (reader.HasRows)
            {
                while (reader.Read())
                {
                    TrendingMonDTO trendingMon = new TrendingMonDTO();
                    trendingMon.TenMon  = reader.GetString(0);
                    trendingMon.SoLuong = reader.GetInt32(1);
                    result.Add(trendingMon);
                }
            }

            connection.Close();
            return(result);
        }
        private void radTop10_CheckedChanged(object sender, EventArgs e)
        {
            if (radTrendingTop10.Checked)
            {
                chartTrending.Series.Clear();

                Func <ChartPoint, string> labelPoint = chartPoint => string.Format("{0:#,##0} ({1:P})", chartPoint.Y, chartPoint.Participation);
                chartTrending.Series = new SeriesCollection {
                };

                List <TrendingMonDTO> lsTrendingMon = TrendingMonBUS.LayDanhSachTop10MonDaBan();

                if (lsTrendingMon.Count > 0)
                {
                    int index;
                    if (lsTrendingMon.Count < 10)
                    {
                        index = lsTrendingMon.Count;
                    }
                    else
                    {
                        index = 10;
                    }

                    for (int i = 0; i < index; i++)
                    {
                        TrendingMonDTO trendingMon = lsTrendingMon[i];
                        PieSeries      pieSeries   = new PieSeries();
                        pieSeries.Title  = trendingMon.TenMon;
                        pieSeries.Values = new ChartValues <int> {
                            trendingMon.SoLuong
                        };
                        pieSeries.DataLabels = true;
                        pieSeries.LabelPoint = labelPoint;
                        pieSeries.PushOut    = 5;
                        chartTrending.Series.Add(pieSeries);
                    }
                }

                if (chartTrending.Series.Count == 0)
                {
                    MetroLabel lblThongBao = new MetroLabel();
                    lblThongBao.Text      = "Không có dữ liệu thống kê";
                    lblThongBao.FontSize  = MetroFramework.MetroLabelSize.Tall;
                    lblThongBao.TextAlign = ContentAlignment.MiddleCenter;
                    lblThongBao.Dock      = DockStyle.Fill;
                    panelLoiNhuan.Controls.Add(lblThongBao);
                    lblThongBao.BringToFront();
                    lblT_MonBanChayNhat.Text = "Món bán chạy nhất: không có";
                }
                else
                {
                    lblT_MonBanChayNhat.Text = "Món bán chạy nhất: " + chartTrending.Series[0].Title;
                }
            }
        }