Exemplo n.º 1
0
        /// <summary>
        /// 接受flash传过来的值
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void FromFlashCall(object sender, AxShockwaveFlashObjects._IShockwaveFlashEvents_FlashCallEvent e)
        {
            System.Diagnostics.Debug.Write("解析nodeXml:" + e.request.ToString() + "\n");
            Hashtable requestInfo = NodeXmlToHashtable(e.request.ToString());

            //           MessageBox.Show(requestInfo["rType"].ToString());
            if (requestInfo != null)
            {
                if (requestInfo["rType"].ToString() == "test")
                {
                    //                    MessageBox.Show("test");
                    Hashtable historyInfo = new Hashtable();
                    historyInfo["trid"]  = tdb.GetTrainRecordID();
                    historyInfo["tid"]   = tInfo["tid"];
                    historyInfo["score"] = requestInfo["S"];
                    historyInfo["gate"]  = requestInfo["Gate"];
                    historyInfo["diff"]  = requestInfo["Diff"];
                    historyInfo["o"]     = requestInfo["O"];
                    historyInfo["r"]     = requestInfo["R"];
                    historyInfo["t"]     = requestInfo["T"];
                    historyInfo["e"]     = requestInfo["E"];
                    historyInfo["w"]     = requestInfo["W"];
                    historyInfo["bo"]    = UserInfoStatic.O;
                    historyInfo["br"]    = UserInfoStatic.R;
                    historyInfo["bt"]    = UserInfoStatic.T;
                    historyInfo["be"]    = UserInfoStatic.E;
                    historyInfo["bw"]    = UserInfoStatic.W;
                    tdb.OnInsertTrainToHistory(historyInfo);

                    UserInfoStatic.O += Convert.ToDouble(requestInfo["O"]);
                    UserInfoStatic.R += Convert.ToDouble(requestInfo["R"]);
                    UserInfoStatic.T += Convert.ToDouble(requestInfo["T"]);
                    UserInfoStatic.E += Convert.ToDouble(requestInfo["E"]);
                    UserInfoStatic.W += Convert.ToDouble(requestInfo["W"]);
                    tdb.OnUpdateTrainDataToUserPara();
                    if (UserInfoStatic.O >= 500 && UserInfoStatic.R >= 500 && UserInfoStatic.T >= 500 && UserInfoStatic.E >= 500 && UserInfoStatic.W >= 500)
                    {
                        tdb.OnUpdateTrainAll();
                    }
                    TrainBack tb = tListView as TrainBack;

                    //结束游戏
                    //    MessageBox.Show("结束游戏");

                    isGameStart = false;
                    if (HRVData.Count > 128)
                    {
                        HMMath    hdMath      = new HMMath(HRVData, EPData);          //计算14项数据,调节指数,稳定指数,综合得分和给出评价报告
                        Hashtable HRVDataCalc = hdMath.HRVCalc();                     //用于存放HRV测量后计算的相关数据
                        HRVDataCalc["HRVScore"]  = EPScore;                           //HRV得分
                        HRVDataCalc["Time"]      = (Single)HRVData.Count / 2.0;       //测试时间,单位是秒
                        HRVDataCalc["EndTime"]   = DateTime.Now;                      //结束时间,datetime格式
                        HRVDataCalc["StartTime"] = startTime;                         //开始时间,datetime格式
                        //                HRVDataCalc["TimeType"] = this.SelectComboBox + 1;//HRV检测时间类型
                        HRVDataCalc["TimeType"] = Convert.ToInt32(tInfo["tid"]) + 40; //HRV检测时间类型
                        //                HRVDataCalc["Mood"] = this.systemMeg["Mood"];//测量时心情状态
                        HRVDataCalc["Mood"]    = 101;
                        HRVDataCalc["HRVMark"] = hrvMarkArr;//事件标记

                        //开始数据库操作
                        //lich
                        if (UserInfoStatic.ipAdd != null)
                        {
                            hrvdb.OnInsertHRVDataAndEpData(HRVData, EPData, hrvMarkArr, HRVDataCalc, PPGData, "2");
                        }
                        else
                        {
                            UserHrvRecord hrvRecord = new UserHrvRecord();
                            hrvRecord.HRVData  = HRVData;
                            hrvRecord.EPData   = EPData;
                            hrvRecord.MarkData = hrvMarkArr;
                            hrvRecord.PWRData  = (ArrayList)HRVDataCalc["FS"];
                            hrvRecord.TimeData.Add(HRVDataCalc["fMean"]);
                            hrvRecord.TimeData.Add(HRVDataCalc["fStdDev"]);
                            hrvRecord.TimeData.Add(HRVDataCalc["fSDNN"]);
                            hrvRecord.TimeData.Add(HRVDataCalc["fRMSSD"]);
                            hrvRecord.TimeData.Add(HRVDataCalc["fSD"]);
                            hrvRecord.TimeData.Add(HRVDataCalc["fSDSD"]);
                            hrvRecord.TimeData.Add(HRVDataCalc["fPNN"]);
                            hrvRecord.FreData.Add(HRVDataCalc["tp"]);
                            hrvRecord.FreData.Add(HRVDataCalc["vlf"]);
                            hrvRecord.FreData.Add(HRVDataCalc["lf"]);
                            hrvRecord.FreData.Add(HRVDataCalc["hf"]);
                            hrvRecord.FreData.Add(HRVDataCalc["lhr"]);
                            hrvRecord.FreData.Add(HRVDataCalc["lfnorm"]);
                            hrvRecord.FreData.Add(HRVDataCalc["hfnorm"]);
                            hrvRecord.AnsBalance = Convert.ToDouble(HRVDataCalc["NB"]);
                            hrvRecord.Pressure   = Convert.ToDouble(HRVDataCalc["Pressure"]);
                            hrvRecord.Adjust     = Convert.ToDouble(HRVDataCalc["adjust"]);
                            hrvRecord.Stable     = Convert.ToDouble(HRVDataCalc["stable"]);
                            hrvRecord.Score      = Convert.ToDouble(HRVDataCalc["score"]);
                            hrvRecord.HrvScore   = Convert.ToDouble(HRVDataCalc["HRVScore"]);
                            hrvRecord.TimeLength = Convert.ToDouble(HRVData.Count / 2.0);
                            hrvRecord.StartTime  = Convert.ToDateTime(HRVDataCalc["StartTime"]);
                            hrvRecord.EndTime    = Convert.ToDateTime(HRVDataCalc["EndTime"]);
                            hrvRecord.RecordType = Convert.ToInt32(HRVDataCalc["TimeType"]);
                            hrvRecord.Mood       = Convert.ToInt32(HRVDataCalc["Mood"]);
                            hrvRecord.Report     = Convert.ToString(HRVDataCalc["report"]);

                            MainRightPerson.TmpHrvRecord.Add(hrvRecord);
                        }
                    }
                    //or (int i = 0; i < tb.TrainButtonGrid.Children.Count; i++)
                    //
                    //rainList tl = tb.TrainButtonGrid.Children[i] as TrainList;
                    //f (tl.HistoryButton.Tag.ToString() == tInfo["tid"].ToString())
                    //
                    //   tl.HistoryButton.IsEnabled = true;
                    //   break;
                    //
                    //
                }
                else if (requestInfo["rType"].ToString() == "start")
                {
                    isGameStart = true;
                    HRVData     = new ArrayList(); //初始化HRV曲线数组
                    EPData      = new ArrayList(); //初始化EP数组
                    IBIData     = new ArrayList(); //初始化IBI数组
                    PPGData     = new ArrayList(); //初始化PPG数组
                    hrvMarkArr  = new ArrayList(); //初始化时间标记数组
                    OnChartPaint(HRVData);         //初始化曲线图表
                    OnAnimationForEP(0);           //协调状态条
                    EPScore = 0;
                    //     MessageBox.Show("开始游戏");
                }
                else if (requestInfo["rType"].ToString() == "enter")
                {
                }
                else if (requestInfo["rType"].ToString() == "cmd")
                {
                    //                   MessageBox.Show("cmd");
                    if (requestInfo["cmd"].ToString() == "1")
                    {
                        OnStartHrvToFlash();
                    }
                    else
                    {
                        OnEndHrvToFlash();
                    }
                }
                else if (requestInfo["rType"].ToString() == "click")
                {
                    //                   MessageBox.Show("click");
                }
            }
        }
        /// <summary>
        /// 视频结束
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnEndPlayVideo(object sender, EventArgs e)
        {
/*            startTimer = new System.Windows.Threading.DispatcherTimer();
 *          startTimer.Interval = new TimeSpan(0, 0, 1);
 *          startTimer.Tick += OnShowRe;
 *          startTimer.Start();
 */
            this.RootGrid.Children.Clear();
            this.RootGrid.Children.Add(this.WraingImage);

            endTime = DateTime.Now;
            TimeSpan diffTime  = new TimeSpan();
            TimeSpan startTick = new TimeSpan(startTime.Ticks);
            TimeSpan endTick   = new TimeSpan(endTime.Ticks);

            diffTime = endTick.Subtract(startTick).Duration();
            System.Diagnostics.Debug.Write("开始和结束的时间差:" + diffTime.TotalSeconds + "\n");
            OnStopAllTimerAndHD();//停止所有timer
            this.playGrid.Children.Clear();
            //this.timeGrid.Opacity = 0;
            this.epGrid.Opacity    = 0;
            this.scoreGrid.Opacity = 1;
            this.playGrid.Opacity  = 0;
            if (diffTime.TotalSeconds < 60)
            {
                this.totalTimeText.Text = Math.Floor(diffTime.TotalSeconds) + "秒";
            }
            else
            {
                this.totalTimeText.Text = diffTime.Minutes + "分" + diffTime.Seconds + "秒";
            }
            Double totalScore = Math.Floor((epOver500 / diffTime.TotalSeconds) * 100.0);

            this.totalScoreText.Text = totalScore.ToString();
            //-----------------------------对数据库操作
            Hashtable historyInfo = new Hashtable();

            historyInfo["trid"]  = tdb.GetTrainRecordID();
            historyInfo["tid"]   = 12;
            historyInfo["score"] = totalScore;
            historyInfo["gate"]  = 1;
            historyInfo["diff"]  = 2;
            historyInfo["o"]     = 0;
            historyInfo["r"]     = 0;
            historyInfo["t"]     = 0;
            historyInfo["e"]     = totalScore * 0.2;
            historyInfo["w"]     = totalScore * 0.05;
            historyInfo["bo"]    = UserInfoStatic.O;
            historyInfo["br"]    = UserInfoStatic.R;
            historyInfo["bt"]    = UserInfoStatic.T;
            historyInfo["be"]    = UserInfoStatic.E;
            historyInfo["bw"]    = UserInfoStatic.W;
            tdb.OnInsertTrainToHistory(historyInfo);

            UserInfoStatic.E += totalScore * 0.2;
            UserInfoStatic.W += totalScore * 0.05;
            tdb.OnUpdateTrainDataToUserPara();
            if (UserInfoStatic.O >= 500 && UserInfoStatic.R >= 500 && UserInfoStatic.T >= 500 && UserInfoStatic.E >= 500 && UserInfoStatic.W >= 500)
            {
                tdb.OnUpdateTrainAll();
            }
            //--------------------------------绘制雷达图
            DrawRadar(UserInfoStatic.O, UserInfoStatic.W, UserInfoStatic.E, UserInfoStatic.T, UserInfoStatic.R);
            //--------------------------------基本属性归零
            epOver500 = 0.0;



            //new           OnStopAllTimerAndHD();
        }