0

So I have a Winforms program that is set up such that There is a single form with a datagridview that is responsible for displaying Litigation Matters. A matter is just a class that contains an ID, Description, some Dates, and then some Collections (Navigation properties) eg:

public int MatterID
public string Description
public DateTime? DateFiled
public ICollection<Contact> Plaintiffs
public ICollection<Contact> Attorneys

Now here is where the problem starts:

The user can view different sets of Matters; All Matters, Open Matters, Closed Matters, Searched Matters (based on search criteria), Matters associated with a given contact, etc (many more)

This MatterViewer form has a datagridview that is responsible for displaying the matters and refreshing the data as things get updated. (eg. A user could right click on a Matter in the datagridview and edit it, then the Matters in the Datagridview need to be refreshed).

In order for this to work, I currently have form constructors that take in a querystring so that I have access to the query that was used to obtain these specific matters and use it to refresh the specific data as needed:

public FormViewMatters(string matterQueryString, string dataSetName = null)
{
    //Code here
}

If I were to pass in just a list of Matters to the Form, then I would only ever be able to refresh items in that list, not refresh the all potential matters based on the query.

Using the querystring however, limits me to lazy loading navigation properties. I currently need to eager load some of the properties and I am unable to do so.

So what is the best approach to go about refreshing specific data in general (including navigation properties)?

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
Michael
  • 739
  • 12
  • 27
  • I suppose the `ListForm` has a `LoadData` method. And your `EditForm` has been shown using `ShowDialog` and also saves data that passed to it. Then you can call `LoadData` method of the list form after the dialog closed. Is the case different than what I said? – Reza Aghaei Aug 09 '16 at 13:54
  • That part is generally correct, yes. But how the LoadData method should work is my concern. – Michael Aug 09 '16 at 13:59
  • You can use a single `SearchModel` which performs search using a single Method which accepts a parameter of type of that `SearchModel`. Then when showing the `ListForm`, you can pass an instance of SearchModel containing suitable values to the form. For example Your `SearchModel` can contains a `Nullable Color` property, then you can open the form passing `new SearchModel(){Color = Color.Red}` to find `RedProducts`, or pass `new SearchModel(){Color = Color.Blue}` to find `BlueProducts`. `RedProducts` and `BlueProducts` can be name of methods that show the form with suitable parameters. – Reza Aghaei Aug 09 '16 at 14:08
  • Also you can create multiple `SearchModel` classes and create multiple overload for constructor of `ListForm` and then based on the passed `SearchModel` (you can use a flag) call suitable `LoadData` method which accept suitable `SearchModel`. – Reza Aghaei Aug 09 '16 at 14:12
  • Also as another option, you can define `public Func LoadData { get; set; }` in your `LoadData` form and inject an implementation to your `ListForm` when you want to show it. For example you can have `GetRedProducts` and `GetBlueProducts` methods and when you want to create and show the `ListForm`, set `list.LoadData = ()=>GetRedProducts();`. Then in `ListForm` when you need to load data, call `var data = this.LoadData();`. – Reza Aghaei Aug 09 '16 at 14:16
  • To have a better understanding of what a `SearchModel` may look like, take a look at this post: [Filter/Search using Multiple Fields - ASP.NET MVC](http://stackoverflow.com/a/33154580/3110834). The answer written for an ASP.NET MVC question, but it's the same way that I use in windows forms applications too, when I need a `SearchModel` (which also can be filled using data-binding). – Reza Aghaei Aug 09 '16 at 14:19
  • @RezaAghaei these are good ideas, I was starting to think about using a delegate or func, but I am inexperienced with them. Still I feel that this may not solve the "Specific" query problem. Yes I could create functions to get all the Open or Closed (eg Red or Blue) matters but if a specific query was created to obtain those matters, I would need that specific search query. – Michael Aug 09 '16 at 14:20
  • Maybe yes, maybe no. For example if you have a method which accepts a parameter of type `SearchModel`, for example `List Search(SearchModel model)`, then red products is `var data = Search(new SearchModel(){Color = Color.Red});` and blue products is red products is `var data = Search(new SearchModel(){Color = Color.Blue});`. – Reza Aghaei Aug 09 '16 at 14:24
  • Also you can use different search methods (search queries). It's not bad. – Reza Aghaei Aug 09 '16 at 14:24
  • Since you know ASP.NET MVC, you may find the linked post useful. – Reza Aghaei Aug 09 '16 at 14:24
  • Also Injecting `Func>` is a good option which you can simply use with multiple search methods (queries). – Reza Aghaei Aug 09 '16 at 14:27
  • @RezaAghaei thank you :) I will start giving some of these suggestions a try – Michael Aug 09 '16 at 14:49
  • What have you tried so far? hope you can give us some code in each functionalities you define and i think LINQ will be effective in handling this. – Shift 'n Tab Aug 11 '16 at 06:23

0 Answers0