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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
| using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
using System.IO;
namespace WFApp1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
// Appi guyner
BackColor = Color.LightGreen;
textBox1.BackColor = Color.LightCyan;
textBox2.BackColor = Color.LightCyan;
textBox3.BackColor = Color.LightCyan;
textBox4.BackColor = Color.LightCyan;
button1.BackColor = Color.Transparent;
listView1.BackColor = Color.LightGoldenrodYellow;
}
private void Form1_Load(object sender, EventArgs e)
{
// App@ skseluc mtnum, kardum u cucadrum e Filei meji tvyalner@
string dataStr = File.ReadAllText("AddedDatas.txt");
foreach (var item in dataStr.Replace("\r", "").Split('\n'))
{
List<string> columns = item.Split('_').ToList();
if (columns.Count >= 4)
{
ListViewItem lvi = new ListViewItem(columns[0]);
lvi.SubItems.Add(columns[1]);
lvi.SubItems.Add(columns[2]);
lvi.SubItems.Add(columns[3]);
listView1.Items.Add(lvi);
}
}
}
private void button1_Click(object sender, EventArgs e)
{
// textBoxer@ veragrvum en listViewi meji syunyaknerin
ListViewItem lvi = new ListViewItem(textBox1.Text);
lvi.SubItems.Add(textBox2.Text);
lvi.SubItems.Add(textBox3.Text);
lvi.SubItems.Add(textBox4.Text);
// stugvum en mutqagrvac tvyalner@
if (textBox1.Text == "" || textBox2.Text == "" || textBox3.Text == "" || textBox4.Text == "")
{
MessageBox.Show("Please fill ALL fields!", "Stop", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
try
{
int phone = int.Parse(textBox3.Text);
}
catch (Exception)
{
MessageBox.Show("Please write ONLY numbers in 'Phone' field!", "Stop", MessageBoxButtons.OK,
MessageBoxIcon.Error);
textBox3.Clear();
return;
}
try
{
new System.Net.Mail.MailAddress(textBox4.Text);
}
catch (Exception)
{
MessageBox.Show("Please write ONLY mail address in 'E-mail' field!", "Stop", MessageBoxButtons.OK,
MessageBoxIcon.Error);
textBox4.Clear();
return;
}
// tvyalner@ avelanum en listViewi mej ev textBoxer@ datarkvum en` noric lracvelu hamar
listView1.Items.Add(lvi);
textBox1.Clear();
textBox2.Clear();
textBox3.Clear();
textBox4.Clear();
// stexcvum e File, vori mej pahpanvum en listViewum mutqagrvac tvyalner@
FileInfo fi = new FileInfo("AddedDatas.txt");
var vItem = listView1.Items[listView1.Items.Count - 1];
using (StreamWriter swAppend = fi.AppendText())
{
for (int i = 0; i < vItem.SubItems.Count; i++)
{
swAppend.Write(vItem.SubItems[i].Text + "_");
}
swAppend.WriteLine();
}
}
// @ntrum enq sxal parunakox tox@ u veracnum enq sxal@
private void listView1_SelectedIndexChanged(object sender, EventArgs e)
{
if (listView1.SelectedItems.Count > 0)
{
ListViewItem item = listView1.SelectedItems[0];
textBox1.Text = item.SubItems[0].Text;
textBox2.Text = item.SubItems[1].Text;
textBox3.Text = item.SubItems[2].Text;
textBox4.Text = item.SubItems[3].Text;
}
else
{
textBox1.Text = string.Empty;
textBox2.Text = string.Empty;
textBox3.Text = string.Empty;
textBox4.Text = string.Empty;
}
}
// buttoni ognutyamb tvyal toxum grum enq uxxvac tarberak@
private void button2_Click(object sender, EventArgs e)
{
update();
textBox1.Clear();
textBox2.Clear();
textBox3.Clear();
textBox4.Clear();
// jnjum e fayli meji toxer@
File.WriteAllText("AddedDatas.txt", String.Empty);
// Filin e poxancum listView1-i` ayd pahin exac cucak@
FileInfo fi = new FileInfo("AddedDatas.txt");
foreach (ListViewItem vItem in listView1.Items)
{
using (StreamWriter swAppend = fi.AppendText())
{
for (int i = 0; i < vItem.SubItems.Count; i++)
{
swAppend.Write(vItem.SubItems[i].Text + "_");
}
swAppend.WriteLine();
}
}
}
private void update()
{
listView1.SelectedItems[0].SubItems[0].Text = textBox1.Text;
listView1.SelectedItems[0].SubItems[1].Text = textBox2.Text;
listView1.SelectedItems[0].SubItems[2].Text = textBox3.Text;
listView1.SelectedItems[0].SubItems[3].Text = textBox4.Text;
}
}
} |