Example #1
0
        private void OK_Click(object sender, RoutedEventArgs e)
        {
            using (var context = new PCContext())
            {
                var partType = cb_Type.SelectedIndex;
                switch (partType)
                {
                case 0:
                    var c = (from i in context.CPUs where i.Name == cb_CPU.Text select i).FirstOrDefault();
                    context.CPUs.Remove(c);
                    MessageBox.Show("CPU has been removed.");
                    break;

                case 1:
                    var g = (from i in context.GPUs where i.Name == cb_GPU.Text select i).FirstOrDefault();
                    context.GPUs.Remove(g);
                    MessageBox.Show("GPU has been removed.");
                    break;

                case 2:
                    var m = (from i in context.MBs where i.Name == cb_MB.Text select i).FirstOrDefault();
                    context.MBs.Remove(m);
                    MessageBox.Show("MB has been removed.");
                    break;

                case 3:
                    var r = (from i in context.RAMs where i.Name == cb_RAM.Text select i).FirstOrDefault();
                    context.RAMs.Remove(r);
                    MessageBox.Show("RAM has been removed.");
                    break;

                case 4:
                    var s = (from i in context.Storages where i.Name == cb_Storage.Text select i).FirstOrDefault();
                    context.Storages.Remove(s);
                    MessageBox.Show("Storage has been removed.");
                    break;
                }

                context.SaveChanges();
            }
            this.Close();
        }
        private void OK_Click(object sender, RoutedEventArgs e)
        {
            using (var context = new PCContext())
            {
                var partType = cb_Type.SelectedIndex;
                switch (partType)
                {
                case 0:
                    context.CPUs.Add
                    (
                        new CPU()
                    {
                        Brand = tb_Brand.Text,
                        Name  = tb_Name.Text,
                        Cost  = Int32.Parse(tb_Cost.Text)
                    }
                    );
                    MessageBox.Show("CPU has been added.");
                    break;

                case 1:
                    context.GPUs.Add
                    (
                        new GPU()
                    {
                        Brand = tb_Brand.Text,
                        Name  = tb_Name.Text,
                        Cost  = Int32.Parse(tb_Cost.Text)
                    }
                    );
                    MessageBox.Show("GPU has been added.");
                    break;

                case 2:
                    context.MBs.Add
                    (
                        new MB()
                    {
                        Brand = tb_Brand.Text,
                        Name  = tb_Name.Text,
                        Cost  = Int32.Parse(tb_Cost.Text)
                    }
                    );
                    MessageBox.Show("Motherboard has been added.");
                    break;

                case 3:
                    context.RAMs.Add
                    (
                        new RAM()
                    {
                        Brand = tb_Brand.Text,
                        Name  = tb_Name.Text,
                        Cost  = Int32.Parse(tb_Cost.Text)
                    }
                    );
                    MessageBox.Show("Memory has been added.");
                    break;

                case 4:
                    context.Storages.Add
                    (
                        new Storage()
                    {
                        Brand = tb_Brand.Text,
                        Name  = tb_Name.Text,
                        Cost  = Int32.Parse(tb_Cost.Text)
                    }
                    );
                    MessageBox.Show("Storage has been added.");
                    break;
                }

                context.SaveChanges();
            }
            this.Close();
        }