Пример #1
0
        public void DeleteCPUCooler()
        {
            // Remove item from database if it already exists
            if (DC.ItemExists("Corsair H100i PRO"))
            {
                int tempID = DC.GetItems().Find(a => a.Name == "Corsair H100i PRO").ID;
                DC.DeleteItem(tempID, false);
            }
            // Test CPU
            Item item = new Item
            {
                Name      = "Corsair H100i PRO",
                Price     = 27.95m,
                Quantity  = 3,
                Component = Database.Model.Type.CPUCOOLER
            };
            CPUCooler cpuCooler = new CPUCooler
            {
                FanRPM     = "600 - 2000 RPM",
                NoiseLevel = 37d
            };

            // Add Item
            Assert.IsTrue(DC.AddItem(item, cpuCooler), "Couldnt Add Item for test.");
            // Delete Item (Returns false if transaction couldnt be added)
            int id = DC.GetItems().Find(a => a.Name == item.Name).ID;

            Assert.IsTrue(DC.DeleteItem(id), "Failed to delete from database");
        }
Пример #2
0
        /// <summary>
        /// Adds CP
        /// </summary>
        /// <param name="_item">Item details of CPU.</param>
        /// <param name="_cpuCooler"></param>
        /// <returns></returns>
        public bool AddItem(Item _item, CPUCooler _cpuCooler)
        {
            try
            {
                // Using database context
                using (var db = new InventorySystemContext())
                {
                    // Add CPU to database if item does not fail.
                    if (AddItem(_item))
                    {
                        // Get item ID
                        var item = db.Items.First(c => c.Name == _item.Name);

                        // Add Item to cpu
                        CPUCooler cpuCooler = _cpuCooler;
                        cpuCooler.Item = item;

                        db.CPUCoolers.Add(_cpuCooler);
                        db.SaveChanges();
                    }
                    else
                    {
                        // Returns false if name exists.
                        return(false);
                    }
                }
            }
            catch (Exception e)
            {
                // Return false if failed.
                return(false);
            }
            // Return true if successful.
            return(true);
        }
Пример #3
0
        private void SaveCPUCooler_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                CPUCoolerProperties cpuCoolerProperties = new CPUCoolerProperties()
                {
                    MinRotationalSpeed = Convert.ToInt32(CPUCoolerMinRotationalSpeed.Text),
                    MaxRotationalSpeed = Convert.ToInt32(CPUCoolerMaxRotationalSpeed.Text),
                    AirFlow            = Convert.ToInt32(CPUCoolerAirFlow.Text),
                    MinNoiseLevel      = Convert.ToInt32(CPUCoolerMinNoiseLevel.Text),
                    MaxNoiseLevel      = Convert.ToInt32(CPUCoolerMaxNoiseLevel.Text),
                    SpeedController    = CPUCoolerSpeedController.IsChecked.Value,
                    Size = new Size(Convert.ToInt32(CPUCoolerWidth.Text),
                                    Convert.ToInt32(CPUCoolerHeight.Text),
                                    Convert.ToInt32(CPUCoolerDepth.Text)),
                };
                for (int i = 0; CPUCoolerSockets.SelectedItems.Count > i; i++)
                {
                    cpuCoolerProperties.Sockets.Add((Sockets)Enum.Parse(typeof(Sockets), CPUCoolerSockets.SelectedItems[i].ToString()));
                }
                CPUCooler cpuCooler = new CPUCooler(0, CPUCoolerName.Text, "cpu_cooler", Convert.ToInt32(CPUCoolerPrice.Text), CPUCoolerManufacturingDate.SelectedDate.Value, cpuCoolerProperties);

                int id = InsertToDB(cpuCooler);
                cpuCooler.Uid = id;
                items.AllCPUCoolers.Add(cpuCooler);
                CPUCoolers.Items.Refresh();
                MessageBox.Show("Запись добавлена!");
            } catch {
                MessageBox.Show("Запись не была добавлена в базу, вероятно не заполнено одно или несколько полей, либо заполнены неверно.");
            }
        }
