public List <Area> GetAreas(List <TagPack> Tags) { if (null == Tags) { return(null); } if (Tags.Count <= 0) { return(null); } List <Area> Areas = new List <Area>(); foreach (TagPack tp in Tags) { if (null == tp) { continue; } string StrRouterID = tp.RD_New[0].ToString("X2") + tp.RD_New[1].ToString("X2"); Area area = CommonBoxOperation.GetAreaFromRouterID(StrRouterID); if (null == area) { continue; } string StrAreaID = area.ID[0].ToString("X2") + area.ID[1].ToString("X2"); if (!IsAreas(Areas, StrAreaID)) { Areas.Add(area); } } return(Areas); }
/// <summary> /// 获取Tag在指定的区域呆的总时间; /// </summary> /// <param name="Tags"></param> /// <param name="StrAreaID"></param> /// <param name="StrTagID"></param> /// <returns></returns> public int GetTagInAreaTime(List <TagPack> Tags, string StrAreaID, string StrTagID) { if (null == Tags || null == StrAreaID || "".Equals(StrAreaID) || null == StrTagID || "".Equals(StrTagID)) { return(0); } int TotalTime = 0; foreach (TagPack tpk in Tags) { if (null == tpk) { continue; } string StrTID = tpk.TD[0].ToString("X2") + tpk.TD[1].ToString("X2"); if (StrTID.Equals(StrTagID)) { string StrRID = tpk.RD_New[0].ToString("X2") + tpk.RD_New[1].ToString("X2"); Area CurArea = CommonBoxOperation.GetAreaFromRouterID(StrRID); if (null == CurArea) { continue; } string StrAid = CurArea.ID[0].ToString("X2") + CurArea.ID[1].ToString("X2"); if (StrAid.Equals(StrAreaID)) { TotalTime += tpk.Sleep; } } } return(TotalTime); }
/// <summary> /// 获取在集合Tags中在区域StrAreaID上的数量 /// </summary> /// <param name="Tags"></param> /// <param name="StrAreaID"></param> /// <returns></returns> public int GetTagNum(List <TagPack> Tags, string StrAreaID) { if (null == Tags || Tags.Count <= 0) { return(0); } if (null == StrAreaID || "".Equals(StrAreaID)) { return(0); } int num = 0; foreach (TagPack tpk in Tags) { if (null == tpk) { continue; } string StrRouterID = tpk.RD_New[0].ToString("X2") + tpk.RD_New[1].ToString("X2"); Area CurArea = CommonBoxOperation.GetAreaFromRouterID(StrRouterID); if (null == CurArea) { continue; } string StrCurAreaID = CurArea.ID[0].ToString("X2") + CurArea.ID[1].ToString("X2"); if (StrAreaID.Equals(StrCurAreaID)) { num++; } } return(num); }
/// <summary> /// 切换显示模式时,初始化各种模式 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> public void ShowModeTabControl_SelectedIndexChanged(object sender, EventArgs e) { switch (ShowModeTabControl.SelectedIndex) { case 0: // 列表模式 if (ImageTimer != null) { ImageTimer.Stop(); } ListTimer.Start(); break; case 1: // 图形模式 if (ListTimer != null) { ListTimer.Stop(); } ImageTimer.Start(); //初始化所有参考点的周围位置占用信息 CommonBoxOperation.InitAllReferLocaInfo(); break; } }
private void PersonAlarmListView_ItemChecked(object sender, ItemCheckedEventArgs e) { //点击的过程中发现列表中的项全部被勾选, if (PersonAlarmListView.CheckedItems.Count >= CommonBoxOperation.GetAlarmTagsNum(CurSpeceilAlarm)) { PsAlarmAllSelecCB.Checked = true; } if (PersonAlarmListView.CheckedItems.Count <= 0) { PsAlarmAllSelecCB.Checked = false; } }
private void ReferParamSetWin_Load(object sender, EventArgs e) { //記錄当前人员进入Node参数设置界面的操作 PersonOperation curpersonoper = new PersonOperation(frm.CurPerson.ID, OperType.EnterReferParam); CommonCollection.personOpers.Add(curpersonoper); string strrefermsg = ""; string strid = mrefer.ID[0].ToString("X2") + mrefer.ID[1].ToString("X2"); string strname = CommonBoxOperation.GetRouterName(strid); rstlb.Visible = false; if (null == strname || "".Equals(strname)) { strrefermsg = strid; } else { strrefermsg = strname + "(" + strid + ")"; } refermsgtxt.Text = strrefermsg; eqpttypetxt.Text = ConstInfor.GetDevType(NodeType.ReferNode, mrefer.type); vertxt.Text = ((byte)(mrefer.Version >> 24)).ToString("D2") + ((byte)(mrefer.Version >> 16)).ToString("D2") + ((byte)(mrefer.Version >> 8)).ToString("D2") + ((byte)(mrefer.Version)).ToString("X2"); /*读取参数信息 */ //读取信号阀值 referparam mrfpm = null; mrfpm = ReadReferParam(mrefer, frm.MyUdpClient, referparm.Sgthreshold); if (null == mrfpm) { sthdlb.Text = "read error"; } else { sthdlb.Text = "read ok"; sthdtxt.Text = mrfpm.Sgthreshold + ""; } //读取信号强度系数 mrfpm = ReadReferParam(mrefer, frm.MyUdpClient, referparm.Sgstrengthfac); if (null == mrfpm) { ssfaclb.Text = "read error"; } else { ssfaclb.Text = "read ok"; ssfactxt.Text = string.Format("{0:F2}", (double)mrfpm.Sgstrengthfac / 100); } }
/// <summary> /// 刷新地图 /// </summary> /// <param name="obj"></param> /// <param name="args"></param> private void ImageTimer_Tick(Object obj, EventArgs args) { if (null == MyArea.AreaBitMap || null == MyArea.AreaBitMap.MyBitmap) { return; } ImageBitmap = new Bitmap(MyArea.AreaBitMap.MyBitmap, ImagePanel.Width, ImagePanel.Height); //if (scalew < scaleh) //{ // ImageBitmap = new Bitmap(MyArea.AreaBitMap.MyBitmap, ImagePanel.Width, (int)(ConstInfor.MapHeight * scalew)); //} //else //{ // ImageBitmap = new Bitmap(MyArea.AreaBitMap.MyBitmap, (int)(scaleh * ImagePanel.Width), ImagePanel.Height); //} DrawAreaMap.DrawBasicRouter(ImageBitmap, StrAreaID, 1, scalew, scaleh); RtAroundTagPlace.ClearAreaAllRouterStand(MyArea); IEnumerable <KeyValuePair <string, TagPack> > TEMP = CommonCollection.TagPacks.Reverse <KeyValuePair <string, TagPack> >(); try{ foreach (KeyValuePair <string, TagPack> tp in TEMP) { if (null == tp.Value) { continue; } //判断Tag是否在当前区域中 if (CommonBoxOperation.JudgeTagArea(tp.Key, StrAreaID)) { RtAroundTagPlace.Num = CommonBoxOperation.GetRouterAroundNum(tp.Value.RD_New[0].ToString("X2") + tp.Value.RD_New[1].ToString("X2")); RtAroundTagPlace.CurImageTag = tp.Value; if (ImageBitmap == null) { continue; } RtAroundTagPlace.DrawTag3_Place(ImageBitmap, scalew, scaleh); } } }catch (Exception) { } ImagePanel_Paint(null, null); }
/// <summary> /// 根据接收到的数据包统计总的时间 /// </summary> /// <returns></returns> public int GetTagInAreaTimeReport(List <TagPack> Tags, string StrAreaID, string StrTagID) { if (null == Tags || null == StrAreaID || "".Equals(StrAreaID) || null == StrTagID || "".Equals(StrTagID)) { return(0); } if (Tags.Count <= 0) { return(0); } int TotalTime = 0; TagPack[] tpks = Tags.ToArray(); for (int i = 0; i < tpks.Length; i++) { if (null == Tags[i]) { continue; } string StrTID = Tags[i].TD[0].ToString("X2") + Tags[i].TD[1].ToString("X2"); if (StrTID.Equals(StrTagID)) { string StrRID = Tags[i].RD_New[0].ToString("X2") + Tags[i].RD_New[1].ToString("X2"); Area CurArea = CommonBoxOperation.GetAreaFromRouterID(StrRID); if (null == CurArea) { continue; } string StrAID = CurArea.ID[0].ToString("X2") + CurArea.ID[1].ToString("X2"); if (StrAID.Equals(StrAreaID)) { //判断确定在区域中了 if (i + 1 < tpks.Length) { TotalTime += (tpks[i + 1].ReportTime - tpks[i].ReportTime).Seconds; } else { continue; } } } } return(TotalTime); }
public void DrawTimer_Tick(Object obj, EventArgs args) { StartDTe = StartDTe.AddMilliseconds(1000);//每次增加1s label7.Text = "當前時間:" + StartDTe.ToString(); if (CurIndex >= PickTags.Length) { Stop(); return; } float scalew, scaleh; if (DateTime.Compare(StartDTe, PickTags[CurIndex].ReportTime) >= 0) {//画出当前的地图 string StrTagID = PickTags[CurIndex].TD[0].ToString("X2") + PickTags[CurIndex].TD[1].ToString("X2"); string StrRouterID = PickTags[CurIndex].RD_New[0].ToString("X2") + PickTags[CurIndex].RD_New[1].ToString("X2"); Area CurArea = CommonBoxOperation.GetAreaFromRouterID(StrRouterID); if (CurArea != null) { if (null == CurArea.Name || "".Equals(CurArea.Name)) { CurAreaLabel.Text = "當前區域:" + CurArea.ID[0].ToString("X2") + CurArea.ID[1].ToString("X2"); } else { CurAreaLabel.Text = "當前區域:" + CurArea.Name + "(" + CurArea.ID[0].ToString("X2") + CurArea.ID[1].ToString("X2") + ")"; } BasicRouter CurBasic = CommonBoxOperation.GetBasicRouter(StrRouterID); CurBasic.isReport = true; string StrTagInfor = ""; string StrTagName = CommonBoxOperation.GetTagName(StrTagID); if (null == StrTagName || "".Equals(StrTagName)) { StrTagInfor = StrTagID; } else { StrTagInfor = StrTagName + "(" + StrTagID + ")"; } scalew = (float)TrackPanel.Width / CurArea.AreaBitMap.MyBitmap.Width; scaleh = (float)TrackPanel.Height / CurArea.AreaBitMap.MyBitmap.Height; TrackBtm = new Bitmap(655, 358); TrackBtm = new Bitmap(CurArea.AreaBitMap.MyBitmap, TrackPanel.Width, TrackPanel.Height); //画Router的信息 DrawAreaMap.DrawBasicRouter(TrackBtm, CurArea.ID[0].ToString("X2") + CurArea.ID[1].ToString("X2"), 1, scalew, scaleh); //画Tag的信息 if (null != CurBasic) { if (PickTags[CurIndex].isAlarm == 0x03) { Graphics.FromImage(TrackBtm).FillEllipse(SimpleBrush, CurBasic.x * scalew - 8, CurBasic.y * scaleh - 32, ConstInfor.TagR * 2, ConstInfor.TagR * 2); Graphics.FromImage(TrackBtm).DrawString(StrTagInfor, new Font("宋体", 10), SimpleBrush, CurBasic.x * scalew - 5, CurBasic.y * scaleh - 42); } else if (PickTags[CurIndex].isAlarm == 0x04) { Graphics.FromImage(TrackBtm).FillEllipse(AlarmBrush, CurBasic.x * scalew - 8, CurBasic.y * scaleh - 32, ConstInfor.TagR * 2, ConstInfor.TagR * 2); Graphics.FromImage(TrackBtm).DrawString(StrTagInfor, new Font("宋体", 10), AlarmBrush, CurBasic.x * scalew - 5, CurBasic.y * scaleh - 42); } } TrackPanel_Paint(null, null); } CurIndex++; } }
/// <summary> /// 刷新列表 /// </summary> /// <param name="obj"></param> /// <param name="args"></param> private void ShowTimer_Tick(Object obj, EventArgs args) { String StrRouterName, StrRouterID, StrTagName, StrID; ListViewItem item = null; int num = CommonBoxOperation.GetCurAreaTagNum(StrAreaID); label4.Text = "人員當前總數:" + num; ArrayList MyArrayList = new ArrayList(); Area ar = null; try{ foreach (ListViewItem im in AreaTaglistView.Items) { StrID = im.Name; if (!CommonCollection.TagPacks.ContainsKey(StrID)) { MyArrayList.Add(StrID); } } //清除TagPacks中已经不存在的项 for (int i = 0; i < MyArrayList.Count; i++) { AreaTaglistView.Items.RemoveByKey(MyArrayList[i].ToString()); } foreach (KeyValuePair <string, TagPack> tbk in CommonCollection.TagPacks) { StrRouterID = tbk.Value.RD_New[0].ToString("X2") + tbk.Value.RD_New[1].ToString("X2"); //判断当前的Router是否在本区域中 Area CurArea = CommonBoxOperation.GetAreaFromRouterID(StrRouterID); if (null == CurArea) { continue; } if (CurArea.ID[0] != MyArea.ID[0] || CurArea.ID[1] != MyArea.ID[1]) { continue; } StrRouterName = CommonBoxOperation.GetRouterName(StrRouterID); //判断当前Tag是否在当前的区域中 if (AreaTaglistView.Items.ContainsKey(tbk.Key)) { item = null; if (AreaTaglistView.Items.Count > 0) { item = AreaTaglistView.FindItemWithText(tbk.Key, false, 0); } else { continue; } if (null == item) { StrTagName = CommonBoxOperation.GetTagName(tbk.Key); if (null == StrTagName) { continue; } item = AreaTaglistView.FindItemWithText(StrTagName, false, 0); } ar = CommonBoxOperation.GetRouterArea(StrRouterID); if (ar == null) { continue; } if (!(ar.ID[0].ToString("X2") + ar.ID[1].ToString("X2")).Equals(StrAreaID)) { continue; } if (null != item) { if (null == StrRouterName || "".Equals(StrRouterName)) { item.SubItems[2].Text = StrRouterID; } else { item.SubItems[2].Text = StrRouterName; } item.SubItems[3].Text = tbk.Value.SigStren.ToString(); item.SubItems[4].Text = tbk.Value.Bat.ToString(); item.SubItems[5].Text = tbk.Value.ResTime.ToString(); item.SubItems[6].Text = tbk.Value.ReportTime.ToString(); } } else { ListViewItem Item = new ListViewItem(); Item.Name = tbk.Key;//其中Name是指Tag的ID Item.Text = tbk.Key; StrTagName = CommonBoxOperation.GetTagName(tbk.Key); if (null == StrTagName) { Item.SubItems.Add("****"); } else { Item.SubItems.Add(StrTagName); } if (null == StrRouterName || "".Equals(StrRouterName)) { Item.SubItems.Add(StrRouterID); } else { Item.SubItems.Add(StrRouterName); } Item.SubItems.Add(tbk.Value.SigStren.ToString()); Item.SubItems.Add(tbk.Value.Bat.ToString()); Item.SubItems.Add(tbk.Value.ResTime.ToString()); Item.SubItems.Add(tbk.Value.ReportTime.ToString()); AreaTaglistView.Items.Add(Item); } } }catch (Exception) { } }
private void mytimer_Tick(Object obj, EventArgs args) { string strname = ""; Area area = null; foreach (KeyValuePair <string, Router> router in CommonCollection.Routers) { if (null == router.Value) { continue; } if (router.Value.CurType != NodeType.DataNode) {//若当前的节点断开了连接,删除掉这个参考点 continue; } if (nodelistview.Items.ContainsKey(router.Key)) { if (!router.Value.status) {//断开连接了 nodelistview.Items.RemoveByKey(router.Key); continue; } ListViewItem[] items = nodelistview.Items.Find(router.Key, false); if (items.Length > 0) { strname = CommonBoxOperation.GetNodeName(router.Key); if (null == strname || "".Equals(strname)) { items[0].SubItems[1].Text = "****"; } else { items[0].SubItems[1].Text = strname; } area = CommonBoxOperation.GetAreaFromNodeID(router.Key); if (null == area) { items[0].SubItems[2].Text = "****"; } else { if (null == area.Name || "".Equals(area.Name)) { items[0].SubItems[2].Text = area.ID[0].ToString("X2") + area.ID[1].ToString(); } else { items[0].SubItems[2].Text = area.Name; } } items[0].SubItems[3].Text = router.Value.ReportTime.ToString(); } continue; } if (!router.Value.status) {//断开连接了 nodelistview.Items.RemoveByKey(router.Key); continue; } ListViewItem item = new ListViewItem(); item.Text = router.Key; item.Name = router.Key; strname = CommonBoxOperation.GetNodeName(router.Key); if (null == strname || "".Equals(strname)) { item.SubItems.Add("****"); } else { item.SubItems.Add(strname); } area = CommonBoxOperation.GetAreaFromNodeID(router.Key); if (null == area) { item.SubItems.Add("****"); } else { if (null == area.Name || "".Equals(area.Name)) { item.SubItems.Add(area.ID[0].ToString("X2") + area.ID[1].ToString()); } else { item.SubItems.Add(area.Name); } } item.SubItems.Add(router.Value.ReportTime.ToString()); nodelistview.Items.Add(item); } }
/// <summary> /// 查找按钮,用于查找Tag和设备讯息 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void SearchBtn_Click(object sender, EventArgs e) { String StrIDorName = TagIDorNameTB.Text.ToUpper(); if ("".Equals(StrIDorName)) { MessageBox.Show("設備的ID或名稱不能為空!"); return; } if (tagrb.Checked) { #region 查找Tag设备 PersonOperation curpersonoper = new PersonOperation(frm.CurPerson.ID, OperType.SearchTag); CommonCollection.personOpers.Add(curpersonoper); TagPack MyTag = null; MyTag = SysParam.GetPackTag(StrIDorName); if (null == MyTag) { MyTag = SysParam.GetPackTag_Name(StrIDorName); } if (null == MyTag) { MessageBox.Show("查詢" + StrIDorName + "的Tag設備不存在!"); return; } Area curarea = CommonBoxOperation.GetAreaFromRouterID(MyTag.RD_New[0].ToString("X2") + MyTag.RD_New[1].ToString("X2")); if (null == curarea) { MessageBox.Show("對不起,卡片所在的區域不存在!"); return; } try { SysParam.isTracking = true; MyAllRegInfoWin = new AllRegInfoWin(frm, SpeceilAlarm.PersonHelp, MyTag.TD[0].ToString("X2") + MyTag.TD[1].ToString("X2")); MyAllRegInfoWin.ShowDialog(); } catch (Exception ex) { FileOperation.WriteLog("搜索Tag設備出現異常!異常原因:" + ex.ToString()); } finally { this.Close(); } #endregion } else if (rfrb.Checked) { #region 查找Refer设备 PersonOperation curpersonoper = new PersonOperation(frm.CurPerson.ID, OperType.SearchRefer); CommonCollection.personOpers.Add(curpersonoper); string strareaid = ""; BasicRouter mrt = null; foreach (KeyValuePair <string, Area> marea in CommonCollection.Areas) { if (null == marea.Value) { continue; } marea.Value.AreaRouter.TryGetValue(StrIDorName, out mrt); if (mrt != null) { strareaid = marea.Key; break; } foreach (KeyValuePair <string, BasicRouter> router in marea.Value.AreaRouter) { if (null == router.Value) { continue; } if (StrIDorName.Equals(router.Value.Name)) { mrt = router.Value; break; } } if (null != mrt) { strareaid = marea.Key; break; } } if (null == strareaid || "".Equals(strareaid)) { MessageBox.Show("查詢" + StrIDorName + @"的參考點設備不存在!"); return; } RegInfoWin myregwin = new RegInfoWin(frm, strareaid); myregwin.ShowDialog(); this.Close(); #endregion } else if (ndrb.Checked) { #region 查找Node设备 PersonOperation curpersonoper = new PersonOperation(frm.CurPerson.ID, OperType.SearchNode); CommonCollection.personOpers.Add(curpersonoper); string strareaid = ""; BasicNode mnd = null; foreach (KeyValuePair <string, Area> marea in CommonCollection.Areas) { if (null == marea.Value) { continue; } marea.Value.AreaNode.TryGetValue(StrIDorName, out mnd); if (mnd != null) { strareaid = marea.Key; break; } foreach (KeyValuePair <string, BasicNode> node in marea.Value.AreaNode) { if (null == node.Value) { continue; } if (StrIDorName.Equals(node.Value.Name)) { mnd = node.Value; break; } } if (null != mnd) { strareaid = marea.Key; break; } } if (null == strareaid || "".Equals(strareaid)) { MessageBox.Show("查詢" + StrIDorName + @"的數據節點設備不存在!"); return; } RegInfoWin myregwin = new RegInfoWin(frm, strareaid); myregwin.ShowDialog(); this.Close(); #endregion } }
/// <summary> /// 删除参考点 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void DeleBt_Click(object sender, EventArgs e) { string StrID1, StrID2; StrID1 = RID_1TB.Text; StrID2 = RID_2TB.Text; int index = NodeTypeCB.SelectedIndex; if ("".Equals(StrID1) || "".Equals(StrID2)) { MessageBox.Show("ID不能为空!"); return; } if (StrID1.Length != 2 || StrID2.Length != 2) { MessageBox.Show("ID格式有誤!"); return; } byte[] ID = new byte[2]; try { ID[0] = Convert.ToByte(StrID1, 16); ID[1] = Convert.ToByte(StrID2, 16); } catch (Exception) { MessageBox.Show("ID格式有误!"); return; } if (null == area) { MessageBox.Show("區域不能為空!"); return; } if (null == area.AreaRouter) { MessageBox.Show("參考點不存在!"); return; } //判断 if (null != StrRouterID && !"".Equals(StrRouterID)) { if (type == 0) {//删除参考点 if (!area.AreaRouter.ContainsKey(StrID1 + StrID2)) { MessageBox.Show("參考點不存在"); return; } else { //检查Tag中是否有这个可进的参考点 Tag tag = CommonBoxOperation.GetExistRefer(StrID1 + StrID2); if (null != tag) { if (MessageBox.Show("卡片中存在" + StrID1 + StrID2 + "參考點可進,確定要清除這些卡片中的可進參考點嗎?", "警告", MessageBoxButtons.OKCancel) == System.Windows.Forms.DialogResult.OK) {//清除警告讯息 #region 当Tag的可进区域中存在删除的参考点时 if (null == ID || ID.Length != 2) { MessageBox.Show("對不起,參考點ID有誤!"); return; } //清除Tag中所有含有指定参考点 ClearAllTag_EnRefer(ID); //删除当前的参考点 area.AreaRouter.Remove(StrID1 + StrID2); //重新去更新Tag中的Area树状图 Ps.AddCheckControl(Ps.ReferTreeView); MessageBox.Show("刪除參考點完成!"); this.Close(); #endregion } //string taginfor = (null == tag.Name || "".Equals(tag.Name)) ? (tag.ID[0].ToString("X2") + tag.ID[1].ToString("X2")) : tag.Name + "(" + (tag.ID[0].ToString("X2") + tag.ID[1].ToString("X2")) + ")"; //MessageBox.Show(taginfor + "卡片中" + StrID1 + StrID2+"參考點可進,請先取消..."); return; } area.AreaRouter.Remove(StrID1 + StrID2); } } else { if (!area.AreaNode.ContainsKey(StrID1 + StrID2)) { MessageBox.Show("數據節點不存在"); return; } else { area.AreaNode.Remove(StrID1 + StrID2); } } } //删除参考点后重新刷新面板 SysParam.RestoreShow(); this.Close(); }
/// <summary> /// Excel导出 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void excelbtn_Click(object sender, EventArgs e) { //开始选择出入讯息 DateTime dt = startdtpicker.Value; DateTime Startdt = new DateTime(dt.Year, dt.Month, dt.Day); dt = enddtpicker.Value; DateTime Enddt = new DateTime(dt.Year, dt.Month, dt.Day); List <AccessRecord> lists = new List <AccessRecord>(); string strid = "", strname = "", strinname = "", stroutname = ""; strid = tagtb.Text; if (!"".Equals(strid)) { strname = CommonBoxOperation.GetTagName(strid); if (null == strname) {//说明strid可能是名称 Tag tg = CommonBoxOperation.GetTagFromName(strid); if (null != tg) { strid = tg.ID[0].ToString("X2") + tg.ID[1].ToString("X2"); } } } TagAccessRecordOperation.tagAccessOper.GetAccessRecord(strid, Startdt, Enddt, ref lists); if (lists.Count <= 0) { MessageBox.Show("對不起,記錄不存在!"); return; } SaveFileDialog MyDialog = new SaveFileDialog(); MyDialog.Title = "選擇出入統計文件保存位置"; MyDialog.Filter = "所有文本文件|*.xls"; if (MyDialog.ShowDialog() != DialogResult.OK) { return; } string StrFilePath = MyDialog.FileName; NpoiLib MyNpoiLib = new NpoiLib("Access statistics"); MyNpoiLib.writeToCell(MyNpoiLib.sheet1, 0, 0, "Tag ID"); MyNpoiLib.SetColumnWidth(MyNpoiLib.sheet1, 0, 6000); MyNpoiLib.writeToCell(MyNpoiLib.sheet1, 0, 1, "卡片名稱"); MyNpoiLib.SetColumnWidth(MyNpoiLib.sheet1, 1, 6000); MyNpoiLib.writeToCell(MyNpoiLib.sheet1, 0, 2, "入口基站"); MyNpoiLib.SetColumnWidth(MyNpoiLib.sheet1, 2, 6000); MyNpoiLib.writeToCell(MyNpoiLib.sheet1, 0, 3, "出口基站"); MyNpoiLib.SetColumnWidth(MyNpoiLib.sheet1, 3, 6000); MyNpoiLib.writeToCell(MyNpoiLib.sheet1, 0, 4, "進入時間"); MyNpoiLib.SetColumnWidth(MyNpoiLib.sheet1, 4, 8000); MyNpoiLib.writeToCell(MyNpoiLib.sheet1, 0, 5, "外出時間"); MyNpoiLib.SetColumnWidth(MyNpoiLib.sheet1, 5, 8000); MyNpoiLib.writeToCell(MyNpoiLib.sheet1, 0, 6, "間隔時間"); MyNpoiLib.SetColumnWidth(MyNpoiLib.sheet1, 6, 2000); int index = -1, row = 0; foreach (AccessRecord record in lists) { index++; if (record.isMark) { continue; } strid = record.TagID[0].ToString("X2") + record.TagID[1].ToString("X2"); strname = CommonBoxOperation.GetTagName(strid); AccessRecord access = null; if (record.rttype == ReferType.Entrance) {//说明当前是一个入口参考点,我们接下来需要找出口 strinname = CommonBoxOperation.GetRouterName(record.RouterID[0].ToString("X2") + record.RouterID[1].ToString("X2")); access = SelectAccessRecord(lists.GetRange(index + 1, lists.Count - index - 1), record.TagID, ReferType.Export); if (null == access) { continue; } stroutname = CommonBoxOperation.GetRouterName(access.RouterID[0].ToString("X2") + access.RouterID[1].ToString("X2")); access.isMark = true; } else { continue; } MyNpoiLib.writeToCell(MyNpoiLib.sheet1, row + 1, 0, strid); if (null == strname || "".Equals(strname)) { MyNpoiLib.writeToCell(MyNpoiLib.sheet1, row + 1, 1, "****"); } else { MyNpoiLib.writeToCell(MyNpoiLib.sheet1, row + 1, 1, strname); } if (null == strinname || "".Equals(strinname)) { MyNpoiLib.writeToCell(MyNpoiLib.sheet1, row + 1, 2, record.RouterID[0].ToString("X2") + record.RouterID[1].ToString("X2")); } else { MyNpoiLib.writeToCell(MyNpoiLib.sheet1, row + 1, 2, strinname + "(" + record.RouterID[0].ToString("X2") + record.RouterID[1].ToString("X2") + ")"); } if (null == stroutname || "".Equals(stroutname)) { MyNpoiLib.writeToCell(MyNpoiLib.sheet1, row + 1, 3, access.RouterID[0].ToString("X2") + access.RouterID[1].ToString("X2")); } else { MyNpoiLib.writeToCell(MyNpoiLib.sheet1, row + 1, 3, stroutname + "(" + access.RouterID[0].ToString("X2") + access.RouterID[1].ToString("X2") + ")"); } MyNpoiLib.writeToCell(MyNpoiLib.sheet1, row + 1, 4, record.Occtime.ToString()); MyNpoiLib.writeToCell(MyNpoiLib.sheet1, row + 1, 5, access.Occtime.ToString()); if (DateTime.Compare(record.Occtime, access.Occtime) > 0) { MyNpoiLib.writeToCell(MyNpoiLib.sheet1, row + 1, 6, "****"); } else { MyNpoiLib.writeToCell(MyNpoiLib.sheet1, row + 1, 6, String.Format("{0:N2} h", (access.Occtime - record.Occtime).TotalHours)); } row++; } if (row <= 0) { MessageBox.Show("對不起,當前沒有記錄!"); return; } MyNpoiLib.writeToCell(MyNpoiLib.sheet1, row + 1, 0, "###當前記錄總數為:"); MyNpoiLib.writeToCell(MyNpoiLib.sheet1, row + 1, 1, row.ToString() + " 條"); MyNpoiLib.WriteToFile(StrFilePath); MessageBox.Show("導出文件成功!"); }
private void selectbtn_Click(object sender, EventArgs e) { DateTime dt = startdtpicker.Value; DateTime Startdt = new DateTime(dt.Year, dt.Month, dt.Day); dt = enddtpicker.Value; DateTime Enddt = new DateTime(dt.Year, dt.Month, dt.Day); List <AccessRecord> lists = new List <AccessRecord>(); string strid = "", strname = "", strinname = "", stroutname = ""; strid = tagtb.Text; if (!"".Equals(strid)) { strname = CommonBoxOperation.GetTagName(strid); if (null == strname) {//说明strid可能是名称 Tag tg = CommonBoxOperation.GetTagFromName(strid); if (null != tg) { strid = tg.ID[0].ToString("X2") + tg.ID[1].ToString("X2"); } } } TagAccessRecordOperation.tagAccessOper.GetAccessRecord(strid, Startdt, Enddt, ref lists); recordlistview.Items.Clear(); int index = -1; ListViewItem item = null; foreach (AccessRecord record in lists) { index++; if (record.isMark) { continue; } item = new ListViewItem(); item.Text = record.TagID[0].ToString("X2") + record.TagID[1].ToString("X2"); strname = CommonBoxOperation.GetTagName(item.Text); if (null == strname || "".Equals(strname)) { item.SubItems.Add("****"); } else { item.SubItems.Add(strname); } AccessRecord access = null; if (record.rttype == ReferType.Entrance) {//说明当前是一个入口参考点,我们接下来需要找出口 strinname = CommonBoxOperation.GetRouterName(record.RouterID[0].ToString("X2") + record.RouterID[1].ToString("X2")); access = SelectAccessRecord(lists.GetRange(index + 1, lists.Count - index - 1), record.TagID, ReferType.Export); if (null == access) { continue; } access.isMark = true; if (null == strinname || "".Equals(strinname)) { item.SubItems.Add(record.RouterID[0].ToString("X2") + record.RouterID[1].ToString("X2")); } else { item.SubItems.Add(strinname + "(" + record.RouterID[0].ToString("X2") + record.RouterID[1].ToString("X2") + ")"); } stroutname = CommonBoxOperation.GetRouterName(access.RouterID[0].ToString("X2") + access.RouterID[1].ToString("X2")); if (null == stroutname || "".Equals(stroutname)) { item.SubItems.Add(access.RouterID[0].ToString("X2") + access.RouterID[1].ToString("X2")); } else { item.SubItems.Add(stroutname + "(" + access.RouterID[0].ToString("X2") + access.RouterID[1].ToString("X2") + ")"); } item.SubItems.Add(record.Occtime.ToString()); item.SubItems.Add(access.Occtime.ToString()); if (DateTime.Compare(record.Occtime, access.Occtime) > 0) { item.SubItems.Add("****"); } else { item.SubItems.Add(String.Format("{0:N2} h", (access.Occtime - record.Occtime).TotalHours)); } } else { continue; } recordlistview.Items.Add(item); } label4.Text = "Current record number: " + recordlistview.Items.Count; }
//定时器触发的事件 private void MyTimer_Tick(Object obj, EventArgs arg) { // 列表中的每一项都将对应的警告集合中的项,这样便于查找 string strtagid, strtagname, strreferid, strrefername, strareaid; StringBuilder strtaginfor = null, strreferinfor = null, strareainfo = null; Area curarea = null; ListViewItem item = null; List <WarmInfo> tempwarms = null; lock (CommonCollection.warm_lock) { tempwarms = CommonCollection.WarmInfors.ToList(); } for (int i = 0; i < tempwarms.Count; i++) { if (null == tempwarms[i]) { continue; } string strclassname = tempwarms[i].GetType().Name; switch (CurSpeceilAlarm) { case SpeceilAlarm.PersonHelp: { if (!"PersonHelp".Equals(strclassname)) { continue; } strtagid = ((PersonHelp)tempwarms[i]).TD[0].ToString("X2") + ((PersonHelp)tempwarms[i]).TD[1].ToString("X2"); strtagname = CommonBoxOperation.GetTagName(strtagid); if (null != strtagname && !"".Equals(strtagname)) { strtaginfor = new StringBuilder(strtagname); strtaginfor.Append("("); strtaginfor.Append(strtagid); strtaginfor.Append(")"); //TagInfo = TagName + "(" + TagInfo + ")"; } else { strtaginfor = new StringBuilder(strtagid); } break; } case SpeceilAlarm.AreaControl: { if (!"AreaAdmin".Equals(strclassname)) { continue; } strtagid = ((AreaAdmin)tempwarms[i]).TD[0].ToString("X2") + ((AreaAdmin)tempwarms[i]).TD[1].ToString("X2"); strtagname = CommonBoxOperation.GetTagName(strtagid); if (null != strtagname && !"".Equals(strtagname)) { strtaginfor = new StringBuilder(strtagname); strtaginfor.Append("("); strtaginfor.Append(strtagid); strtaginfor.Append(")"); } else { strtaginfor = new StringBuilder(strtagid); } break; } case SpeceilAlarm.Resid: { if (!"PersonRes".Equals(strclassname)) { continue; } strtagid = ((PersonRes)tempwarms[i]).TD[0].ToString("X2") + ((PersonRes)tempwarms[i]).TD[1].ToString("X2"); strtagname = CommonBoxOperation.GetTagName(strtagid); if (null != strtagname && !"".Equals(strtagname)) { strtaginfor = new StringBuilder(strtagname); strtaginfor.Append("("); strtaginfor.Append(strtagid); strtaginfor.Append(")"); } else { strtaginfor = new StringBuilder(strtagid); } break; } default: break; } strreferid = tempwarms[i].RD[0].ToString("X2") + tempwarms[i].RD[1].ToString("X2"); curarea = CommonBoxOperation.GetAreaFromRouterID(strreferid); strrefername = CommonBoxOperation.GetRouterName(strreferid); if (null != strrefername && !"".Equals(strrefername)) { strreferinfor = new StringBuilder(strrefername); strreferinfor.Append("("); strreferinfor.Append(strreferid); strreferinfor.Append(")"); } else { strreferinfor = new StringBuilder(strreferid); } if (null != curarea) { strareaid = curarea.ID[0].ToString("X2") + curarea.ID[1].ToString("X2"); if (null != curarea.Name && !"".Equals(curarea.Name)) { strareainfo = new StringBuilder(curarea.Name); strareainfo.Append("("); strareainfo.Append(strareaid); strareainfo.Append(")"); } else { strareainfo = new StringBuilder(strareaid); } } else { strareainfo = new StringBuilder("****"); } if (PersonAlarmListView.Items.ContainsKey(i + "")) {//没有包含这一项 ListViewItem[] Items = PersonAlarmListView.Items.Find(i.ToString(), false); if (null != Items && Items.Length > 0) { Items[0].SubItems[3].Text = tempwarms[i].AlarmTime.ToString(); if (!tempwarms[i].isHandler) {//说明没有被处理 Items[0].SubItems[4].Text = "****"; Items[0].SubItems[5].Text = "未處理"; } else { Items[0].SubItems[4].Text = tempwarms[i].ClearAlarmTime.ToString(); Items[0].SubItems[5].Text = "處理"; } } } else { if (tempwarms[i].isClear) { continue; } //包含这一项 item = new ListViewItem(); item.Name = i.ToString(); item.Text = strtaginfor.ToString();//Tag信息 item.SubItems.Add(strareainfo.ToString()); item.SubItems.Add(strreferinfor.ToString()); item.SubItems.Add(tempwarms[i].AlarmTime.ToString()); if (!tempwarms[i].isHandler) { item.SubItems.Add("****"); item.SubItems.Add("未處理"); } else { item.SubItems.Add(tempwarms[i].ClearAlarmTime.ToString()); item.SubItems.Add("處理"); } PersonAlarmListView.Items.Add(item); } } //显示当前的总人数 label1.Text = "報警資訊數量:" + PersonAlarmListView.Items.Count; }
/// <summary> /// 开始按钮,从原始资料中取出时间段的数据包数据 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void StartBtn_Click(object sender, EventArgs e) { if (StrStart.Equals(StartBtn.Text)) { //获取设置的年月日,并判断其是否符合条件 int syear, smonth, sday, eyear, emonth, eday, shour, sminute, ehour, eminute; //tag的ID或名称 string strtaginfor = TrackTagText.Text.ToUpper().Trim(); if ("".Equals(strtaginfor)) { MessageBox.Show("軌跡分析的Tag信息不能為空!"); return; } Tag tag_name = CommonBoxOperation.GetTagFromName(strtaginfor); if (null != tag_name) { strtaginfor = tag_name.ID[0].ToString("X2") + tag_name.ID[1].ToString("X2"); } DateTime StartDT, EndDT; StartDT = StartDTPicker.Value; EndDT = EndDTPicker.Value; syear = StartDT.Year; smonth = StartDT.Month; sday = StartDT.Day; eyear = EndDT.Year; emonth = EndDT.Month; eday = EndDT.Day; try { shour = Convert.ToInt32(sHourCb.Text); sminute = Convert.ToInt32(sMinitueCb.Text); ehour = Convert.ToInt32(eHourCB.Text); eminute = Convert.ToInt32(eMinitueCB.Text); } catch (Exception) { MessageBox.Show("對不起,設置的開始時間或結束時間有誤!"); return; } //获取开始时间和结束时间 StartDT = new DateTime(syear, smonth, sday, shour, sminute, 0); EndDT = new DateTime(eyear, emonth, eday, ehour, eminute, 59); //小于零t1早于t2 if (DateTime.Compare(StartDT, EndDT) > 0) { MessageBox.Show("結束日期時間應該在開始日期時間之後!"); return; } //取出原始记录信息 string strrecorddir = Environment.CurrentDirectory + @"\Record"; if (!Directory.Exists(strrecorddir)) { MessageBox.Show("對不起,沒有任何記錄!"); return; } string[] StrDirs = FileOperation.GetAllDirName(strrecorddir); if (null == StrDirs || StrDirs.Length <= 0) { MessageBox.Show("對不起,沒有任何記錄!"); return; } if (null != DrawIMG.Frm && DrawIMG.Frm.MyUdpClient != null) { MessageBox.Show("對不起,查詢歷史軌跡時需要關閉網絡連接!"); return; } string strdirname = "", strcuryear = "", strcurmonth = "", strcurday = "", strcurhour = ""; int index = -1, curyear = -1, curmonth = -1, curday = -1, curhour = -1; DateTime curdt; PickerTagsList.Clear(); //判断年月日是否符合条件 foreach (string dir in StrDirs) { index = dir.LastIndexOf("\\"); strdirname = dir.Substring(index + 1, 8); 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); DateTime startdt = new DateTime(StartDT.Year, StartDT.Month, StartDT.Day); DateTime enddt = new DateTime(EndDT.Year, EndDT.Month, EndDT.Day); //判断文件创建时间是否在指定的范围内 if (DateTime.Compare(curdt, startdt) < 0 || DateTime.Compare(curdt, enddt) > 0) { continue; } //获取到当前时间的小时部分 try { string[] StrFiles = Directory.GetFiles(dir); foreach (string str in StrFiles) { strcurhour = str.Substring(str.LastIndexOf("\\") + 1, 2); try { curhour = Convert.ToInt32(strcurhour); } catch (Exception) { continue; } //此时判断小时是否满足要求 curdt = new DateTime(curdt.Year, curdt.Month, curdt.Day, curhour, 0, 0); startdt = new DateTime(startdt.Year, startdt.Month, startdt.Day, shour, 0, 0); enddt = new DateTime(enddt.Year, enddt.Month, enddt.Day, ehour, 0, 0); if (DateTime.Compare(curdt, startdt) < 0 || DateTime.Compare(curdt, enddt) > 0) { continue; } //记录年月日时都满足要求 startdt = new DateTime(startdt.Year, startdt.Month, startdt.Day, startdt.Hour, sminute, 0); enddt = new DateTime(enddt.Year, enddt.Month, enddt.Day, enddt.Hour, eminute, 0); RecordOperation.GetRecord(startdt, enddt, strtaginfor, str, ref PickerTagsList); } } catch (System.IO.IOException) { MessageBox.Show("對不起,文件流已经被占用。請先關閉連接監控..."); } catch (Exception ex) { FileOperation.WriteLog("获取原始记录时出现异常,异常异常原因:" + ex.ToString()); } } List <TagPack> deletagpacks = new List <TagPack>(); TagPack temptpk = null; //清除掉两个序列号相同的Tag数据包 for (int i = 0; i < PickerTagsList.Count; i++) { if (i + 1 < PickerTagsList.Count) { if (PickerTagsList[i].index == PickerTagsList[i + 1].index) { if (PickerTagsList[i].SigStren < PickerTagsList[i + 1].SigStren) {//交换位置 temptpk = CommonBoxOperation.CloneTagPack(PickerTagsList[i]); PickerTagsList[i] = PickerTagsList[i + 1]; PickerTagsList[i + 1] = temptpk; } deletagpacks.Add(PickerTagsList[i]); } } } foreach (TagPack deletp in deletagpacks) { PickerTagsList.Remove(deletp); } //此时所有符合添加的数据包都添加到PickerTags集合中处了 TrackListBX.Items.Clear(); foreach (TagPack tpk in PickerTagsList) { TrackListBX.Items.Add( tpk.ReportTime + " TagID:" + tpk.TD[0].ToString("X2") + tpk.TD[1].ToString("X2") + " RouterID:" + tpk.RD_New[0].ToString("X2") + tpk.RD_New[1].ToString("X2") + " 是否警報:" + (tpk.isAlarm == 0x04 ? "yes" : "no") + " 信號強度:" + tpk.SigStren.ToString() + " 電量:" + tpk.Bat.ToString() + " 休眠時間:" + (tpk.Sleep / 10).ToString() + " 未移動時間:" + tpk.ResTime.ToString() + " 序列號:" + tpk.index.ToString()); } recordnumlabel.Text = "總記錄數為:" + PickerTagsList.Count; if (PickerTagsList.Count <= 0) { MessageBox.Show("該Tag的原始資料不存在!"); return; } //图形模式画图地图 StartDTe = new DateTime(StartDT.Year, StartDT.Month, StartDT.Day, StartDT.Hour, StartDT.Minute, StartDT.Second); EndDTe = new DateTime(EndDT.Year, EndDT.Month, EndDT.Day, EndDT.Hour, EndDT.Minute, EndDT.Second); Start(); } else { Stop(); recordnumlabel.Text = "總記錄數為:0"; return; } }
private void MyTimer_Tick(object obj, EventArgs e) { if (null == br) { return; } string StrTagID = ""; if (null == DeleList) { DeleList = new ArrayList(); } DeleList.Clear(); //将当前的Router 周围的参考点刷新到列表中 foreach (ListViewItem item in RouterTaglistView.Items) { StrTagID = item.Name; TagPack MyTagPack = null; if (!CommonCollection.TagPacks.TryGetValue(StrTagID, out MyTagPack)) { DeleList.Add(StrTagID); continue; } if (MyTagPack.RD_New[0] != br.ID[0] || MyTagPack.RD_New[1] != br.ID[1]) { DeleList.Add(StrTagID); } } //清除不应该在列表中的项 foreach (string str in DeleList) { RouterTaglistView.Items.RemoveByKey(str); } ListViewItem listitem = null; String StrTagName = null, StrTagIDName = null; //lock(CommonCollection.TagPacks_Lock) try { foreach (KeyValuePair <string, TagPack> tp in CommonCollection.TagPacks) { if (null == tp.Value) { continue; } if (tp.Value.RD_New[0] == br.ID[0] && tp.Value.RD_New[1] == br.ID[1]) { listitem = null; if (RouterTaglistView.Items.ContainsKey(tp.Key)) { StrTagName = null; listitem = null; if (RouterTaglistView.Items.Count > 0) { listitem = RouterTaglistView.FindItemWithText(tp.Key, false, 0); } if (null == listitem) { StrTagName = CommonBoxOperation.GetTagName(tp.Key); if (null != StrTagName) { listitem = RouterTaglistView.FindItemWithText(tp.Key, false, 0); } else { continue; } } if (null != listitem) { if (null == StrTagName) { StrTagName = CommonBoxOperation.GetTagName(tp.Key); } if (null != StrTagName) { if ("".Equals(StrTagName)) { StrTagIDName = tp.Key; } else { StrTagIDName = StrTagName; } } else { StrTagIDName = tp.Key; } listitem.Text = StrTagIDName; listitem.SubItems[1].Text = tp.Value.SigStren.ToString(); listitem.SubItems[2].Text = tp.Value.Bat.ToString(); listitem.SubItems[3].Text = tp.Value.ResTime.ToString() + "秒"; listitem.SubItems[4].Text = tp.Value.ReportTime.ToString(); } continue; } listitem = new ListViewItem(); listitem.Name = tp.Key; //判断卡片是否有名字 StrTagName = CommonBoxOperation.GetTagName(tp.Key); if (null != StrTagName) { if ("".Equals(StrTagName)) { StrTagIDName = tp.Key; } else { StrTagIDName = StrTagName; } } else { StrTagIDName = tp.Key; } listitem.Text = StrTagIDName; listitem.SubItems.Add(tp.Value.SigStren.ToString()); listitem.SubItems.Add(tp.Value.Bat.ToString()); listitem.SubItems.Add(tp.Value.ResTime.ToString() + "秒"); listitem.SubItems.Add(tp.Value.ReportTime.ToString()); RouterTaglistView.Items.Add(listitem); } } }catch (Exception) { } label1.Text = "Tag的總數量為:" + RouterTaglistView.Items.Count; }
/// <summary> /// 开始统计分析 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void SttAlBtn_Click(object sender, EventArgs e) { label10.Visible = false; label8.Text = ""; PanelBitmap = null; PieCharPanel_Paint(null, null); PickerTagsList.Clear(); string StrTagInfor = TagInforTb.Text; if ("".Equals(StrTagInfor)) { MessageBox.Show("Tag的ID或名稱不能為空!"); return; } //查看时间是否有效 DateTime StartDT, EndDT; StartDT = StartDTPicker.Value; EndDT = EndDTPicker.Value; int syear, smonth, sday, shour, sminute, eyear, emonth, eday, ehour, eminute; syear = StartDT.Year; smonth = StartDT.Month; sday = StartDT.Day; eyear = EndDT.Year; emonth = EndDT.Month; eday = EndDT.Day; if (eyear < syear || (eyear == syear && emonth < smonth) || (eyear == syear && emonth == smonth && eday < sday)) { MessageBox.Show("結束日期時間應該在開始日期時間之後!"); return; } string StrSHour, StrSMinute, StrEHour, StrEMinute; StrSHour = sHourCb.Text; StrSMinute = sMinuteCb.Text; StrEHour = eHourCb.Text; StrEMinute = eMinuteCb.Text; try{ shour = Convert.ToInt32(StrSHour); sminute = Convert.ToInt32(StrSMinute); ehour = Convert.ToInt32(StrEHour); eminute = Convert.ToInt32(StrEMinute); }catch (Exception) { MessageBox.Show("對不起,開始時間或結束時間格式有誤!"); return; } string[] StrDirs = FileOperation.GetAllDirName(FileOperation.Original); if (null == StrDirs) { MessageBox.Show("對不起,没有任何原始數據包資料,不能進行軌跡分析!"); return; } int IntStartDT, IntEndDT; try { IntStartDT = Convert.ToInt32(syear.ToString() + smonth.ToString() + sday.ToString()); IntEndDT = Convert.ToInt32(eyear.ToString() + emonth.ToString() + eday.ToString()); } catch (Exception) { MessageBox.Show("對不起,選擇的日期時間格式有誤!"); return; } int CurFileDT; foreach (string DirName in StrDirs) { if (null == DirName || "".Equals(DirName)) { continue; } try { CurFileDT = Convert.ToInt32(DirName.Substring(DirName.LastIndexOf('\\') + 1, DirName.Length - DirName.LastIndexOf('\\') - 1)); } catch (Exception) { continue; } if (CurFileDT < IntStartDT || CurFileDT > IntEndDT) { continue; } //当前的文件夹中的数据满足要求 string[] AllFileNames = FileOperation.GetAllFileName(DirName); if (null == AllFileNames) { continue; } //符合时间条件的文件才有效:SHour<CurHour<Ehour foreach (string StrHour in AllFileNames) { if (null == StrHour || "".Equals(StrHour)) { continue; } int CurHour; try { string StrCurHour = StrHour.Substring(StrHour.LastIndexOf('\\') + 1, StrHour.IndexOf(".") - StrHour.LastIndexOf('\\') - 1); CurHour = Convert.ToInt32(StrCurHour); } catch (Exception) { continue; } if (IntStartDT == CurFileDT && CurFileDT == IntEndDT) { if (CurHour < shour || CurHour > ehour) { continue; } } else if (IntStartDT < CurFileDT && CurFileDT == IntEndDT) { if (CurHour > ehour) { continue; } } else if (IntStartDT == CurFileDT && CurFileDT < IntEndDT) { if (CurHour < shour) { continue; } } List <TagPack> CurList = FileOperation.GetOriginalData(StrHour); if (null == CurList) { continue; } if (CurList.Count <= 0) { continue; } foreach (TagPack tp in CurList) { if (null == tp) { continue; } int CurMinite = tp.ReportTime.Minute; if (IntStartDT == CurFileDT && CurFileDT == IntEndDT) { if (CurHour == shour && CurHour == ehour) { if (CurMinite >= eminute || CurMinite < sminute) { continue; } } else if (CurHour == shour && CurHour < ehour) { if (CurMinite < sminute) { continue; } } else if (CurHour > shour && CurHour == ehour) { if (CurMinite >= eminute) { continue; } } } else if (IntStartDT < CurFileDT && CurFileDT == IntEndDT) { if (CurHour == ehour) { if (CurMinite > eminute) { continue; } } else if (CurHour > ehour) { continue; } } else if (IntStartDT == CurFileDT && CurFileDT < IntEndDT) { if (CurHour == shour) { if (CurMinite < sminute) { continue; } } else if (CurHour < shour) { continue; } } string StrTagID = tp.TD[0].ToString("X2") + tp.TD[1].ToString("X2"); if (StrTagInfor.Equals(StrTagID)) { PickerTagsList.Add(tp); } Tag tag = CommonBoxOperation.GetTag(StrTagID); if (null == tag) { continue; } if (StrTagInfor.Equals(tag.Name)) { PickerTagsList.Add(tp); } } } } //资料全部取出到集合PickerTagsList中,统计时根据集合中的类型进行统计 if (null == PickerTagsList || PickerTagsList.Count <= 0) { label8.Text = "當前的時間段不存在任何Tag!"; return; } List <Area> Areas = GetAreas(PickerTagsList); if (null == Areas || Areas.Count <= 0) { label8.Text = "當前時間段上的Tag区域不存在!"; return; } label10.Visible = true; PanelBitmap = null; PieCharPanel_Paint(null, null); // 计算时间段上的总秒数 int TotalSec = 0; TotalSec = (eyear - syear) * 365 * 24 * 60 * 60 + (emonth - smonth) * 30 * 24 * 60 * 60 + (eday - sday) * 24 * 60 * 60 + (ehour - shour) * 60 * 60 + (eminute - sminute) * 60; label8.Text = "統計的總時間: " + TotalSec + " 秒"; PanelBitmap = new Bitmap(654, 317); PanelBitmap = new Bitmap(PanelBitmap); Graphics.FromImage(PanelBitmap).DrawString("統計餅狀圖", new Font("黑体", 12), Brushes.Black, PanelBitmap.Width / 2 + 75, 10); Graphics.FromImage(PanelBitmap).DrawString(StrTagInfor + "卡片在各個區域的停留總時間:", new Font("黑体", 10), Brushes.Black, 5, 20); Graphics.FromImage(PanelBitmap).FillEllipse(Brushes.Gray, PanelBitmap.Width / 2 + 20, 50, 200, 200); Brush CurAreaColor = null; float startAngle = -90; int index = 0; foreach (Area CurArea in Areas) { if (null == CurArea) { continue; } string StrAreaID = CurArea.ID[0].ToString("X2") + CurArea.ID[1].ToString("X2"); int num = GetTagNum(PickerTagsList, StrAreaID); //----表示当前Tag在区域CurArea中的数据包数----// switch (index) { case 0: CurAreaColor = Brushes.Red; break; case 1: CurAreaColor = Brushes.Blue; break; case 2: CurAreaColor = Brushes.Green; break; case 3: CurAreaColor = Brushes.Yellow; break; case 4: CurAreaColor = Brushes.Azure; break; case 5: CurAreaColor = Brushes.Beige; break; case 6: CurAreaColor = Brushes.Brown; break; case 7: CurAreaColor = Brushes.Coral; break; case 8: CurAreaColor = Brushes.Cyan; break; case 9: CurAreaColor = Brushes.Fuchsia; break; default: CurAreaColor = Brushes.Snow; break; } string StrTagID = PickerTagsList[0].TD[0].ToString("X2") + PickerTagsList[0].TD[1].ToString("X2"); int TagInAreaTime = GetTagInAreaTimeReport(PickerTagsList, StrAreaID, StrTagID); float rec = ((float)TagInAreaTime / TotalSec); Graphics.FromImage(PanelBitmap).FillPie(CurAreaColor, PanelBitmap.Width / 2 + 20, 50, 200, 200, startAngle, rec * 360); if ("".Equals(CurArea.Name)) { Graphics.FromImage(PanelBitmap).DrawString(" #" + StrAreaID + "區域:" + TagInAreaTime.ToString() + "秒" + " 百分比:" + (rec * 100).ToString("#0.00") + "%", new Font("宋体", 10), CurAreaColor, 5, 20 + (index + 1) * 20); } else { Graphics.FromImage(PanelBitmap).DrawString(" #" + CurArea.Name + "(" + StrAreaID + ")區域:" + TagInAreaTime.ToString() + "秒" + " 百分比:" + (rec * 100).ToString("#0.00") + "%", new Font("宋体", 10), CurAreaColor, 5, 20 + (index + 1) * 20); } startAngle += rec * 360; index++; } PieCharPanel_Paint(null, null); }