日期:2014-05-16  浏览次数:20513 次

AIR桌面程序-实现对客户信息管理(FLEX+XML数据库)

本程序实现了对XML的增、删、改、查操作,并同步到xml数据库中

用到的技术:

1.Flex基本布局技术,常用控件操作

2.基本事件的触发、自定义事件的触发

3.flex读写更改 操作XML对象

4.基本数据库知识

<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication 
						xmlns:mx="http://www.adobe.com/2006/mxml" 
						layout="absolute"
						width="720" 
						height="600" 
						creationComplete="initApp()"
						xmlns:s="library://ns.adobe.com/flex/spark" 
						viewSourceURL="srcview/index.html">
	
	<mx:Script>
		<![CDATA[
			import event.*;
			
			import mx.collections.ArrayCollection;
			import mx.controls.Alert;
			import mx.events.IndexChangedEvent;
			import mx.modules.Module;
			import mx.utils.StringUtil;
			
			import tree.*;  
			
			//set bindable
			[Bindable]
			internal var currentPeople:people=new people;
			public var peopledata:XML;
			public var path:File=File.documentsDirectory.resolvePath("D:/peoples.xml");
			public var n:Number;
			public var warning:String="填写信息不全";
			public var warningtitle:String="警告";
			public var searchwarning:String="填写内容不全";
			
			/**
			 * InitApp function handler
			 * */
			internal function initApp():void{				
				var peoples:FileStream=new FileStream;
				peoples.open(path,FileMode.READ);
				peopledata=XML(peoples.readUTFBytes(peoples.bytesAvailable));
				peoples.close();
				var users:Object=peopledata.user;
				n=0;
				
				for(var i:* in users){
					var newPeople:peopleItem=new peopleItem();
					var peopleInfo:people=new people;
					peopleInfo.setpeople(users[i]);
					newPeople.p=peopleInfo;
					holder_user.addChild(newPeople);
					newPeople.addEventListener(selectPeopleEvent.CLICK_PEOPLE,selectHandler);
					newPeople.y=n*newPeople.height;
					n++;
				}
			}
			/**
			 * writedata
			 **/
			public function writedata():void{
				var writedata:FileStream=new FileStream;
				writedata.open(path,FileMode.WRITE);
				writedata.writeUTFBytes(peopledata.toString());
				writedata.close();
			}
			
			/**
			 * 
			 * match
			 * */
			public function match(selectedone:people):int{
				var index:int=new int;
				var conter:int;
				for(conter=n-1;conter>=0;conter--){
					if(selectedone.id==peopledata.user[conter].id){
						index=conter;
					}else{
						continue;
					}
				}
				return index;
			}
			/**
			 * 
			 * 
			 * */
			internal function selectHandler(evt:selectPeopleEvent):void{
				currentPeople=evt.selectedUser;
			}
			/**
			 * 
			 * 
			 * */
			public function clearHandler():void{
				addname.text="";
				addotherinfo.text="";
				addphone.text="";
				addotherinfo.text = "";
				addmale.selected=false;
				addfemale.selected=false;
			}
			/**
			 * 
			 * 
			 * */
			public function addHandler():void{
				var addcontent:XML;
				if(addname.text==""||addotherinfo.text==""||addphone.text==""||(!(addmale.selected||addfemale.selected))){
					Alert.show(warning,warningtitle,Alert.OK);
				}
				else if(addmale.selected){
					 addcontent = <user>
						 					<id>{n}</id>
											<name>{addname.text}</name>
											<sex>male</sex>
											<phonenum>{addphone.text}</phonenum>
											<otherinfo>{addotherinfo.text}</otherinfo>
											</user>;
					peopledata.appendChild(addcontent);
					writedata();
					holder_user.removeAllChildren();
					initApp();
					Alert.show("添加成功!");
				}
				else{
					addcontent  =   <user>
											<id>{n}</id>
											<name>{addname.text}</name>
											<sex>female</sex>
											<phonenum>{addphone.text}</phonenum>
											<otherinfo>{addotherinfo.text}</otherinfo>
											</user>;
					peopledata.appendChild(addcontent);
					writedata();
					holder_user.removeAllChildren();
					initApp();
					Alert.show("添加成功!");
				}
				clearHandler();
			}
			public function textChangeHandler(modified:peop