Пример #4
0
        public void AddCPUCooler()
        {
            // Remove item from database if it already exists
            if (DC.ItemExists("Cooler Master Hyper 212 EVO"))
            {
                int id = DC.GetItems().Find(a => a.Name == "Cooler Master Hyper 212 EVO").ID;
                DC.DeleteItem(id, false);
            }
            // Test CPU
            Item item = new Item
            {
                Name      = "Cooler Master Hyper 212 EVO",
                Price     = 27.95m,
                Quantity  = 3,
                Component = Database.Model.Type.CPUCOOLER
            };
            CPUCooler cpuCooler = new CPUCooler
            {
                FanRPM     = "600 - 2000 RPM",
                NoiseLevel = 37d
            };

            Assert.IsTrue(DC.AddItem(item, cpuCooler), "Failed to add test CPU Cooler.");

            Assert.IsTrue(DC.ItemExists("Cooler Master Hyper 212 EVO"), "Can't find test CPU Cooler in database.");
        }
Пример #5
0
 public CreateViewModel()
 {
     Item        = new Item();
     CPU         = new CPU();
     CPUCooler   = new CPUCooler();
     GPU         = new GPU();
     Motherboard = new Motherboard();
     PSU         = new PSU();
     RAM         = new RAM();
     Case        = new Case();
 }
Пример #6
0
        public ActionResult CPUCooler(CPUCooler cpuCooler)
        {
            newItem.CPUCooler = cpuCooler;

            // save to database
            DatabaseController db = new DatabaseController();

            db.AddItem(newItem.Item, newItem.CPUCooler);


            newItem = null;
            return(RedirectToAction("Index", "Inventory"));
        }
        private bool IsСompatibleCPU(Collection <ListBoxObject> collection, CPUCooler cpuCooler, string problem_report)
        {
            bool isValid = false;

            if (cpuCooler.CheckCompatibility((GetSingleItem(collection, "cpu") as CPU).Properties))
            {
                isValid = true;
            }
            else
            {
                ProblemReport(problem_report);
            }
            return(isValid);
        }
