-
Notifications
You must be signed in to change notification settings - Fork 0
/
FieldManagementForm.cs
132 lines (114 loc) · 4.1 KB
/
FieldManagementForm.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
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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace CertMaker5000
{
public partial class FieldManagementForm : Form
{
public List<PDFFieldValue> pDFFieldValues = new List<PDFFieldValue>();
public List<string> CSVFields = new List<string>();
public BindingSource CSVFieldsBindingSource;
public BindingSource PDFFieldValueBindingSource;
PDFFieldValue EditRow;
bool IsEditing = false;
public FieldManagementForm()
{
InitializeComponent();
PDFFieldValueBindingSource = new BindingSource { DataSource = pDFFieldValues };
CSVFieldsBindingSource = new BindingSource { DataSource = CSVFields };
FieldsDataGrid.DataSource = PDFFieldValueBindingSource;
CSVFieldsCombo.DataSource = CSVFieldsBindingSource;
}
private void FieldsDataGrid_DoubleClick(object sender, EventArgs e)
{
if (FieldsDataGrid.SelectedRows.Count > 0)
{
EditRow = (PDFFieldValue)FieldsDataGrid.SelectedRows[0].DataBoundItem;
PDFFieldTextBox.Text = EditRow.Field;
CSVFieldsCombo.Text = EditRow.Value;
CapsCheckBox.Checked = EditRow.CapsValue;
IsEditing = true;
AddEditButtonTextChange();
}
}
private void AddEditButtonTextChange()
{
AddEditFieldButton.Visible = IsEditing;
CapsCheckBox.Visible = IsEditing;
CSVFieldsCombo.Visible = IsEditing;
PDFFieldTextBox.Visible = IsEditing;
//AddEditFieldButton.Text = IsEditing ? "Save" : "Add";
}
private void FieldManagementForm_FormClosing(object sender, FormClosingEventArgs e)
{
e.Cancel = true;
this.Hide();
}
private void AddEditFieldButton_Click(object sender, EventArgs e)
{
// Validation Step
// Is PDF Field Text Box Empty?
if (String.IsNullOrEmpty(PDFFieldTextBox.Text))
{
MessageBox.Show($"You must provide text in the {Environment.NewLine}PDF Field TextBox");
return;
}
// Is PDF Field Value Text Box Empty?
if (String.IsNullOrEmpty(CSVFieldsCombo.Text))
{
MessageBox.Show($"You must provide text in the {Environment.NewLine}PDF Field Value TextBox");
return;
}
// ToDo: .. Add Validation that the field Exists in the PDF as a fillable field
PDFFieldValue row;
if (IsEditing) // Editing a Row
{
row = EditRow;
}
else // Adding a Row
{
row = new PDFFieldValue();
PDFFieldValueBindingSource.Add(row);
}
row.Field = PDFFieldTextBox.Text;
row.Value = CSVFieldsCombo.Text;
row.CapsValue = CapsCheckBox.Checked;
FieldsDataGrid.Refresh();
IsEditing = false;
ClearForm();
AddEditButtonTextChange();
}
private void ClearForm()
{
PDFFieldTextBox.Text = String.Empty;
CSVFieldsCombo.Text = String.Empty;
CapsCheckBox.Checked = false;
}
private void FieldsDataGrid_DataSourceChanged(object sender, EventArgs e)
{
FieldsDataGrid.Columns["Display"].Visible = false;
}
private void label3_Click(object sender, EventArgs e)
{
}
}
public class PDFFieldValue
{
public PDFFieldValue()
{
Field = String.Empty;
Value = String.Empty;
}
public string Field { get; set; }
public string Value { get; set; }
public bool CapsValue { get; set; } = false;
public string Display { get { return Field + "( " + Value + " )"; } }
}
}