| 2 |
clempaul |
1 |
using System; |
|
|
2 |
using System.Collections.Generic; |
|
|
3 |
using System.ComponentModel; |
|
|
4 |
using System.Data; |
|
|
5 |
using System.Drawing; |
|
|
6 |
using System.Linq; |
|
|
7 |
using System.Text; |
|
|
8 |
using System.Windows.Forms; |
|
|
9 |
using clempaul.Dreamhost.ResponseData; |
|
|
10 |
using clempaul; |
|
|
11 |
|
|
|
12 |
namespace DNS_Manager |
|
|
13 |
{ |
|
|
14 |
public partial class AddEdit : Form |
|
|
15 |
{ |
|
|
16 |
private BackgroundWorker AddRecord = new BackgroundWorker(); |
|
|
17 |
private BackgroundWorker EditRecord = new BackgroundWorker(); |
|
|
18 |
|
|
|
19 |
private DreamhostAPI API; |
|
|
20 |
private DNSRecord Record; |
|
|
21 |
|
|
|
22 |
private bool IsEdit = false; |
|
|
23 |
|
|
|
24 |
public AddEdit(DreamhostAPI API, DNSRecord Record) |
|
|
25 |
: this(API) |
|
|
26 |
{ |
|
|
27 |
this.IsEdit = true; |
|
|
28 |
this.Record = Record; |
|
|
29 |
|
|
|
30 |
this.Text = "Edit Record"; |
|
|
31 |
this.textBoxRecord.Text = this.Record.record; |
|
|
32 |
this.textBoxComment.Text = this.Record.comment; |
|
|
33 |
this.textBoxValue.Text = this.Record.value; |
|
|
34 |
this.comboBoxType.Text = this.Record.type; |
|
|
35 |
this.textBoxRecord.Enabled = false; |
|
|
36 |
this.comboBoxType.Enabled = false; |
|
|
37 |
|
|
|
38 |
this.EditRecord.DoWork += new DoWorkEventHandler(EditRecord_DoWork); |
|
|
39 |
this.EditRecord.RunWorkerCompleted += new RunWorkerCompletedEventHandler(AddRecord_RunWorkerCompleted); |
|
|
40 |
} |
|
|
41 |
|
|
|
42 |
|
|
|
43 |
|
|
|
44 |
public AddEdit(DreamhostAPI API) |
|
|
45 |
{ |
|
|
46 |
InitializeComponent(); |
|
|
47 |
|
|
|
48 |
this.API = API; |
|
|
49 |
|
|
|
50 |
this.AddRecord.DoWork += new DoWorkEventHandler(AddRecord_DoWork); |
|
|
51 |
this.AddRecord.RunWorkerCompleted += new RunWorkerCompletedEventHandler(AddRecord_RunWorkerCompleted); |
|
|
52 |
} |
|
|
53 |
|
|
|
54 |
void AddRecord_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) |
|
|
55 |
{ |
|
|
56 |
this.DialogResult = DialogResult.OK; |
|
|
57 |
this.Close(); |
|
|
58 |
} |
|
|
59 |
|
|
|
60 |
void AddRecord_DoWork(object sender, DoWorkEventArgs e) |
|
|
61 |
{ |
|
|
62 |
this.API.DNS.AddRecord((DNSRecord)e.Argument); |
|
|
63 |
System.Threading.Thread.Sleep(3000); |
|
|
64 |
} |
|
|
65 |
|
|
|
66 |
void EditRecord_DoWork(object sender, DoWorkEventArgs e) |
|
|
67 |
{ |
|
|
68 |
this.API.DNS.RemoveRecord(this.Record); |
|
|
69 |
System.Threading.Thread.Sleep(3000); |
|
|
70 |
this.API.DNS.AddRecord((DNSRecord)e.Argument); |
|
|
71 |
System.Threading.Thread.Sleep(3000); |
|
|
72 |
} |
|
|
73 |
|
|
|
74 |
private void buttonSave_Click(object sender, EventArgs e) |
|
|
75 |
{ |
|
|
76 |
if (this.textBoxRecord.Text == string.Empty) |
|
|
77 |
{ |
|
|
78 |
MessageBox.Show("You must enter a record", "DNS Manager", MessageBoxButtons.OK, MessageBoxIcon.Error); |
|
|
79 |
} |
|
|
80 |
else if (this.comboBoxType.Text == string.Empty) |
|
|
81 |
{ |
|
|
82 |
MessageBox.Show("You must select a type", "DNS Manager", MessageBoxButtons.OK, MessageBoxIcon.Error); |
|
|
83 |
} |
|
|
84 |
else if (this.textBoxValue.Text == string.Empty) |
|
|
85 |
{ |
|
|
86 |
MessageBox.Show("You must enter a value", "DNS Manager", MessageBoxButtons.OK, MessageBoxIcon.Error); |
|
|
87 |
} |
|
|
88 |
else |
|
|
89 |
{ |
|
|
90 |
this.buttonSave.Enabled = false; |
|
|
91 |
this.buttonCancel.Enabled = false; |
|
|
92 |
this.textBoxComment.Enabled = false; |
|
|
93 |
this.textBoxValue.Enabled = false; |
|
|
94 |
this.textBoxRecord.Enabled = false; |
|
|
95 |
this.comboBoxType.Enabled = false; |
|
|
96 |
|
|
|
97 |
if (this.IsEdit) |
|
|
98 |
{ |
|
|
99 |
this.EditRecord.RunWorkerAsync( |
|
|
100 |
new DNSRecord |
|
|
101 |
{ |
|
|
102 |
record = this.textBoxRecord.Text, |
|
|
103 |
value = this.textBoxValue.Text, |
|
|
104 |
type = this.comboBoxType.Text, |
|
|
105 |
comment = this.textBoxComment.Text |
|
|
106 |
} |
|
|
107 |
); |
|
|
108 |
} |
|
|
109 |
else |
|
|
110 |
{ |
|
|
111 |
this.AddRecord.RunWorkerAsync( |
|
|
112 |
new DNSRecord |
|
|
113 |
{ |
|
|
114 |
record = this.textBoxRecord.Text, |
|
|
115 |
value = this.textBoxValue.Text, |
|
|
116 |
type = this.comboBoxType.Text, |
|
|
117 |
comment = this.textBoxComment.Text |
|
|
118 |
} |
|
|
119 |
); |
|
|
120 |
} |
|
|
121 |
} |
|
|
122 |
|
|
|
123 |
} |
|
|
124 |
|
|
|
125 |
private void buttonCancel_Click(object sender, EventArgs e) |
|
|
126 |
{ |
|
|
127 |
this.DialogResult = DialogResult.Cancel; |
|
|
128 |
this.Close(); |
|
|
129 |
} |
|
|
130 |
} |
|
|
131 |
} |