Пример #8
0
        private void BuyButton_Click(object sender, RoutedEventArgs e)
        {
            if (GameEnvironment.Player.House == null)
            {
                GameMessageBox.Show("Покупка", "Вам негде это хранить, для начала обзаведитесь жильем.", GameMessageBox.MessageBoxType.Information); return;
            }
            Button button = sender as Button;

            if (button.Tag is BaseItem)
            {
                double price = (button.Tag as BaseItem).Price * GameEnvironment.Money.PlayerCurrency[0].Course;
                price += price / 100 * StorePercentage;

                if (price <= GameEnvironment.Money.PlayerCurrency[0].Count)
                {
                    GameEnvironment.Money.PlayerCurrency[0].Withdraw("Оплата покупки: " + (button.Tag as BaseItem).Name, Properties.Resources.ComponentStoreFullName, GameEnvironment.GameEvents.GameTimer.DateAndTime, price);
                    CoinCount.Content = GameEnvironment.Money.PlayerCurrency[0].Count.ToString("N3") + " " + GameEnvironment.Money.PlayerCurrency[0].Abbreviation;

                    if (button.Tag is Case)
                    {
                        Case @case = (button.Tag as Case);
                        GameEnvironment.Items.Cases.Add(new Case(@case.Uid, @case.Name, @case.GetTypeValue(), @case.Price, @case.ManufacturingDate, @case.Properties));
                    }
                    else if (button.Tag is Motherboard)
                    {
                        Motherboard motherboard = (button.Tag as Motherboard);
                        GameEnvironment.Items.Motherboards.Add(new Motherboard(motherboard.Uid, motherboard.Name, motherboard.GetTypeValue(), motherboard.Price, motherboard.ManufacturingDate, motherboard.Properties));
                    }
                    else if (button.Tag is PowerSupplyUnit)
                    {
                        PowerSupplyUnit psu = (button.Tag as PowerSupplyUnit);
                        GameEnvironment.Items.PowerSupplyUnits.Add(new PowerSupplyUnit(psu.Uid, psu.Name, psu.GetTypeValue(), psu.Price, psu.ManufacturingDate, psu.Properties));
                    }
                    else if (button.Tag is CPU)
                    {
                        CPU cpu = (button.Tag as CPU);
                        GameEnvironment.Items.CPUs.Add(new CPU(cpu.Uid, cpu.Name, cpu.GetTypeValue(), cpu.Price, cpu.ManufacturingDate, cpu.Properties));
                    }
                    else if (button.Tag is RAM)
                    {
                        RAM ram = (button.Tag as RAM);
                        GameEnvironment.Items.RAMs.Add(new RAM(ram.Uid, ram.Name, ram.GetTypeValue(), ram.Price, ram.ManufacturingDate, ram.Properties));
                    }
                    else if (button.Tag is CPUCooler)
                    {
                        CPUCooler cpuCooler = button.Tag as CPUCooler;
                        GameEnvironment.Items.CPUCoolers.Add(new CPUCooler(cpuCooler.Uid, cpuCooler.Name, cpuCooler.GetTypeValue(), cpuCooler.Price, cpuCooler.ManufacturingDate, cpuCooler.Properties));
                    }
                    else if (button.Tag is HDD)
                    {
                        HDD hdd = button.Tag as HDD;
                        GameEnvironment.Items.HDDs.Add(new HDD(hdd.Uid, hdd.Name, hdd.GetTypeValue(), hdd.Price, hdd.ManufacturingDate, hdd.Properties));
                    }
                    else if (button.Tag is Monitor)
                    {
                        Monitor monitor = button.Tag as Monitor;
                        GameEnvironment.Items.Monitors.Add(new Monitor(monitor.Uid, monitor.Name, monitor.GetTypeValue(), monitor.Price, monitor.ManufacturingDate, monitor.Properties));
                    }
                    else if (button.Tag is VideoCard)
                    {
                        VideoCard videoCard = button.Tag as VideoCard;
                        GameEnvironment.Items.VideoCards.Add(new VideoCard(videoCard.Uid, videoCard.Name, videoCard.GetTypeValue(), videoCard.Price, videoCard.ManufacturingDate, videoCard.Properties));
                    }
                    else if (button.Tag is OpticalDrive)
                    {
                        OpticalDrive opticalDrive = button.Tag as OpticalDrive;
                        GameEnvironment.Items.OpticalDrives.Add(new OpticalDrive(opticalDrive.Uid, opticalDrive.Name, opticalDrive.GetTypeValue(), opticalDrive.Price, opticalDrive.ManufacturingDate, opticalDrive.Properties));
                    }
                    else if (button.Tag is Keyboard)
                    {
                        Keyboard keyboard = button.Tag as Keyboard;
                        GameEnvironment.Items.Keyboards.Add(new Keyboard(keyboard.Uid, keyboard.Name, keyboard.GetTypeValue(), keyboard.Price, keyboard.ManufacturingDate, keyboard.Properties));
                    }

                    SellerText.Text = "Спасибо за покупку " + (button.Tag as BaseItem).Name + ", хороший выбор!";
                }
                else
                {
                    SellerText.Text = "Извини дружище, нет денег нет товара.";
                }
            }
            else if (button.Tag is Mouse)
            {
                Mouse mouse = button.Tag as Mouse;
                GameEnvironment.Items.Mice.Add(new Mouse(mouse.Uid, mouse.Name, mouse.GetTypeValue(), mouse.Price, mouse.ManufacturingDate, mouse.Properties));
            }
        }
        private void AddItemButton_Click(object sender, RoutedEventArgs e)
        {
            if (sender is Button & !String.IsNullOrEmpty(AssemblyList.Text))
            {
                if (!(ComputerСomponents.ItemsSource is Collection <ListBoxObject>))
                {
                    ComputerСomponents.ItemsSource = new Collection <ListBoxObject>();
                }

                Button button = sender as Button;
                Collection <ListBoxObject> items = ComputerСomponents.ItemsSource as Collection <ListBoxObject>;

                if (button.Tag is Case)
                {
                    Case @case = (button.Tag as Case);
                    if (IsEquality(GetCount(items, @case.GetTypeValue()), 0, Operators.Equally, "У вас уже есть корпус в этой конфигурации!") &&
                        IsNullOrCompatibleMotherboard(items, @case, "Материнская плата не станет в этот корпус!") &&
                        IsСapacityHDD(items, @case, "Все диски сюда не влезут!") &&
                        IsNullOrCompatiblePSU(items, @case, "Блок питания не станет в этот корпус!"))
                    {
                        InstallСomponent <Case>(items, @case, button);
                    }
                }
                else if (button.Tag is Motherboard)
                {
                    Motherboard motherboard = (button.Tag as Motherboard);
                    if (IsEquality(GetCount(items, motherboard.GetTypeValue()), 0, Operators.Equally, "У вас уже есть материнская плата в этой конфигурации!") &&
                        IsNullOrCompatibleMotherboard(items, motherboard, "Материнская плата не станет в этот корпус!"))
                    {
                        InstallСomponent <Motherboard>(items, motherboard, button);
                    }
                }
                else if (button.Tag is PowerSupplyUnit)
                {
                    PowerSupplyUnit psu = (button.Tag as PowerSupplyUnit);
                    if (IsEquality(GetCount(items, psu.GetTypeValue()), 0, Operators.Equally, "У вас уже есть блок питания в этой конфигурации!") &&
                        IsEquality(GetCount(items, "motherboard"), 1, Operators.Equally, "У вас нет материнской платы, к чему подключать собрались?") &&
                        IsNullOrCompatibleCase(items, psu, "Блок питания не станет в этот корпус!"))
                    {
                        InstallСomponent <PowerSupplyUnit>(items, psu, button);
                    }
                }
                else if (button.Tag is CPU)
                {
                    CPU cpu = (button.Tag as CPU);
                    if (IsEquality(GetCount(items, cpu.GetTypeValue()), 0, Operators.Equally, "У вас уже есть процессор в этой конфигурации!") &&
                        IsEquality(GetCount(items, "motherboard"), 1, Operators.Equally, "У вас нет материнской платы, и куда вы собрались ставить процессор?") &&
                        IsСompatibleSocket((GetSingleItem(items, "motherboard") as Motherboard), cpu, "Впихнуть невпихуемое? На сокет посмотри!"))
                    {
                        InstallСomponent <CPU>(items, cpu, button);
                    }
                }
                else if (button.Tag is RAM)
                {
                    RAM ram = (button.Tag as RAM);
                    if (IsEquality(GetCount(items, "motherboard"), 1, Operators.Equally, "У вас нет материнской платы, и куда вы собрались вставлять память?") &&
                        IsСompatibleRAMSlots(items, ram, "Все слоты заняты!") &&
                        IsEnteringRangeFrequency(ram, GetSingleItem(items, "motherboard") as Motherboard, "Материнской платой не поддерживаеться память с такой частатой.") &&
                        IsEnteringRangeVolume(items, ram, "По объему не подходит!") &&
                        IsСompatibleRAMType(items, ram, "Ну не лезет же, тип памяти другой!"))
                    {
                        InstallСomponent <RAM>(items, ram, button);
                    }
                }
                else if (button.Tag is CPUCooler)     //Дописать проверку на размер
                {
                    CPUCooler cpuCooler = button.Tag as CPUCooler;
                    if (IsEquality(GetCount(items, cpuCooler.GetTypeValue()), 0, Operators.Equally, "У вас уже есть куллер для процессора в этой конфигурации!") &&
                        IsEquality(GetCount(items, "cpu"), 1, Operators.Equally, "Хмм... куда же всунуть эту непонятную штуку? Правильно некуда! У вас нет процессора.") &&
                        IsСompatibleCPU(items, cpuCooler, "Это сюда не встанет!"))
                    {
                        InstallСomponent <CPUCooler>(items, cpuCooler, button);
                    }
                }
                else if (button.Tag is HDD)
                {
                    HDD hdd = button.Tag as HDD;
                    if (IsEquality(GetCount(items, "motherboard"), 1, Operators.Equally, "У вас нет материнской платы, и куда вы собрались подключать диск?") &&
                        IsFreeSpaceInstallation(items, hdd, "Увы, но некуда поставить.") &&
                        IsFreeSlotsInstallation(items, hdd, "Ничего у вас не выйдет, нет свободных слотов!"))
                    {
                        InstallСomponent <HDD>(items, hdd, button);
                    }
                }
                else if (button.Tag is Monitor)
                {
                    Monitor monitor = button.Tag as Monitor;
                    if (IsEquality(GetCount(items, "motherboard"), 1, Operators.Equally, "У вас нет материнской платы!") &&
                        IsFreeVideoInterfaces(items, monitor, "Нет свободных гнезд для подключения."))
                    {
                        InstallСomponent <Monitor>(items, monitor, button);
                    }
                }
                else if (button.Tag is VideoCard)
                {
                    VideoCard videoCard = button.Tag as VideoCard;
                    if (IsEquality(GetCount(items, "motherboard"), 1, Operators.Equally, "У вас нет материнской платы, видеокарту куда вставлять прикажете?") &&
                        IsСompatibleInterface(items, videoCard, "Нет подходящего интерфейса!"))
                    {
                        InstallСomponent(items, videoCard, button);
                    }
                }
                else if (button.Tag is OpticalDrive)
                {
                    OpticalDrive opticalDrive = button.Tag as OpticalDrive;
                    if (IsEquality(GetCount(items, "motherboard"), 1, Operators.Equally, "У вас нет материнской платы, куда прикажете привод подключить?!") &&
                        IsFreeSpaceInstallation(items, opticalDrive, "Нет свободных мест для установки оптического привода.") &&
                        IsFreeSlotsInstallation(items, opticalDrive, "Нет свободных интерфейсов для подключения оптического привода."))
                    {
                        InstallСomponent <OpticalDrive>(items, opticalDrive, button);
                    }
                }
                else if (button.Tag is Mouse)
                {
                    Mouse mouse = button.Tag as Mouse;
                    if (IsEquality(GetCount(items, "motherboard"), 1, Operators.Equally, "У вас нет материнской платы, грызуна некуда воткнуть!") &&
                        IsFreeInterfaces(items, mouse, "Нет свободных гнезд для подключения мышки."))
                    {
                        InstallСomponent <Mouse>(items, mouse, button);
                    }
                }
                else if (button.Tag is Keyboard)
                {
                    Keyboard keyboard = button.Tag as Keyboard;
                    if (IsEquality(GetCount(items, "motherboard"), 1, Operators.Equally, "У вас нет материнской платы, клаву некуда воткнуть!") &&
                        IsFreeInterfaces(items, keyboard, "Нет свободных гнезд для подключения клавиатуры."))
                    {
                        InstallСomponent <Keyboard>(items, keyboard, button);
                    }
                }
            }
        }
