/// <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) { } }
/// <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; }
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++; } }
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; }
//定时器触发的事件 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; }