Restoring original values - linq-to-sql

I have a form in which we are showing customer records in a grid.User clicks a row, and in a new form record is shown.After editing some values, user may click cancel. if so, in grid we need to return to original values.
How can I restore the original state of the entity.We are using linq-to-sql, and grid is bounded to List.One way I see is,using getoriginalentitystate method.

If a user cancels a process, no change is made at the Database and the control reverts back to the pre-action state. This is a normal and built-in behaviour.
In case, if this is not happening, try rebinding List to it's DataSource, like
myList.Databind()

As the user is entering data in the form, the values should be stored in your UI layer (not written to your "database"). The data in the form is held there temporarily until the user clicks 'OK'/commit. If the user clicks 'cancel' the form is simply discarded and not written to the database.
Until the user hits 'OK', the original data is still in the database. You can get the original values there.

Related

ms access: 'cannot assign value to this object' message, but assigning value works anyway

I have a strange issue with one of my data entry forms. I have a main form from which I open said data entry form using a button. Once the form is open, I can enter a new record (the DE-form is set to allow additions and data entry is set to YES). The first time AFTER opening the main form, and only the very first time (subsequent tries work as intended), when opening the DE-form from the button and attempting to enter new data into the field "Bezeichnung", I get the following error message:
You can't assign a value to this object.
The weird thing comes now. After clicking OK in the dialogue box, in spite of what the message just indicated, the field contains the character I had just entered and allows me to continue adding data without issue.
After adding the new record and confirming, it shows up on my main form, as well as the related table, as intended. I have tried making a new DE-form from scratch but encountered the same thing. The message only pops up the very first time I attempt to enter new data via the DE-form after opening the main form. Opening the DE-form a second or third time while the main form is still up does not result in the same message. Also, it's the same with any of the fields on the DE-form, not just the first one. After the message pops once, it never shows up again until I close the main form. This is the only DE-form in my project that has this issue, I can#t seem to figure out why. Any help is appreciated.
Database Structure:
Details of my data entry form:
*The DE-form consists of a form with a subform on it (white box in the middle). I have other forms where this is neccesary and in order to keep the design consitent I opted to do the same with this one. Both forms have an invisible textbox bound to stoff_id. The DE-subform has Link Master Field and Link Child Field set to stoff_id
Recordsource DE-form main
SELECT chemikalien_tabelle.stoff_id
FROM chemikalien_tabelle;
Recordsource DE-form sub
SELECT chemikalien_tabelle.stoff_id, chemikalien_tabelle.bezeichnung, chemikalien_tabelle.einsatzgebiet, chemikalien_tabelle.kategorie_id
FROM kategorie_tabelle INNER JOIN chemikalien_tabelle ON kategorie_tabelle.kategorie_id = chemikalien_tabelle.kategorie_id;
I found a solution on another site. Apparently, what is causing the message is an invisible textfield bound to the primary key stoff_id (which is AutoValue) of chemikalien_tabelle on the DE-subform. I usually add the primary key somewhere to my forms since it is likely I will need it. I still don't know why this issue popped up though. The original answer I am refering to did not either Foreign Solution. The post is in German, so check it out at your discretion. Removing the textbox fixes the issue but without it I cannot assign a completely new record. I have a number of other data-entry forms that have the same setup, so I am not sure why this only caused issues in this particular case. Maybe someone else has a an idea?

How to populate an append only long text data type field

I use a form to update/insert a database in Access 2016.
I found Access has an option to record version of a field value change if data type of this field is long text and append only property is set to yes. I decided to concat all the values of a single record and save to this long text (history) field.
Now I have added an invisible textbox control to that form. The value of this field i.e. "history" will be populated when an event occurs (on unload from form current record) and that invisible textbox control value is set running a function.
So now I need to know which event should I address to populate history field?
I tried several events but all say conflict!
This seems like a last changed date kind of problem. I have has success with using the form's before update event for this. E.g.:
Private Sub Form_BeforeUpdate(Cancel As Integer)
With Me
.LastChangedDate = Now()
End With
End Sub
If you are having trouble accessing the history from the control you could set a vba variable to it using the Current event of the form. Be careful, the Current Event fires for many reasons and the code has to defend itself from running except when you want.
I frequently test many conditions and switch settings so the Current event does not crash or worse. Trial and error needed.
For example, you could record the key of the record whose history you have saved for later and test to see if it has changed before saving it again. Also, I make sure that initialization of the OPEN and LOAD events are complete along with any other initialization necessary before I allow the Current event to do anything significant.
Good luck.

How can I clear a specific filter without clearing all filters?

Background:
I am creating an app that stores record of trainings that employees in a company took in table. I want to filter the rows of the table based on training name and/or employee name. I was able to figure out this first part, and I was able to create a button that clears all the filters and reloads the entire table using the clearFilters() function.
Problem:
I want to create two buttons that clear the filter selections one ("All Trainings") for the training name and one ("All Employees") for the employee name. To be more clear, when I click on the "All Trainings" button, I want to clear the filters on the training name, but not on the Employee name. This will become useful once I have a table with multiple fields that I want to filter, and I want to navigate the table without having to reset all fields every time.
I tried searching the functions available on Google App Maker, but there was nothing that seemed to be able to solve my problem. Any suggestions?
From the Reference about datasources:
https://developers.google.com/appmaker/models/datasources#query_datasources
Like field filters, assigning null to a relation filter property clears that restriction.
So, something like:
datasource.query.filters.Employee._contains = null;
datasource.load();
should work for you.
I am sure there is a better way to do this, so you may want to wait for someone smarter to chime in, but I BELIEVE you can just have your button clear the filters, but reapply a new filter.
So for my situation I have the table do a filter for items that are listed as "Complete", so those are hidden when the user opens the page.
Then, when the users filter another field and want to clear out that search I didn't want the "Complete" items to reappear (which is what happened when I just used the clearFilters() function. So my workaround was to make the clear button actually clear the filter, but apply the original "Complete" filter.
So for my OnClick action, for my "Clear Button" I have:
widget.datasource.query.clearFilters();
widget.datasource.load();
app.closeDialog();
var datasource = app.datasources.TestModel;
datasource.query.filters.Status._notContains = 'Complete';
datasource.load();
The
widget.datasource.load();
app.closeDialog();
May be redundant/unnecessary.
Can you simply take 3 steps in your onClick handler?
(1) clear all filter
(2) set the employee name filter
(3) load data

