-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathForm1.cs
128 lines (107 loc) · 4.91 KB
/
Form1.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using MyProject.vCard;
namespace testVCardReader
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
if (openFileDialog1.ShowDialog() == DialogResult.OK)
textBox1.Text = File.ReadAllText(openFileDialog1.FileName);
}
const int MaxPhones = 4, MaxEmail = 4, MaxAddresses = 4, MaxUrls = 2;
private void button2_Click(object sender, EventArgs e)
{
textBox2.Clear();
textBox2.AppendText("Full Name\t");
textBox2.AppendText("Surname\tGiven Name\tMiddle Name\t");
textBox2.AppendText("Title\t");
textBox2.AppendText("Prefix\t");
textBox2.AppendText("Suffix\t");
textBox2.AppendText("Birthday\t");
textBox2.AppendText("Rev\t");
textBox2.AppendText("Org\t");
for (int i = 0; i < MaxPhones; i++)
{
textBox2.AppendText("Phone " + (i + 1).ToString() + "\t");
}
for (int i = 0; i < MaxEmail; i++)
{
textBox2.AppendText("Email " + (i + 1).ToString() + "\t");
}
for (int i = 0; i < MaxUrls; i++)
{
textBox2.AppendText("URL " + (i + 1).ToString() + "\t");
}
for (int i = 0; i < MaxAddresses; i++)
{
textBox2.AppendText("Address " + (i + 1).ToString() + "\t");
}
textBox2.AppendText("Note" + Environment.NewLine);
foreach (string s in textBox1.Text.Split(new string[] { "END:VCARD" }, StringSplitOptions.RemoveEmptyEntries))
{
vCardReader vc = new vCardReader();
vc.ParseLines(s); //textBox1.Text);
//textBox2.Clear();
textBox2.AppendText(vc.FormattedName + "\t");
textBox2.AppendText(vc.Surname + "\t" + vc.GivenName + "\t" + vc.MiddleName + "\t");
textBox2.AppendText(vc.Title + "\t");
textBox2.AppendText(vc.Prefix + "\t");
textBox2.AppendText(vc.Suffix + "\t");
textBox2.AppendText((vc.Birthday.HasValue ? vc.Birthday.Value.ToShortDateString() : "") + "\t");
textBox2.AppendText((vc.Rev.HasValue ? vc.Rev.Value.ToShortDateString() + " " + vc.Rev.Value.ToShortTimeString() : "") + "\t");
textBox2.AppendText(vc.Org + "\t");
for (int i = 0; i < MaxPhones; i++)
{
if (i < vc.Phones.Count)
textBox2.AppendText(/*vc.Phones[i].phoneType.ToString() + " " + vc.Phones[i].homeWorkType.ToString() + (vc.Phones[i].pref ? "Preferred" : "") + "=" +*/
(!vc.Phones[i].number.Contains(" ") ? "'" : "") + vc.Phones[i].number);
textBox2.AppendText("\t");
}
for (int i = 0; i < MaxEmail; i++)
{
if (i < vc.Emails.Count)
textBox2.AppendText(/*vc.Emails[i].homeWorkType.ToString() + " " + (vc.Emails[i].pref ? "Preferred" : "") + "=" +*/ vc.Emails[i].address);
textBox2.AppendText("\t");
}
for (int i = 0; i < MaxUrls; i++)
{
if (i < vc.URLs.Count)
textBox2.AppendText(/*vc.Emails[i].homeWorkType.ToString() + " " + (vc.Emails[i].pref ? "Preferred" : "") + "=" +*/ vc.URLs[i]);
textBox2.AppendText("\t");
}
for (int i = 0; i < MaxAddresses; i++)
{
if (i < vc.Addresses.Count)
{
textBox2.AppendText(//vc.Addresses[i].homeWorkType.ToString() + "=" + vc.Addresses[i].po + "," + vc.Addresses[i].ext + ", "
vc.Addresses[i].street + ", "
+ vc.Addresses[i].locality + ", "
+ vc.Addresses[i].region + ", "
+ vc.Addresses[i].postcode + ", "
+ vc.Addresses[i].country);
}
textBox2.AppendText("\t");
}
textBox2.AppendText((vc.Note != null ? vc.Note.Replace(@"\n", " ").Trim() : "") + Environment.NewLine);
}
}
private void button3_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(textBox2.SelectedText))
textBox2.SelectAll();
textBox2.Copy();
}
}
}