Flex 4 data management - how do I approach this? - database

quite an explanation here, hope someone has the patience to read it through
I'm building an application in Flex 4 that handles an ordering system. I have a small mySql database and I've written a few services in php to handle the database.
Basically the logic goes like this:
I have tables for customers, products, productGroups, orders, and orderContent
I have no problem with the CRUD management of the products, orders and customers, it is the order submission that the customer will fill in that is giving me headaches:
What I want is to display the products in dataGrids, ordered by group, which will be populated with Flex datamanagement via the php-services, and that per se is no problem. But I also want an extra column in the datagrid that the user can fill in with the amount he wishes to order of that product. This column would in theory then bind to the db table "orderContent" via the php services.
The problem is that you would need to create a new order in the database first that the data could bind to (orderContent is linked to an order in the db).
I do not want to create a new order every time a user enters the page to look at the products, rather I would like to create the order when a button is pressed and then take everything from the datagrids on the page and submit it into the database.
My idea has been to create a separate one-column datagrid, line it up next to the datagrid that contains the products and in that datagrid the user would be able to enter the amount of that product he'd like to order.
I've created a valueObject that contains the data I would need for an order:
Code:
package valueObjects
{
public class OrderAmount
{
public var productId:int;
public var productAmount:int;
public var productPrice:Number;
public function orderAmount()
{
}
}
}
My idea was to use a service to get all products from a certain group, populate an ArrayCollection with the data, then transfer each object in that ArrayCollection to an instance of the Value Object above, add the value object to another ArrayCollection that would the be used as a dataProvider for the one-column datagrid (I would only display amount which would be set to zero at first, but use the other data upon transfering it to the db)
I've tried to use the results from the automatically generated serviceResults that retrieve the products for the datagrid and put in a resultHandler that transfers the valueobjects, however this does not seem to work.
Basically my question is this: Am I approaching this thing completely wrong, or is there a way I can get it to work the way I planned?
Would I need to create a completely new service request to get the product id:s, and price to populate the one-column datagrid.
I'll post some code if that would help.
Thank you if you read this far.

Solved it by creating a Value Object class to hold all the info needed for each row in the grid and from the php service that returned all products in a group, I looped through the result and transfered the data needed into my Value Object.
I then added each Value Object into an ArrayCollection and made that the dataProvider for the dataGrid.
No need to use two grids. I forgot how logic things get when you think of datagrid data just as an ArrayCollection and forget the visual presentation of it on screen.
Put in a few itemRenderers and the whole thing is beautiful!

Related

ExtJS synchronize record between clients

