Здравствуйте!
Есть код
C# |
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
| using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
namespace ConsoleApplication1
{
class SubjiectGuide
{
string word;
int[] page;
public SubjiectGuide(string word, int[] page)
{
this.word = word;
this.page = page;
}
public static void InputFromFile(List<SubjiectGuide> TargetSG, string FileName)
{
string InputText = System.IO.File.ReadAllText(FileName);
string patern = @"[A-Z]*[a-z]*";
MatchCollection wordsMatches=Regex.Matches(InputText,patern);
List<string> words = new List<string>();
foreach (Match value in wordsMatches)
{
if (value.ToString() != "," && value.ToString()!="")
{
words.Add(value.ToString());
}
}
List<int[]> pages = new List<int[]>();
for (int i = 0; i < words.Count; i++)
{
string SubCat;
if (i < words.Count - 1)
{
SubCat = InputText.Substring(InputText.IndexOf(words[i]), InputText.IndexOf(words[i + 1]) - InputText.IndexOf(words[i]) - 1);
}
else
{
SubCat = InputText.Substring(InputText.IndexOf(words[i]));
}
patern = @"[0-9]+";
MatchCollection pagesMatches = Regex.Matches(SubCat, patern);
int[] pagesTemp = new int[pagesMatches.Count];
for (int j = 0; j < pagesTemp.Length; j++)
{
pagesTemp[j] =Convert.ToInt32( pagesMatches[j].ToString());
}
pages.Add(pagesTemp);
SubjiectGuide SGtemp = new SubjiectGuide(words[i], pages[i]);
TargetSG.Add(SGtemp);
}}
public static void InputFromKeyboard(List<SubjiectGuide> TargetSG)
{
Console.WriteLine("Input slovo");
string word=Console.ReadLine();
Console.WriteLine("Input pages. For plural item use symbol ","");
string pagesInStr = Console.ReadLine();
List<int> pages=new List<int>();
string pattern = @"[0-9]+";
MatchCollection Matches = Regex.Matches(pagesInStr, pattern);
foreach (Match value in Matches)
{
pages.Add(Convert.ToInt32(value.ToString()));
}
SubjiectGuide tempSG = new SubjiectGuide(word, pages.ToArray());
TargetSG.Add(tempSG);
}
public override string ToString()
{
string result = this.word+" ";
foreach (int value in page)
{
result += value.ToString();
result += ",";
}
return result;
}
}
class Program
{
public static bool readFromFile;
static void DataInput(List<SubjiectGuide> TargetSG, bool fileread)
{
if (fileread)
{
Console.WriteLine("Enter path");
string path = Console.ReadLine();
SubjiectGuide.InputFromFile(TargetSG,path);
}
else
{
while (true)
{
SubjiectGuide.InputFromKeyboard(TargetSG);
Console.WriteLine("Еще значения? y/n");
if (Console.ReadLine().ToLower() == "n") break;
}
}
}
public static void Menu(List<SubjiectGuide> MySG)
{
Console.Clear();
Console.WriteLine("1. Ввести указатель");
Console.WriteLine("2. Просмотреть указатель");
Console.WriteLine("3. Удалить элемент из указателя");
Console.WriteLine("0. Выход");
string answer=Console.ReadLine();
bool exit=false;
switch(answer)
{
case "1":
{
Console.WriteLine("Use file fol data input? Yes/No");
string answer2 = Console.ReadLine();
if (answer2 == "Yes")
{
readFromFile = true;
}
else
{
readFromFile = false;
}
DataInput(MySG, readFromFile);
break;
}
case "2":
{
foreach (SubjiectGuide value in MySG)
{
Console.WriteLine(value.ToString());
}
Console.WriteLine("Press any key...");
Console.ReadKey();
break;
}
case "3":
{
Console.WriteLine("Enter index of element");
int index = Convert.ToInt32(Console.ReadLine());
MySG.Remove(MySG[index-1]);
break;
}
case "0":
{
exit = true;
break;
}
}
if (!exit) Menu(MySG);
}
static void Main(string[] args)
{
List<SubjiectGuide> MySG=new List<SubjiectGuide>();
Menu(MySG);
}
}
} |
|
Этот код нужно сделать в WindowsFormsApplication VS.
Будет 3 кнопки формировать,вывести,удалить.Код под эти кнопки могу скинуть.
Кто может сделать?Может быть платно.