private void Edit_Click(object sender, RoutedEventArgs e) { if (!(datas.SelectedItem is BibaObject obj)) { return; } if (!Current.CanWrite(obj)) { MessageBox.Show("没有权限修改!"); return; } EditDialog editDialog = new EditDialog(); bool? dialogResult = editDialog.ShowDialog(); switch (dialogResult) { case true: obj.Value = editDialog.Value; ConfigUtil.WriteObject(MainWindow.Data, obj); break; case false: break; default: break; } }
private void OkButton_Click(object sender, RoutedEventArgs e) { string inputKey = key.Text; string inputValue = value.Text; string inputLevel = level.Text; if (string.IsNullOrEmpty(inputKey)) { error.Text = "请输入键!"; } else if (string.IsNullOrEmpty(inputValue)) { error.Text = "请输入值!"; } else if (string.IsNullOrEmpty(inputLevel)) { error.Text = "请输入等级!"; } else if (ConfigUtil.ObjectExists(MainWindow.Data, inputKey)) { error.Text = "键已存在,请换个!"; } else if (!subject.CanWrite(int.Parse(inputLevel))) { error.Text = string.Format("无权限写等级为{0}的客体", inputLevel); } else { Key = inputKey; Value = inputValue; Level = int.Parse(inputLevel); DialogResult = true; Close(); } }