예제 #1
0
        public void sort(TcpClient tcpClient)
        {
            Posts    post = new Posts(tcpClient);
            SQLclass sql  = new SQLclass();

            List <string> str2  = sql.getLoginsAndId();
            List <string> ready = new List <string>();
            List <string> name  = new List <string>();
            int           i     = 0;

            while (i != str2.Count())
            {
                string[] words = str2[i].Split('|');
                name.Add(words[1]);
                i++;
            }
            string mes;

            name.Sort();
            Thread.Sleep(50);
            post.sendMes(str2.Count().ToString());
            Thread.Sleep(40);
            post.sendMes("|id|Логин                    |Пароль                   |ФИО                      |Зарплата                 |Должность                |Телефон                  |\n");
            for (i = 0; i < str2.Count(); i++)
            {
                Thread.Sleep(40);
                mes = sql.getInfoUserWhereLogin(name[i]) + "|" + sql.getInfoUser(sql.getInfoUserWhereLogin(name[i]))[0];
                ready.Add(mes);
                post.sendMes(this.makeTable(ready, 1)[0] + "\n");
                ready.Clear();
            }
        }
예제 #2
0
        public List <string> serchForm()
        {
            List <List <string> > arr = new List <List <string> >();
            List <string>         str = new List <string>();

            List <List <string> > arr1 = new List <List <string> >();
            List <string>         str1 = new List <string>();

            str = objSQL.getLoginsAndId();
            int size = objSQL.returnSizeBD();

            int i = 0, j = 0, k = 0, bilLiSovpod = 0, maxSchet = 0;

            int[] schet = new int[size];

            for (i = 0; i < size; i++)
            {
                schet[i] = 0;
                str[i]  += '\n';
                while (true)
                {
                    if (str[i][j] == '\n')
                    {
                        if (maxSchet < schet[i])
                        {
                            maxSchet = schet[i];
                        }

                        j = 0; break;
                    }

                    if (str[i][j] >= 'А' && str[i][j] <= 'я')
                    {
                        if (str[i][j] == message[k] || str[i][j] == message[k] - 32 || str[i][j] == message[k] + 32)
                        {
                            schet[i]++;
                            k++;
                            bilLiSovpod = 1;
                        }
                        else
                        if (maxSchet < schet[i])
                        {
                            maxSchet = schet[i];
                            schet[i] = 0;

                            k = 0;
                        }
                    }
                    else
                    if (str[i][j] >= 'A' && str[i][j] <= 'Z' || str[i][j] >= 'a' && str[i][j] <= 'z')
                    {
                        if (str[i][j] >= 'a' && str[i][j] <= 'z')
                        {
                            if (str[i][j] == message[k] || str[i][j] - 32 == message[k])
                            {
                                schet[i]++;
                                k++;
                                bilLiSovpod = 1;
                            }
                            else
                            if (maxSchet < schet[i])
                            {
                                maxSchet = schet[i];
                                schet[i] = 0;

                                k = 0;
                            }
                        }
                        else
                        if (str[i][j] == message[k] || str[i][j] + 32 == message[k])
                        {
                            schet[i]++;
                            k++;
                            bilLiSovpod = 1;
                        }
                        else
                        if (maxSchet < schet[i])
                        {
                            maxSchet = schet[i];
                            schet[i] = 0;

                            k = 0;
                        }
                    }
                    else
                    if (str[i][j] >= '0' && str[i][j] <= '9')
                    {
                        if (str[i][j] == message[k])
                        {
                            schet[i]++;
                            k++;
                            bilLiSovpod = 1;
                        }
                        else
                        if (maxSchet < schet[i])
                        {
                            maxSchet = schet[i];
                            schet[i] = 0;

                            k = 0;
                        }
                    }

                    j++;
                }

                schet[i] = maxSchet;
                maxSchet = 0;
                k        = 0;
            }

            if (bilLiSovpod == 0)
            {
                str1.Add("Не было ни одного совпадения");
                return(str1);
            }
            else
            {
                maxSchet = 0;

                for (i = 0; i < size; i++)
                {
                    if (schet[i] > maxSchet)
                    {
                        maxSchet = schet[i];
                    }
                }
                k = 0;
                int[] mas = new int[size];
                for (i = 0; i < size; i++)
                {
                    if (schet[i] == 0)
                    {
                        continue;
                    }
                    if (schet[i] == maxSchet || schet[i] == maxSchet - 1)
                    {
                        str1.Add(str[i]);

                        k++;
                    }
                    else
                    {
                        mas[i] = 0;
                    }
                }
                i = 0;
                int size2 = k;
                k++;
                post.sendMes(k.ToString());
                k = 0;
                List <string> id = new List <string>();
                while (true)
                {
                    if (k == size2)
                    {
                        break;
                    }
                    string[] words = str1[k].ToString().Split('|');
                    id.Add(words[0]);
                    str      = objSQL.getInfoUser(id[k].ToString());
                    str1[k]  = id[k] + "|";
                    str1[k] += str[0];
                    k++;
                    i++;
                }

                return(str1);
            }
        }