AS3 Custom Event Best Practices Questions (Opinions) - actionscript-3

I'm just curious how a lot of you handle custom events.
My custom event/s that I will be creating pertain to creating and displaying views. I want to have two separate events dispatched, one to create the view and then one to display the view. I'd like the create a view using an ID that corresponds to the type of view to create and when displaying the view would like to pass the handler a view object to add to the stage.
I see three ways of doing this:
Create a single ViewEvent class with two event types CREATE_VIEW and DISPLAY_VIEW. The problem with a single event class is that I would like if possible to use strongly typed parameters. When using CREATE_VIEW though, I want to pass an ID that corresponds to the view to create and when I dispatch DISPLAY_VIEW I'd like to pass the view object to display. So to get them strongly typed I'd have to two optional parameters, one for viewId of type int and one for view of type DisplayObject and then test for which one exists which I don't like.
Same as number 1 except use a single generic parameter and check for it's type to see what the event's payload is which I don't like generic parameters either.
Create two separate event classes, a CreateViewEvent and a DisplayViewEvent. This would allow me to use the proper typed parameters, but it seems a little weird since both event actions are so closely related that I feel they should be within the same event class.
So the question is... in general what are everyone's views on handling a situation like this? Is there a better way to handle this?
I've run into this situation before too with other types of events, my view example is just a simple example of what I'm currently running into.

Related

Access combo box for DB mapping table 2-1 Table relation

I've run into a bit of a snag with a project I'm working on, and being new to Access I don't know if what I want to do is possible without VBA. I've looked around but all I can find are answers related to showing multiple columns, not controlling multiple fields in my DB.
To paint a picture I have a mapping system set up in my DB to help me distinguish the name and type of data is held in a table.
The setup is as follows:
-Data table is "LineItems" with an ID and the line data (think typical excel format)
-Mapping table is "LineItem_Mapper" with LineItem_ID, DataType, and Entity_ID
-A helper table "Data_Type" with ID and Name
-two "Entity" tables with differing properties both have ID and Name
The reason for the split is on data type is that the two types of data behave differently. One type has a parent child relation, and the other is a standalone row. I want to preserve this structure in my DB and feel I have done so with this mapping.
Now, on to the issue I'm running into. In my Access data entry form I want to use a combo box, as the options a user may chose for each line when entering are finite. However, this combo box is affecting the Mapping table above. I have been able to populate the box with my desired list with a custom query built from my 2 entity tables, but I don't know how to get Access to create or update the Mapping table using this box.
what I want to happen is when I chose something in the box, a line is created (or changed) in the mapping table with all 3 columns being populated. first the LineItem_ID for the line I am populating, and then the DataType and Entity ID to reflect the proper mapping.
Can Access do this on its own? Or do I need to do this with VBA?
As requested by the OP converting my commend as an answer (with a little bit more detail):
By far your best option is to use VBA. I doubt there is another way and even if there is it would be so convoluted it would be unworkable and unmanageable.
This should get you started:
In the combo box properties go tot the events tab and in After Update or On Change (look up the difference between the two events to see which behavior you prefer) click the down arrow and select [Event Procedure], then click on the … button. This will create a VBA module for you complete with the function that runs when the selected event is triggered.
You can use DoCmd.RunSQL "[Access SQL INSERT statement]" to add records to tables.
You can use Me.[MyComboBoxName] to get the current value of the combo box. Similarly the value of anything else in your active form.
You can use DLookup to get the value of any record in your tables.
Hopefully these will give you a relatively quick start.

Symfony/Doctrine - Query to Set/Change the Value for a Field when Selecting an Entity

