public void ShowResult()
        {
            if (PreProcess.FinalFiles.Count == 0)
            {
                sw.Stop();
                elapsedTime      = sw.Elapsed;
                lblProgress.Text = "الوقت المستغرق بالثواني" + elapsedTime.TotalSeconds.ToString();
                lstResults.Items.Add("لاتوجد ملفات متشابهة");
                return;
            }
            for (int i = 0; i < PreProcess.FinalFiles.Count; i++)
            {
                for (int j = 0; j < PreProcess.FinalFiles.Count - 1; j++)
                {
                    if (PreProcess.FinalFiles[j].sl < PreProcess.FinalFiles[j + 1].sl)
                    {
                        file_con temp = PreProcess.FinalFiles[j + 1];
                        PreProcess.FinalFiles[j + 1] = PreProcess.FinalFiles[j];
                        PreProcess.FinalFiles[j]     = temp;
                    }
                }
            }
            for (int i = 0; i < PreProcess.FinalFiles.Count; i++)
            {
                string        s            = "";
                SqlConnection myconnection = new SqlConnection(DB.constr);
                SqlCommand    mycom        = new SqlCommand("SearchStudent", myconnection);
                myconnection.Open();
                mycom.CommandType = CommandType.StoredProcedure;
                mycom.Parameters.AddWithValue("@book_id", PreProcess.FinalFiles[i].id);

                SqlDataReader students;

                students = mycom.ExecuteReader();



                while (students.Read())
                {
                    s += " " + students["student_name"].ToString();
                }

                myconnection.Close();
                lstResults.Items.Add(" عنوان الأطروحة " + PreProcess.FinalFiles[i].name);
                lstResults.Items.Add("  للمؤلفين  " + "/" + s + "/" + "  تاريخ الإضافة " + "-" + "14/5/2012" + "-" + "\t بنسبة تشابه \t" + PreProcess.FinalFiles[i].sl + "%");
            }

            sw.Stop();
            elapsedTime      = sw.Elapsed;
            lblProgress.Text = "الوقت المستغرق بالثواني" + elapsedTime.TotalSeconds.ToString();

            /* for (int i = 0; i < PreProcess.ResFile.sim; i++)
             * {
             *   for (int j = i+1; j < PreProcess.ResFile.sim - 1; j++)
             *       if (PreProcess.ResFile.dim[j, 0] >= PreProcess.ResFile.dim[i, 0] && (PreProcess.ResFile.dim[j, 1] + PreProcess.ResFile.dim[j, 0]) <= (PreProcess.ResFile.dim[i, 0] + PreProcess.ResFile.dim[i, 1]))
             *               PreProcess.ResFile.dim[j, 1] = -1;
             *       else
             *           if (PreProcess.ResFile.dim[i, 0] >= PreProcess.ResFile.dim[j, 0] && PreProcess.ResFile.dim[i, 1] <= PreProcess.ResFile.dim[j, 1])
             *               PreProcess.ResFile.dim[i, 1] = -1;
             *
             *
             * }
             * int all=0;
             * for (int i = 0; i < PreProcess.ResFile.sim; i++)
             * {
             *   if   (PreProcess.ResFile.dim[i, 1]!=-1)
             *        all +=PreProcess.ResFile.dim[i, 1];
             * }
             * lstResults.Items.Add("نسبة المتشابه في الملف المدخل" + all * 100 / PreProcess.c_text.Length + "%" + "من الملف");*/
        }
        //-----------------------------------------------------------------------------------------------------------------------------------

        public void SearchSimilarity()
        {
            //get list from database
            while (ScanFilesReader.Read())
            {
                Log olf = new Log();
                olf.Deserialize((byte[])ScanFilesReader["log_file"]);
                MetaData meta = new MetaData(MetaWordsLimit);
                meta.Deserialize((byte[])ScanFilesReader["metadata"]);
                string DBtxt = ScanFilesReader["coded_file"].ToString();
                int    c     = 0;
                if (searchtype == "classfied")
                {
                    c = 1;
                }
                else
                {
                    foreach (string cur in fm)
                    {
                        foreach (string ext in meta.FinalMeta)
                        {
                            if (cur == ext)
                            {
                                c++; break;
                            }
                        }
                        if (c > 0)
                        {
                            break;
                        }
                    }
                }

                if ((c > 0))
                {
                    file_con f     = new file_con();
                    int      count = 0;
                    int      sl    = 0;



                    int readed_chars = 0;

                    int offset = 0;
                    while (offset < DBtxt.Length)
                    {
                        if (c_text == DBtxt)
                        {
                            count       = 1;
                            sl          = DBtxt.Length;
                            f.dim[0, 0] = 0;
                            f.dim[0, 1] = DBtxt.Length;
                            ResFile.dim[ResFile.sim, 0] = 0;
                            ResFile.dim[ResFile.sim, 1] = c_text.Length;
                            ResFile.sim++;
                            break;
                        }
                        // Cut a string
                        string comstr = "";
                        if (offset + ngram < DBtxt.Length)
                        {
                            comstr = DBtxt.Substring(offset, ngram);
                        }
                        else
                        {
                            comstr = DBtxt.Substring(offset, DBtxt.Length - offset);

                            if (comstr.Length < ngram)
                            {
                                break;
                            }
                        }
                        offset += ngram;

                        if (c_text.IndexOf(comstr) != -1)
                        {
                            // find it in the text
                            // before similraty
                            int    jj    = c_text.IndexOf(comstr);
                            int    gg    = DBtxt.IndexOf(comstr, readed_chars);
                            string mystr = "";
                            while ((jj > 0) && (gg > readed_chars))
                            {
                                if (c_text[jj - 1] == DBtxt[gg - 1])
                                {
                                    string ch = Convert.ToString(DBtxt[gg - 1]);
                                    mystr = mystr.Insert(0, ch);

                                    jj--;
                                    gg--;
                                }
                                else
                                {
                                    break;
                                }
                            }

                            comstr = comstr.Insert(0, mystr);

                            // after similraty
                            int j = c_text.IndexOf(comstr) + comstr.Length;
                            gg = DBtxt.IndexOf(comstr, readed_chars) + comstr.Length;
                            for (int g = gg; g < DBtxt.Length; g++)
                            {
                                if (j >= c_text.Length)
                                {
                                    break;
                                }
                                if (DBtxt[g] == c_text[j])
                                {
                                    offset++;
                                    comstr += DBtxt[g];
                                }
                                else
                                {
                                    break;
                                }
                                j++;
                            }
                            int startindex = DBtxt.IndexOf(comstr, readed_chars);
                            //  if (startindex != -1)
                            // {
                            int sellength = comstr.Length;
                            sl += sellength;
                            f.dim[count, 0] = startindex;
                            f.dim[count, 1] = sellength;
                            count++;
                            readed_chars = DBtxt.IndexOf(comstr, readed_chars) + comstr.Length;
                            ResFile.dim[ResFile.sim, 0] = c_text.IndexOf(comstr);
                            ResFile.dim[ResFile.sim, 1] = comstr.Length;

                            ResFile.sim++;
                            //  }
                            // else
                            // readed_chars = comstr.Length;
                        } // end if
                    }     // end while
                    if (count > 0)
                    {
                        f.text      = ScanFilesReader["File_txt"].ToString();
                        f.sim       = count;
                        f.sl        = sl;
                        f.codedfile = DBtxt;
                        f.id        = (int)ScanFilesReader["Book_id"];
                        f.name      = ScanFilesReader["Book_name"].ToString();
                        f.sl        = Math.Round((f.sl * 100) / f.codedfile.Length, 1);
                        for (int i = 0; i < f.sim; i++)
                        {
                            olf.DecodePosition(ref f.dim[i, 0], ref f.dim[i, 1]);
                        }

                        Files.Add(f);
                        sl = 0;
                    }
                } // end if
            }     //end while


            for (int j = 0; j < Files.Count; j++)
            {
                PreProcess.FinalFiles.Add(Files[j]);
            }
            // return files;
        }