using CommonLib; using CommonLib.utils; using ControlLib.com; using ControlLib.inh; using DevExpress.XtraEditors; using DevExpress.XtraTab; using Lskj.Main.Properties; using System; using System.Collections; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Data.SqlClient; using System.Drawing; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; using System.Windows; using System.Diagnostics; using Lskj.Main.sub; using Lskj.MyControl; using Lskj.Common; using DevExpress.XtraEditors.Controls; using Lskj.Main.main2; using System.Net; namespace Lskj.Main { public partial class FrmMain2 : Form { #region 属性 // 生成地址 private bool m_isMouseDown = false;//窗体是否移动 private Point m_mousePos;//记录窗体的位置 private string qxCond; private int MainMenuType = 1; // 1.顶部菜单显示为当前菜单,2.顶部菜单显示为所有子系统 private IntPtr m_ClientTestHandle = IntPtr.Zero; private XtraTabPage CurrentPage = new XtraTabPage(); //存放当前选中tabpage private string ConfigMenuVisible = ""; private float dpiX, dpiY; private string topTitle = string.Empty; private Button lastMenuButton; // 上次点击的button private ToolStripMenuItem lastMenuItem; // 上次点击的Item private ToolStripMenuItem firstMenuItem; // 第一个menuItem private TreeViewCustom.ButtonClickEventHandler clickEvent = null; private DataTable dtAllMenus = new DataTable(); // 菜单数据缓存 private DataTable dtSubMenus = new DataTable(); // 缓存当前选中的子系统数据 private Dictionary> dicMenus = new Dictionary>(); // 缓存菜单控件 private DataTable dtDesktop = new DataTable(); // 我的桌面数据 private Dictionary dicGrids = new Dictionary(); #endregion #region 构造函数 public FrmMain2() { Graphics graphics = this.CreateGraphics(); dpiX = graphics.DpiX; dpiY = graphics.DpiY; InitializeComponent(); this.MaximumSize = new Size(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height); } #endregion #region 窗体初始化 private void FrmMain_Load(object sender, EventArgs e) { pl_top_left.BackgroundImage = BitMapHelper.getBitmap(BitMapEnum.logo2bg); ConfigMenuVisible = ""; string tmpsql = "select 1 from sys.columns where object_id=object_id('P_FormMenuConfigTab') and name='useFlag'"; object rlt = SqlHelper.ExecuteScalar(CommandType.Text, tmpsql); if (rlt + "" == "1") ConfigMenuVisible = " and isnull(useFlag,0)=1"; this.tsmi_time.Alignment = ToolStripItemAlignment.Right; this.tsmi_split.Alignment = ToolStripItemAlignment.Right; this.tsmi_time.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); this.lbUserName.Text = ERPInfo.Instance.EmployeeName; this.tsslUserName.Text = "用户名:" + ERPInfo.Instance.EmployeeName; this.TabMain.HeaderButtons = ((DevExpress.XtraTab.TabButtons)((((DevExpress.XtraTab.TabButtons.Prev | DevExpress.XtraTab.TabButtons.Next) | DevExpress.XtraTab.TabButtons.Close) | DevExpress.XtraTab.TabButtons.Default))); this.TabMain.HeaderButtonsShowMode = DevExpress.XtraTab.TabButtonShowMode.Always; this.timer1.Start(); this.calcPanelWidth(); this.setMenuStripColor(Color.Gray); this.lblSubTitle.Focus(); LoadSystemConfig(); if (MainMenuType > 2) qxCond = getQxCond(); menuSearch.searcherPropertyCollector.SQL = "SELECT MenuId,MenuCaption+'-'+b.SubSysName as MenuCaption FROM P_FormMenuConfigTab a\n" + "INNER JOIN P_SubSystemTab b ON a.SubSysId=b.SubSysId\n" + "WHERE ISNULL(b.UseEd,0)=1 and isnull(DllFileName,'')<>'' " + qxCond + ConfigMenuVisible; menuSearch.searcherPropertyCollector.QuerySQL = menuSearch.searcherPropertyCollector.SQL; this.initMainData(); new Thread(SetHostEntry).Start(); } private bool LoadSystemConfig() { bool Result = false; try { string strSql = string.Format("select * from p_systemtab "); DataTable dtTable = SqlHelper.ExecuteDataTable(strSql); if (dtTable.Rows.Count > 0) { DataRow dr = dtTable.Rows[0]; string ShortcutDll = (dr["ShortcutDll"] + "").Trim(); lblShortcutset.Tag = ShortcutDll; string OperatorNameDll = (dr["OperatorNameDll"] + "").Trim(); lbUserName.Tag = OperatorNameDll; Result = bool.Parse(dr["UseCustomTitleBar"] + ""); MainMenuType = Convert.ToInt32(dr["MainMenuType"]); topTitle = (dtTable.Columns.Contains("topName")) ? dr["topName"] + "" : dr["ClientName"] + ""; this.tslCompany.Text = dr["ClientName"] + ""; this.lblSubTitle.Text = topTitle; } } catch (Exception ex) { PubUtil.WriteError("读取系统配置出错!", ex.Message); MessageBox.Show("读取系统配置出错!"); } return Result; } /// /// 检查是否配置我的桌面 /// /// private bool CheckDesktopConfig() { try { string sqlValue = string.Format("select 1 from P_SystemDesktopTab where 1<>1"); SqlHelper.ExecuteDataSet(sqlValue); return true; } catch (Exception ex) { } return false; } private string getQxCond() { // string Result = ""; // string qxCols = ""; // string strSql = "select name from sys.columns where object_id=object_id('p_SubsysPurviewTab') and name like '%purview'"; // try // { // DataTable dt = SqlHelper.ExecuteDataSet(strSql).Tables[0]; // foreach (DataRow dr in dt.Rows) // { // if (qxCols == "") // qxCols = "','+isnull(" + dr["name"].ToString() + ",'')+','"; // else // qxCols = qxCols + "+','+isnull(" + dr["name"].ToString() + ",'')+','"; // } // if (qxCols == "") // qxCols = @"','+isnull([KcPurview],'')+','+isnull([crmPurview],'')+','+isnull([bomPurview],'')+','+ // isnull([mrpPurview],'')+','+isnull([scmPurview],'')+','+isnull([sellPurview],'')+','+ // isnull([RdmPurview],'')+','+isnull([hrPurview],'')+','+isnull([costPurview],'')+','+ // isnull([eamPurview],'')+','+isnull([FmPurview],'')+','+isnull([oaPurview],'')+','+ // isnull([BiPurview],'')+','+isnull([QmsPurview],'')+','"; // else // qxCols = "','+" + qxCols; // Result = @"and (CHARINDEX(','+CAST(menuid as varchar)+',',(select top 1 // " + qxCols + @" // from [p_SubsysPurviewTab] // where employeeid=" + ERPInfo.Instance.EmployeeId.ToString() + "))>0 "+ // @" or CHARINDEX(','+CAST(menuid as varchar)+'|,',(select top 1 // " + qxCols + @" // from [p_SubsysPurviewTab] // where employeeid=" + ERPInfo.Instance.EmployeeId.ToString() + "))>0 "+ // "or len(menustruct)=2 or " + ERPInfo.Instance.EmployeeId.ToString() + "=1 or '" + ERPInfo.Instance.EmployeeName.ToString() + "'='管理员')"; // return Result; // } // catch (Exception ex) // { // PubUtil.WriteError("读取系统配置出错!", ex.Message); // MessageBox.Show("读取系统配置出错!"); // return ""; // } string Result = ""; string qxCols = ""; string qxCols1 = ""; string strSql = "select name from sys.columns where object_id=object_id('p_SubsysPurviewTab') and name like '%purview'"; try { DataTable dt = SqlHelper.ExecuteDataSet(strSql).Tables[0]; foreach (DataRow dr in dt.Rows) { if (qxCols == "") { qxCols = "','+isnull(" + dr["name"].ToString() + ",'')+','"; qxCols1 = "','+isnull(" + dr["name"].ToString() + ",'')+'|,'"; } else { qxCols = qxCols + "+','+isnull(" + dr["name"].ToString() + ",'')+','"; qxCols1 = qxCols1 + "+','+isnull(" + dr["name"].ToString() + ",'')+'|,'"; } } if (qxCols == "") { qxCols = @"','+isnull([KcPurview],'')+','+isnull([crmPurview],'')+','+isnull([bomPurview],'')+','+ isnull([mrpPurview],'')+','+isnull([scmPurview],'')+','+isnull([sellPurview],'')+','+ isnull([RdmPurview],'')+','+isnull([hrPurview],'')+','+isnull([costPurview],'')+','+ isnull([eamPurview],'')+','+isnull([FmPurview],'')+','+isnull([oaPurview],'')+','+ isnull([BiPurview],'')+','+isnull([QmsPurview],'')+','"; qxCols1 = @"','+isnull([KcPurview],'')+'|,'+isnull([crmPurview],'')+'|,'+isnull([bomPurview],'')+'|,'+ isnull([mrpPurview],'')+'|,'+isnull([scmPurview],'')+'|,'+isnull([sellPurview],'')+'|,'+ isnull([RdmPurview],'')+'|,'+isnull([hrPurview],'')+'|,'+isnull([costPurview],'')+'|,'+ isnull([eamPurview],'')+'|,'+isnull([FmPurview],'')+'|,'+isnull([oaPurview],'')+'|,'+ isnull([BiPurview],'')+',|'+isnull([QmsPurview],'')+'|,'"; } else { qxCols = "','+" + qxCols; qxCols1 = "','+" + qxCols1; } // Result = @"and (CHARINDEX(CAST(menuid as varchar)+',',(select top 1 // " + qxCols + @" // from [p_SubsysPurviewTab] // where employeeid=" + ERPInfo.Instance.EmployeeId.ToString() + "))>0 or len(menustruct)=2 or " + ERPInfo.Instance.EmployeeId.ToString() + "=1 or '" + ERPInfo.Instance.EmployeeName.ToString() + "'='管理员') "; Result = @"and (CHARINDEX(','+CAST(menuid as varchar)+',',(select top 1 " + qxCols + @" from [p_SubsysPurviewTab] where employeeid=" + ERPInfo.Instance.EmployeeId.ToString() + "))>0 " + @" or CHARINDEX(','+CAST(menuid as varchar)+'|,',(select top 1 " + qxCols1 + @" from [p_SubsysPurviewTab] where employeeid=" + ERPInfo.Instance.EmployeeId.ToString() + "))>0 " + "or len(menustruct)=2 or " + ERPInfo.Instance.EmployeeId.ToString() + "=1 or '" + ERPInfo.Instance.EmployeeName.ToString() + "'='管理员')"; return Result; } catch (Exception ex) { PubUtil.WriteError("读取系统配置出错!", ex.Message); MessageBox.Show("读取系统配置出错!"); return ""; } } /// /// 初始化系统DNS字段 /// private void InitHostEntryField() { try { // 创建DNS字段 string sqlValue = "alter table p_systemtab add DnsHostEntry varchar(50)"; int result = SqlHelper.ExecuteNonQuery(sqlValue); sqlValue = "update p_systemtab set DnsHostEntry = InternetIP"; result = SqlHelper.ExecuteNonQuery(sqlValue); } catch (Exception) { } } /// /// 解析DNS /// private void SetHostEntry() { try { this.InitHostEntryField(); string sqlValue = "select DnsHostEntry from p_systemtab"; DataTable dtTable = SqlHelper.ExecuteDataTable(sqlValue); if (dtTable != null && dtTable.Rows.Count > 0) { string dnsHostEntry = dtTable.Rows[0]["DnsHostEntry"] + ""; if (!string.IsNullOrWhiteSpace(dnsHostEntry)) { string ipAddress = Dns.GetHostEntry(dnsHostEntry).AddressList[0] + ""; sqlValue = string.Format("update p_systemtab set InternetIP = '{0}'", ipAddress); int result = SqlHelper.ExecuteNonQuery(sqlValue); } } } catch (Exception) { } } #endregion #region 窗口关闭 private void btnClose_Click(object sender, EventArgs e) { try { if (ERPInfo.Instance.SubCount == 1) { if (XtraMessageBox.Show("确定退出系统吗?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { return; } this.Close(); //Process[] p = Process.GetProcessesByName("Ls_ERP"); //foreach (Process item in p) // item.Kill(); } else { PubUtil.ModuleForms.Clear(); this.Close(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } private void btnClose_MouseLeave(object sender, EventArgs e) { btnClose.BackgroundImage = Resources.close_default; } private void btnClose_MouseMove(object sender, MouseEventArgs e) { btnClose.BackgroundImage = Resources.close_select; } #endregion #region 窗口最大化 private void btnMax_Click(object sender, EventArgs e) { this.WindowState = this.WindowState == FormWindowState.Normal ? FormWindowState.Maximized : FormWindowState.Normal; btnMax.BackgroundImage = this.WindowState == FormWindowState.Normal ? Resources.max_default : Resources.window_default; this.calcPanelWidth(); } private void btnMax_MouseLeave(object sender, EventArgs e) { if (this.WindowState == FormWindowState.Normal) { btnMax.BackgroundImage = Resources.max_default; } else { btnMax.BackgroundImage = Resources.window_default; } } private void btnMax_MouseMove(object sender, MouseEventArgs e) { if (this.WindowState == FormWindowState.Normal) { btnMax.BackgroundImage = Resources.max_select; } else { btnMax.BackgroundImage = Resources.window_select; } } #endregion #region 窗口最小化 private void btnMin_Click(object sender, EventArgs e) { this.WindowState = FormWindowState.Minimized; } private void btnMin_MouseLeave(object sender, EventArgs e) { btnMin.BackgroundImage = Resources.smail_default; } private void btnMin_MouseMove(object sender, MouseEventArgs e) { btnMin.BackgroundImage = Resources.smail_select; } #endregion #region 窗口拖动行为 private void plTop_MouseDoubleClick(object sender, MouseEventArgs e) { this.WindowState = this.WindowState == FormWindowState.Normal ? FormWindowState.Maximized : FormWindowState.Normal; btnMax.BackgroundImage = this.WindowState == FormWindowState.Normal ? Resources.max_default : Resources.window_default; this.calcPanelWidth(); this.calcMenuLocation(); } private void plTop_MouseDown(object sender, MouseEventArgs e) { base.OnMouseDown(e); m_mousePos = Cursor.Position; m_isMouseDown = true; } private void plTop_MouseUp(object sender, MouseEventArgs e) { base.OnMouseUp(e); m_isMouseDown = false; this.Focus(); } private void plTop_MouseMove(object sender, MouseEventArgs e) { base.OnMouseMove(e); if (m_isMouseDown) { Point tempPos = Cursor.Position; this.Location = new Point(Location.X + (tempPos.X - m_mousePos.X), Location.Y + (tempPos.Y - m_mousePos.Y)); m_mousePos = Cursor.Position; } } #endregion #region 底部状态栏 private void timer1_Tick(object sender, EventArgs e) { this.tsmi_time.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); } #endregion #region 渲染顶部菜单 private void setMenuStripColor(Color color) { //menuStrip1.Renderer = new CustomProfessionalRenderer(color); } #endregion #region 重置界面宽度高度 /// /// 计算快速通道宽度 /// private void calcPanelWidth() { //int width = pl_center_main_bottom.Width; //pl_center_main_bottom_left_1.Width = pl_center_main_bottom_right_1.Width = width / 2; pl_center_main_bottom_left.Height = pl_center_main_bottom_right.Height = pl_center_main_right.Height / 2; } /// /// 重新计算菜单显示位置 /// private void calcMenuLocation() { int menuLeft = 5, menuTop = 5; // 模块距离左边距,模块距离顶部边距 int menuWidth = 110, menuHeight = 127; // 模块宽度,模块高度 int centerWidth = pl_center_main.Width - pl_center_main_right.Width; // 内容区域宽度-右侧快捷栏宽度 string defaultParentMenu = string.Empty; foreach (DataRow item in dtSubMenus.Rows) { defaultParentMenu = dtSubMenus.Rows[0]["menustruct"] + ""; string menuStruct = item["menustruct"] + ""; string menuCaption = item["menucaption"] + ""; string menuid = item["menuid"] + ""; if (menuStruct.Length == 2) { menuLeft = 5; menuTop = 5; } // 加载右侧模块 if (menuStruct.Length == 4) { Control[] ctrs = pl_center_main.Controls.Find(menuid, true); if (ctrs != null && ctrs.Length > 0) { if (ctrs[0] is Menu_Item) { ctrs[0].Location = new Point(menuLeft, menuTop); menuLeft += 116; // 换行显示 if (menuLeft + menuWidth > centerWidth) { menuLeft = 5; menuTop += menuHeight; } } } } } } #endregion #region 加载数据 /// /// 初始化数据 /// private void initMainData() { Application.DoEvents();// 处理当前消息队列中的所有windows消息 initMenus(); // 加载菜单、模块 initRightGallery(); // 加载通道数据 initTopMenu(); // 加载顶部菜单数据 } private void initMenus() { //string sqlValue = "select * from Hr_PeraonnelSpecTab order by speciesno desc"; string sqlValue = string.Format(@"select distinct * from ( select a.* from Hr_PeraonnelSpecTab a inner join( select SpeciesNo,speciesname from Hr_PeraonnelSpecTab where CHARINDEX(',{0},',','+purview+',')>0 and LEN(SpeciesNo)=6 ) b on LEFT(a.SpeciesNo,4)=LEFT(b.SpeciesNo,4) or LEFT(a.SpeciesNo,2)=LEFT(b.SpeciesNo,2) where len(a.SpeciesNo)<>6 union all select * from Hr_PeraonnelSpecTab where CHARINDEX(',{0},',','+purview+',')>0 and LEN(SpeciesNo)=6 )a order by speciesno desc", ERPInfo.Instance.OperatorName); DataTable dtTable = SqlHelper.ExecuteDataTable(sqlValue); clickEvent += new TreeViewCustom.ButtonClickEventHandler(menuButtonClick); tvcTree.ParentField = "speciesno"; tvcTree.ParentKeyLength = 2; tvcTree.TextField = "speciesname"; tvcTree.SetClickEvent(clickEvent); tvcTree.SetDataSource(dtTable); } /// /// 获取通道数据 /// private void initGallery() { string sqlValue = string.Format("select a.*,b.PurviewId from(select * from P_MessageToolLinkDllTab where employeeid={0} and grouptagid=1 " + " union " + " select * from P_MessageToolLinkDllTab where employeeid={0} and grouptagid=2 " + ")a join p_formmenuconfigtab b on a.LMenuId=b.MenuId order by grouptagid,ItemTagId", 1); DataTable dtTable = SqlHelper.ExecuteDataSet(sqlValue).Tables[0]; int top = 10, height = 30, left = 5; int width = pl_center_main_bottom_left_main.Width; int divide = width / 3; // 分为3等分 var baseTable = dtTable.Rows.Cast().Where(x => x["grouptagid"] + "" == "1").ToArray(); var reportTable = dtTable.Rows.Cast().Where(x => x["grouptagid"] + "" == "2").ToArray(); // 显示我的操作通道 for (int i = 0; i < baseTable.Count(); i++) { DataRow item = baseTable[i]; if (i > 0 && i % 3 == 0) { top += height; } Label label = new Label(); label.Location = new Point(i % 3 * divide + left, top); label.Text = item["DllShowCaption"] + ""; label.Font = new Font("微软雅黑", 10); label.Tag = item; label.MouseMove += label_MouseMove; label.MouseLeave += label_MouseLeave; pl_center_main_bottom_left_main.Controls.Add(label); } top = 10; // 显示我的报表通道 for (int i = 0; i < reportTable.Count(); i++) { DataRow item = reportTable[i]; if (i > 0 && i % 3 == 0) { top += height; } Label label = new Label(); label.Location = new Point(i % 3 * divide + left, top); label.Text = "· " + item["DllShowCaption"] + ""; label.Font = new Font("微软雅黑", 10); label.Tag = item; label.MouseMove += label_MouseMove; label.MouseLeave += label_MouseLeave; pl_center_main_bottom_right_main.Controls.Add(label); } } private void initRightGallery() { string sqlValue = string.Format("select a.*,b.PurviewId,b.UrlParams from(select * from P_MessageToolLinkDllTab where employeeid={0} and grouptagid=1 " + " union " + " select * from P_MessageToolLinkDllTab where employeeid={0} and grouptagid=2 " + ")a join p_formmenuconfigtab b on a.LMenuId=b.MenuId order by grouptagid,ItemTagId", ERPInfo.Instance.EmployeeId); DataTable dtTable = SqlHelper.ExecuteDataSet(sqlValue).Tables[0]; int top = 10, height = 30, left = 12; int width = pl_center_main_bottom_left_main.Width; int divide = width / 3; // 分为3等分 var baseTable = dtTable.Rows.Cast().Where(x => x["grouptagid"] + "" == "1").ToArray(); var reportTable = dtTable.Rows.Cast().Where(x => x["grouptagid"] + "" == "2").ToArray(); // 显示我的操作通道 for (int i = 0; i < baseTable.Count(); i++) { DataRow item = baseTable[i]; if (i > 0) { top += height; } // 前方箭头 PictureBox pic = new PictureBox(); pic.BackgroundImage = Resources.arrows; pic.Size = new Size(16, 16); pic.Location = new Point(left, top); Label label = new Label(); label.Location = new Point(left + 20, top - 3); label.Text = item["DllShowCaption"] + ""; label.Font = new Font("微软雅黑", 10); label.ForeColor = ColorTranslator.FromHtml("#0a57a7"); label.Tag = item; label.MouseMove += label_MouseMove; label.MouseLeave += label_MouseLeave; label.MouseClick += label_MouseClick; pl_center_main_bottom_left_main.Controls.Add(pic); pl_center_main_bottom_left_main.Controls.Add(label); } top = 10; // 显示我的报表通道 for (int i = 0; i < reportTable.Count(); i++) { DataRow item = reportTable[i]; if (i > 0) { top += height; } // 前方箭头 PictureBox pic = new PictureBox(); pic.BackgroundImage = Resources.arrows; pic.Size = new Size(16, 16); pic.Location = new Point(left, top); Label label = new Label(); label.Location = new Point(left + 20, top - 3); label.Text = item["DllShowCaption"] + ""; label.Font = new Font("微软雅黑", 10); label.ForeColor = ColorTranslator.FromHtml("#0a57a7"); label.Tag = item; label.MouseMove += label_MouseMove; label.MouseLeave += label_MouseLeave; label.MouseClick += label_MouseClick; pl_center_main_bottom_right_main.Controls.Add(pic); pl_center_main_bottom_right_main.Controls.Add(label); } } /// /// 加载顶部菜单数据(有权限的) /// private void initTopMenu() { try { //string sqlValue = string.Format("select * from P_FormMenuConfigTab where LEN(MenuStruct)=2 and SubSysId={0} {1} {2} order by MenuStruct", ERPInfo.Instance.SubSysId, qxCond, ConfigMenuVisible); string sqlValue = string.Format(@"select * from (select MenuId,MouseOutImg,MouseOverImg1,MenuCaption,DllFileName,MenuStruct,PurviewId,UrlParams,SubSysId FROM p_formmenuconfigtab WHERE SubSysId={0} " + qxCond + ConfigMenuVisible + @") x inner join (select left(MenuStruct,2) as MenuStruct,count(1) as menucount FROM p_formmenuconfigtab WHERE SubSysId={0} and LEN(MenuStruct)=4 and isnull(dllfilename,'')<>'' " + qxCond + ConfigMenuVisible + @" group by left(MenuStruct,2) ) y on left(x.menustruct,2)=y.menustruct where LEN(x.MenuStruct)=2 ORDER BY x.menustruct", ERPInfo.Instance.SubSysId); DataTable dtTable = SqlHelper.ExecuteDataSet(sqlValue).Tables[0]; for (int i = 0; i < dtTable.Rows.Count; i++) { DataRow item = dtTable.Rows[i]; string menuCaption = item["MenuCaption"] + ""; ToolStripMenuItem menuItem = new ToolStripMenuItem(); menuItem.Text = menuCaption; menuItem.Tag = item; menuItem.Font = new Font("微软雅黑", 12); menuItem.BackColor = Color.Transparent; menuItem.ForeColor = Color.White; menuItem.Click += new EventHandler(menuTopItem_Click); menuMain.Items.Add(menuItem); if (i == 0) firstMenuItem = menuItem; } } catch (Exception ex) { PubUtil.WriteError("读取菜单数据出错!", ex.Message); MessageBox.Show("读取菜单数据出错!"); } } public void menuItem_MouseLeave(object sender, EventArgs e) { } public void menuItem_MouseMove(object sender, MouseEventArgs e) { ToolStripMenuItem menuItem = (sender as ToolStripMenuItem); menuItem.ForeColor = Color.Black; } /// /// 加载明细 /// /// /// /// private void initTopSubMenus(string subSysId, DataTable subTable, ToolStripMenuItem parent) { //foreach (DataRow row in subTable.Rows) //{ // if (menuStruct.Length == 2) // { // // if (childs.Rows.Count > 0) // { // initTopSubMenus(subSysId, childs, subItem); // } // } // else // { // ToolStripMenuItem subItem = new ToolStripMenuItem(); // subItem.Text = menuCaption; // subItem.Tag = new string[] { row["DllFileName"] + "", row["PurviewId"] + "", row["MenuId"] + "", row["UrlParams"] + "", subSysId + "" }; // subItem.Click += subItem_Click; // parent.DropDownItems.Add(subItem); // } //} } /// /// 顶部菜单打开模块 /// /// /// public void subItem_Click(object sender, EventArgs e) { try { ToolStripMenuItem item = (ToolStripMenuItem)sender; string[] arr = (string[])item.Tag; int subSysId = arr.Length == 5 ? Convert.ToInt32(arr[4]) : ERPInfo.Instance.SubSysId; this.OpenMenu(subSysId, int.Parse(arr[2]), item.Text, arr[0], arr[1], arr[3]); } catch (Exception ex) { MessageBox.Show(ex.Message); } } /// /// 顶部菜单打开模块 /// /// /// private void menuTopItem_Click(object sender, EventArgs e) { try { // 功能模块 try { ToolStripMenuItem menuItem = sender as ToolStripMenuItem; if (menuItem == null || lastMenuButton == null || lastMenuItem == menuItem) return; this.lastMenuItem = menuItem; DataRow row = menuItem.Tag as DataRow; string sqlValue = string.Format("select * from P_FormMenuConfigTab where subsysid='{0}' and LEN(MenuStruct)=4 and SUBSTRING(MenuStruct,1,2)='{1}' and isnull(useflag,0)=1 {2} {3} order by MenuStruct", row["subsysid"] + "", row["MenuStruct"] + "", qxCond, ConfigMenuVisible); DataTable childs = SqlHelper.ExecuteDataTable(sqlValue); int buttonTop = Convert.ToInt32(0.05 * dpiY); // 按钮上边距 int menuLeft = Convert.ToInt32(0.05 * dpiY), menuTop = Convert.ToInt32(0.05 * dpiY); // 模块距离左边距,模块距离顶部边距 int menuWidth = Convert.ToInt32(1.14 * dpiX), menuHeight = Convert.ToInt32(1.32 * dpiY); // 模块宽度,模块高度 int centerWidth = pl_center_main.Width - pl_center_main_right.Width; // 内容区域宽度-右侧快捷栏宽度 pl_center_main.Controls.Clear(); if (childs != null && childs.Rows.Count > 0) { foreach (DataRow item in childs.Rows) { Application.DoEvents();// 处理当前消息队列中的所有windows消息 string defaultImg = PubUtil.AbsolutelyPath + "Images/main/module/" + item["MouseOutImg"] + ""; string hoverImg = PubUtil.AbsolutelyPath + "Images/main/module/" + item["MouseOverImg1"] + ""; Menu_Item menu = new Menu_Item(); menu.Name = item["menuid"] + ""; menu.Size = new Size(menuWidth, menuHeight); menu.Location = new Point(menuLeft, menuTop); menu.SetMenuCaption(item["menuCaption"] + ""); menu.SetRoundRadius = 20; menu.GetButton().Tag = new string[] { item["DllFileName"] + "", item["PurviewId"] + "", item["MenuId"] + "", item["UrlParams"] + "", item["SubSysId"] + "", item["menucaption"] + "" }; menu.GetButton().Click += FrmMain_Click; try { menu.SetMenuImg(Image.FromFile(defaultImg)); } catch (Exception) { menu.SetMenuImg(Resources.default_icon); } // 116 menuLeft += Convert.ToInt32(1.20 * dpiX); // 换行显示 if (menuLeft + menuWidth > centerWidth) { menuLeft = 5; menuTop += menuHeight; } pl_center_main.Controls.Add(menu); } } } catch (Exception) { } } catch (Exception ex) { MessageBox.Show(ex.Message); } } private void menuButtonClick(Button button) { try { if (this.lastMenuButton != button && TabMain.TabPages.Count > 1) { if (XtraMessageBox.Show("您确定切换菜单[切换将关闭已打开的模块]?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { int count = TabMain.TabPages.Count; for (int i = count; i > 0; i--) { XtraTabPage item = TabMain.TabPages[i - 1]; if (item.Text.Contains("寺庙导航")) continue; TabMain.TabPages.Remove(item); string menuId = item.Tag + ""; DllModule m = PubUtil.ModuleForms[menuId]; PubUtil.UnLoadDLL(m.ModuleForm); PubUtil.ModuleForms.Remove(m.Id); } } else { return; } } this.lblSubTitle.Text = topTitle + "-" + button.Text; this.lastMenuButton = button; ERPInfo.Instance.GroupId = (lastMenuButton.Tag as DataRow)["smid"] + ""; menuTopItem_Click(firstMenuItem, null); } catch (Exception) { } } /// /// 功能图标打开模块 /// /// /// public void FrmMain_Click(object sender, EventArgs e) { try { Button item = (Button)sender; string[] arr = (string[])item.Tag; int subSysId = arr.Length == 6 ? Convert.ToInt32(arr[4]) : ERPInfo.Instance.SubSysId; this.OpenMenu(subSysId, int.Parse(arr[2]), arr[5], arr[0], arr[1], arr[3]); } catch (Exception ex) { MessageBox.Show(ex.Message); } } public void label_MouseLeave(object sender, EventArgs e) { Label label = sender as Label; label.Font = new Font("微软雅黑", 10); label.ForeColor = ColorTranslator.FromHtml("#0a57a7"); } /// /// 快速通道 /// /// /// public void label_MouseMove(object sender, MouseEventArgs e) { Label label = sender as Label; label.Font = new Font("微软雅黑", 10, FontStyle.Bold | FontStyle.Underline); label.ForeColor = ColorTranslator.FromHtml("#1ba109"); this.Cursor = Cursors.Hand; } // 打开模块 public void label_MouseClick(object sender, MouseEventArgs e) { Label label = sender as Label; DataRow item = label.Tag as DataRow; if (item != null) { this.OpenMenu(Convert.ToInt32(item["LSubSysId"] + ""), Convert.ToInt32(item["LMenuId"] + ""), item["DllShowCaption"] + "", item["ObjDll"] + "", item["PurviewId"] + "", item["UrlParams"] + ""); } } /// /// 切换模块 /// /// public void TriggerMenu(Button before, Button after) { if (before != null) { DataRow item_before = before.Tag as DataRow; DataRow item_after = after.Tag as DataRow; if (item_before != null) { List beforeButtons = new List(); List afterButtons = new List(); // 隐藏控件 if (dicMenus.TryGetValue(item_before["menustruct"] + "", out beforeButtons)) { foreach (Menu_Item item in beforeButtons) { item.Visible = false; } } // 显示控件 if (dicMenus.TryGetValue(item_after["menustruct"] + "", out afterButtons)) { foreach (Menu_Item item in afterButtons) { item.Visible = true; } } } } } public void image_OnFrameChanged(object sender, EventArgs e) { Invalidate(); } #endregion #region 加载我的桌面 /// /// 加载基础档案表格列头 /// /// public DataTable InitColumns(string dllcoid) { SqlParameter[] p = { new SqlParameter("@modid",SqlDbType.VarChar,20), new SqlParameter("@operatorname",SqlDbType.VarChar,20) }; p[0].Value = dllcoid; p[1].Value = ERPInfo.Instance.OperatorName; return SqlHelper.ExecuteDataSet(CommandType.StoredProcedure, "[p_getBaseModuleField]", "temp", p).Tables[0]; } #endregion #region 打开模块 /// /// 打开模块 /// /// /// /// /// /// public void OpenMenu(int subSysId, int menuId, string menuName, string dllName, string modelFlag, string urlParams) { int OpenMode = ERPInfo.Instance.SoftOpenMode; int Code = GetOperatorPurview(subSysId, menuId); string showid = Convert.ToString(Code); if (Code == 0) { XtraMessageBox.Show("你无权操作此功能"); return; } string groupId = (lastMenuButton.Tag as DataRow)["id"] + ""; string Systmp = ServerTimer.ServerTime.ToString("yyyy-MM-dd HH:mm:ss:fff") + "@" + (new Random()).Next(1000).ToString(); PubUtil.WriteOpLog(Systmp, menuId.ToString(), "操作模块", menuName, menuName); DllModule dm = new DllModule(); dm.DllName = dllName; dm.Id = menuId.ToString(); dm.Name = menuName; string[] args = { menuName, ERPInfo.Instance.EmployeeId.ToString(), ERPInfo.Instance.EmployeeName, ERPInfo.Instance.Privilege, urlParams, menuId+"" }; if (string.IsNullOrEmpty(dllName) || string.IsNullOrEmpty(menuId + "")) { XtraMessageBox.Show("未找到对应模块参数,请联系管理员"); } dllName = dllName.Replace("{loginid}", ERPInfo.Instance.EmployeeId.ToString()); dllName = dllName.Replace("{loginname}", ERPInfo.Instance.EmployeeName.ToString()); //打开exe if (dllName.ToLower().IndexOf(".exe", 1) != -1) { PubUtil.WinExec(dllName, 0); } else if ((dllName.ToLower().IndexOf("http:", StringComparison.OrdinalIgnoreCase) != -1) || (dllName.ToLower().IndexOf("www.", StringComparison.OrdinalIgnoreCase) != -1) || (dllName.ToLower().IndexOf("ftp:", StringComparison.OrdinalIgnoreCase) != -1)) { System.Diagnostics.Process.Start(dllName); } else if (OpenMode == 0) { if (modelFlag == string.Empty) { //ModuleManager.AddModuleDelphiToTab(TabMain, dm, true); PubUtil.LoadDelphiDll(PubUtil.AbsolutelyPath + "lib/" + dllName, "", menuName, "", "", Code, urlParams); } else { ModuleManager.AddModuleToTab(TabMain, dm, args, true); } } else if (OpenMode == 1) { if (modelFlag == string.Empty) { //ModuleManager.AddModuleDelphiToShow(dm); PubUtil.LoadDelphiDll(PubUtil.AbsolutelyPath + "lib/" + dllName, "", menuName, "", "", Code, urlParams); } else { ModuleManager.AddModuleToShow(dm, args); } } else { if (modelFlag == string.Empty) PubUtil.LoadDelphiDll(PubUtil.AbsolutelyPath + "lib/" + dllName, "", menuName, "", "", Code, urlParams); else { IForm form = PubUtil.LoadDllForm(dllName, args); form.SubForm.ShowDialog(); } } PubUtil.WriteOpLog(Systmp); } private int GetOperatorPurview(int Gsysid, int I2) { if (ERPInfo.Instance.EmployeeName == "管理员") return 1; int OperatorPurview = 0; string strSql = "select * from P_SubSystemTab where subsysid=" + Gsysid.ToString(); try { string systempurview = ""; using (SqlDataReader dr = SqlHelper.ExecuteReader(CommandType.Text, strSql, null)) { if (dr.Read()) { systempurview = dr["subsyscode"].ToString().Trim() + "purview"; } } strSql = "select * from p_SubsysPurviewTab where employeeid=" + ERPInfo.Instance.EmployeeId.ToString(); string purviewStr = ""; using (SqlDataReader dr = SqlHelper.ExecuteReader(CommandType.Text, strSql, null)) { if (dr.Read()) { if (dr[systempurview].ToString().Trim() == "") purviewStr = ",0,"; else purviewStr = "," + dr[systempurview].ToString().Trim(); } } int i = 0; strSql = "select CHARINDEX('," + I2.ToString() + ",','" + purviewStr + "') as aaa"; using (SqlDataReader dr = SqlHelper.ExecuteReader(CommandType.Text, strSql, null)) { if (dr.Read()) { i = int.Parse(dr["aaa"].ToString()); } } if (i != 0) { OperatorPurview = 1; return OperatorPurview; } strSql = "select CHARINDEX('," + I2.ToString() + "|,','" + purviewStr + "') as aaa"; using (SqlDataReader dr = SqlHelper.ExecuteReader(CommandType.Text, strSql, null)) { if (dr.Read()) { i = int.Parse(dr["aaa"].ToString()); } } if (i != 0) { OperatorPurview = 2; } } catch (Exception ex) { PubUtil.WriteError("查询权限出错,请与管理员联系", ex.Message); MessageBox.Show("查询权限出错,请与管理员联系"); } return OperatorPurview; } #endregion #region 关闭模块 private void TabMain_HotTrackedPageChanged(object sender, TabPageChangedEventArgs e) { try { CurrentPage = e.Page; } catch (System.Exception ex) { CurrentPage = null; } } private void TabMain_CloseButtonClick(object sender, EventArgs e) { try { DevExpress.XtraTab.ViewInfo.ClosePageButtonEventArgs EArg = (DevExpress.XtraTab.ViewInfo.ClosePageButtonEventArgs)e; XtraTabPage tp = this.TabMain.SelectedTabPage; //根据标题栏汉字决定,后台定义时注意功能描述必须唯一 string pgText = EArg.Page.Text; foreach (XtraTabPage page in TabMain.TabPages) { if (page.Text == pgText) { tp = page; break; } } string MenuId = tp.Tag.ToString(); DllModule m = PubUtil.ModuleForms[MenuId]; if (PubUtil.ModuleForms.ContainsKey(MenuId)) { TabMain.TabPages.Remove(tp); PubUtil.UnLoadDLL(m.ModuleForm); PubUtil.ModuleForms.Remove(m.Id); } } catch { } } private void TabMain_MouseDoubleClick(object sender, MouseEventArgs e) { if (CurrentPage == null) { return; } try { string MenuId = CurrentPage.Tag.ToString(); DllModule m = PubUtil.ModuleForms[MenuId]; if (PubUtil.ModuleForms.ContainsKey(MenuId)) { TabMain.TabPages.Remove(CurrentPage); PubUtil.UnLoadDLL(m.ModuleForm); PubUtil.ModuleForms.Remove(m.Id); } } catch { } } #endregion #region 筛选打开模块相关 /// /// 选择模块后 /// /// /// private void menuSearch_GetReturnValue(object sender, EventArgs e) { AutoSearcher search = sender as AutoSearcher; if (!string.IsNullOrEmpty(search.ReturnValue)) { if (XtraMessageBox.Show("确定打开[" + search.Text + "]模块?", "温馨提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { var item = dtAllMenus.Rows.Cast().FirstOrDefault(x => x["menuid"] + "" == search.ReturnValue); if (item != null) { this.OpenMenu(Convert.ToInt32(item["SubSysId"] + ""), Convert.ToInt32(item["MenuId"] + ""), item["menucaption"] + "", item["DllFileName"] + "", item["PurviewId"] + "", item["UrlParams"] + ""); } } } } /// /// OnTextChange之前调用 /// /// /// private void menuSearch_HandleSQL(object sender, EventArgs e) { ControlLib.inh.AutoSearcher search = (ControlLib.inh.AutoSearcher)sender; if (search.Text == "请输入模块名称") { search.Text = ""; } } #endregion #region 打开修改密码 private void lbUserName_Click(object sender, EventArgs e) { try { string OperatorNameDll = lbUserName.Tag + ""; if (string.IsNullOrEmpty(OperatorNameDll)) { PubUtil.LoadDelphiDll(PubUtil.AbsolutelyPath + "lib/" + OperatorNameDll); } else { PubUtil.LoadDelphiDll(PubUtil.AbsolutelyPath + "lib/p_PassWordMge.lsp"); } } catch (Exception) { XtraMessageBox.Show("打开修改密码出错,请联系管理员"); } } #endregion #region 切换用户 /// /// 切换用户 /// /// /// private void lblSwapUser_Click(object sender, EventArgs e) { FrmRelogin _FrmRelogin = new FrmRelogin(); _FrmRelogin.ShowDialog(); ENUMCloseAction eca = ERPInfo.Instance.ExitResult; if (eca == ENUMCloseAction.caRelogin) { PubUtil.ModuleForms.Clear(); this.Close(); } PubUtil.ReleaseForm(_FrmRelogin); _FrmRelogin = null; } #endregion #region 打开快捷通道配置 private void lblShortcutset_Click(object sender, EventArgs e) { try { string ShortcutDll = lblShortcutset.Tag + ""; if (!string.IsNullOrEmpty(ShortcutDll)) { PubUtil.LoadDelphiDll(PubUtil.AbsolutelyPath + "lib/" + ShortcutDll); } else { PubUtil.LoadDelphiDll(PubUtil.AbsolutelyPath + "lib/P_Lsplanes.lsp"); } } catch (Exception) { XtraMessageBox.Show("打开配置快捷通道出错,请联系管理员"); } } #endregion #region 无标题栏窗体最大化最小化 protected override CreateParams CreateParams { get { const int WS_MINIMIZEBOX = 0x00020000; // Winuser.h中定义 CreateParams cp = base.CreateParams; cp.Style = cp.Style | WS_MINIMIZEBOX; // 允许最小化操作 return cp; } } #endregion } }