Пример #10
0
        public Dictionary <string, string> GetObject(int _id)
        {
            Dictionary <string, string> keyValuePairs = new Dictionary <string, string>();

            using (var db = new InventorySystemContext())
            {
                if (db.Items.Any(i => i.ID == _id))
                {
                    Item item = db.Items.First(i => i.ID == _id);
                    // Check all lists and delete where necessary
                    // Case
                    switch (item.Component)
                    {
                    case (Model.Type.CASE):
                        Case @case = db.Cases.First(c => c.ItemID == _id);
                        keyValuePairs.Add("Type", @case.Type.ToString());
                        keyValuePairs.Add("External 5 1/4\" bays", @case.ExtFiveBays.ToString());
                        keyValuePairs.Add("Internal 3 1/3\" bays", @case.IntThreeBays.ToString());
                        break;

                    case (Model.Type.CPU):
                        CPU cpu = db.CPUs.First(c => c.ItemID == _id);
                        keyValuePairs.Add("Power", cpu.Power.ToString() + " W");
                        keyValuePairs.Add("Speed", cpu.Speed.ToString() + " GHz");
                        break;

                    case (Model.Type.CPUCOOLER):
                        CPUCooler cpuCooler = db.CPUCoolers.First(c => c.ItemID == _id);
                        keyValuePairs.Add("Fan RPM", cpuCooler.FanRPM);
                        keyValuePairs.Add("Noise Level", cpuCooler.NoiseLevel.ToString() + " dB");
                        break;

                    case (Model.Type.GPU):
                        GPU gpu = db.GPUs.First(c => c.ItemID == _id);
                        keyValuePairs.Add("Series", gpu.Series);
                        keyValuePairs.Add("Chipset", gpu.Chipset);
                        keyValuePairs.Add("Memory", gpu.Memory);
                        keyValuePairs.Add("Core Clock", gpu.CoreClock.ToString() + " GHz");
                        break;

                    case (Model.Type.MOTHERBOARD):
                        Motherboard motherboard = db.Motherboards.First(c => c.ItemID == _id);
                        keyValuePairs.Add("Socket", motherboard.Socket);
                        keyValuePairs.Add("Form Factor", motherboard.FormFactor);
                        keyValuePairs.Add("RAM Slots", motherboard.RamSlots.ToString());
                        keyValuePairs.Add("Max RAM", motherboard.MaxRam);
                        break;

                    case (Model.Type.PSU):
                        PSU psu = db.PSUs.First(c => c.ItemID == _id);
                        keyValuePairs.Add("Series", psu.Series);
                        keyValuePairs.Add("Form", psu.Form);
                        keyValuePairs.Add("Efficiency", psu.Efficiency);
                        keyValuePairs.Add("Watts", psu.Watts.ToString() + " W");
                        keyValuePairs.Add("Modular", psu.Modular);
                        break;

                    case (Model.Type.RAM):
                        RAM ram = db.RAMs.First(c => c.ItemID == _id);
                        keyValuePairs.Add("Speed", ram.Speed);
                        keyValuePairs.Add("Type", ram.Type);
                        keyValuePairs.Add("CAS", ram.CAS.ToString());
                        keyValuePairs.Add("Modules", ram.Modules);
                        keyValuePairs.Add("Size", ram.Size);
                        break;

                    default:
                        return(keyValuePairs);
                    }
                }
                return(keyValuePairs);
            }
        }