Пример #1
0
        public void DeviceSettingUpdate(DeviceSettingsDTO dsdto)
        {
            var entity = DeviceSettings.GetAll().SingleOrDefault(c => c.Id == dsdto.Id);

            DeviceSettings.Update(mapper.Map <DeviceSettingsDTO, DeviceSettings>(dsdto, entity));
        }
        private bool SavePlcSettings()
        {
            settingsService = Program.kernel.Get <ISettingsService>();

            if (FindDeviceNameDuplicate((DeviceInfoDTO)dropoffWindBS.Current))
            {
                MessageBox.Show("Устройство с таким именем уже используется для данного комп'ютера. Введите другое наименование.\n",
                                "Проверка уникальности наименования устройства", MessageBoxButtons.OK, MessageBoxIcon.Information);
                nameTBox.Focus();

                return(false);
            }

            DevicesDTO entity = new DevicesDTO()
            {
                Id         = ((DeviceInfoDTO)dropoffWindBS.Current).DeviceId,
                Name       = ((DeviceInfoDTO)dropoffWindBS.Current).Name,
                TypeId     = ((DeviceInfoDTO)dropoffWindBS.Current).TypeId,
                LocalCPUID = ((DeviceInfoDTO)dropoffWindBS.Current).LocalCPUID
            };

            if (_operation == Utils.Operation.Add)
            {
                int deviceTypeId = settingsService.GetDeviceTypeIdByName("DropoffWindow");
                entity.TypeId     = deviceTypeId;
                entity.LocalCPUID = ConfigClass.Instance.LocalCPUID;

                dropoffWindBS.EndEdit();

                _deviceId = settingsService.DeviceCreate(entity);

                if (_deviceId > 0)
                {
                    int skId = settingsService.GetSettingKindIdByName("WindNumber");

                    settingsService.DeviceSettingCreate(new DeviceSettingsDTO()
                    {
                        DeviceId      = _deviceId,
                        SettingKindId = skId,
                        SettingValue  = ((DeviceInfoDTO)dropoffWindBS.Current).SettingValue
                    });
                }
                else
                {
                    MessageBox.Show("Ошибка при добавлении нового устройства! Проверьте настройки подключения.\n", "Сохранение", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return(false);
                }
            }
            else
            {
                settingsService.DeviceUpdate(entity);

                var model = new DeviceSettingsDTO()
                {
                    Id            = ((DeviceInfoDTO)dropoffWindBS.Current).DeviceSettingId ?? 0,
                    DeviceId      = ((DeviceInfoDTO)dropoffWindBS.Current).DeviceId,
                    SettingKindId = ((DeviceInfoDTO)dropoffWindBS.Current).SettingKindId ?? 0,
                    SettingValue  = ((DeviceInfoDTO)dropoffWindBS.Current).SettingValue
                };

                settingsService.DeviceSettingUpdate(model);
            }

            return(true);
        }
Пример #3
0
        public int DeviceSettingCreate(DeviceSettingsDTO dsdto)
        {
            var newSetting = DeviceSettings.Create(mapper.Map <DeviceSettings>(dsdto));

            return(newSetting.Id);
        }
Пример #4
0
        private bool SaveDBSettings()
        {
            settingsService = Program.kernel.Get <ISettingsService>();

            if (FindDeviceNameDuplicate((DeviceInfoDTO)DBDeviceBS.Current, _parentDeviceId))
            {
                MessageBox.Show("Блок памяти таким именем уже используется для данного контроллера. Введите другое наименование.\n",
                                "Сохранение", MessageBoxButtons.OK, MessageBoxIcon.Information);
                nameTBox.Focus();

                return(false);
            }

            DBSettingsBS.EndEdit();
            DBDeviceBS.EndEdit();

            int deviceTypeId = settingsService.GetDeviceTypeIdByName("DB");

            DevicesDTO entity = new DevicesDTO()
            {
                Id         = _deviceId,
                Name       = ((DeviceInfoDTO)DBDeviceBS.Current).Name,
                TypeId     = deviceTypeId,
                LocalCPUID = ConfigClass.Instance.LocalCPUID
            };

            if (_operation == Utils.Operation.Add)
            {
                if (!dataItemList.Any(s => s.ItemTypeId == 0))
                {
                    _deviceId = settingsService.DeviceCreate(entity);

                    if (_deviceId > 0)
                    {
                        int skId = settingsService.GetSettingKindIdByName("DataBlockIndex");

                        settingsService.DeviceSettingCreate(new DeviceSettingsDTO()
                        {
                            DeviceId      = _deviceId,
                            SettingKindId = skId,
                            SettingValue  = ((DeviceInfoDTO)DBDeviceBS.Current).SettingValue
                        });

                        int iId = settingsService.GetSettingKindIdByName("Interval");

                        settingsService.DeviceSettingCreate(new DeviceSettingsDTO()
                        {
                            DeviceId      = _deviceId,
                            SettingKindId = iId,
                            SettingValue  = refreshSpin.EditValue.ToString()
                        });

                        dataItemList.ForEach(s => s.DeviceId = _deviceId);

                        var items = dataItemList.Select(s => new DataItemsDTO()
                        {
                            DeviceId       = s.DeviceId,
                            ItemTypeId     = s.ItemTypeId,
                            Name           = s.Name,
                            Offset         = s.Offset,
                            ParentDeviceId = s.ParentDeviceId,
                            CanListen      = (s.CanListen) ? 1 : 0
                        }).ToList();

                        settingsService.DataItemsCreate(items);
                    }
                    else
                    {
                        MessageBox.Show("Ошибка при добавлении нового устройства! Проверьте настройки подключения.", "Сохранение", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return(false);
                    }
                }
                else
                {
                    MessageBox.Show("Не выбран тип данных для одной или нескольких переменных блока памяти!", "Сохранение", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return(false);
                }
            }
            else
            {
                settingsService.DeviceUpdate(entity);

                var modelIndex = new DeviceSettingsDTO()
                {
                    Id            = ((DeviceInfoDTO)DBDeviceBS.Current).DeviceSettingId ?? 0,
                    DeviceId      = ((DeviceInfoDTO)DBDeviceBS.Current).DeviceId,
                    SettingKindId = settingsService.GetSettingKindIdByName("DataBlockIndex"),
                    SettingValue  = ((DeviceInfoDTO)DBDeviceBS.Current).SettingValue
                };

                settingsService.DeviceSettingUpdate(modelIndex);

                var modelInterval = new DeviceSettingsDTO()
                {
                    Id            = _intervatSettingId,
                    DeviceId      = ((DeviceInfoDTO)DBDeviceBS.Current).DeviceId,
                    SettingKindId = settingsService.GetSettingKindIdByName("Interval"),
                    SettingValue  = refreshSpin.EditValue.ToString()
                };

                settingsService.DeviceSettingUpdate(modelInterval);

                var items = dataItemList.Select(s => new DataItemsDTO()
                {
                    Id             = s.Id,
                    DeviceId       = s.DeviceId,
                    ItemTypeId     = s.ItemTypeId,
                    Name           = s.Name,
                    Offset         = s.Offset,
                    ParentDeviceId = s.ParentDeviceId,
                    CanListen      = (s.CanListen) ? 1 : 0
                }).ToList();

                settingsService.DataItemsUpdate(items);
            }

            return(true);
        }