コード例 #1
0
ファイル: InsertBoxSet.cs プロジェクト: altras/fmi_projects
        public int PopulateDataBase()
        {
            try
            {
                int cpuId = this.InsertCpu();
                int videoId = this.InsertVideoCard();
                int hddId = this.InsertHdd();
                string motherBoard = this.boxSet.GetMotherBoard();
                string ram = this.boxSet.GetRam();
                string coolSys = this.boxSet.GetCoolingSystem();
                string soundCard = this.boxSet.GetSoundCard();
                string powerSupply = this.boxSet.GetPowerSupply();
                string expansionCard = this.boxSet.GetExpansionCard();
                string box = this.boxSet.GetBox();
                string usb = this.boxSet.GetRemovableDevices().Item1;
                string disk = this.boxSet.GetRemovableDevices().Item2;
                string cardReader = this.boxSet.GetRemovableDevices().Item3;
                string removableDev = usb + "; " + disk + "; " + cardReader;

                CustomComputersAspEntities db = new CustomComputersAspEntities();

                BoxSet match = db.BoxSets.FirstOrDefault(b => b.cupId == cpuId && b.videoCardId == videoId && b.hddId == hddId
                                                           && b.motherboard == motherBoard && b.ram == ram && b.coolingSystem == coolSys
                                                           && b.powerSupply == powerSupply && b.expansionCards == expansionCard
                                                           && b.box == box && b.removableDevices == removableDev);
                if (match == null)
                {
                    db.AddToBoxSets(new BoxSet()
                    {
                        cupId = cpuId,
                        videoCardId = videoId,
                        hddId = hddId,
                        motherboard = motherBoard,
                        ram = ram,
                        coolingSystem = coolSys,
                        powerSupply = powerSupply,
                        expansionCards = expansionCard,
                        box = box,
                        removableDevices = removableDev,
                    });
                    db.SaveChanges();
                    match = db.BoxSets.FirstOrDefault(b => b.cupId == cpuId && b.videoCardId == videoId && b.hddId == hddId
                                                           && b.motherboard == motherBoard && b.ram == ram && b.coolingSystem == coolSys
                                                           && b.powerSupply == powerSupply && b.expansionCards == expansionCard
                                                           && b.box == box && b.removableDevices == removableDev);
                }
                return match.id;
            }
            catch (Exception ex)
            {
                Console.WriteLine("Could not successsfully populate DataBase with BoxSet. Reason: {0}",ex.Message);
                return 0;
            }
        }
コード例 #2
0
        public int PopulateDataBase()
        {
            try
            {
                int    cpuId         = this.InsertCpu();
                int    videoId       = this.InsertVideoCard();
                int    hddId         = this.InsertHdd();
                string motherBoard   = this.boxSet.GetMotherBoard();
                string ram           = this.boxSet.GetRam();
                string coolSys       = this.boxSet.GetCoolingSystem();
                string soundCard     = this.boxSet.GetSoundCard();
                string powerSupply   = this.boxSet.GetPowerSupply();
                string expansionCard = this.boxSet.GetExpansionCard();
                string box           = this.boxSet.GetBox();
                string usb           = this.boxSet.GetRemovableDevices().Item1;
                string disk          = this.boxSet.GetRemovableDevices().Item2;
                string cardReader    = this.boxSet.GetRemovableDevices().Item3;
                string removableDev  = usb + "; " + disk + "; " + cardReader;

                CustomComputersAspEntities db = new CustomComputersAspEntities();

                BoxSet match = db.BoxSets.FirstOrDefault(b => b.cupId == cpuId && b.videoCardId == videoId && b.hddId == hddId &&
                                                         b.motherboard == motherBoard && b.ram == ram && b.coolingSystem == coolSys &&
                                                         b.powerSupply == powerSupply && b.expansionCards == expansionCard &&
                                                         b.box == box && b.removableDevices == removableDev);
                if (match == null)
                {
                    db.AddToBoxSets(new BoxSet()
                    {
                        cupId            = cpuId,
                        videoCardId      = videoId,
                        hddId            = hddId,
                        motherboard      = motherBoard,
                        ram              = ram,
                        coolingSystem    = coolSys,
                        powerSupply      = powerSupply,
                        expansionCards   = expansionCard,
                        box              = box,
                        removableDevices = removableDev,
                    });
                    db.SaveChanges();
                    match = db.BoxSets.FirstOrDefault(b => b.cupId == cpuId && b.videoCardId == videoId && b.hddId == hddId &&
                                                      b.motherboard == motherBoard && b.ram == ram && b.coolingSystem == coolSys &&
                                                      b.powerSupply == powerSupply && b.expansionCards == expansionCard &&
                                                      b.box == box && b.removableDevices == removableDev);
                }
                return(match.id);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Could not successsfully populate DataBase with BoxSet. Reason: {0}", ex.Message);
                return(0);
            }
        }