Advertisement

08.05.2008 at 11:56AM PDT, ID: 23623381
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

8.2

Need to click a datagrid row to populate a form - code included

Asked by Anthony_Harris in ActionScript, PHP and Databases, Adobe Flex

Tags: , , , , ,

So I have this datagrid that is working great, pulling from MySQL with PHP. I even am able to edit directly in the datagrid, which is great. However, The table I am pulling from, employees, is very detailed and what I want to do to conserve space is have either the datagrid I have now or a combobox with the employees that populates the full employee data into the formatted employee info form when a record is selected. I am able to populate over but only what is displayed in the datagrid, and I dont have room to display everything. I have code below. I'm just starting with Actionscript, so I'm sure this is something simple that I don't have the experience to know. I've included my .as file to show whats going on behind the scenes.Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192:
193:
194:
195:
196:
197:
198:
199:
200:
201:
202:
203:
204:
205:
206:
207:
208:
209:
210:
211:
212:
213:
214:
215:
216:
217:
218:
219:
220:
221:
222:
223:
224:
225:
226:
227:
228:
229:
230:
231:
232:
233:
234:
235:
236:
237:
238:
239:
240:
241:
242:
243:
244:
245:
246:
247:
248:
249:
250:
251:
252:
253:
254:
255:
256:
257:
258:
259:
260:
261:
262:
263:
264:
265:
266:
267:
268:
269:
270:
271:
272:
273:
274:
275:
276:
277:
278:
279:
280:
281:
282:
283:
284:
285:
286:
287:
288:
289:
290:
291:
292:
293:
294:
295:
296:
297:
298:
299:
300:
301:
302:
303:
304:
305:
306:
307:
308:
309:
310:
311:
312:
313:
314:
315:
316:
317:
318:
319:
320:
321:
322:
323:
324:
325:
326:
327:
328:
329:
330:
331:
332:
333:
334:
335:
336:
337:
338:
339:
340:
341:
342:
343:
344:
345:
346:
347:
348:
349:
350:
351:
352:
353:
354:
355:
356:
357:
358:
359:
360:
361:
362:
363:
364:
365:
366:
367:
368:
369:
370:
371:
372:
373:
374:
375:
376:
377:
378:
379:
380:
381:
382:
383:
384:
385:
386:
387:
388:
389:
390:
391:
392:
393:
394:
395:
396:
397:
398:
399:
400:
401:
402:
403:
404:
405:
406:
407:
408:
409:
410:
411:
412:
413:
414:
415:
416:
417:
418:
419:
420:
421:
422:
423:
424:
425:
426:
427:
428:
429:
430:
431:
432:
433:
434:
435:
436:
437:
438:
439:
440:
441:
442:
443:
444:
445:
446:
447:
448:
449:
450:
451:
452:
453:
454:
455:
456:
457:
458:
459:
460:
461:
462:
463:
464:
465:
466:
467:
468:
469:
470:
471:
472:
473:
474:
475:
476:
477:
478:
479:
480:
481:
482:
483:
484:
485:
486:
487:
488:
489:
490:
491:
492:
493:
494:
495:
496:
497:
498:
499:
500:
501:
502:
503:
504:
505:
506:
507:
508:
509:
510:
511:
512:
513:
514:
515:
516:
517:
518:
519:
520:
521:
522:
523:
524:
525:
526:
527:
528:
529:
530:
531:
532:
533:
534:
535:
536:
537:
538:
539:
540:
541:
542:
543:
544:
545:
546:
547:
548:
549:
550:
551:
552:
553:
554:
555:
556:
557:
558:
559:
560:
561:
562:
563:
564:
565:
566:
567:
568:
569:
570:
571:
572:
573:
574:
575:
576:
577:
578:
579:
580:
581:
582:
583:
584:
585:
586:
587:
588:
589:
590:
591:
592:
593:
594:
595:
596:
597:
598:
599:
600:
601:
602:
603:
604:
605:
606:
607:
608:
609:
610:
611:
612:
613:
614:
615:
616:
617:
618:
619:
620:
621:
622:
623:
624:
625:
626:
627:
628:
629:
630:
631:
632:
633:
634:
635:
636:
637:
638:
639:
640:
641:
642:
643:
644:
645:
646:
647:
648:
649:
650:
651:
652:
653:
654:
655:
656:
657:
658:
659:
660:
661:
//Anthony Harris: This is the component mxml file
<?xml version="1.0" encoding="utf-8"?>
<mx:ViewStack xmlns:mx="http://www.adobe.com/2006/mxml" width="800" height="600" creationComplete="initApp()">
  <mx:Script source="employeeScript.as" />
 
	<!--
		The tags below define the application's UI components and their initial properties.
		Every tag can be accessed in ActionScript via its "id" property, similar to HTML tags
		accessed via JavaScript.
		Note that unlike HTML, Flex does not use a flow-based model.  With the exception of
		some containers, Flex controls are positioned on the page using their width and height
		properties, so the order of the tags in the file does not affect the layout.
	-->
	<mx:ViewStack id="applicationScreens" width="869" height="100%">
		<mx:Canvas id="view" width="100%" height="100%">
 
		<!--
			This DataGrid is bound to a data provider, the object "dataArr" which is
			instantiated in the included script file.  In general, data providers are collections
			such as Array, ArrayCollection, XMLObject, etc. that are declared with the [Bindable]
			tag and set as the "dataProvider" property of a UI component.  When the data in
			a data provider changes, Flex will automatically update any bound UI components
			with the new data.
		-->
		<mx:DataGrid id="dataGrid"
			dataProvider="{dataArr}"
			rowCount="8"
			editable="true"
			resizableColumns="true" 
			headerRelease="setOrder(event);"
			right="431" left="10" top="28" bottom="360">
				<mx:columns>
					<mx:DataGridColumn headerText="Employee ID" dataField="empidCol" />
					<mx:DataGridColumn headerText="Last Name" dataField="emplnCol" />
					<mx:DataGridColumn headerText="First Name" dataField="empfnCol" />
					<mx:DataGridColumn headerText="empmi" dataField="empmiCol" visible="true" />
					<mx:DataGridColumn headerText="empsfx" dataField="empsfxCol" visible="false" />
					<mx:DataGridColumn headerText="empssn" dataField="empssnCol"  visible="false"/>
					<mx:DataGridColumn headerText="empdob" dataField="empdobCol"  visible="false"/>
					<mx:DataGridColumn headerText="empdl" dataField="empdlCol"  visible="false"/>
					<mx:DataGridColumn headerText="empdlst" dataField="empdlstCol" visible="false" />
					<mx:DataGridColumn headerText="empstreet1" dataField="empstreet1Col" visible="false" />
					<mx:DataGridColumn headerText="empcity1" dataField="empcity1Col" visible="false" />
					<mx:DataGridColumn headerText="empapt" dataField="empaptCol"  visible="false"/>
					<mx:DataGridColumn headerText="empst1" dataField="empst1Col"  visible="false"/>
					<mx:DataGridColumn headerText="empzip1" dataField="empzip1Col"  visible="false"/>
					<mx:DataGridColumn headerText="empcounty1" dataField="empcounty1Col"  visible="false"/>
					<mx:DataGridColumn headerText="empphn1" dataField="empphn1Col"  visible="false"/>
					<mx:DataGridColumn headerText="empcell" dataField="empcellCol"  visible="false"/>
					<mx:DataGridColumn headerText="empcontphn" dataField="empcontphnCol"  visible="false"/>
					<mx:DataGridColumn headerText="empcontname" dataField="empcontnameCol"  visible="false"/>
					<mx:DataGridColumn headerText="emphiredate" dataField="emphiredateCol"  visible="false"/>
					<mx:DataGridColumn headerText="emptermdate" dataField="emptermdateCol"  visible="false"/>
					<mx:DataGridColumn headerText="empstatus" dataField="empstatusCol"  visible="false"/>
					<mx:DataGridColumn headerText="emppaytype" dataField="emppaytypeCol"  visible="false"/>
					<mx:DataGridColumn headerText="empbasecraft" dataField="empbasecraftCol"  visible="false"/>
					<mx:DataGridColumn headerText="empbasewage" dataField="empbasewageCol"  visible="false"/>
					<mx:DataGridColumn headerText="empdepstatus" dataField="empdepstatusCol"  visible="false"/>
					<mx:DataGridColumn headerText="projectid" dataField="projectidCol"  visible="false"/>
					<mx:DataGridColumn headerText="empshift" dataField="empshiftCol"  visible="false"/>
					<mx:DataGridColumn headerText="craftid" dataField="craftidCol"  visible="false"/>
					<mx:DataGridColumn headerText="empwage" dataField="empwageCol"  visible="false"/>
					<mx:DataGridColumn headerText="empperdiem" dataField="empperdiemCol"  visible="false"/>
					<mx:DataGridColumn headerText="empstatus1" dataField="empstatus1Col"  visible="false"/>
					<mx:DataGridColumn headerText="empremarks" dataField="empremarksCol"  visible="false"/>
					<mx:DataGridColumn headerText="empphoto" dataField="empphotoCol"  visible="false"/>
				</mx:columns>
		</mx:DataGrid>
 
		<!--
			These Buttons call ActionScript functions defined in
			employeesScript.as when they are clicked (as defined by the "click"
			event on the tag).  In general, UI event handling in Flex is done by assigning
			handler functions to the events on the UI component.
		-->
		<mx:Button id="btnAddNew" click="goToUpdate()" icon="@Embed('icons/AddRecord.png')" toolTip="Add Record" x="10" bottom="330"/>
		<mx:Button id="btnDelete" click="deleteItem()" icon="@Embed('icons/DeleteRecord.png')" toolTip="Delete Record" x="58" bottom="330"/>
		<mx:Label text="Search by Employee ID" right="482" bottom="304"/>
		<mx:TextInput id="filterTxt" width="137" toolTip="Search by empid" enter="filterResults()" right="479" bottom="330"/>
		<mx:Button click="filterResults()" id="filterButton" icon="@Embed('icons/SearchRecord.png')" toolTip="Search by empid" right="431" bottom="330"/>
		<mx:Label x="10" y="0" text="Select an Employee" width="146" fontSize="12" fontWeight="bold" textDecoration="underline"/>
		<mx:TextInput id="empidCol2" text="{dataGrid.selectedItem.empidCol}" x="543" y="28" width="124"/>
		<mx:Label x="455" y="0" text="Employee Records" width="146" fontSize="12" fontWeight="bold" textDecoration="underline"/>
		<mx:Label x="455" y="30" text="Employee ID"/>
		<mx:Label x="455" y="56" text="Last" width="41"/>
		<mx:TextInput x="543" y="54"  text="{dataGrid.selectedItem.emplnCol}" width="160"/>
		<mx:Label x="455" y="84" text="First"/>
		<mx:TextInput x="543" y="82" text="{dataGrid.selectedItem.empfnCol}"  width="160"/>
		<mx:Label x="455" y="112" text="Middle"/>
		<mx:TextInput x="543" y="110" text="{dataGrid.selectedItem.empmiCol}" width="160"/>
		<mx:Label x="455" y="140" text="Suffix"/>
		<mx:TextInput x="543" y="138" text="{dataGrid.selectedItem.empsfxCol.txt}" width="58"/>
		<mx:Label x="455" y="168" text="SSN"/>
		<mx:TextInput x="543" y="166" text="{dataGrid.selectedItem.empssnCol}" width="124"/>
		<mx:Label x="455" y="196" text="DOB"/>
		<mx:TextInput x="543" y="194" text="{dataGrid.selectedItem.empdobCol}" width="124"/>
		<mx:Label x="455" y="224" text="DL"/>
		<mx:TextInput x="543" y="222" text="{dataGrid.selectedItem.empdlCol}" width="124"/>
		<mx:Label x="455" y="252" text="DL State"/>
		<mx:TextInput x="543" y="250" text="{dataGrid.selectedItem.empdlstCol}" width="58"/>
		<mx:Label x="455" y="280" text="County"/>
		<mx:TextInput x="543" y="278" width="124" text="{dataGrid.selectedItem.empcity1Col}"/>
		<mx:Label x="455" y="308" text="Street 1"/>
		<mx:TextInput x="543" y="306" text="{dataGrid.selectedItem.empaptCol}"/>
		<mx:TextInput x="543" y="336" text="{dataGrid.selectedItem.empst1Col}" width="58"/>
		<mx:TextInput x="543" y="364" text="{dataGrid.selectedItem.empzip1Col}" width="160"/>
		<mx:TextInput x="543" y="394" text="{dataGrid.selectedItem.empcounty1Col}" width="58"/>
		<mx:TextInput x="543" y="422" text="{dataGrid.selectedItem.empphn1Col}" width="82"/>
		<mx:TextInput x="543" y="450" text="{dataGrid.selectedItem.empcellCol}" width="124"/>
		<mx:TextInput x="543" y="478" text="{dataGrid.selectedItem.empcontphnCol}" width="124"/>
		<mx:Label x="455" y="338" text="Suite"/>
		<mx:Label x="455" y="366" text="City"/>
		<mx:Label x="455" y="396" text="State"/>
		<mx:Label x="455" y="424" text="Zip"/>
		<mx:Label x="455" y="452" text="Home Phone"/>
		<mx:Label x="455" y="480" text="Cell Phone"/>
		<mx:Image x="716" y="0" width="84" height="88"/>
 
	</mx:Canvas>
 
	<mx:Canvas id="update" width="100%" height="100%">
		<mx:Form width="100%" height="80%" id="employeeForm">
                    <mx:FormItem label="Empid:" id="empid_form">
                        <mx:TextInput id="empidCol" text=""/>
                    </mx:FormItem>
                    <mx:FormItem label="Empln:" id="empln_form">
                        <mx:TextInput id="emplnCol" text=""/>
                    </mx:FormItem>
                    <mx:FormItem label="Empfn:" id="empfn_form">
                        <mx:TextInput id="empfnCol" text=""/>
                    </mx:FormItem>
                    <mx:FormItem label="Empmi:" id="empmi_form">
                        <mx:TextInput id="empmiCol" text=""/>
                    </mx:FormItem>
                    <mx:FormItem label="Empsfx:" id="empsfx_form">
                        <mx:TextInput id="empsfxCol" text=""/>
                    </mx:FormItem>
                    <mx:FormItem label="Empssn:" id="empssn_form">
                        <mx:TextInput id="empssnCol" text=""/>
                    </mx:FormItem>
                    <mx:FormItem label="Empdob:" id="empdob_form">
                        <mx:TextInput id="empdobCol" text=""/>
                    </mx:FormItem>
                    <mx:FormItem label="Empdl:" id="empdl_form">
                        <mx:TextInput id="empdlCol" text=""/>
                    </mx:FormItem>
                    <mx:FormItem label="Empdlst:" id="empdlst_form">
                        <mx:TextInput id="empdlstCol" text=""/>
                    </mx:FormItem>
                    <mx:FormItem label="Empstreet1:" id="empstreet1_form">
                        <mx:TextInput id="empstreet1Col" text=""/>
                    </mx:FormItem>
                    <mx:FormItem label="Empcity1:" id="empcity1_form">
                        <mx:TextInput id="empcity1Col" text=""/>
                    </mx:FormItem>
                    <mx:FormItem label="Empapt:" id="empapt_form">
                        <mx:TextInput id="empaptCol" text=""/>
                    </mx:FormItem>
                    <mx:FormItem label="Empst1:" id="empst1_form">
                        <mx:TextInput id="empst1Col" text=""/>
                    </mx:FormItem>
                    <mx:FormItem label="Empzip1:" id="empzip1_form">
                        <mx:TextInput id="empzip1Col" text=""/>
                    </mx:FormItem>
                    <mx:FormItem label="Empcounty1:" id="empcounty1_form">
                        <mx:TextInput id="empcounty1Col" text=""/>
                    </mx:FormItem>
                    <mx:FormItem label="Empphn1:" id="empphn1_form">
                        <mx:TextInput id="empphn1Col" text=""/>
                    </mx:FormItem>
                    <mx:FormItem label="Empcell:" id="empcell_form">
                        <mx:TextInput id="empcellCol" text=""/>
                    </mx:FormItem>
                    <mx:FormItem label="Empcontphn:" id="empcontphn_form">
                        <mx:TextInput id="empcontphnCol" text=""/>
                    </mx:FormItem>
                    <mx:FormItem label="Empcontname:" id="empcontname_form">
                        <mx:TextInput id="empcontnameCol" text=""/>
                    </mx:FormItem>
                    <mx:FormItem label="Emphiredate:" id="emphiredate_form">
                        <mx:TextInput id="emphiredateCol" text=""/>
                    </mx:FormItem>
                    <mx:FormItem label="Emptermdate:" id="emptermdate_form">
                        <mx:TextInput id="emptermdateCol" text=""/>
                    </mx:FormItem>
                    <mx:FormItem label="Empstatus:" id="empstatus_form">
                        <mx:TextInput id="empstatusCol" text=""/>
                    </mx:FormItem>
                    <mx:FormItem label="Emppaytype:" id="emppaytype_form">
                        <mx:TextInput id="emppaytypeCol" text=""/>
                    </mx:FormItem>
                    <mx:FormItem label="Empbasecraft:" id="empbasecraft_form">
                        <mx:TextInput id="empbasecraftCol" text=""/>
                    </mx:FormItem>
                    <mx:FormItem label="Empbasewage:" id="empbasewage_form">
                        <mx:TextInput id="empbasewageCol" text=""/>
                    </mx:FormItem>
                    <mx:FormItem label="Empdepstatus:" id="empdepstatus_form">
                        <mx:TextInput id="empdepstatusCol" text=""/>
                    </mx:FormItem>
                    <mx:FormItem label="Projectid:" id="projectid_form">
                        <mx:TextInput id="projectidCol" text=""/>
                    </mx:FormItem>
                    <mx:FormItem label="Empshift:" id="empshift_form">
                        <mx:TextInput id="empshiftCol" text=""/>
                    </mx:FormItem>
                    <mx:FormItem label="Craftid:" id="craftid_form">
                        <mx:TextInput id="craftidCol" text=""/>
                    </mx:FormItem>
                    <mx:FormItem label="Empwage:" id="empwage_form">
                        <mx:TextInput id="empwageCol" text=""/>
                    </mx:FormItem>
                    <mx:FormItem label="Empperdiem:" id="empperdiem_form">
                        <mx:TextInput id="empperdiemCol" text=""/>
                    </mx:FormItem>
                    <mx:FormItem label="Empstatus1:" id="empstatus1_form">
                        <mx:TextInput id="empstatus1Col" text=""/>
                    </mx:FormItem>
                    <mx:FormItem label="Empremarks:" id="empremarks_form">
                        <mx:TextInput id="empremarksCol" text=""/>
                    </mx:FormItem>
                    <mx:FormItem label="Empphoto:" id="empphoto_form">
                        <mx:TextInput id="empphotoCol" text=""/>
                    </mx:FormItem>
		</mx:Form>
		<mx:Button label="Save" id="btnSubmit" click="insertItem()" right="81" bottom="10"/>
		<mx:Button label="Cancel" id="btnCancel" click="goToView()" right="10" bottom="10"/>
	</mx:Canvas>
 
	</mx:ViewStack>
