public Recorder(IMeasuringDevice device) { measuringDevice = device; timer = new System.Timers.Timer(period); timer.Elapsed += new ElapsedEventHandler(timerElapsed); samples = new List <Sample>(); window = new RecorderWindow(this); if (ConnectWithDevice()) { throw new Exception(); } window.Show(); timer.Start(); }
public async Task <ActionResult> Edit([Bind(Include = "ID,Name,SerialNumber,CalibrationExpirationDate,EmployeeID")] MeasuringDeviceEditViewModel editedMeasuringDevice) { try { if (ModelState.IsValid) { IMeasuringDevice measuringDevice = (Mapper.Map <MeasuringDevice>(editedMeasuringDevice)); await Service.UpdateAsync(measuringDevice); return(RedirectToAction("Index")); } } catch (DataException) { ModelState.AddModelError("", "Unable to save changes. Try again and if the problem persists see your system administrator."); } return(View(editedMeasuringDevice)); }
//---------------------------------------------------------------------------- /// <summary> /// Создаём виртуальное устройство и функционал для работы с ним /// </summary> /// <param name="device">Устройство КИП, /// если передаётся null - создаётся новое устройство</param> private void CreateDevice(IMeasuringDevice device) { if (device == null) { // Открываем форму для создания нового устройства Forms.FormSelectTypeDevice frm = new Forms.FormSelectTypeDevice(); DialogResult result = frm.ShowDialog(this); if (result != System.Windows.Forms.DialogResult.OK) { return; } else { // Создаём экземпляр switch (frm.TypeDevice) { case TYPE_NGK_DEVICE.BI_BATTERY_POWER: { //MessageBox.Show(this, "Данный тип БИ не поддерживается ПО", // "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); //return; MeasuringDeviceBatteryPower dv = new MeasuringDeviceBatteryPower(); device = (IMeasuringDevice)dv; break; } case TYPE_NGK_DEVICE.BI_MAIN_POWERED: { MeasuringDeviceMainPower dv = new MeasuringDeviceMainPower(); device = (IMeasuringDevice)dv; break; } default: { MessageBox.Show(this, "Данный тип БИ не поддерживается ПО", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } } } switch (device.GetDeviceType()) { case TYPE_NGK_DEVICE.BI_MAIN_POWERED: { _Host = new Modbus.OSIModel.ApplicationLayer.Master.Device( "NetworkModbus", (IDataLinkLayer)_SerialPort); _MeasuringDevice = device; _MeasuringDevice.PropertyChanged += new PropertyChangedEventHandler(_MeasuringDevice_PropertyChanged); break; } case TYPE_NGK_DEVICE.BI_BATTERY_POWER: { _Host = new Modbus.OSIModel.ApplicationLayer.Master.Device("NetworkModbus", (IDataLinkLayer)_SerialPort); _MeasuringDevice = device; _MeasuringDevice.PropertyChanged += new PropertyChangedEventHandler(_MeasuringDevice_PropertyChanged); break; } default: { throw new Exception("Попытка создания устройства БИ с неопределённым типом"); } } // Настраиваем элементы навигации, управления и меню ToolStripMenuItem itemMenu; ToolStripButton button; // Главное меню: // Меню "Файл" itemMenu = ((ToolStripMenuItem)this.menuStripMain.Items["mnuFile"]); itemMenu.Enabled = true; itemMenu.DropDownItems["mnuFileCreate"].Enabled = false; itemMenu.DropDownItems["mnuFileOpen"].Enabled = true; itemMenu.DropDownItems["mnuFileClose"].Enabled = true; itemMenu.DropDownItems["mnuFileSave"].Enabled = true; itemMenu.DropDownItems["mnuFileSaveAs"].Enabled = true; itemMenu.DropDownItems[MENU.mnuFilePrint].Enabled = true; itemMenu.DropDownItems[MENU.mnuFilePrintPreview].Enabled = true; itemMenu.DropDownItems[MENU.mnuFilePrintSettings].Enabled = true; itemMenu.DropDownItems[MENU.mnuFilePageSettings].Enabled = true; itemMenu.DropDownItems["mnuFileExit"].Enabled = true; // Меню "Устройство КИП" if (_SerialPort.IsOpen()) { itemMenu = ((ToolStripMenuItem)this.menuStripMain.Items["mnuDevice"]); itemMenu.Enabled = true; itemMenu.DropDownItems["mnuDeviceRead"].Enabled = true; itemMenu.DropDownItems["mnuDeviceWrite"].Enabled = true; } else { itemMenu = ((ToolStripMenuItem)this.menuStripMain.Items["mnuDevice"]); itemMenu.Enabled = false; itemMenu.DropDownItems["mnuDeviceRead"].Enabled = true; itemMenu.DropDownItems["mnuDeviceWrite"].Enabled = true; } // Меню "Подключение" //itemMenu = ((ToolStripMenuItem)this.menuStripMain.Items["mnuConnection"]); //itemMenu.Enabled = true; //itemMenu.DropDownItems["mnuConnectionConnect"].Enabled = false; //itemMenu.DropDownItems["mnuConnectionDisconnect"].Enabled = true; // Меню "Помощь" itemMenu = ((ToolStripMenuItem)this.menuStripMain.Items["mnuHelp"]); itemMenu.Enabled = true; itemMenu.DropDownItems["mnuHelpHelp"].Enabled = true; itemMenu.DropDownItems["mnuHelpAbout"].Enabled = true; // Инициализируем панель инструментов button = (ToolStripButton)this.toolStripMain.Items["buttonSaveDevice"]; button.Enabled = true; button = (ToolStripButton)this.toolStripMain.Items["buttonNewDevice"]; button.Enabled = false; button = (ToolStripButton)this.toolStripMain.Items["buttonDeleteDevice"]; button.Enabled = true; button = (ToolStripButton)this.toolStripMain.Items["buttonConnection"]; //button.Enabled = true; //button.ToolTipText = "Поключить"; //button.Image = global::NGK.MeasuringDeviceTech.Properties.Resources.IconDisconnect; //((ToolStripMenuItem)menuStripMain.Items["mnuConnection"]).DropDownItems["mnuConnectionConnect"].Enabled = true; //((ToolStripMenuItem)menuStripMain.Items["mnuConnection"]).DropDownItems["mnuConnectionDisconnect"].Enabled = false; if (_SerialPort.IsOpen()) { button = (ToolStripButton)this.toolStripMain.Items["buttonReadDevice"]; button.Enabled = true; button = (ToolStripButton)this.toolStripMain.Items["buttonWriteDevice"]; button.Enabled = true; button = (ToolStripButton)this.toolStripMain.Items["buttonVerifyInitDevice"]; button.Enabled = true; button = (ToolStripButton)this.toolStripMain.Items["buttonSyncDateTime"]; button.Enabled = true; button = (ToolStripButton)this.toolStripMain.Items[TOOLSTRIPBUTTON.buttonStartMonitor]; button.Enabled = true; button = (ToolStripButton)this.toolStripMain.Items[TOOLSTRIPBUTTON.buttonStopMonitor]; button.Enabled = false; } else { button = (ToolStripButton)this.toolStripMain.Items["buttonReadDevice"]; button.Enabled = false; button = (ToolStripButton)this.toolStripMain.Items["buttonWriteDevice"]; button.Enabled = false; button = (ToolStripButton)this.toolStripMain.Items["buttonVerifyInitDevice"]; button.Enabled = false; button = (ToolStripButton)this.toolStripMain.Items["buttonSyncDateTime"]; button.Enabled = false; button = (ToolStripButton)this.toolStripMain.Items[TOOLSTRIPBUTTON.buttonStartMonitor]; button.Enabled = false; button = (ToolStripButton)this.toolStripMain.Items[TOOLSTRIPBUTTON.buttonStopMonitor]; button.Enabled = false; } // Переходим в дереве на устройство и обновляем данные if (this.treeViewMain.SelectedNode == this.treeViewMain.Nodes["NodeRoot"].Nodes["NodeMeasuringDevice"]) { // Это необходимо делать, т.к. если в данный момен выбран нод "NodeMeasuringDevice" // и создаётся устройство, то отображение данных созданного устройства в propertygrid не происходит!!! this.treeViewMain.SelectedNode = this.treeViewMain.Nodes["NodeRoot"]; this.treeViewMain.SelectedNode = this.treeViewMain.Nodes["NodeRoot"].Nodes["NodeMeasuringDevice"]; } else { this.treeViewMain.SelectedNode = this.treeViewMain.Nodes["NodeRoot"].Nodes["NodeMeasuringDevice"]; } return; }
//---------------------------------------------------------------------------- /// <summary> /// Удаляет открытое устройство КИП. /// </summary> /// <returns>возвращает false - елсли операция была отменена пользователем</returns> private Boolean DeleteDevice() { DialogResult result; Boolean res = true; if (_MeasuringDevice != null) { result = MessageBox.Show(this, "Устройство КИП будет удалено! Сохранить изменения?", "Внимание", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); switch (result) { case System.Windows.Forms.DialogResult.No: { if (this.propertyGridMain.SelectedObject is IMeasuringDevice) { this.propertyGridMain.SelectedObject = null; } _MeasuringDevice = null; // Закрываем файл устройсва КИП if (_File != null) { _File.Flush(); _File.Close(); GC.Collect(); _File = null; // Удаляем путь к файлу ((ToolStripLabel)this.statusStripMain.Items["PathToFile"]).Visible = false; ((ToolStripLabel)this.statusStripMain.Items["PathToFile"]).Text = String.Empty; } // Настраиваем элементы навигации и управления на форме ToolStripMenuItem itemMenu; ToolStripButton button; // Главное меню: // Меню "Файл" itemMenu = ((ToolStripMenuItem)this.menuStripMain.Items["mnuFile"]); itemMenu.Enabled = true; itemMenu.DropDownItems["mnuFileCreate"].Enabled = true; itemMenu.DropDownItems["mnuFileOpen"].Enabled = true; itemMenu.DropDownItems["mnuFileClose"].Enabled = false; itemMenu.DropDownItems["mnuFileSave"].Enabled = false; itemMenu.DropDownItems["mnuFileSaveAs"].Enabled = false; itemMenu.DropDownItems[MENU.mnuFilePrint].Enabled = false; itemMenu.DropDownItems[MENU.mnuFilePrintPreview].Enabled = false; itemMenu.DropDownItems[MENU.mnuFilePrintSettings].Enabled = false; itemMenu.DropDownItems[MENU.mnuFilePageSettings].Enabled = false; itemMenu.DropDownItems["mnuFileExit"].Enabled = true; // Меню "Устройство КИП" itemMenu = ((ToolStripMenuItem)this.menuStripMain.Items["mnuDevice"]); itemMenu.Enabled = false; itemMenu.DropDownItems["mnuDeviceRead"].Enabled = true; itemMenu.DropDownItems["mnuDeviceWrite"].Enabled = true; // Меню "Подключение" //itemMenu = ((ToolStripMenuItem)this.menuStripMain.Items["mnuConnection"]); //itemMenu.Enabled = true; //itemMenu.DropDownItems["mnuConnectionConnect"].Enabled = true; //itemMenu.DropDownItems["mnuConnectionDisconnect"].Enabled = false; // Меню "Помощь" itemMenu = ((ToolStripMenuItem)this.menuStripMain.Items["mnuHelp"]); itemMenu.Enabled = true; itemMenu.DropDownItems["mnuHelpHelp"].Enabled = true; itemMenu.DropDownItems["mnuHelpAbout"].Enabled = true; // Инициализируем панель инструментов button = (ToolStripButton)this.toolStripMain.Items["buttonSaveDevice"]; button.Enabled = false; button = (ToolStripButton)this.toolStripMain.Items["buttonNewDevice"]; button.Enabled = true; button = (ToolStripButton)this.toolStripMain.Items["buttonDeleteDevice"]; button.Enabled = false; //button = (ToolStripButton)this.toolStripMain.Items["buttonConnection"]; //button.Enabled = true; button = (ToolStripButton)this.toolStripMain.Items["buttonVerifyInitDevice"]; button.Enabled = false; button = (ToolStripButton)this.toolStripMain.Items["buttonReadDevice"]; button.Enabled = false; button = (ToolStripButton)this.toolStripMain.Items["buttonWriteDevice"]; button.Enabled = false; button = (ToolStripButton)this.toolStripMain.Items["buttonSyncDateTime"]; button.Enabled = false; button = (ToolStripButton)this.toolStripMain.Items[TOOLSTRIPBUTTON.buttonStartMonitor]; button.Enabled = false; button = (ToolStripButton)this.toolStripMain.Items[TOOLSTRIPBUTTON.buttonStopMonitor]; button.Enabled = false; res = true; break; } case System.Windows.Forms.DialogResult.Yes: { // Сохраняем устройство в файл. Если он не был открыт, // то предлагаем сохранить вновь this.SaveFile(); // Удаляем устройство КИП if (this.propertyGridMain.SelectedObject is IMeasuringDevice) { this.propertyGridMain.SelectedObject = null; } _MeasuringDevice = null; // Закрываем файл устройсва КИП if (_File != null) { _File.Flush(); _File.Close(); GC.Collect(); _File = null; // Удаляем путь к файлу ((ToolStripLabel)this.statusStripMain.Items["PathToFile"]).Visible = false; ((ToolStripLabel)this.statusStripMain.Items["PathToFile"]).Text = String.Empty; } // Настраиваем элементы навигации и управления на форме ToolStripMenuItem itemMenu; ToolStripButton button; // Главное меню: // Меню "Файл" itemMenu = ((ToolStripMenuItem)this.menuStripMain.Items["mnuFile"]); itemMenu.Enabled = true; itemMenu.DropDownItems["mnuFileCreate"].Enabled = true; itemMenu.DropDownItems["mnuFileOpen"].Enabled = true; itemMenu.DropDownItems["mnuFileClose"].Enabled = false; itemMenu.DropDownItems["mnuFileSave"].Enabled = false; itemMenu.DropDownItems["mnuFileSaveAs"].Enabled = false; itemMenu.DropDownItems[MENU.mnuFilePrint].Enabled = false; itemMenu.DropDownItems[MENU.mnuFilePrintPreview].Enabled = false; itemMenu.DropDownItems[MENU.mnuFilePrintSettings].Enabled = false; itemMenu.DropDownItems[MENU.mnuFilePageSettings].Enabled = false; itemMenu.DropDownItems["mnuFileExit"].Enabled = true; // Меню "Устройство КИП" itemMenu = ((ToolStripMenuItem)this.menuStripMain.Items["mnuDevice"]); itemMenu.Enabled = false; itemMenu.DropDownItems["mnuDeviceRead"].Enabled = true; itemMenu.DropDownItems["mnuDeviceWrite"].Enabled = true; // Меню "Подключение" //itemMenu = ((ToolStripMenuItem)this.menuStripMain.Items["mnuConnection"]); //itemMenu.Enabled = true; //itemMenu.DropDownItems["mnuConnectionConnect"].Enabled = true; //itemMenu.DropDownItems["mnuConnectionDisconnect"].Enabled = false; // Меню "Помощь" itemMenu = ((ToolStripMenuItem)this.menuStripMain.Items["mnuHelp"]); itemMenu.Enabled = true; itemMenu.DropDownItems["mnuHelpHelp"].Enabled = true; itemMenu.DropDownItems["mnuHelpAbout"].Enabled = true; // Инициализируем панель инструментов button = (ToolStripButton)this.toolStripMain.Items["buttonSaveDevice"]; button.Enabled = false; button = (ToolStripButton)this.toolStripMain.Items["buttonNewDevice"]; button.Enabled = true; button = (ToolStripButton)this.toolStripMain.Items["buttonDeleteDevice"]; button.Enabled = false; //button = (ToolStripButton)this.toolStripMain.Items["buttonConnection"]; //button.Enabled = true; button = (ToolStripButton)this.toolStripMain.Items["buttonVerifyInitDevice"]; button.Enabled = false; button = (ToolStripButton)this.toolStripMain.Items["buttonReadDevice"]; button.Enabled = false; button = (ToolStripButton)this.toolStripMain.Items["buttonWriteDevice"]; button.Enabled = false; button = (ToolStripButton)this.toolStripMain.Items["buttonSyncDateTime"]; button.Enabled = false; button = (ToolStripButton)this.toolStripMain.Items[TOOLSTRIPBUTTON.buttonStartMonitor]; button.Enabled = false; button = (ToolStripButton)this.toolStripMain.Items[TOOLSTRIPBUTTON.buttonStopMonitor]; button.Enabled = false; res = true; break; } case System.Windows.Forms.DialogResult.Cancel: { // Действие отменено. res = false; break; } } } else { // Устройство не существует, закрыть не можем res = true; } return res; }
//---------------------------------------------------------------------------- /// <summary> /// Открывает файл образа устройства КИП /// </summary> private void OpenFile() { DialogResult result; // Проверяем. Если устройство создано, но файл с ним не связан // Предлагаем сохранить его if (_MeasuringDevice != null) { // Если удаление устройства отменено пользователем, то просто выходим if (!this.DeleteDevice()) { return; } } // Проверяем если открыт другой файл, закрываем его if (_File != null) { result = MessageBox.Show(this, "Сохранить и закрыть текущее устройство КИП?", "Внимание", MessageBoxButtons.OKCancel, MessageBoxIcon.Question); if (result == System.Windows.Forms.DialogResult.OK) { // Сохраняем и закрываем SaveFile(); _File.Flush(); _File.Close(); GC.Collect(); _File = null; // Выполняем открытие файла образа OpenFileDialog dlg = new OpenFileDialog(); dlg.Title = "Открыть файл образа КИП"; dlg.Multiselect = false; //dlg.InitialDirectory = Properties.Settings.Default.FilesDirectory; dlg.DefaultExt = "kip"; dlg.Filter = "NGK файлы образов КИП-ов (*.kip)|*.kip"; result = dlg.ShowDialog(this); if (result == System.Windows.Forms.DialogResult.OK) { // Открываем файл _File = (FileStream)dlg.OpenFile(); // Десериализуем объект Object obj = MeasuringDeviceMainPower.Deserialize(_File); if (obj == null) { obj = MeasuringDeviceBatteryPower.Deserialize(_File); if (obj == null) { _File.Flush(); _File.Close(); GC.Collect(); _File = null; MessageBox.Show(this, "Неудалось открыть файл, формат не известен", "Ошибки", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } _MeasuringDevice = (IMeasuringDevice)obj; if (_MeasuringDevice == null) { MessageBox.Show(this, "Неудалость открыть устройство КИП", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); _File.Flush(); _File.Close(); GC.Collect(); _File = null; } } } else { return; } } else { // Если файл не открыт, открываем... OpenFileDialog dlg = new OpenFileDialog(); dlg.Title = "Открыть файл образа КИП"; dlg.Multiselect = false; //dlg.InitialDirectory = Properties.Settings.Default.FilesDirectory; dlg.DefaultExt = "kip"; dlg.Filter = "NGK файлы образов КИП-ов (*.kip)|*.kip"; result = dlg.ShowDialog(this); if (result == System.Windows.Forms.DialogResult.OK) { // Открываем файл //_File = File.Open(dlg.FileName, FileMode.Open, FileAccess.ReadWrite, FileShare.None); _File = new FileStream(dlg.FileName, FileMode.Open, FileAccess.ReadWrite, FileShare.None); // Десериализуем объект IMeasuringDevice dv; Object obj = MeasuringDeviceMainPower.Deserialize(_File); if (obj == null) { obj = MeasuringDeviceBatteryPower.Deserialize(_File); if (obj == null) { _File.Flush(); _File.Close(); GC.Collect(); _File = null; MessageBox.Show(this, "Неудалось открыть файл, формат не известен", "Ошибки", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } dv = (IMeasuringDevice)obj; if (dv == null) { MessageBox.Show(this, "Неудалость открыть устройство КИП", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); _File.Flush(); _File.Close(); GC.Collect(); _File = null; } else { // Сохраняем путь к файлу ((ToolStripLabel)this.statusStripMain.Items["PathToFile"]).Visible = true; ((ToolStripLabel)this.statusStripMain.Items["PathToFile"]).Text = dlg.FileName; // Добавляем устройство CreateDevice(dv); } } } return; }
public async Task UpdateAsync(IMeasuringDevice measuringDevice) { var measuringDeviceEntity = Mapper.Map <MeasuringDeviceEntity>(measuringDevice); await Repository.UpdateAsync(measuringDeviceEntity); }
public async Task UpdateAsync(IMeasuringDevice measuringDevice) { await MeasuringDeviceRepository.UpdateAsync(measuringDevice); }
public void InitializeSimulator() { _simulator = new Simulator(); }
public MainWindow() { InitializeComponent(); units = Units.Imperial; measuringDevice = new MeasureLengthDevice(units); }