|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,194
|
Hi, You will need to capture and handle both by yourself, very similar to the way you handled Del key. The Grid won't handle these two keys for you in your case because the Editor is outside of the Grid. Here are the available API on the Grid object: http://doc.essentialobjects.com/library/1/jsdoc.public.grid.aspxMost likely you will need to call editCell(-1) when ESC is pressed and selectCell when tab is pressed. Thanks
|
|
Rank: Advanced Member Groups: Member
Joined: 3/27/2010 Posts: 48
|
Thanks again. Handling KeyPress and other events was difficult, but I found another AutoComplete Ajax Control property "CompletionListElementID" which solved the problem for me without any javascript. Now I am proceding for Database Update, things looking fine, but still few issues. When I am handling the Grid Updates on the Click Event of the "Save Lab Items" button, and if there is an unexpected error within the "Try-Catch" block, the update process is canceled and when the page is loaded back on the client, the error is displayed as expected, and the last modifications are still shown on the grid, but if I click the "Save Lab Request" button again, the ChangedItems array is now empty. See code sample below:
Code: Visual Basic.NET
Protected Sub btnSaveLabItems_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSaveLabItems.Click
Dim theLabRequest As LabRequest
Dim theLabItems As LabRequestItems
Dim theLabItem As LabRequestItem
Try
theLabRequest = GetLabRequest()
If Not theLabRequest Is Nothing Then
theLabItems = theLabRequest.RequestItems
If Not theLabItems Is Nothing Then
Dim updItem As EO.Web.GridItem
Dim ItemKey As Integer
For Each updItem In gridLabItems.ChangedItems
ItemKey = updItem.Key
theLabItem = theLabItems.FindItem(ItemKey)
If Not theLabItem Is Nothing Then
theLabItem.LabTestKeyValue = updItem.Cells("LabTestKeyValue").Value
theLabItem.LabTestResult = updItem.Cells("LabTestResult").Value
End If
Next
theLabRequest.Save()
End If
End If
Catch ex As Exception
Me.ErrorLabel.Text = ex.Message
End Try
End Sub
How I can retain the ChangedItems array if there was an error during a post-back ? So that I can ensure that such changes are updated to the Database in the next post-back. Tarek.
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,194
|
Hi,
ChangedItems doesn't work that way. It is handed over to you once and it will be up to you to keep it in case the update fails. If you need to manually keep track of the data, you can add a separate invisible column in the Grid and use the cell value of that column to keep track of whether that row has been changed/saved.
Glad that you found another AutoComplete solution that allows you to place the list box outside.
Thanks!
|
|
Rank: Advanced Member Groups: Member
Joined: 3/27/2010 Posts: 48
|
Thanks again.
This coming Saturday, I have to show working demo for the Doctors at our Clinic the work I have done so far, and I need to complete the missing little features (the President is keen to know about the progress too!).
I have to make sure I am following the right path. I need your confirmation on the following:
1. Reference to the above conde in "btnSaveLabItems_Click(...)", is this the correct way to handle Updates ? and same for deletions and additions ?
2. I was thinking there is a way to notify the Grid that the changed items have not been updated to the Database. But seems there is no such feature. I will follow this technique to reatain the changed/deleted/added items in case of error after a post-back:
- In the catch block of "try-catch", I will create a copy (or clone) of the changed/added/deleted items which have not been applied to the Database. I will save this copy in a Session Variable. In the next post-back, I will check if this Session Variable is empty, if not, I will apply it to the Database. So I will have to have 3 separate session variable to retain failed changes, additions and deletions.
Appreciate your reply.
Tarek.
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,194
|
Hi,
As to your questions:
1. That is correct;
2. No. There is no mechanism for you to notify the Grid changed items have not been updated. You can save the changed item cell data in session variables, but you should not save GridItem object in session variables. This is because internally GridItem references the Grid object, which no longer exists once the current page cycle ends;
Thanks
|
|
Rank: Advanced Member Groups: Member
Joined: 3/27/2010 Posts: 48
|
eo_support wrote:Hi, 2. No. There is no mechanism for you to notify the Grid changed items have not been updated. You can save the changed item cell data in session variables, but you should not save GridItem object in session variables. This is because internally GridItem references the Grid object, which no longer exists once the current page cycle ends;
Thanks Ok, I am now testing the following program to save and re-use the failed changes, but the Back-End Database (Unix/Adabas) is down for some maintenance wotk! So, I could not test it. In the mean time, I appreciate you taking a look at it, and let me know if I am doing the right thing: This sub will save a given array of changed Grid Items:
Code: Visual Basic.NET
Public Sub ApplyGridChanges(ByVal theGirdItems As EO.Web.GridItem(), ByVal theLabRequest As LabRequest)
Dim theLabItems As LabRequestItems
Dim theLabItem As LabRequestItem
If Not theLabRequest Is Nothing Then
theLabItems = theLabRequest.RequestItems
If Not theLabItems Is Nothing Then
Dim updItem As EO.Web.GridItem
Dim ItemKey As Integer
For Each updItem In theGirdItems
ItemKey = updItem.Key
theLabItem = theLabItems.FindItem(ItemKey)
If Not theLabItem Is Nothing Then
theLabItem.LabTestKeyValue = updItem.Cells("LabTestKeyValue").Value
theLabItem.LabTestResult = updItem.Cells("LabTestResult").Value
End If
Next
theLabRequest.Save()
End If
End If
End Sub
This sub will check of there were failed changes in the last post-back, and re-apply them, and if there is error during updated, it will accumulate a copy of such failed updates in Array/ArrayList.
Code: Visual Basic.NET
Protected Sub btnSaveLabItems_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSaveLabItems.Click
Dim theLabRequest As LabRequest
Dim theChangedItemsArrList As ArrayList = New ArrayList()
Dim theChangedItems As EO.Web.GridItem() = Nothing
Try
theLabRequest = GetLabRequest()
theChangedItems = CType(Session("ChangedItems"), EO.Web.GridItem())
Session("ChangedItems") = Nothing
If Not theChangedItems Is Nothing Then
theChangedItemsArrList.AddRange(theChangedItems)
End If
If gridLabItems.ChangedItems.Length > 0 Then
theChangedItemsArrList.AddRange(gridLabItems.ChangedItems)
End If
ApplyGridChanges(theChangedItemsArrList.ToArray(), theLabRequest)
Catch ex As Exception
If theChangedItemsArrList.Count > 0 Then
Session("ChangedItems") = CType(theChangedItemsArrList.ToArray(), EO.Web.GridItem())
Else
Session("ChangedItems") = Nothing
End If
Me.ErrorLabel.Text = ex.Message
End Try
End Sub
I will test the above code when the Database is back on-line. The question here is that the ArrayList object when it is created it will be separate from the Grid.ChangedItems Array, right ? Tarek.
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,194
|
Hi,
Unfortunately we can not answer that question. We usually do not review or troubleshoot user code (definitely not for trial users). For paid users, we don't mind to point you to the right direction in case you are not familiar with our product. In any case you should not rely on us to review your code for you before you even try to run it. While we do our best to help you using our product, we are not a part of your development team, so we usually only answer questions directly related to our product (such as if it supports feature X?) and make suggestions. We do not code, review, or debug for you except for certain special cases where inside knowledge about the product is required to come up the code (such as the custom item sample code). We would love to be your live coding assistant but it is not something we can afford to. Sorry about it!
We are also expecting to receive your license payment soon, otherwise we will have to stop the trial support as well.
Thanks
|
|
Rank: Advanced Member Groups: Member
Joined: 3/27/2010 Posts: 48
|
I am not sure why you made such comments ! Simply, I found a missing feature, which I expect to find in the Grid Control, and I am trying to find ways to cover for this missing feature. I am sure this will be a great feedback for the future development of the Grid Control.
In any case, the EO.Web Grid Control is a great control.
Kindly keep in mind, that when I am posting here, I am not expecting an answer from you. If you post an answer, it will be great. I am posting so that other people can benifit too, and also, in case there is someting seriously worng in my approach, you may be kind enough to point me in the right direction.
With regards to the payment, I know its late, and it is for reasons beyond my control. If on-line trnasfer does not work, I will find another way.
But I am not feeling confortable your saying "We would love to be your live coding assistant ..." cause this is not the case.
Tarek.
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,194
|
tarekahf wrote:But I am not feeling confortable your saying "We would love to be your live coding assistant ..." cause this is not the case.
Sorry about the wording and we do appreciate your feedback about the product very much. What we meant is we are not in a position to check your code before you even verify/debug it yourself. We understand that you have contributed a lot and “live coding assistant” is just a hypothetical situation. It certainly does not apply to you because that that's we want to avoid, not what's happening. Thanks
|
|
Rank: Advanced Member Groups: Member
Joined: 3/27/2010 Posts: 48
|
I am posting again, just to show you the amount of coding I had to do to Synchronize ONLY Changes and Additions (deletions not yet implemented) between the Grid and the Database. See the code below:
Code: Visual Basic.NET
Public Sub ApplyGridChanges(ByVal theLabRequest As LabRequest)
Dim theLabItems As LabRequestItems
Dim theLabItem As LabRequestItem
Dim theGridItems As EO.Web.GridItem() = Nothing
Dim theChangedItemsArrList As List(Of EO.Web.GridItem) = New List(Of EO.Web.GridItem)
Dim theChangedItems As EO.Web.GridItem() = Nothing
Try
' Get the failed Changed Items in the last post back
theChangedItems = CType(Session("ChangedItems"), EO.Web.GridItem())
If Not theChangedItems Is Nothing Then
theChangedItemsArrList.AddRange(theChangedItems)
End If
' Remove Duplicates of Changed Items by comparing each item
' with the new changed items
Dim itm As EO.Web.GridItem
Dim IsItmFound As Boolean = False
Dim itmIdx As Integer = 0
Dim itm2Idx As Integer = 0
For Each itm In gridLabItems.ChangedItems
If Not String.IsNullOrEmpty(itm.Key) Then
itm2Idx = 0
IsItmFound = False
For Each itm2 As EO.Web.GridItem In theChangedItemsArrList.ToArray()
If itm.Key.ToString = itm2.Key.ToString Then
' Same Key Value? Remove it !
theChangedItemsArrList.Remove(itm2)
IsItmFound = True
Exit For
End If
itm2Idx += 1
Next
' Either replace the changed item, or add it to the temp list.
If IsItmFound Then
theChangedItemsArrList.Insert(itm2Idx, itm)
Else
theChangedItemsArrList.Add(itm)
End If
Else
Throw New Exception("Unexpected error: Null key value for Changed Item of LabKeyValue '" + itm.Cells("1").Value + "'.")
End If
Next
' Insert the new Added Items from the Grid to the list
' Generate Dummy Key Value
itmIdx = -1
Dim tempKey As Integer
For Each itm In theChangedItemsArrList
' these are the item that failed to be added in a previous post-back
If itm.Key.ToString.IndexOf("N*") >= 0 Then
' get greatest value
tempKey = Convert.ToInt16(itm.Key.ToString.Substring(itm.Key.ToString.IndexOf("N*") + 2))
If tempKey > itmIdx Then
itmIdx = tempKey
End If
End If
Next
If itmIdx < 0 Then
itmIdx = 1
Else
itmIdx += 1
End If
For Each itm In gridLabItems.AddedItems
itm.Key = "N*" & itmIdx
itm.Cells(0).Value = itm.Key
theChangedItemsArrList.Add(itm)
itmIdx += 1
Next
Session("ChangedItems") = Nothing
Try
' Update the changed items New Temp Array List to Database.
' In case of any error, save the changed items for next post-back
If Not theLabRequest Is Nothing Then
theLabItems = theLabRequest.RequestItems
If Not theLabItems Is Nothing Then
' Apply Database Updates for Changed Items
Dim updItem As EO.Web.GridItem
Dim ItemKey As String
Dim theLabTestKeyValue As String
Dim theLabResult As String
theChangedItems = theChangedItemsArrList.ToArray()
For Each updItem In theChangedItems
ItemKey = updItem.Key
If ItemKey.IndexOf("N*") < 0 Then
theLabItem = theLabItems.FindItem(Convert.ToInt16(ItemKey))
Else
theLabItem = Nothing
End If
If Not theLabItem Is Nothing Then
' Update
theLabItem.LabTestKeyValue = updItem.Cells("LabTestKeyValue").Value
theLabItem.LabTestResult = updItem.Cells("LabTestResult").Value
Else
' Insert
theLabTestKeyValue = updItem.Cells("LabTestKeyValue").Value
theLabResult = updItem.Cells("LabTestResult").Value
theLabRequest.RequestItems.AddLabRequestItem(theLabTestKeyValue, theLabResult)
theChangedItemsArrList.Remove(updItem)
End If
Next
End If
End If
SaveLabRequest(theLabRequest, True)
gridLabItems.DataSource = theLabRequest.RequestItems
gridLabItems.DataBind()
Catch ex As Exception
If theChangedItemsArrList.Count > 0 Then
' Save the last submitted Changes/Additions
Session("ChangedItems") = CType(theChangedItemsArrList.ToArray(), EO.Web.GridItem())
Else
Session("ChangedItems") = Nothing
End If
Me.ErrorLabel.Text = ex.Message
End Try
Catch ex As Exception
gridLabItems.DataSource = theLabRequest.RequestItems
gridLabItems.DataBind() ' to Make sure the Grid is Synchronized with the Datasource.
Me.ErrorLabel.Text = "Unexpected Error while saving the new changed items for next post-back: " & ex.Message & "<br/>" & ex.StackTrace
End Try
End Sub
Protected Sub btnSaveLabItems_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSaveLabItems.Click
Dim theLabRequest As LabRequest
theLabRequest = GetLabRequest()
ApplyGridChanges(theLabRequest)
End Sub
I have tested the above logic extensively, with all possible combinations, and it looks OK so far. My question: Is this a normal approach ? Appreciate your feedback, if possible. Tarek.
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,194
|
Hi,
Yes. This looks correct. Another way is to use a hidden column. You can add an additional column to the grid and then set that column's Visible to false. Then use that column's value to keep track of which item needs to be saved. The advantage of that method is you don't need to keep a map between key and items. However you will still need to check ChangedItems, AddItems and update the hidden column value accordingly. So it may not be much easier. The bottom line is the Grid fires change event only once. This is very much the same way as a standard ASP.NET TextBox that only fires change event once.
Thanks
|
|
Rank: Advanced Member Groups: Member
Joined: 3/27/2010 Posts: 48
|
I want to simplify repeated code segments in the above program which is searching for an item inside the "List(of type)" object. This is part of the code I want to simplify:
Code: Visual Basic.NET
For Each itm2 As EO.Web.GridItem In theChangedItemsArrList.ToArray()
If itm.Key.ToString = itm2.Key.ToString Then
' Same Key Value? Remove it !
theChangedItemsArrList.Remove(itm2)
IsItmFound = True
Exit For
End If
itm2Idx += 1
Next
I looked for such code by Google, but no much luck. Appreciate your help. Tarek.
|
|
Rank: Advanced Member Groups: Member
Joined: 3/27/2010 Posts: 48
|
I have impleted all CRUD Operations from the Grid to CSLA .NET to Database, and things are looking great so far.
Just one small issue.
After the user will complete the last save operation, and since the program is using Session Object for keeping track of failed changes/deletions ...
Then, if the user will press the Refresh Button of the Browser Window, it seems that the it will re-submit the last session object used and the last Grid Changes made.
So, How I can clear the browser request after the save ? How I can stop this behaviour ?
Tarek.
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,194
|
Hi,
This probably doesn’t have anything to do with session data. If it is just session data, you can always clear it as soon as you saved the data. Even without session as soon as you refresh a submitted a form you will get duplicate data. All browsers would warn you if you do that. You can write additional code to check this but this it will be totally up to you.
Thanks
|
|
Rank: Advanced Member Groups: Member
Joined: 3/27/2010 Posts: 48
|
Yes, as soon as I refresh, I get this warning.
I think one way to get rid of this is to do a "response.redirect()" to the same page, to clear the request object. If you can recommend any other way, I appreciate it.
Tarek.
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,194
|
Hi, Yes. You can do that. If you still have further questions about this issue, we would recommend you to research it on the Web because it is really a general Web programming issue that has nothing to do with us. As a general guideline, if a problem is general in nature and can exist without our product at all, then we consider it out of the scope of our support and will ask you to resolve it yourself. We noticed that you tend to ask whatever questions you run into while using our product no matter it has to do with our product or not. We appreciate your participating in the forum because it does provide a lot of useful information for other users. However at the same time, we would appreciate if you can understand that we only intend to support questions that are directly related to our product, so please understand that we may not be able to answer all of them (We ignored your List question for this reason). In some cases we may simply delete your question without notice if they are obviously out of scope of our support because we need to focus our resource on our product. You may also want to review our official support policy here: http://www.essentialobjects.com/forum/postst1368_Product-support.aspxThanks
|
|
Rank: Advanced Member Groups: Member
Joined: 3/27/2010 Posts: 48
|
I fully understand your policy. Initially I though this problem is due to extensive use of Session Objects to keep track of failed updates. But, I truned out that it is not related. I can understand your point of view.
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,194
|
Great. Thank you very much for your understanding!
|
|