Example #1
0
        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;
        }
Example #2
0
        /// <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("導出文件成功!");
        }
Example #3
0
        //定时器触发的事件
        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;
        }