Exemplo n.º 1
0
        public static List <MetersList> findMeters()
        {
            List <string>   finalList  = new List <string>();
            List <string>   cleanList  = new List <string>();
            List <string>   metersList = new List <string>();
            MySqlConnection myConn;
            MySqlDataReader dataReader;

            myConn = new MySqlConnection(TaqtiController.connectionString);
            myConn.Open();
            MySqlCommand cmd = new MySqlCommand(TaqtiController.connectionString);

            cmd             = myConn.CreateCommand();
            cmd.CommandText = "select meterID from Poetry;";
            dataReader      = cmd.ExecuteReader();
            while (dataReader.Read())
            {
                metersList.Add(dataReader.GetString(0));
            }
            myConn.Close();

            foreach (var meter in metersList)
            {
                char[] delimiters = new[] { ',', '،' };  // List of delimiters
                var    subStrings = meter.Split(delimiters, StringSplitOptions.RemoveEmptyEntries);
                foreach (var t in subStrings)
                {
                    cleanList.Add(t);
                    if (finalList.Count == 0)
                    {
                        finalList.Add(t);
                    }
                    bool flag = true;
                    foreach (var m in finalList)
                    {
                        if (m.Equals(t.Trim()))
                        {
                            flag = false;
                            break;
                        }
                    }
                    if (flag)
                    {
                        finalList.Add(t.Trim());
                    }
                }
            }

            string[] meterNames = new string[finalList.Count()];
            for (int i = 0; i < finalList.Count; i++)
            {
                meterNames[i] = finalList[i];
            }

            Array.Sort(meterNames);
            finalList.Clear();
            foreach (var m in meterNames)
            {
                finalList.Add(m);
            }

            List <MetersList> list = new List <MetersList>();

            foreach (var m in finalList)
            {
                int count = 0;
                foreach (var t in cleanList)
                {
                    if (t.Equals(m))
                    {
                        count++;
                    }
                }
                MetersList ml = new MetersList();
                ml.name  = m;
                ml.count = count;
                list.Add(ml);
            }
            return(list);
        }
Exemplo n.º 2
0
        public static List<MetersList> findMeters()
        {
            List<string> finalList = new List<string>();
            List<string> cleanList = new List<string>();
            List<string> metersList = new List<string>();
            MySqlConnection myConn;
            MySqlDataReader dataReader;
            myConn = new MySqlConnection(TaqtiController.connectionString);
            myConn.Open();
            MySqlCommand cmd = new MySqlCommand(TaqtiController.connectionString);
            cmd = myConn.CreateCommand();
            cmd.CommandText = "select meterID from Poetry;";
            dataReader = cmd.ExecuteReader();
            while (dataReader.Read())
            {
                metersList.Add(dataReader.GetString(0));
            }
            myConn.Close();

            foreach (var meter in metersList)
            {
                char[] delimiters = new[] { ',', '،' };  // List of delimiters
                var subStrings = meter.Split(delimiters, StringSplitOptions.RemoveEmptyEntries);
                foreach (var t in subStrings)
                {
                    cleanList.Add(t);
                    if (finalList.Count == 0)
                    {
                        finalList.Add(t);
                    }
                    bool flag = true;
                    foreach (var m in finalList)
                    {
                        if (m.Equals(t.Trim()))
                        {
                            flag = false;
                            break;
                        }
                    }
                    if (flag)
                    {
                        finalList.Add(t.Trim());
                    }
                }
            }

            string[] meterNames = new string[finalList.Count()];
            for (int i = 0; i < finalList.Count; i++)
            {
                meterNames[i] = finalList[i];
            }

            Array.Sort(meterNames);
            finalList.Clear();
            foreach (var m in meterNames)
            {
                finalList.Add(m);
            }

            List<MetersList> list = new List<MetersList>();
            foreach(var m in finalList)
            {
                int count = 0; 
                foreach(var t in cleanList)
                {
                    if(t.Equals(m))
                    {
                        count++;
                    }
                }
                MetersList ml = new MetersList();
                ml.name = m;
                ml.count = count;
                list.Add(ml);
            }
            return list;
        }