-
Notifications
You must be signed in to change notification settings - Fork 14
/
frmAddGroup.cs
86 lines (73 loc) · 2.42 KB
/
frmAddGroup.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
using System;
using System.IO;
using System.Text;
using System.Windows.Forms;
namespace Coffeed
{
public partial class frmAddGroup : Form
{
public static string groups = File.ReadAllText(Path.Combine(Application.StartupPath, "groups.dat"), Encoding.UTF8).TrimEnd(',');
public frmAddGroup()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
if (!GroupExists(groupName.Text))
{
File.AppendAllText(Path.Combine(Application.StartupPath, "groups.dat"), groupName.Text + ",");
this.Close();
}
}
internal static void RefreshGroups()
{
try
{
if (File.Exists(Path.Combine(Application.StartupPath, "groups.dat"))) groups = File.ReadAllText(Path.Combine(Application.StartupPath, "groups.dat"), Encoding.UTF8).TrimEnd(',');
}
catch (Exception err)
{
Logging.M(err.Message, "Oops, there's an error that needs special attetion.");
Logging.LogError(err);
}
}
public bool GroupExists(string groupName)
{
var allGroups = groups.Split(',');
var result = false;
foreach (var g in allGroups)
{
if (g == groupName)
{
result = true;
break;
}
else
{
result = false;
}
}
return result;
}
public void removeGroup(string key)
{
try
{
if (File.Exists(Path.Combine(Application.StartupPath, "groups.dat")))
{
var data = File.ReadAllText(Path.Combine(Application.StartupPath, "groups.dat"), Encoding.UTF8).TrimEnd(',');
data = data.Replace(key + ",", string.Empty);
File.WriteAllText(Path.Combine(Application.StartupPath, "groups.dat"), data, Encoding.UTF8);
}
}
catch (Exception err)
{
Logging.M(err.Message, "Oops, there's an error that needs special attetion.");
Logging.LogError(err);
}
}
private void frmAddGroup_Load(object sender, EventArgs e)
{
}
}
}