FormLevin.cs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Data.SqlClient;
  6. using System.Drawing;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Windows.Forms;
  11. namespace СУБД_Фабрика
  12. {
  13. public partial class FormLevin : Form
  14. {
  15. public FormLevin()
  16. {
  17. InitializeComponent();
  18. }
  19. SqlConnection Con = new SqlConnection(FormMain.txtCon);
  20. List<string> LstTitle = new List<string>();
  21. static int Levenshtein(string text1, string text2)
  22. {
  23. int CntLev = Math.Abs(text1.Length - text2.Length);
  24. for (int i = 0; i <= Math.Min(text1.Length, text2.Length) - 1; i++)
  25. {
  26. if (text1[i] != text2[i])
  27. CntLev++;
  28. }
  29. return CntLev;
  30. }
  31. private void FormLevin_Load(object sender, EventArgs e)
  32. {
  33. string txtQuery = "select Title from Cloth";
  34. Con.Open();
  35. SqlCommand query = new SqlCommand(txtQuery, Con);
  36. SqlDataReader Res = query.ExecuteReader();
  37. while(Res.Read())
  38. {
  39. LstTitle.Add(Res["Title"].ToString());
  40. }
  41. Con.Close();
  42. BtnShowAll_Click(sender, e);
  43. }
  44. private void BtnShowAll_Click(object sender, EventArgs e)
  45. {
  46. DgvClothes.Rows.Clear();
  47. foreach (string title in LstTitle)
  48. DgvClothes.Rows.Add(title);
  49. }
  50. private void BtnLeven_Click(object sender, EventArgs e)
  51. {
  52. DgvClothes.Rows.Clear();
  53. foreach(string title in LstTitle)
  54. {
  55. if(Levenshtein(title, TbxLeven.Text) <= 3)
  56. {
  57. DgvClothes.Rows.Add(title);
  58. }
  59. }
  60. }
  61. }
  62. }