예제 #1
0
        private void AddSirenEvent()
        {
            SirenEventForm seForm = new SirenEventForm();

            seForm.Timestamp             = SirenEvent.GetCurretnTimestamp();
            seForm.dateTimePicker1.Value = DateTime.Now;
            seForm.dateTimePicker1.Value = seForm.dateTimePicker1.Value.AddHours(24);
            seForm.textBox1.Text         = "";

            EventFormDisplayed = true;
            DialogResult result = seForm.ShowDialog(this);

            EventFormDisplayed = false;
            if (result == DialogResult.Cancel)
            {
                return;
            }

            SirenEvent se = new SirenEvent(
                seForm.dateTimePicker1.Value,
                seForm.textBox1.Text
                );

            sirenEvents.Add(se);
            try {
                sirenEvents.Flush();
            } catch (Exception e) {
                MessageBox.Show(e.ToString());
                return;
            }

            AddListItem(se);
        }
예제 #2
0
        private void EditSirenEvent()
        {
            ListView.SelectedListViewItemCollection lvs = listView1.SelectedItems;
            if (1 != lvs.Count)
            {
                return;
            }

            SirenEvent se;

            try {
                se = sirenEvents.Find(Int32.Parse(lvs[0].Name));
            } catch (Exception e) {
                MessageBox.Show(e.ToString());
                return;
            }

            if (null == se)
            {
                MessageBox.Show("Item not found");
            }

            SirenEventForm seForm = new SirenEventForm();

            seForm.Timestamp             = se.Timestamp;
            seForm.dateTimePicker1.Value = se.DateTimeFromTimestamp;
            seForm.textBox1.Text         = se.EventText;
            EventFormDisplayed           = true;
            DialogResult result = seForm.ShowDialog(this);

            EventFormDisplayed = false;
            if (result == DialogResult.Cancel)
            {
                return;
            }

            SirenEvent newSe = new SirenEvent(
                seForm.dateTimePicker1.Value,
                seForm.textBox1.Text
                );

            sirenEvents.Remove(se.Timestamp);
            sirenEvents.Add(newSe);
            try {
                sirenEvents.Flush();
            } catch (Exception e) {
                MessageBox.Show(e.ToString());
                return;
            }

            lvs[0].Remove();
            AddListItem(newSe);
        }
예제 #3
0
        public SirenEvent FindExpired()
        {
            Int32 timestamp = SirenEvent.GetCurretnTimestamp();

            foreach (SirenEvent se in items)
            {
                if (se.Timestamp <= timestamp)
                {
                    return(se);
                }
            }
            return(null);
        }
예제 #4
0
        public static void Main(string[] args)
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            try {
                SirenEvents = new SirenEvents(eventsFilePath);
            } catch (Exception e) {
                MessageBox.Show(e.ToString());
                Application.Exit();
            }

            bool isFirstInstance;
            // Please use a unique name for the mutex to prevent conflicts with other programs
            string appName = System.Reflection.Assembly.GetExecutingAssembly().GetName().Name;

            using (Mutex mtx = new Mutex(true, appName, out isFirstInstance)) {
                if (isFirstInstance)
                {
                    NotificationIcon notificationIcon = new NotificationIcon();
                    notificationIcon.notifyIcon.Visible = true;
                    timer       = new System.Windows.Forms.Timer();
                    timer.Tick += delegate(object sender, EventArgs e)
                    {
                        SirenEvent se = SirenEvents.FindExpired();
                        if (null != se)
                        {
                            ShowSirenEventsForm(true, se.EventText);
                        }
                    };
                    timer.Interval = 2000;
                    timer.Enabled  = true;
                    timer.Start();
                    Application.Run();
                    notificationIcon.notifyIcon.Dispose();
                }
                else
                {
                    // The application is already running
                    MessageBox.Show(
                        "Application already running, look at system tray icon",
                        "Application already running",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Asterisk
                        );
                }
            } // releases the Mutex
        }
예제 #5
0
        public int CompareTo(object obj)
        {
            if (null == obj)
            {
                return(1);
            }

            SirenEvent otherSirenEvent = obj as SirenEvent;

            if (otherSirenEvent != null)
            {
                return(this.Timestamp.CompareTo(otherSirenEvent.Timestamp));
            }

            throw new ArgumentException("Object is not a SirenEvent");
        }
예제 #6
0
        void SirenEventsFormLoad(object sender, EventArgs e)
        {
            Int32 currentTimestamp = SirenEvent.GetCurretnTimestamp();

            sirenEvents = NotificationIcon.SirenEvents;

            listView1.ListViewItemSorter =
                new ListViewItemComparer(
                    (-1 != sortColumn ? sortColumn : 0),
                    listView1.Sorting
                    );

            foreach (SirenEvent se in sirenEvents)
            {
                AddListItem(se);
            }
        }
예제 #7
0
        protected void AddListItem(SirenEvent se)
        {
            string key = se.Timestamp.ToString();

            ListViewItem lvi =
                listView1.Items.Add(
                    key,
                    se.DateTimeFromTimestamp.ToString(),
                    ""
                    );

            lvi.SubItems.Add(se.EventText);

            if (se.Expired)
            {
                lvi.BackColor = Color.Pink;
            }

            listView1.Sort();

            listView1.Items[key].Selected = true;
        }
예제 #8
0
 public void Add(SirenEvent se)
 {
     items.Add(se);
 }