예제 #1
0
        private void btnWrite_Click(object sender, EventArgs e)
        {
            if (card == null)
            {
                card = new vCard();
            }

            DialogResult dresult = dlgSave.ShowDialog();

            if (dresult != DialogResult.Cancel)
            {
                string FileName = dlgSave.FileName;
                card.FullName = txtFirstName.Text;
                card.Nickname = txtLastName.Text;
                if (card.EmailAddresses.Count == 0)
                {
                    card.EmailAddresses.Add(txtEmail.Text, true);
                }
                else
                {
                    card.EmailAddresses[0].Address = txtEmail.Text;
                }
                card.Birthday = dtBirth.Value;
                card.SaveToFile(FileName);
            }
        }
예제 #2
0
        private void saveAsButton_Click(object sender, EventArgs e)
        {
            DialogResult result = this.savevCardDialog.ShowDialog();

            if (result == DialogResult.OK)
            {
                try
                {
                    vCard card = new vCard();

                    card.Name.GivenName  = this.firstNameTextbox.Text;
                    card.Name.FamilyName = this.lastNameTextbox.Text;

                    if (this.companyTextbox.Text != string.Empty)
                    {
                        card.Organization.Add(this.companyTextbox.Text);
                    }

                    if (this.officePhoneTextbox.Text != string.Empty)
                    {
                        card.TelephoneNumbers.Add(this.officePhoneTextbox.Text, TelephoneNumberSingleType.Work);
                    }

                    if (this.homePhoneTextbox.Text != string.Empty)
                    {
                        card.TelephoneNumbers.Add(this.homePhoneTextbox.Text, TelephoneNumberSingleType.Home);
                    }

                    if (this.mobilePhoneTextbox.Text != string.Empty)
                    {
                        card.TelephoneNumbers.Add(this.mobilePhoneTextbox.Text, TelephoneNumberSingleType.Cellular);
                    }

                    if (this.emailTextbox.Text != string.Empty)
                    {
                        card.EmailAddresses.Add(this.emailTextbox.Text);
                    }

                    if (this.birthdayDatePicker.Value != DateTime.Now)
                    {
                        card.Birthday = this.birthdayDatePicker.Value;
                    }

                    if (this.photoPictureBox.Image != null)
                    {
                        Image        image  = this.photoPictureBox.Image;
                        MemoryStream stream = new MemoryStream();
                        image.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg);
                        card.Photo = stream.ToArray();
                    }

                    card.SaveToFile(this.savevCardDialog.FileName);

                    MessageBox.Show(string.Format("The file {0} was saved successfully.", Path.GetFileName(this.savevCardDialog.FileName)));
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error while trying to save the vCard file.");
                }
            }
        }