Beispiel #1
0
 private void StopTrace()
 {
     StartBtn.Text        = StrStart;
     TraceCb.Enabled      = true;
     TagTB.Enabled        = true;
     speedupBtn.Enabled   = false;
     speeddownBtn.Enabled = false;
     pauseBtn.Enabled     = false;
     isStop = false;
     if (null != ShowThread)
     {
         if (ShowThread.IsAlive)
         {
             ShowThread.Abort();
         }
         ShowThread = null;
     }
     Application.DoEvents();
     Thread.Sleep(10);
     ClearTagPen();
     Ini.Close(Ini.CardPath);
 }
Beispiel #2
0
        /// <summary>
        /// 开始轨迹
        /// </summary>
        private void StartTrace()
        {
            //判断日期时间是否选择正确
            int start, end;
            int syear, smonth, sday, shour, sminute, eyear, emonth, eday, ehour, eminute;

            syear = StartTimePicker.Value.Year; smonth = StartTimePicker.Value.Month; sday = StartTimePicker.Value.Day;
            eyear = EndTimePicker.Value.Year; emonth = EndTimePicker.Value.Month; eday = EndTimePicker.Value.Day;
            string StrSHour, StrSMinute, StrEHour, StrEMinute;

            StrSHour = shourTB.Text.Trim(); StrSMinute = sminuteTB.Text.Trim();
            StrEHour = ehourTB.Text.Trim(); StrEMinute = eminuteTB.Text.Trim();
            string strtagid = TagTB.Text;

            if (Parameter.isSupportMulArea)
            {
                if (null == strtagid || "".Equals(strtagid))
                {
                    MessageBox.Show("Sorry, in multi-zone mode, the card ID cannot be empty!");
                    return;
                }
            }

            if ("".Equals(StrSHour))
            {
                MessageBox.Show("The beginning hour cannot be empty!");
                return;
            }
            if ("".Equals(StrSMinute))
            {
                MessageBox.Show("The beginning minute cannot be empty!");
                return;
            }
            if ("".Equals(StrEHour))
            {
                MessageBox.Show("The end hour cannot be empty!");
                return;
            }
            if ("".Equals(StrEMinute))
            {
                MessageBox.Show("The end minute cannot be empty!");
                return;
            }
            try
            {
                shour   = Convert.ToInt32(StrSHour); ehour = Convert.ToInt32(StrEHour);
                sminute = Convert.ToInt32(StrSMinute); eminute = Convert.ToInt32(StrEMinute);
            }
            catch (Exception)
            {
                MessageBox.Show("The hour or minute format is wrong!");
                return;
            }
            if (shour < 0 || shour > 23 || sminute < 0 || sminute > 59 ||
                ehour < 0 || ehour > 23 || eminute < 0 || eminute > 59)
            {
                MessageBox.Show("The range of the hour is 0-24, the range of the minute needle is 0-60!");
                return;
            }
            startdt = new DateTime(syear, smonth, sday, shour, sminute, 0);
            enddt   = new DateTime(eyear, emonth, eday, ehour, eminute, 59);
            if (DateTime.Compare(startdt, enddt) > 0)
            {
                MessageBox.Show("I'm sorry, the start time is earlier than the end!");
                return;
            }
            //读取记录文件
            if (!Directory.Exists(Parameter.RecordDir))
            {
                MessageBox.Show("Sorry, the record file doesn't exist!");
                return;
            }
            string[] dirs = Directory.GetDirectories(Parameter.RecordDir);
            string   strdirname = "", strcuryear = "", strcurmonth = "", strcurday = "", strcurhour = "";
            int      index = -1, curyear = -1, curmonth = -1, curday = -1, curhour = -1;
            DateTime curdt;

            Allpack.Clear();
            foreach (string dir in dirs)
            {
                index       = dir.LastIndexOf("\\");
                strdirname  = dir.Substring(index + 1, dir.Length - index - 1);
                strcuryear  = strdirname.Substring(0, 4);
                strcurmonth = strdirname.Substring(4, 2);
                strcurday   = strdirname.Substring(6, 2);
                try
                {
                    curyear  = Convert.ToInt32(strcuryear);
                    curmonth = Convert.ToInt32(strcurmonth);
                    curday   = Convert.ToInt32(strcurday);
                }catch (Exception)
                {
                    continue;
                }
                curdt = new DateTime(curyear, curmonth, curday, 23, 59, 59);
                //说明当前的年+月+日符合选择的时间
                string[] StrFiles = Directory.GetFiles(dir);
                foreach (string str in StrFiles)
                {
                    index      = str.LastIndexOf("\\");
                    strcurhour = str.Substring(index + 1, str.Length - index - 5);
                    try
                    {
                        curhour = Convert.ToInt32(strcurhour);
                    }
                    catch (Exception)
                    {
                        continue;
                    }
                    curdt = new DateTime(curyear, curmonth, curday, curhour, startdt.Minute, 0);
                    if (DateTime.Compare(curdt, startdt) < 0)
                    {
                        continue;
                    }
                    curdt = new DateTime(curyear, curmonth, curday, curhour, enddt.Minute, 0);
                    if (DateTime.Compare(curdt, enddt) > 0)
                    {
                        continue;
                    }
                    //说明符合要求,将其序列化回来
                    Object obj = null;
                    frm.DeserializeObject(out obj, str);
                    if (null == obj)
                    {
                        continue;
                    }
                    List <CardImg> tpks = obj as List <CardImg>;
                    if (null == tpks)
                    {
                        continue;
                    }
                    //从当前的集合中找出时间头和时间尾,排除掉"分"不符合要求
                    start = GetDTHead(tpks, startdt);
                    end   = GetDTEnd(tpks, enddt);
                    if (start < 0)
                    {
                        continue;
                    }
                    for (int i = start; i <= end; i++)
                    {
                        Allpack.Add(tpks[i]);
                    }
                }
            }
            if (Allpack.Count <= 0)
            {
                MessageBox.Show("Sorry, there is no record!");
                return;
            }
            if (TraceCb.SelectedIndex == 0)
            {
                TraceMode = 0;
            }
            else
            {
                TraceMode = 1;
            }
            //启动一个定时器在面板上显示历史Tag的位置
            StrTagInfor = TagTB.Text.Trim();
            if (!"".Equals(StrTagInfor))
            {
                bool isShow = false;
                foreach (CardImg tg in Allpack)
                {
                    if (StrTagInfor.Equals(tg.Name))
                    {
                        isShow = true;
                        break;
                    }
                    if (StrTagInfor.Equals(tg.ID[0].ToString("X2") + tg.ID[1].ToString("X2")))
                    {
                        isShow = true;
                        break;
                    }
                }
                if (!isShow)
                {
                    MessageBox.Show("Sorry,there are no tags of " + StrTagInfor);
                    return;
                }
            }
            index_color = -1;
            isStop      = true;
            TabSec      = 1;
            if (null == ShowThread)
            {
                ShowThread = new Thread(ShowTag);
            }
            try
            {
                ShowThread.Start();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
            Speedratelabel.Text  = "Speed rating: " + SpeedRate + " (level)";
            StartBtn.Text        = StrStop;
            speedupBtn.Enabled   = true;
            speeddownBtn.Enabled = true;
            pauseBtn.Enabled     = true;
            TraceCb.Enabled      = false;
            TagTB.Enabled        = false;
        }