Rev 2 Rev 6
Line 34... Line 34...
34             this.comboBoxType.Text = this.Record.type; 34             this.comboBoxType.Text = this.Record.type;
35             this.textBoxRecord.Enabled = false; 35             this.textBoxRecord.Enabled = false;
36             this.comboBoxType.Enabled = false; 36             this.comboBoxType.Enabled = false;
37   37  
38             this.EditRecord.DoWork += new DoWorkEventHandler(EditRecord_DoWork); 38             this.EditRecord.DoWork += new DoWorkEventHandler(EditRecord_DoWork);
39             this.EditRecord.RunWorkerCompleted += new RunWorkerCompletedEventHandler(AddRecord_RunWorkerCompleted); 39             this.EditRecord.RunWorkerCompleted += new RunWorkerCompletedEventHandler(EditRecord_RunWorkerCompleted);
40         } 40         }
41   41  
42         -  
43   -  
44         public AddEdit(DreamhostAPI API) 42         public AddEdit(DreamhostAPI API)
45         { 43         {
46             InitializeComponent(); 44             InitializeComponent();
47   45  
48             this.API = API; 46             this.API = API;
Line 51... Line 49...
51             this.AddRecord.RunWorkerCompleted += new RunWorkerCompletedEventHandler(AddRecord_RunWorkerCompleted); 49             this.AddRecord.RunWorkerCompleted += new RunWorkerCompletedEventHandler(AddRecord_RunWorkerCompleted);
52         } 50         }
53   51  
54         void AddRecord_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) 52         void AddRecord_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
55         { 53         {
-   54             if (e.Error == null)
-   55             {
-   56                 this.DialogResult = DialogResult.OK;
-   57                 this.Close();
-   58             }
-   59             else
-   60             {
-   61                 if (e.Error.Message == "CNAME_already_on_record")
-   62                 {
-   63                     MessageBox.Show("There can only be one CNAME for this record.", "DNS Manager", MessageBoxButtons.OK, MessageBoxIcon.Error);
-   64                 }
-   65                 else if (e.Error.Message == "CNAME_must_be_only_record")
-   66                 {
-   67                     MessageBox.Show("A CNAME already exists for this record.", "DNS Manager", MessageBoxButtons.OK, MessageBoxIcon.Error);
-   68                 }
-   69                 else if (e.Error.Message.Contains("invalid_record"))
-   70                 {
-   71                     MessageBox.Show("This record is invalid:\n" + e.Error.Message.Replace("invalid_record\t", "").CapitaliseFirstLetter(), "DNS Manager", MessageBoxButtons.OK, MessageBoxIcon.Error);
-   72                 }
-   73                 else if (e.Error.Message.Contains("invalid_value"))
-   74                 {
-   75                     MessageBox.Show("This value is invalid:\n" + e.Error.Message.Replace("invalid_value\t", "").CapitaliseFirstLetter(), "DNS Manager", MessageBoxButtons.OK, MessageBoxIcon.Error);
-   76                 }
-   77                 else if (e.Error.Message == "no_such_zone")
-   78                 {
-   79                     MessageBox.Show("Unable to add record to this zone", "DNS Manager", MessageBoxButtons.OK, MessageBoxIcon.Error);
-   80                 }
-   81                 else if (e.Error.Message == "record_already_exists_not_editable")
-   82                 {
-   83                     MessageBox.Show("This record already exists and is not editable", "DNS Manager", MessageBoxButtons.OK, MessageBoxIcon.Error);
-   84                 }
-   85                 else if (e.Error.Message == "record_already_exists_remove_first")
-   86                 {
-   87                     MessageBox.Show("This record already exists.\nPlease try editing it or removing it first.", "DNS Manager", MessageBoxButtons.OK, MessageBoxIcon.Error);
-   88                 }
-   89                 else if (e.Error.Message.Contains("internal_error"))
-   90                 {
-   91                     if (MessageBox.Show("An internal error has occurred", "DNS Manager", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error) == DialogResult.Retry)
-   92                     {
-   93                         this.AddRecord.RunWorkerAsync(this.BuildRecord());
-   94                         return;
-   95                     }
-   96                 }
-   97                 else
-   98                 {
-   99                     if (MessageBox.Show(e.Error.Message, "DNS Manager", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error) == DialogResult.Retry)
-   100                     {
-   101                         this.AddRecord.RunWorkerAsync(this.BuildRecord());
-   102                         return;
-   103                     }
-   104                 }
-   105  
-   106                 this.buttonSave.Enabled = true;
-   107                 this.buttonCancel.Enabled = true;
-   108                 this.textBoxComment.Enabled = true;
-   109                 this.textBoxValue.Enabled = true;
-   110                 this.textBoxRecord.Enabled = true;
-   111                 this.comboBoxType.Enabled = true;
-   112             }
-   113         }
-   114  
-   115         void EditRecord_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
-   116         {
56             this.DialogResult = DialogResult.OK; 117             this.DialogResult = DialogResult.OK;
57             this.Close(); 118             this.Close();
58         } 119         }
59   120  
60         void AddRecord_DoWork(object sender, DoWorkEventArgs e) 121         void AddRecord_DoWork(object sender, DoWorkEventArgs e)
Line 94... Line 155...
94                 this.textBoxRecord.Enabled = false; 155                 this.textBoxRecord.Enabled = false;
95                 this.comboBoxType.Enabled = false; 156                 this.comboBoxType.Enabled = false;
96   157  
97                 if (this.IsEdit) 158                 if (this.IsEdit)
98                 { 159                 {
99                     this.EditRecord.RunWorkerAsync( 160                     this.EditRecord.RunWorkerAsync(this.BuildRecord());
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                 } 161                 }
109                 else 162                 else
110                 { 163                 {
111                     this.AddRecord.RunWorkerAsync( 164                     this.AddRecord.RunWorkerAsync(this.BuildRecord());
-   165                 }
-   166             }
-   167  
-   168         }
-   169  
-   170         private DNSRecord BuildRecord()
-   171         {
112                         new DNSRecord 172             return new DNSRecord
113                         { 173                         {
114                             record = this.textBoxRecord.Text, 174                             record = this.textBoxRecord.Text,
115                             value = this.textBoxValue.Text, 175                             value = this.textBoxValue.Text,
116                             type = this.comboBoxType.Text, 176                             type = this.comboBoxType.Text,
117                             comment = this.textBoxComment.Text 177                             comment = this.textBoxComment.Text
118                         } -  
119                         ); 178                         };
120                 } -  
121             } -  
122   -  
123         } 179         }
124   180  
125         private void buttonCancel_Click(object sender, EventArgs e) 181         private void buttonCancel_Click(object sender, EventArgs e)
126         { 182         {
127             this.DialogResult = DialogResult.Cancel; 183             this.DialogResult = DialogResult.Cancel;