Beispiel #1
0
 public SearchForm(Books b, Authors a, Themes t)
 {
     InitializeComponent();
     this.b = b;
     this.a = a;
     this.t = t;
     bd     = new Book_ShopEntities();
     cmbBoxName.DataSource   = null;
     cmbBoxAuthor.DataSource = null;
     cmbBoxTheme.DataSource  = null;
     //cmbBoxName.DataSource = bd.Books.ToList();
     //cmbBoxName.DisplayMember = "NameBook";
     //cmbBoxName.ValueMember = "Id_Book";
     //cmbBoxAuthor.DataSource = bd.Books.ToList();
     //cmbBoxAuthor.DisplayMember = "LastName";
     //cmbBoxAuthor.ValueMember = "Id_Author";
     //cmbBoxTheme.DataSource = bd.Books.ToList();
     //cmbBoxTheme.DisplayMember = "NameGenre";
     //cmbBoxTheme.ValueMember = "Id_Theme";
 }
        private void buttonMostPopular_Click(object sender, EventArgs e)
        {
            b = new Books();
            a = new Authors();
            s = new Sales();
            t = new Themes();
            var query = bd.Sales.GroupBy(x => x.Id_Book).Select(s => new
            {
                id    = s.Key,
                count = s.Count()
            }).OrderByDescending(s => s.count).ToList();
            var item = (from b in bd.Books
                        join s in bd.Sales on b.Id_Book equals s.Id_Book
                        group s by new { b.NameBook, s.Id_Book } into gr
                        select new
            {
                gr.Key.NameBook,
                maxSales = gr.Sum(g => g.Quantity)
            }).OrderByDescending(x => x.maxSales).Take(5).ToList();

            dataGridViewAllBooks.DataSource = null;
            dataGridViewAllBooks.DataSource = item;
        }