</mx:ViewStack>
 
 
/**ANTHONY HARRIS: START FLEX AUTOGEN ACTIONSCRIPT 
 * ActionScript source file that defines the UI logic and some of the data access code.
 * This file is linked into the main application MXML file using the mx:Script tag.
 * Most of the functions in this file are called by event handlers defined in
 * the MXML.
 */
import mx.collections.ArrayCollection;
import mx.controls.Alert;
import mx.controls.dataGridClasses.DataGridColumn;
import mx.controls.dataGridClasses.DataGridItemRenderer;
import mx.events.CloseEvent;
import mx.events.DataGridEvent;
import mx.rpc.events.ResultEvent;
import mx.managers.CursorManager;
import mx.utils.ObjectUtil;
 
import mx.rpc.http.HTTPService;
import mx.rpc.events.FaultEvent;
import mx.rpc.AsyncToken;
 
//include the constant definition of the server endpoint URL
include "employeeconfig.as";
 
/**
 * gateway : this is the communication layer with the server side php code
 */
private var gateway:HTTPService = new HTTPService();
 
/**
 * the array collection holds the rows that we use in the grid
 */
[Bindable]
public var dataArr:ArrayCollection = new ArrayCollection();
 
/**
 * column that we order by. This is updated each time the users clicks on the 
 * grid column header. 
 * see headerRelease="setOrder(event);" in the DataGrid instantiation in the 
 * mxml file
 */
