/// <summary>
        /// Adds contact and writes to file and closes parent form.
        /// </summary>
        private void b_AddContact_Click(object sender, EventArgs e)
        {
            if (tb_fname.Text == "" || tb_email.Text == "")
            MessageBox.Show("You must enter a name and email to add a contact.");
              else if (!Regex.Match(tb_email.Text, @"\w+([\.-_]?\w+)*@\w+([\.-]?\w+)*", RegexOptions.IgnoreCase).Success)
            MessageBox.Show("Please enter a valid email.");
              else
              {
            Contact ct = new Contact(tb_fname.Text, tb_lname.Text, tb_email.Text);
            if (tb_mname.Text != "")
              ct.MiddleName = tb_mname.Text;
            if (tb_tel.Text != "")
              ct.Telephone = tb_tel.Text;
            if (tb_address.Text != "")
              ct.Address = tb_address.Text;
            if (tb_city.Text != "")
              ct.City = tb_city.Text;
            if (tb_pcode.Text != "")
              ct.PostalCode = tb_pcode.Text;
            if (tb_country.Text != "")
              ct.Country = tb_country.Text;
            contacts.Add(ct);

            if (!Directory.Exists(MainWindow.contactPath))
              Directory.CreateDirectory(MainWindow.contactPath);
            Common.SerializeContact(ct, string.Format("{0}\\{1}.contact", MainWindow.contactPath, ct.Name));

            ContactAdded();

            EmptyForm parent = (EmptyForm)this.Parent;
            parent.Close();
              }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Serialize Contact object.
 /// </summary>
 /// <param name="serializableObject">The Contact object you would like to serialize</param>
 /// <param name="fileName">The path string you would like the file to be saved</param>
 public static void SerializeContact(Contact contact, string fileName)
 {
     if (contact == null)
     return;
       XmlSerializer xmls = new XmlSerializer(typeof(Contact));
       Stream stream = File.Open(fileName, FileMode.Create);
       xmls.Serialize(stream, contact);
       stream.Close();
       stream.Dispose();
 }
        public wuc_viewContact(Contact contact)
        {
            this.contact = contact;

              InitializeComponent();

              tb_fname.Text = contact.FirstName;
              tb_mname.Text = contact.MiddleName;
              tb_lname.Text = contact.LastName;
              tb_email.Text = contact.Email;
              tb_tel.Text = contact.Telephone;
              tb_address.Text = contact.Address;
              tb_city.Text = contact.City;
              tb_pcode.Text = contact.PostalCode;
              tb_country.Text = contact.PostalCode;
        }