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.Navigation;
|
using System.Windows.Shapes;
|
using XCommon.Log;
|
using XHandler.View.Com;
|
using XHandler.View.Classes;
|
using XImagingXhandler.XDAL;
|
using DataEntity.Share;
|
using DataEntity.UserManager;
|
using DataRWDAL.UserManager;
|
using System.Collections.ObjectModel;
|
namespace XHandler.View.User
|
{
|
/// <summary>
|
/// MenuManagement.xaml 的交互逻辑
|
/// </summary>
|
public partial class MenuManagement : UserControl
|
{
|
public event EventHandler menuChanged;
|
ObservableCollection<MenuInfoModel> menuList;
|
MenuTree menuTree = new MenuTree();
|
public MenuManagement()
|
{
|
InitializeComponent();
|
}
|
|
private void UserControl_Loaded(object sender, RoutedEventArgs e)
|
{
|
tv.ItemsSource = null;
|
menuList = new ObservableCollection<MenuInfoModel>(MenuInfoDB.GetAllRootMenu());
|
listboxMenu.ItemsSource = menuList;
|
|
GetMenuTree();
|
tv.ItemsSource = menuTree.Children;
|
}
|
|
private void GetMenuTree()
|
{
|
try
|
{
|
ObservableCollection<Method> methods = MethodDB.GetMethodFromdb(Shared.SoftwareInformation.software_device_number);
|
|
ObservableCollection<MethodGroup> group = MethodGroupDB.GetMethodGroupFromdb();
|
foreach (var mg in group)
|
{
|
MenuTree menu = new MenuTree();
|
menu.Id = mg.id;
|
menu.Name = mg.method_group_name;
|
menu.IsExpanded = true;
|
menu.ImgDefault = "";
|
|
var list = methods.Where(s => s.method_group_id == mg.method_group_id).ToList();
|
foreach (var item in list)
|
{
|
MenuTree mt = new MenuTree();
|
mt.Id = item.method_id;
|
mt.Name = item.method_name;
|
mt.Level = item.method_group_id;
|
mt.ImgDefault = item.method_ico;
|
mt.IsExpanded = false;
|
if (item.method_status == 1)
|
mt.IsChecked = true;
|
else
|
mt.IsChecked = false;
|
menu.Children.Add(mt);
|
}
|
|
menuTree.Children.Add(menu);
|
}
|
}
|
catch (Exception ex)
|
{
|
LoggerHelper.ErrorLog("btnUp_Click error ", ex);
|
}
|
}
|
|
private void btnUp_Click(object sender, RoutedEventArgs e)
|
{
|
try
|
{
|
if (listboxMenu.SelectedItem == null)
|
return;
|
int index = listboxMenu.SelectedIndex;
|
|
menuList.Move(index, index - 1);
|
listboxMenu.SelectedIndex = index - 1;
|
listboxMenu.Focus();
|
}
|
catch (Exception ex)
|
{
|
LoggerHelper.ErrorLog("btnUp_Click error ", ex);
|
}
|
}
|
|
private void btnDown_Click(object sender, RoutedEventArgs e)
|
{
|
try
|
{
|
if (listboxMenu.SelectedItem == null)
|
return;
|
int index = listboxMenu.SelectedIndex;
|
|
menuList.Move(index, index + 1);
|
listboxMenu.SelectedIndex = index + 1;
|
listboxMenu.Focus();
|
}
|
catch (Exception ex)
|
{
|
LoggerHelper.ErrorLog("btnDown_Click error ", ex);
|
}
|
}
|
|
private void btnMenuSave_Click(object sender, RoutedEventArgs e)
|
{
|
try
|
{
|
for (int i = 0; i < menuList.Count; i++)
|
{
|
MenuInfoModel menu = menuList[i];
|
menu.Sequence = i + 1;
|
MenuInfoDB.Update(menu);
|
}
|
menuChanged?.Invoke(this, new EventArgs());
|
}
|
catch(Exception ex)
|
{
|
LoggerHelper.ErrorLog("btnMenuSave_Click error ", ex);
|
}
|
}
|
|
private void btnCommandSave_Click(object sender, RoutedEventArgs e)
|
{
|
try
|
{
|
foreach (var menu in menuTree.Children)
|
{
|
foreach (var item in menu.Children)
|
{
|
Method method = new Method();
|
method.method_id = item.Id;
|
method.method_status = item.IsChecked == true ? 1 : 0;
|
|
MethodDB.UpdateMethodIntodb(method);
|
}
|
}
|
}
|
catch (Exception ex)
|
{
|
LoggerHelper.ErrorLog("btnCommandSave_Click error ", ex);
|
}
|
}
|
|
private void listboxCommand_PreviewMouseWheel(object sender, MouseWheelEventArgs e)
|
{
|
try
|
{
|
ItemsControl items = (ItemsControl)sender;
|
ScrollViewer scroll = XHandler.Class.Utilities.FindVisualChild<ScrollViewer>(items);
|
if (scroll != null)
|
{
|
scroll.ScrollToVerticalOffset(scroll.VerticalOffset - e.Delta);
|
}
|
}
|
catch (Exception ex)
|
{
|
LoggerHelper.ErrorLog("listboxCommand_PreviewMouseWheel ERROR:", ex);
|
}
|
}
|
}
|
}
|