You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
232 lines
9.3 KiB
232 lines
9.3 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Input;
|
|
using System.Windows.Media.Imaging;
|
|
using AvalonDock;
|
|
using Fluent;
|
|
using SSWMS.Common;
|
|
|
|
namespace SSWMS.Client
|
|
{
|
|
public partial class MainWindow : RibbonWindow
|
|
{
|
|
public static MainWindow mainWin;
|
|
private IList<SYS_MENU> listSYS_MENU = null;
|
|
|
|
public MainWindow()
|
|
{
|
|
InitializeComponent();
|
|
Application.Current.MainWindow = this;
|
|
mainWin = this;
|
|
MainWindow_Loaded(null, null);
|
|
}
|
|
|
|
private void MainWindow_Loaded(object sender, RoutedEventArgs e)
|
|
{
|
|
MainWindow.mainWin.Cursor = Cursors.Wait;
|
|
string sRole = string.Empty;
|
|
foreach (SYS_ROLE sr in MainApp._lRole)
|
|
{
|
|
sRole += sr.ROLE_NAME + " ";
|
|
}
|
|
this.sbitemNote.Content = string.Format(
|
|
Application.Current.FindResource("Status").ToString(),
|
|
MainApp._USER.USER_NAME, sRole);
|
|
this.listSYS_MENU = WCFChannel._I_SystemService.GetSystemMenuByUserID(MainApp._USER.USER_ID);
|
|
InitMenu();
|
|
InvorkStartWindow();
|
|
MainWindow.mainWin.Cursor = Cursors.Arrow;
|
|
}
|
|
|
|
private void InvorkStartWindow()
|
|
{
|
|
try
|
|
{
|
|
SYS_MENU menu = WCFChannel._I_SystemService.GetSystemMenu(MainApp._lRole[0].ROLE_START_MENU_ID);
|
|
if (menu != null && menu.MENU_IS_PARENT == SystemCode.FLAG.Disable &&
|
|
menu.MENU_FLAG == SystemCode.FLAG.Enable)
|
|
{
|
|
DynamicCode.DicDynamicMenu[menu.MENU_PARAMETER](menu.MENU_NAME);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageDialog.ShowException(ex);
|
|
}
|
|
}
|
|
|
|
public void ActivateForm(Type type, string winTitle, object[] arParaObj)
|
|
{
|
|
string sResult = string.Empty;
|
|
ActivateForm(type, winTitle, arParaObj, out sResult);
|
|
}
|
|
|
|
public bool ActivateForm(Type type, string winTitle, object[] arParaObj, out string sResult)
|
|
{
|
|
try
|
|
{
|
|
MainWindow.mainWin.Cursor = Cursors.Wait;
|
|
ManagedContentCollection<DocumentContent> cnts = this.DockManager.Documents;
|
|
if (cnts.Count(r => r.Title == winTitle) > 0)
|
|
{
|
|
cnts.First(r => r.Title == winTitle).Activate();
|
|
}
|
|
else
|
|
{
|
|
DocumentContent newContent = (DocumentContent)Activator.CreateInstance(type, arParaObj);
|
|
if (newContent != null)
|
|
{
|
|
newContent.Title = winTitle;
|
|
newContent.Show(DockManager, false);
|
|
newContent.Activate();
|
|
}
|
|
}
|
|
MainWindow.mainWin.Cursor = Cursors.Arrow;
|
|
sResult = string.Empty;
|
|
return true;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
sResult = ex.Message;
|
|
MainWindow.mainWin.Cursor = Cursors.Arrow;
|
|
MessageDialog.ShowException(ex);
|
|
return false;
|
|
}
|
|
}
|
|
|
|
private void MainWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e)
|
|
{
|
|
if (!MessageDialog.ShowDialog("确认退出系统"))
|
|
{
|
|
e.Cancel = true;
|
|
}
|
|
}
|
|
|
|
private void MainWindow_Closed(object sender, EventArgs e)
|
|
{
|
|
MainApp.Current.Shutdown();
|
|
}
|
|
|
|
private void InitMenu()
|
|
{
|
|
foreach (SYS_MENU sm in listSYS_MENU.Where(r => r.MENU_PARENT_ID == 0).OrderBy(r => r.MENU_ORDER))
|
|
{
|
|
RibbonTabItem rti = new RibbonTabItem
|
|
{
|
|
Name = string.Format("RibbonTab{0}", sm.MENU_ID),
|
|
Header = sm.MENU_NAME,
|
|
ToolTip = sm.MENU_NAME,
|
|
Tag = sm.MENU_ID,
|
|
FontFamily = new System.Windows.Media.FontFamily("Microsoft YaHei"),
|
|
FontSize = 13,
|
|
Width = 100
|
|
};
|
|
InitMenuTab(rti);
|
|
if (((sm.MENU_ID == 2 && MainApp._USER.USER_ID == 0)
|
|
|| sm.MENU_ID > 2) && rti.Groups.Count > 0)
|
|
{
|
|
this.ribbon.Tabs.Add(rti);
|
|
}
|
|
}
|
|
}
|
|
|
|
private void InitMenuTab(RibbonTabItem tab)
|
|
{
|
|
int iParentID = Convert.ToInt32(tab.Tag);
|
|
IEnumerable<SYS_MENU> lMenuChildren = null;
|
|
RibbonGroupBox rgb = new RibbonGroupBox();
|
|
foreach (SYS_MENU smParent in listSYS_MENU.Where(r => r.MENU_PARENT_ID == iParentID).OrderBy(r => r.MENU_ORDER))
|
|
{
|
|
lMenuChildren = listSYS_MENU.Where(r => r.MENU_PARENT_ID == smParent.MENU_ID).OrderBy(r => r.MENU_ORDER);
|
|
if (lMenuChildren != null && lMenuChildren.Count() > 0)
|
|
{
|
|
DropDownButton ddb = new DropDownButton
|
|
{
|
|
Name = string.Format("RibbonMenuItem{0}", smParent.MENU_ID),
|
|
Header = smParent.MENU_NAME,
|
|
ToolTip = smParent.MENU_NAME,
|
|
LargeIcon = new BitmapImage(new Uri(string.Format("/@Images/{0}", string.IsNullOrEmpty(smParent.MENU_IMAGE) ? "role.png" : smParent.MENU_IMAGE), UriKind.RelativeOrAbsolute)),
|
|
Icon = new BitmapImage(new Uri(string.Format("/@Images/{0}", string.IsNullOrEmpty(smParent.MENU_IMAGE) ? "role.png" : smParent.MENU_IMAGE), UriKind.RelativeOrAbsolute)),
|
|
Tag = smParent.MENU_PARAMETER,
|
|
FontFamily = new System.Windows.Media.FontFamily("Microsoft YaHei"),
|
|
FontSize = 13,
|
|
Margin = new Thickness(10, 0, 10, 0)
|
|
};
|
|
foreach (SYS_MENU smChild in lMenuChildren)
|
|
{
|
|
Fluent.MenuItem mi = new Fluent.MenuItem
|
|
{
|
|
Name = string.Format("RibbonMenuButton{0}", smChild.MENU_ID),
|
|
Header = smChild.MENU_NAME,
|
|
ToolTip = smChild.MENU_NAME,
|
|
Tag = smChild.MENU_PARAMETER,
|
|
FontFamily = new System.Windows.Media.FontFamily("Microsoft YaHei"),
|
|
FontSize = 13
|
|
};
|
|
mi.Click += new RoutedEventHandler(menuBtn_Click);
|
|
ddb.Items.Add(mi);
|
|
}
|
|
rgb.Items.Add(ddb);
|
|
}
|
|
else
|
|
{
|
|
if (!string.IsNullOrWhiteSpace(smParent.MENU_PARAMETER))
|
|
{
|
|
Fluent.Button b = new Fluent.Button
|
|
{
|
|
Name = string.Format("RibbonButton{0}", smParent.MENU_ID),
|
|
Header = smParent.MENU_NAME,
|
|
ToolTip = smParent.MENU_NAME,
|
|
LargeIcon = new BitmapImage(new Uri(string.Format("/@Images/{0}", string.IsNullOrEmpty(smParent.MENU_IMAGE) ? "role.png" : smParent.MENU_IMAGE), UriKind.RelativeOrAbsolute)),
|
|
Icon = new BitmapImage(new Uri(string.Format("/@Images/{0}", string.IsNullOrEmpty(smParent.MENU_IMAGE) ? "role.png" : smParent.MENU_IMAGE), UriKind.RelativeOrAbsolute)),
|
|
Tag = smParent.MENU_PARAMETER,
|
|
FontFamily = new System.Windows.Media.FontFamily("Microsoft YaHei"),
|
|
FontSize = 13,
|
|
Margin = new Thickness(10, 0, 10, 0)
|
|
};
|
|
b.Click += new RoutedEventHandler(menuBtn_Click);
|
|
if (smParent.MENU_PARENT_ID == 1)
|
|
{
|
|
this.ribbon.QuickAccessItems.Add(new QuickAccessMenuItem
|
|
{
|
|
Target = b,
|
|
IsChecked = true,
|
|
HorizontalContentAlignment = HorizontalAlignment.Stretch
|
|
});
|
|
}
|
|
else
|
|
{
|
|
rgb.Items.Add(b);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if (rgb.Items.Count > 0)
|
|
{
|
|
tab.Groups.Add(rgb);
|
|
}
|
|
}
|
|
|
|
private void menuBtn_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
try
|
|
{
|
|
MainWindow.mainWin.Cursor = Cursors.Wait;
|
|
Control c = sender as Control;
|
|
if (c != null)
|
|
{
|
|
DynamicCode.DicDynamicMenu[c.Tag.ToString()](c.ToolTip.ToString());
|
|
}
|
|
MainWindow.mainWin.Cursor = Cursors.Arrow;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MainWindow.mainWin.Cursor = Cursors.Arrow;
|
|
MessageDialog.ShowException(ex);
|
|
}
|
|
}
|
|
}
|
|
}
|