public void AddTaskInfo( U50TaskInfo taskInfo )
        {
            m_TaskInfoByGuid.Add( taskInfo.Guid, taskInfo );

            if ( AddedTaskInfo != null )
                AddedTaskInfo( this, EventArgs.Empty );
        }
Exemple #2
0
        private void button3_Click(object sender, EventArgs e)
        {
            if (m_TaskInfo == null)
            {
                return;
            }

            U50TaskInfo taskInfo = new U50TaskInfo();

            taskInfo.Guid    = m_TaskInfo.Guid;
            taskInfo.Name    = m_TaskInfo.Name;
            taskInfo.General = m_TaskBControl.GetTaskGeneral();
            taskInfo.Request = m_TaskCControl.GetTaskRequest();
            taskInfo.Policy  = m_TaskDControl.GetTaskPolicy();
            taskInfo.Result  = m_TaskEControl.GetTaskResult();

            U50GlobalSetting.ScanTaskThread(taskInfo);

            this.button3.Enabled = false;
            this.Timer1.Enabled  = true;

            //TaskPolicy taskPolicy = GetTaskPolicy();

            ////ReportInfo reportInfo = ScanTask( taskPolicy );
            //ReportInfo reportInfo = new ReportInfo();

            //for ( int i = 0; i < reportInfo.ReportArray.Length; i++ )
            //{
            //    Report report = reportInfo.ReportArray[i];
            //}
        }
        private void TreeView_AfterLabelEdit(object sender, NodeLabelEditEventArgs e)
        {
            if (e.Node.Parent != null)
            {
                e.CancelEdit = true;
                return;
            }

            if (e.Node == m_MainTreeNode)
            {
                e.CancelEdit = true;
                return;
            }

            if (e.Label == string.Empty || e.Label == null)
            {
                e.CancelEdit = true;
                return;
            }

            U50TaskInfo outPolicyInfo = null;

            if (m_TreeNodeTaskInfo.TryGetValue(e.Node, out outPolicyInfo) == false)
            {
                e.CancelEdit = true;
                return;
            }

            if (outPolicyInfo.Name == e.Label)
            {
                return;
            }

            if (m_TaskName.Contains(e.Label) == true)
            {
                MainForm.ShowPopupMessage(e.Label, "名称已经存在!");
                e.CancelEdit = true;
                return;
            }

            m_TaskName.Remove(outPolicyInfo.Name);

            outPolicyInfo.Name = e.Label;

            m_TaskName.Add(outPolicyInfo.Name);

            TaskManager.Instance.OnRefreshStockInfo();
        }
        private void ButtonOK_Click(object sender, EventArgs e)
        {
            foreach (var item in m_DeleteTreeNode)
            {
                UserControl outConfigControl = null;
                if (this.m_AllConfigControlInfo.TryGetValue(item.Nodes[0], out outConfigControl) == true)
                {
                    if (outConfigControl == m_CurrentConfigControl)
                    {
                        this.TreeView.SelectedNode = m_MainTreeNodeSub;
                    }

                    this.Panel.Controls.Remove(outConfigControl);
                }

                if (this.m_AllConfigControlInfo.TryGetValue(item.Nodes[1], out outConfigControl) == true)
                {
                    if (outConfigControl == m_CurrentConfigControl)
                    {
                        this.TreeView.SelectedNode = m_MainTreeNodeSub;
                    }

                    this.Panel.Controls.Remove(outConfigControl);
                }

                if (this.m_AllConfigControlInfo.TryGetValue(item.Nodes[2], out outConfigControl) == true)
                {
                    if (outConfigControl == m_CurrentConfigControl)
                    {
                        this.TreeView.SelectedNode = m_MainTreeNodeSub;
                    }

                    this.Panel.Controls.Remove(outConfigControl);
                }

                if (this.m_AllConfigControlInfo.TryGetValue(item.Nodes[3], out outConfigControl) == true)
                {
                    if (outConfigControl == m_CurrentConfigControl)
                    {
                        this.TreeView.SelectedNode = m_MainTreeNodeSub;
                    }

                    this.Panel.Controls.Remove(outConfigControl);
                }

                this.m_AllConfigControlInfo.Remove(item.Nodes[0]);
                this.m_AllConfigControlInfo.Remove(item.Nodes[1]);
                this.m_AllConfigControlInfo.Remove(item.Nodes[2]);
                this.m_AllConfigControlInfo.Remove(item.Nodes[3]);
                this.m_AllConfigControlInfo.Remove(item);

                U50TaskInfo outTaskInfo = null;
                if (this.m_TreeNodeTaskInfo.TryGetValue(item, out outTaskInfo) == true)
                {
                    this.m_TreeNodeTaskInfo.Remove(item);
                    TaskManager.Instance.RemoveTaskInfoByGuid(outTaskInfo.Guid);
                }
            }

            foreach (var item in m_TreeNodeTaskInfo)
            {
                UserControl outTaskControl = null;
                if (m_AllConfigControlInfo.TryGetValue(item.Key.Nodes[0], out outTaskControl) == false)
                {
                    continue;
                }

                TaskBControl taskBControl = outTaskControl as TaskBControl;
                if (taskBControl == null)
                {
                    continue;
                }

                item.Value.General = taskBControl.GetTaskGeneral();

                if (m_AllConfigControlInfo.TryGetValue(item.Key.Nodes[1], out outTaskControl) == false)
                {
                    continue;
                }

                TaskCControl taskCControl = outTaskControl as TaskCControl;
                if (taskCControl == null)
                {
                    continue;
                }

                item.Value.Request = taskCControl.GetTaskRequest();

                if (m_AllConfigControlInfo.TryGetValue(item.Key.Nodes[2], out outTaskControl) == false)
                {
                    continue;
                }

                TaskDControl taskDControl = outTaskControl as TaskDControl;
                if (taskDControl == null)
                {
                    continue;
                }

                item.Value.Policy = taskDControl.GetTaskPolicy();

                if (m_AllConfigControlInfo.TryGetValue(item.Key.Nodes[3], out outTaskControl) == false)
                {
                    continue;
                }

                TaskEControl taskEControl = outTaskControl as TaskEControl;
                if (taskDControl == null)
                {
                    continue;
                }

                item.Value.Result = taskEControl.GetTaskResult();

                if (m_NewTreeNode.Contains(item.Key) == true)
                {
                    TaskManager.Instance.AddTaskInfo(item.Value);
                }
            }

            U50GlobalSetting.SaveTaskSetting(U50GlobalSetting.TaskFilePath, TaskManager.Instance.ToArray());
            U50GlobalSetting.SaveGlobalRegistry();

            m_NewTreeNode.Clear();
            m_DeleteTreeNode.Clear();
        }
        private void NewTask(U50TaskInfo taskInfo)
        {
            m_TaskName.Add(taskInfo.Name);

            // U50策略01
            TreeNode newTreeNodeTask     = new TreeNode(string.Format("U50任务{0}", m_TaskCount++));
            TreeNode newTreeNodeTaskSub  = new TreeNode("常规");
            TreeNode newTreeNodeTaskSub1 = new TreeNode("需求");
            TreeNode newTreeNodeTaskSub2 = new TreeNode("策略");
            TreeNode newTreeNodeTaskSub3 = new TreeNode("扫描结果");

            newTreeNodeTask.Nodes.Add(newTreeNodeTaskSub);
            newTreeNodeTask.Nodes.Add(newTreeNodeTaskSub1);
            newTreeNodeTask.Nodes.Add(newTreeNodeTaskSub2);
            newTreeNodeTask.Nodes.Add(newTreeNodeTaskSub3);


            TaskBControl taskBControl = new TaskBControl();

            taskBControl.Dock    = DockStyle.Fill;
            taskBControl.Visible = false;
            taskBControl.SetConfigPolicy(taskInfo.General);

            this.m_AllConfigControlInfo.Add(newTreeNodeTask, taskBControl);
            this.m_AllConfigControlInfo.Add(newTreeNodeTaskSub, taskBControl);

            this.Panel.Controls.Add(taskBControl);

            TaskCControl taskCControl = new TaskCControl();

            taskCControl.Dock    = DockStyle.Fill;
            taskCControl.Visible = false;
            taskCControl.SetConfigPolicy(taskInfo.Request);

            this.m_AllConfigControlInfo.Add(newTreeNodeTaskSub1, taskCControl);

            this.Panel.Controls.Add(taskCControl);

            TaskDControl taskDControl = new TaskDControl();

            taskDControl.Dock    = DockStyle.Fill;
            taskDControl.Visible = false;
            taskDControl.SetConfigPolicy(taskInfo.Policy);

            this.m_AllConfigControlInfo.Add(newTreeNodeTaskSub2, taskDControl);

            this.Panel.Controls.Add(taskDControl);

            TaskEControl taskEControl = new TaskEControl();

            taskEControl.Dock    = DockStyle.Fill;
            taskEControl.Visible = false;
            taskEControl.SetConfigPolicy(taskInfo.Result);

            this.m_AllConfigControlInfo.Add(newTreeNodeTaskSub3, taskEControl);

            this.Panel.Controls.Add(taskEControl);

            //
            taskDControl.m_TaskInfo     = taskInfo;
            taskDControl.m_TaskBControl = taskBControl;
            taskDControl.m_TaskCControl = taskCControl;
            taskDControl.m_TaskDControl = taskDControl;
            taskDControl.m_TaskEControl = taskEControl;

            this.TreeView.Nodes.Add(newTreeNodeTask);

            this.TreeView.SelectedNode = newTreeNodeTask;

            m_TreeNodeTaskInfo.Add(newTreeNodeTask, taskInfo);
        }
        public void NewTask()
        {
            if (m_IsInitializing == false)
            {
                TaskForm_Load(this, EventArgs.Empty);
            }

            U50TaskInfo taskInfo = new U50TaskInfo();

            taskInfo.Guid = Guid.NewGuid().ToString();

            do
            {
                taskInfo.Name = string.Format("U50任务{0}", m_TaskCount++);

                if (m_TaskName.Contains(taskInfo.Name) == false)
                {
                    break;
                }
            } while (true);

            // U50策略01
            TreeNode newTreeNodeTask     = new TreeNode(taskInfo.Name);
            TreeNode newTreeNodeTaskSub  = new TreeNode("常规");
            TreeNode newTreeNodeTaskSub1 = new TreeNode("需求");
            TreeNode newTreeNodeTaskSub2 = new TreeNode("策略");
            TreeNode newTreeNodeTaskSub3 = new TreeNode("扫描结果");

            newTreeNodeTask.Nodes.Add(newTreeNodeTaskSub);
            newTreeNodeTask.Nodes.Add(newTreeNodeTaskSub1);
            newTreeNodeTask.Nodes.Add(newTreeNodeTaskSub2);
            newTreeNodeTask.Nodes.Add(newTreeNodeTaskSub3);

            TaskBControl taskBControl = new TaskBControl();

            taskBControl.Dock    = DockStyle.Fill;
            taskBControl.Visible = false;
            taskInfo.General     = taskBControl.GetTaskGeneral();

            this.m_AllConfigControlInfo.Add(newTreeNodeTask, taskBControl);
            this.m_AllConfigControlInfo.Add(newTreeNodeTaskSub, taskBControl);

            this.Panel.Controls.Add(taskBControl);

            TaskCControl taskCControl = new TaskCControl();

            taskCControl.Dock    = DockStyle.Fill;
            taskCControl.Visible = false;
            taskInfo.Request     = taskCControl.GetTaskRequest();

            this.m_AllConfigControlInfo.Add(newTreeNodeTaskSub1, taskCControl);

            this.Panel.Controls.Add(taskCControl);

            TaskDControl taskDControl = new TaskDControl();

            taskDControl.Dock    = DockStyle.Fill;
            taskDControl.Visible = false;
            taskInfo.Policy      = taskDControl.GetTaskPolicy();

            this.m_AllConfigControlInfo.Add(newTreeNodeTaskSub2, taskDControl);

            this.Panel.Controls.Add(taskDControl);

            TaskEControl taskEControl = new TaskEControl();

            taskEControl.Dock    = DockStyle.Fill;
            taskEControl.Visible = false;
            taskInfo.Result      = taskEControl.GetTaskResult();

            this.m_AllConfigControlInfo.Add(newTreeNodeTaskSub3, taskEControl);

            this.Panel.Controls.Add(taskEControl);

            //
            taskDControl.m_TaskInfo     = taskInfo;
            taskDControl.m_TaskBControl = taskBControl;
            taskDControl.m_TaskCControl = taskCControl;
            taskDControl.m_TaskDControl = taskDControl;
            taskDControl.m_TaskEControl = taskEControl;

            this.TreeView.Nodes.Add(newTreeNodeTask);

            this.TreeView.SelectedNode = newTreeNodeTask;

            m_NewTreeNode.Add(newTreeNodeTask);

            m_TreeNodeTaskInfo.Add(newTreeNodeTask, taskInfo);
        }
        private void button3_Click( object sender, EventArgs e )
        {
            if ( m_TaskInfo == null )
                return;

            U50TaskInfo taskInfo = new U50TaskInfo();
            taskInfo.Guid = m_TaskInfo.Guid;
            taskInfo.Name = m_TaskInfo.Name;
            taskInfo.General = m_TaskBControl.GetTaskGeneral();
            taskInfo.Request = m_TaskCControl.GetTaskRequest();
            taskInfo.Policy = m_TaskDControl.GetTaskPolicy();
            taskInfo.Result = m_TaskEControl.GetTaskResult();

            U50GlobalSetting.ScanTaskThread( taskInfo );

            this.button3.Enabled = false;
            this.Timer1.Enabled = true;

            //TaskPolicy taskPolicy = GetTaskPolicy();

            ////ReportInfo reportInfo = ScanTask( taskPolicy );
            //ReportInfo reportInfo = new ReportInfo();

            //for ( int i = 0; i < reportInfo.ReportArray.Length; i++ )
            //{
            //    Report report = reportInfo.ReportArray[i];
            //}
        }
 public void FromConfigTaskInfo( U50TaskInfo[] taskInfoArray )
 {
     for ( int iIndex = 0; iIndex < taskInfoArray.Length; iIndex++ )
         AddTaskInfo( taskInfoArray[iIndex] );
 }
        public static U50TaskInfo[] LoadTaskSetting( string strTaskFile )
        {
            if ( File.Exists( strTaskFile ) == false )
            {
                if ( U50GlobalSetting.TaskFilePath == strTaskFile )
                    SaveTaskSetting( U50GlobalSetting.TaskFilePath, U50GlobalSetting.TaskInfos );
                else
                    return null;
            }

            XDocument documentConfig = XDocument.Load( strTaskFile );
            if ( documentConfig == null )
                return null;

            XElement elementRoot = documentConfig.Element( (XName)"Demo.Stock" );
            if ( elementRoot == null )
                return null;

            XAttribute attributeVer = elementRoot.Attribute( (XName)"Ver" );
            if ( attributeVer == null )
                return null;

            //////////////////////////////////////////////////////////////////////////
            // <Settings>
            IEnumerable<XElement> elementU50Tasks = elementRoot.Elements( (XName)"U50Task" );
            if ( elementU50Tasks == null )
                return null;

            List<U50TaskInfo> policyInfoList = new List<U50TaskInfo>();
            foreach ( var elementU50Task in elementU50Tasks )
            {
                XAttribute attributeName = elementU50Task.Attribute( (XName)"Name" );
                if ( attributeName == null )
                    continue;

                XAttribute attributeGuid = elementU50Task.Attribute( (XName)"Guid" );
                if ( attributeGuid == null )
                    continue;

                U50TaskInfo taskInfo = new U50TaskInfo();
                taskInfo.Name = attributeName.Value;
                taskInfo.Guid = attributeGuid.Value;

                // U50Task -> General
                XElement elementGeneral = elementU50Task.Element( (XName)"General" );
                if ( elementGeneral == null )
                    continue;
                {
                    XAttribute attributeAutoScan = elementGeneral.Attribute( (XName)"SaneType" );
                    if ( attributeAutoScan == null )
                        continue;
                    else
                        taskInfo.General.SaneType = (U50TaskSaneType)int.Parse( attributeAutoScan.Value );
                }

                // U50Task -> Request
                XElement elementRequest = elementU50Task.Element( (XName)"Request" );
                if ( elementRequest == null )
                    continue;
                {
                    XAttribute attributeSelectType = elementRequest.Attribute( (XName)"SelectType" );
                    if ( attributeSelectType == null )
                        continue;
                    else
                        taskInfo.Request.Select = (U50TaskSelectType)int.Parse( attributeSelectType.Value );

                    XAttribute attributePlate = elementRequest.Attribute( (XName)"Plate" );
                    if ( attributePlate == null )
                        continue;
                    else
                        taskInfo.Request.Plate = attributePlate.Value;

                    XAttribute attributeVariety = elementRequest.Attribute( (XName)"Variety" );
                    if ( attributeVariety == null )
                        continue;
                    else
                        taskInfo.Request.Variety = attributeVariety.Value;

                    // U50Task -> Request -> StockInfo
                    IEnumerable<XElement> elementStockInfo = elementRequest.Elements( (XName)"StockInfo" );
                    if ( elementStockInfo != null )
                    {
                        List<U50StockInfo> stockInfoList = new List<U50StockInfo>();

                        foreach ( var item in elementStockInfo )
                        {
                            U50StockInfo stockInfo = new U50StockInfo();

                            XAttribute attributePlateSub = item.Attribute( (XName)"Plate" );
                            if ( attributePlateSub == null )
                                continue;
                            else
                                stockInfo.Plate = attributePlateSub.Value;

                            XAttribute attributeVarietySub = item.Attribute( (XName)"Variety" );
                            if ( attributeVarietySub == null )
                                continue;
                            else
                                stockInfo.Variety = attributeVarietySub.Value;

                            XAttribute attributeNameSub = item.Attribute( (XName)"Name" );
                            if ( attributeNameSub == null )
                                continue;
                            else
                                stockInfo.Name = attributeNameSub.Value;

                            XAttribute attributeSymbolSub = item.Attribute( (XName)"Symbol" );
                            if ( attributeSymbolSub == null )
                                continue;
                            else
                                stockInfo.Symbol = attributeSymbolSub.Value;

                            stockInfoList.Add( stockInfo );
                        }

                        taskInfo.Request.StockInfo = stockInfoList.ToArray();
                    }
                }

                // U50Task -> Policy
                XElement elementPolicy = elementU50Task.Element( (XName)"Policy" );
                if ( elementPolicy == null )
                    continue;
                {
                    XAttribute attributeScanType = elementPolicy.Attribute( (XName)"ScanType" );
                    if ( attributeScanType == null )
                        continue;
                    else
                        taskInfo.Policy.ScanType = (U50ScanType)int.Parse( attributeScanType.Value );

                    // U50Task -> Policy -> PolicyGuid
                    IEnumerable<XElement> elementPolicyGuid = elementPolicy.Elements( (XName)"PolicyGuid" );
                    if ( elementRequest != null )
                    {
                        List<string> stockPolicyList = new List<string>();

                        foreach ( var item in elementPolicyGuid )
                        {
                            XAttribute attributeNameSub = item.Attribute( (XName)"Guid" );
                            if ( attributeNameSub == null )
                                continue;
                            else
                                stockPolicyList.Add( attributeNameSub.Value );
                        }

                        taskInfo.Policy.PolicyGuid = stockPolicyList.ToArray();
                    }
                }

                // U50Task -> Result
                XElement elementResult = elementU50Task.Element( (XName)"Result" );
                if ( elementResult == null )
                    continue;
                {
                    // U50Task -> Request -> LastReportGuid
                    XAttribute attributeLastReportGuid = elementResult.Attribute( (XName)"LastReportGuid" );
                    if ( attributeLastReportGuid == null )
                        continue;
                    else
                        taskInfo.Result.LastReportGuid = attributeLastReportGuid.Value;
                }

                policyInfoList.Add( taskInfo );
            }

            return policyInfoList.ToArray();
        }
        public static U50ReportInfo[] LoadReports( string strTaskGuid )
        {
            U50ReportInfo[] reportInfos = new U50ReportInfo[0];

            if ( File.Exists( strTaskGuid ) == false )
                SaveReport( U50GlobalSetting.TaskFilePath, reportInfos );

            XDocument documentConfig = XDocument.Load( strTaskGuid );
            if ( documentConfig == null )
                return null;

            XElement elementRoot = documentConfig.Element( (XName)"Demo.Stock" );
            if ( elementRoot == null )
                return null;

            XAttribute attributeVer = elementRoot.Attribute( (XName)"Ver" );
            if ( attributeVer == null )
                return null;

            //////////////////////////////////////////////////////////////////////////
            // <Settings>
            IEnumerable<XElement> elementU50Reports = elementRoot.Elements( (XName)"U50Report" );
            if ( elementU50Reports == null )
                return null;

            List<U50ReportInfo> reportInfoList = new List<U50ReportInfo>();
            foreach ( var elementU50Task in elementU50Reports )
            {
                XAttribute attributeGuid = elementU50Task.Attribute( (XName)"Guid" );
                if ( attributeGuid == null )
                    continue;

                XAttribute attributeScanTime = elementU50Task.Attribute( (XName)"ScanTime" );
                if ( attributeScanTime == null )
                    continue;

                XAttribute attributeScanSpan = elementU50Task.Attribute( (XName)"ScanSpan" );
                if ( attributeScanSpan == null )
                    continue;

                U50ReportInfo reportInfo = new U50ReportInfo();
                reportInfo.Guid = attributeGuid.Value;
                reportInfo.ScanTime = DateTime.Parse( attributeScanTime.Value );
                reportInfo.ScanSpan = TimeSpan.Parse( attributeScanSpan.Value );

                XElement elementTask = elementU50Task.Element( (XName)"Task" );
                if ( elementTask == null )
                    continue;
                {
                    XAttribute attributeName = elementU50Task.Attribute( (XName)"Name" );
                    if ( attributeName == null )
                        continue;

                    XAttribute attributeGuid1 = elementU50Task.Attribute( (XName)"Guid" );
                    if ( attributeGuid1 == null )
                        continue;

                    U50TaskInfo taskInfo = new U50TaskInfo();
                    taskInfo.Name = attributeName.Value;
                    taskInfo.Guid = attributeGuid1.Value;

                    // U50Task -> General
                    XElement elementGeneral = elementU50Task.Element( (XName)"General" );
                    if ( elementGeneral == null )
                        continue;
                    {
                        XAttribute attributeAutoScan = elementGeneral.Attribute( (XName)"SaneType" );
                        if ( attributeAutoScan == null )
                            continue;
                        else
                            taskInfo.General.SaneType = (U50TaskSaneType)int.Parse( attributeAutoScan.Value );
                    }

                    // U50Task -> Request
                    XElement elementRequest = elementU50Task.Element( (XName)"Request" );
                    if ( elementRequest == null )
                        continue;
                    {
                        XAttribute attributeSelectType = elementRequest.Attribute( (XName)"SelectType" );
                        if ( attributeSelectType == null )
                            continue;
                        else
                            taskInfo.Request.Select = (U50TaskSelectType)int.Parse( attributeSelectType.Value );

                        XAttribute attributePlate = elementRequest.Attribute( (XName)"Plate" );
                        if ( attributePlate == null )
                            continue;
                        else
                            taskInfo.Request.Plate = attributePlate.Value;

                        XAttribute attributeVariety = elementRequest.Attribute( (XName)"Variety" );
                        if ( attributeVariety == null )
                            continue;
                        else
                            taskInfo.Request.Variety = attributeVariety.Value;

                        // U50Task -> Request -> StockInfo
                        IEnumerable<XElement> elementStockInfo = elementRequest.Elements( (XName)"StockInfo" );
                        if ( elementStockInfo == null )
                            continue;
                        {
                            List<U50StockInfo> stockInfoList = new List<U50StockInfo>();

                            foreach ( var item in elementStockInfo )
                            {
                                U50StockInfo stockInfo = new U50StockInfo();

                                XAttribute attributePlateSub = item.Attribute( (XName)"Plate" );
                                if ( attributePlateSub == null )
                                    continue;
                                else
                                    stockInfo.Variety = attributeVariety.Value;

                                XAttribute attributeVarietySub = item.Attribute( (XName)"Variety" );
                                if ( attributeVarietySub == null )
                                    continue;
                                else
                                    stockInfo.Variety = attributeVariety.Value;

                                XAttribute attributeNameSub = item.Attribute( (XName)"Name" );
                                if ( attributeNameSub == null )
                                    continue;
                                else
                                    stockInfo.Name = attributeVariety.Value;

                                XAttribute attributeSymbolSub = item.Attribute( (XName)"Symbol" );
                                if ( attributeSymbolSub == null )
                                    continue;
                                else
                                    stockInfo.Symbol = attributeVariety.Value;

                                stockInfoList.Add( stockInfo );
                            }

                            taskInfo.Request.StockInfo = stockInfoList.ToArray();
                        }
                    }

                    // U50Task -> Policy
                    XElement elementPolicy = elementU50Task.Element( (XName)"Policy" );
                    if ( elementPolicy == null )
                        continue;
                    {
                        XAttribute attributeScanType = elementPolicy.Attribute( (XName)"ScanType" );
                        if ( attributeScanType == null )
                            continue;
                        else
                            taskInfo.Policy.ScanType = (U50ScanType)int.Parse( attributeScanType.Value );

                        // U50Task -> Policy -> PolicyGuid
                        IEnumerable<XElement> elementPolicyGuid = elementPolicy.Elements( (XName)"PolicyGuid" );
                        if ( elementRequest == null )
                            continue;
                        {
                            List<string> stockPolicyList = new List<string>();

                            foreach ( var item in elementPolicyGuid )
                            {
                                XAttribute attributeNameSub = item.Attribute( (XName)"Guid" );
                                if ( attributeNameSub == null )
                                    continue;
                                else
                                    stockPolicyList.Add( attributeNameSub.Value );
                            }

                            taskInfo.Policy.PolicyGuid = stockPolicyList.ToArray();
                        }
                    }

                    // U50Task -> Result
                    XElement elementResult = elementU50Task.Element( (XName)"Result" );
                    if ( elementResult == null )
                        continue;
                    {
                        // U50Task -> Request -> LastReportGuid
                        XAttribute attributeStockInfo = elementResult.Attribute( (XName)"LastReportGuid" );
                        if ( attributeStockInfo == null )
                            continue;
                        else
                            taskInfo.Result.LastReportGuid = attributeStockInfo.Value;
                    }

                    reportInfo.StaticTaskInfo = taskInfo;
                }

                IEnumerable<XElement> elementPolicyInfo = elementU50Task.Elements( (XName)"PolicyInfo" );
                if ( elementPolicyInfo == null )
                    continue;
                {
                    List<U50PolicyInfo> rolicyInfo = new List<U50PolicyInfo>();
                    foreach ( var item in elementPolicyInfo )
                    {
                        XAttribute attributeName = item.Attribute( (XName)"Name" );
                        if ( attributeName == null )
                            continue;

                        XAttribute attributeGuid11 = item.Attribute( (XName)"Guid" );
                        if ( attributeGuid11 == null )
                            continue;

                        U50PolicyInfo policyInfo = new U50PolicyInfo { Name = attributeName.Value, Guid = attributeGuid11.Value };

                        // U50Policy -> Policy
                        XElement elementPolicy = item.Element( (XName)"Policy" );
                        if ( elementPolicy == null )
                            continue;

                        // U50Policy -> Policy -> DateTime
                        XElement elementDateTime = elementPolicy.Element( (XName)"DateTime" );
                        if ( elementDateTime == null )
                            continue;
                        {
                            XAttribute attributeIsDateNow = elementDateTime.Attribute( (XName)"IsDateNow" );
                            if ( attributeIsDateNow == null )
                                continue;
                            else
                                policyInfo.Policy.IsDateNow = bool.Parse( attributeIsDateNow.Value );

                            XAttribute attributeKN = elementDateTime.Attribute( (XName)"KN" );
                            if ( attributeKN == null )
                                continue;
                            else
                                policyInfo.Policy.KN = uint.Parse( attributeKN.Value );

                            XAttribute attributeDate = elementDateTime.Attribute( (XName)"Date" );
                            if ( attributeDate == null )
                                continue;
                            else
                                policyInfo.Policy.DateSelect = DateTime.Parse( attributeDate.Value );
                        }

                        // U50Policy -> Policy -> ExOption
                        XElement elementExOption = elementPolicy.Element( (XName)"ExOption" );
                        if ( elementExOption == null )
                            continue;
                        {
                            XAttribute attributePriority = elementExOption.Attribute( (XName)"Priority" );
                            if ( attributePriority == null )
                                continue;
                            else
                                policyInfo.Policy.Priority = (U50PriorityType)int.Parse( attributePriority.Value );

                            XAttribute attributeOutput = elementExOption.Attribute( (XName)"Output" );
                            if ( attributeOutput == null )
                                continue;
                            else
                                policyInfo.Policy.Output = (U50OutputType)int.Parse( attributeOutput.Value );

                            // U50Policy -> Policy -> ExOption -> Date
                            XElement elementDate = elementExOption.Element( (XName)"Date" );
                            if ( elementDate == null )
                                continue;
                            {
                                XAttribute attributeDateAllow = elementDate.Attribute( (XName)"Allow" );
                                if ( attributeDateAllow == null )
                                    continue;
                                else
                                    policyInfo.Policy.IsAllowDate = bool.Parse( attributeDateAllow.Value );

                                XAttribute attributeDateStep = elementDate.Attribute( (XName)"Step" );
                                if ( attributeDateStep == null )
                                    continue;
                                else
                                    policyInfo.Policy.DateStep = uint.Parse( attributeDateStep.Value );

                                XAttribute attributeDateEnd = elementDate.Attribute( (XName)"End" );
                                if ( attributeDateEnd == null )
                                    continue;
                                else
                                    policyInfo.Policy.DateEnd = DateTime.Parse( attributeDateEnd.Value );
                            }

                            // U50Policy -> Policy -> ExOption -> KN
                            XElement elementKN = elementExOption.Element( (XName)"KN" );
                            if ( elementKN == null )
                                continue;
                            {
                                XAttribute attributeKNAllow = elementKN.Attribute( (XName)"Allow" );
                                if ( attributeKNAllow == null )
                                    continue;
                                else
                                    policyInfo.Policy.IsAllowKN = bool.Parse( attributeKNAllow.Value );

                                XAttribute attributeKNStep = elementKN.Attribute( (XName)"Step" );
                                if ( attributeKNStep == null )
                                    continue;
                                else
                                    policyInfo.Policy.KNStep = uint.Parse( attributeKNStep.Value );

                                XAttribute attributeKNEnd = elementKN.Attribute( (XName)"End" );
                                if ( attributeKNEnd == null )
                                    continue;
                                else
                                    policyInfo.Policy.KNEnd = uint.Parse( attributeKNEnd.Value );
                            }
                        }

                        // U50Policy -> Filtrate
                        XElement elementFiltrate = item.Element( (XName)"Filtrate" );
                        if ( elementFiltrate == null )
                            continue;
                        {
                            // U50Policy -> Filtrate -> PDU
                            XElement elementPDU = elementFiltrate.Element( (XName)"PDU" );
                            if ( elementPDU == null )
                                continue;
                            {
                                XAttribute attributePDUEnabled = elementPDU.Attribute( (XName)"Enabled" );
                                if ( attributePDUEnabled == null )
                                    continue;
                                else
                                    policyInfo.Filtrate.PDU.Enabled = bool.Parse( attributePDUEnabled.Value );

                                XAttribute attributePDUSelect = elementPDU.Attribute( (XName)"Select" );
                                if ( attributePDUSelect == null )
                                    continue;
                                else
                                    policyInfo.Filtrate.PDU.Select = (U50SelectType)int.Parse( attributePDUSelect.Value );

                                XAttribute attributePDUBig = elementPDU.Attribute( (XName)"Big" );
                                if ( attributePDUBig == null )
                                    continue;
                                else
                                    policyInfo.Filtrate.PDU.Big = float.Parse( attributePDUBig.Value );

                                XAttribute attributePDUSmall = elementPDU.Attribute( (XName)"Small" );
                                if ( attributePDUSmall == null )
                                    continue;
                                else
                                    policyInfo.Filtrate.PDU.Small = float.Parse( attributePDUSmall.Value );
                            }

                            // U50Policy -> Filtrate -> PCU
                            XElement elementPCU = elementFiltrate.Element( (XName)"PCU" );
                            if ( elementPCU == null )
                                continue;
                            {
                                XAttribute attributePCUEnabled = elementPCU.Attribute( (XName)"Enabled" );
                                if ( attributePCUEnabled == null )
                                    continue;
                                else
                                    policyInfo.Filtrate.PCU.Enabled = bool.Parse( attributePCUEnabled.Value );

                                XAttribute attributePCUSelect = elementPCU.Attribute( (XName)"Select" );
                                if ( attributePCUSelect == null )
                                    continue;
                                else
                                    policyInfo.Filtrate.PCU.Select = (U50SelectType)int.Parse( attributePCUSelect.Value );

                                XAttribute attributePCUBig = elementPCU.Attribute( (XName)"Big" );
                                if ( attributePCUBig == null )
                                    continue;
                                else
                                    policyInfo.Filtrate.PCU.Big = float.Parse( attributePCUBig.Value );

                                XAttribute attributePCUSmall = elementPCU.Attribute( (XName)"Small" );
                                if ( attributePCUSmall == null )
                                    continue;
                                else
                                    policyInfo.Filtrate.PCU.Small = float.Parse( attributePCUSmall.Value );
                            }

                            // U50Policy -> Filtrate -> TDU
                            XElement elementTDU = elementFiltrate.Element( (XName)"TDU" );
                            if ( elementTDU == null )
                                continue;
                            {
                                XAttribute attributeTDUEnabled = elementTDU.Attribute( (XName)"Enabled" );
                                if ( attributeTDUEnabled == null )
                                    continue;
                                else
                                    policyInfo.Filtrate.TDU.Enabled = bool.Parse( attributeTDUEnabled.Value );

                                XAttribute attributeTDUSelect = elementTDU.Attribute( (XName)"Select" );
                                if ( attributeTDUSelect == null )
                                    continue;
                                else
                                    policyInfo.Filtrate.TDU.Select = (U50SelectType)int.Parse( attributeTDUSelect.Value );

                                XAttribute attributeTDUBig = elementTDU.Attribute( (XName)"Big" );
                                if ( attributeTDUBig == null )
                                    continue;
                                else
                                    policyInfo.Filtrate.TDU.Big = float.Parse( attributeTDUBig.Value );

                                XAttribute attributeTDUSmall = elementTDU.Attribute( (XName)"Small" );
                                if ( attributeTDUSmall == null )
                                    continue;
                                else
                                    policyInfo.Filtrate.TDU.Small = float.Parse( attributeTDUSmall.Value );
                            }

                            // U50Policy -> Filtrate -> TCD
                            XElement elementTCD = elementFiltrate.Element( (XName)"TCD" );
                            if ( elementTCD == null )
                                continue;
                            {
                                XAttribute attributeTCDEnabled = elementTCD.Attribute( (XName)"Enabled" );
                                if ( attributeTCDEnabled == null )
                                    continue;
                                else
                                    policyInfo.Filtrate.TCD.Enabled = bool.Parse( attributeTCDEnabled.Value );

                                XAttribute attributeTCDSelect = elementTCD.Attribute( (XName)"Select" );
                                if ( attributeTCDSelect == null )
                                    continue;
                                else
                                    policyInfo.Filtrate.TCD.Select = (U50SelectType)int.Parse( attributeTCDSelect.Value );

                                XAttribute attributeTCDBig = elementTCD.Attribute( (XName)"Big" );
                                if ( attributeTCDBig == null )
                                    continue;
                                else
                                    policyInfo.Filtrate.TCD.Big = float.Parse( attributeTCDBig.Value );

                                XAttribute attributeTCDSmall = elementTCD.Attribute( (XName)"Small" );
                                if ( attributeTCDSmall == null )
                                    continue;
                                else
                                    policyInfo.Filtrate.TCD.Small = float.Parse( attributeTCDSmall.Value );
                            }

                            // U50Policy -> Filtrate -> TBU
                            XElement elementTBU = elementFiltrate.Element( (XName)"TBU" );
                            if ( elementTBU == null )
                                continue;
                            {
                                XAttribute attributeTCUEnabled = elementTBU.Attribute( (XName)"Enabled" );
                                if ( attributeTCUEnabled == null )
                                    continue;
                                else
                                    policyInfo.Filtrate.TBU.Enabled = bool.Parse( attributeTCUEnabled.Value );

                                XAttribute attributeTCUSelect = elementTBU.Attribute( (XName)"Select" );
                                if ( attributeTCUSelect == null )
                                    continue;
                                else
                                    policyInfo.Filtrate.TBU.Select = (U50SelectType)int.Parse( attributeTCUSelect.Value );

                                XAttribute attributeTCUBig = elementTBU.Attribute( (XName)"Big" );
                                if ( attributeTCUBig == null )
                                    continue;
                                else
                                    policyInfo.Filtrate.TBU.Big = float.Parse( attributeTCUBig.Value );

                                XAttribute attributeTCUSmall = elementTBU.Attribute( (XName)"Small" );
                                if ( attributeTCUSmall == null )
                                    continue;
                                else
                                    policyInfo.Filtrate.TBU.Small = float.Parse( attributeTCUSmall.Value );
                            }

                            // U50Policy -> Filtrate -> Vac-UC
                            XElement elementVacUC = elementFiltrate.Element( (XName)"Vac-UC" );
                            if ( elementVacUC == null )
                                continue;
                            {
                                XAttribute attributeVacUCEnabled = elementVacUC.Attribute( (XName)"Enabled" );
                                if ( attributeVacUCEnabled == null )
                                    continue;
                                else
                                    policyInfo.Filtrate.VacUC.Enabled = bool.Parse( attributeVacUCEnabled.Value );

                                XAttribute attributeVacUCSelect = elementVacUC.Attribute( (XName)"Select" );
                                if ( attributeVacUCSelect == null )
                                    continue;
                                else
                                    policyInfo.Filtrate.VacUC.Select = (U50SelectType)int.Parse( attributeVacUCSelect.Value );

                                XAttribute attributeVacUCBig = elementVacUC.Attribute( (XName)"Big" );
                                if ( attributeVacUCBig == null )
                                    continue;
                                else
                                    policyInfo.Filtrate.VacUC.Big = float.Parse( attributeVacUCBig.Value );

                                XAttribute attributeVacUCSmall = elementVacUC.Attribute( (XName)"Small" );
                                if ( attributeVacUCSmall == null )
                                    continue;
                                else
                                    policyInfo.Filtrate.VacUC.Small = float.Parse( attributeVacUCSmall.Value );
                            }
                        }

                        // U50Policy -> Extend
                        XElement elementExtend = item.Element( (XName)"Extend" );
                        if ( elementExtend == null )
                            continue;
                        {
                            // U50Policy -> Extend -> Info01
                            XElement elementInfo01 = elementExtend.Element( (XName)"Info01" );
                            if ( elementInfo01 == null )
                                continue;
                            {
                                XAttribute attributeInfo01Enabled = elementInfo01.Attribute( (XName)"Enabled" );
                                if ( attributeInfo01Enabled == null )
                                    continue;
                                else
                                    policyInfo.Extend.Info01.Enabled = bool.Parse( attributeInfo01Enabled.Value );

                                XAttribute attributeInfo01Select = elementInfo01.Attribute( (XName)"Select" );
                                if ( attributeInfo01Select == null )
                                    continue;
                                else
                                    policyInfo.Extend.Info01.Select = (U50ExtendInfo01Type)int.Parse( attributeInfo01Select.Value );

                                XAttribute attributeInfo01Big = elementInfo01.Attribute( (XName)"HighNumber" );
                                if ( attributeInfo01Big == null )
                                    continue;
                                else
                                    policyInfo.Extend.Info01.HighNumber = int.Parse( attributeInfo01Big.Value );
                            }

                            // U50Policy -> Extend -> Info02
                            XElement elementInfo02 = elementExtend.Element( (XName)"Info02" );
                            if ( elementInfo02 == null )
                                continue;
                            {
                                XAttribute attributeInfo02Enabled = elementInfo02.Attribute( (XName)"Enabled" );
                                if ( attributeInfo02Enabled == null )
                                    continue;
                                else
                                    policyInfo.Extend.Info02.Enabled = bool.Parse( attributeInfo02Enabled.Value );

                                XAttribute attributeInfo02Select = elementInfo02.Attribute( (XName)"Select" );
                                if ( attributeInfo02Select == null )
                                    continue;
                                else
                                    policyInfo.Extend.Info02.Select = (U50SelectType)int.Parse( attributeInfo02Select.Value );

                                XAttribute attributeInfo02Big = elementInfo02.Attribute( (XName)"Big" );
                                if ( attributeInfo02Big == null )
                                    continue;
                                else
                                    policyInfo.Extend.Info02.Big = long.Parse( attributeInfo02Big.Value );

                                XAttribute attributeInfo02Small = elementInfo02.Attribute( (XName)"Small" );
                                if ( attributeInfo02Small == null )
                                    continue;
                                else
                                    policyInfo.Extend.Info02.Small = long.Parse( attributeInfo02Small.Value );
                            }

                            // U50Policy -> Extend -> Info03
                            XElement elementInfo03 = elementExtend.Element( (XName)"Info03" );
                            if ( elementInfo03 == null )
                                continue;
                            {
                                XAttribute attributeInfo03Enabled = elementInfo03.Attribute( (XName)"Enabled" );
                                if ( attributeInfo03Enabled == null )
                                    continue;
                                else
                                    policyInfo.Extend.Info03.Enabled = bool.Parse( attributeInfo03Enabled.Value );

                                XAttribute attributeInfo03Select = elementInfo03.Attribute( (XName)"Select" );
                                if ( attributeInfo03Select == null )
                                    continue;
                                else
                                    policyInfo.Extend.Info03.Select = (U50SelectType)int.Parse( attributeInfo03Select.Value );

                                XAttribute attributeInfo03Big = elementInfo03.Attribute( (XName)"Big" );
                                if ( attributeInfo03Big == null )
                                    continue;
                                else
                                    policyInfo.Extend.Info03.Big = int.Parse( attributeInfo03Big.Value );

                                XAttribute attributeInfo03Small = elementInfo03.Attribute( (XName)"Small" );
                                if ( attributeInfo03Small == null )
                                    continue;
                                else
                                    policyInfo.Extend.Info03.Small = int.Parse( attributeInfo03Small.Value );
                            }

                            // U50Policy -> Extend -> Info04
                            XElement elementInfo04 = elementExtend.Element( (XName)"Info04" );
                            if ( elementInfo04 == null )
                                continue;
                            {
                                XAttribute attributeInfo04Enabled = elementInfo04.Attribute( (XName)"Enabled" );
                                if ( attributeInfo04Enabled == null )
                                    continue;
                                else
                                    policyInfo.Extend.Info04.Enabled = bool.Parse( attributeInfo04Enabled.Value );

                                XAttribute attributeInfo04Select = elementInfo04.Attribute( (XName)"Select" );
                                if ( attributeInfo04Select == null )
                                    continue;
                                else
                                    policyInfo.Extend.Info04.Select = (U50ExtendInfo04Type)int.Parse( attributeInfo04Select.Value );
                            }

                            // U50Policy -> Extend -> Info05
                            XElement elementInfo05 = elementExtend.Element( (XName)"Info05" );
                            if ( elementInfo05 == null )
                                continue;
                            {
                                XAttribute attributeInfo05Enabled = elementInfo05.Attribute( (XName)"Enabled" );
                                if ( attributeInfo05Enabled == null )
                                    continue;
                                else
                                    policyInfo.Extend.Info05.Enabled = bool.Parse( attributeInfo05Enabled.Value );

                                XAttribute attributeInfo05Select = elementInfo05.Attribute( (XName)"Select" );
                                if ( attributeInfo05Select == null )
                                    continue;
                                else
                                    policyInfo.Extend.Info05.Select = (U50SelectType)int.Parse( attributeInfo05Select.Value );

                                XAttribute attributeInfo05Big = elementInfo05.Attribute( (XName)"Big" );
                                if ( attributeInfo05Big == null )
                                    continue;
                                else
                                    policyInfo.Extend.Info05.Big = int.Parse( attributeInfo05Big.Value );

                                XAttribute attributeInfo05Small = elementInfo05.Attribute( (XName)"Small" );
                                if ( attributeInfo05Small == null )
                                    continue;
                                else
                                    policyInfo.Extend.Info05.Small = int.Parse( attributeInfo05Small.Value );
                            }
                        }

                        rolicyInfo.Add( policyInfo );
                    }

                    reportInfo.StaticReportInfo = rolicyInfo.ToArray();
                }

                IEnumerable<XElement> elementReportInfo = elementU50Task.Elements( (XName)"ReportInfo" );
                if ( elementReportInfo == null )
                    continue;
                {
                    List<U50Report> reportList = new List<U50Report>();
                    foreach ( var item in elementReportInfo )
                    {
                        U50Report report = new U50Report();

                        XAttribute attributeName = item.Attribute( (XName)"Name" );
                        if ( attributeName == null )
                            continue;
                        else
                            report.Name = attributeName.Value;

                        XAttribute attributeSymbol = item.Attribute( (XName)"Symbol" );
                        if ( attributeSymbol == null )
                            continue;
                        else
                            report.Symbol = attributeSymbol.Value;

                        //XAttribute attributeS_Date = item.Attribute( (XName)"S_Date" );
                        //if ( attributeS_Date == null )
                        //    continue;
                        //else
                        //    report.S_Date = DateTime.Parse( attributeS_Date.Value );

                        //XAttribute attributeVa_U50 = item.Attribute( (XName)"Va_U50" );
                        //if ( attributeVa_U50 == null )
                        //    continue;
                        //else
                        //    report.Va_U50 = int.Parse( attributeVa_U50.Value );

                        //XAttribute attributeVsc = item.Attribute( (XName)"Vsc" );
                        //if ( attributeVsc == null )
                        //    continue;
                        //else
                        //    report.Vsc = int.Parse( attributeVsc.Value );

                        //XAttribute attributeClose = item.Attribute( (XName)"Close" );
                        //if ( attributeClose == null )
                        //    continue;
                        //else
                        //    report.Close = int.Parse( attributeClose.Value );

                        //XAttribute attributeScanner = item.Attribute( (XName)"Scanner" );
                        //if ( attributeScanner == null )
                        //    continue;
                        //else
                        //    report.Scanner = attributeScanner.Value;

                        //XAttribute attributeQ_U50 = item.Attribute( (XName)"Q_U50" );
                        //if ( attributeQ_U50 == null )
                        //    continue;
                        //else
                        //    report.Q_U50 = int.Parse( attributeQ_U50.Value );

                        //XAttribute attributeKLineNumber = item.Attribute( (XName)"KLineNumber" );
                        //if ( attributeKLineNumber == null )
                        //    continue;
                        //else
                        //    report.KLineNumber = int.Parse( attributeKLineNumber.Value );

                        XAttribute attributeScanTime1 = item.Attribute( (XName)"ScanTime" );
                        if ( attributeScanTime1 == null )
                            continue;
                        else
                            report.ScanTime = DateTime.Parse( attributeScanTime1.Value );

                        XAttribute attributeScanSpan1 = item.Attribute( (XName)"ScanSpan" );
                        if ( attributeScanSpan1 == null )
                            continue;
                        else
                            report.ScanSpan = TimeSpan.Parse( attributeScanSpan1.Value );

                        reportList.Add( report );
                    }

                    reportInfo.ReportArray = reportList.ToArray();
                }

                reportInfoList.Add( reportInfo );
            }

            return reportInfos;
        }
        public static U50ReportInfo ScanTask( U50TaskInfo taskInfo )
        {
            U50ReportInfo reportInfo = new U50ReportInfo();
            reportInfo.Guid = Guid.NewGuid().ToString();
            reportInfo.ScanTime = DateTime.Now;
            reportInfo.StaticTaskInfo = taskInfo;

            List<U50PolicyInfo> policyInfoList = new List<U50PolicyInfo>();
            foreach ( var policyGuid in taskInfo.Policy.PolicyGuid )
            {
                U50PolicyInfo policyInfo = PolicyManager.Instance.GetPolicyInfoByGuid( policyGuid );
                if ( policyInfo == null )
                    continue;
                else
                    policyInfoList.Add( policyInfo );
            }
            reportInfo.StaticReportInfo = policyInfoList.ToArray();

            //MessageBox.Show("reportInfo.StaticReportInf = " + policyInfoList.Count.ToString() );

            List<Demo.Stock.X.Common.StockInfo> stockInfoList = new List<Demo.Stock.X.Common.StockInfo>();
            foreach ( var stockInfo in taskInfo.Request.StockInfo )
            {
                StockManager stockManager = GlobalStockManager.GetStockManagerByPlateAndVariety(stockInfo.Plate, stockInfo.Variety);
                if ( stockManager == null )
                    continue;

                Demo.Stock.X.Common.StockInfo stockInfox = stockManager.GetStockDataByStockCode( GlobalSetting.GetStockCode( stockInfo.Name, stockInfo.Symbol ) );
                if ( stockInfox == null )
                    continue;
                else
                    stockInfoList.Add( stockInfox );
            }

            //MessageBox.Show("stockInfoList = " + stockInfoList.Count.ToString() );

            List<U50Report> reportList = new List<U50Report>();
            foreach ( var stockInfoxx in stockInfoList )
            {
                foreach ( var policyInfoxx in policyInfoList )
                {

                    if ( policyInfoxx.Policy.Priority == U50PriorityType.BaseDate )
                    {
                        if ( policyInfoxx.Policy.IsAllowDate )
                        {

                            //MessageBox.Show( "policyInfoxx.Policy.IsAllowDate" );

                            DateTime iStart = DateTime.Now;
                            if ( policyInfoxx.Policy.IsDateNow != true )
                                iStart = policyInfoxx.Policy.DateSelect;
                            for ( ; iStart > policyInfoxx.Policy.DateEnd; iStart -= TimeSpan.FromDays( policyInfoxx.Policy.DateStep ) )
                            {
                                StockData[] stockDataArray = stockInfoxx.GetStockDataRangeByKn( iStart, (int)policyInfoxx.Policy.KN );

                                //MessageBox.Show( "stockDataArray = " + stockDataArray.Length.ToString() );
                                //MessageBox.Show( "iStart = " + iStart.ToString() );

                                U50Report report = new U50Report();
                                report.Name = stockInfoxx.StockName;
                                report.Symbol = stockInfoxx.StockSymbol;
                                report.Guid = policyInfoxx.Guid;

                                report.ReportSubInfo.S_Date = iStart;

                                report.ScanTime = DateTime.Now;

                                bool isOK = IsPassGeneral( stockDataArray, stockInfoxx, policyInfoxx.Filtrate, policyInfoxx.Extend, ref report.ReportSubInfo );
                                if ( isOK == false )
                                    continue;
                                else
                                {
                                    report.ScanSpan = DateTime.Now - report.ScanTime;
                                    reportList.Add( report );

                                    if ( policyInfoxx.Policy.Output == U50OutputType.One )
                                        break;
                                }
                            }
                        }

                        if ( policyInfoxx.Policy.IsAllowKN )
                        {
                            //MessageBox.Show( "policyInfoxx.Policy.IsAllowKN" );

                            DateTime iStart = DateTime.Now;
                            if ( policyInfoxx.Policy.IsDateNow != true )
                                iStart = policyInfoxx.Policy.DateSelect;
                            for ( int iKn = (int)policyInfoxx.Policy.KN; iKn < policyInfoxx.Policy.KNEnd; iKn += (int)policyInfoxx.Policy.KNStep )
                            {
                                StockData[] stockDataArray = stockInfoxx.GetStockDataRangeByKn( iStart, (int)policyInfoxx.Policy.KN );

                                U50Report report = new U50Report();
                                report.Name = stockInfoxx.StockName;
                                report.Symbol = stockInfoxx.StockSymbol;
                                report.Guid = policyInfoxx.Guid;

                                report.ReportSubInfo.S_Date = iStart;

                                report.ScanTime = DateTime.Now;

                                bool isOK = IsPassGeneral( stockDataArray, stockInfoxx, policyInfoxx.Filtrate, policyInfoxx.Extend, ref report.ReportSubInfo );
                                if ( isOK == false )
                                    continue;
                                else
                                {
                                    report.ScanSpan = DateTime.Now - report.ScanTime;
                                    reportList.Add( report );

                                    if ( policyInfoxx.Policy.Output == U50OutputType.One )
                                        break;
                                }
                            }
                        }

                        if ( policyInfoxx.Policy.IsAllowDate == false && policyInfoxx.Policy.IsAllowKN == false )
                        {
                            //MessageBox.Show( "policyInfoxx.Policy.IsAllowDate&IsAllowKN false" );

                            DateTime iStart = DateTime.Now;
                            if ( policyInfoxx.Policy.IsDateNow != true )
                                iStart = policyInfoxx.Policy.DateSelect;

                            StockData[] stockDataArray = stockInfoxx.GetStockDataRangeByKn( iStart, (int)policyInfoxx.Policy.KN );

                            U50Report report = new U50Report();
                            report.Name = stockInfoxx.StockName;
                            report.Symbol = stockInfoxx.StockSymbol;
                            report.Guid = policyInfoxx.Guid;

                            report.ReportSubInfo.S_Date = iStart;

                            report.ScanTime = DateTime.Now;

                            bool isOK = IsPassGeneral( stockDataArray, stockInfoxx, policyInfoxx.Filtrate, policyInfoxx.Extend, ref report.ReportSubInfo );
                            if ( isOK == false )
                                continue;

                            report.ScanSpan = DateTime.Now - report.ScanTime;

                            reportList.Add( report );
                        }
                    }
                    else if ( policyInfoxx.Policy.Priority == U50PriorityType.BaseKN )
                    {
                        if ( policyInfoxx.Policy.IsAllowKN )
                        {
                            DateTime iStart = DateTime.Now;
                            if ( policyInfoxx.Policy.IsDateNow != true )
                                iStart = policyInfoxx.Policy.DateSelect;
                            for ( int iKn = (int)policyInfoxx.Policy.KN; iKn < policyInfoxx.Policy.KNEnd; iKn += (int)policyInfoxx.Policy.KNStep )
                            {
                                StockData[] stockDataArray = stockInfoxx.GetStockDataRangeByKn( iStart, (int)policyInfoxx.Policy.KN );

                                U50Report report = new U50Report();
                                report.Name = stockInfoxx.StockName;
                                report.Symbol = stockInfoxx.StockSymbol;
                                report.Guid = policyInfoxx.Guid;

                                report.ReportSubInfo.S_Date = iStart;

                                report.ScanTime = DateTime.Now;

                                bool isOK = IsPassGeneral( stockDataArray, stockInfoxx, policyInfoxx.Filtrate, policyInfoxx.Extend, ref report.ReportSubInfo );
                                if ( isOK == false )
                                    continue;

                                else
                                {
                                    report.ScanSpan = DateTime.Now - report.ScanTime;
                                    reportList.Add( report );

                                    if ( policyInfoxx.Policy.Output == U50OutputType.One )
                                        break;
                                }
                            }
                        }

                        if ( policyInfoxx.Policy.IsAllowDate )
                        {
                            DateTime iStart = DateTime.Now;
                            if ( policyInfoxx.Policy.IsDateNow != true )
                                iStart = policyInfoxx.Policy.DateSelect;
                            for ( ; iStart > policyInfoxx.Policy.DateEnd; iStart -= TimeSpan.FromDays( policyInfoxx.Policy.DateStep ) )
                            {
                                StockData[] stockDataArray = stockInfoxx.GetStockDataRangeByKn( iStart, (int)policyInfoxx.Policy.KN );

                                U50Report report = new U50Report();
                                report.Name = stockInfoxx.StockName;
                                report.Symbol = stockInfoxx.StockSymbol;
                                report.Guid = policyInfoxx.Guid;

                                report.ReportSubInfo.S_Date = iStart;

                                report.ScanTime = DateTime.Now;

                                bool isOK = IsPassGeneral( stockDataArray, stockInfoxx, policyInfoxx.Filtrate, policyInfoxx.Extend, ref report.ReportSubInfo );
                                if ( isOK == false )
                                    continue;
                                else
                                {
                                    report.ScanSpan = DateTime.Now - report.ScanTime;
                                    reportList.Add( report );

                                    if ( policyInfoxx.Policy.Output == U50OutputType.One )
                                        break;
                                }
                            }
                        }

                        if ( policyInfoxx.Policy.IsAllowDate == false && policyInfoxx.Policy.IsAllowKN == false )
                        {
                            DateTime iStart = DateTime.Now;
                            if ( policyInfoxx.Policy.IsDateNow != true )
                                iStart = policyInfoxx.Policy.DateSelect;

                            StockData[] stockDataArray = stockInfoxx.GetStockDataRangeByKn( iStart, (int)policyInfoxx.Policy.KN );

                            U50Report report = new U50Report();
                            report.Name = stockInfoxx.StockName;
                            report.Symbol = stockInfoxx.StockSymbol;
                            report.Guid = policyInfoxx.Guid;

                            report.ReportSubInfo.S_Date = iStart;

                            report.ScanTime = DateTime.Now;

                            bool isOK = IsPassGeneral( stockDataArray, stockInfoxx, policyInfoxx.Filtrate, policyInfoxx.Extend, ref report.ReportSubInfo );
                            if ( isOK == false )
                                continue;

                            report.ScanSpan = DateTime.Now - report.ScanTime;

                            reportList.Add( report );
                        }
                    }
                    else
                    {
                        if ( policyInfoxx.Policy.IsAllowKN )
                        {
                            DateTime iStart = DateTime.Now;
                            if ( policyInfoxx.Policy.IsDateNow != true )
                                iStart = policyInfoxx.Policy.DateSelect;
                            for ( int iKn = (int)policyInfoxx.Policy.KN; iKn < policyInfoxx.Policy.KNEnd; iKn += (int)policyInfoxx.Policy.KNStep )
                            {
                                StockData[] stockDataArray = stockInfoxx.GetStockDataRangeByKn( iStart, (int)policyInfoxx.Policy.KN );

                                U50Report report = new U50Report();
                                report.Name = stockInfoxx.StockName;
                                report.Symbol = stockInfoxx.StockSymbol;
                                report.Guid = policyInfoxx.Guid;

                                report.ReportSubInfo.S_Date = iStart;

                                report.ScanTime = DateTime.Now;

                                bool isOK = IsPassGeneral( stockDataArray, stockInfoxx, policyInfoxx.Filtrate, policyInfoxx.Extend, ref report.ReportSubInfo );
                                if ( isOK == false )
                                    continue;
                                else
                                {
                                    report.ScanSpan = DateTime.Now - report.ScanTime;
                                    reportList.Add( report );

                                    if ( policyInfoxx.Policy.Output == U50OutputType.One )
                                        break;
                                }
                            }
                        }

                        if ( policyInfoxx.Policy.IsAllowDate )
                        {
                            DateTime iStart = DateTime.Now;
                            if ( policyInfoxx.Policy.IsDateNow != true )
                                iStart = policyInfoxx.Policy.DateSelect;
                            for ( ; iStart > policyInfoxx.Policy.DateEnd; iStart -= TimeSpan.FromDays( policyInfoxx.Policy.DateStep ) )
                            {
                                StockData[] stockDataArray = stockInfoxx.GetStockDataRangeByKn( iStart, (int)policyInfoxx.Policy.KN );

                                U50Report report = new U50Report();
                                report.Name = stockInfoxx.StockName;
                                report.Symbol = stockInfoxx.StockSymbol;
                                report.Guid = policyInfoxx.Guid;

                                report.ReportSubInfo.S_Date = iStart;

                                report.ScanTime = DateTime.Now;

                                bool isOK = IsPassGeneral( stockDataArray, stockInfoxx, policyInfoxx.Filtrate, policyInfoxx.Extend, ref report.ReportSubInfo );
                                if ( isOK == false )
                                    continue;
                                else
                                {
                                    report.ScanSpan = DateTime.Now - report.ScanTime;
                                    reportList.Add( report );

                                    if ( policyInfoxx.Policy.Output == U50OutputType.One )
                                        break;
                                }
                            }
                        }


                        if ( policyInfoxx.Policy.IsAllowDate == false && policyInfoxx.Policy.IsAllowKN == false )
                        {
                            DateTime iStart = DateTime.Now;
                            if ( policyInfoxx.Policy.IsDateNow != true )
                                iStart = policyInfoxx.Policy.DateSelect;

                            StockData[] stockDataArray = stockInfoxx.GetStockDataRangeByKn( iStart, (int)policyInfoxx.Policy.KN );

                            U50Report report = new U50Report();
                            report.Name = stockInfoxx.StockName;
                            report.Symbol = stockInfoxx.StockSymbol;
                            report.Guid = policyInfoxx.Guid;

                            report.ReportSubInfo.S_Date = iStart;

                            report.ScanTime = DateTime.Now;

                            bool isOK = IsPassGeneral( stockDataArray, stockInfoxx, policyInfoxx.Filtrate, policyInfoxx.Extend, ref report.ReportSubInfo );
                            if ( isOK == false )
                                continue;

                            report.ScanSpan = DateTime.Now - report.ScanTime;

                            reportList.Add( report );
                        }
                    }

                }
            }

            reportInfo.ReportArray = reportList.ToArray();
            reportInfo.ScanSpan = DateTime.Now - reportInfo.ScanTime;

            return reportInfo;
        }
        public static void ScanTaskThread( U50TaskInfo taskInfo )
        {
            ThreadReportInfo threadReportInfo = new ThreadReportInfo();
            threadReportInfo.TaskInfo = taskInfo;
            threadReportInfo.ScanNowReport = new U50Form.ScanNowReport();
            threadReportInfo.ScanNowReport.Name = taskInfo.Name;

            MainForm.Instance.U50Form.AddToList( threadReportInfo.ScanNowReport );

            ThreadPool.QueueUserWorkItem( new WaitCallback( First_Thread ), threadReportInfo );
        }
        public static void SaveTaskSetting( string strTaskFile, U50TaskInfo[] taskInfos )
        {
            if ( taskInfos == null )
                return;

            if ( File.Exists( strTaskFile ) == true )
                File.Delete( strTaskFile );

            XElement elementRoot = new XElement( "Demo.Stock", new XAttribute( "Ver", "0.0.1.0" ) );

            for ( int iIndex = 0; iIndex < taskInfos.Length; iIndex++ )
            {
                U50TaskInfo taskInfo = taskInfos[iIndex];

                XElement elementU50Task = new XElement( "U50Task", new XAttribute( "Name", taskInfo.Name ) );
                elementU50Task.Add( new XAttribute( "Guid", taskInfo.Guid ) );
                {
                    XElement elementGeneral = new XElement( "General" );
                    {
                        elementGeneral.Add( new XAttribute( "SaneType", ( (int)taskInfo.General.SaneType ).ToString() ) );
                    }
                    elementU50Task.Add( elementGeneral );

                    XElement elementRequest = new XElement( "Request" );
                    {
                        elementRequest.Add( new XAttribute( "SelectType", ( (int)taskInfo.Request.Select ).ToString() ) );
                        elementRequest.Add( new XAttribute( "Plate", taskInfo.Request.Plate ) );
                        elementRequest.Add( new XAttribute( "Variety", taskInfo.Request.Variety ) );

                        for ( int iIndex2 = 0; iIndex2 < taskInfo.Request.StockInfo.Length; iIndex2++ )
                        {
                            U50StockInfo stockInfo = taskInfo.Request.StockInfo[iIndex2];

                            XElement elementStockInfo = new XElement( "StockInfo" );
                            {
                                elementStockInfo.Add( new XAttribute( "Plate", stockInfo.Plate ) );
                                elementStockInfo.Add( new XAttribute( "Variety", stockInfo.Variety ) );
                                elementStockInfo.Add( new XAttribute( "Name", stockInfo.Name ) );
                                elementStockInfo.Add( new XAttribute( "Symbol", stockInfo.Symbol ) );
                            }
                            elementRequest.Add( elementStockInfo );
                        }
                    }
                    elementU50Task.Add( elementRequest );

                    XElement elementPolicy = new XElement( "Policy" );
                    {
                        elementPolicy.Add( new XAttribute( "ScanType", ( (int)taskInfo.Policy.ScanType ).ToString() ) );

                        for ( int iIndex2 = 0; iIndex2 < taskInfo.Policy.PolicyGuid.Length; iIndex2++ )
                        {
                            string strPolicyGuid = taskInfo.Policy.PolicyGuid[iIndex2];

                            XElement elementPolicyGuid = new XElement( "PolicyGuid" );
                            {
                                elementPolicyGuid.Add( new XAttribute( "Guid", strPolicyGuid ) );
                            }
                            elementPolicy.Add( elementPolicyGuid );
                        }
                    }
                    elementU50Task.Add( elementPolicy );

                    XElement elementResult = new XElement( "Result" );
                    {
                        elementResult.Add( new XAttribute( "LastReportGuid", taskInfo.Result.LastReportGuid ) );
                    }
                    elementU50Task.Add( elementResult );
                }
                elementRoot.Add( elementU50Task );
            }

            XDocument documentConfig = new XDocument( new XDeclaration( "1.0", "utf - 8", "yes" ), elementRoot );
            documentConfig.Save( strTaskFile );
        }