segunda-feira, 7 de maio de 2012 17:43
I have a button which opens a Modal Window for me to add a new customer entry to my Customer Table. I have another button on the Modal Window which runs the following code:
Private Sub SaveNewCustomer_Execute() 'Create a new Customer Dim newCustomer As Customer = New Customer 'Set new Customer values to data entered on modal screen newCustomer.CustomerName = CurrentCustomerName newCustomer.CustomerAddress1 = CurrentCustomerAddress1 newCustomer.RepFirm = CurrentRepFirm 'Add new Customer to Customer Table Me.CustomerTable = newCustomer 'Close the modal window Me.CloseModalWindow("NewCustomer") End Sub
After this runs, the newly added customer shows up in an AutoCompleteBox on the screen. If I close the screen and then rerun the application, then new customer is not available from the AutoCompleteBox. However, if I click the Save button in the ribbon and then close the screen, the new customer is available the next time I run the application.
The Save method only contains this one line of code:
Private Sub StartQuote_Saved() Me.Close(False) End Sub
How can I save new data to the table each time it is entered without having to click the Save button? Executing StartQuote_Saved() just closes the screen and the data is not available when the program is rerun.
Todas as Respostas
segunda-feira, 7 de maio de 2012 18:02
You have to call SaveChanges on you CustomerTable to persists changes; see Creating, Adding, Modifying, and Deleting Objects for Entity Framework.
Same as in e.g. editable list, as long as you don't click on "Save" all changes discard when you close then window.
segunda-feira, 7 de maio de 2012 18:02Moderador
How can I save new data to the table each time it is entered without having to click the Save button?Just call Me.Save() every time you want to save. This will save all changes that exist on the data workspace of the screen.
Justin Anderson, LightSwitch Development Team
- Marcado como Resposta kyle ls segunda-feira, 7 de maio de 2012 18:23
segunda-feira, 7 de maio de 2012 18:23That is some good information @Olaf and I may need to use that method in the future. But @Justin got it done with less code.
segunda-feira, 7 de maio de 2012 18:38
I've been fighting the framework to accomplish basic functionality that doesn't exist or is still buggy. And the Add/Edit screens have been my unwanted "hobby" for the last week.
I've ended up using Modal windows in ALL forms PER tab (and there's many!)
Just like you, I'm committing the record in the OK button of the Modal window, to avoid that extra unwanted step (per my requirements).
But you'll find much work ahead, such as the X button that has the wrong function, and the identical issue for "Enter", and then you want to do validation when wrong data is inputted, and I may be forgetting some.
But to give my contribution (newbie), this is what I have as "OK" and "Cancel" of the Modal:
Private Sub btn_Modal_Faqs_OK_Execute() ' Write your code here. If Me.Details.ValidationResults.HasErrors = False Then Me.CloseModalWindow("Faqs_AddEdit") Me.Save() Else Dim res As String = "" For Each msg In Me.Details.ValidationResults res = res & msg.Property.DisplayName & ": " & msg.Message & vbCrLf Next msg Me.ShowMessageBox(res, "Validation error", MessageBoxOption.Ok) End If End Sub Private Sub btn_Modal_Faqs_Cancel_Execute() ' Write your code here. Me.Faqs.SelectedItem.Details.DiscardChanges() Me.CloseModalWindow("Faqs_AddEdit") End Sub
segunda-feira, 7 de maio de 2012 18:57Oh boy. The things you don't think of until you really start testing. Thanks for the heads up!