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.Animation;
|
using System.Windows.Media.Imaging;
|
using System.Windows.Navigation;
|
using System.Windows.Shapes;
|
using XHandler.Class;
|
using DataEntity.User;
|
using XImagingXhandler.XDAL;
|
using XHandler.View.MethodProperty;
|
|
namespace XHandler.View.User
|
{
|
/// <summary>
|
/// EditAuthority.xaml 的交互逻辑
|
/// </summary>
|
public partial class EditAuthority : UserControl
|
{
|
public event EventHandler closeEvent;
|
public event EventHandler saveOkEvent;
|
string ID;
|
RoleTab roleModel;
|
MenuTree menuTrees = new MenuTree();
|
public EditAuthority()
|
{
|
InitializeComponent();
|
}
|
|
public EditAuthority(string id)
|
{
|
InitializeComponent();
|
ID = id;
|
|
roleModel = UserDB.GetARoleTab(ID);
|
this.DataContext = roleModel;
|
|
List<string> statusList = GetStatusList();
|
comboxStatus.ItemsSource = statusList;
|
|
GetAuthorityTrees(roleModel);
|
tv.ItemsSource = menuTrees.Children;
|
}
|
|
public List<string> GetStatusList()
|
{
|
List<string> list = new List<string>();
|
string disable = XImagingXhandler.XDAL.UserStatusEnum.DisablEnum.GetDescription();
|
list.Add(disable);
|
string enable = XImagingXhandler.XDAL.UserStatusEnum.EnableEnum.GetDescription();
|
list.Add(enable);
|
return list;
|
}
|
|
private List<MenuTree> GetAuthorityTrees(RoleTab role)
|
{
|
List<MenuTree> treeList = new List<MenuTree>();
|
|
List<MenuTab> menuList = UserDB.GetAllMenuTab();
|
|
var parentList = menuList.Where(s => s.level == 0).OrderBy(x => x.sequence).ToList();
|
var childList = menuList.Where(s => s.level == 1).ToList();
|
foreach (var menu in parentList)
|
{
|
MenuTree m = new MenuTree(menu);
|
menuTrees.Children.Add(m);
|
int a = 0;
|
if (m.Name == "设备管理")
|
a = 0;
|
AddSubMenu(m, childList);
|
}
|
|
return treeList;
|
}
|
|
private void AddSubMenu(MenuTree parentMenu, List<MenuTab> list)
|
{
|
if (!string.IsNullOrEmpty(parentMenu.ChildrenId))
|
{
|
string[] strAry = parentMenu.ChildrenId.Split(',');
|
foreach (string str in strAry)
|
{
|
var sub = list.Where(s => s.menu_id == str).FirstOrDefault();
|
MenuTree menuTree = new MenuTree(sub);
|
bool isCheck = false;
|
if (roleModel.menu_id.Contains(sub.menu_id))
|
{
|
isCheck = true;
|
}
|
parentMenu.CreateTreeWithChildren(menuTree, isCheck);
|
AddSubMenu(menuTree, list);
|
}
|
}
|
else
|
{
|
if (roleModel.menu_id.Contains(parentMenu.Id))
|
parentMenu.IsChecked = true;
|
else
|
parentMenu.IsChecked = false;
|
}
|
}
|
|
private void UserControl_Loaded(object sender, RoutedEventArgs e)
|
{
|
Storyboard storyboard = new Storyboard();
|
|
DoubleAnimation doubleAnimation = new DoubleAnimation(0, 600, new Duration(TimeSpan.FromSeconds(0.25)));
|
Storyboard.SetTarget(doubleAnimation, border);//Target对象
|
Storyboard.SetTargetProperty(doubleAnimation, new PropertyPath("Width"));//Target属性
|
storyboard.Children.Add(doubleAnimation);
|
|
ObjectAnimationUsingKeyFrames showAnimation = new ObjectAnimationUsingKeyFrames();
|
showAnimation.BeginTime = TimeSpan.FromSeconds(0);
|
Storyboard.SetTarget(showAnimation, border);
|
Storyboard.SetTargetProperty(showAnimation, new PropertyPath("(UIElement.Visibility)"));
|
DiscreteObjectKeyFrame closeKeyFrame = new DiscreteObjectKeyFrame(Visibility.Visible, TimeSpan.FromSeconds(0.01));
|
showAnimation.KeyFrames.Add(closeKeyFrame);
|
storyboard.Children.Add(showAnimation);
|
|
storyboard.Begin();
|
|
if (roleModel.dataauthority == "0")
|
radioBtnSelf.IsChecked = true;
|
else
|
radioBtnAll.IsChecked = true;
|
|
comboxStatus.SelectedIndex = Convert.ToInt16(roleModel.type);
|
}
|
|
private void root_PreviewMouseDown(object sender, MouseButtonEventArgs e)
|
{
|
if (e.OriginalSource is Grid)
|
{
|
Grid grid = e.OriginalSource as Grid;
|
if (grid.Name == "root")
|
Button_Click(this, null);
|
}
|
}
|
|
private void Button_Click(object sender, RoutedEventArgs e)
|
{
|
if (EventResponseController.Instance.CanExecute() == false)
|
return;
|
|
Storyboard storyboard = new Storyboard();
|
|
DoubleAnimation doubleAnimation = new DoubleAnimation(600, 0, new Duration(TimeSpan.FromSeconds(0.25)));
|
Storyboard.SetTarget(doubleAnimation, border);//Target对象
|
Storyboard.SetTargetProperty(doubleAnimation, new PropertyPath("Width"));//Target属性
|
storyboard.Children.Add(doubleAnimation);
|
|
ObjectAnimationUsingKeyFrames showAnimation = new ObjectAnimationUsingKeyFrames();
|
showAnimation.BeginTime = TimeSpan.FromSeconds(0);
|
Storyboard.SetTarget(showAnimation, border);
|
Storyboard.SetTargetProperty(showAnimation, new PropertyPath("(UIElement.Visibility)"));
|
DiscreteObjectKeyFrame closeKeyFrame = new DiscreteObjectKeyFrame(Visibility.Collapsed, TimeSpan.FromSeconds(0.26));
|
showAnimation.KeyFrames.Add(closeKeyFrame);
|
storyboard.Children.Add(showAnimation);
|
storyboard.Completed += delegate { closeEvent?.Invoke(this, EventArgs.Empty); };
|
storyboard.Begin();
|
}
|
|
private void comboxStatus_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
{
|
if (comboxStatus.SelectedIndex < 0)
|
return;
|
roleModel.type = comboxStatus.SelectedIndex.ToString();
|
}
|
|
private void radioBtnSelf_Checked(object sender, RoutedEventArgs e)
|
{
|
if (radioBtnSelf.IsChecked == true)
|
roleModel.dataauthority = "0";
|
}
|
|
private void radioBtnAll_Checked(object sender, RoutedEventArgs e)
|
{
|
if (radioBtnAll.IsChecked == true)
|
roleModel.dataauthority = "1";
|
}
|
|
private void btnCancel_Click(object sender, RoutedEventArgs e)
|
{
|
if (EventResponseController.Instance.CanExecute() == false)
|
return;
|
Button_Click(this, null);
|
}
|
|
private void btnSave_Click(object sender, RoutedEventArgs e)
|
{
|
if (EventResponseController.Instance.CanExecute() == false)
|
return;
|
string ids = "";
|
foreach (var item in menuTrees.Children)
|
{
|
string id = GetSelectedAuthorityIDs(item);
|
if (!string.IsNullOrEmpty(id))
|
{
|
if (string.IsNullOrEmpty(ids))
|
ids = id;
|
else
|
ids += "," + id;
|
}
|
}
|
roleModel.menu_id = ids;
|
roleModel.remarks = textboxRemark.Text.Trim();
|
roleModel.modifytime = UserManagerment.currentUser.username;
|
roleModel.modifytime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
|
int model = UserDB.UpdateRoleIntodb(roleModel);//rolesBLL.Update(roleModel);
|
if (model != 0)
|
{
|
PlsToolTipWin plsToolTipWin = new PlsToolTipWin(Properties.UserResource.strModifyRoleSuccess);
|
plsToolTipWin.WindowStartupLocation = WindowStartupLocation.CenterScreen;
|
plsToolTipWin.Height = 450;
|
plsToolTipWin.Width = 600;
|
plsToolTipWin.btnCancel.Visibility = Visibility.Hidden;
|
SolidColorBrush mybtn1_Brush = new SolidColorBrush(System.Windows.Media.Color.FromArgb(0, 0, 0, 0));
|
plsToolTipWin.Background = (System.Windows.Media.Brush)mybtn1_Brush;
|
plsToolTipWin.ShowDialog();
|
}
|
else
|
{
|
PlsToolTipWin plsToolTipWin = new PlsToolTipWin(Properties.UserResource.strModifyRoleFailed);
|
plsToolTipWin.WindowStartupLocation = WindowStartupLocation.CenterScreen;
|
plsToolTipWin.Height = 450;
|
plsToolTipWin.Width = 600;
|
plsToolTipWin.btnCancel.Visibility = Visibility.Hidden;
|
SolidColorBrush mybtn1_Brush = new SolidColorBrush(System.Windows.Media.Color.FromArgb(0, 0, 0, 0));
|
plsToolTipWin.Background = (System.Windows.Media.Brush)mybtn1_Brush;
|
plsToolTipWin.ShowDialog();
|
}
|
|
ButtonOK_Click(this, null);
|
}
|
|
private string GetSelectedAuthorityIDs(MenuTree tree)
|
{
|
string ret = "";
|
if (tree.IsChecked == false)
|
return ret;
|
else
|
{
|
if (tree.Children.Count == 0)
|
{
|
if (tree.IsChecked == true)
|
{
|
ret = tree.Id;
|
return ret;
|
}
|
}
|
else
|
{
|
foreach (var item in tree.Children)
|
{
|
string id = GetSelectedAuthorityIDs(item);
|
if (!string.IsNullOrEmpty(id))
|
{
|
if (string.IsNullOrEmpty(ret))
|
ret = id;
|
else
|
ret += "," + id;
|
}
|
|
}
|
return ret;
|
}
|
}
|
return ret;
|
}
|
|
private void ButtonOK_Click(object sender, RoutedEventArgs e)
|
{
|
if (EventResponseController.Instance.CanExecute() == false)
|
return;
|
|
Storyboard storyboard = new Storyboard();
|
|
DoubleAnimation doubleAnimation = new DoubleAnimation(600, 0, new Duration(TimeSpan.FromSeconds(0.25)));
|
Storyboard.SetTarget(doubleAnimation, border);//Target对象
|
Storyboard.SetTargetProperty(doubleAnimation, new PropertyPath("Width"));//Target属性
|
storyboard.Children.Add(doubleAnimation);
|
|
ObjectAnimationUsingKeyFrames showAnimation = new ObjectAnimationUsingKeyFrames();
|
showAnimation.BeginTime = TimeSpan.FromSeconds(0);
|
Storyboard.SetTarget(showAnimation, border);
|
Storyboard.SetTargetProperty(showAnimation, new PropertyPath("(UIElement.Visibility)"));
|
DiscreteObjectKeyFrame closeKeyFrame = new DiscreteObjectKeyFrame(Visibility.Collapsed, TimeSpan.FromSeconds(0.26));
|
showAnimation.KeyFrames.Add(closeKeyFrame);
|
storyboard.Children.Add(showAnimation);
|
storyboard.Completed += delegate { saveOkEvent?.Invoke(this, EventArgs.Empty); };
|
storyboard.Begin();
|
}
|
}
|
}
|