private var orderColumn:Number;
 
 
/**
 * the list of fields in the database table
 * needed to parse the response into hashes
 */ 
private var fields:Object = { 'empid':String, 'empln':String, 'empfn':String, 'empmi':String, 'empsfx':String, 'empssn':String, 'empdob':String, 'empdl':String, 'empdlst':String, 'empstreet1':String, 'empcity1':String, 'empapt':String, 'empst1':String, 'empzip1':String, 'empcounty1':String, 'empphn1':String, 'empcell':String, 'empcontphn':String, 'empcontname':String, 'emphiredate':String, 'emptermdate':String, 'empstatus':String, 'emppaytype':String, 'empbasecraft':String, 'empbasewage':String, 'empdepstatus':String, 'projectid':String, 'empshift':String, 'craftid':String, 'empwage':String, 'empperdiem':String, 'empstatus1':String, 'empremarks':String, 'empphoto':String};
 
/**
 * Executes when the mxml is completed loaded. Initialize the Rest Gateway.
 */
private function initApp():void 
{
 
    /**
     * initialize the gateway
     * - this will take care of server communication and simple xml protocol.
     */
    gateway.url = ENDPOINT_URL;
    gateway.method = "POST";
    gateway.useProxy = false;
    gateway.resultFormat = "e4x";
 
    /**
     * set the event handler which prevents editing of the primary key
     */
    dataGrid.addEventListener(DataGridEvent.ITEM_EDIT_BEGINNING, editCellHandler);
 
    /**
     * set the event handler which triggers the update actions - everytime an 
     * edit operation is finished
     */
    dataGrid.addEventListener(DataGridEvent.ITEM_EDIT_END, editCellEnd);
 
    gateway.addEventListener(ResultEvent.RESULT, resultHandler);
    gateway.addEventListener(FaultEvent.FAULT, faultHandler);
    
    fill();
}
 
