Ejemplo n.º 1
0
 public ReportRevenue(ReportRevenue report)
 {
     id      = report.id;
     kind    = report.kind;
     revenue = report.revenue;
     ratio   = report.ratio;
 }
Ejemplo n.º 2
0
        private void RefreshRevenueTab(int indexMonth)    //làm mới dữ liệu bảng báo cáo doanh thu theo loại phòng
        {
            List <ReportRevenue> sources  = new List <ReportRevenue>();
            List <string>        category = fRoomCategories.kindAndPrice.Keys.ToList(); //lấy danh sách các loại phòng
            float total = 0;                                                            //tổng doanh thu

            for (int i = 0; i < category.Count; i++)                                    //traverse hết danh mục phần
            {
                string             kind           = category[i];                        //danh mục hiện tại
                string             monthComponent = month.ElementAt(indexMonth).Month;
                string             yearComponent  = month.ElementAt(indexMonth).Year;
                List <RoomHistory> histories      = (from p in entities.RoomHistories
                                                     where p.kind == kind && p.rentedDay.Value.Month.ToString() == monthComponent &&
                                                     p.rentedDay.Value.Year.ToString() == yearComponent
                                                     select p).ToList(); //truy vấn đúng danh mục hiện tại

                ReportRevenue currentRoom = new ReportRevenue();
                currentRoom.Id   = i + 1;               //tạo cột số thứ tự
                currentRoom.Kind = kind;
                foreach (RoomHistory room in histories) //tính tổng doanh thu của danh sách phòng hiện tại
                {
                    currentRoom.Revenue += (float)room.total;
                }
                total += currentRoom.Revenue;

                sources.Add(currentRoom);
            }
            foreach (ReportRevenue item in sources)     //tính tỷ lệ bằng cách chia doanh thu theo loại phòng cho tổng doanh thu
            {
                item.Ratio = (float)Math.Round(item.Revenue / total * 100, 2);
            }

            //đổ dữ liệu vào DataGridView, đặt tên cho tiêu đề của các cột
            dgvRevenue.DataSource            = sources;
            dgvRevenue.Columns[0].HeaderText = "Số thứ tự";
            dgvRevenue.Columns[1].HeaderText = "Loại phòng";
            dgvRevenue.Columns[2].HeaderText = "Doanh thu";
            dgvRevenue.Columns[3].HeaderText = "Tỷ lệ";

            CreateRevenueChart();   //vẽ biểu đồ doanh thu theo loại phòng
        }