static void Main(string[] args)
            {
                PersonList obj = new PersonList();
                obj.Add("Aliona");
                obj.Add("Anna");
                Console.WriteLine(obj.ToString());

                obj.Update(MyWork);
                Console.WriteLine(obj.ToString());

                Console.ReadKey();
            }
Exemple #2
0
        private void OnGetAllFromDB()
        {
            if (!PersonList.Count.Equals(0))
            {
                if (MessageBox.Show("All changes will be lost - do you want to proceed?", "Question",
                                    MessageBoxButton.YesNo,
                                    MessageBoxImage.Warning) == MessageBoxResult.Yes)
                {
                    PersonList.Clear();
                }
                else
                {
                    return;
                }
            }

            _repository = new PeopleRepository(BuildConnectionString(DataSourceConnString, InitialDirectioryConnString, IntegratedSecurityConnString));
            if (_repository == null ? IsEnabled_SaveToDatabase = false : IsEnabled_SaveToDatabase = true)
            {
                var peopleRepository = _repository.GetAll();
                foreach (var person in peopleRepository)
                {
                    var personBelongins = _repository.GetThingsOwnedOfPerson(person.ID);

                    person.ThingsOwned = personBelongins;
                    PersonList.Add(person);
                }
                IsEnabled_UpdatePersonInDatabase = true;
                IsEnabled_RemovePersonInDatabase = true;
                DatabaseConnected = true;
            }
        }
Exemple #3
0
        /// <summary>
        /// Точка вхождения.
        /// </summary>
        /// <param name="args">Аргументы</param>
        static void Main(string[] args)
        {
            Console.Write("Генерируем 7 человек:\n");

            var persons = new PersonList();

            for (int i = 0; i < 7; i++)
            {
                persons.Add(RandomPerson.GetRandomAdultOrChild());
                Console.WriteLine(persons[i].Info);
                Console.WriteLine();
            }

            Console.Write("Четвертый человек в списке - это ");

            //TODO: pattern-matching +
            if (persons[3] is Adult)
            {
                Console.WriteLine("взрослый человек.");
                var person = (Adult)persons[3];
                Console.WriteLine(person.GoToNightclub(person));
            }
            else if (persons[3] is Child)
            {
                Console.WriteLine("ребенок.");
                var person = (Child)persons[3];
                Console.WriteLine(person.GoToNightclub(person));
            }

            Console.ReadKey();
        }
Exemple #4
0
        // Rulet Tekerleği => Uygunluk Değerlerine Göre işlem Yapılır. İlk olarak bütün bireylerin uygunluk değerler toplanır.
        // Bireyin Uygunluk değerli / Toplam uygunluk değerleri toplamı oranlanır, her bir birey için oran belirlenir
        // Bu oranlar en küçükten başlayarak sırasıyla yüzdelik dilime pay edilir.
        // Örn: x1 = 6/359 = 3.67 ,x2 =  25/359 = 62.67 ... bu şekilde ortaya çıkan oranlara göre doldurulur.
        // Rulet Tekerleği Hazırlandıktan sonra populasyon yeniden oluşturulur.
        // Populasyon Sayısı kadar random değer üretiriz bu değerler 0-100 arasında olur.
        // Random değerin isabe ettiği dairenin kısmına karışık gelen birey , yeni populasyona eklenir.
        // Örn: RandomSay = 75 olsun bu değer yüzdelik kısmında x2 bireyine dekkeliyor çünkü yüzde 60'lık kısmı karışılıyor(küçüklerden başlayarak daireye eklendiği için)
        // Bu şekilde yeni populasyon oluşturulur

        private void RouletteWheelMethod()
        {
            // Yüzdelik oranın kurulması için bireylerin uygunluk değerlerini topladık
            double total = PersonList.Sum(s => s.AccordanceValue);

            // Her birey için yüzdelik kısım hesaplancak
            // Oranlar RateByTotalAccordanceValues propuna yazılır
            PersonList.ForEach(person => person.RateByTotalAccordanceValues = (person.AccordanceValue / total));// Uygunluk Değeri / Toplam

            // Yeniden Populasyon Oluşturulacak , o yüzden ilk önce populasyon temizlenir
            // Oranları Belirledikten sonra Populasyondaki birey sayısı kadar random değer üretilip 1-100 arasında
            // Rulet Tekerleğindeki , Üretilen random değere karşılık gelen birey populasyona eklenir
            List <Person> temp = new List <Person>();

            temp.AddRange(PersonList);
            temp = temp.OrderByDescending(s => s.RateByTotalAccordanceValues).ToList(); // Orana Göre Sıraladık Çünkü Rulet Tekerleğine Bu Şekilde yerleştireceğiz

            PersonList.Clear();

            for (int i = 0; i < PopulationCount; i++)
            {
                Person newPerson   = new Person();
                double randomValue = rn.NextDouble();// 0-1 arasında random değer oluşturuldu, rulet tekerleğide 0-1 arasında

                // Random değerin işaret ettiği birey bulunarak yeni populasyona eklenir
                newPerson.Value = PersonForRouletteWheelPoint(randomValue, temp);

                PersonList.Add(newPerson);  // Bireyi populasyona Ekledik
            }

            this.PurposeFunction(); // Uygunluk değerleri yeni bireylere göre güncellendi
        }
