-
Notifications
You must be signed in to change notification settings - Fork 6
/
Form1.cs
78 lines (66 loc) · 2.25 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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace RecipeManager
{
public partial class Form1 : Form
{
private List<Recipe> m_recipes = new List<Recipe>();
public Form1()
{
InitializeComponent();
LoadRecipes();
}
private void LoadRecipes()
{
DirectoryInfo directoryInfo = new DirectoryInfo(@"e:\portkata");
m_recipes = directoryInfo.GetFiles("*")
.Select(fileInfo => new Recipe { Name = fileInfo.Name, Size = fileInfo.Length, Text = File.ReadAllText(fileInfo.FullName) }).ToList();
PopulateList();
}
private void PopulateList()
{
listView1.Items.Clear();
foreach (Recipe recipe in m_recipes)
{
listView1.Items.Add(new RecipeListViewItem(recipe));
}
}
private void DeleteClick(object sender, EventArgs e)
{
foreach (RecipeListViewItem recipeListViewItem in listView1.SelectedItems)
{
m_recipes.Remove(recipeListViewItem.Recipe);
File.Delete(@"e:\portkata\" + recipeListViewItem.Recipe.Name);
}
PopulateList();
NewClick(null, null);
}
private void NewClick(object sender, EventArgs e)
{
textBoxName.Text = "";
textBoxObjectData.Text = "";
}
private void SaveClick(object sender, EventArgs e)
{
File.WriteAllText(Path.Combine("e:\\portkata", textBoxName.Text), textBoxObjectData.Text);
LoadRecipes();
}
private void SelectedIndexChanged(object sender, EventArgs e)
{
foreach (RecipeListViewItem recipeListViewItem in listView1.SelectedItems)
{
textBoxName.Text = recipeListViewItem.Recipe.Name;
textBoxObjectData.Text = recipeListViewItem.Recipe.Text;
break;
}
}
}
}