129 lines
4.0 KiB
C#
129 lines
4.0 KiB
C#
using CeramicProjectTool.Model;
|
|
using CeramicProjectTool.Util;
|
|
using CeramicProjectTool.ViewModel;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Security;
|
|
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.Navigation;
|
|
using System.Windows.Shapes;
|
|
|
|
namespace CeramicProjectTool.Pages
|
|
{
|
|
/// <summary>
|
|
/// ModelConfigPage.xaml 的交互逻辑
|
|
/// </summary>
|
|
public partial class ModelConfigPage : System.Windows.Controls.Page
|
|
{
|
|
private MKConfigViewModel configViewModel;
|
|
public ModelConfigPage()
|
|
{
|
|
InitializeComponent();
|
|
configViewModel = new MKConfigViewModel();
|
|
this.DataContext = configViewModel;
|
|
}
|
|
|
|
private void Page_Loaded(object sender, RoutedEventArgs e)
|
|
{
|
|
LoadData();
|
|
}
|
|
|
|
private async void ModelListView_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
|
{
|
|
var datas = ((ListView)sender).ItemsSource as List<ModuleModel>;
|
|
var selectedIndex = ((ListView)sender).SelectedIndex;
|
|
var mkModel = datas?[selectedIndex == -1 ? 0 : selectedIndex];
|
|
LoadModuleData(mkModel);
|
|
|
|
}
|
|
|
|
private void LoadData()
|
|
{
|
|
var modelList = configViewModel.GetMkList();
|
|
modelList.ContinueWith((task) =>
|
|
{
|
|
ModelListView.Dispatcher.Invoke(() =>
|
|
{
|
|
ModelListView.ItemsSource = task.Result;
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
private async void LoadModuleData(ModuleModel mkModel)
|
|
{
|
|
if (mkModel == null)
|
|
{
|
|
mkModel = configViewModel.SelectedModule;
|
|
}
|
|
|
|
if (mkModel != null)
|
|
{
|
|
configViewModel.SetSelectMKModel(mkModel);
|
|
var permissonList = await configViewModel.GetPermissons(mkModel.ModuleName);
|
|
if (permissonList != null)
|
|
{
|
|
permissonData.Dispatcher.Invoke(() =>
|
|
{
|
|
permissonData.ItemsSource = permissonList;
|
|
});
|
|
}
|
|
}
|
|
}
|
|
private async void SaveBtn_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
var module = configViewModel.SelectedModule;
|
|
if (module == null)
|
|
{
|
|
MessageBox.Show("请选择一个模块");
|
|
return;
|
|
}
|
|
await configViewModel.UpdateModule(module);
|
|
var permissonList = permissonData.ItemsSource as List<PermissonModel>;
|
|
if (permissonList != null)
|
|
{
|
|
await configViewModel.UpdatePermissons(permissonList);
|
|
}
|
|
|
|
}
|
|
|
|
private async void addPermissonBtn_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
var addedPermissons = new List<PermissonModel>();
|
|
var permissonList = permissonData.ItemsSource as List<PermissonModel>;
|
|
addedPermissons = permissonList?.Where(i => i.Id == 0).ToList();
|
|
if (addedPermissons == null)
|
|
{
|
|
return;
|
|
}
|
|
await configViewModel.InsertPermissons(addedPermissons);
|
|
LoadModuleData(null);
|
|
}
|
|
|
|
private async void delPermissonBtn_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
var selectedItems = permissonData.SelectedItems;
|
|
var permissonList = permissonData.ItemsSource as List<PermissonModel>;
|
|
var permissonIds = selectedItems.Cast<PermissonModel>().Select(x => x.Id).ToList();
|
|
await configViewModel.DeletePermissons(permissonIds);
|
|
LoadModuleData(null);
|
|
|
|
}
|
|
|
|
private void ResetBtn_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
LoadModuleData(null);
|
|
|
|
}
|
|
}
|
|
}
|