ab56a9bcf7
SVN-Revision: r240
425 lines
18 KiB
C#
425 lines
18 KiB
C#
using DevExpress.XtraTab;
|
|
using Lskj.Business;
|
|
using Lskj.Business.Impl;
|
|
using Lskj.Control;
|
|
using Lskj.Core;
|
|
using Lskj.Data;
|
|
using Lskj.Model;
|
|
using Lskj.Util;
|
|
using Lskj.WorkshopProgram.Control;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Data.SqlClient;
|
|
using System.Diagnostics;
|
|
using System.Drawing;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Windows.Forms;
|
|
|
|
namespace Lskj.WorkshopProgram
|
|
{
|
|
public partial class FrmMain : BaseForm
|
|
{
|
|
#region 公共字段
|
|
/// <summary>
|
|
/// 左侧公共表
|
|
/// </summary>
|
|
public DataTable LeftPageTab = new DataTable();
|
|
/// <summary>
|
|
/// 屏幕dpix、dpiy
|
|
/// </summary>
|
|
public float DpiX, DpiY;
|
|
/// <summary>
|
|
/// 缓存菜单控件
|
|
/// </summary>
|
|
private Dictionary<string, List<Menu_Item>> _menus = new Dictionary<string, List<Menu_Item>>();
|
|
/// <summary>
|
|
/// 缓存菜单
|
|
/// </summary>
|
|
private List<Menu_Item> _menuItemList = new List<Menu_Item>();
|
|
|
|
exetowinform fr = null;
|
|
|
|
#endregion
|
|
public FrmMain()
|
|
{
|
|
Graphics graphics = this.CreateGraphics();
|
|
DpiX = graphics.DpiX;
|
|
DpiY = graphics.DpiY;
|
|
InitializeComponent();
|
|
}
|
|
/// <summary>
|
|
/// 界面加载
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
|
|
private void OnFrmLoad(object sender, EventArgs e)
|
|
{
|
|
InitGridData();
|
|
InitGridLoad();
|
|
}
|
|
#region 方法
|
|
#region 构建左右表格数据方法
|
|
/// <summary>
|
|
/// <para>说明:获取左右两侧表的数据源</para>
|
|
/// <para>创建人:王一帆</para>
|
|
/// <para>创建日期:2021-12-02 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
/// <param name="sender">The sender.</param>
|
|
/// <param name="e">The <see cref="PopupMenuShowingEventArgs"/> instance containing the event data.</param>
|
|
public void InitGridData()
|
|
{
|
|
string serverName = IniHelper.Read("数据库连接.ini", "参数", "serverName"); //地址
|
|
string dbName = IniHelper.Read("数据库连接.ini", "参数", "dbName");//数据库名
|
|
string user = IniHelper.Read("数据库连接.ini", "参数", "user");//用户名
|
|
string password = IniHelper.Read("数据库连接.ini", "参数", "password"); //密码
|
|
string connStr = string.Format("Server={0};Database={1};Persist Security Info=True;User ID={2};Password={3};Connection Timeout=5;MultipleActiveResultSets=true", serverName, dbName, user, password);
|
|
//连接数据库
|
|
if (SqlHelper._connection != null)
|
|
{
|
|
try
|
|
{
|
|
SqlHelper._connection.Close();
|
|
SqlHelper._connection.Dispose();
|
|
}
|
|
catch (Exception)
|
|
{
|
|
}
|
|
SqlHelper._connection = null;
|
|
}
|
|
try
|
|
{
|
|
SqlHelper._connection = new SqlConnection(connStr);
|
|
SqlHelper._connection.Open();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
// LogHelper.Instance.WriteLog(ex.Message);
|
|
MessageUtil.Show("数据库连接失败:" + ex.Message);
|
|
}
|
|
|
|
//// 左侧标签自定义数据源
|
|
//LeftPageTab = new DataTable();
|
|
//LeftPageTab.Columns.Add("menustruct");
|
|
//LeftPageTab.Columns.Add("menusName");
|
|
//LeftPageTab.Columns.Add("route");
|
|
|
|
////string route = Lskj.Util.PubUtil.AbsolutelyPath;
|
|
//string route ="最新程序\\";
|
|
//LeftPageTab.Rows.Add("01", "打印与印刷");
|
|
//LeftPageTab.Rows.Add("0101", "吹膜条码打印", route + "永盛-01-吹膜条码打印\\0101吹膜条码打印.exe");
|
|
//LeftPageTab.Rows.Add("0102", "印刷用料登记", route + "永盛-02印刷-01用料登记10028\\0201印刷_材料登记.exe");
|
|
//LeftPageTab.Rows.Add("0103", "印刷版辊上机", route + "永盛-02印刷-02版辊上机\\0202印刷-版辊上机.exe");
|
|
//LeftPageTab.Rows.Add("0104", "印刷工序汇报", route + "永盛-02印刷-03工序汇报\\0203印刷-工序汇报.exe");
|
|
//LeftPageTab.Rows.Add("02", "品检与复合");
|
|
//LeftPageTab.Rows.Add("0201", "品检用料登记", route + "永盛-03品检-01用料登记10028\\0301品检_材料登记.exe");
|
|
//LeftPageTab.Rows.Add("0202", "品检工序汇报", route + "永盛-03品检-03工序汇报\\0303品检_工序汇报.exe");
|
|
//LeftPageTab.Rows.Add("0203", "复合用料登记", route + "永盛-04复合-01用料登记\\0401复合_材料登记.exe");
|
|
//LeftPageTab.Rows.Add("0204", "复合工序汇报", route + "永盛-04复合-03工序汇报\\0403复合-工序汇报.exe");
|
|
//LeftPageTab.Rows.Add("03", "塑化");
|
|
//LeftPageTab.Rows.Add("0301", "塑化用料登记", route + "永盛-05塑化-01用料登记10028\\0501塑化_材料登记.exe");
|
|
//LeftPageTab.Rows.Add("0302", "塑化工序汇报", route + "永盛-05塑化-03工序汇报\\0503塑化_工序汇报.exe");
|
|
//LeftPageTab.Rows.Add("04", "分切与热切");
|
|
//LeftPageTab.Rows.Add("0401", "分切用料登记", route + "永盛-06分切-01用料登记10028\\0601分切_材料登记.exe");
|
|
//LeftPageTab.Rows.Add("0402", "0301半成品汇报", route + "永盛-06分切-0301半成品汇报\\060301分切_半成品汇报.exe");
|
|
//LeftPageTab.Rows.Add("0403", "0302成品汇报", route + "永盛-06分切-0302成品汇报\\060302分切_成品汇报.exe");
|
|
//LeftPageTab.Rows.Add("0404", "热切用料登记", route + "永盛-07热切-01用料登记1028\\0701热切_材料登记.exe");
|
|
//LeftPageTab.Rows.Add("0405", "热切工序汇报", route + "永盛-07热切-03工序汇报\\0703热切_工序汇报.exe");
|
|
//LeftPageTab.Rows.Add("05", "折边与制袋");
|
|
//LeftPageTab.Rows.Add("0501", "折边用料登记", route + "永盛-08折边-01用料登记10028\\0801折边_材料登记.exe");
|
|
//LeftPageTab.Rows.Add("0502", "折边工序汇报", route + "永盛-08折边-03工序汇报\\0803折边_工序汇报.exe");
|
|
//LeftPageTab.Rows.Add("0503", "制袋用料登记", route + "永盛-09制袋-01用料登记10028\\0901制袋_材料登记.exe");
|
|
//LeftPageTab.Rows.Add("0504", "制袋余料登记", route + "永盛-09制袋-02余料登记\\0902制袋_余料登记.exe");
|
|
//LeftPageTab.Rows.Add("0505", "制袋成品汇报", route + "永盛-09制袋-03成品汇报\\0903制袋_成品汇报.exe");
|
|
//foreach (DataRow item in LeftPageTab.Rows)
|
|
//{
|
|
// string sql = string.Format("insert into exeFilepath(menustruct,menusName,route) values('{0}','{1}','{2}')", item["menustruct"], item["menusName"], item["route"]);
|
|
// SqlHelper.ExecuteNonQuery(sql);
|
|
//}
|
|
|
|
|
|
string sql = "select * from exeFilepath ";
|
|
LeftPageTab = SqlHelper.ExecuteDataTable(sql).Copy();
|
|
|
|
SqlHelper._connection.Close();
|
|
//SqlHelper._connection.Dispose();
|
|
}
|
|
#endregion
|
|
#region 构造界面左右表格数据
|
|
/// <summary>
|
|
/// <para>说明:构建左右表格数据方法</para>
|
|
/// <para>创建人:王一帆</para>
|
|
/// <para>创建日期:2021-12-02 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
/// <param name="sender">The sender.</param>
|
|
/// <param name="e">The <see cref="PopupMenuShowingEventArgs"/> instance containing the event data.</param>
|
|
public void InitGridLoad()
|
|
{
|
|
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_MainCenter.Width - pl_center_main_right.Width; // 内容区域宽度-右侧快捷栏宽度
|
|
string defaultParentMenu = string.Empty;
|
|
MenuBar.ButtonHoverEventHandler hoverEvent = null;
|
|
|
|
foreach (DataRow item in LeftPageTab.Rows)
|
|
{
|
|
string menuStruct = item["menustruct"] + "";
|
|
// 加载左侧菜单
|
|
if (menuStruct.Length == 2)
|
|
{
|
|
menuLeft = Convert.ToInt32(0.05 * DpiX); menuTop = Convert.ToInt32(0.05 * DpiY);
|
|
//加载左侧菜单栏
|
|
MenuBar button = new MenuBar();
|
|
button.Size = new Size(Convert.ToInt32(1.52 * DpiX), Convert.ToInt32(0.46 * DpiX));
|
|
button.Location = new Point(2, buttonTop);
|
|
button.BackColor = System.Drawing.Color.Transparent;
|
|
button.GetButton().Text = item["menusName"] + "";
|
|
button.GetButton().Tag = item;
|
|
// 注册事件
|
|
hoverEvent += new MenuBar.ButtonHoverEventHandler(OnTriggerMenu);
|
|
button.SetHoverEvent(hoverEvent, (MenuEventType)SystemInfo.Instance.MemuEventType);
|
|
// 44
|
|
buttonTop += Convert.ToInt32(0.45 * DpiY);
|
|
if (menuStruct == defaultParentMenu)
|
|
{
|
|
button.SetDefaultSelectMenu(button);
|
|
button.SetButtonState(MenuButtonState.selectState);
|
|
}
|
|
pl_MainLeft.Controls.Add(button);
|
|
// 缓存控件
|
|
if (!_menus.Keys.Contains(menuStruct))
|
|
{
|
|
_menus.Add(menuStruct, new List<Menu_Item>());
|
|
}
|
|
}
|
|
this.pl_MainLeft.Width = Convert.ToInt32(1.52 * DpiX);
|
|
// 加载右侧模块
|
|
if (menuStruct.Length == 4)
|
|
{
|
|
//string defaultImg = PubUtil.MainMenuDefaultImage + item["MouseOutImg"] + "";
|
|
//string hoverImg = PubUtil.MainMenuDefaultImage + item["MouseOverImg1"] + "";
|
|
//string[] menuTag = new string[] { item["DllFileName"] + "", item["PurviewId"] + "", item["MenuId"] + "", item["UrlParams"] + "", item["SubSysId"] + "", item["menucaption"] + "" };
|
|
|
|
Menu_Item menu = new Menu_Item();
|
|
menu.menuRow = 0;
|
|
menu.Name = item["menustruct"] + "";
|
|
menu.Size = new Size(menuWidth, menuHeight);
|
|
menu.menuNode = menuStruct.Substring(0, 2);
|
|
menu.SetMenuCaption(item["menusName"] + "");
|
|
menu.SetRoundRadius = 20;
|
|
//menu.GetButton().Tag = menuTag;
|
|
menu.GetButton().Tag = item["route"];
|
|
menu.GetButton().Click += OnMenuItemClick;
|
|
|
|
//menu.SetMenuImg(File.Exists(defaultImg) ? Image.FromFile(defaultImg) : Resources.default_icon);
|
|
//menu.SetMenuHoverImg(File.Exists(hoverImg) ? Image.FromFile(hoverImg) : Resources.default_icon);
|
|
// 116
|
|
//menuLeft += Convert.ToInt32(1.20 * DpiX);
|
|
//后台配置模块所在行数
|
|
if (menu.menuRow > 0)
|
|
{
|
|
int count = _menuItemList.Where(o => o.menuRow == menu.menuRow && o.menuNode == menu.menuNode).Count();
|
|
menuLeft = count == 0 ? 5 : count * Convert.ToInt32(1.20 * DpiX) + 5;
|
|
menuTop = menuHeight * (menu.menuRow - 1);
|
|
menu.Location = new Point(menuLeft, menuTop);
|
|
}
|
|
else
|
|
{
|
|
menu.Location = new Point(menuLeft, menuTop);
|
|
menuLeft += Convert.ToInt32(1.20 * DpiX);
|
|
// 换行显示
|
|
if (menuLeft + menuWidth > centerWidth)
|
|
{
|
|
menuLeft = 5;
|
|
menuTop += menuHeight;
|
|
}
|
|
}
|
|
// 默认显示
|
|
if (defaultParentMenu != menuStruct.Substring(0, 2))
|
|
{
|
|
menu.Visible = false;
|
|
}
|
|
pl_MainCenter.Controls.Add(menu);
|
|
|
|
List<Menu_Item> controls = new List<Menu_Item>();
|
|
if (_menus.TryGetValue(menuStruct.Substring(0, 2), out controls))
|
|
{
|
|
controls.Add(menu);
|
|
}
|
|
this._menuItemList.Add(menu);
|
|
}
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region 切换模块
|
|
/// <summary>
|
|
/// <para>说明:切换模块</para>
|
|
/// <para>创建人:王一帆</para>
|
|
/// <para>创建日期:2021-12-03 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
/// <param name="before">The before.</param>
|
|
/// <param name="after">The after.</param>
|
|
public void OnTriggerMenu(Button before, Button after)
|
|
{
|
|
try
|
|
{
|
|
if (before != null)
|
|
{
|
|
DataRow item_before = before.Tag as DataRow;
|
|
DataRow item_after = after.Tag as DataRow;
|
|
if (item_before != null)
|
|
{
|
|
List<Menu_Item> beforeButtons = new List<Menu_Item>();
|
|
List<Menu_Item> afterButtons = new List<Menu_Item>();
|
|
|
|
// 隐藏控件
|
|
if (_menus.TryGetValue(item_before["menustruct"] + "", out beforeButtons))
|
|
{
|
|
foreach (Menu_Item item in beforeButtons)
|
|
{
|
|
item.Visible = false;
|
|
}
|
|
}
|
|
|
|
// 显示控件
|
|
if (_menus.TryGetValue(item_after["menustruct"] + "", out afterButtons))
|
|
{
|
|
foreach (Menu_Item item in afterButtons)
|
|
{
|
|
item.Visible = true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
string Message = ErrorMessage.PromptErrorMessage(ex);
|
|
MessageUtil.Show(Message, ex.Message);
|
|
}
|
|
|
|
}
|
|
#endregion
|
|
#endregion
|
|
#region 事件
|
|
#region 功能图标打开模块
|
|
/// <summary>
|
|
/// 功能图标打开模块
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
public void OnMenuItemClick(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
|
|
Button item = (Button)sender;
|
|
string arr = (string)item.Tag;
|
|
if (!string.IsNullOrWhiteSpace(arr))
|
|
{
|
|
arr = Lskj.Util.PubUtil.AbsolutelyPath + arr;
|
|
Process process = new Process();
|
|
ProcessStartInfo start = new ProcessStartInfo(arr);
|
|
process.StartInfo = start;
|
|
process.Start();
|
|
|
|
//Panel panel = new Panel();
|
|
|
|
//fr = new exetowinform(panel, "");
|
|
//fr.Start(arr);
|
|
//this.Controls.Add(panel);
|
|
|
|
//Manager.TabMain = this.xtraTabControl1;
|
|
//Manager.MinusTheHeight = this.lbTitle.Height ;
|
|
//Manager.OpenModule("cs", arr);
|
|
}
|
|
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
string Message = ErrorMessage.PromptErrorMessage(ex);
|
|
MessageUtil.Show(Message, ex.Message);
|
|
}
|
|
}
|
|
#endregion
|
|
#region 关闭
|
|
/// <summary>
|
|
/// 界面关闭触发事件
|
|
/// </summary>
|
|
public void FrmCloseClick(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
if (ERPInfo.Instance.SubMenuCount == 1)
|
|
{
|
|
if (MessageUtil.Show(ResourceKeys.IsExit, MessageBoxButtons.YesNo) == DialogResult.Yes)
|
|
{
|
|
this.Dispose();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
this.Dispose();
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
string Message = ErrorMessage.PromptErrorMessage(ex);
|
|
MessageUtil.Show(Message, ex.Message);
|
|
}
|
|
|
|
}
|
|
#endregion
|
|
#region 最小化
|
|
/// <summary>
|
|
/// <para>说明:最小化按钮点击</para>
|
|
/// <para>创建人:王一帆</para>
|
|
/// <para>创建日期:2021-12-06 </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 OnBtnMinClick(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
this.WindowState = FormWindowState.Minimized;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
string Message = ErrorMessage.PromptErrorMessage(ex);
|
|
MessageUtil.Show(Message, ex.Message);
|
|
}
|
|
|
|
}
|
|
#endregion
|
|
#endregion
|
|
|
|
|
|
|
|
}
|
|
}
|