Store textbox changes in database - sql

I want to store the values of multiple editable text-boxes in my database. The user can edit them all the time and my question is when to save them? If I execute a SQL statement every time the content changes (in the onchange event) there is too much traffic on the database, isn't it?
Is there any better solution?
I'd like to do it without a save button.

You can send the changes periodically (e.g. every 5 seconds), and try sending any unsaved changes upon leaving the page (beforeunload event):
window.addEventListener("beforeunload", function () {
/* Check for changes and send anything unsaved. */
});

Related

Allowing User to Select off of Partial Records in a Continuous Form in Access

I am creating a form in access to allow users to input multiple production records for a day.
The form is set as a continuous data entry form and has data validation in place to ensure the information being entered is consistent.
I am having a problem where if a user starts typing something on a new entry, they essentially have no way to back out of it or cancel the entry without completely filling out the form.
I want to keep the data validation to ensure the data being recorded is accurate, but also do not want to lock users into an entry unless it is completely filled out.
I think the ideal would be to allow users to create a new record or select other records without needing to save the current record.
If it would be possible to make it so records only save when a button at the top of the form is pressed I think that would be ideal, but I have not found a good way to do this without requiring it on every single entry.
I have attached a picture of what I am talking about, there could be various error messages but essentially if you try to click off when a record is incomplete it will give an error until the entire form is filled out.
Example of Error Message and Image of Continuous Form
'deselect' without saving but still save what had been entered up to
that point.
That you can simulate by setting the DefaultValue of each control in the AfterUpdate event of each control:
Me!SomeTextBox.DefaultValue = Nz(Me!SomeTextBox.Value)
However, I'm not sure that will be a good idea. And you may have to reset the default values when opening the form.

How to know when a form is done loading or is loading in MS Access 2016

Is there a way to know when a form is finished loading, or to know that it is loading?
One of the reasons I want to know this, is I have a save routine within a drop down box [Updated] event. This event gets called when the form is loading, and I want to only call it when someone manually changes the selection, not when the form changes it.

Best way to save status of dynamic web interface

Basically in my website I have a sidebar with a stack of boxes; each box can be collapsed or expanded by the user. I need to save the status of each box for the currently logged in user.
I don't want to use cookies because if an user changes browser or computer, all the boxes will go to the default status.
Should I save this information on the database making a query every time the user collapses/expands a box? How would you handle this? Thanks.
Edit: What if an user clicks on the toggle button repeatedly, like ten times in two seconds, just because he enjoys the boxes' animation? He will make ten queries in two seconds. So maybe the question should be: when should I save this data?
Call a (client-side) "changed" function every time a box changes.
Keep two items of (client-side) state: the time the last update to the server was sent and whether a timer has been set.
Write a (client-side) "update" function that sends the update and updates the state to mark that the last update was just now.
When the changed function is called: if a timer is set, then return immediately; if an update has never been sent or the last update was sent more than ten seconds ago, then call the update function and return. Otherwise set a timer to send the update after ten seconds.
The timer callback should simply clear the timer flag and call the update function.
Also on an unload event check if a timer was set and if it was then clear the timer and call the timer callback function.
So the result is that you send the update immediately except when the user is flapping, in which case you only send an update every ten seconds at most.
There might be some cases where you lose an update, but this is likely to only happen if the user was playing with the toggling and then closed the page before the timer fired, in which case he probably won't notice anyway.
If you need to persist these options from multiple computers you will need some form of server side storage.
This could be database or flat file. The choice depends on what you have available, skill set, and the need to scale. If you are going to have just a few users, a flat file may be your best choice.

ASP.NET Keep fileupload after postback

I'm writing an intranet ASP.NET page using VB.NET. I've run into a particularly nasty problem dealing with handling file uploads. I'll do my best to explain the problem, and perhaps someone can help.
My problem is almost a duplicate of this one, or this one, except (other than the filename) I don't care about sending the file to the server until the other data has been reviewed.
Here's the situation:
Joe Q. Dataentry inputs some data into several fields. The first 3 are drop down, and when he changes the selection, a postback event is fired that queries a database for valid entries for the other drop down selections. After selecting the values, he inputs some other data, chooses a file to accompany the data and clicks the "Update" button. When he hits the button, it fires a postback event that sends the current data to the server to be validated. The data will create a change in the database, so he is presented with a view of the current state, and what it will look like when his changes are made. He can now either confirm or cancel the operation for whatever reason.
Part of the data he will see involves the extension of the file which may be a PDF, or could also be some image file or other document.
Now here's where my problem is - on each postback event, the fileupload dialog is cleared. I was getting around it by creating a temporary file on the first postback and then renaming if he clicks OK or deleting on Cancel... but I need to do a variety of things, based on the previous state of data and the filename. I've tried to keep some session variables to retain the filename, and that works OK for just renaming the file, but for what I need to do it gets unwieldy.
What I want to do is be able to have the postback event to present the changes, and then when the user clicks "OK", submit the file. Is there any possible way to do that?
One of my thoughts was to do some of the validation client-side (I'm already re-validating server side so I'm not too worried about data security there), but I don't know how I could get the information from the database query.
Thanks for any help, and reading my slightly convoluted story/situation!
EDIT:
It appears that what I want to do is prevent a certain button from firing a full postback. Is there any way to do that?
EDIT II:
I have an update panel on the page already - is there any way for the button to only post what's in the update panel?
What you might want to do is place your drop-downs inside of an ASP.NET AJAX UpdatePanel, and keep your file upload control out of that.
Your update panel will do the post backs and allow your validation logic to happen without submitting the file, then when you hit your final "Save" button (which is also outside of your UpdatePanel) the entire form will be submitted back and you can work with your file then.

How can I "undo send" like in Gmail?

How can I undo send, save or delete in Vb like Gmail is using this feature in Messages.
The feature used by Gmail is they are queing the message for 5 secs and if the user clicks on Undo before that 5secs the whole send process is pulled back.
Now what I want is to implement this same in my Vb.net application. Is there any code available to do this. Please help ?
About an "undo send" feature, the most evident way of doing that is to actually not "do" what you want to "undo".
What I mean is :
When a user clicks on "send", you should not really send the message
Instead, you should mark it as "to send in X seconds" -- place it in some queue, for instance
Which means it'll only be sent after X seconds, and not immediatly.
During this X number of seconds, if the user clicks "undo send", you just have to remove that mail from the "waiting queue"
Of course, you cannot "undo send" on a mail which has already been sent : it's gone from your server, and there is nothing you can do anymore about it.
To implement that, you'll need :
Some queue for actions
To place your data into this queue when the user clicks "send"
To have some batch that really sends data that's been in the queue for more than X seconds
To remove the data from the queue when the user clicks "undo send".
The same idea can be applied to "undo delete" :
When a user clicks on "delete", don't physicilly delete the data
Instead, use some boolean flag to indicate that it should be considered as deleted
Then, un-doping that deletion only means de-activating that flag
This can easily be implemented in any language :
Add a is_deleted field on your data
When displaying the data, filter those for which this flag is enabled
When deleting, instead of physically deleting, set this flag
When un-deleting, un-set this flag
The "undo save" can be a bit harder : a solution would be to not keep only one version of the message, but several :
Each time the user clicks "save", you should store a new version of the message
Which means you'll end up, after some time, with many versions of the message
Which will allow you to "come back" to a previous version, restoring it from the history.
This can be done :
adding a new field called like "version" on your data.
each time the user saves, just increment that field, and store a copy of the data
i.e. never actually update any exiting data, but always insert a new version of it.
then, "undo save" only means "get the previous version of the data"