コード例 #1
0
ファイル: AName.cs プロジェクト: jdpoints/BabyNameGenerator
        public void RandomFirst()
        {
            first_name tempFirst = new first_name();

            if (this.FirstName == null)
            {
                tempFirst.FirstID = -1;
            }
            else
            {
                tempFirst = this.FirstName;
            }

            first_name newFirst = new first_name();

            using (var context = new NameGeneratorContext())
            {
                var nameQuery = context.first_name
                                .Where(n => n.Active != false)
                                .ToList();

                nameQuery.Shuffle();

                foreach (first_name qName in nameQuery)
                {
                    newFirst = qName;

                    if (newFirst.FirstID != tempFirst.FirstID)
                    {
                        this.FirstName = newFirst;
                        break;
                    }
                }
            }
        }
コード例 #2
0
ファイル: AName.cs プロジェクト: jdpoints/BabyNameGenerator
        public void RandomMiddle()
        {
            middle_name tempMiddle = new middle_name();

            if (this.MiddleName == null)
            {
                tempMiddle.MiddleID = -1;
            }
            else
            {
                tempMiddle = this.MiddleName;
            }

            middle_name newMiddle = new middle_name();

            using (var context = new NameGeneratorContext())
            {
                var nameQuery = context.middle_name
                                .Where(n => n.Active != false)
                                .ToList();

                nameQuery.Shuffle();

                foreach (middle_name qName in nameQuery)
                {
                    newMiddle = qName;

                    if (newMiddle.MiddleID != tempMiddle.MiddleID)
                    {
                        this.MiddleName = newMiddle;
                        break;
                    }
                }
            }
        }
コード例 #3
0
ファイル: AName.cs プロジェクト: jdpoints/BabyNameGenerator
        public static void RemoveMiddle(int RemID)
        {
            middle_name delMiddle;

            using (var context = new NameGeneratorContext())
            {
                delMiddle = context.middle_name.Where(n => n.MiddleID == RemID).First <middle_name>();

                if (delMiddle != null)
                {
                    delMiddle.Active = false;
                }

                context.SaveChanges();
            }
        }
コード例 #4
0
ファイル: AName.cs プロジェクト: jdpoints/BabyNameGenerator
        public static void RemoveFirst(int RemID)
        {
            first_name delFirst;

            using (var context = new NameGeneratorContext())
            {
                delFirst = context.first_name.Where(n => n.FirstID == RemID).First <first_name>();

                if (delFirst != null)
                {
                    delFirst.Active = false;
                }

                context.SaveChanges();
            }
        }
コード例 #5
0
ファイル: AName.cs プロジェクト: jdpoints/BabyNameGenerator
        public void NewFirst()
        {
            first_name tempFirst = new first_name();

            if (this.FirstName == null)
            {
                tempFirst.FirstID = -1;
            }
            else
            {
                tempFirst = this.FirstName;
            }

            first_name newFirst = new first_name();

            using (var context = new NameGeneratorContext())
            {
                var nameQuery = context.first_name
                                .Where(n => n.Active != false)
                                .ToList();

                nameQuery.Shuffle();

                foreach (first_name qName in nameQuery)
                {
                    newFirst = qName;

                    var fullQuery = context.full_name
                                    .Where(n => n.FirstID == newFirst.FirstID)
                                    .Where(n => n.MiddleID == this.MiddleName.MiddleID)
                                    .FirstOrDefault();

                    if (fullQuery == null &&
                        newFirst.FirstID != tempFirst.FirstID)
                    {
                        this.FirstName = newFirst;
                        break;
                    }
                }
            }

            if (this.FirstName.FirstID == tempFirst.FirstID)
            {
                System.Windows.Forms.MessageBox.Show("All valid combinations with the current middle name have been tried. Please select a new middle name");
                this.RandomMiddle();
            }
        }
コード例 #6
0
        private static List <ExportRow> CreateList()
        {
            List <ExportRow> tempList = new List <ExportRow>();

            using (var context = new NameGeneratorContext())
            {
                var query = context.full_name
                            .Where(n => n.Good == true)
                            .ToList();

                foreach (full_name name in query)
                {
                    bool active = name.middle_name.Active && name.first_name.Active;

                    var goodNames = context.full_name
                                    .Where(n => n.Good == true);

                    var badNames = context.full_name
                                   .Where(n => n.Good == false);

                    int winsFirst = goodNames
                                    .Where(n => n.FirstID == name.FirstID)
                                    .Count();

                    int winsMiddle = goodNames
                                     .Where(n => n.MiddleID == name.MiddleID)
                                     .Count();

                    int lossesFirst = badNames
                                      .Where(n => n.FirstID == name.FirstID)
                                      .Count();

                    int lossesMiddle = badNames
                                       .Where(n => n.MiddleID == name.MiddleID)
                                       .Count();

                    tempList.Add(new ExportRow(name.first_name.Name, name.middle_name.Name, name.Good, active, winsFirst + winsMiddle, lossesFirst + lossesMiddle));
                }
            }

            return(tempList);
        }
コード例 #7
0
        private void frmStatus_Load(object sender, EventArgs e)
        {
            using (var context = new NameGeneratorContext())
            {
                int activeFirst = context.first_name
                                  .Where(n => n.Active == true)
                                  .Count();

                int activeMiddle = context.middle_name
                                   .Where(n => n.Active == true)
                                   .Count();

                var activeNames = context.full_name
                                  .Where(n => n.middle_name.Active == true)
                                  .Where(n => n.first_name.Active == true);

                this.TriedNames = activeNames.Count();
                this.GoodNames  = activeNames
                                  .Where(n => n.Good == true)
                                  .Count();

                this.ValidNames = activeFirst * activeMiddle;

                if (this.GoodNames == 0 ||
                    this.TriedNames == 0)
                {
                    this.progbarNames.Value = 0;
                }
                else
                {
                    this.progbarNames.Value = Convert.ToInt32((this.TriedNames / this.ValidNames) * 100);
                }
            }

            this.txtValidNames.Text = this.ValidNames.ToString();
            this.txtTriedNames.Text = this.TriedNames.ToString();
            this.txtGoodNames.Text  = this.GoodNames.ToString();
        }
コード例 #8
0
ファイル: AName.cs プロジェクト: jdpoints/BabyNameGenerator
        public void WriteFull(bool IsGood)
        {
            full_name FullName = new full_name();

            FullName.FirstID = this.FirstName.FirstID;

            FullName.MiddleID = this.MiddleName.MiddleID;

            FullName.Good = IsGood;

            try
            {
                using (var context = new NameGeneratorContext())
                {
                    context.full_name.Add(FullName);
                    context.SaveChanges();
                }
            }
            catch
            {
                System.Windows.Forms.MessageBox.Show("This name has already been entered. Please try another name combination.");
            }
        }