Refresh WPF usercontrol when navigated to it - c#

I'm new to WPF and now i'm making an app that gets some data from MS SQL Server, places it to the table and allows to modify it. I'm using a M:UI template to make my app look metro-styled. My app structure: MainWindow.xaml and some UserControls placed into it with Itemsource="page" etc. Navigation between UserControls is made with Links and LinkGroups, generated upon MainWindow after successful login.
What I want is to launch a method that gets data from SQL every time I go to any of UserControls. Data is retrieved from server with SQLDataReader and placed to the ObservableCollection (one UserControl - one collection). At this moment my method works fine when I first go to any of UserControls, because it's placed to the constructor of the UserControl class, and I want to get some changes in all my tables when some other table was edited. How can I do this? Is there an event I can raise or some other way to update a table?

Since communicating constantly or background tasks running for server might take overhead and bit of memory wastage so I prefer u start using push notification :) Here's the link that will guide you through the push notification
Push Notification Overview
Raw Notifications
Please go through them design the proper object to pass to you app and to display in the table :) Once you receive a change notification you can map that object to the table you are using .... or read through the sql reader all the records but that wont be a good practice to send all the records so you can go ahead fetch the latest data and append it to the table ... next time when user visits the page it will obviously be refreshed :)

Related

sql + visual studio/(login/registration System) How to make a user control hold data

The application is a store, it's a windows form application, where the user can login/register, buy and sell it's products, with items based per tags.
The thing is, I want to know if there is a way to make a user control hold the data inserted on him, and then, only when the process of registration is over, let it send to the database.
The idea is to have only one windows form for Registration, inside it, two user controls, since I don't want the app to take much space on the screen.
Should I make the user control send the data to the button that finish the registration and then when i click on him he releases to the database? Is there a way to do this?
*This question stayed with me after i finished my course. We had to do a project on the final of the course using both sql and visual studios, we weren't able to finish it the way we wanted.
It bugged me, so I'm trying to do it now.
*

Is it possible to store and later retrieve user-configured WPF/XAML User Controls in SQL

I'm relatively new to .NET development (though I have a lot of Java experience) and I'm trying to see if that what I want to do is possible. I want to create a drag-and-drop template builder so that users can add and position things like comboboxes and textboxes on a gridpanel. Later, users can be assigned an instance of this item to complete.
Here's the ideal process:
Manager creates template using d&d builder to position fields. The number of fields are unknown by me, the programmer (but have a cap, like 15-20) at design time.
On save, this new control (the grid and all of the controls it's wrapped around) is added to a SQL database
Later, the manager assigns an instance of this process to an employee.
The employee opens the item, and queries the DB for the control.
The control is added to a content area (designated by me at design time).
Any existing data is populated into the fields of the control.
At save, the user saves the data for the fields.
For now SQL is non-negotiable. I have already worked out how I'm going to store the data for the fields, I just need to know how to store the actual visual element exactly as configured, and how to display said element to users.
Thoughts?

Sharing the same viewmodel between pages/main page and sub-page

I'm kinda new to the whole windows platform and I'm trying to create mvvm portable class library for windows and windows phone. Now that I have all my smaller pieces ready, I've found myself stuck at trying to figure out how to achieve the following with mvvm.
I have a main page where I can see the information for a car rental reservation and in this page. I'll be able to see a pickup location and a dropoff location (which are both inside a PointOfInterestViewModel). When I click on either the pickup/dropoff location. I want to switch to anther page which has a pivot with multiple list of possible locations. Once the user selects a location, I'll want to update the location in the PointOfInterestViewModel and then send the user back to the main view.
Is there a way where I can achieve it without having multiple PointOfInterestViewModel(s) and passing data between them? I would much rather have one single viewmodel but still adhere to mvvm.
You could put the PointOfInterestViewModel on the App class, bind the main form to it - then you could update it from the pivot:
((App)App.Current).PointOfInterestVM = ....

Auto refresh databinded component after Database update

fellow devs! I need to know a strategy that will allow me to know that the database has been updated so that I can rebind respective controls (DropDownLists in this case. Here is a bit more details:
I have three Combo-Boxes (DropDownLists) on a MDI Parent form. Selecting a value from these combos will allow me to directly jump to the view form for the selected entity. Now, on MDI parent load, these combos are filled up. But once the application is running, anyone from anywhere can edit an entity or add a new one. i need to detect this and somehow cause the combo(s) to reload again.
Using Linq-2-SQL to load the Combos, Backend is a SQL 2005 DB on a SQL 2008 Server.
There's no builtin functionality to do all of this, so you'll have to roll your own.
One possibility I can see is to have a timer that periodically checks whether the items have been updated. You could do this by storing a last updated timestamp somewhere and checking against it. When you detect that the items changed, requery the data and rebuild the combos.
didn't try it, but you may take a look at the Sql Service Broker feature.
From my memory, it can create a file on the file system and you can monitor the creation of this file.
it's the feature used by the ASP.Net cache and its dependencies check.

Fast way to code forms in C# which is bind to SQL data

I am coming from MS-ACESS world and their programing habits, There was nice utility to make form from table, You can simply hit right click on table and make form for it. Now I looking for something similar for Visual Studio and WinForms. I am trying to develop simple application for which I need to have more then 30 forms for handling data, till now I designed database tables, keys and sprocs in SQL2008 and before I start coding forms for handling data, I asking You for main guidelines how to save my time while coding forms.
Click in VS2008 within the menu bar on Data - Show Data Sources.
In the new window you can select the first icon in the top left to create a new dataSource by help from a wizard.
Just step through it and select the database, tables, views, etc. you like.
When you're finished in the wizard, you can drag and drop the tables from the Data Sources window onto your form. You can also before drag and drop something click on the icon next to the table, view, etc. and change the container type which should be auto-generated.
Starting with these tips it should be quite easy to get a first version to run.
Last but not least:
These wizards create normal code files, which can be viewed and editing like any self written code file. So you can also take a look there to find out which base classes are needed to get all these thing to work to know how you can do some special task manually on yourself.
a simple way is to use a typed dataset (generated by vs) and to bind that to a datagridview.

Categories