private void CmdOk_Click(object sender, EventArgs e) { if (!this.MapViewToModel()) { return; } try { Cursor.Current = Cursors.WaitCursor; AccessoryDecoder.Save(this.Decoder); // Add the decoder into the project if (!OTCContext.Project.AccessoryDecoders.Contains(this.Decoder)) { OTCContext.Project.AccessoryDecoders.Add(this.Decoder); } this.DialogResult = DialogResult.OK; this.Close(); } catch (Exception ex) { Cursor.Current = Cursors.Default; MessageBox.Show(ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { Cursor.Current = Cursors.Default; } }
private void CmdOk_Click(object sender, EventArgs e) { if (string.IsNullOrWhiteSpace(txtName.Text)) { MessageBox.Show("You must provide a valid name for the decoder.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Warning); txtName.Focus(); return; } else if (int.Parse(txtOutputs.Text) <= 0) { MessageBox.Show("Invalid number of decoder digital outputs.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Warning); txtOutputs.SelectAll(); txtOutputs.Focus(); return; } Cursor.Current = Cursors.WaitCursor; this.Decoder.Project = OTCContext.Project; this.Decoder.Name = txtName.Text.Trim(); this.Decoder.Manufacturer = cboManufacturer.EditValue as Manufacturer; this.Decoder.Model = cboModel.Text.Trim(); this.Decoder.Section = cboSection.SelectedSection; this.Decoder.StartAddress = (int)nudAddress.Value; this.Decoder.Outputs = int.Parse(txtOutputs.Text); this.Decoder.Notes = txtNotes.Text.Trim(); try { AccessoryDecoder.Save(this.Decoder); // Add the decoder into the project if (!OTCContext.Project.AccessoryDecoders.Contains(this.Decoder)) { OTCContext.Project.AccessoryDecoders.Add(this.Decoder); } this.DialogResult = DialogResult.OK; this.Close(); } catch (Exception ex) { Cursor.Current = Cursors.Default; MessageBox.Show(ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { Cursor.Current = Cursors.Default; } }