Exemple #5
0
        public static void GenerateCitizens(int a) //Skapar x-antal medborgare med Readline, slumpar startpositioner, Lägger till i listan Person
        {
            for (int i = 0; i < a; i++)            //slumpa startpositioner
            {
                Random r = new Random();
                int    x = r.Next(0, 100);

                Random r1 = new Random();
                int    y  = r1.Next(0, 25);

                Random r2 = new Random();
                int    z  = r2.Next(1, 9);
                //Inventory.Add(new Belongings("Phone"));
                //Inventory.Add(new Belongings("Keys"));
                //Inventory.Add(new Belongings("Wallet"));
                //Inventory.Add(new Belongings("Money"));

                List <Belongings> Inventory = new List <Belongings>();
                Inventory.Add(new Belongings("telefon"));
                Inventory.Add(new Belongings("Nycklar"));
                Inventory.Add(new Belongings("Plånbok"));
                Inventory.Add(new Belongings("pengar"));


                PersonList.Add(new Citizen(x, y, z, "M", Inventory));
            }
        }
Exemple #6
0
 private void 设置位置ToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if ((this.Persons != null) && (this.Persons.Count != 0))
     {
         PersonList list = new PersonList();
         for (int i = 0; i < this.dgvPersons.SelectedRows.Count; i++)
         {
             list.Add(this.dgvPersons.SelectedRows[i].DataBoundItem as Person);
         }
         frmSelectArchitectureList list2 = new frmSelectArchitectureList();
         list2.Architectures = this.Persons[0].Scenario.Architectures;
         list2.SelectOne     = true;
         list2.ShowDialog();
         if (list2.IDList.Count > 0)
         {
             this.lastArchitecture = this.Persons[0].Scenario.Architectures.GetGameObject(list2.IDList[0]) as Architecture;
             this.menuRecentLocation.DropDownItems.Add(this.lastArchitecture.Name, null, new EventHandler(this.RecentLocationToolStripMenuItem_Click)).Tag = this.lastArchitecture;
             if (this.menuRecentLocation.DropDownItems.Count > 10)
             {
                 this.menuRecentLocation.DropDownItems.RemoveAt(0);
             }
             foreach (Person person in list)
             {
                 this.ApplyLastArchitecture(person);
             }
             this.dgvPersons.Invalidate();
         }
     }
 }
Exemple #7
0
 public void AddPeople(IPerson person)
 {
     if (PersonList.Contains(person))
     {
         throw new InvalidOperationException();
     }
     PersonList.Add(person);
 }
Exemple #8
0
 private PersonList GetPersons(Boolean refresh)
 {
     if (_persons.IsNull() || refresh)
     {
         _persons = new PersonList();
         _persons.Add(PersonTest.GetOnePerson(GetUserContext()));
     }
     return(_persons);
 }
Exemple #9
0
        public async Task FillPersonModel()
        {
            var listEnumerable = await PersonDao.Instance.GetAllPeopleAsync();

            foreach (var pPerson in listEnumerable)
            {
                PersonList.Add(pPerson);
            }
        }