/**
 * Disallow editing of the primary key column.
 * @param e DataGridEvent contains details about the row and column of the grid 
 * where the user clicked
 */
private function editCellHandler(e:DataGridEvent):void
{
    /**
     * if the user clicked on the primary key column, stop editing
     */
    if(e.dataField == "empidCol")
    {
        e.preventDefault();
        return;
    }
}
 
/**
 * Click handler for "Filter" button.
 * When setting another filter, refresh the collection, and load the new data
 */
private function filterResults():void
{
    fill();
}
 
/**
 * Event handler triggered when the user finishes editing an entry
 * triggers an "update" server command
 */
private function editCellEnd(e:DataGridEvent):void
{
    var dsRowIndex:int = e.rowIndex;
    var dsFieldName:String = e.dataField;
    var dsColumnIndex:Number = e.columnIndex;
 
    var vo:* = dataArr[dsRowIndex];
    
    var col:DataGridColumn = dataGrid.columns[dsColumnIndex];
    var newvalue:String = dataGrid.itemEditorInstance[col.editorDataField];
 
    trace("a:" + dsRowIndex + ", " + dsFieldName + ", " + dsColumnIndex);
 
    var parameters:* =
    {
        "empid": vo.empidCol,        "empln": vo.emplnCol,        "empfn": vo.empfnCol,        "empmi": vo.empmiCol,        "empsfx": vo.empsfxCol,        "empssn": vo.empssnCol,        "empdob": vo.empdobCol,        "empdl": vo.empdlCol,        "empdlst": vo.empdlstCol,        "empstreet1": vo.empstreet1Col,        "empcity1": vo.empcity1Col,        "empapt": vo.empaptCol,        "empst1": vo.empst1Col,        "empzip1": vo.empzip1Col,        "empcounty1": vo.empcounty1Col,        "empphn1": vo.empphn1Col,        "empcell": vo.empcellCol,        "empcontphn": vo.empcontphnCol,        "empcontname": vo.empcontnameCol,        "emphiredate": vo.emphiredateCol,        "emptermdate": vo.emptermdateCol,        "empstatus": vo.empstatusCol,        "emppaytype": vo.emppaytypeCol,        "empbasecraft": vo.empbasecraftCol,        "empbasewage": vo.empbasewageCol,        "empdepstatus": vo.empdepstatusCol,        "projectid": vo.projectidCol,        "empshift": vo.empshiftCol,        "craftid": vo.craftidCol,        "empwage": vo.empwageCol,        "empperdiem": vo.empperdiemCol,        "empstatus1": vo.empstatus1Col,        "empremarks": vo.empremarksCol,        "empphoto": vo.empphotoCol    }
 
	parameters[dsFieldName.substr(0,dsFieldName.length-3)] = newvalue;
 
	/**
	 * execute the server "update" command
	 */
    doRequest("Update", parameters, saveItemHandler);    
 
}
 
