FormClothFind.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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 FormClothFind : Form
  14. {
  15. public FormClothFind()
  16. {
  17. InitializeComponent();
  18. }
  19. private void FormClothFind_Load(object sender, EventArgs e)
  20. {
  21. // TODO: This line of code loads data into the 'fabrikaLDADataSet.Cloth' table. You can move, or remove it, as needed.
  22. this.clothTableAdapter.Fill(this.fabrikaLDADataSet.Cloth);
  23. SqlConnection con = new SqlConnection(FormAuthorization.StrCon);
  24. con.Open();
  25. SqlCommand cmd = new SqlCommand("select * from Cloth", con);
  26. SqlDataReader res = cmd.ExecuteReader();
  27. while (res.Read())
  28. {
  29. lstCloth.Add(res["Title"].ToString());
  30. }
  31. con.Close();
  32. btnAll_Click(sender, e);
  33. }
  34. static int Levenshtein(string str1,string str2)
  35. {
  36. int CountLeven = Math.Abs(str1.Length - str2.Length);
  37. for (int i = 0; i < Math.Min(str1.Length,str2.Length); i++)
  38. {
  39. if (str1[i] != str2[i])
  40. CountLeven++;
  41. }
  42. return CountLeven;
  43. }
  44. List<string> lstCloth = new List<string>();
  45. private void btnFind_Click(object sender, EventArgs e)
  46. {
  47. dgvCLoth.Rows.Clear();
  48. foreach(string str in lstCloth)
  49. {
  50. if (Levenshtein(str,tbxFind.Text) <= 3)
  51. {
  52. dgvCLoth.Rows.Add(str);
  53. }
  54. }
  55. }
  56. private void btnAll_Click(object sender, EventArgs e)
  57. {
  58. dgvCLoth.Rows.Clear();
  59. foreach(string str in lstCloth)
  60. dgvCLoth.Rows.Add(str);
  61. }
  62. }
  63. }