Bill Cunnien
|
|
Group: Forum Members
Posts: 785,
Visits: 3.6K
|
When I attempt to filter a BO on a custom property, the debugger tells that the specified column does not exist. It is true that it cannot be found in the DB, but it is on the BO. Is there a trick to filtering on a custom property? Thanks, Bill
|
|
|
Greg McGuffey
|
|
Group: Forum Members
Posts: 2K,
Visits: 6.6K
|
Some more thoughts (do I smell something burning?)....  The second option is basically the first, just using a method to do the walking and loading, rather than the custom property...probably won't be any good in your situation either. I'd also try to find out why it takes so long...maybe there is something you could do to speed it up. Unless the data set is very large and/or the computation very complicated, this should be fast. For the third option, if you are using SQL Server 2005, consider a CLR sproc. You program in the .NET language of choice (C# for you I believe) and they tend to be fast. You likely could get a several minute process down to milliseconds. Search the forum for CLR stored procedures, there are some good posts about them by the SF team. While I agree that placing code in BOs is the way to go, when I need speed for a data intensive process, I use SQL Server. Now, sometimes, I can get the SQL Server joy AND put the code in the BO. That command object can accept any sort of SQL. I.e. you can do the work on SQL server but put the code (SQL script) in your BO. This won't be as fast as a sproc (the execution plan isn't precompiled and cached on SQL Server), but might do the trick. If your custom properties aren't showing up, my first guess would be that you forgot to setup the custom property descriptors, but I'm still a newbie when it comes to grids so not sure if they are used in that case...  Good luck and remember to wear your fire retardant pants!
|
|
|
Trent Taylor
|
|
Group: StrataFrame Developers
Posts: 6.6K,
Visits: 6.9K
|
Bill, I think that you are trying to make this too complicated. I think that I would first backup and then start rethinking through your process. First, we use custom columns as aggregates OR create a custom property that dynamically returns aggregates a lot. Now since you are trying to apply a filter, then you will most likely want a column in the data table. OK. Since we have that established, from what I can understand, you always want to have a calculated column within your data table. So obviously if you perform a query, then you can do this as part of the query (easier and faster in some cases). However, if you will have a scenario that will not retrieve data from a database query first, then you would need to ensure that the column gets manually added prior to being refrenced or accessed. So in this case, I would do one of two things to ensure that the column exists within the BO. - Override the OnAfterAddNew method of the BO and ensure that the desired columns get added within the BO and/or exist when a new record is added. This way a query is not required, but when you add a new record the BO will ensure that the column exists.
- Override the OnCurrentDataTableRefilled method of the BO and call the same logic that is added as part of the OnAfterAddNew method.
By doing the above two things you will always be ensured that you have the column within your data table, thus allowing a filter to be applied. At this point, you will just create the custom property on the BO to access it through the strong-typed reference, but you can then treat this column just as though you could any other column that comes from the database, however, it just resides within the BO.
|
|
|
Trent Taylor
|
|
Group: StrataFrame Developers
Posts: 6.6K,
Visits: 6.9K
|
One other point that I saw in regards to your grid...if you do not have a custom property descriptor setup, it will not show up in a grid. You will need to override the GetCustomBindablePropertyDescriptors method on the BO and provide a ReflectionPropertyDescriptor.
|
|
|
Bill Cunnien
|
|
Group: Forum Members
Posts: 785,
Visits: 3.6K
|
Here is my actual custom property code. Please criticize at will. I have no other code reviewer here. There has got to be something fundamentally wrong with what I am doing so that none of the custom properties values are showing up in a DevEx XtraGrid (via BBS). I have done this with several other BOs so the process is not new to me. From these custom properties, I would like to filter the grid on the spxRequiredQty value. Somehow, I have to tell the underlying table of the BO that the column exists and what the data actually is (without resorting to stored procs and such). I know I am being difficult with this. I have tried so many things that all of this is becoming a blur. I have read through this thread several times, but just cannot see the light. Thought I did a few times, but it was just that proverbial debug train coming at me through the tunnel of code exceptions. Bill P.S. Still using SQL Server 2000.
|
|
|
Ivan George Borges
|
|
Group: StrataFrame MVPs
Posts: 1.9K,
Visits: 21K
|
Hey Bill. Just in case it might help you see what Trent told you about adding a new field to your table and filtering on it, here is some code of mine where I do exactly the same, filtering on a field that doesn't exist on the underlying table. On your BO: Private Sub MyBO_CurrentDataTableRefilled() Handles MyBase.CurrentDataTableRefilled If Me.CurrentDataTable.Columns.Contains("myField") = False Then Me.CurrentDataTable.Columns.Add("myField", System.Type.GetType("System.Boolean")) End If End Sub Private Sub MyBO_CurrentDataTableInitialized() Handles MyBase.CurrentDataTableInitialized If Me.CurrentDataTable.Columns.Contains("myField") = False Then Me.CurrentDataTable.Columns.Add("myField", System.Type.GetType("System.Boolean")) End If End Sub
And, of course, the property: <Browsable(False), _ BusinessFieldDisplayInEditor(), _ Description("My property"), _ DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> _ Public Property [myFieldProperty]() As Boolean Get Dim loValue As Object loValue = Me.CurrentRow.Item("myField") If loValue Is DBNull.Value Then Return False Else Return CBool(Me.CurrentRow.Item("myField")) End If End Get Set(ByVal value As Boolean) Me.CurrentRow.Item("myField") = value End Set End Property Protected Overrides Function GetCustomBindablePropertyDescriptors() As MicroFour.StrataFrame.Business.FieldPropertyDescriptor() '-- Create and return a new array of FieldPropertyDescriptor ' objects that contains the ReflectionPropertyDescriptor ' for the cas_Idade field. Return New MicroFour.StrataFrame.Business.FieldPropertyDescriptor() { _ New MicroFour.StrataFrame.Business.ReflectionPropertyDescriptor("myFieldProperty", GetType(MyBO))} End Function
So, now, on my logic, after setting my field depending on conditions: '-- applies the filter Me.MyBO1.Filter = "myField = True"
Hope it helps in some way...
|
|
|
Greg McGuffey
|
|
Group: Forum Members
Posts: 2K,
Visits: 6.6K
|
Bill, You might try doing something real simply like just returning a constant, bypassing all the code in you properties to see if that works. i.e. public decimal spxSalesOrderQty
{
get
{
// just skip the rest for now
return 1;
decimal mSOQty = 0;
...rest of code untouched
}
}
If this works, then it has something to do with the property code. If it doesn't, then is has to do with the properties themselves or how the grid is using those properties.
|
|
|
Bill Cunnien
|
|
Group: Forum Members
Posts: 785,
Visits: 3.6K
|
Paul: I have a very similar setup on my InvoiceBO with the [invoicetotal] field. It is a custom property and displays nicely on a grid via a BBS. I am mimicking much of what I did there within this current BO. Greg: I returned only a constant and the value still are not showing up in the grid. Disturbing. For some reason, as Paul is alluding to, the BBS is not picking up these values and passing them to the grid. Guys...thanks for all of the help. I am hitting the 24 hour mark on this current problem. Hopefully, it will get resolved soon. Btw, I have eliminated any column adding and filtering options...I need to get the data flowing first to the grid. I will go from there once that is back in business.
|
|
|
Trent Taylor
|
|
Group: StrataFrame Developers
Posts: 6.6K,
Visits: 6.9K
|
BILL, if you would read my previous post, there is ONLY one reason it would not show up in a grid through a BBS. You are missing a property descriptor for the custom property...period! You may be dealing with post and information overload, but this is not an overly complicated process or problem...when I run into something like this it is generally due to frustration and dealing with the same problem over a period of time. There is a lot of good information in this thread...but first things first, I had posted explaining how to ensure the column always exists within the CurrentDataTable. Secondly, I have told you the one and only reason why a custom property would not be visible through the BBS. Please check and refer to these two points and I am sure that you will see where your problem is.
|
|
|
Trent Taylor
|
|
Group: StrataFrame Developers
Posts: 6.6K,
Visits: 6.9K
|
Also, if you read Ivan's post, he has posted some code that shows an example of how to setup the basic structure of this custom property. If you backup and start with his code, you are going to be a long way down the road.
|
|
|
Bill Cunnien
|
|
Group: Forum Members
Posts: 785,
Visits: 3.6K
|
Trent L. Taylor (06/26/2008) Also, if you read Ivan's post, he has posted some code that shows an example of how to setup the basic structure of this custom property. If you backup and start with his code, you are going to be a long way down the road.Were you able to review the code that I posted? Other than the initialize and refilled code, I didn't think I was that far off. Maybe I am. At this point, I am just wanting a simple value to show up in the grid from a custom property. Not even worried about filtering for now.
|
|
|
Paul Chase
|
|
Group: Forum Members
Posts: 414,
Visits: 2.8K
|
If your customer property work's fine with textbox's but not with a BBS then what does that tell you?
|
|
|
Bill Cunnien
|
|
Group: Forum Members
Posts: 785,
Visits: 3.6K
|
Paul Chase (06/26/2008) If your customer property work's fine with textbox's but not with a BBS then what does that tell you?I am focusing on the BBS, as mentioned in an earlier post (following Greg's suggestion to return a constant). My biggest issue is why the code works for one grid and not another. Both have BOs with custom properties flowing through a BBS to the grid. I'll continue to grind it out on my own. Apparently, I have worn y'all out with this one. Sorry about that, Bill
|
|
|
Ivan George Borges
|
|
Group: StrataFrame MVPs
Posts: 1.9K,
Visits: 21K
|
Hey Bill. Don't even know wether this would make a difference or not, but had a look at your code and couldn't see the "OnSalesOrder" property defined (which you create a Descriptor for)... I guess you just didn't post it, is that so?
|
|
|
Bill Cunnien
|
|
Group: Forum Members
Posts: 785,
Visits: 3.6K
|
Thanks for reviewing the code, Ivan. Yup, just left it out, since I am replacing it with the newer properties that I shared with you.
|
|
|
Bill Cunnien
|
|
Group: Forum Members
Posts: 785,
Visits: 3.6K
|
I thought I would try to wrap up this thread with a play-by-play of what I did to solve the problem. Thanks everyone for all of the help!
1) Added code to the CurrentDataTableInitialized and CurrentDataTableRefilled (per Trent and Ivan) if (CurrentDataTable.Columns["spxInventoryQty"] == null) { CurrentDataTable.Columns.Add(new DataColumn("spxInventoryQty", typeof(decimal))); } 2) Altered the custom property to a basic structure (no reference to the new column) [<snipped>] public decimal InventoryQty { get { decimal mInvQty = 0; // calculate the amount on hand (pending) mInvQty = this.onhandqty; // use the invalid value for now (for testing) return mInvQty; } } 3) Filled the BO that applies a similar filter to what I wanted in the BO (removed that part of the problem entirely) 4) Set all new data column values to the existing value of the custom property (note: using the various code supplied in this thread, the best I could do was fill the first row with data from the custom properties...the rows' column data mostly stayed empty) private void SetColumnValues() { foreach (PartsBO mBO in partsBO1.GetEnumerable()) { partsBO1.CurrentDataTable.Rows[partsBO1.CurrentRowIndex]["spxInventoryQty"] = partsBO1.InventoryQty; } } 5) Create a dataset from the CurrentDataTable(s) to be the data source for the DevEx Grid (necessary for the master/detail gridviews, BBS bypassed) DataSet ds = new DataSet(); ds.Tables.Add(partsBO1.CurrentDataTable); ds.Tables.Add(salesOrderDetailsBO1.CurrentDataTable); ds.Relations.Add("SalesOrders", ds.Tables[0].Columns["partindex"], ds.Tables[1].Columns["partindex"], false); PartsGridControl.DataSource = ds.Tables[0]; PartsGridControl.LevelTree.Nodes.Add("SalesOrders", SalesOrderView); PartsGridControl.RefreshDataSource();
There are a couple of outstanding issues...the main one is that once I set a column's value in the CurrentDataTable the row is now dirty and the BO wants to save whenever I exit the window. I will do some searching on how to prevent saves in this situation. I am sure it has been covered in the docs or other forum entries. The secondary one is that the lookup data in the related sales order grid (e.g. customer name, unit description, etc.) is always empty. Since this is new water for me, I will do my due diligence and research the DevEx grid more throroughly and come up with a solution. Thanks, again, for everyone's help! Naturally, if anyone sees something that may help me improve things, feel free to let me know. Have a great day! Bill
|
|
|
Ivan George Borges
|
|
Group: StrataFrame MVPs
Posts: 1.9K,
Visits: 21K
|
Glad you got it going, Bill!  There are a couple of outstanding issues...the main one is that once I set a column's value in the CurrentDataTable the row is now dirty and the BO wants to save whenever I exit the window. Not sure this is the recommended way, I'm sure you will be adviced against it if not. Have you tryed issuing a SAVE right after you modifiy all your custom field values? This is what I'm doing, anyway!  As this column is not part of your table, nothing will happen to it, I suppose.
|
|
|
Bill Cunnien
|
|
Group: Forum Members
Posts: 785,
Visits: 3.6K
|
Since the form's purpose is to display information only, I set the AutoShowSaveChangesMessage on the maintenance form to 'false.' That took care of it.
|
|
|
Bill Cunnien
|
|
Group: Forum Members
Posts: 785,
Visits: 3.6K
|
 The three columns (which are blank) are dragged from the available columns in the BBS to the layout of the grid. All three are read-only custom properties that return a constant (3, 2, 1, respectively; no complex logic, at all, per Greg). I have done nothing else. You can see from my attached code earlier that I indeed have the proper ReflectionPropertyDescriptors set for each custom property. Otherwise, these properties wouldn't even be seen by the grid design tool via the BBS. I'll re-re-re-read everything, Trent. I am not ignoring anyone's counsel. I have acted on every part. (I haven't found any towels, yet) Bill
|
|
|
Paul Chase
|
|
Group: Forum Members
Posts: 414,
Visits: 2.8K
|
Bill, Try taking the business binding source out of the equation, just throw a few text boxes on a form bound to your business object custom properties fill it and navigate through your record set and see if it works. The business binding source can create some serious migraine style headaches as it creates a new instance of the business object for each row so some things that have been set in the original BO are not longer "set" in the newly created bo.. Try it withough the BBS and see if your logic works. If it works without the BBS in the middle then you can play doctor with the BBS source code and create a BBS specific to the business object you are binding to. Paul
|
|
|
Bill Cunnien
|
|
Group: Forum Members
Posts: 785,
Visits: 3.6K
|
With the textboxes, the values are showing up properly as I navigate through the BO. The grid has a BBS datasource that points to the exact same BO. All of the fields in the grid are blank. (preparing to look for a towel to throw in)
|
|
|
Bill Cunnien
|
|
Group: Forum Members
Posts: 785,
Visits: 3.6K
|
Hi Ivan, Thanks for the input. The only real difference is that my properties are read-only; therefore, no set portion. I have done exactly what you did...except I did not put the add column code in both methods of the BO (initialize and refilled). I will try that. Bill
|
|
|
Paul Chase
|
|
Group: Forum Members
Posts: 414,
Visits: 2.8K
|
That is good, if it work's without the BBS then you know it is a BBS issue and not a business object issue. What happens when you use a BBS is that it creates a new instance of the busines object for every row. However it does not carry over any custom properties etc that are to the new instance.for instance if you have a property called foo in you business object and its value has been set to "Something" what the business binding source create a new instance of the Bo for that row the property foo's value with be nothing. If that is what is happening then you can fix it by creating a BBS that is customized to your business object type. If you rthink this is where your problem is i can send you a copy of one I modified. Paul
|
|
|