Windows Form Application : Save the Contents then close

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nightscorpion
    New Member
    • Jul 2008
    • 19

    #1

    Windows Form Application : Save the Contents then close

    Hello,
    i make some changes in my windows form applications and commit to save it in my database. However if the commit has not yet taken place.i would like to have an alert box with states if the user wants to quit without saving "yes" or "no".
    however i do not know how to implement this. espiacially to check if the commit has taken place or no?

    would be gratefull for any suggestion
  • Plater
    Recognized Expert Expert
    • Apr 2007
    • 7872

    #2
    If anything on the form has been changed since the last time the data was saved, set a boolean to false.
    Then check for it on exit?

    Comment

    • r035198x
      MVP
      • Sep 2006
      • 13225

      #3
      Originally posted by Plater
      If anything on the form has been changed since the last time the data was saved, set a boolean to false.
      Then check for it on exit?
      That would require a check for every keypress e.t.c on the windows. I'd rather do the check against the database just before exit only. If there is anything on the window that is different from what's in the database then ask for confirmation.

      Comment

      • TTCEric
        New Member
        • Jul 2008
        • 26

        #4
        Originally posted by r035198x
        That would require a check for every keypress e.t.c on the windows. I'd rather do the check against the database just before exit only. If there is anything on the window that is different from what's in the database then ask for confirmation.
        This would be my approach (it avoids the back/forth trips to the database).

        1. Create a function that creates a string containing the values in your controls. For example, it creates one huge string of control values.

        2. Get the result of the function just after loading the database values. Throw it in a global variable.

        3. Before exiting, make another call to the function but this time do a string comparison against the functions returned value and your global string variable. If they dont match, they haven't saved.

        Of course, this assumes no one changes database values besides the user using your app. It wont be ideal if you also need to check changes other users may have made.

        Comment

        • r035198x
          MVP
          • Sep 2006
          • 13225

          #5
          More or less what I suggested above without representing all the values as one string though.

          Comment

          • TTCEric
            New Member
            • Jul 2008
            • 26

            #6
            Originally posted by r035198x
            More or less what I suggested above without representing all the values as one string though.
            I find string comparisons very fast so I try to do alot of operations with them.

            Comment

            • nightscorpion
              New Member
              • Jul 2008
              • 19

              #7
              thank u ..i solved it with the help of boolean values.. thanx a lot

              Comment

              Working...