private void button2_Click(object sender, EventArgs e) { if (listView1.SelectedItems.Count > 0) { using (ProductListEntities db = new ProductListEntities()) { int id = (int)listView1.SelectedItems[0].Tag; var result = from a in db.Attributes where a.IdAttribute == id select a; foreach (var item in result) { db.Attributes.Remove(item); } db.SaveChanges(); listView1.Items.Clear(); int index = 0; var list = db.Attributes.ToList(); foreach (var element in list) { listView1.Items.Add(new ListViewItem(element.Name)); listView1.Items[index++].Tag = element.IdAttribute; } } } }
private void button1_Click(object sender, EventArgs e) { Form5 form5 = new Form5(ref listView1); form5.ShowDialog(); using (ProductListEntities db = new ProductListEntities()) { foreach (var item in listView1.Items) { Set set = new Set(); set.IdProduct = Convert.ToInt32(str[3]); set.IdAttribute = (int)((ListViewItem)item).Tag; set.Value = ""; db.Set.Add(set); } db.SaveChanges(); } }
private void button3_Click(object sender, EventArgs e) { if (listView1.SelectedItems.Count > 0) { listView1.SelectedItems[0].SubItems[1].Text = textBox4.Text; using (ProductListEntities db = new ProductListEntities()) { int idProd = Convert.ToInt32(str[3]); int idAttrib = (int)listView1.SelectedItems[0].Tag; var result = from s in db.Set join a in db.Attributes on s.IdAttribute equals a.IdAttribute join p in db.Product on s.IdProduct equals p.IdProduct where s.IdProduct == idProd && s.IdAttribute == idAttrib select s; foreach (var item in result) { item.Value = textBox4.Text; } db.SaveChanges(); } } }
private void ListView1_MouseDoubleClick(object sender, MouseEventArgs e) { DialogResult result; string[] str = new string[4]; using (ProductListEntities db = new ProductListEntities()) { var product = db.Product.Find(listView1.SelectedItems[0].Tag); str[0] = product.Name; str[1] = product.Price.ToString(); str[2] = product.Manufacturer.Name.ToString(); str[3] = ((int)listView1.SelectedItems[0].Tag).ToString(); } Form2 form2 = new Form2(str); result = form2.ShowDialog(); if (result == DialogResult.OK) { using (ProductListEntities db = new ProductListEntities()) { var product = db.Product.Find(listView1.SelectedItems[0].Tag); product.Name = str[0]; product.Price = Convert.ToInt32(str[1]); product.Manufacturer.Name = str[2]; db.SaveChanges(); listView1.Items.Clear(); int index = 0; var list = db.Product.ToList(); foreach (var element in list) { listView1.Items.Add(new ListViewItem(element.Name)); listView1.Items[index].Tag = element.IdProduct; listView1.Items[index++].SubItems.Add(element.Price.ToString()); } } } }
private void button1_Click(object sender, EventArgs e) { if (textBox1.Text != null && textBox1.Text != "") { using (ProductListEntities db = new ProductListEntities()) { var result = from c in db.Attributes where c.Name == textBox1.Text select c; if (result.Count() > 0) { MessageBox.Show($"Атрибут с названием {textBox1.Text} существует", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { listView1.Items.Add(new ListViewItem(textBox1.Text)); Attributes attribute = new Attributes(); attribute.Name = textBox1.Text; db.Attributes.Add(attribute); db.SaveChanges(); } } } }
private void ListView1_MouseDoubleClick(object sender, MouseEventArgs e) { string str = listView1.SelectedItems[0].Text; DialogResult result; Form4 form4 = new Form4(ref str); result = form4.ShowDialog(); if (result == DialogResult.OK) { listView1.SelectedItems[0].Text = str; int id = (int)listView1.SelectedItems[0].Tag; using (ProductListEntities db = new ProductListEntities()) { var result2 = from a in db.Attributes where a.IdAttribute == id select a; foreach (var item in result2) { item.Name = str; } db.SaveChanges(); } } }