Exemple #1
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            if (Seriestxt == null)
            {
                MessageBox.Show("Không được để trống");
                return;
            }
            else
            {
                Category x = new Category();
                x.Name = Seriestxt.Text;;

                x.Products = _category.Products;

                var    db = new HREntities();
                string a  = _category.Name;

                var kq = from s in db.Hurom where s.Series == a select s;
                foreach (var data in kq)
                {
                    db.Hurom.Remove(data);
                }

                for (int i = 0; i < x.Products.Count(); i++)
                {
                    var h = new Hurom()
                    {
                        Series = x.Name,
                        Name   = x.Products[i].Name,
                        Price  = x.Products[i].Price,
                        Avatar = x.Products[i].ImagePath
                    };
                    db.Hurom.Add(h);
                }



                db.SaveChanges();


                MainWindow xx = new MainWindow();
                this.Close();
                xx.ShowDialog();
            }

            this.DialogResult = true;
        }
Exemple #2
0
        private void SaveButton_Click(object sender, RoutedEventArgs e)
        {
            using (var db = new HREntities())
            {
                if (nameTextBox.Text == "" || priceTextBox.Text == "")
                {
                    MessageBox.Show("phải nhập đầy đủ thông tin");
                    return;
                }
                else
                {
                    Product _product = new Product();
                    _product.Name  = nameTextBox.Text;
                    _product.Price = int.Parse(priceTextBox.Text);

                    if (_category.Products == null)
                    {
                        BindingList <Product> Products = new BindingList <Product>()
                        {
                            new Product()
                            {
                                Name  = _product.Name,
                                Price = _product.Price,
                            },
                        };
                        _category.Products = Products;
                    }
                    else
                    {
                        _category.Products.Add(_product);
                    }



                    var h = new Hurom()
                    {
                        Series = _category.Name,
                        Name   = _product.Name,
                        Price  = _product.Price,
                    };
                    db.Hurom.Add(h);
                    db.SaveChanges();
                    this.DialogResult = true;
                }
            }
        }
Exemple #3
0
 private void Button_Click(object sender, RoutedEventArgs e)
 {
     if (Series.Text == "")
     {
         MessageBox.Show("Vui lòng nhập tên category cần thêm");
         return;
     }
     else
     {
         var db = new HREntities();
         var h  = new Hurom()
         {
             Series = Series.Text,
         };
         db.Hurom.Add(h);
         db.SaveChanges();
         MainWindow l = new MainWindow();
         this.Close();
         l.ShowDialog();
     }
 }