using System;
using System.Collections.Generic;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using UAS_MES_NEW.DataOperate;
using UAS_MES_NEW.Entity;
using DevExpress.XtraNavBar;
using System.Collections;
using System.Reflection;
namespace UAS_MES_NEW.CustomControl.AccordionMenu
{
public partial class NavagationBar : NavBarControl
{
StringBuilder sql = new StringBuilder();
public static int WinIndex = 0;
///
/// 记录当前功能面板中的按钮
///
private ArrayList ArrFunButton = new ArrayList();
///
/// 记录当前功能面板中的listview
///
private ArrayList ArrFunListView = new ArrayList();
///
/// 已经打开的Form
///
public static Dictionary OpenedFormName = new Dictionary();
public NavagationBar()
{
InitializeComponent();
DataHelper dh = SystemInf.dh;
if (dh == null)
return;
if (User.UserAccountType == "admin")
{
sql.Clear();
sql.Append("select distinct sn_id,sn_detno,sn_module,sn_modulecode,sn_classname,sn_displayname,sn_caller ugp_caller,1 ugp_ifdelete,1 ugp_ifread,1 ugp_ifspecial,1 ugp_ifall,");
sql.Append("1 ugp_ifwrite from CS$SYSNAVATION left join CS$USERGROUPPOWER on sn_caller=ugp_caller where sn_using=1 order by sn_modulecode,sn_detno");
}
else
{
sql.Clear();
sql.Append("select sn_id,sn_detno,sn_module,sn_displayname,sn_modulecode,sn_classname,ugp_caller,max(ugp_ifdelete)ugp_ifdelete,max(ugp_ifread)ugp_ifread");
sql.Append(",max(ugp_ifspecial)ugp_ifspecial,max(ugp_ifwrite)ugp_ifwrite,max(ugp_ifall)ugp_ifall from CS$USERGROUPPOWER ");
sql.Append("left join CS$SYSNAVATION on sn_caller=ugp_caller where sn_using=1 and ugp_groupcode in ( select eg_groupcode from cs$empgroup ");
sql.Append("left join cs$userresource on ur_groupcode = eg_groupcode where eg_emcode = '" + User.UserCode + "') and (nvl(ugp_ifread,0)<>0 or nvl(ugp_ifall,0)<>0) group by sn_id,sn_caller,sn_detno,sn_modulecode,sn_classname,sn_module,sn_displayname,ugp_caller order by sn_modulecode,sn_detno");
}
DataTable dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
if (dt.Rows.Count == 0 && User.UserAccountType != "admin")
{
return;
}
for (int i = 0; i < dt.Rows.Count; i++)
{
bool ContainGroup = false;
string module_name = dt.Rows[i]["sn_module"].ToString();
string caller = dt.Rows[i]["sn_displayname"].ToString();
NavBarItem nbi = new NavBarItem(caller);
nbi.Tag = dt.Rows[i]["sn_classname"].ToString();
nbi.LinkClicked += Nbi_LinkClicked;
nbi.Tag = dt.Rows[i]["sn_classname"].ToString();
nbi.Hint = dt.Rows[i]["ugp_caller"].ToString();
nbi.Name = dt.Rows[i]["sn_id"].ToString();
for (int j = 0; j < Groups.Count; j++)
{
if (Groups[j].Caption == module_name)
{
ContainGroup = true;
if (dt.Rows[i]["ugp_ifread"].ToString() != "0" || dt.Rows[i]["ugp_ifall"].ToString() != "0")
{
Groups[j].ItemLinks.Add(nbi);
}
}
else
{
ContainGroup = false;
}
}
if (!ContainGroup)
{
NavBarGroup nbg = new NavBarGroup(module_name);
//如果加载Icon失败则加载默认图片
try
{
nbg.LargeImage = new Bitmap(@Application.StartupPath + "/Resources/" + dt.Rows[i]["sn_module"].ToString() + ".png");
}
catch (Exception)
{
try
{
nbg.LargeImage = new Bitmap(@Application.StartupPath + "/Resources/defaulticon.png");
}
catch (Exception)
{
nbg.ImageUri = null;
}
}
Groups.Add(nbg);
nbg.ItemLinks.Add(nbi);
}
}
//查询出的用户可见的Caller
//将查询出的数据添加到队列中
for (int i = 0; i < dt.Rows.Count; i++)
{
//添加权限
Dictionary dic = new Dictionary();
dic.Add("IFDELETE", dt.Rows[i]["UGP_IFDELETE"].ToString() != "1" ? false : true);
dic.Add("IFREAD", dt.Rows[i]["UGP_IFREAD"].ToString() != "1" ? false : true);
dic.Add("IFWRITE", dt.Rows[i]["UGP_IFWRITE"].ToString() != "1" ? false : true);
dic.Add("IFSPECIAL", dt.Rows[i]["UGP_IFSPECIAL"].ToString() != "1" ? false : true);
dic.Add("IFALL", dt.Rows[i]["UGP_IFALL"].ToString() != "1" ? false : true);
//之后通过Call来获取页面操作的权限
if (SystemInf.Caller.ContainsKey(dt.Rows[i]["ugp_caller"].ToString()))
{
SystemInf.Caller.Remove(dt.Rows[i]["ugp_caller"].ToString());
}
SystemInf.Caller.Add(dt.Rows[i]["ugp_caller"].ToString(), dic);
}
}
private void Nbi_LinkClicked(object sender, NavBarLinkEventArgs e)
{
NavBarItem nbi = (sender as NavBarItem);
Form OpenForm = (Form)Assembly.GetExecutingAssembly().CreateInstance("UAS_MES_NEW." + nbi.Tag.ToString());
OpenForm.Dock = DockStyle.Fill;
OpenForm.Text = nbi.Caption;
//用Tag保存Caller
OpenForm.Tag = nbi.Hint;
TabControl tc = (TabControl)this.Parent.Controls["MainTabControl"];
//如果窗体不存在进行打开,item.ToolTip是Caller
if (!OpenedFormName.ContainsKey(nbi.Hint))
{
TabPage tb = new TabPage { Name = nbi.Name, Tag = nbi.Hint, Text = OpenForm.Text };
OpenForm.TopLevel = false;
tc.TabPages.Add(tb);
//直接选中新打开的界面
tc.SelectedTab = tb;
tb.Controls.Add(OpenForm);
OpenedFormName.Add(nbi.Hint, WinIndex);
tc.TabIndex = WinIndex;
WinIndex++;
OpenForm.Show();
}
//如果窗体已存在展示该窗体
else
tc.SelectTab(nbi.Name);
}
}
}