Ejemplo n.º 1
0
        private void SavePSU_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                PowerSupplyUnitProperties psuProperties = new PowerSupplyUnitProperties()
                {
                    PSUType                = (PSUTypes)Enum.Parse(typeof(PSUTypes), PSUType.SelectedItem.ToString()),
                    Power                  = Convert.ToInt32(PSUPower.Text),
                    TypeCM                 = (TypeConnectorMotherboard)Enum.Parse(typeof(TypeConnectorMotherboard), PSUTypeCM.SelectedItem.ToString()),
                    Pin4plus4CPU           = Convert.ToInt32(PSUPin4plus4CPU.Text),
                    Pin6plus2PCIE          = Convert.ToInt32(PSUPin6plus2PCIE.Text),
                    Pin6PCIE               = Convert.ToInt32(PSUPin6PCIE.Text),
                    Pin8PCIE               = Convert.ToInt32(PSUPin8PCIE.Text),
                    Pin15SATA              = Convert.ToInt32(PSUPin15SATA.Text),
                    Pin4IDE                = Convert.ToInt32(PSUPin4IDE.Text),
                    Pin4Floppy             = Convert.ToInt32(PSUPin4Floppy.Text),
                    MinNoiseLevel          = Convert.ToInt32(PSUMinNoiseLevel.Text),
                    MaxNoiseLevel          = Convert.ToInt32(PSUMaxNoiseLevel.Text),
                    OvervoltageProtection  = PSUOvervoltageProtection.IsChecked.Value,
                    OverloadProtection     = PSUOverloadProtection.IsChecked.Value,
                    ShortCircuitProtection = PSUShortCircuitProtection.IsChecked.Value,
                };
                PowerSupplyUnit psu = new PowerSupplyUnit(0, PSUName.Text, "psu", Convert.ToInt32(PSUPrice.Text), PSUManufacturingDate.SelectedDate.Value, psuProperties);

                int id = InsertToDB(psu);
                psu.Uid = id;
                items.AllPowerSupplyUnits.Add(psu);
                PSUs.Items.Refresh();
                MessageBox.Show("Запись добавлена!");
            } catch {
                MessageBox.Show("Запись не была добавлена в базу, вероятно не заполнено одно или несколько полей, либо заполнены неверно.");
            }
        }
        private bool IsNullOrCompatibleCase(Collection <ListBoxObject> collection, PowerSupplyUnit psu, string problem_report)
        {
            bool isValid = false;

            if (GetCount(collection, "case") == 0 || psu.CheckCompatibility((GetSingleItem(collection, "case") as Case).Properties))
            {
                isValid = true;
            }
            else
            {
                ProblemReport(problem_report);
            }
            return(isValid);
        }
        //Create
        public bool CreatePSU(PSUCreate model)
        {
            PowerSupplyUnit entity = new PowerSupplyUnit
            {
                Name             = model.Name,
                Manufacturer     = model.Manufacturer,
                EffeciencyRating = model.EffeciencyRating,
                Type             = model.Type,
                TypeOfModular    = model.TypeOfModular,
                Color            = model.Color,
                Fanless          = model.Fanless,
                ATXConnectors    = model.ATXConnectors,
                IsAvailable      = model.IsAvailable
            };

            _db.PowerSupplyUnits.Add(entity);
            return(_db.SaveChanges() == 1);
        }
Ejemplo n.º 4
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);
                    }
                }
            }
        }