/**
 * result handler for the "update" server command.
 * Just alert the error, or do nothing if it's ok - the data has already 
 * been updated in the grid
 */
private function saveItemHandler(e:Object):void
{
    if (e.isError)
    {
        Alert.show("Error: " + e.data.error);
    }
    else
    {
    }     
}
 
/**
 * dragHeader handler for the datagrid. This handler is executed when the user 
 * clicks on a header column in the datagrid
 * updates the global orderColumn variable, refreshes the TableCollection
 * @param event DataGridEvent details about the column
 */
private function setOrder(event:DataGridEvent):void 
{
    orderColumn = event.columnIndex;
    var col:DataGridColumn = dataGrid.columns[orderColumn];
    col.sortDescending = !col.sortDescending;
    
    event.preventDefault();
    fill();
}
 
/**
 * Click handler for the "Save" button in the "Add" state
 * collects the information in the form and adds a new object to the collection
 */
private function insertItem():void {
    var parameters:* =
    {
        "method": "Insert",		"empid": empidCol.text,		"empln": emplnCol.text,		"empfn": empfnCol.text,		"empmi": empmiCol.text,		"empsfx": empsfxCol.text,		"empssn": empssnCol.text,		"empdob": empdobCol.text,		"empdl": empdlCol.text,		"empdlst": empdlstCol.text,		"empstreet1": empstreet1Col.text,		"empcity1": empcity1Col.text,		"empapt": empaptCol.text,		"empst1": empst1Col.text,		"empzip1": empzip1Col.text,		"empcounty1": empcounty1Col.text,		"empphn1": empphn1Col.text,		"empcell": empcellCol.text,		"empcontphn": empcontphnCol.text,		"empcontname": empcontnameCol.text,		"emphiredate": emphiredateCol.text,		"emptermdate": emptermdateCol.text,		"empstatus": empstatusCol.text,		"emppaytype": emppaytypeCol.text,		"empbasecraft": empbasecraftCol.text,		"empbasewage": empbasewageCol.text,		"empdepstatus": empdepstatusCol.text,		"projectid": projectidCol.text,		"empshift": empshiftCol.text,		"craftid": craftidCol.text,		"empwage": empwageCol.text,		"empperdiem": empperdiemCol.text,		"empstatus1": empstatus1Col.text,		"empremarks": empremarksCol.text,		"empphoto": empphotoCol.text    };
 
	/**
	 * execute the server "insert" command
	 */
    doRequest("Insert", parameters, insertItemHandler);
}
 
