Ejemplo n.º 1
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                Category sel = CategoryGrid.SelectedItem as Category;


                if (Manufacturer.Text != "Manufacturer" && Manufacturer.Text != null &&
                    Model.Text != "Model" && Model.Text != null &&
                    Count.Text != "Count" && Count.Text != null &&
                    Price.Text != "Price" && Price.Text != null)
                {
                    WH part = new WH();

                    part.Manufacturer = Manufacturer.Text;
                    part.Model        = Model.Text;
                    part.Count        = int.Parse(Count.Text);
                    part.Price        = int.Parse(Price.Text);
                    part.Categories.Add(adoDB.Categories.Where(c => c.NameCategory == sel.NameCategory).First());

                    adoDB.WHs.Add(part);
                    adoDB.SaveChanges();
                    this.Close();
                }
                else
                {
                    MessageBox.Show("Please enter correct value");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error: " + ex.Message);
            }
        }
Ejemplo n.º 2
0
        private void EditBuilder(int idPart, string nameCategory, string manufdcturer, string model, int count, int price)
        {
            WH part = adoDB.WHs.Where(p => p.ID_Pard == idPart).First();


            part.Manufacturer = manufdcturer;
            part.Model        = model;
            part.Count        = count;
            part.Price        = price;
            part.Categories.Add(adoDB.Categories.Where(c => c.NameCategory == nameCategory).First());
            adoDB.Entry(part).State = EntityState.Modified;
            Dispatcher.Invoke(() => adoDB.SaveChanges());
        }
Ejemplo n.º 3
0
        protected void Delete()
        {
            try
            {
                selectItem = MainGrid.SelectedItem as AllResullt;

                if (selectItem != null && selectItem.CategoryName != null)
                {
                    WH       delPart = adoDB.WHs.Where(o => o.Model == selectItem.Model).First();
                    Category delcat  = adoDB.Categories.Where(c => c.NameCategory == selectItem.CategoryName).First();
                    delcat.WHs.Remove(delPart);
                    adoDB.Entry(delcat).State = EntityState.Modified;
                    adoDB.WHs.Remove(delPart);
                    adoDB.SaveChanges();
                    Connect();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error: " + ex.Message);
            }
        }