How to disallow user to edit a record if another user is already editing that record?


Author
Message
Vikram Saxena
Vikram Saxena
StrataFrame Novice (69 reputation)StrataFrame Novice (69 reputation)StrataFrame Novice (69 reputation)StrataFrame Novice (69 reputation)StrataFrame Novice (69 reputation)StrataFrame Novice (69 reputation)StrataFrame Novice (69 reputation)StrataFrame Novice (69 reputation)StrataFrame Novice (69 reputation)
Group: Forum Members
Posts: 41, Visits: 99
Respected Sir/Madam,





We are using SF with our project.

we just have developed a windows application that will run on different machine on a Local are network with central Database present at server. Now, as all user can add, view, edit, update all the records so i don't want any user to edit a record if any other user is already been editing that record. i just wanna show him a message when he/she clicks edit that "Any other user is already editing this records so you can't edit this record." Please tell me how can i achieve this kind of functionality using SF.



Thanks,



Aman.
Replies
Trent Taylor
Trent Taylor
StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 7K
Well, this goes beyond concurrency.  StrataFrame has teh ability to handle concurrency so if two users modify the same data, it will raise the ConcurrencyException event (and even manage it for you if you by default).  However, if you do not want to use concurrency and just have a "hard" lock on the record when editing, you will have to add another field to the table and update that field when the end-user edits the BO.

You would have to handle the EditingStateChanged event in the BO to determine when you are editing.  Within this event if you are editing you would want to update that single field back on the database.  You will need to do this outside of the BO otherwise the state will change back.  Wheh I say outside of the BO, I just mean you will need to use a connection and command object manually.  HOwever, you will already have the connection string the in DataSources collection which can be used within the connection object.

'-- Establish Locals
Dim loCommand As New SQLCommand()
Dim loConn As New SQLConnection(MicroFour.StrataFrame.Data.Databasics.DataSources(0).ConnectionString)

loCommand.CommandText = "UPDATE MyTable SET MyField = MyValue WHERE MyPrimaryKey = MyPKValue"

'-- Open the connection
loConn.Open()

'-- Set the connection on the command
loCommand.Connection = loConn

'-- Execute the query
loCommand.ExecuteNonQuery()

'-- Close the connection
loConn.Close()

When the state goes back to Idle, you will then just reset the flag back to a "allow edit" state.  I will caution you against this type of functionality as it goes against the purpose of concurrency and can potentially leave records "locked" if there is some type of error.  I recommend using the built in concurrency rather than this methodology.

Ben Hayat
Ben Hayat
Advanced StrataFrame User (946 reputation)Advanced StrataFrame User (946 reputation)Advanced StrataFrame User (946 reputation)Advanced StrataFrame User (946 reputation)Advanced StrataFrame User (946 reputation)Advanced StrataFrame User (946 reputation)Advanced StrataFrame User (946 reputation)Advanced StrataFrame User (946 reputation)Advanced StrataFrame User (946 reputation)
Group: Forum Members
Posts: 374, Visits: 1.2K
I will caution you against this type of functionality as it goes against the purpose of concurrency and can potentially leave records "locked" if there is some type of error. I recommend using the built in concurrency rather than this methodology.




As Trent has pointed out, "Hard Lock" can eventualy drive you crazy, due to some issues remaining there. I had my share of problems many years ago, and I won't do it again.



Just my 2 cents!

..ßen
GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...





Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search