alielie
2025-03-13 ba6207f52db76ab47cd6534de0cf1712674ff179
HMI.AlermInfoManage/AlarmSettingList.xaml.cs
@@ -47,7 +47,7 @@
        }
        private ObservableCollection<string> items =
            new ObservableCollection<string> { "DB块报警", "标志位报警" };
            new ObservableCollection<string> { LangUtil.Get("Alm.DbBlockAlarm"), LangUtil.Get("Alm.TagAlarm") };
        public ObservableCollection<string> Items
        {
@@ -55,14 +55,13 @@
            set { Set(ref items, value); }
        }
        private string selectedValue;
        public string SelectedValue
        private int itemIndex;
        public int ItemIndex
        {
            get { return selectedValue; }
            get => itemIndex;
            set
            {
                Set(ref selectedValue, value);
                Set(ref itemIndex, value);
                LoadData();
            }
        }
@@ -99,12 +98,12 @@
            try
            {
                ObservableCollection<AlarmSetting> datasource = new ObservableCollection<AlarmSetting>();
                if (SelectedValue == "DB块报警" && File.Exists(blockFile))
                if (ItemIndex == 0 && File.Exists(blockFile))
                {
                    datasource =
                        XmlHelper.DeserializeFromXml<ObservableCollection<AlarmSetting>>(blockFile);
                }
                else if (SelectedValue == "标志位报警" && File.Exists(markFile))
                else if (ItemIndex == 1 && File.Exists(markFile))
                {
                    datasource =
                        XmlHelper.DeserializeFromXml<ObservableCollection<AlarmSetting>>(markFile);
@@ -113,7 +112,7 @@
            }
            catch (Exception ex)
            {
                ToastHelper.Error(this, $"加载错误!{ex.Message}");
                ToastHelper.Error(this, $"{this.lang("App.LoadFailed")}: {ex.Message}");
            }
        }
@@ -121,10 +120,11 @@
        {
            try
            {
                var file = SelectedValue == "DB块报警" ? blockFile : markFile;
                var file = ItemIndex == 0 ? blockFile : markFile;
                var temp = ItemIndex == 0 ? this.lang("Alm.DbBlockAlarm") : this.lang("Alm.TagAlarm");
                var modal = new AlarmSettingModal(log)
                {
                    Title = $"新增{SelectedValue}",
                    Title = $"{this.lang("App.Add")}{temp}",
                    Owner = Window.GetWindow(this),
                };
                if (modal.Open(-1, data, Datasource, file) == true)
@@ -135,7 +135,7 @@
            catch (Exception ex)
            {
                log.Error("Add AlarmSetting Failed.", ex);
                ToastHelper.Error(this, $"新增失败!{ex.Message}");
                ToastHelper.Error(this, $"{this.lang("App.AddFailed")}: {ex.Message}");
            }
        }
@@ -143,10 +143,11 @@
        {
            try
            {
                var file = SelectedValue == "DB块报警" ? blockFile : markFile;
                var file = ItemIndex == 0 ? blockFile : markFile;
                var temp = ItemIndex == 0 ? this.lang("Alm.DbBlockAlarm") : this.lang("Alm.TagAlarm");
                var modal = new AlarmSettingModal(log)
                {
                    Title = $"编辑{SelectedValue}",
                    Title = $"{this.lang("App.Edit")}{temp}",
                    Owner = Window.GetWindow(this),
                };
                if (modal.Open(index, data, Datasource, file) == true)
@@ -157,16 +158,16 @@
            catch (Exception ex)
            {
                log.Error("Edit AlarmSetting Failed.", ex);
                ToastHelper.Error(this, $"编辑失败!{ex.Message}");
                ToastHelper.Error(this, $"{this.lang("App.EditFailed")}: {ex.Message}");
            }
        }
        private void DeleteData(int index)
        {
            try
            {
                if (MsgBoxHelper.WarnMessage(Window.GetWindow(this), "确定要删除该项吗?该操作不可逆") == MessageBoxResult.OK)
                if (MsgBoxHelper.WarnMessage(Window.GetWindow(this), this.lang("HMI.MakeSureDeleteThis")) == MessageBoxResult.OK)
                {
                    var file = SelectedValue == "DB块报警" ? blockFile : markFile;
                    var file = ItemIndex == 0 ? blockFile : markFile;
                    var temp = XmlHelper.DeepClone(Datasource);
                    temp.RemoveAt(index);
@@ -177,7 +178,7 @@
            catch (Exception ex)
            {
                log.Error("Delete AlarmSetting Failed.", ex);
                ToastHelper.Error(this, $"删除失败!{ex.Message}");
                ToastHelper.Error(this, $"{this.lang("App.DeleteFailed")}: {ex.Message}");
            }
        }
        private void DeleteBatchData()
@@ -187,13 +188,14 @@
                var temp = Datasource.Where(e => e.IsSelected).ToList();
                if (temp == null || temp.Count <= 0)
                {
                    ToastHelper.Warning(Window.GetWindow(this), "请选择要删除的数据");
                    ToastHelper.Warning(Window.GetWindow(this), this.lang("HMI.NoDeleteData"));
                    return;
                }
                if (MsgBoxHelper.WarnMessage(Window.GetWindow(this), $"确定要删除{temp.Count}项数据吗?该操作不可逆") == MessageBoxResult.OK)
                if (MsgBoxHelper.WarnMessage(Window.GetWindow(this), this.lang("HMI.MakeSureDeletes", temp.Count))
                    == MessageBoxResult.OK)
                {
                    var file = SelectedValue == "DB块报警" ? blockFile : markFile;
                    var file = ItemIndex == 0 ? blockFile : markFile;
                    temp = Datasource.Where(e => !e.IsSelected).ToList();
                    XmlHelper.SerializeToXml(file, temp);
                    LoadData();
@@ -202,13 +204,13 @@
            catch (Exception ex)
            {
                log.Error("Delete Batch AlarmSetting Failed.", ex);
                ToastHelper.Error(this, $"删除失败!{ex.Message}");
                ToastHelper.Error(this, $"{this.lang("App.DeleteFailed")}: {ex.Message}");
            }
        }
        private void WindowX_Loaded(object sender, RoutedEventArgs e)
        {
            SelectedValue = "DB块报警";
            ItemIndex = 0;
            Loaded -= WindowX_Loaded;
        }
    }