/**
 * Result handler for the insert call.
 * Alert the error if it exists
 * if the call went through ok, return to the list, and refresh the data
 */
private function insertItemHandler(e:Object):void
{
    if (e.isError)
    {
        Alert.show("Error: " + e.data.error);
    }
    else
    {
        goToView();
        fill();
    }     
}
 
/** 
 * general utility function for refreshing the data 
 * gets the filtering and ordering, then dispatches a new server call
 *
 */
private function fill():void 
{
    /**
     * find the order parameters
     */
    var desc:Boolean = false;
    var orderField:String = '';
    
    if(!isNaN(orderColumn))
    {
        var col:DataGridColumn = dataGrid.columns[orderColumn];
        desc = col.sortDescending;
		//remove the 'Col' particle
        orderField = col.dataField.substr(0,col.dataField.length-3);
    }
 
    dataGrid.enabled = false;
    CursorManager.setBusyCursor();
 
    var parameters:* =
    {
        "orderField": orderField,
        "orderDirection": (desc) ? "DESC" : "ASC", 
        "filter": filterTxt.text
    }
	/**
	 * execute the server "select" command
	 */
    doRequest("FindAll", parameters, fillHandler);
}
 
/** 
 * result handler for the fill call. 
 * if it is an error, show it to the user, else refill the arraycollection with the new data
 *
 */
