| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- 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 FormClothFind : Form
- {
- public FormClothFind()
- {
- InitializeComponent();
- }
- private void FormClothFind_Load(object sender, EventArgs e)
- {
- // TODO: This line of code loads data into the 'fabrikaLDADataSet.Cloth' table. You can move, or remove it, as needed.
- this.clothTableAdapter.Fill(this.fabrikaLDADataSet.Cloth);
- SqlConnection con = new SqlConnection(FormAuthorization.StrCon);
- con.Open();
- SqlCommand cmd = new SqlCommand("select * from Cloth", con);
- SqlDataReader res = cmd.ExecuteReader();
- while (res.Read())
- {
- lstCloth.Add(res["Title"].ToString());
- }
- con.Close();
- btnAll_Click(sender, e);
- }
- static int Levenshtein(string str1,string str2)
- {
- int CountLeven = Math.Abs(str1.Length - str2.Length);
- for (int i = 0; i < Math.Min(str1.Length,str2.Length); i++)
- {
- if (str1[i] != str2[i])
- CountLeven++;
- }
- return CountLeven;
- }
- List<string> lstCloth = new List<string>();
- private void btnFind_Click(object sender, EventArgs e)
- {
- dgvCLoth.Rows.Clear();
- foreach(string str in lstCloth)
- {
- if (Levenshtein(str,tbxFind.Text) <= 3)
- {
- dgvCLoth.Rows.Add(str);
- }
- }
- }
- private void btnAll_Click(object sender, EventArgs e)
- {
- dgvCLoth.Rows.Clear();
- foreach(string str in lstCloth)
- dgvCLoth.Rows.Add(str);
- }
- }
- }
|