private void Button_DeleteSinger_Click(object sender, EventArgs e) { int index = listView1_Disc.FocusedItem.Index; Disc disc = list[index]; using (MusicStoreEntities1 db = new MusicStoreEntities1()) { var find = db.Disc.FirstOrDefault(z => z.Id == disc.Id); db.Disc.Remove(find); db.SaveChanges(); } Show_Table(); }
private void Edit_database() { using (MusicStoreEntities1 db = new MusicStoreEntities1()) { var disc = db.Disc.FirstOrDefault(z => z.Id == disc_disc.Id); disc.Singer = textBox_SingerEdit.Text; disc.Tracks = col; disc.CostPrice = seb_pr; disc.DiskTitle = textBox_AlbumEdit.Text; disc.Genre = textBox_GenreEdit.Text; disc.Publisher = textBox_PublisherEdit.Text; disc.Cover = textBox1_imgEdit.Text; disc.SellPrice = pr; disc.YearPublishing = date; db.Disc.AddOrUpdate(disc); db.SaveChanges(); } DialogResult = DialogResult.OK; }
private void Button_LoginEnter_Click(object sender, EventArgs e) { if (textBox_Login.Text == "" || textBox_Password.Text == "") { MessageBox.Show("Fill all fields", "Attention", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } using (MusicStoreEntities1 db = new MusicStoreEntities1()) { var log = db.LoginPassword.FirstOrDefault(z => z.Id == 1); log.Login = textBox_Login.Text; log.Password = textBox_Password.Text; db.LoginPassword.AddOrUpdate(log); db.SaveChanges(); } MessageBox.Show("Admin data has changed!", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information); DialogResult = DialogResult.OK; }
private void Add_database() { using (MusicStoreEntities1 db = new MusicStoreEntities1()) { Disc disc = new Disc { Singer = textBox_SingerAdd.Text, Tracks = col, CostPrice = seb_pr, DiskTitle = textBox_AlbumAdd.Text, Genre = textBox_GenreAdd.Text, Publisher = textBox_PublisherAdd.Text, Cover = textBox1_img.Text, SellPrice = pr, YearPublishing = date }; db.Disc.Add(disc); db.SaveChanges(); } DialogResult = DialogResult.OK; }
private void Checkout(List <Disc> discs, string lastName, string firstName) { using (MusicStoreEntities1 db = new MusicStoreEntities1()) { var user = db.Buyer.Where(z => z.LastName == lastName && z.FirstName == firstName).ToList(); if (user.Count != 0) { foreach (Buyer VARIABLE in user) { int col = VARIABLE.Quantity; col += discs.Count; VARIABLE.Quantity = col; db.Buyer.AddOrUpdate(VARIABLE); db.SaveChanges(); } } else { Buyer buyer = new Buyer { Quantity = discs.Count, LastName = lastName, FirstName = firstName }; db.Buyer.Add(buyer); db.SaveChanges(); } } using (MusicStoreEntities1 db = new MusicStoreEntities1()) { var user = db.Buyer.Where(z => z.LastName == lastName && z.FirstName == firstName).ToList(); foreach (var VARIABLE in user) { var sumPrise = db.Checkk.Where(z => z.IdBuyer == VARIABLE.Id).Select(z => z.Summ).ToList(); decimal sum = 0; foreach (decimal VAR in sumPrise) { sum += VAR; } if (sum > 1000) { decimal s = 0; decimal nous = 0; panel_OrderDiscount.Visible = true; foreach (var V in discs) { decimal pr = 0; s += V.SellPrice; pr = (V.SellPrice - 15); nous = nous + (V.SellPrice - 15); Checkk checkk = new Checkk { DataSale = DateTime.Now.Date, IdDisc = V.Id, IdBuyer = VARIABLE.Id, Summ = pr }; db.Checkk.Add(checkk); } db.SaveChanges(); label_TotalDiscount.Text = s.ToString(); label_ToPayDiscount.Text = nous.ToString(); } else { decimal s = 0; panel_OrderDefault.Visible = true; foreach (var V in discs) { s += V.SellPrice; Checkk checkk = new Checkk { DataSale = DateTime.Now.Date, IdDisc = V.Id, IdBuyer = VARIABLE.Id, Summ = V.SellPrice }; db.Checkk.Add(checkk); } db.SaveChanges(); label_TotalDefault.Text = s.ToString(); } } } }