-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAddpaper.cs
More file actions
94 lines (82 loc) · 2.75 KB
/
Addpaper.cs
File metadata and controls
94 lines (82 loc) · 2.75 KB
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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace kolokvezba
{
public partial class Addpaper : Form
{
public Paper NewPaper { get; set; }
ErrorProvider errorProvider = new ErrorProvider();
private void Addpaper_Load(object sender, EventArgs e)
{
}
public Addpaper()
{
InitializeComponent();
}
private bool ValidateInput()
{
if (Titletb.Text.Length == 0)
{
errorProvider.SetError(Titletb, "Must contain title");
return false;
}
else errorProvider.SetError(Titletb, "");
if (Author1tb.Text.Length == 0)
{
errorProvider.SetError(Author1tb, "Must have at least 1 author");
return false;
}
else errorProvider.SetError(Author1tb, "");
if (Keywordtb.Text.Length == 0 || Keywordtb.Text.Contains(' '))
{
errorProvider.SetError(Keywordtb, "Keywords must be seperated with comma");
return false;
}
else errorProvider.SetError(Keywordtb, "");
return true;
}
private void Okbtn_Click(object sender, EventArgs e)
{
if (ValidateInput())
{
List<String> authors = new List<string>();
string[] keywords = Keywordtb.Text.Split(',');
authors.Add(Author1tb.Text);
if (!string.IsNullOrWhiteSpace(Author2tb.Text))
authors.Add(Author2tb.Text);
if (!string.IsNullOrWhiteSpace(Author3tb.Text))
authors.Add(Author3tb.Text);
if (!string.IsNullOrWhiteSpace(Author4tb.Text))
authors.Add(Author4tb.Text);
if (!string.IsNullOrWhiteSpace(Author5tb.Text))
authors.Add(Author5tb.Text);
NewPaper = new Paper(Titletb.Text, authors.ToArray(), keywords);
this.DialogResult = DialogResult.OK;
return;
}
}
private void Titletb_TextChanged(object sender, EventArgs e)
{
ValidateInput();
}
private void Keywordtb_TextChanged(object sender, EventArgs e)
{
ValidateInput();
}
private void Author1tb_TextChanged(object sender, EventArgs e)
{
ValidateInput();
}
private void Cancelbtn_Click(object sender, EventArgs e)
{
this.DialogResult = DialogResult.Cancel;
}
}
}