/****************************** * 说明:子系统选择 * 创建人:龚宇超 * 创建日期:2017-08-12 * 修改人: * 修改日期: * 修改备注: * 版本:1.0.0.0 ******************************/ using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using Lskj.Main3.Properties; using Lskj.Data; using Lskj.Control; using Lskj.Main3.Control; using Lskj.Main3.Model; using Lskj.Util; using Lskj.Business; using Lskj.Model; using Lskj.Control.Model; using Lskj.Business.Impl; using System.Diagnostics; using Lskj.Core; namespace Lskj.Main3 { /// /// 子系统选择 /// public partial class FrmSubSystem : Form { public string BsName; public string BsUrl; #region 私有属性 /// /// 是否鼠标按下 /// private bool _isMouseDown; /// /// 记录窗口位置 /// private Point _mousePostion; /// /// 默认选中的page /// private PictureBox _defaultSelectPage; /// /// 子系统不可用颜色 /// private string _unUseColor = "#8d9aaa"; /// /// 子系统 /// private List _menuList = new List(); /// /// 子系统默认背景色 /// private string[] _defaultColors = { "#55bf07", "#01caa2", "#bb6aee", "#199efb", "#33b4fe", "#8bc91e", "#1cabed", "#0fc37d" }; /// /// 子系统默认图片 /// private Bitmap[] _defaultImages = { Resources.sub_pzjk,Resources.sub_scgx,Resources.sub_khgl,Resources.sub_cggl,Resources.sub_gdzc, Resources.sub_sczw,Resources.sub_khgx,Resources.sub_scl}; #endregion #region 窗口加载 public FrmSubSystem() { InitializeComponent(); } /// /// 说明:窗口加载 /// 创建人:龚宇超 /// 创建日期:2017-08-12 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The source of the event. /// The instance containing the event data. private void FrmSubSystem_Load(object sender, EventArgs e) { try { WaitForm.ShowForm();//等待框 this.pictureEdit1.Properties.ContextMenu = new ContextMenu();//把菜单类赋格控件 this.pl_bg.BackgroundImage = BitMapHelper.getBitmap(BitMapEnum.submenubg);//本地拿到自带背景 this.pictureEdit1.Image = BitMapHelper.getBitmap(BitMapEnum.submenubg_tip);//如果有自定义别的背景,就拿自定义的 if (this.pictureEdit1.Image != Resources.sub_tip_backgound) { // 有自定义图片则去掉说明 this.rtbTip.Visible = false; } this.lblTip.Text = string.Format("今天是{0} {1}", DateTime.Now.ToString("yyyy年MM月dd日"), DateHelper.GetDayOfWeek()); InitSubItem(MainImpl.GetSubSystems());//获取全部子系统信息,并把信息承认 子菜单创建方法 } catch (Exception ex) { string Message = ErrorMessage.PromptErrorMessage(ex); MessageUtil.Show(Message, ex.Message); } finally { WaitForm.HideForm(); } } #endregion #region 私有方法 /// /// 创建子菜单 /// private void InitSubItem(DataTable itemTable) { SubItem.HoverEventHandler hoverHandler = null;//子菜单鼠标悬停处理程序 SubItem.MouseClickEventHanlder clickHandler = null;//子菜单鼠标点击事件处理程序 Graphics graphics = this.CreateGraphics(); //创建图形图像的对象 float dpiX = graphics.DpiX;//宽 float dpiY = graphics.DpiY;//高 // 100%分辨率下itemWidth=175px;itemHeight=154px; int itemWidth = Convert.ToInt32(dpiX * 1.82f), itemHeight = Convert.ToInt32(dpiY * 1.62f); int itemLeft = 0, itemTop = 0; for (int i = 0; i < itemTable.Rows.Count; i++) { DataRow item = itemTable.Rows[i];//表格中每一行的数据 SubItem sub_item = new SubItem(); // 换行显示 if (i > 3 && i % 4 == 0) { itemLeft = 0; itemTop = Convert.ToInt32(dpiY * 1.74f); } // 下一页子系统,自动隐藏 if (i > 7 && i % 8 == 0) { itemTop = 0; sub_item.Visible = false;//隐藏 } string useEd = item["UseEd"] + ""; sub_item.Location = new Point(itemLeft, itemTop);//位置 sub_item.Size = new Size(itemWidth, itemHeight);//大小 sub_item.GetLabel.Text = item["SubSysName"] + "";//显示名称 sub_item.GetPictureBox.BackgroundImage = _defaultImages[i % 8];//背景图 sub_item.GetPictureBox.BackgroundImageLayout = ImageLayout.Stretch;//图片布局 sub_item.BackColor = Convert.ToBoolean(useEd) ? ColorTranslator.FromHtml(_defaultColors[i % 8]) : ColorTranslator.FromHtml(_unUseColor);//背景颜色 sub_item.DefaultColor = Convert.ToBoolean(useEd) ? _defaultColors[i % 8] : _unUseColor;//默认颜色 sub_item.Visible = true;//显示 sub_item.Tag = item; sub_item.IsUsed = Convert.ToBoolean(useEd); sub_item.SubName = item["SubSysName"] + ""; hoverHandler += new SubItem.HoverEventHandler(SwapMenuTip); sub_item.SetHoverEvent(hoverHandler);//注册鼠标划过事件 clickHandler += new SubItem.MouseClickEventHanlder(OpenMainSystem); sub_item.SetClickEvent(clickHandler);//注册鼠标点击事件 rtbTip.Text = " " + itemTable.Rows[0]["SubSysTip"] + ""; itemLeft += itemWidth + 11; plSubMenus.Controls.Add(sub_item); this._menuList.Add(sub_item); } // 创建分页图标 int pageCount = itemTable.Rows.Count / 8 + (itemTable.Rows.Count % 8 == 0 ? 0 : 1);//页数 int pageLeft = this.Width / 2 - (pageCount / 2 * 30);//页数框到左边的宽度 for (int i = 0; i < pageCount; i++) { PictureBox subpage = new PictureBox(); subpage.BackColor = Color.Transparent; subpage.BackgroundImage = i == 0 ? Resources.sub_page_select : Resources.sub_page_default; subpage.Size = new Size(30, 30); subpage.Location = new Point(pageLeft + i * 30, 0); subpage.MouseClick += subpage_MouseClick; subpage.MouseMove += subpage_MouseMove; subpage.Name = "subpage_" + i; if (i == 0) { _defaultSelectPage = subpage;//选中页面 } plSubPages.Controls.Add(subpage); } } /// /// 切换简介 /// /// private void SwapMenuTip(SubItem item) { try { DataRow row = item.Tag as DataRow; if (row != null) { rtbTip.Text = " " + row["SubSysTip"] + ""; } } catch (Exception ex) { MessageUtil.Show(ex); } } /// /// 说明:鼠标移动 /// 创建人:龚宇超 /// 创建日期:2017-11-29 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The source of the event. /// The instance containing the event data. private void subpage_MouseMove(object sender, MouseEventArgs e) { try { (sender as PictureBox).Cursor = Cursors.Hand; } catch (Exception ex) { string Message = ErrorMessage.PromptErrorMessage(ex); MessageUtil.Show(Message, ex.Message); } } /// /// 切换子系统 /// /// /// private void subpage_MouseClick(object sender, MouseEventArgs e) { try { PictureBox selectPage = sender as PictureBox; if (selectPage != _defaultSelectPage) { selectPage.BackgroundImage = Resources.sub_page_select; _defaultSelectPage.BackgroundImage = Resources.sub_page_default; int page = Convert.ToInt32(selectPage.Name.Replace("subpage_", "")); for (int i = 0; i < this._menuList.Count; i++) { SubItem item = this._menuList[i]; item.Visible = (i >= page * 8 && i < (page + 1) * 8) ? true : false; } _defaultSelectPage = selectPage; } } catch (Exception ex) { string Message = ErrorMessage.PromptErrorMessage(ex); MessageUtil.Show(Message, ex.Message); } } /// /// 打开主系统 /// private void OpenMainSystem(SubItem item) { DataRow row = item.Tag as DataRow; if (row != null) { ERPInfo.Instance.SubSysId = row["SubSysId"] + ""; ERPInfo.Instance.SubSysName = row["SubSysName"] + ""; string BsTag = row.Table.Columns.Contains("targetLink") && !string.IsNullOrEmpty(row["targetLink"] + "") ? row["targetLink"] + "" : ""; if (!string.IsNullOrEmpty(BsTag) && BsTag.StartsWith("http", StringComparison.OrdinalIgnoreCase)) { this.BsName = row["SubSysName"] + ""; this.BsUrl = row["targetLink"] + ""; DialogResult = DialogResult.Yes; } else DialogResult = DialogResult.OK; Close(); } } #endregion #region 最小化 /// /// 说明:最小化 /// 创建人:龚宇超 /// 创建日期:2017-08-12 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The source of the event. /// The instance containing the event data. private void btnMin_Click(object sender, EventArgs e) { try { this.WindowState = FormWindowState.Minimized; } catch (Exception ex) { string Message = ErrorMessage.PromptErrorMessage(ex); MessageUtil.Show(Message, ex.Message); } } /// /// 说明:最小化鼠标离开 /// 创建人:龚宇超 /// 创建日期:2017-08-12 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The source of the event. /// The instance containing the event data. private void btnMin_MouseLeave(object sender, EventArgs e) { try { btnMin.BackgroundImage = Resources.sub_btn_min; } catch (Exception ex) { string Message = ErrorMessage.PromptErrorMessage(ex); MessageUtil.Show(Message, ex.Message); } } /// /// 说明:最小化鼠标移动 /// 创建人:龚宇超 /// 创建日期:2017-08-12 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The source of the event. /// The instance containing the event data. private void btnMin_MouseMove(object sender, MouseEventArgs e) { try { btnMin.Cursor = Cursors.Hand; btnMin.BackgroundImage = Resources.sub_btn_min_select; } catch (Exception ex) { string Message = ErrorMessage.PromptErrorMessage(ex); MessageUtil.Show(Message, ex.Message); } } #endregion #region 关闭 /// /// 说明:关闭 /// 创建人:龚宇超 /// 创建日期:2017-08-12 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The source of the event. /// The instance containing the event data. private void btnColse_Click(object sender, EventArgs e) { try { DialogResult result = MessageUtil.Show(ResourceKeys.IsExit, MessageBoxButtons.YesNo); if (result == DialogResult.Yes) { Close(); if (DBConfig.Instance.NoticeExit) { Process[] p1 = Process.GetProcessesByName("Ls_Notice"); foreach (Process item in p1) item.Kill(); } //记录登出日志 LogUtil.WriteDebug("", "退出软件", "软件退出", "系统登录"); Process[] p = Process.GetProcessesByName("Ls_ERP"); foreach (Process item in p) item.Kill(); } } catch (Exception ex) { string Message = ErrorMessage.PromptErrorMessage(ex); MessageUtil.Show(Message, ex.Message); } } /// /// 说明:关闭按钮离开 /// 创建人:龚宇超 /// 创建日期:2017-08-12 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The source of the event. /// The instance containing the event data. private void btnColse_MouseLeave(object sender, EventArgs e) { try { btnColse.BackgroundImage = Resources.sub_btn_default; } catch (Exception ex) { string Message = ErrorMessage.PromptErrorMessage(ex); MessageUtil.Show(Message, ex.Message); } } /// /// 说明:关闭按钮移动 /// 创建人:龚宇超 /// 创建日期:2017-08-12 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The source of the event. /// The instance containing the event data. private void btnColse_MouseMove(object sender, MouseEventArgs e) { try { btnColse.Cursor = Cursors.Hand; btnColse.BackgroundImage = Resources.sub_btn_select; } catch (Exception ex) { string Message = ErrorMessage.PromptErrorMessage(ex); MessageUtil.Show(Message, ex.Message); } } #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 #region 窗口拖动行为 /// /// 说明:鼠标按下 /// 创建人:龚宇超 /// 创建日期:2017-08-14 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The source of the event. /// The instance containing the event data. private void plTop_MouseDown(object sender, MouseEventArgs e) { try { base.OnMouseDown(e); _mousePostion = Cursor.Position; _isMouseDown = true; } catch (Exception ex) { string Message = ErrorMessage.PromptErrorMessage(ex); MessageUtil.Show(Message, ex.Message); } } /// /// 说明:鼠标放开 /// 创建人:龚宇超 /// 创建日期:2017-08-14 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The source of the event. /// The instance containing the event data. private void plTop_MouseUp(object sender, MouseEventArgs e) { try { base.OnMouseUp(e); _isMouseDown = false; this.Focus(); } catch (Exception ex) { string Message = ErrorMessage.PromptErrorMessage(ex); MessageUtil.Show(Message, ex.Message); } } /// /// 说明:鼠标移动 /// 创建人:龚宇超 /// 创建日期:2017-08-14 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The source of the event. /// The instance containing the event data. private void plTop_MouseMove(object sender, MouseEventArgs e) { try { base.OnMouseMove(e); if (_isMouseDown) { Point tempPos = Cursor.Position; this.Location = new Point(Location.X + (tempPos.X - _mousePostion.X), Location.Y + (tempPos.Y - _mousePostion.Y)); _mousePostion = Cursor.Position; } } catch (Exception ex) { string Message = ErrorMessage.PromptErrorMessage(ex); MessageUtil.Show(Message, ex.Message); } } #endregion } }