I'm trying to do something fun: I'd like to send the record changes from one client to another and have the second client updated to show these changes. Basically collaborative viewing. The second client is disabled from making changes, he can only watch.
Simple fields like strings, numbers, checkboxes, etc. are easy, that worked right away.
The references are the problem. If I have a combo that uses another model as it's source, I am unable to update it on the second client.
I tried setting just the id, then the entire referenced object, I tried various set options, but simply no dice.
The record does change, I see that the data is updated, I was even able to manually modify the _ reference attributes, but the UI keeps showing the old values for those fields.
Is there a way to send the record from one client to another and have the other client just take over all values and display them in the UI? (it would be better to send just the changes, but I'd be very happy if I could get it to work with the entire record)
EDIT: I'm using SailsJS with socket.io, so the p2p connection is not the issue.
I'm getting the data like this:
var data = record.getData(true);
broadcastRecord(data);
And on the other side I tried:
record.set(data);
A code example for the receiving side would be appreciated, if anyone has an ide how to solve this...
I think your problem is related to associations and comboboxes.
Let's say you have a model User with a field group that references model Group, and that you have a User form with a Group combobox.
In the receiver client, you are probably getting only the group id. record.set(data) updates the bound combobox calling setValue(groupId).
This setValue will try to find the corresponding record inside its store, but it won't ask server-side for that record. Instead, it will create a new record with the passed id (showing an empty combobox).
If possibile, you can set remoteFilter:false to the store and queryMode:'local' on the combobox and preload all the data from that store.
Otherwise, I think you'll have to override the combobox setValue method to get the record remotely.

How to save child properties?

Breeze & Angular & MV*
I get an invoice object and expand it's necessary properties: Customer, Details, etc.
To access detail properties is easy, invoice.detail[n].property. And saving changes to existing properties (1 - n) is also easy. In my UI, I simply loop through my object vm.invoice.details to get & display all existing details, bind them to inputs, edit at will, call saveChanges(), done!
(keep in mind, in this UI, I need to complete the following too....)
Now, I have blank inputs for a new detail I need to insert.
However, I need to insert a new detail into the existing array of invoice details.
For example: invoice #5 has 3 details (detail[0], detail[1], detail[2]). I need to insert into this existing invoice, detail[3], and call saveChanges()
I've tried to call the manger.createEntity('invoice') but it complains about FK constraints. I know you can pass values as a second argument in createEntity('obj', newvalues)...but is that the correct and only method?
Seems like this should all be much easier but, well, I am at a loss so, please help where you can. TIA!
Take a look at the DocCode sample which has tests for all kinds of scenarios including this one.
Perhaps the following provides the insight you're looking for:
function addNewDetail() {
var newDetail = manager.createEntity('Detail', {
invoice: vm.currentInvoice,
... other initial values
});
// the newDetail will show up automatically if the view is bound to vm.details
}
Notice that I'm initializing the parent invoice navigation property. Alternatively, I could just set the Detail entity's FK property inside the initializer:
...
invoiceId: vm.currentInvoice.id,
...
Either way, Breeze will add the new detail to the details collection of the currentInvoice.
Your question spoke in terms of inserting the new Detail. There is no need to insert the new Detail manually and you can't manage the sort order of the vm.currentInvoice.details property any way.
Breeze has no notion of sort order for collection navigation properties.
If you need to display the details in a particular order you could add a sorting filter to your angular binding to vm.currentInvoice.details.
Make sure you have correct EntityName, because sometimes creating entity is a not as simple as it seems.Before working with entities see
http://www.getbreezenow.com/documentation/creating-entities
I will suggest you to look ur metadata file, go to last line of your file, you can see the field named "entitySet"
"entitySet":{"name":"Entity_Name","entityType":"Self.Entity_Name"}
check the entityName here i took as "Entity_Name" and then try to create the entity and use this name
manger.createEntity('Entity_Name');

Populating a field in wpf

I have a database of finance info and i want to check that supplied totals 'add up'. I have added fields to the database for the check data and am using data binding via the Entity Framework. How do i populate these 'check' fields while the user is adding data to the record?
Eg The form contains SubtotalA, SubtotalB and TotalAB textboxes. The database has these fields plus CheckTotalAB. The user keys in SubtotalA, SubtotalB and TotalAB from a hard copy form. I want to populate CheckTotalAB with the sum of SubtotalA and SubtotalB to compare against the provided TotalAB.
I first tried getting the data from the textboxes. Unfortunately txtSubtotalA.Value doesn't exist.
I then thought I'd have to go to the entity itself. Unfortunately I don't know how to access the current record/entity being entered and if I did, how would I access the value of fields that haven't been saved yet.
Can someone point me in the right direction?
tia
mcalex
Accessing the entity was the answer. This was accomplished through use of an entity property in the datacontext that i set to equal a class member i added to my form class.
After that getting to the entity's fields including my calculated fields was just a case of getting/setting the member's properties.

Loading dropdownlists

what is the best way to load dropdown lists from reference/lookup tables for a desktop application?
the application is layed out into 3 tiers. I've built up my entities.
the front end has a form with 6 tabs. and one big save (another discussion :)
Should I load them all when the form is initially loaded? Are there any caching mechanisms I could use?
it is vb.net app on a network drive that is accessed by several users.
it's also worth noting that some reference tables may be updated. Via another form.
thanks
T
Lots of factors. One you need to populate in constructor so the data is there to populate the visual elements. Beware that just because a tab is not visible does not mean it is not loaded when you app starts.
For a static list of strings
public class Library : INotifyPropertyChanged
{
private List<string> dropDown1;
public List<string> DropDown1 { get { return dropDown1; } }
public Library()
{
// use data reader to populate dropDown1
}
}
I know this will get comments that can use something lighter than a List but List has a lot of nice features, easy syntax, and easy to populate. As a next step you could structure as a client server and use some static so the list is populated once and then shared by all. If you have more properties then substitute string with a class. For a dynamic list then in the get you grab the current data from the table on demand. In your get you could hold on to the last list and if the next request is within X seconds then return stale data. It depends on if stale data is acceptable.
There are many other approaches and I do not pretend this is the best. Just putting out a relatively simple example to get you started.
When it gets to hierarchical then things get a little more complex. There you can use ADO.NET table to store the static dependent data and then apply a filter on a view.
If its a web page you don't have to load all tabs on page load.
Desktop i think it will be more easy and it should be like that.
Only when the user click on the tab show the page and hide all the pages
associated for other tabs.
i hope all tab pages values will be on session so that user can go and come back to any tab and your Big Save at last.
Something useful related to your question i found here
http://www.syncfusion.com/FAQ/windowsforms/faq_c93c.aspx
and one more

RIA Services get list of entities

I am working on a Silverlight application using RIA services with Entities Framework.
Forgive me, i'm fairly new with Ria services, but how do i go about getting a list of objects from the db without doing a load operation?
Example: I have an Employees table, in this table there's a IsSupervisor flag. I want to show a list of employees in a grid with a combobox cell bound to a list of supervisors (employees where isSupervisor = true).
The problem i have is that when the list of supervisors come back, the employee list only displays supervisors.
I hope this makes sense....
It's hard to really say without seeing your code, as RIA Services is pretty darn flexible.
It sounds like you are binding a DataGrid to your DomainContext's Employee EntitySet, and then making two calls to the server, one to get all employees, then one to get supervisors. If this is the case then yes your second call can wipe out the first one (depends on how you have LoadBehavior set).
But if you are querying the db to get all employees, then you already have the supervisors on the client side. Just create a separate collection that only contains the supervisors, and bind the ComboBox to this. Something like:
private void OnEmployeesLoaded(LoadOperation<Employee> loadOp) {
if(!loadOp.HasError) {
Employees = new List<Employee>(loadOp.Entities);
Supervisors = new List<Employee>(loadOp.Entities.Where(e => e.IsSupervisor));
}
}

Resources