I am writing at this point an application that will mainly display data. I've used EF to display data and have a method that pulls data to a datagridview. Based on this method, I would like to create a search for WZ documents using a textbox. Generally, it worked, but I know that both of these methods can be somehow transformed into shorter ones.
namespace Sito{
public partial class MainWindow : Window
{
public object SqlMethods { get; private set; }
public MainWindow()
{
InitializeComponent();
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
EntitiesSito db = new EntitiesSito();
getdata();
}
private void filtertxbox_TextChanged(object sender, TextChangedEventArgs e)
{
string numberofWZ = filtertxbox.Text;
if (string.IsNullOrEmpty(numberofWZ) )
{
getdata();
}
else
{
EntitiesSito db = new EntitiesSito();
var query2 = (from a in db.WZ_DWS_SITO
where a.WZ.Contains(numberofWZ)
orderby a.WZ_DATA descending
group a by new { a.WZ, a.KUNNR, a.WZ_DATA } into grp
select new
{
grp.Key.WZ,
grp.Key.KUNNR,
grp.Key.WZ_DATA,
MATERIAL = grp.Count(),
}).ToList();
datagridview.ItemsSource = query2;
}
}
public void getdata()
{
EntitiesSito db = new EntitiesSito();
var query = (from d in db.WZ_DWS_SITO
orderby d.WZ_DATA descending
group d by new { d.WZ, d.KUNNR, d.WZ_DATA } into grp
select new
{
grp.Key.WZ,
grp.Key.KUNNR,
grp.Key.WZ_DATA,
MATERIAL = grp.Count(),
}).ToList();
datagridview.ItemsSource = query;
}}}
How to improve this code for better ergonomy.
I am also asking for clarification of the issues related to writing a better code and what I can pay attention to in the future.