Пример #1
0
        public int CompareTo(object o)//сортироовка объектов класса по полю fullName
        {
            Pers p = o as Pers;

            if (p != null)
            {
                return(this.FullNameToStr.CompareTo(p.FullNameToStr));
            }
            else
            {
                throw new Exception("Невозможно сравнить два объекта");
            }
        }
Пример #2
0
        public Pers[] GetPeople()
        {
            Pers[] persons = new Pers[getCount()];
            com = new SqlCommand();

            string[] FullName;
            FullName = new string[getCount()];



            for (int i = 0; i < getCount(); i++)
            {
                for (int j = 0; j < 2; j++)
                {
                    switch (j)
                    {
                    case 0:
                        com = new SqlCommand("Select FirsName From Account where id=@id", con);    //"Sergeyus", "Serg"
                        break;

                    case 1:
                        com = new SqlCommand("Select LastName From Account where id=@id", con);    //"Sergeyus", "Serg"
                        break;
                    }
                    com.Connection = con;
                    com.Parameters.AddWithValue("@id", i + 1);
                    //      com.Parameters.AddWithValue("@id", Key);//Key global tmp
                    con.Open();
                    SqlDataReader reader = com.ExecuteReader();
                    while (reader.Read())
                    {
                        switch (j)
                        {
                        case 0:
                            FullName[i]  = reader.GetString(0);
                            FullName[i] += " ";
                            break;

                        case 1:
                            FullName[i] += reader.GetString(0);
                            // FullName[i] += "\n";
                            persons[i] = new Pers(i + 1, FullName[i].Split(' ')[0], FullName[i].Split(' ')[1]);    //

                            break;
                        }
                    }
                    con.Close();
                }
            }
            return(persons);
        }
Пример #3
0
        public Pers[] StateOf(int ID, int Category)// 1-isWrite, 2-isFriend,3-in BlackList
        {
            string        isWriteField = "";
            string        IdField      = "";
            SqlDataReader reader;
            string        QueryString = "";
            int           size        = getCount();

            Pers[]      AllPeople = new Pers[size];
            List <Pers> Companion = new List <Pers>();

            com = new SqlCommand();

            string[] FullName;
            FullName = new string[size];

            for (int i = 0; i < size; i++)
            {
                for (int j = 0; j < 2; j++)
                {
                    switch (j)
                    {
                    case 0:
                        com = new SqlCommand("Select FirsName From Account where id=@id", con);    //"Sergeyus", "Serg"
                        break;

                    case 1:
                        com = new SqlCommand("Select LastName From Account where id=@id", con);    //"Sergeyus", "Serg"
                        break;
                    }
                    com.Connection = con;
                    com.Parameters.AddWithValue("@id", i + 1);

                    //      com.Parameters.AddWithValue("@id", Key);//Key global tmp
                    con.Open();
                    reader = com.ExecuteReader();
                    while (reader.Read())
                    {
                        switch (j)
                        {
                        case 0:
                            FullName[i]  = reader.GetString(0);
                            FullName[i] += " ";
                            break;

                        case 1:
                            FullName[i] += reader.GetString(0);
                            // FullName[i] += "\n";
                            AllPeople[i] = new Pers(i + 1, FullName[i].Split(' ')[0], FullName[i].Split(' ')[1]);    //

                            break;
                        }
                    }
                    con.Close();
                }
            }

            com = new SqlCommand(@"Select idOfPers from Relations where idOfOwner=@id", con);
            con.Open();
            com.Parameters.AddWithValue("@id", ID);
            reader = com.ExecuteReader();
            while (reader.Read())
            {
                IdField = reader.GetString(0);
            }
            con.Close();
            switch (Category)
            {
            case 1:
                QueryString = @"Select isWrite from Relations where idOfOwner=@id";
                break;

            case 2:
                QueryString = @"Select isfriend from Relations where idOfOwner=@id";
                break;

            case 3:
                QueryString = @"Select isblackList from Relations where idOfOwner=@id";
                break;
            }



            //
            com = new SqlCommand(QueryString, con);
            con.Open();
            com.Parameters.AddWithValue("@id", ID);
            reader = com.ExecuteReader();
            while (reader.Read())
            {
                isWriteField = reader.GetString(0);
            }
            con.Close();



            int[]      IF        = new int[size];
            int[]      CF        = new int[size];
            List <int> FriendsId = new List <int>();

            for (int i = 0; i < size - 1; i++)
            {
                IF[i] = Convert.ToInt32(IdField.Split(' ')[i]);
                CF[i] = Convert.ToInt32(isWriteField.Split(' ')[i]);
                if (CF[i] == 1)
                {
                    FriendsId.Add(IF[i]);
                }
            }

            for (int i = 0; i < FriendsId.Count; i++)
            {
                Companion.Add(AllPeople[FriendsId[i] - 1]);
            }
            //FriendsData
            return(Companion.ToArray());
        }