Exemple #10
0
        public void AddPerson()
        {
            int newId = 1;

            if (PersonList.Count > 0)
            {
                newId = PersonList.Max(x => x.PersonId) + 1;
            }

            PersonList.Add(DataAccess.GetPerson(newId));
        }
 private void AddViewToList(PersonView pview, ref PersonList list)
 {
     // Map PersonView to Person and add to PersonList
      list.Add(new Person()
      {
         Id = pview.Id,
         FirstName = pview.FirstName.Trim(),
         LastName = pview.LastName.Trim(),
         Email = pview.Email.Trim()
      });
 }
Exemple #12
0
        private void CreateCommand_Execute()
        {
            if (PersonList == null)
            {
                return;
            }

            PersonList.Add(new Person {
                FirstName = "newFirstN", LastName = "newLastN", Age = 22
            });
        }
Exemple #13
0
 /// <summary>
 /// Erzeugt eine einzelne Person
 /// </summary>
 public void CreateNewPerson()
 {
     if (!string.IsNullOrEmpty(PersonInputViewModel.BirthDay))
     {
         PersonList.Add(personalManager.CreateNewPerson(PersonInputViewModel.FirstName, PersonInputViewModel.LastName, DateTime.Parse(PersonInputViewModel.BirthDay), personInputViewModel.HairColor));
     }
     else
     {
         DateTime?birthDayNull = null;
         PersonList.Add(personalManager.CreateNewPerson(PersonInputViewModel.FirstName, PersonInputViewModel.LastName, birthDayNull, PersonInputViewModel.HairColor));
     }
 }
Exemple #14
0
 public ActionResult Create(PersonLocal NewPerson)
 {
     try
     {
         PersonList.Add(NewPerson);
         return(RedirectToAction("Index"));
     }
     catch
     {
         return(View());
     }
 }
        public TestCollections(int count)
        {
            Console.WriteLine($"\t\t\tCollection has {count} elements\n");

            for (int i = 1; i <= count; i++)
            {
                Man man = GenerateElement(i);
                PersonList.Add(new Person($"PersonList {i},", $"PersonList {i}", DateTime.Today));
                StringList.Add($"String {i}");
                PersonManDictionary.Add(new Person($"\nPersonManDictionary {i},", $"PersonManDictionary {i}", DateTime.Today), man);
                StringManDictionary.Add($"\nStringManDictionary {i}", man);
            }
        }
Exemple #16
0
        private async void TraerDatos()
        {
            HttpClient client   = new HttpClient();
            var        response = await client.GetStringAsync("http://restapicem.somee.com/api/usuarios");

            List <Usuario> datos = JsonConvert.DeserializeObject <List <Usuario> >(response);

            string[] nombres = new string[datos.Count];
            for (int i = 0; i < nombres.Length; i++)
            {
                PersonList.Add(datos[i]);
            }
        }
Exemple #17
0
        public void AddSpouse(TreeChartPerson spouse)
        {
            if (spouse == null)
            {
                return;
            }

            if (fSpouses == null)
            {
                fSpouses = new PersonList(false);
            }

            fSpouses.Add(spouse);
        }
Exemple #18
0
        public void AddChild(TreeChartPerson child)
        {
            if (child == null)
            {
                return;
            }

            if (fChilds == null)
            {
                fChilds = new PersonList(false);
            }

            fChilds.Add(child);
        }
Exemple #19
0
        //TODO: Сделать сохранение дня рождения
        public void Save()
        {
            int id;

            int.TryParse(_provider.Insert("SF_Person", ID, LastName, NumberSF, FirstName, SecondName, Appeal, (Position == null) ? 0 : Position.ID,
                                          (MainSpecPerson == null) ? 0 : MainSpecPerson.ID, (AcademTitle == null) ? 0 : AcademTitle.ID,
                                          Email, Mobile, Phone, Comment, (Organization == null) ? 0 : Organization.ID, Deleted.ToString(), CrmID), out id);

            ID = id;

            PersonList personList = GetPersonList();

            personList.Add(this);
        }
Exemple #20
0
        public static void GeneratePolices(int a) //Skapar x-antal medborgare med Readline, slumpar startpositioner, Lägger till i listan Person
        {
            for (int i = 0; i < a; i++)           //slumpa startpositioner
            {
                Random            r         = new Random();
                int               x         = r.Next(0, 100);
                Random            r1        = new Random();
                int               y         = r1.Next(0, 25);
                Random            r2        = new Random();
                int               z         = r2.Next(1, 9);
                List <Belongings> Inventory = new List <Belongings>();

                PersonList.Add(new Police(x, y, z, "P", Inventory));
            }
        }
        private void PersonChanged(object obj)
        {
            Person person = (Person)obj;

            int index = PersonList.IndexOf(person);

            if (index != -1)
            {
                PersonList.RemoveAt(index);
                PersonList.Insert(index, person);
            }
            else
            {
                PersonList.Add(person);
            }
        }
