Ejemplo n.º 1
0
        public void RefreshAlarmRecordList(IMonitorSystem system, string sender, DateTime date)
        {
            dataGridView_alarm_record.Rows.Clear();
            CleanupAlarmRecordInfo();

            string path = mAlarmInfoRootPath + "\\" + system.Name + "\\" + sender + "\\" + date.ToString("yyyy-MM-dd");

            if (System.IO.Directory.Exists(path))
            {
                string[] files = Directory.GetFiles(path, "*.xml");
                if (files != null && files.Length > 0)
                {
                    object[]   row_params = new object[6];
                    int        index      = 0;
                    IAlarmInfo alarmInfo;

                    for (int i = 0; i < files.Length; i++)
                    {
                        alarmInfo = CAlarmInfo.LoadFromFile(files[i]);
                        if (alarmInfo != null)
                        {
                            row_params[0] = Convert.ToString(++index);
                            row_params[1] = alarmInfo;
                            row_params[2] = alarmInfo.GetAlarmType();
                            row_params[3] = alarmInfo.AlarmTime.ToString("yyyy-MM-dd HH:mm:ss");
                            row_params[4] = alarmInfo.TransactTime.ToString("yyyy-MM-dd HH:mm:ss");
                            row_params[5] = alarmInfo.Transactor;

                            dataGridView_alarm_record.Rows.Add(row_params);
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public static IAlarmInfo LoadFromFile(string filename)
        {
            XmlDocument doc = new XmlDocument();

            try
            {
                doc.Load(filename);
            }
            catch (Exception e)
            {
                System.Console.Out.WriteLine("CAlarmInfo.LoadFromFile Exception: {0}", e);
                return(null);
            }

            CAlarmInfo alarmInfo = null;

            try
            {
                foreach (XmlNode rootNode in doc.ChildNodes)
                {
                    if (rootNode.Name.Equals("AlarmInfo"))
                    {
                        alarmInfo = new CAlarmInfo();

                        foreach (XmlNode xSubNode in rootNode.ChildNodes)
                        {
                            if (xSubNode.FirstChild != null)
                            {
                                if (xSubNode.FirstChild.Value != null && !xSubNode.FirstChild.Value.Equals(""))
                                {
                                    if (xSubNode.Name.Equals("SystemContext"))
                                    {
                                        alarmInfo.ContextName = xSubNode.FirstChild.Value;
                                    }
                                    else if (xSubNode.Name.Equals("ID"))
                                    {
                                        alarmInfo.ID = xSubNode.FirstChild.Value;
                                    }
                                    else if (xSubNode.Name.Equals("Sender"))
                                    {
                                        alarmInfo.Sender = xSubNode.FirstChild.Value;
                                    }
                                    else if (xSubNode.Name.Equals("VideoSource"))
                                    {
                                        alarmInfo.VideoSource = xSubNode.FirstChild.Value;
                                    }
                                    else if (xSubNode.Name.Equals("AlarmType"))
                                    {
                                        alarmInfo.AlarmType = (TVisionEventType)Convert.ToInt32(xSubNode.FirstChild.Value);
                                    }
                                    else if (xSubNode.Name.Equals("AlertOpt"))
                                    {
                                        alarmInfo.AlertOpt = (TAlertOpt)Convert.ToInt32(xSubNode.FirstChild.Value);
                                    }
                                    else if (xSubNode.Name.Equals("GuardLevel"))
                                    {
                                        alarmInfo.GuardLevel = (TGuardLevel)Convert.ToInt32(xSubNode.FirstChild.Value);
                                    }
                                    else if (xSubNode.Name.Equals("AlarmTime"))
                                    {
                                        alarmInfo.AlarmTime = Convert.ToDateTime(xSubNode.FirstChild.Value);
                                    }
                                    else if (xSubNode.Name.Equals("TransactTime"))
                                    {
                                        alarmInfo.TransactTime = Convert.ToDateTime(xSubNode.FirstChild.Value);
                                    }
                                    else if (xSubNode.Name.Equals("Transactor"))
                                    {
                                        alarmInfo.Transactor = xSubNode.FirstChild.Value;
                                    }
                                }
                            }
                        }

                        break;
                    }
                }

                return(alarmInfo);
            }
            catch (Exception e)
            {
                System.Console.Out.WriteLine("CAlarmInfo.LoadFromFile Building Exception: {0}", e);
                return(null);
            }
        }