using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace OsaGateway
{
    public partial class SMSDetail : Form
    {
        string phoneNumber = string.Empty;

        public delegate void SMSDetailHandler();
        static public event SMSDetailHandler NewSMSChange;

        public SMSDetail(Guid messageGuid)
        {
            InitializeComponent();
            Message message = Message.Get(messageGuid);
            phoneNumber = message.Phone;            
            label2.Text = message.Date.ToString();
            label6.Text = message.Text;
            try
            {
                label4.Text = Contact.Get(message.Phone).Name + " (" + Contact.Get(message.Phone).Phone + ")";
            }
            catch (Exception)
            {
                label4.Text = message.Phone;
            }
            string[] tmp = Program.NewSMSGuid.ToArray();
            if (tmp != null && tmp.Count() > 0)
            {
                foreach (string item in tmp)
                {
                    if (item == messageGuid.ToString())
                    {
                        Program.NewSMSGuid.Remove(item);
                    }
                }
                if (NewSMSChange != null)
                    NewSMSChange();
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            NewSMS sms = new NewSMS(phoneNumber);
            sms.Show();
            this.Hide();
            this.Close();
        }
    }
}
