private void EditName()
 {
     using (var context = new DesktopBuildsContext())
     {
         if (Desktop.Name != NameTxtBox)
         {
             Desktop.Name = NameTxtBox;
         }
         if (Desktop.CPU.Id != CPUs[SelectedCPU].Id)
         {
             Desktop.CPU = CPUs[SelectedCPU];
         }
         if (Desktop.Ram.Id != Rams[SelectedRam].Id)
         {
             Desktop.Ram = Rams[SelectedRam];
         }
         if (Desktop.Motherboard.Id != Motherboards[SelectedMotherboard].Id)
         {
             Desktop.Motherboard = Motherboards[SelectedMotherboard];
         }
         if (Desktop.GraphicCard.Id != GraphicsCards[SelectedGraphicsCard].Id)
         {
             Desktop.GraphicCard = GraphicsCards[SelectedGraphicsCard];
         }
         context.Desktops.Update(Desktop);
         context.SaveChanges();
     }
 }
Exemple #2
0
 private void FillLists()
 {
     CPUs         = new ObservableCollection <CPU>();
     Motherboards = new ObservableCollection <Motherboard>();
     Memories     = new ObservableCollection <Ram>();
     GraphicCards = new ObservableCollection <GraphicCard>();
     using (var context = new DesktopBuildsContext())
     {
         var c  = context.CPUs;
         var mo = context.Motherboards;
         var me = context.Rams;
         var g  = context.GraphicCards;
         foreach (CPU cpu in c)
         {
             CPUs.Add(cpu);
         }
         foreach (Motherboard m in mo)
         {
             Motherboards.Add(m);
         }
         foreach (Ram m in me)
         {
             Memories.Add(m);
         }
         foreach (GraphicCard graphicCard in g)
         {
             GraphicCards.Add(graphicCard);
         }
     }
 }
 private void FillLists()
 {
     using (var context = new DesktopBuildsContext())
     {
         CPUs = new ObservableCollection <CPU>();
         foreach (CPU c in context.CPUs)
         {
             CPUs.Add(c);
         }
         Rams = new ObservableCollection <Ram>();
         foreach (Ram r in context.Rams)
         {
             Rams.Add(r);
         }
         Motherboards = new ObservableCollection <Motherboard>();
         foreach (Motherboard m in context.Motherboards)
         {
             Motherboards.Add(m);
         }
         GraphicsCards = new ObservableCollection <GraphicCard>();
         foreach (GraphicCard g in context.GraphicCards)
         {
             GraphicsCards.Add(g);
         }
     }
 }
Exemple #4
0
 private void AddDesktop()
 {
     if (SelectedCPU == null ||
         SelectedGraphicCard == null ||
         SelectedMemory == null ||
         SelectedMemory == null ||
         DesktopName == null ||
         DesktopName.Length < 4)
     {
         return;
     }
     using (var context = new DesktopBuildsContext())
     {
         Desktop desktop = new Desktop()
         {
             CPU         = context.CPUs.First(c => c.Name == selectedCPU.Name),
             GraphicCard = context.GraphicCards.First(g => g.Name == selectedGraphicCard.Name),
             Ram         = context.Rams.First(m => m.Name == selectedMemory.Name),
             Motherboard = context.Motherboards.First(m => m.Name == selectedMotherboard.Name),
             Name        = DesktopName
         };
         Debug.WriteLine(desktop.Name);
         Debug.WriteLine(desktop.CPU.Id);
         Debug.WriteLine(desktop.GraphicCard.Id);
         Debug.WriteLine(desktop.Ram.Id);
         Debug.WriteLine(desktop.Motherboard.Id);
         if (context.Desktops.Any(d => d.Name.ToLower() == desktop.Name.ToLower()))
         {
             return;
         }
         context.Desktops.Add(desktop);
         context.SaveChanges();
     }
 }
Exemple #5
0
        private void MakeNewGraphicCard(string name, string frequency, string memory, string manufacturer)
        {
            int _frequency;
            int _memory;

            if (!int.TryParse(frequency, out _frequency) || !int.TryParse(memory, out _memory))
            {
                return;
            }

            GraphicCard graphicCard = new GraphicCard
            {
                Name         = name,
                Manufacturer = manufacturer,
                Frequency    = _frequency,
                Memory       = _memory,
            };

            using (var context = new DesktopBuildsContext())
            {
                if (context.GraphicCards.Any(g => g.Name.ToLower() == graphicCard.Name.ToLower()))
                {
                    return;
                }
                context.GraphicCards.Add(graphicCard);
                context.SaveChanges();
            }
        }
