private void buttonOk_Click(object sender, EventArgs e) { if (str == "collective") { using (MyDbContext context = new MyDbContext()) { Collective collec = new Collective() { Name = textBoxName.Text }; context.Collectives.Add(collec); context.SaveChanges(); } } else { if (str == "genre") { using (MyDbContext context = new MyDbContext()) { Genre collec = new Genre() { Title = textBoxName.Text }; context.Genres.Add(collec); context.SaveChanges(); } } } }
private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e) { Collective s = new Collective(); s = dataGridView1.CurrentRow.DataBoundItem as Collective; using (MyDbContext context = new MyDbContext()) { var res = context.Collectives.Where(x => x.IdCollective == s.IdCollective).FirstOrDefault(); res.Name = s.Name; context.SaveChanges(); } }
private void buttonMostPopularCollectiveMonth_Click(object sender, EventArgs e) { using (MyDbContext context = new MyDbContext()) { try { var PopularCollecMonth = context.Sellings.AsEnumerable() .Where(r => r.DateSell.Month == DateTime.Now.Month) .GroupBy(r => r.IdDisk) .OrderByDescending(g => g.Sum(r => r.Quantity)) .Select(g => g.First().IdDisk).ToList(); List <Collective> collect = new List <Collective>(); foreach (var item in PopularCollecMonth) { foreach (var item2 in context.Disks.ToList()) { if (item2.IdDisk == item) { Collective coll = context.Collectives.Where(x => x.IdCollective == item2.IdCollective).FirstOrDefault(); collect.Add(coll); } } } var res = collect.GroupBy(x => x.IdCollective); int c = res.Count(); List <Collective> coll2 = new List <Collective>(); foreach (var key in res) { foreach (var item in key) { coll2.Add(item); break; } } ResultsDiscs f9 = new ResultsDiscs(coll2); f9.ShowDialog(); } catch (Exception ex) { } } }
private void buttonOk_Click(object sender, EventArgs e) { if (this.Text == "Add Disk") { try { Disk disk1; using (MyDbContext context = new MyDbContext()) { Collective coll1 = comboBoxCollective.SelectedItem as Collective; Publisher p1 = comboBoxPublisher.SelectedItem as Publisher; bool IsWriteOff; if (checkBoxIsWriteOff.Checked) { IsWriteOff = true; } else { IsWriteOff = false; } Disk newdisk = new Disk() { Title = textBoxTitle.Text, IdCollective = coll1.IdCollective, IdPublisher = p1.IdPublisher, CountSongs = Convert.ToInt32(textBoxCountSongs.Text), DtPublish = dateTimePickerDatePublish.Value, Quantity = Convert.ToInt32(textBoxQuantity.Text), Cost = Convert.ToInt32(textBoxCost.Text), SellingPrice = Convert.ToInt32(textBoxSellingPrice.Text), IsWriteOff = IsWriteOff }; context.Disks.Add(newdisk); context.SaveChanges(); disk1 = newdisk; } if (disk1 != null) { AddGenreToDisk f4 = new AddGenreToDisk(disk1); f4.ShowDialog(); } } catch (Exception ex) { MessageBox.Show("Data not correct"); } } else if (this.Text == "Update Disk") { try { using (MyDbContext context = new MyDbContext()) { var c1 = context.Disks.Where(x => x.IdDisk == d1.IdDisk).FirstOrDefault(); c1.Title = textBoxTitle.Text; c1.IdCollective = (comboBoxCollective.SelectedItem as Collective).IdCollective; c1.IdPublisher = (comboBoxPublisher.SelectedItem as Publisher).IdPublisher; c1.CountSongs = Convert.ToInt32(textBoxCountSongs.Text); c1.DtPublish = dateTimePickerDatePublish.Value; c1.Quantity = Convert.ToInt32(textBoxQuantity.Text); c1.Cost = Convert.ToInt32(textBoxCost.Text); c1.SellingPrice = Convert.ToInt32(textBoxSellingPrice.Text); if (checkBoxIsWriteOff.Checked) { c1.IsWriteOff = true; } else { c1.IsWriteOff = false; } context.SaveChanges(); } } catch (Exception ex) { MessageBox.Show("Data not correct"); } } }
protected override void Seed(MyDbContext context) { User user1 = new User() { Login = "******", Password = "******", IsClient = false }; context.Users.Add(user1); context.SaveChanges(); Collective collective1 = new Collective() { Name = "Stars" }; Collective collective2 = new Collective() { Name = "Sky" }; Collective collective3 = new Collective() { Name = "Black" }; context.Collectives.Add(collective1); context.Collectives.Add(collective2); context.Collectives.Add(collective3); context.SaveChanges(); Publisher p1 = new Publisher() { Name = "Publis", Country = "Ukraine" }; Publisher p2 = new Publisher() { Name = "NewPublis", Country = "Ukraine" }; context.Publishers.Add(p1); context.Publishers.Add(p2); context.SaveChanges(); Genre g1 = new Genre() { Title = "Jazz" }; Genre g2 = new Genre() { Title = "Pop" }; Genre g3 = new Genre() { Title = "Disco" }; context.Genres.Add(g1); context.Genres.Add(g2); context.Genres.Add(g3); context.SaveChanges(); Disk d1 = new Disk() { Title = "Disk1", IdCollective = 1, IdPublisher = 1, CountSongs = 10, DtPublish = new System.DateTime(2020, 5, 5), Quantity = 55, Cost = 50, SellingPrice = 100, IsWriteOff = false }; context.Disks.Add(d1); context.SaveChanges(); }