Files
lserp_cs_6.0/插件库/Lskj.Main/FrmSubSystem.cs
T

720 lines
27 KiB
C#

/******************************
* 说明:子系统选择
* 创建人:龚宇超
* 创建日期: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.Main.Properties;
using Lskj.Data;
using Lskj.Control;
using Lskj.Main.Control;
using Lskj.Main.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.Main
{
/// <summary>
/// 子系统选择
/// </summary>
public partial class FrmSubSystem : Form
{
public string BsName;
public string BsUrl;
#region 私有属性
/// <summary>
/// 是否鼠标按下
/// </summary>
private bool _isMouseDown;
/// <summary>
/// 记录窗口位置
/// </summary>
private Point _mousePostion;
/// <summary>
/// 默认选中的page
/// </summary>
private PictureBox _defaultSelectPage;
/// <summary>
/// 子系统不可用颜色
/// </summary>
private string _unUseColor = "#8d9aaa";
/// <summary>
/// 子系统
/// </summary>
private List<SubItem> _menuList = new List<SubItem>();
/// <summary>
/// 子系统默认背景色
/// </summary>
private string[] _defaultColors = { "#55bf07", "#01caa2", "#bb6aee", "#199efb", "#33b4fe", "#8bc91e", "#1cabed", "#0fc37d" };
/// <summary>
/// 子系统默认图片
/// </summary>
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};
//是否配置了左侧提示信息 true为存在信息sql,查询结果第一行第一列展示到左侧
private bool _information = false;
#endregion
#region 窗口加载
public FrmSubSystem()
{
InitializeComponent();
//if (this.pl_bg != null && !(this.pl_bg is BackgroundPanel))
//{
// this.pl_bg = new BackgroundPanel();
// this.pl_bg.Dock = DockStyle.Fill;
// this.pl_bg.Name = "pl_bg";
// this.Controls.Add(this.pl_bg);
// // 确保pl_bg在最底层,不遮挡其他控件
// this.pl_bg.SendToBack();
//}
}
/// <summary>
/// <para>说明:窗口加载</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2017-08-12 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
private void FrmSubSystem_Load(object sender, EventArgs e)
{
try
{
WaitForm.ShowForm();//等待框
//判断是否配置了左侧提示信息 true为存在信息sql,查询结果第一行第一列展示到左侧
_information = !string.IsNullOrWhiteSpace(SystemInfo.Instance.PromptInformationSql);
this.pictureEdit1.Properties.ContextMenu = new ContextMenu();//把菜单类赋格控件
this.pl_bg.BackgroundImage = BitMapHelper.getBitmap(BitMapEnum.submenubg);//本地拿到自带背景
//pl_bg.BackgroundImageCustom = BitMapHelper.getBitmap(BitMapEnum.submenubg);
//if (this.pl_bg is BackgroundPanel)
//{
// // 从本地获取背景位图并设置到自定义属性
// (pl_bg as BackgroundPanel).BackgroundImageCustom = 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());
string where = string.IsNullOrEmpty(ERPInfo.Instance.SeriesId) ? "" : string.Format("and SeriesId={0}", ERPInfo.Instance.SeriesId);
InitSubItem(MainImpl.GetSubSystems(where));//获取全部子系统信息,并把信息承认 子菜单创建方法
}
catch (Exception ex)
{
string Message = ErrorMessage.PromptErrorMessage(ex);
MessageUtil.Show(Message, ex.Message);
}
finally
{
WaitForm.HideForm();
}
}
#endregion
#region 私有方法
/// <summary>
/// 创建子菜单
/// </summary>
private void InitSubItem(DataTable itemTable)
{
SubItem.HoverEventHandler hoverHandler = null;//子菜单鼠标悬停处理程序
SubItem.MouseClickEventHanlder clickHandler = null;//子菜单鼠标点击事件处理程序
//执行左侧提示信息sql
if (_information)
{
this.rtbTip.Visible = true;
this.rtbTip.ReadOnly = true;
this.rtbTip.ScrollBars = RichTextBoxScrollBars.None;
//this.KeyPreview = true;
this.rtbTip.MouseWheel += RtbTip_MouseWheel;
DataTable dt = BillImpl.GetDataTableResult(ReplaceHelper.ReplaceUserInfo(SystemInfo.Instance.PromptInformationSql));
string text = string.Empty;
foreach (DataRow dr in dt.Rows)
{
text += dr[0] + "\r\n";
}
rtbTip.Text = text;
}
if (Business.Impl.LanguageTranslation.Translatable)
{
itemTable = Business.Impl.LanguageTranslation.TranslationTableColumn(itemTable, "SubSysName");
}
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"] + "";//显示名称
//如果配置了语言替换,需要重新设置text的最大宽度以支持换行
if (Business.Impl.LanguageTranslation.Translatable)
{
sub_item.GetLabel.MaximumSize = new Size(sub_item.Size.Width - 20, 0);
sub_item.GetLabel.AutoSize = true;
sub_item.GetPlTop.AutoSize = true;
//sub_item.GetLabel.BringToFront();
//sub_item.GetLabel.Hide();
//Label label = new Label();
//label.MaximumSize = new Size(sub_item.Size.Width - 20, 0);
//label.AutoSize = true;
//label.Font = new System.Drawing.Font("宋体", 14F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
//label.ForeColor = System.Drawing.Color.White;
//sub_item.Controls.Add(label);
////label.Location = new System.Drawing.Point(19, 13);
//label.BringToFront();
}
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"] + "";
if (!_information)
{
hoverHandler += new SubItem.HoverEventHandler(SwapMenuTip);
sub_item.SetHoverEvent(hoverHandler);//注册鼠标划过事件
rtbTip.Text = " " + itemTable.Rows[0]["SubSysTip"] + "";
}
clickHandler += new SubItem.MouseClickEventHanlder(OpenMainSystem);
sub_item.SetClickEvent(clickHandler);//注册鼠标点击事件
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);
}
}
/// <summary>
/// 提示信息滚动
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void RtbTip_MouseWheel(object sender, MouseEventArgs e)
{
rtbTip.Focus();
// 取消默认的滚动行为
((HandledMouseEventArgs)e).Handled = true;
// 获取滚轮滚动的方向
int scrollDirection = e.Delta > 0 ? -1 : 1;
// 滚动速度,可以调整这个值来改变滚动的行数
int linesToScroll = 1;
// 计算需要滚动的字符数,这通常依赖于字体大小和行高
int charsToScroll = rtbTip.Font.Height * linesToScroll;
// 根据滚轮滚动的方向调整文本选择的位置
int newSelectionStart = rtbTip.SelectionStart + (scrollDirection * charsToScroll);
// 确保选择的位置在有效范围内
if (newSelectionStart < 0)
{
newSelectionStart = 0;
}
else if (newSelectionStart > rtbTip.Text.Length)
{
newSelectionStart = rtbTip.Text.Length;
}
// 设置新的选择位置和长度,这将移动视图
rtbTip.SelectionStart = newSelectionStart;
rtbTip.SelectionLength = 0; // 不选择任何文本
//// 自定义滚动效果
//int delta = e.Delta / Math.Abs(e.Delta);
//if (delta > 0 && rtbTip.SelectionStart < rtbTip.TextLength - 1 ||
// delta < 0 && rtbTip.SelectionStart > 0)
//{
// // 向前/向后移动光标位置
// rtbTip.Select(rtbTip.SelectionStart - delta, 0);
// // 重新选择文本区域
// rtbTip.Focus();
//}
}
/// <summary>
/// 切换简介
/// </summary>
/// <param name="item"></param>
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);
}
}
/// <summary>
/// <para>说明:鼠标移动</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2017-11-29 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="MouseEventArgs"/> instance containing the event data.</param>
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);
}
}
/// <summary>
/// 切换子系统
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
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);
}
}
/// <summary>
/// 打开主系统
/// </summary>
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 最小化
/// <summary>
/// <para>说明:最小化</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2017-08-12 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
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);
}
}
/// <summary>
/// <para>说明:最小化鼠标离开</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2017-08-12 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
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);
}
}
/// <summary>
/// <para>说明:最小化鼠标移动</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2017-08-12 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="MouseEventArgs"/> instance containing the event data.</param>
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 关闭
/// <summary>
/// <para>说明:关闭</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2017-08-12 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
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)
{
try
{
item.Kill();
}
catch (Exception)
{
}
}
}
if (!string.IsNullOrWhiteSpace(SystemInfo.Instance.QuickMenuId))
{
Process[] p2 = Process.GetProcessesByName("Lskj.QuickModule");
foreach (Process item in p2)
{
try
{
item.Kill();
}
catch (Exception)
{
}
}
}
//记录登出日志
LogUtil.WriteDebug("", "退出软件", "软件退出", "系统登录");
Process[] p = Manager.GetApplicationProcesses();
foreach (Process item in p)
{
try
{
item.Kill();
}
catch (Exception)
{
}
}
//Environment.Exit(0);
Application.Exit();
}
}
catch (Exception ex)
{
string Message = ErrorMessage.PromptErrorMessage(ex);
MessageUtil.Show(Message, ex.Message);
}
}
/// <summary>
/// <para>说明:关闭按钮离开</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2017-08-12 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
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);
}
}
/// <summary>
/// <para>说明:关闭按钮移动</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2017-08-12 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="MouseEventArgs"/> instance containing the event data.</param>
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 窗口拖动行为
/// <summary>
/// <para>说明:鼠标按下</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2017-08-14 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="MouseEventArgs"/> instance containing the event data.</param>
private void plTop_MouseDown(object sender, MouseEventArgs e)
{
try
{
base.OnMouseDown(e);
System.Windows.Forms.Control control = (System.Windows.Forms.Control)sender;
Point mousePoint = control.PointToClient(System.Windows.Forms.Control.MousePosition);
_mousePostion = new Point(mousePoint.X, mousePoint.Y);
_isMouseDown = true;
}
catch (Exception ex)
{
string Message = ErrorMessage.PromptErrorMessage(ex);
MessageUtil.Show(Message, ex.Message);
}
}
/// <summary>
/// <para>说明:鼠标放开</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2017-08-14 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="MouseEventArgs"/> instance containing the event data.</param>
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);
}
}
/// <summary>
/// <para>说明:鼠标移动</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期:2017-08-14 </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="MouseEventArgs"/> instance containing the event data.</param>
private void plTop_MouseMove(object sender, MouseEventArgs e)
{
try
{
base.OnMouseMove(e);
if (_isMouseDown && e.Button == MouseButtons.Left)
{
this.Location = new Point(Location.X + (e.X - _mousePostion.X), Location.Y + (e.Y - _mousePostion.Y));
}
}
catch (Exception ex)
{
string Message = ErrorMessage.PromptErrorMessage(ex);
MessageUtil.Show(Message, ex.Message);
}
}
#endregion
}
}