[Usage: Doctrine 2.6, Symfony 2.7]
Using Doctrine queryBuilder or straight DQL, how can I set a value for a field of an entity that is selected, or otherwise change or manipulate the value of a field that is returned BEFORE the postLoad event listener is called?
Background
As a simplified description of my context, I have an entity view that can be associated with a ton of different "Content Type" entities, so it doesn't (can't) have a direct doctrine association. But I usually want that other entity to be loaded and attached to view->content property. So I have a postLoad listener that automatically checks what type of content it is, and loads it from the right entity if content hasn't been loaded already.
I usually want this to happen automatically, but if I get an array of views this lazy loading is too inefficient (too many database calls), so in those cases I want to fetch the content separately in a more efficient way after I get the results back (not in the postLoad listener one entity at a time). Which means I need to tell the listener to ignore it's usual automatic loading. I can do this easily if I am able to pre-populate that field with a TRUE value (so the listener thinks it's already loaded and doesn't try to fetch it automatically.
Pseudo Idea for Solution
So what if when I create my query that fetches a list of views I make doctrine fill that field with a default value of 1. In MySQL that is easy, just:
SELECT *, 1 AS `content` FROM `view`;
NOTE: This unfortunately doesn't actually set the value of view.content, it just appends an alias called content...
While content is a property in the view entity, it is not a persisted property, so there is no database field for that property. But I could make it persists (just as a placeholder). Let's say I do that, I still can't figure out how to manipulate the value that gets returned (always empty in the database) and pre-fill it with a 1 whenever I want to notify the postLoad Listener to ignore the auto loading.

Backing an actionscript DataGrid

I am trying to implement the model for a DataGrid. The documentation:
http://help.adobe.com/en_US/flex/using/WS0ab2a460655f2dc3-427f401412c60d04dca-8000.html#WS0ab2a460655f2dc3-427f401412c60d04dca-7fff
indicates that I need to use an implementation of IList which contains rows. What the docs do not indicate however is what interface I need to use to implement a row class. The examples are all in XML, which suggests static content.
What I need is a row implementation that can receive changes from the underlying model and provide them to the DataGrid, and likewise, receive changes from the DataGrid and provide them to the underlying model.
The documentation you cite suggests using an ArrayList class as one of the possible implementations of IList as a data provider. And the ArrayList manual states that the row class is plain Object, and all the property change handling and notification is done within ArrayList instance using its methods for add, update, delete and set index operations. So, either use this class, or ArrayCollection, or write your own IList implementation that will handle data update notification process in itself, without referring to row class.
I also think that making row class update its container list is rather pointless, because rows are designed to be just data, without any "sanity", and lists are what actively process that data, including reordering, sorting, filtering and so on. Thus, adding such a functionality to row class overturns this (working) model, thus is not needed.

customize initial data issue and solution

I want to design an object for loading and showing customized data, for example, the object firstly loads all employees in database, then look up whether login user in the list, if so then show the login user, otherwise show dummy data "all employees"(means null). But another scenario is the component should "remember" last time user selected data and show in another page, any good design suggestion?
You describe four major pieces of function:
checking the user against a list
identifying one of two scenarios
remembering selected data
using the remembered selected data
Overall I don't think you've decomposed the problem enough yet to start thinking about design patterns - patterns become important once you've identified some candidate classes and start to look at how to decouple them. So my next step would be to design some classes to do these 4 tasks and then critically example the resulting Object model, see whether refinement is needed. THe first step: identify classes with clear interfaces and responsibilities.

How do I use LINQ to SQL with stored procedures returning multiple result sets without ORM?

http://blogs.msdn.com/b/dditweb/archive/2008/05/06/linq-to-sql-and-multiple-result-sets-in-stored-procedures.aspx
Similar to this link however the project I'm working on doesn't use the ORM component of LINQ to SQL (we use it more for quickly generating the ADO.Net interface to the db).
Currently, the pattern we follow is:
var result = myDataContext.GetAllCustomersAndOrders();
And the stored procedure looks like this:
Are there extra steps I need to take? Do I need to extend the generated dbml or the data context partial class file?
Hopefully this makes sense... It's a bit difficult to explain and all the examples I've found use the ORM piece of the dbml (dragging and dropping tables onto the dbml designer surface).
Yes, you can do this, but i will require creating a partial class for your dbml.
So, if your dbml file is MyLinqToSQL.dbml
open the dbml designer
drag the SP onto the design surface
save
and then press F7.
This will create a partial class of MyLinqToSQL.cs.
Now...
open the auto-generated MyLinqToSQL.designer.cs
copy the access method with the same name as the SP (the one you want to return multiple sets from.)
Insert this into the body of the partial class in MyLinqToSQL.cs you just created.
change the name of the method to something at least slightly different
change the return type from ISingleResult to IMultipleResult.
decorate your new class with System.Data.Linq.Mapping.ResultType attributes to define your return set types.
All of the resultsets will be returned in a single collection of IQueryable.
You can then use reflection to determine the type of each collection item and then cast them for use.
See http://kishor-naik-dotnet.blogspot.com/2011/12/linq-multiple-result-set-of-procedure.html