"Create or update" form behavior when hitting back button

I have the following workflow on a website:
Some user John Doe declares a company through form 1
(fields: name, head office location)
After John Doe submits (HTTP POST) form 1, he is redirected (HTTP 302) to company form 2 with additional legal information about the company.
The problem is, if John Doe hits the back button of his browser during step 2, he will land on the form 1, with data filled by the browser (using values he already submitted — that's what Firefox and major browsers seem to do).
John Doe might then think he can use this form to update some information (e.g. fix a typo in the name of the company) whereas he will actually create a new company doing so, as we don't know on the server side whether he wants to declare a new company or update the one he just created.
Do you know any simple solution to handle that problem ?
Use javascript/jquery script after the page is loaded to empty all the inputs. This will prevent confusion of "updating the company".
jQuery would look something like this:
$('#elementID').val('');
You can also handle the situation by manipulating the browser history
on load of form 2, and pass the CompanyId generated on submit of form 1 using querystring. So that you can actually update the company as the user
Suppose John submits form1.html, a unique CompanyId "1001" is generated and redirected to form2.html. Now on load of form2 you can modify the browser history form1.html?companyid=1001 using
var stateObj = { foo: "bar" };
history.pushState(stateObj, "page 1", "form1.html?companyid=1001");
Now, when the user click back button and submits the form1 again. you can check for companyid in querystring and update the company.
I think it is more user-friendly when user can return back to previous form and update it (instead preventing the described behavior).
I use in most cases similar way to handle described problem:
Let's assume that user is on the page /some-page, that contains "Create new company" button.
When the user opens this page, will be executed special method createOrFindCompanyDraft() on the server-side. This method creates new company "draft" record in DB (only for the current user). For example, draft record has primary key id=473. When you execute this method again it will return the same record with the id=473 (with "draft" status). "Draft" record should't display on any other interfaces.
And "Create new company" has link /company/common/473.
When user go to /company/common/473, you display form 1, that will be filled from "draft" record. At first time user will see empty form.
Technically user will update the existing record, but you can display "Create new company" title on the page.
Then user go to form 2, for example, /company/legal-info/473, you create similar draft record for the this form (similar to step 1).
When user submit the form 2, you will remove "draft" status from the record id=473 (and any related records).
Next time when user open page /some-page, will be created new draft record for the current user.
Browser history will contain:
/some-page
/company/common/473
/company/legal-info/473
/some-page2
I like this approach, because all form only update records. You can go to previous/next form many times (for example "Back"/"Forward" browser buttons). You can close browser, and open not completed forms tomorrow. This way doesn't require any additional manipulation with the browser history.
try this
<form autocomplete="off" ...></form>
And Another
Use temporary tables or session to store the Page 1 form data. If the page 2 form is submitted use the temporary data of page 1 which is stored in database or in session.
Use a Separate key (Hidden field ) in both page 1 and page 2.
Actually I thought of a trick to obtain that "create on first post, update after" behavior (just like the user thinks it should behave).
Let's say the step 1 form is at the URL /create_company/. Then I could have that page generate a random code XXX and redirect to /create_company/?token=XXX. When I create the company I save the information that it was created through page with token XXX (for instance, I save it in user's session as we don't need to keep that information forever) and when the form is submitted, if I know that a company was already generated using this token, I know the user used the same form instance and must have used the back button since the token would be different if he explicitly asked for another company.
What do you think ? (I initially thought there should be a simpler solution, as this seems a little bit over-engineered for such a simple issue)
This is more like a UX question.
I'd think that the solution lies within the information given to the user on that form, to help them understand what they're doing.
Set a title that says 'Create a company', for example, and set your submit button as 'Create Company' will help your user with that. Use a unique id when you create the company object, and pass the id back to the same URL in order to perform an update. You should then update your title and button that tells user that they are updating instead of creating.
In that sense I'd say it's better to use a more generic URL like /company and /company?id=12345.
You could also consider using Restful API protocol to help your server identifies the CRUD operation. http://www.restapitutorial.com/lessons/httpmethods.html
Without the "routing" part of django it is hard to help. I can just answer my experience from the express.js-router functionality:
you can specify a post on /company, which is for new users.
you can specify another route for post on /company/:companyid for a changing form
and as a response from the create-post you can redirect to the different location.

Changing message box activation

My database has a unique field for the name of the child receiving gifts from our Christmas project and notifies us of the duplication as we leave the record. However that is many keystrokes later. Is there a way to activate the message upon leaving the field rather than the record.?
Yes, use the BeforeUpdate event of the field. In this, look up the value entered and, if found, set:
Cancel = True
and pop a messagebox.