private function fillHandler(e:Object):void
{
    if (e.isError)
    {
        Alert.show("Error: " + e.data.error);
    } 
    else
    {
        dataArr.removeAll();
        for each(var row:XML in e.data.row) 
        {
            var temp:* = {};
            for (var key:String in fields) 
            {
                temp[key + 'Col'] = row[key];
            }
 
            dataArr.addItem(temp);
        }
 
        CursorManager.removeBusyCursor();
        dataGrid.enabled = true;
    }    
}
 
/**
 * Click handler for the "delete" button in the list
 * confirms the action and launches the deleteClickHandler function
 */
private function deleteItem():void {
    
    if (dataGrid.selectedItem)
    {
        Alert.show("Are you sure you want to delete the selected record?",
        "Confirm Delete", 3, this, deleteClickHandler);
    }
    
}
 
/**
 * Event handler function for the Confirm dialog raises when the 
 * Delete button is pressed.
 * If the pressed button was Yes, then the product is deleted.
 * @param object event
 * @return nothing
 */ 
private function deleteClickHandler(event:CloseEvent):void
{
    if (event.detail == Alert.YES) 
    {
        var vo:* = dataGrid.selectedItem;
 
        var parameters:* =
        {
            "empid": vo.empidCol
        }
 
		/**
		 * execute the server "delete" command
		 */
        doRequest("Delete", parameters, deleteHandler);
 
        setTimeout( function():void
        {
            dataGrid.destroyItemEditor();
        },
        1);
    }
}
 
