ab56a9bcf7
SVN-Revision: r240
445 lines
18 KiB
C#
445 lines
18 KiB
C#
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.Control;
|
|
using Lskj.Data;
|
|
using Lskj.Business.Impl;
|
|
using Lskj.Business;
|
|
using Lskj.Model;
|
|
using Lskj.Util;
|
|
using System.Diagnostics;
|
|
using Lskj.Core;
|
|
using System.Threading;
|
|
|
|
namespace CensorModule
|
|
{
|
|
|
|
public partial class FrmMain : BaseForm
|
|
{
|
|
|
|
public FrmMain()
|
|
{
|
|
InitializeComponent();
|
|
InitializeControl();
|
|
this.TopLevel = true; //重要的一个步骤
|
|
}
|
|
#region 参数
|
|
private bool NewInitSuccess = false;//初始化标识字段
|
|
private int ModuleCount;//需要测试模块的个数
|
|
private bool isFinish;//是否加载完成
|
|
private DataTable MenuConfigdt;//获取所有模块表
|
|
#endregion
|
|
#region 模块检测方法
|
|
/// <summary>
|
|
/// <para>说明:开始模块检测方法</para>
|
|
/// <para>创建人:王一帆</para>
|
|
/// <para>创建日期:2020-03-19 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
|
|
public void start()
|
|
{
|
|
this.lbl_progress.Maximum = ModuleCount = MenuConfigdt.Rows.Count;
|
|
RefreshLogUIThread(string.Format("开始检测发布模板:\r\n"));
|
|
RefreshLogUIThread(string.Format("开始测试:.\r\n"));
|
|
for (int i = 0; i < MenuConfigdt.Rows.Count; i++)
|
|
{
|
|
DataRow rowItem = MenuConfigdt.Rows[i];
|
|
//更新进度条进度状态,当进度条为跑马灯模式时(ProgressBarStyle.Marquee)不可能调用该方法
|
|
this.lbl_progress.PerformStep();
|
|
//设置进度百分比
|
|
double dCount = ModuleCount, dProg = this.lbl_progress.Value;
|
|
this.lbl_progress.Text = (((i + 1) / dCount) * 100).ToString() + "%";
|
|
this.lab_Sop.Text = (i + 1) + "/" + dCount;
|
|
this.lab_Name.Text = "当前项目:" + rowItem["MenuCaption"] + "";
|
|
this.lbl_progress.Refresh();
|
|
OpenModule(rowItem["menuId"] + "", rowItem["MenuCaption"] + "", rowItem["DllFileName"] + "", rowItem["PurviewId"] + "", rowItem["UrlParams"] + "");
|
|
}
|
|
this.pl_Main.Controls.Clear();
|
|
isFinish = true;
|
|
MessageUtil.Show("加载完毕请统计错误信息!");
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:打开模块</para>
|
|
/// <para>创建人:王一帆</para>
|
|
/// <para>创建日期:2020-03-18 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
/// <param name="menuId">The menu identifier.</param>
|
|
/// <param name="menuName">Name of the menu.</param>
|
|
/// <param name="modelFlag">The model flag.</param>
|
|
/// <param name="urlParams">The URL parameters.</param>
|
|
public void OpenModule(string menuId, string menuName, string dllName, string modelFlag, string urlParams)
|
|
{
|
|
// 验证参数
|
|
if (string.IsNullOrWhiteSpace(menuId) || string.IsNullOrWhiteSpace(dllName))
|
|
{
|
|
MessageUtil.Show(ResourceKeys.NotFoundMenu);
|
|
return;
|
|
}
|
|
// 验证权限
|
|
int purview = MainImpl.GetUserPurviewsByMenuId(menuId);
|
|
if (purview == 0)
|
|
{
|
|
return;
|
|
}
|
|
LogUtil.WriteDebug(menuId.ToString(), "操作模块", menuName, menuName);
|
|
DllModule module = new DllModule
|
|
{
|
|
DllName = ReplaceDllFileName(dllName),
|
|
Id = menuId,
|
|
Name = menuName
|
|
};
|
|
string[] args = new string[]{
|
|
menuName,
|
|
ERPInfo.Instance.UserId,
|
|
ERPInfo.Instance.UserName,
|
|
purview + "",
|
|
urlParams,
|
|
menuId
|
|
};
|
|
dllName = MainImpl.GetDefaultValue(dllName);
|
|
|
|
if (dllName.ToLower().Contains(".exe"))
|
|
{
|
|
//WinHelper.WinExec(dllName);
|
|
return;
|
|
}
|
|
else if (dllName.ToLower().IndexOf("http:", StringComparison.OrdinalIgnoreCase) != -1 ||
|
|
dllName.ToLower().IndexOf("www.", StringComparison.OrdinalIgnoreCase) != -1 ||
|
|
dllName.ToLower().IndexOf("ftp:", StringComparison.OrdinalIgnoreCase) != -1)
|
|
{
|
|
//Process.Start(dllName);
|
|
return;
|
|
}
|
|
else
|
|
{
|
|
if (string.IsNullOrWhiteSpace(modelFlag))
|
|
{
|
|
//MessageBox.Show(PubUtil.AbsolutelyLibPath + dllName+" "+ menuName+" "+purview+" "+urlParams);
|
|
// 打开delphi程序
|
|
// DelphiHelper.LoadDelphiDll(PubUtil.AbsolutelyLibPath + dllName, "", menuName, "", "", purview, urlParams);
|
|
return;
|
|
}
|
|
else
|
|
{
|
|
// 打开module程序
|
|
OpenModuleText(module, args);
|
|
}
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:循环打开模块测试</para>
|
|
/// <para>创建人:王一帆</para>
|
|
/// <para>创建日期:2020-03-18 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
/// <param name="tabMain">The tab main.</param>
|
|
/// <param name="module">The module.</param>
|
|
/// <param name="args">The arguments.</param>
|
|
public void OpenModuleText(DllModule module, string[] args)
|
|
{
|
|
try
|
|
{
|
|
Application.DoEvents();
|
|
foreach (Form frm in this.pl_Main.Controls)
|
|
{
|
|
frm.Dispose();
|
|
}
|
|
IForm iform = FormHelper.LoadDllForm(module.DllName, args);
|
|
// 菜单打开的模块默认最大化,界面FormState设置为Normal模式,否则会出现界面不是全屏,会显示默认阴影界面
|
|
iform.SubForm.WindowState = FormWindowState.Maximized;
|
|
Form form = iform.SubForm;
|
|
form.TopLevel = false;
|
|
form.Dock = DockStyle.Fill;
|
|
form.FormBorderStyle = FormBorderStyle.None;
|
|
pl_Main.Controls.Add(form);
|
|
form.Show();
|
|
//LastModuleForm.Add(module);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
RefreshLogUIThread(DateTime.Now + "打开" + module.Name + "失败!" + "\r模块id:" + module.Id + "\r\n");
|
|
LogUtil.WriteError("打开" + module.Name + "模块失败!", ex);
|
|
|
|
}
|
|
}
|
|
#endregion
|
|
#region 初始化检测发布平台工具
|
|
/// <summary>
|
|
/// <para>说明:初始化检测发布平台工具</para>
|
|
/// <para>创建人:王一帆</para>
|
|
/// <para>创建日期:2020-03-19 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
|
|
private void InitializeControl()
|
|
{
|
|
try
|
|
{
|
|
RefreshLog(DateTime.Now + "正在初始化平台.\r\n");
|
|
if (DBConfig.Instance.CreateConnection())
|
|
{
|
|
DataTable table = MainImpl.GetEmployeeList();
|
|
isFinish = false;
|
|
DataRow[] drRows = table.Select("UserName='" + DBConfig.Instance.LoginName + "'");
|
|
DataRow drRow = drRows[0];
|
|
if (drRow != null)
|
|
{
|
|
ERPInfo.Instance.UserId = drRow["UserId"] + "";
|
|
ERPInfo.Instance.UserName = drRow["UserName"] + "";
|
|
}
|
|
MenuConfigdt = GetMenusByMenuType();
|
|
NewInitSuccess = true;
|
|
|
|
RefreshLog(DateTime.Now + "初始化平台成功.\r\n");
|
|
//获取指定目录下所有文件数量(实际过程忽略)
|
|
ModuleCount = 1;
|
|
ModuleCount = MenuConfigdt.Rows.Count > 0 ? MenuConfigdt.Rows.Count : ModuleCount;
|
|
//设置进度条基础属性
|
|
this.lbl_progress.Value = 0;
|
|
this.lbl_progress.Style = ProgressBarStyle.Blocks;
|
|
this.lbl_progress.Minimum = 0;
|
|
this.lbl_progress.MarqueeAnimationSpeed = 100;
|
|
this.lbl_progress.Step = 1;
|
|
this.lbl_progress.Text = "0%";
|
|
this.lbl_progress.Refresh();
|
|
|
|
}
|
|
else
|
|
{
|
|
RefreshLog(DateTime.Now + " 初始化平台失败.\r\n");
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
RefreshLog(DateTime.Now + string.Format("初始化失败.原因:{0}.\r\n", ex.Message));
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:初始化所有模块表</para>
|
|
/// <para>创建人:王一帆</para>
|
|
/// <para>创建日期:2020-03-19 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
/// <returns>DataTable.</returns>
|
|
public static DataTable GetMenusByMenuType()
|
|
{
|
|
// MainMenuType:1: 加载子系统菜单数据,2.加载所有菜单,3.加载子系统权限菜单,4.加载所有权限菜单
|
|
int menutype = SystemInfo.Instance.MainMenuType;
|
|
string condWhere = string.Empty;
|
|
string sqlValue = string.Empty;
|
|
|
|
if (menutype > 2)
|
|
{
|
|
// 获取权限
|
|
condWhere = MainImpl.GetPurviewCond();
|
|
}
|
|
if (MainImpl.HasExistsColumn("P_FormMenuConfigTab", "useFlag"))
|
|
{
|
|
// 获取可用菜单标识
|
|
condWhere += " and isnull(useFlag,0)=1";
|
|
}
|
|
if (MainImpl.HasExistsColumn("P_FormMenuConfigTab", "TargetMode"))
|
|
{
|
|
// 获取CS端显示标识(0 全部、1cs、 2 手机、3、bs)
|
|
condWhere += " and isnull(TargetMode,1) in (1)";
|
|
}
|
|
string fields = string.Empty, field = string.Empty;
|
|
if (MainImpl.HasExistsColumn("p_formmenuconfigtab", "menuRow"))
|
|
{
|
|
fields = ",menuRow";
|
|
field = "a.menuRow,";
|
|
}
|
|
// 加载所有菜单下的数据
|
|
sqlValue = string.Format(@"select * from (
|
|
select a.MenuId,a.MouseOutImg,a.MouseOverImg1,a.MenuCaption,a.DllFileName,a.MenuStruct,a.PurviewId,a.UrlParams,a.subsysid,{0}
|
|
z.SubSysName,MenuCaption+'-'+z.SubSysName SearchMenuCaption
|
|
FROM p_formmenuconfigtab a
|
|
left join P_SubSystemTab z on a.SubSysId=z.SubSysId
|
|
WHERE 1=1 " + condWhere + @") x
|
|
where LEN(x.MenuStruct)=4", field);
|
|
|
|
return SqlHelper.ExecuteDataTable(sqlValue);
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:初始化所有模块表</para>
|
|
/// <para>创建人:王一帆</para>
|
|
/// <para>创建日期:2020-03-19 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
/// <param name="dllName">Name of the DLL.</param>
|
|
/// <returns>System.String.</returns>
|
|
private static string ReplaceDllFileName(string dllName)
|
|
{
|
|
switch (dllName.ToLower().Trim())
|
|
{
|
|
case "pubspec.dll":
|
|
dllName = "Lskj.PubSpec.dll";
|
|
break;
|
|
}
|
|
return dllName;
|
|
}
|
|
#endregion
|
|
#region 刷新日志数据
|
|
/// <summary>
|
|
/// <para>说明:主线程刷新</para>
|
|
/// <para>创建人:王一帆</para>
|
|
/// <para>创建日期:2020-03-19 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
|
|
public void RefreshLog(string msg)
|
|
{
|
|
txtLog.Text += msg;
|
|
txtLog.Select(txtLog.TextLength, 0);
|
|
txtLog.ScrollToCaret();
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:后台线程刷新数据</para>
|
|
/// <para>创建人:王一帆</para>
|
|
/// <para>创建日期:2020-03-19 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
|
|
public void RefreshLogUIThread(string msg)
|
|
{
|
|
txtLog.Text += msg;
|
|
txtLog.Select(txtLog.TextLength, 0);
|
|
txtLog.ScrollToCaret();
|
|
}
|
|
#endregion
|
|
#region 点击事件
|
|
/// <summary>
|
|
/// <para>说明:点击开始</para>
|
|
/// <para>创建人:王一帆</para>
|
|
/// <para>创建日期:2020-03-18 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
/// <param name="dllName">Name of the DLL.</param>
|
|
/// <returns>System.String.</returns>
|
|
private void OnStartClick(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
if (isFinish) {
|
|
InitializeControl();//初始化
|
|
}
|
|
if (!this.che_All.Checked)
|
|
{
|
|
//string allMaxModelId = string.Empty;
|
|
//string modelIdItem = string.Empty;
|
|
//DataTable SomeTable = SqlHelper.ExecuteDataTable("select max(MenuId) as id from P_FormMenuConfigTab where DllFileName!='' group by DllFileName ");
|
|
//foreach (DataRow item in MenuConfigdt.Rows)
|
|
//{
|
|
// string MenuId = item["MenuId"] + "";
|
|
// foreach (DataRow someTable in SomeTable.Rows)
|
|
// {
|
|
// string someMenuId = someTable["id"] + "";
|
|
// if (MenuId.Equals(someMenuId))
|
|
// {
|
|
// allMaxModelId = allMaxModelId + someTable["id"] + ',';
|
|
// }
|
|
// }
|
|
//}
|
|
//modelIdItem = modelIdItem.Trim().TrimEnd(',');
|
|
//allMaxModelId = allMaxModelId.Trim().TrimEnd(',');
|
|
//MenuConfigdt = MenuConfigdt.Select(string.Format("MenuId in ({0})", allMaxModelId)).CopyToDataTable();
|
|
//MenuConfigdt.Compute("max(MenuId)", "");
|
|
MenuConfigdt.DefaultView.Sort = "MenuId DESC";
|
|
MenuConfigdt = MenuConfigdt.DefaultView.ToTable();
|
|
MenuConfigdt = MenuConfigdt.AsEnumerable().GroupBy(r => new { Col1 = r["DllFileName"] }).Select(g => g.OrderBy(r => r["DllFileName"]).First()).CopyToDataTable();
|
|
}
|
|
start();
|
|
}
|
|
catch (Exception)
|
|
{
|
|
|
|
throw;
|
|
}
|
|
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:点击重置界面</para>
|
|
/// <para>创建人:王一帆</para>
|
|
/// <para>创建日期:2020-03-18 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
/// <param name="dllName">Name of the DLL.</param>
|
|
/// <returns>System.String.</returns>
|
|
private void OnResetClick(object sender, EventArgs e)
|
|
{
|
|
|
|
InitializeControl();
|
|
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:选择全局查询</para>
|
|
/// <para>创建人:王一帆</para>
|
|
/// <para>创建日期:2020-03-18 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
/// <param name="dllName">Name of the DLL.</param>
|
|
/// <returns>System.String.</returns>
|
|
private void OnsomeCheckedChanged(object sender, EventArgs e)
|
|
{
|
|
|
|
this.che_All.Checked = !this.che_some.Checked;
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:选择部分查询</para>
|
|
/// <para>创建人:王一帆</para>
|
|
/// <para>创建日期:2020-03-18 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
/// <param name="dllName">Name of the DLL.</param>
|
|
/// <returns>System.String.</returns>
|
|
private void OnAllCheckedChanged(object sender, EventArgs e)
|
|
{
|
|
this.che_some.Checked = !this.che_All.Checked;
|
|
}
|
|
#endregion
|
|
}
|
|
}
|