Пример #1
0
        private void MobileDeviceEditForm_Load(object sender, EventArgs e)
        {
            if (_context.Assets.OfType <MobileDevice>().Any(x => x.AssetId.Equals(_mobileDevice.AssetId, StringComparison.OrdinalIgnoreCase)))
            {
                assetId_TextBox.ReadOnly = true;
                connectionId_TextBox.Focus();
            }
            else
            {
                //Didn't find the passed-in AssetId in the database.  New object, set defaults.
                if (string.IsNullOrEmpty(_mobileDevice.AssetId))
                {
                    AssetConfigurationController controller = new AssetConfigurationController(_context);
                    int count = _context.Assets.OfType <MobileDevice>().Count() + 1;
                    _mobileDevice.AssetId    = $"MOB-{count.ToString("D5")}";
                    _mobileDevice.AssetType  = _mobileDevice.GetType().Name;
                    _mobileDevice.Pool       = controller.GetDefaultAssetPool();
                    _mobileDevice.Capability = AssetAttributes.Mobile;
                }
                assetId_TextBox.Focus();
            }

            assetId_TextBox.Text      = _mobileDevice.AssetId;
            connectionId_TextBox.Text = _mobileDevice.MobileEquipmentId;
            type_ComboBox.Text        = _mobileDevice.MobileDeviceType;
            description_TextBox.Text  = _mobileDevice.Description;
        }
Пример #2
0
        private void button_Ok_Click(object sender, EventArgs e)
        {
            using (new BusyCursor())
            {
                if (ValidateInput())
                {
                    AssetConfigurationController controller = new AssetConfigurationController(_context);
                    _simulator.AssetId         = textBox_AssetId.Text;
                    _simulator.Product         = textBox_Product.Text;
                    _simulator.Address         = textBox_Address.Text;
                    _simulator.VirtualMachine  = textBox_VmName.Text;
                    _simulator.FirmwareVersion = textBox_Firmware.Text;
                    _simulator.Password        = textBox_Password.Text;
                    _simulator.SimulatorType   = comboBox_Type.Text;
                    _simulator.Pool            = controller.GetDefaultAssetPool();

                    try
                    {
                        int capability = 0;
                        foreach (CheckBox checkBox in _capabilityControls)
                        {
                            if (checkBox.Checked)
                            {
                                capability += int.Parse(checkBox.Tag.ToString());
                            }
                        }
                        _simulator.Capability = (AssetAttributes)capability;
                    }
                    catch (FormatException ex)
                    {
                        TraceFactory.Logger.Error("Unable to Parse Simulator Capability.  Make sure the CheckBox.Tag property is set on all Capability Checkboxes.", ex);
                        MessageBox.Show("Unable to determine Simulator Capability.", "Save Changes", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        DialogResult = DialogResult.Abort;
                        return;
                    }

                    if (_context.Entry(_simulator).State == EntityState.Detached)
                    {
                        // New Simulator
                        _context.Assets.Add(_simulator);
                    }
                    _context.SaveChanges();

                    DialogResult = DialogResult.OK;
                }
            }
        }