Exemple #6
0
        private void MakeNewMotherboard(string name, string socket, string PCICount, string PCIEx16Count, string PCIExCount, string manufacturer)
        {
            int _PCICount;
            int _PCIEx16Count;
            int _PCIExCount;

            if (!int.TryParse(PCICount, out _PCICount) || !int.TryParse(PCIEx16Count, out _PCIEx16Count) || !int.TryParse(PCIExCount, out _PCIExCount))
            {
                return;
            }
            Motherboard motherboard = new Motherboard
            {
                Socket       = socket,
                Manufacturer = manufacturer,
                PCICount     = _PCICount,
                PCIEx16Count = _PCIEx16Count,
                PCIExCount   = _PCIExCount,
                Name         = name
            };

            using (var context = new DesktopBuildsContext())
            {
                if (context.Motherboards.Any(m => m.Name.ToLower() == motherboard.Name.ToLower()))
                {
                    return;
                }
                context.Motherboards.Add(motherboard);
                context.SaveChanges();
            }
        }
        private void MakeNewMemory(string name, string capacity, string frequency, string generation, string manufacturer)
        {
            int _capacity;
            int _frequency;

            if (!int.TryParse(capacity, out _capacity) || !int.TryParse(frequency, out _frequency))
            {
                return;
            }
            Ram memory = new Ram
            {
                Name         = name,
                Capacity     = _capacity,
                Frequency    = _frequency,
                Generation   = generation,
                Manufacturer = manufacturer
            };

            using (var context = new DesktopBuildsContext())
            {
                if (context.Rams.Any(m => m.Name.ToLower() == memory.Name.ToLower()))
                {
                    return;
                }
                context.Rams.Add(memory);
                context.SaveChanges();
            }
        }
Exemple #8
0
 private static void SaveAll()
 {
     using (var context = new DesktopBuildsContext())
     {
         context.Rams.Add(ram);
         context.CPUs.Add(cpu);
         context.Motherboards.Add(motherboard);
         context.GraphicCards.Add(graphicCard);
         context.Desktops.Add(desktop);
         context.SaveChanges();
     }
 }
Exemple #9
0
        private void Edit()
        {
            using (var context = new DesktopBuildsContext())
            {
                if (MotherboardName != Motherboard.Name)
                {
                    Motherboard.Name = MotherboardName;
                }

                if (Manufacturer != Motherboard.Manufacturer)
                {
                    Motherboard.Manufacturer = Manufacturer;
                }

                if (Socket != Motherboard.Socket)
                {
                    Motherboard.Socket = Socket;
                }

                int c;
                if (int.TryParse(PCICount, out c) && Motherboard.PCICount != c)
                {
                    Motherboard.PCICount = c;
                }

                int ex16;
                if (int.TryParse(PCIEx16Count, out ex16) && Motherboard.PCIEx16Count != ex16)
                {
                    Motherboard.PCIEx16Count = ex16;
                }

                int ex;
                if (int.TryParse(PCIExCount, out ex) && Motherboard.PCIExCount != ex)
                {
                    Motherboard.PCIExCount = ex;
                }

                if (Motherboard.Name != Original.Name ||
                    Motherboard.Manufacturer != Original.Manufacturer ||
                    Motherboard.Socket != Original.Socket ||
                    Motherboard.PCICount != Original.PCICount ||
                    Motherboard.PCIEx16Count != Original.PCIEx16Count ||
                    Motherboard.PCIExCount != Original.PCIExCount)
                {
                    context.Motherboards.Update(Motherboard);
                    context.SaveChanges();
                    Close();
                }
            }
        }
