コード例 #1
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            int i = 1;

            if ((string)categoeryCB.SelectedItem != "" && (string)categoeryCB.SelectedItem != null)
            {
                var categoery = _db.Catergoeries.ToList();
                i = categoery.First(c => c.Name == (string)categoeryCB.SelectedItem).Id;
            }
            Part updatePart = (from p in _db.Parts where p.Id == Id select p).Single();

            if (partNumTB.Text == currentPartNum || !partsObject.CheckIfPartNumberCreated(partNumTB.Text))
            {
                updatePart.Link        = linkTB.Text;
                updatePart.PartNumber  = partNumTB.Text;
                updatePart.Description = DescTB.Text;
                updatePart.Supplier    = supplierTB.Text;
                updatePart.Price       = priceTB.Text;

                updatePart.CatergoeryId = i;

                _db.SaveChanges();
                MainWindow.frame.Content = new PartsHomePage();
            }
            else
            {
                MessageBox.Show($"{updatePart.PartNumber} is already used. Please update part with this part number\nor check part number is correct.");
            }
        }
コード例 #2
0
        private void addBtn_Click(object sender, RoutedEventArgs e)
        {
            PartsViewModel parts = new PartsViewModel();
            int            i     = 9;

            try
            {
                if ((string)catergoeryComboBox.SelectedItem != "")
                {
                    var categoery = _db.Catergoeries.ToList();
                    i = categoery.First(c => c.Name == (string)catergoeryComboBox.SelectedItem).Id;
                }
            }
            catch (Exception ex)
            {
                //throw;
            }
            if (descTextBox.Text == "")
            {
                MessageBox.Show("Please enter a description to this part before adding");
            }
            else if (partNumTextBox.Text == "")
            {
                MessageBox.Show("Please enter a part number to this part before adding");
            }
            else
            {
                bool exists = parts.CheckIfPartNumberCreated(partNumTextBox.Text);
                if (!exists)
                {
                    Part newPart = new Part()
                    {
                        Description  = descTextBox.Text,
                        PartNumber   = partNumTextBox.Text,
                        Link         = linkTextBox.Text,
                        Supplier     = supplierTextBox.Text,
                        Price        = priceTextBox.Text,
                        CatergoeryId = i
                    };

                    _db.Parts.Add(newPart);
                    _db.SaveChanges();
                    MainWindow.frame.Content = new PartsHomePage();
                    MessageBox.Show($"Part Number {newPart.PartNumber} was added to the database");
                }

                else
                {
                    MessageBox.Show("There is already a part created with this part number.\nCheck parts list to update this part\nor change part number");
                }
                //Load();
            }
        }