public SettingsStackerEditFm(Utils.Operation operation, DevicesDTO model) { InitializeComponent(); _operation = operation; stackerBS.DataSource = model; nameTBox.DataBindings.Add("EditValue", stackerBS, "Name"); }
private bool FindDeviceNameDuplicate(DevicesDTO item) { bool result = false; if (ConfigClass.Instance.DeviceSettingsList != null) { var source = (ConfigClass.Instance.DeviceSettingsList).FirstOrDefault(s => s.Name == item.Name); if (source != null) { result = (source.DeviceId != item.Id) ? true : false; } } return(result); }
public void DeviceUpdate(DevicesDTO ddto) { var entity = Devices.GetAll().SingleOrDefault(c => c.Id == ddto.Id); Devices.Update(mapper.Map <DevicesDTO, Devices>(ddto, entity)); }
public int DeviceCreate(DevicesDTO ddto) { var newDevice = Devices.Create(mapper.Map <Devices>(ddto)); return(newDevice.Id); }
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); }
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); }