Esempio n. 1
0
        private void search(HashSet <string> tagHash, HashSet <string> wordHash, SqlConnection con)
        {
            int index;

            hashSet = new HashSet <long>();

            if (wordHash.Count != 0)
            {
                index = 0;
                using (SqlCommand command = new SqlCommand("SELECT ID, DisplayName, ProductPrice FROM [dbo].[Product] WHERE", con))
                {
                    foreach (var item in wordHash)
                    {
                        if (index == 0)
                        {
                            command.CommandText += " [DisplayName] LIKE @Name" + index;
                        }
                        else
                        {
                            command.CommandText += " OR [DisplayName] LIKE @Name" + index;
                        }
                        command.Parameters.AddWithValue("Name" + index, "%" + item + "%");
                        index++;
                    }

                    command.Connection.Open();

                    using (SqlDataReader sqlr = command.ExecuteReader())
                    {
                        while (sqlr.Read())
                        {
                            SerchResult r = new SerchResult(sqlr);
                            hashSet.Add(r.id);
                            SerchResultsList.Add(r);
                        }
                    }
                }
            }

            if (tagHash.Count != 0)
            {
                index = 0;
                using (SqlCommand command = new SqlCommand(
                           "SELECT j3.ID, j3.DisplayName, j3.ProductPrice FROM [dbo].[TagTyp] AS j1 " +
                           "RIGHT OUTER JOIN [dbo].[Product_has_TagTyp] AS j2 ON j1.[ID] = j2.[TagTyp_ID] " +
                           "RIGHT OUTER JOIN [dbo].[Product] AS j3 ON j2.[Product_ID] = j3.[ID] " +
                           "WHERE ", con))
                {
                    foreach (var item in tagHash)
                    {
                        if (index == 0)
                        {
                            command.CommandText += " j1.[DisplayName] LIKE @tag" + index;
                        }
                        else
                        {
                            command.CommandText += " OR j1.[DisplayName] LIKE @tag" + index;
                        }
                        command.Parameters.AddWithValue("tag" + index, "%" + item + "%");
                        index++;
                    }

                    if (command.Connection.State != ConnectionState.Open)
                    {
                        command.Connection.Open();
                    }

                    using (SqlDataReader sqlr = command.ExecuteReader())
                    {
                        while (sqlr.Read())
                        {
                            SerchResult r = new SerchResult(sqlr);
                            if (hashSet.Add(r.id))
                            {
                                SerchResultsList.Add(r);
                            }
                        }
                    }
                }
                hashSet = null;
            }
        }
Esempio n. 2
0
        public override bool Equals(object obj)
        {
            SerchResult r = (SerchResult)obj;

            return(r.id == id);
        }