123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Data.SqlClient;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace СУБД_Фабрика
- {
- public partial class FormLevin : Form
- {
- public FormLevin()
- {
- InitializeComponent();
- }
- SqlConnection Con = new SqlConnection(FormMain.txtCon);
- List<string> LstTitle = new List<string>();
- static int Levenshtein(string text1, string text2)
- {
- int CntLev = Math.Abs(text1.Length - text2.Length);
- for (int i = 0; i <= Math.Min(text1.Length, text2.Length) - 1; i++)
- {
- if (text1[i] != text2[i])
- CntLev++;
- }
- return CntLev;
- }
- private void FormLevin_Load(object sender, EventArgs e)
- {
- string txtQuery = "select Title from Cloth";
- Con.Open();
- SqlCommand query = new SqlCommand(txtQuery, Con);
- SqlDataReader Res = query.ExecuteReader();
- while(Res.Read())
- {
- LstTitle.Add(Res["Title"].ToString());
- }
- Con.Close();
- BtnShowAll_Click(sender, e);
- }
- private void BtnShowAll_Click(object sender, EventArgs e)
- {
- DgvClothes.Rows.Clear();
- foreach (string title in LstTitle)
- DgvClothes.Rows.Add(title);
- }
- private void BtnLeven_Click(object sender, EventArgs e)
- {
- DgvClothes.Rows.Clear();
- foreach(string title in LstTitle)
- {
- if(Levenshtein(title, TbxLeven.Text) <= 3)
- {
- DgvClothes.Rows.Add(title);
- }
- }
- }
- }
- }
|