Exemple #22
0
        public void SquareBracketOperator()
        {
            PersonList newPersonList, oldPersonList;
            Int32      personIndex;

            oldPersonList = GetPersons(true);
            newPersonList = new PersonList();
            for (personIndex = 0; personIndex < oldPersonList.Count; personIndex++)
            {
                newPersonList.Add(oldPersonList[oldPersonList.Count - personIndex - 1]);
            }
            for (personIndex = 0; personIndex < oldPersonList.Count; personIndex++)
            {
                Assert.AreEqual(newPersonList[personIndex], oldPersonList[oldPersonList.Count - personIndex - 1]);
            }
        }
        internal static bool Insert(Person newPerson)
        {
            if (PersonList.Any(x => x.Fullname == newPerson.Fullname))
            {
                return(false);
            }
            else
            {
                DatabaseService dbService = new DatabaseService();

                PersonList.Add(newPerson);
                dbService.Insert(newPerson);

                return(true);
            }
        }
Exemple #24
0
 private void 设置为前一个位置ToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (((this.Persons != null) && (this.Persons.Count != 0)) && (this.lastArchitecture != null))
     {
         PersonList list = new PersonList();
         for (int i = 0; i < this.dgvPersons.SelectedRows.Count; i++)
         {
             list.Add(this.dgvPersons.SelectedRows[i].DataBoundItem as Person);
         }
         foreach (Person person in list)
         {
             this.ApplyLastArchitecture(person);
         }
         this.dgvPersons.Invalidate();
     }
 }
        public void LoadData()
        {
            XmlSerializer xs = new XmlSerializer(typeof(ObservableCollection <Person>));

            using (StreamReader rd = new StreamReader(Path))
            {
                ObservableCollection <Person> temp = xs.Deserialize(rd) as ObservableCollection <Person>;

                PersonList.Clear();

                foreach (Person person in temp)
                {
                    PersonList.Add(person);
                }
            }
            IsChanged = false;
        }
    static void Main()
    {
        var persons = new PersonList();

        for (int i = 0; i < 100000; i++)
        {
            persons.Add(new Person("P" + i.ToString(), RandomString(5, true)));
        }

        var unsortedPersons = new PersonList(persons);

        const int COUNT = 30;
        Stopwatch watch = new Stopwatch();

        for (int i = 0; i < COUNT; i++)
        {
            watch.Start();
            Sort(persons);
            watch.Stop();
            persons.Clear();
            persons.AddRange(unsortedPersons);
        }
        Console.WriteLine("Sort: {0}ms", watch.ElapsedMilliseconds);

        watch = new Stopwatch();
        for (int i = 0; i < COUNT; i++)
        {
            watch.Start();
            OrderBy(persons);
            watch.Stop();
            persons.Clear();
            persons.AddRange(unsortedPersons);
        }
        Console.WriteLine("OrderBy: {0}ms", watch.ElapsedMilliseconds);

        watch = new Stopwatch();
        for (int i = 0; i < COUNT; i++)
        {
            watch.Start();
            OrderByWithToList(persons);
            watch.Stop();
            persons.Clear();
            persons.AddRange(unsortedPersons);
        }
        Console.WriteLine("OrderByWithToList: {0}ms", watch.ElapsedMilliseconds);
    }
Exemple #27
0
        private void RefreshPersonListMethod()
        {
            try
            {
                PersonList.Clear();

                foreach (skPerson P in skPerson.GetPersonList())
                {
                    PersonList.Add(P);
                }
            }
            catch (Exception E)
            {
                ExepionLogger.Logger.LogException(E);
                ExepionLogger.Logger.Show(E);
            }
        }