Exemple #10
0
        private void Edit()
        {
            if (RAMName != Ram.Name)
            {
                Ram.Name = RAMName;
            }

            if (Manufacturer != Ram.Manufacturer)
            {
                Ram.Manufacturer = Manufacturer;
            }

            int c;

            if (int.TryParse(Capacity, out c) && Ram.Capacity != c)
            {
                Ram.Capacity = c;
            }

            int f;

            if (int.TryParse(Frequency, out f) && Ram.Frequency != f)
            {
                Ram.Frequency = f;
            }

            if (Generation != Ram.Generation)
            {
                Ram.Generation = Generation;
            }

            if (Ram.Name != Original.Name ||
                Ram.Manufacturer != Original.Manufacturer ||
                Ram.Capacity != Original.Capacity ||
                Ram.Frequency != Original.Frequency ||
                Ram.Generation != Original.Generation)
            {
                using (var context = new DesktopBuildsContext())
                {
                    context.Rams.Update(Ram);
                    context.SaveChanges();
                    Close();
                }
            }
        }
        private void FillList()
        {
            int index;

            if (SelectedItem == null)
            {
                index = 0;
            }
            else
            {
                index = ItemsToEdit.IndexOf(SelectedItem);
            }

            ItemsToEdit.Clear();
            using (var context = new DesktopBuildsContext())
            {
                var c  = context.CPUs;
                var mo = context.Motherboards;
                var me = context.Rams;
                var g  = context.GraphicCards;
                var d  = context.Desktops;
                foreach (CPU cpu in c)
                {
                    ItemsToEdit.Add(cpu);
                }
                foreach (Motherboard m in mo)
                {
                    ItemsToEdit.Add(m);
                }
                foreach (Ram m in me)
                {
                    ItemsToEdit.Add(m);
                }
                foreach (GraphicCard graphicCard in g)
                {
                    ItemsToEdit.Add(graphicCard);
                }
                foreach (Desktop desktop in d)
                {
                    ItemsToEdit.Add(desktop);
                }
                SelectedItem = ItemsToEdit[index];
            }
        }
        private void Edit()
        {
            using (var context = new DesktopBuildsContext())
            {
                bool changed = false;
                if (Manufacturer != CPU.Manufacturer)
                {
                    CPU.Manufacturer = Manufacturer;
                    changed          = true;
                }
                if (CPUName != CPU.Name)
                {
                    CPU.Name = CPUName;
                    changed  = true;
                }
                float df;
                if (float.TryParse(DefaultFrequency, out df) && df != CPU.DefaultFrequency)
                {
                    CPU.DefaultFrequency = df;
                    changed = true;
                }
                float mf;
                if (float.TryParse(MaxFrequency, out mf) && mf != CPU.MaxFrequency)
                {
                    CPU.MaxFrequency = mf;
                    changed          = true;
                }
                int c;
                if (int.TryParse(Cache, out c) && c != CPU.Cache)
                {
                    CPU.Cache = c;
                    changed   = true;
                }
                if (changed)
                {
                    context.CPUs.Update(CPU);
                    context.SaveChanges();

                    Close();
                }
            }
        }
        private void MakeNewCPU(string name, int cache, float defaultFrequency, float maxFrequency, string manufacturer)
        {
            CPU cpu = new CPU
            {
                Cache            = cache,
                DefaultFrequency = defaultFrequency,
                MaxFrequency     = maxFrequency,
                Manufacturer     = manufacturer,
                Name             = name
            };

            using (var context = new DesktopBuildsContext())
            {
                if (context.CPUs.Any(c => c.Name.ToLower() == cpu.Name.ToLower()))
                {
                    return;
                }
                context.CPUs.Add(cpu);
                context.SaveChanges();
            }
        }
        private void Edit()
        {
            using (var context = new DesktopBuildsContext())
            {
                if (GFXName != GraphicCard.Name)
                {
                    GraphicCard.Name = GFXName;
                }

                if (Manufacturer != GraphicCard.Manufacturer)
                {
                    GraphicCard.Manufacturer = Manufacturer;
                }

                int f;
                if (int.TryParse(Frequency, out f) && GraphicCard.Frequency != f)
                {
                    GraphicCard.Frequency = f;
                }

                int m;
                if (int.TryParse(Memory, out m) && GraphicCard.Memory != m)
                {
                    GraphicCard.Memory = m;
                }

                if (GraphicCard.Name != Original.Name ||
                    GraphicCard.Manufacturer != Original.Manufacturer ||
                    GraphicCard.Frequency != Original.Frequency ||
                    GraphicCard.Memory != Original.Memory)
                {
                    context.GraphicCards.Update(GraphicCard);
                    context.SaveChanges();
                    Close();
                }
            }
        }
 private void DeleteSelectedItem()
 {
     using (var context = new DesktopBuildsContext())
     {
         try
         {
             if (selectedItem.GetType() == typeof(Desktop))
             {
                 context.Desktops.Remove(selectedItem as Desktop);
             }
             else if (selectedItem.GetType() == typeof(GraphicCard))
             {
                 context.GraphicCards.Remove(selectedItem as GraphicCard);
             }
             else if (selectedItem.GetType() == typeof(Motherboard))
             {
                 context.Motherboards.Remove(selectedItem as Motherboard);
             }
             else if (selectedItem.GetType() == typeof(CPU))
             {
                 context.CPUs.Remove(selectedItem as CPU);
             }
             else if (selectedItem.GetType() == typeof(Ram))
             {
                 context.Rams.Remove(selectedItem as Ram);
             }
             context.SaveChanges();
             FillList();
         }
         catch
         {
             Debug.WriteLine("Item was a part of current desktop");
         }
     }
     return;
 }