1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- using MV485.db;
- using MV485.model;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Data;
- using System.Windows.Documents;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- using System.Windows.Shapes;
- namespace MV485.Dlg
- {
- /// <summary>
- /// DlgUpdateDevice.xaml 的交互逻辑
- /// </summary>
- public partial class DlgUpdateDevice : Window
- {
- private TSlave _slave;
- public DlgUpdateDevice(TSlave slave)
- {
- InitializeComponent();
- _slave = slave;
- InitView(slave);
- }
- private void InitView(TSlave slave)
- {
- txtPortName.Text = slave.PortName;
- txtBaudrate.Text = slave.BaudRate.ToString();
- txtDevId.Text = slave.Address.ToString();
- txtReadInterval.Text = slave.ReadInterval.ToString();
- chkReadImage.IsChecked = slave.ReadImageFlag == 1;
- chkRun.IsChecked = slave.RunFlag == 1;
- }
- private async void BtnOK_Click(object sender, RoutedEventArgs e)
- {
- if (!int.TryParse(txtReadInterval.Text, out int readInterval) || readInterval < 1 || readInterval > 1440)
- {
- MessageBox.Show(this, "请输入正确的间隔时间(5-1440)分钟", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
- return;
- }
- string titleInfo = "正在更新数据库,请稍候...";
- WaitWindow waitWindow = new WaitWindow(titleInfo)
- {
- Owner = this,
- WindowStartupLocation = WindowStartupLocation.CenterOwner
- };
- waitWindow.Show();
- try
- {
- _slave.ReadInterval = readInterval;
- _slave.ReadImageFlag = chkReadImage.IsChecked == true ? 1 : 0;
- _slave.RunFlag = chkRun.IsChecked == true ? 1 : 0;
- bool blUpdate = await Task.Run(() =>
- {
- return DBSlave.UpdateTSlave(_slave);
- });
- if (blUpdate)
- {
- }
- }
- catch (Exception ex)
- {
- MessageBox.Show($"更新数据失败:{ex.Message}", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
- }
- finally
- {
- waitWindow.Close();
- }
- DialogResult = true;
- this.Close();
- }
- private void BtnClose_Click(object sender, RoutedEventArgs e)
- {
- DialogResult = false;
- this.Close();
- }
- //-------------------------------------------------
- }
- }
|