Example #1
0
 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;
             }
         }
     }
 }
Example #2
0
 public Form5(ref ListView listView)
 {
     InitializeComponent();
     this.listView = listView;
     using (ProductListEntities db = new ProductListEntities())
     {
         int index = 0;
         var list  = db.Attributes.ToList();
         foreach (var element in list)
         {
             listView1.Items.Add(new ListViewItem(element.Name));
             listView1.Items[index].SubItems.Add("");
             listView1.Items[index++].Tag = element.IdAttribute;
         }
     }
 }
Example #3
0
 public Form3()
 {
     InitializeComponent();
     button1.Enabled             = false;
     listView1.MouseDoubleClick += ListView1_MouseDoubleClick;
     using (ProductListEntities db = new ProductListEntities())
     {
         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;
         }
     }
 }
Example #4
0
 public Form1()
 {
     InitializeComponent();
     listView1.FullRowSelect = true;
     using (ProductListEntities db = new ProductListEntities())
     {
         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());
         }
     }
     listView1.MouseDoubleClick += ListView1_MouseDoubleClick;
 }
Example #5
0
        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();
            }
        }
Example #6
0
        private void loadAttribute()
        {
            listView1.Items.Clear();
            int id = Convert.ToInt32(str[3]);

            using (ProductListEntities db = new ProductListEntities())
            {
                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 p.IdProduct == id
                             select new { Name = a.Name, Value = s.Value, IdAttr = a.IdAttribute };
                int index = 0;
                foreach (var item in result)
                {
                    listView1.Items.Add(item.Name);
                    listView1.Items[index].Tag = item.IdAttr;
                    listView1.Items[index++].SubItems.Add(item.Value);
                }
            }
        }
Example #7
0
 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();
         }
     }
 }
Example #8
0
        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());
                    }
                }
            }
        }
Example #9
0
 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();
             }
         }
     }
 }
Example #10
0
        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();
                }
            }
        }