예제 #1
0
        private void cmdOk_Click(object sender, EventArgs e)
        {
            DataTable        dt = null;
            DeviceConnection dc = null;

            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.Name         = txtName.Text.Trim();
            this.Decoder.Manufacturer = cboManufacturer.EditValue as Manufacturer;
            this.Decoder.Model        = cboModel.Text.Trim();
            this.Decoder.Outputs      = int.Parse(txtOutputs.Text);
            this.Decoder.Notes        = txtNotes.Text.Trim();
            this.Decoder.Type         = Device.DeviceType.AccessoryDecoder;

            try
            {
                if (!this.Decoder.IsNew)
                {
                    // Update the outputs addresses
                    // At this point the module must have all outputs created in DB
                    dt = grdConnect.DataSource as DataTable;
                    foreach (DataRow row in dt.Rows)
                    {
                        dc         = DeviceConnection.Get((long)row[0]);
                        dc.Address = (int)row[3];
                    }
                }

                Device.Save(this.Decoder);

                this.DialogResult = System.Windows.Forms.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;
            }
        }