Guys, how to do the search itself, I know the queries and all that. Help me, is it possible to write a beautiful condition if there are several types of search? or I’ll have to, as I started, this is somewhat (very much) else if.
//По году else if (numericUpDownMonth.Value == 0 && textBoxArticle.Text.Equals("") && textBoxFIOSuspect.Text.Equals("")) { conn.Open(); SqlCommand cmd = new SqlCommand(string.Format("Select ID AS 'П/н', NumberCriminalCases AS '№ у/д' , Article AS 'Статья', DateIntination AS 'Дата возбуждения у/д', Subdivision AS 'Подразделение', FIOEmployee AS 'ФИО Сотрудника', NumberCRB AS '№ КУСП', DateCRB AS 'Дата КУСП', Fabula AS 'Фабула', FIOSuspect AS 'ФИО подозреваемого', LimitationDate AS 'Срок' From dbo.ListOfCriminalCases Where YEAR(DateCRB) = {0}", numericUpDownYear.Value), conn); DataTable dt = new DataTable(); SqlDataAdapter da = new SqlDataAdapter(cmd); da.Fill(dt); dgvArchive.DataSource = dt; conn.Close(); numericUpDownMonth.Value = 0; tabControlSearch.Visible = false; } //По месяцу else if (numericUpDownYear.Value == 0 && textBoxArticle.Text.Equals("") && textBoxFIOSuspect.Text.Equals("")) { conn.Open(); SqlCommand cmd = new SqlCommand(string.Format("Select ID AS 'П/н', NumberCriminalCases AS '№ у/д' , Article AS 'Статья', DateIntination AS 'Дата возбуждения у/д', Subdivision AS 'Подразделение', FIOEmployee AS 'ФИО Сотрудника', NumberCRB AS '№ КУСП', DateCRB AS 'Дата КУСП', Fabula AS 'Фабула', FIOSuspect AS 'ФИО подозреваемого', LimitationDate AS 'Срок' From dbo.ListOfCriminalCases Where Month(DateCRB) = {0}",numericUpDownMonth.Value), conn); DataTable dt = new DataTable(); SqlDataAdapter da = new SqlDataAdapter(cmd); da.Fill(dt); dgvArchive.DataSource = dt; conn.Close(); numericUpDownMonth.Value = 0; tabControlSearch.Visible = false; } //По году и месяцу else if(textBoxArticle.Text.Equals("") && textBoxFIOSuspect.Text.Equals("")) { conn.Open(); SqlCommand cmd = new SqlCommand(string.Format("Select ID AS 'П/н', NumberCriminalCases AS '№ у/д' , Article AS 'Статья', DateIntination AS 'Дата возбуждения у/д', Subdivision AS 'Подразделение', FIOEmployee AS 'ФИО Сотрудника', NumberCRB AS '№ КУСП', DateCRB AS 'Дата КУСП', Fabula AS 'Фабула', FIOSuspect AS 'ФИО подозреваемого', LimitationDate AS 'Срок' From dbo.ListOfCriminalCases Where YEAR(DateCRB) = {0} and Month(DateCRB) = {1}", numericUpDownYear.Value, numericUpDownMonth.Value), conn); DataTable dt = new DataTable(); SqlDataAdapter da = new SqlDataAdapter(cmd); da.Fill(dt); dgvArchive.DataSource = dt; conn.Close(); numericUpDownMonth.Value = 0; tabControlSearch.Visible = false; } else if (textBoxFIOSuspect.Text.Equals("")) { conn.Open(); SqlCommand cmd = new SqlCommand(string.Format("Select ID AS 'П/н', NumberCriminalCases AS '№ у/д' , Article AS 'Статья', DateIntination AS 'Дата возбуждения у/д', Subdivision AS 'Подразделение', FIOEmployee AS 'ФИО Сотрудника', NumberCRB AS '№ КУСП', DateCRB AS 'Дата КУСП', Fabula AS 'Фабула', FIOSuspect AS 'ФИО подозреваемого', LimitationDate AS 'Срок' From dbo.ListOfCriminalCases Where YEAR(DateCRB) = {0} and Month(DateCRB) = {1} and Article = '{2}'", numericUpDownYear.Value, numericUpDownMonth.Value,textBoxArticle.Text), conn); DataTable dt = new DataTable(); SqlDataAdapter da = new SqlDataAdapter(cmd); da.Fill(dt); dgvArchive.DataSource = dt; conn.Close(); numericUpDownMonth.Value = 0; tabControlSearch.Visible = false; } This is not the end, you have to write a bunch of conditions to empty this or that value.
I will try to describe what should be the types of search
- Search by year
- Search by month only
- Year and Month
- Year and Article
- Year and name
- Month and Article
- Month and name
- Year, month and name
- Year month and Article
I do not even know if I listed everything.
I hope for bright ideas.
Or am I doing the right thing or not?
You can throw your options as you would have done, maybe I will redo it.