Esempio n. 1
0
        private void SaveOpticalDrive_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                OpticalDriveProperties opticalDriveProperties = new OpticalDriveProperties()
                {
                    Interface       = (OpticalDriveInterface)Enum.Parse(typeof(OpticalDriveInterface), OpticalDriveInterface.SelectedItem.ToString()),
                    Size            = new Size(Convert.ToInt32(OpticalDriveWidth.Text), Convert.ToInt32(OpticalDriveHeight.Text), Convert.ToInt32(OpticalDriveDepth.Text)),
                    MaxWritingSpeed = new int[] { Convert.ToInt32(OpticalDriveMaxWritingSpeedCD_R.Text),
                                                  Convert.ToInt32(OpticalDriveMaxWritingSpeedCD_RW.Text),
                                                  Convert.ToInt32(OpticalDriveMaxWritingSpeedDVD_R.Text),
                                                  Convert.ToInt32(OpticalDriveMaxWritingSpeedDVDplusR_DL.Text),
                                                  Convert.ToInt32(OpticalDriveMaxWritingSpeedDVD_RW.Text),
                                                  Convert.ToInt32(OpticalDriveMaxWritingSpeedDVDplusR.Text),
                                                  Convert.ToInt32(OpticalDriveMaxWritingSpeedDVDplusR_DL.Text),
                                                  Convert.ToInt32(OpticalDriveMaxWritingSpeedDVDplusRW.Text),
                                                  Convert.ToInt32(OpticalDriveMaxWritingSpeedDVD_RAM.Text) },
                    MaxReadSpeedCD    = Convert.ToInt32(OpticalDriveMaxReadSpeedCD.Text),
                    MaxReadSpeedDVD   = Convert.ToInt32(OpticalDriveMaxReadSpeedDVD.Text),
                    ReadAccessTimeCD  = Convert.ToInt32(OpticalDriveReadAccessTimeCD.Text),
                    ReadAccessTimeDVD = Convert.ToInt32(OpticalDriveReadAccessTimeDVD.Text),
                };
                OpticalDrive opticalDrive = new OpticalDrive(0, OpticalDriveName.Text, "optical_drive", Convert.ToInt32(OpticalDrivePrice.Text), OpticalDriveManufacturingDate.SelectedDate.Value, opticalDriveProperties);

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

            if (GetCount(collection, "case") == 1)
            {
                isValid = GetCount(collection, "optical_drive") < 2 ? true : false;
            }
            else
            {
                isValid = true;
            }                                                                                                                                       //2 статическое значение слотов под приводы в систмном блоке, потом может преместиться в параметр
            if (!isValid)
            {
                ProblemReport(problem_report);
            }
            return(isValid);
        }
        private bool IsFreeSlotsInstallation(Collection <ListBoxObject> collection, HDD hdd, string problem_report)
        {
            bool isValid          = false;
            int  count_interfaces = 0;

            for (int i = 0; i > (collection.Where(m => m.Item.GetTypeValue() == "optical_drive" || m.Item.GetTypeValue() == "hdd").Count()); i++)
            {
                if (collection[i].Item.Type == "optical_drive")
                {
                    OpticalDrive od = collection[i].IObject as OpticalDrive;
                    if ((hdd.Properties.Interface == HDDInterface.sata_20 || hdd.Properties.Interface == HDDInterface.sata_30) &&
                        od.Properties.Interface == OpticalDriveInterface.SATA)
                    {
                        count_interfaces++;
                    }
                    else if (hdd.Properties.Interface == HDDInterface.IDE && od.Properties.Interface == OpticalDriveInterface.IDE)
                    {
                        count_interfaces++;
                    }
                }
                else if (collection[i].Item.Type == "hdd")
                {
                    HDD lhdd = collection[i].IObject as HDD;
                    if ((hdd.Properties.Interface == HDDInterface.sata_20 || hdd.Properties.Interface == HDDInterface.sata_30) &&
                        (lhdd.Properties.Interface == HDDInterface.sata_20 || lhdd.Properties.Interface == HDDInterface.sata_30))
                    {
                        count_interfaces++;
                    }
                    else if (hdd.Properties.Interface == HDDInterface.IDE && lhdd.Properties.Interface == HDDInterface.IDE)
                    {
                        count_interfaces++;
                    }
                }
            }
            if (count_interfaces < hdd.Compatibility((GetSingleItem(collection, "motherboard") as Motherboard).Properties))
            {
                isValid = true;
            }
            if (!isValid)
            {
                ProblemReport(problem_report);
            }
            return(isValid);
        }
Esempio 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);
                    }
                }
            }
        }