Beispiel #1
0
 int selectedRAMType = SelectMain(selectedSocket);
            SelectRAM(selectedRAMType);       

            int powReq = (RatioList[5] != 0) ? SelectVGA() : 0;
            SelectPSU(powReq);

            if (RatioList[7] != 0)
                SelectCase();

            SelectHDD();
            if (RatioList[4] != 0)
                SelectSSD();
        }
        public List<int> DoWork(int id, uint money, ProductList list)
        {
            
            this.LoadRecipe(id, money);
            this.Money = money;
            this.pList = list;

            LoadPossibleList();
            SelectHardware();
            return SelectedList;
        }
        //select hardware
        private int SelectCPU() // index = 0, return socketID of selected CPU
        {
            int maxPrice = 0;
            List<Component> tmp = pList.List(0);
            for (int i = 0; i < CPUList.Count; i++)
            {
                CPU cpu = (tmp[CPUList[i]] as CPU);
                if (cpu.Price > maxPrice)
                {
                    maxPrice = cpu.Price;
                    SelectedList[0] = CPUList[i];
                }              
            }
            return (tmp[SelectedList[0]] as CPU).Socket;
        }
        private int SelectMain(int Socket) // index = 1, return memType of selected Mainboard
        {
            int maxPrice = 0;
            List<Component> tmp = pList.List(1);
            for (int i = 0; i < MainbList.Count; i++)
            {
                Mainboard main = (tmp[MainbList[i]] as Mainboard);
                if (main.Socket == Socket )
                {
                    if(main.Price > maxPrice)
                    {
                        maxPrice = main.Price;
                        SelectedList[1] = MainbList[i];
                    }
                }
            }
            return (tmp[SelectedList[1]] as Mainboard).memType;
        }
        private void SelectRAM(int memType) // index = 2, return RAMTypeID of selected RAM
        {
            int maxPrice = 0;
            List<Component> tmp = pList.List(2);
            for (int i = 0; i < RAMList.Count; i++)
            {
                RAM ram = (tmp[RAMList[i]] as RAM);
                if (ram.memType == memType)
                {
                    if (ram.Price > maxPrice)
                    {
                        maxPrice = ram.Price;
                        SelectedList[2] = RAMList[i];
                    }
                }
            }
        }
        private void SelectHDD() // index = 3,
        {
            int maxPrice = 0;
            List<Component> tmp = pList.List(3);
            for (int i = 0; i < HDDList.Count; i++)
            {
                HDD hdd = (tmp[HDDList[i]] as HDD);
                if (hdd.Price > maxPrice)
                {
                    maxPrice = hdd.Price;
                    SelectedList[3] = HDDList[i];
                }
            }
        }
        private void SelectSSD() // index = 4,
        {
            int maxPrice = 0;
            List<Component> tmp = pList.List(4);
            for (int i = 0; i < SSDList.Count; i++)
            {
                SSD ssd = (tmp[SSDList[i]] as SSD);
                if (ssd.Price > maxPrice)
                {
                    maxPrice = ssd.Price;
                    SelectedList[4] = SSDList[i];
                }
            }
        }
        private int SelectVGA() // index = 5, return Power Require of selected VGA
        {
            int maxPrice = 0;
            List<Component> tmp = pList.List(5);
            for (int i = 0; i < VGAList.Count; i++)
            {
                VGA vga = (tmp[VGAList[i]] as VGA);
                if (vga.Price > maxPrice)
                {
                    maxPrice = vga.Price;
                    SelectedList[5] = VGAList[i];
                }
            }
            return (tmp[SelectedList[5]] as VGA).PowReq;
        }
        private void SelectPSU(int PowerReq) //index = 6,
        {
            int maxPrice = 0;
            List<Component> tmp = pList.List(6);
            for (int i = 0; i < PSUList.Count; i++)
            {
                PSU psu = (tmp[PSUList[i]] as PSU);
                if (psu.Power >= PowerReq) // + 80)
                {
                    if (psu.Price > maxPrice)
                    {
                        maxPrice = psu.Price;
                        SelectedList[6] = PSUList[i];
                    }
                }
            }
        }
        private void SelectCase() //index 7,
        {
            int maxPrice = 0;
            List<Component> tmp = pList.List(7);
            for (int i = 0; i < CaseList.Count; i++)
            {
                Case cse = (tmp[CaseList[i]] as Case);
                if (cse.Size >= (pList.List(1)[SelectedList[1]] as Mainboard).Size)
                {
                    if (cse.Price > maxPrice)
                    {
                        maxPrice = cse.Price;
                        SelectedList[7] = CaseList[i];
                    }
                }
            }
        }
        //current not supported
        private void SelectFan() //index = 8,
        { }
        private void SelectCooler() // index = 9
        { }
        private void SelectODD() // index = 10
        { }
        private void SelectSC() // index = 11
        { }
        #endregion
    }
}
 public void Load(ProductList list, List<int> selected)
 {
     this.pList = list;
     SelectedList = selected;
     DoWord();
 }
 public ProductList Clone()
 {
     ProductList tmp = new ProductList();
     return tmp;
 }