var project Project var parser XMLTaskParser new XMLTaskParser parser

  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
var project:Project;
var parser:XMLTaskParser = new XMLTaskParser();
//=======================================================================================
parser.parseProject(project, this);//o`zini bervoramiz
project = parser.getProject();
//=======================================================================================
package com.workforce.utils{
import flash.xml.*;
import flash.events.*;
import flash.xml.*;
import flash.net.*;
import com.workforce.project.*;
import com.workforce.utils.MyDate;
import com.workforce.project.*;
public class XMLTaskParser {
public var xml:XML;
private var xmlNode:XMLNode;
public var proj:Project;
//==================================
private var obj:Object;//bu metod tepadagi klass
function XMLTaskParser() {
/*this.xml = new XML(xml);
this.xml.ignoreWhite = true;
//trace(this.xml.status);
xmlNode = this.xml.childNodes[0].childNodes[0];
*/
proj = new Project();
}
function loadXML(e:Event):void {
xml = new XML(e.target.data);
trace(xml);
}
public function ParseTasks(project:Project) {
var startDate:MyDate;
var endDate:MyDate;
if ((this.xml.childNodes[0].attributes['canModify']=="true")||(this.xml.childNodes[0].attributes['canModify']=="TRUE")) {
project.setCanModify(true);
} else {
project.setCanModify(false);
}
trace("!!! =) !!! LOGGGG!!!! =( "+this.xml.childNodes[0].attributes['canModify']);
var taskId:Number = 0;
project.Define(xmlNode.attributes['name'],xmlNode.attributes['description'],xmlNode.attributes['startDate']);
for (var i=0; i<this.xmlNode.childNodes.length; i++) {
taskId=project.addTask(this.xmlNode.childNodes[i].attributes['id'],this.xmlNode.childNodes[i].attributes['name'],this.xmlNode.childNodes[i].attributes['startDate'],this.xmlNode.childNodes[i].attributes['endDate'],this.xmlNode.childNodes[i].attributes['duration']);
}
startDate = new MyDate(project.getTaskById(0).getStartDate().toString("dd.mm.yyyy"));
endDate = new MyDate(project.getTaskById(0).getEndDate().toString("dd.mm.yyyy"));
for (var i=1; i<project.getTasks().length; i++) {
if (project.getTaskById(i).getStartDate().beforeDate(startDate)) {
startDate.parseDate(project.getTaskById(i).getStartDate().toString("dd.mm.yyyy"));
}
if (project.getTaskById(i).getEndDate().afterDate(endDate)) {
endDate.parseDate(project.getTaskById(i).getEndDate().toString("dd.mm.yyyy"));
}
}
startDate.resetByWeek();
startDate.predWeek();
endDate.resetByWeek();
endDate.nextWeek();
endDate.predDay();
project.setStartDate(startDate.toString("dd.mm.yyyy"));
project.setDuration(startDate.getDaysBetweenDates(endDate));
trace("Start date of project: "+startDate.toString("dd.mm.yyyy"));
trace("End date of project: "+endDate.toString("dd.mm.yyyy"));
trace("Total Days: "+project.getDuration());
}
//============================================================
public function parseProject(proj:Project, obj:Object) {
this.proj = proj;
var loader:URLLoader = new URLLoader();
loader.addEventListener(ProgressEvent.PROGRESS, onXmlProgress);
loader.addEventListener(Event.COMPLETE, onXmlLoad);
loader.load(new URLRequest("files\\data.xml"));
//============================================
this.obj = obj;//tepadagi obyektni olvolamiz
trace(xml);
}
private function onXmlProgress(e:ProgressEvent) {
trace("Loaded: "+e.bytesLoaded+", "+"Total: "+e.bytesTotal);
}
private function onXmlLoad(e:Event) {
if(proj == null) proj = new Project();
var startDate:MyDate;
var endDate:MyDate;
xml = new XML(e.target.data);
var xmlList:XMLList = xml..project;
var list:XMLList = xml.attribute("canModify");
if (list.toString()=="true") {
proj.setCanModify(true);
} else {
proj.setCanModify(false);
}
//project.Define(xml.attribute("name").toString(),xml.attribute("description").toString(),xml.attribute("startDate").toString());
var taskId:Number = 0;
for each (var project:XML in xmlList) {
trace(project.@description.toString());
trace(project.@startDate.toString());
proj.Define(project.@name.toString(), project.@description.toString(), project.@startDate.toString());
//for (var i=0; i<this.xmlNode.childNodes.length; i++) {
//taskId=project.addTask(this.xmlNode.childNodes[i].attributes['id'],this.xmlNode.childNodes[i].attributes['name'],this.xmlNode.childNodes[i].attributes['startDate'],this.xmlNode.childNodes[i].attributes['endDate'],this.xmlNode.childNodes[i].attributes['duration']);
//}
xmlList = project..task;
for each (var tasks:XML in xmlList) {
trace(tasks.@id.toString() +" "+ tasks.@name.toString()+" "+ tasks.@startDate.toString()+" "+tasks.@endDate.toString()+" "+tasks.@duration.toString());
taskId = proj.addTask(Number(tasks.@id.toString()), tasks.@name.toString(), tasks.@startDate.toString(), tasks.@endDate.toString(), Number(tasks.@duration.toString()));
}
startDate = new MyDate(proj.getTaskById(0).getStartDate().toString("dd.mm.yyyy"));
endDate = new MyDate(proj.getTaskById(0).getEndDate().toString("dd.mm.yyyy"));
startDate = new MyDate(proj.getTaskById(0).getStartDate().toString("dd.mm.yyyy"));
endDate = new MyDate(proj.getTaskById(0).getEndDate().toString("dd.mm.yyyy"));
startDate.resetByWeek();
startDate.predWeek();
endDate.resetByWeek();
endDate.nextWeek();
endDate.predDay();
proj.setStartDate(startDate.toString("dd.mm.yyyy"));
proj.setDuration(startDate.getDaysBetweenDates(endDate));
trace("Start date of project: "+startDate.toString("dd.mm.yyyy"));
trace("End date of project: "+endDate.toString("dd.mm.yyyy"));
trace("Total Days: "+proj.getDuration());
}
//===============================================
this.obj.method();//tepadagi obyekt metodini chaqiramiz.
}
public function getProject(): Project {
return this.proj;
}
}
}