Exemple #28
0
        private void Read_From_DataBase()
        {
            // read Users table
            using (SQLiteConnection conn = new SQLiteConnection(config.DataSource))
            {
                using (SQLiteCommand cmd = new SQLiteCommand())
                {
                    conn.Open();
                    cmd.Connection = conn;

                    SQLiteHelper sqlite = new SQLiteHelper(cmd);

                    DataTable personTable = new DataTable();
                    personTable.Columns.Add(new DataColumn {
                        ColumnName = "ID", DataType = typeof(Int32)
                    });
                    personTable.Columns.Add(new DataColumn {
                        ColumnName = "FirstName", DataType = typeof(String)
                    });
                    personTable.Columns.Add(new DataColumn {
                        ColumnName = "LastName", DataType = typeof(String)
                    });
                    personTable.Columns.Add(new DataColumn {
                        ColumnName = "Age", DataType = typeof(Int32)
                    });

                    string cmd_get_table = "SELECT * FROM " + config.TableName_Users;

                    personTable = sqlite.Select(cmd_get_table);


                    foreach (DataRow row in personTable.Rows)
                    {
                        Person person = new Person();
                        person.FirstName = row.Field <string>("FirstName");
                        person.LastName  = row.Field <string>("LastName");
                        person.Age       = Convert.ToInt32(row.Field <Int64>("Age"));
                        PersonList.Add(person);
                    }

                    conn.Close();
                }
            }
        }
 public ShellViewModel()
 {
     PersonList.Add(new PersonModel()
     {
         FirstName = string.Empty, LastName = string.Empty
     });
     PersonList.Add(new PersonModel()
     {
         FirstName = "Naruto", LastName = "Uzumaki"
     });
     PersonList.Add(new PersonModel()
     {
         FirstName = "Sasuke", LastName = "Uchiha"
     });
     PersonList.Add(new PersonModel()
     {
         FirstName = "Sakura", LastName = "Haruno"
     });
 }
Exemple #30
0
        public bool InsertPerson(PersonModel iList)
        {
            var PersonFile = PersonDBHandler.PersonFile;
            var PeopleData = System.IO.File.ReadAllText(PersonFile);
            List <PersonModel> PersonList = new List <PersonModel>();

            PersonList = JsonConvert.DeserializeObject <List <PersonModel> >(PeopleData);

            if (PersonList == null)
            {
                PersonList = new List <PersonModel>();
            }

            PersonList.Add(iList);

            System.IO.File.WriteAllText(PersonFile, JsonConvert.SerializeObject(PersonList));

            return(true);
        }
Exemple #31
0
 private void EditPersons()
 {
     if ((this.Persons != null) && (this.Persons.Count != 0))
     {
         PersonList list = new PersonList();
         for (int i = 0; i < this.dgvPersons.SelectedRows.Count; i++)
         {
             list.Add(this.dgvPersons.SelectedRows[i].DataBoundItem as Person);
         }
         frmEditPerson person = new frmEditPerson();
         person.Owner    = this;
         person.MainForm = this.MainForm;
         person.Persons  = list;
         person.SetTabIndex(this.EditPersonTabIndex);
         person.AllPersons = this.Persons;
         person.ShowDialog();
         this.dgvPersons.Invalidate();
     }
 }
Exemple #32
0
        // Populasyon oluşturma => En büyük ve En küçük değerlere göre random bireyleri oluşturup "PersonList" Listesine ekler
        // İlk Jenarasyon ise "PopulationCount" kadar birey oluşturulur, ilk jenarasyon değil ise "PopulationCount" - "ExclusivenessCount" kadar birey oluşturulur ve
        // Populasyona seçkin bireyleri yani  "ExclusivenessPersonList" listesine ekleyerek "Elitizm" uygulanır
        private void CreatePopulation()
        {
            int Lenght = PopulationCount;

            PersonList.Clear();                                // Yeni Populasyon oluşturacağımız için eskiyi temizliyoruz

            if (ExclusivenessPersonList.Any())                 // Eğer ilk jenerasyon değil ise seçkin bireyleri , yeni populasyona ekliyoruz
            {
                Lenght = PopulationCount - ExclusivenessCount; // Seçkinleri eklediğimiz için , sayıyı azaltıyoruz
                PersonList.AddRange(ExclusivenessPersonList);
            }
            // Populasyonu Oluşturma
            for (int i = 0; i < Lenght; i++)
            {
                Person newPerson = new Person();
                newPerson.Value = rn.Next(MinValueForPerson, MaxValueForPerson); // Min-Max ' a göre random bir birey oluşturuldu

                PersonList.Add(newPerson);                                       // Bireyi populasyona Ekledik
            }
        }