public function deleteHandler(e:*):void
{
    if (e.isError)
    {
        Alert.show("Error: " + e.data.error);
    }
    else
    {
        var empid:Number = parseInt(e.data.toString(), 10);
        for (var index:Number = 0; index < dataArr.length; index++)
        {
            if (dataArr[index].empidCol == empid)
            {
                dataArr.removeItemAt(index);
                break;
            }
        }
    }     
}
 
/**
 * deserializes the xml response
 * handles error cases
 *
 * @param e ResultEvent the server response and details about the connection
 */
public function deserialize(obj:*, e:*):*
{
    var toret:Object = {};
    
    toret.originalEvent = e;
 
    if (obj.data.elements("error").length() > 0)
    {
        toret.isError = true;
        toret.data = obj.data;
    }
    else
    {
        toret.isError = false;
        toret.metadata = obj.metadata;
        toret.data = obj.data;
    }
 
    return toret;
}
 
/**
 * result handler for the gateway
 * deserializes the result, and then calls the REAL event handler
 * (set when making a request in the doRequest function)
 *
 * @param e ResultEvent the server response and details about the connection
 */
public function resultHandler(e:ResultEvent):void
{
    var topass:* = deserialize(e.result, e);
    e.token.handler.call(null, topass);
}
 
/**
 * fault handler for this connection
 *
 * @param e FaultEvent the error object
 */
public function faultHandler(e:FaultEvent):void
{
	var errorMessage:String = "Connection error: " + e.fault.faultString; 
    if (e.fault.faultDetail) 
    { 
        errorMessage += "\n\nAdditional detail: " + e.fault.faultDetail; 
    } 
    Alert.show(errorMessage);
}
 
/**
 * makes a request to the server using the gateway instance
 *
 * @param method_name String the method name used in the server dispathcer
 * @param parameters Object name value pairs for sending in post
 * @param callback Function function to be called when the call completes
 */
public function doRequest(method_name:String, parameters:Object, callback:Function):void
{
    // add the method to the parameters list
    parameters['method'] = method_name;
 
    gateway.request = parameters;
 
    var call:AsyncToken = gateway.send();
    call.request_params = gateway.request;
 
    call.handler = callback;
}
 
 
/**
 * Click handler when the user click the "Create" button
 * Load the "Update" canvas.
 */
public function goToUpdate():void
{
	applicationScreens.selectedChild = update;
}
 
/**
 * Load the "View" canvas.
 */
public function goToView():void
{
    applicationScreens.selectedChild = view;
}
 
 
//AS file
[+][-]08.06.2008 at 12:40AM PDT, ID: 22167861

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: ActionScript, PHP and Databases, Adobe Flex
Tags: Adobe, Flex Actionscript, 3, actionscript, mxml, php, all, medoex.com
Sign Up Now!
Solution Provided By: hobbit72
Participating Experts: 1
Solution Grade: A
 
 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628