using DevExpress.Utils;
using DevExpress.XtraGrid.Columns;
using DevExpress.XtraTab;
using Lskj.Business;
using Lskj.Business.Impl;
using Lskj.Control.Model;
using Lskj.Data;
using Lskj.Model;
using Lskj.Util;
using System;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Xilium.CefGlue;
namespace Lskj.Control.BrowserSetting
{
public class BsOpenModuleHandler : CefV8Handler
{
public CefV8Context V8Context;
public BsOpenModuleHandler()
{
}
protected override bool Execute(string name, CefV8Value obj, CefV8Value[] arguments, out CefV8Value returnValue, out string exception)
{
CefV8Value outreturnValue = null;
string outexception = "";
bool outtrn = false;
if (name == "OpenModule" && arguments.Length == 5)
{
CefProcessMessage cefProcessMessage = CefProcessMessage.Create("OpenModule");
cefProcessMessage.Arguments.SetString(0, arguments[0].GetStringValue());
cefProcessMessage.Arguments.SetString(1, arguments[1].GetStringValue());
cefProcessMessage.Arguments.SetString(2, arguments[2].GetStringValue());
cefProcessMessage.Arguments.SetString(3, arguments[3].GetStringValue());
cefProcessMessage.Arguments.SetString(4, arguments[4].GetStringValue());
V8Context.GetFrame().SendProcessMessage(CefProcessId.Browser, cefProcessMessage);
outreturnValue = CefV8Value.CreateUndefined();
outexception = null;
outtrn = true;
}
else if (name == "OpenOnRightClick" && arguments.Length == 4)
{
CefProcessMessage cefProcessMessage = CefProcessMessage.Create("OpenOnRightClick");
cefProcessMessage.Arguments.SetString(0, arguments[0].GetStringValue());
cefProcessMessage.Arguments.SetString(1, arguments[1].GetStringValue());
cefProcessMessage.Arguments.SetString(2, arguments[2].GetStringValue());
cefProcessMessage.Arguments.SetString(3, arguments[3].GetStringValue());
V8Context.GetFrame().SendProcessMessage(CefProcessId.Browser, cefProcessMessage);
outreturnValue = CefV8Value.CreateUndefined();
outexception = null;
outtrn = true;
}
else if (name == "CloseWin" && arguments.Length == 0)
{
CefProcessMessage cefProcessMessage = CefProcessMessage.Create("CloseWin");
V8Context.GetFrame().SendProcessMessage(CefProcessId.Browser, cefProcessMessage);
outreturnValue = CefV8Value.CreateUndefined();
outexception = null;
outtrn = true;
}
else if (name == "SelectPro" && arguments.Length == 2)
{
CefProcessMessage cefProcessMessage = CefProcessMessage.Create("SelectPro");
cefProcessMessage.Arguments.SetString(0, arguments[0].GetStringValue());
cefProcessMessage.Arguments.SetString(1, arguments[1].GetStringValue());
V8Context.GetFrame().SendProcessMessage(CefProcessId.Browser, cefProcessMessage);
outreturnValue = CefV8Value.CreateUndefined();
outexception = null;
outtrn = true;
}
else
{
outreturnValue = null;
outexception = "Invalid method call";
outtrn = false;
}
returnValue = outreturnValue;
exception = outexception;
return outtrn;
}
///
/// 说明:调用右键方法
/// 创建人:龚宇超
/// 创建日期:2017-08-18
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
///
///
///
///
public static void OpenRightModule(string arrayItem, string rightId, string MenuName, string mMenuCode)
{
DataRow item = BaseImpl.GetDataRowResult(string.Format(@"select * from P_systempopupmenu where id='{0}'", rightId));
if (item != null)
{
GridRightMenuModel menuModel = new GridRightMenuModel(item);
BaseRightMenu menu = new BaseRightMenu();
menu.Model = new DynamicModel(new string[] { MenuName, ERPInfo.Instance.UserId, ERPInfo.Instance.UserName, "1", mMenuCode });
//DataRow[] dataRows = JsonHandler.ParseJsonArrayToDataRows(arrayItem);
//JArray jArray = (JArray)JsonConvert.DeserializeObject(arrayItem);
DataTable dataTable = JsonUtil.ToDataTablePreservingComplexValues(arrayItem);
if (dataTable != null && dataTable.Rows.Count > 0)
{
menu.ExecRightMenu(menuModel, dataTable.Select());
}
}
else
{
MessageUtil.Show("未找到右键id!");
}
}
///
/// 说明:打开模块
/// 创建人:龚宇超
/// 创建日期:2017-08-18
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
/// The menu identifier.
/// Name of the menu.
/// The model flag.
/// The URL parameters.
public static void OpenModule(string menuId, string menuName, string dllName, string modelFlag, string urlParams)
{
try
{
// 验证参数
if (string.IsNullOrWhiteSpace(dllName))
{
MessageUtil.Show(ResourceKeys.NotFoundMenu);
return;
}
// 验证权限
int purview = 1;
if (!string.IsNullOrEmpty(menuId))
{
// 验证权限
purview = MainImpl.GetUserPurviewsByMenuId(menuId);
if (purview == 0)
{
MessageUtil.Show(ResourceKeys.UnPurview);
return;
}
}
LogUtil.WriteDebug(urlParams + "", "操作模块", 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 (SystemInfo.Instance.SoftOpenMode)
{
foreach (XtraTabPage tablepage in ERPInfo.Instance.PageControl.TabPages)
{
if (tablepage.Text == menuName)
{
MessageUtil.Show("已设置不能打开多个相同模块!");
ERPInfo.Instance.PageControl.SelectedTabPage = tablepage;
return;
}
}
}
if (dllName.ToLower().Contains(".exe"))
{
WinHelper.WinExec(dllName);
}
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);
}
else
{
if (dllName.ToLower().EndsWith(".lsp"))
{
//MessageBox.Show(PubUtil.AbsolutelyLibPath + dllName+" "+ menuName+" "+purview+" "+urlParams);
// 打开delphi程序
DelphiHelper.LoadDelphiDll(PubUtil.AbsolutelyLibPath + dllName, "", menuName, "", "", purview, urlParams);
}
else
{
// 打开module程序
AddModuleToTab(module, args);
}
}
}
catch (Exception ex)
{
string Message = ErrorMessage.PromptErrorMessage(ex);
MessageUtil.Show(Message, ex.Message);
}
}
///
/// 说明:特殊dll模块处理
/// 创建人:龚宇超
/// 创建日期:2018-04-20
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
/// Name of the DLL.
/// System.String.
private static string ReplaceDllFileName(string dllName)
{
switch (dllName.ToLower().Trim())
{
case "pubspec.dll":
dllName = "Lskj.PubSpec.dll";
break;
}
return dllName;
}
///
/// 说明:添加模块到tab中
/// 创建人:龚宇超
/// 创建日期:2017-08-16
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
/// The tab main.
/// The module.
/// The arguments.
public static void AddModuleToTab(DllModule module, string[] args)
{
try
{
string guid = Guid.NewGuid().ToString();
XtraTabPage tp = new XtraTabPage();
ERPInfo.Instance.selectFormModleId = module.Id;
IForm iform = FormHelper.LoadDllForm(module.DllName, args);
// 菜单打开的模块默认最大化,界面FormState设置为Normal模式,否则会出现界面不是全屏,会显示默认阴影界面
//iform.SubForm.WindowState = _frmMain.WindowState;
iform.SubForm.WindowState = FormWindowState.Normal; ;
Form form = iform.SubForm; // 表示组成应用程序的用户界面的窗口或对话框。
form.Tag = guid;
tp.Text = module.Name;
tp.Tag = guid;
// 这个必须有不然会提示:"不能向tabControl中添加顶级控件"
form.TopLevel = false;
//form.Location = new Point(0, 0);
form.Dock = DockStyle.Fill;//客户需要缩放
form.AutoSize = true;
//form.Width = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Width;
//form.Height = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Height - MinusTheHeight;
form.FormBorderStyle = FormBorderStyle.None;
tp.AutoScroll = true;
tp.Controls.Add(form);
tp.ShowCloseButton = DefaultBoolean.True;
tp.Dock = DockStyle.Fill;
//module.Tag = "1";
module.Tag = guid;
module.ModuleForm = form;
form.Show();
if (args != null && !string.IsNullOrEmpty(args[4] + ""))
{
ModuleModel moduleModel = new ModuleModel(MainImpl.GetSystemdllTab(args[4] + ""));
if (!string.IsNullOrEmpty(moduleModel.SearchCondFormModuleCode))
{
ModuleConditionsPanelEx mcpex = new ModuleConditionsPanelEx();
mcpex.InitializeControl(new ModuleModel(MainImpl.GetSystemdllTab(moduleModel.SearchCondFormModuleCode)), null, null, true);
if (StaticControl.ConditionsPanelDic.ContainsKey(args[4] + ""))
{
StaticControl.ConditionsPanelDic[args[4] + ""].Dispose();
StaticControl.ConditionsPanelDic[args[4] + ""] = mcpex;
}
else
{
StaticControl.ConditionsPanelDic.Add(args[4] + "", mcpex);
}
DialogResult dialogResult = mcpex.ShowDialog();
}
}
ERPInfo.Instance.PageControl.TabPages.Add(tp);
ERPInfo.Instance.PageControl.SelectedTabPage = tp;
ERPInfo.Instance.ModuleForms.Add(guid, module);
}
catch (Exception ex)
{
string Message = ErrorMessage.PromptErrorMessage(ex);
MessageUtil.Show(ex.InnerException != null ? ex.InnerException.Message : ex.Message);
LogHelper.Instance.WriteError(ex);
//LogUtil.WriteError("打开" + module.Name + "模块失败!", ex);
}
}
public static void AddReturnRow(string rowdata)
{
if (!string.IsNullOrWhiteSpace(rowdata) && StaticControl.RightMenuGridView != null)
{
DataTable dataTable = JsonUtil.ToDataTablePreservingComplexValues(rowdata);
DataTable gridTable = (StaticControl.RightMenuGridView.GridControl.DataSource as DataTable).TrimDeleteRows();
if (gridTable == null) return;
GridColumnCollection gridColumns = StaticControl.RightMenuGridView.Columns;
if (!string.IsNullOrWhiteSpace(StaticControl.Comprefix) && dataTable.Columns.Contains("ProductId"))
{
dataTable.Columns["ProductId"].ColumnName = StaticControl.Comprefix+"ProductId"; // 将ProductId加上前缀
}
DataRow rowItem = dataTable.Rows[0];
StaticControl.ReturnRowLisy.Add(rowItem);
}
}
}
}