Beispiel #1
0
        private void addDeviceButton_Click(object sender, EventArgs e)
        {
            object selectedItem = deviceTypeListBox.SelectedItem;

            if (selectedItem == null)
            {
                MessageBox.Show("Vui lòng chọn một loại thiết bị", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            int number = (int)numberUpDown.Value;

            if (number == 0)
            {
                MessageBox.Show("Số lượng thiết bị phải lớn hơn 0", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            int value = (int)valueUpDown.Value;

            string      code         = codeTextBox.Text.Trim();
            DeviceType  selectedType = (DeviceType)selectedItem;
            DeviceModel deviceModel  = new DeviceModel();

            deviceModel.AddDevice(selectedType.Code, code, value);
        }
        private void addDeviceButton_Click(object sender, EventArgs e)
        {
            object selectedItem = deviceTypeListBox.SelectedItem;

            if (selectedItem == null)
            {
                MessageBox.Show("Vui lòng chọn một loại thiết bị", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            int number = (int)numberUpDown.Value;

            if (number == 0)
            {
                MessageBox.Show("Số lượng thiết bị phải lớn hơn 0", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            DeviceModel deviceModel  = new DeviceModel();
            DeviceType  selectedType = (DeviceType)selectedItem;

            string  description = this.descriptionTextBox.Text;
            Account user        = (Account)userComboBox.SelectedItem;

            int value = (int)valueUpDown.Value;

            for (int i = 0; i < number; i++)
            {
                string code   = selectedType.Code + randomString(4) + i;
                Device device = new Device();
                device.Code        = code;
                device.Type        = selectedType.Code;
                device.Value       = value;
                device.Description = description;
                device.Owner       = user.Username;
                deviceModel.AddDevice(device);
            }
        }