using DevExpress.XtraBars.Navigation;
|
using DevExpress.XtraTab;
|
using System;
|
using System.Collections.Generic;
|
using System.Data;
|
using System.Drawing;
|
using System.Reflection;
|
using System.Windows.Forms;
|
using Gs.DevApp.ToolBox;
|
using Newtonsoft.Json;
|
using Gs.DevApp.Models;
|
using Newtonsoft.Json.Linq;
|
|
namespace Gs.DevApp.DevFrm
|
{
|
public partial class FrmMain : DevExpress.XtraBars.FluentDesignSystem.FluentDesignForm
|
{
|
private static Dictionary<string, XtraTabPage> TabPageDic = new Dictionary<string, XtraTabPage>();
|
public FrmMain()
|
{
|
InitializeComponent();
|
this.Text = System.Configuration.ConfigurationSettings.AppSettings.Get("ProductName").ToString();
|
tab.CloseButtonClick += Tab_CloseButtonClick;
|
tooLoading.Click += TooLoading_Click;
|
getTree();
|
}
|
/// <summary>
|
/// 重新加载系统
|
/// </summary>
|
/// <param name="sender"></param>
|
/// <param name="e"></param>
|
private void TooLoading_Click(object sender, EventArgs e)
|
{
|
int i = 100;
|
Gs.DevApp.UserControl.ShowDialogForm sdf = new Gs.DevApp.UserControl.ShowDialogForm("提示", "", "请耐心等候,正在操作中!");
|
for (int j = 0; j < i; j++)
|
{
|
sdf.SetCaption("执行进度(" + (j) + "/" + i.ToString() + ")");
|
}
|
sdf.Close();
|
getTree();
|
}
|
private void getTree()
|
{
|
toolTime.Text = "登录时间" + LoginInfoModel.CurrentUser.LoginTime;
|
var _obj = new
|
{
|
userGuid = LoginInfoModel.CurrentUser.LoginUserGuid,
|
orgGuid = LoginInfoModel.CurrentUser.LoginOrgGuid,
|
};
|
try
|
{
|
string strJson = UtilityHelper.HttpPost("", "User/GetUserLoginInfo", JsonConvert.SerializeObject(_obj));
|
JObject _job = JObject.Parse(strJson);
|
string rtnCode = _job["rtnCode"].ToString();
|
if (int.Parse(rtnCode) > 0)
|
{
|
this.acrd.Clear();
|
barMsg.Caption = _job["rtnData"]["loginMsg"].ToString();
|
JArray array = new JArray();
|
var d = _job["rtnData"]["list"];
|
foreach (var a in d)
|
{
|
array.Add(a);
|
}
|
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FrmMain));
|
DataTable dt = JsonConvert.DeserializeObject<DataTable>(array.ToString());
|
DataRow[] drGrp = dt.Select("upGuid is null");
|
int gdx = 0, idx = 0;
|
foreach (DataRow _dy in drGrp)
|
{
|
AccordionControlElement _grp = this.acrd.AddGroup();
|
_grp.ImageOptions.Image = UtilityHelper.GetImgFromResource(_dy["icon"].ToString(), 1);
|
_grp.Name = _dy["guid"].ToString();
|
_grp.Style = DevExpress.XtraBars.Navigation.ElementStyle.Group;
|
_grp.Text = _dy["name"].ToString();
|
_grp.Tag = _dy["formPath"].ToString();//存路径,类名
|
_grp.Click += _grp_Click;
|
if (gdx == 0)
|
_grp.Expanded = true;
|
DataRow[] drItem = dt.Select("upGuid='" + _dy["guid"].ToString() + "'");
|
foreach (DataRow _dy2 in drItem)
|
{
|
AccordionControlElement _itm = this.acrd.AddItem();
|
_itm.ImageOptions.Image = UtilityHelper.GetImgFromResource(_dy2["icon"].ToString(), 2);
|
_itm.Name = _dy2["guid"].ToString();
|
_itm.Style = DevExpress.XtraBars.Navigation.ElementStyle.Item;
|
_itm.Text = _dy2["name"].ToString();
|
_itm.Appearance.Normal.Font = new System.Drawing.Font("Tahoma", 10F);
|
_itm.Tag = _dy2["formPath"].ToString();//存路径,类名
|
_itm.Click += _grp_Click;
|
_grp.Elements.Add(_itm);
|
if (idx == 0 && tab.TabPages.Count <= 0)
|
{
|
string tabPageName = _itm.Name + "_page";
|
string tabText = _itm.Text;//当前选项卡页Text标题
|
string newFormName = _itm.Tag.ToString();//存路径,类名
|
Image imgIcon = _itm.Image;
|
AddTabpage(tab, tabPageName, tabText, newFormName, imgIcon);
|
}
|
idx++;
|
};
|
gdx++;
|
}
|
}
|
else
|
{
|
ToolBox.MsgHelper.ShowError("提示:初始化失败,请联系管理员!");
|
}
|
}
|
catch (Exception ex)
|
{
|
ToolBox.MsgHelper.ShowError("提示:" + ex.Message);
|
}
|
}
|
/// <summary>
|
/// 左侧菜单点击
|
/// </summary>
|
/// <param name="sender"></param>
|
/// <param name="e"></param>
|
private void _grp_Click(object sender, EventArgs e)
|
{
|
AccordionControlElement _acd = (AccordionControlElement)sender;
|
if (_acd.Elements.Count > 0) return;
|
string tabPageName = _acd.Name + "_page";
|
string tabText = _acd.Text;
|
string newFormName = _acd.Tag.ToString();
|
Image imgIcon = _acd.Image;
|
AddTabpage(tab, tabPageName, tabText, newFormName, imgIcon);
|
}
|
|
/// <summary>
|
/// 关闭选项卡
|
/// </summary>
|
/// <param name="sender"></param>
|
/// <param name="e"></param>
|
private void Tab_CloseButtonClick(object sender, EventArgs e)
|
{
|
RemoveTabPage(tab, e);
|
}
|
/// <summary>
|
/// 新增选项卡页
|
/// </summary>
|
/// <param name="tabControl">选项卡控件</param>
|
/// <param name="tabPageName">当期选项卡页name名称</param>
|
/// <param name="tabText">当前选项卡页Text标题</param>
|
/// <param name="newFormName">当前选项卡中的新窗体路径,类名</param>
|
public void AddTabpage(XtraTabControl tabControl, string tabPageName, string tabText, string newFormName, Image imgIcon)
|
{
|
if (IsTabpageExsit(tabControl, tabPageName))
|
{
|
return;
|
}
|
XtraTabPage newPage = new XtraTabPage();
|
newPage.Name = tabPageName;
|
newPage.Text = tabText;
|
newPage.Tooltip = newPage.Name;
|
newPage.Appearance.Header.Font = (tab.Appearance.Font);
|
newPage.ImageOptions.Image = imgIcon;
|
Form fm = AddNewForm(newFormName);
|
if (fm != null)
|
{
|
newPage.Controls.Add(fm);
|
tabControl.TabPages.Add(newPage);
|
TabPageDic.Add(tabPageName, newPage);
|
tabControl.SelectedTabPage = newPage;
|
}
|
}
|
|
/// <summary>
|
/// 移除选项卡页
|
/// </summary>
|
/// <param name="tabControl"></param>
|
/// <param name="tabPageName"></param>
|
/// <param name="e"></param>
|
public void RemoveTabPage(XtraTabControl tabControl, EventArgs e)
|
{
|
if (TabPageDic.Count <= 1)
|
{
|
ToolBox.MsgHelper.Warning("请至少保留一个功能!");
|
return;
|
}
|
DevExpress.XtraTab.ViewInfo.ClosePageButtonEventArgs args = (DevExpress.XtraTab.ViewInfo.ClosePageButtonEventArgs)e;
|
string name = args.Page.Tooltip;
|
foreach (XtraTabPage item in tabControl.TabPages)
|
{
|
if (item.Name == name)
|
{
|
tabControl.TabPages.Remove(item);
|
item.Dispose();
|
TabPageDic.Remove(name);
|
return;
|
}
|
}
|
}
|
|
/// <summary>
|
/// 判断选项卡是否已经存在
|
/// </summary>
|
/// <param name="tabControl">选项卡控件</param>
|
/// <param name="tabPageName">选项卡名称</param>
|
/// <returns></returns>
|
private bool IsTabpageExsit(XtraTabControl tabControl, string tabPageName)
|
{
|
foreach (var item in TabPageDic)
|
{
|
if (item.Key == tabPageName)
|
{
|
tabControl.SelectedTabPage = item.Value;
|
return true;
|
}
|
}
|
return false;
|
}
|
|
/// <summary>
|
/// 在选项卡中生成窗体
|
/// </summary>
|
/// <param name="form">窗体名称</param>
|
private Form AddNewForm(string formName)
|
{
|
try
|
{
|
Form newForm = (Form)Assembly.GetExecutingAssembly().CreateInstance(formName);
|
if (newForm == null)
|
{
|
Gs.DevApp.ToolBox.MsgHelper.ShowError("请检查是否开通了该模块!");
|
return null;
|
}
|
newForm.FormBorderStyle = FormBorderStyle.None;
|
newForm.TopLevel = false;
|
newForm.ControlBox = false;
|
newForm.Dock = DockStyle.Fill;
|
newForm.Visible = true;
|
return newForm;
|
}
|
catch (Exception)
|
{
|
Gs.DevApp.ToolBox.MsgHelper.ShowError("请检查是否开通了该模块!");
|
}
|
return null;
|
}
|
}
|
}
|