c1680ca4dd
SVN-Revision: r752
435 lines
18 KiB
C#
435 lines
18 KiB
C#
/******************************
|
|
* 说明:辅助工具操作类
|
|
* 创建人:龚宇超
|
|
* 创建日期:2017-12-20
|
|
* 修改人:
|
|
* 修改日期:
|
|
* 修改备注:
|
|
* 版本:1.0.0.0
|
|
******************************/
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Data;
|
|
using System.Windows.Forms;
|
|
using Lskj.Util;
|
|
using Lskj.Business.Impl;
|
|
using System.Diagnostics;
|
|
using Lskj.Model;
|
|
using Lskj.Data;
|
|
using System.IO;
|
|
using System.Data.SqlClient;
|
|
using Lskj.Business;
|
|
using DevExpress.XtraGrid.Views.Grid;
|
|
|
|
namespace Lskj.Control.Model
|
|
{
|
|
/// <summary>
|
|
/// 辅助工具操作类
|
|
/// </summary>
|
|
public class CommonMenu
|
|
{
|
|
protected GridControlEx GridControlObj;
|
|
protected GridView BaseGridView;
|
|
private DynamicModel _model;
|
|
/// <summary>
|
|
/// 控件面板
|
|
/// </summary>
|
|
private MyControl _controlObj;
|
|
public bool issuccess = true;
|
|
/// <summary>
|
|
/// Occurs when [apply before].
|
|
/// </summary>
|
|
public event CommonToolApplyEventHandler ApplyBefore;
|
|
public event CommonToolAfterDynamicLinkEventHandler DynamicLinkAfter;
|
|
/// <summary>
|
|
/// Initializes a new instance of the <see cref="CommonMenu"/> class.
|
|
/// </summary>
|
|
/// <param name="rowItem">常用工具数据行.</param>
|
|
public CommonMenu(DynamicModel model, MyControl control, System.Windows.Forms.Control view = null)
|
|
{
|
|
this._model = model;
|
|
this._controlObj = control;
|
|
if (view != null) this.GridControlObj = view as GridControlEx;
|
|
if (this.GridControlObj != null)
|
|
{
|
|
this.BaseGridView = this.GridControlObj.GridView;
|
|
}
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// <para>说明:执行常用功能</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2017-12-20 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
/// <param name="rowItem">当前选中按钮绑定的数据源行</param>
|
|
/// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns>
|
|
public bool Apply(DataRow rowItem)
|
|
{
|
|
try
|
|
{
|
|
bool resultValue = false;
|
|
if (rowItem == null || this._controlObj == null) return resultValue;
|
|
|
|
GridRightMenuModel model = new GridRightMenuModel(rowItem);
|
|
|
|
if (!string.IsNullOrWhiteSpace(model.BeforeMsg))
|
|
{
|
|
string prompt = this._controlObj.ReplaceControlValue(model.BeforeMsg);
|
|
if (prompt.StartsWith("@") || prompt.StartsWith("!"))
|
|
{
|
|
prompt = BaseImpl.GetDefaultValue(prompt);
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(prompt))
|
|
{
|
|
DialogResult result = MessageUtil.Show(prompt, MessageBoxButtons.YesNo);
|
|
// DialogResult result = MessageUtil.Show(this._controlObj.ReplaceControlValue(model.BeforeMsg), MessageBoxButtons.YesNo);
|
|
if (result != DialogResult.Yes)
|
|
{
|
|
return resultValue;
|
|
}
|
|
}
|
|
}
|
|
|
|
ApplyArgs applyArgs = new ApplyArgs();
|
|
applyArgs.MemuModel = model;
|
|
if (ApplyBefore != null)
|
|
{
|
|
ApplyBefore(applyArgs);
|
|
}
|
|
|
|
if (applyArgs.CancelFlag) return false;
|
|
|
|
List<string> paramList = HandleRightMenuParams(model.ParamList);
|
|
|
|
string dllName = this._controlObj.ReplaceControlValue(model.DllName).Trim();
|
|
|
|
switch (model.ActionType)
|
|
{
|
|
case 1: // 执行存储过程
|
|
resultValue = ExecProcedure(model.Action, paramList);
|
|
break;
|
|
case 2: // 调用dll程序
|
|
resultValue = ExecDynamicLinkLibary(model, paramList, rowItem);
|
|
break;
|
|
case 3: //调用delphi程序
|
|
resultValue = ExecDelphiLibary(model.DllName, paramList);
|
|
break;
|
|
case 0: // 执行sql语句
|
|
resultValue = ExecSqlValue(model.Action);
|
|
break;
|
|
default:
|
|
// 特殊处理程序
|
|
if (dllName.EndsWith(".exe") && !model.WipeExes.Contains(dllName.ToString()))
|
|
{
|
|
// 执行exe程序
|
|
WinHelper.WinExec(dllName, 1);
|
|
}
|
|
else if (dllName.StartsWith("www.") ||
|
|
dllName.StartsWith("http://") ||
|
|
dllName.StartsWith("https://") ||
|
|
dllName.StartsWith("ftp://") ||
|
|
dllName.StartsWith("file://"))
|
|
{
|
|
// 打开网页程序
|
|
Process.Start(dllName);
|
|
}
|
|
break;
|
|
}
|
|
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogUtil.WriteError("执行常用功能出错!", ex);
|
|
//MessageUtil.Show("执行常用功能出错!" + ex);
|
|
string Message = ErrorMessage.PromptErrorMessage(ex);
|
|
MessageUtil.Show(Message, ex.Message);
|
|
}
|
|
return true;
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:处理常用工具菜单10个扩展参数</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2017-10-30 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
/// <param name="paramList">The parameter list.</param>
|
|
private List<string> HandleRightMenuParams(List<string> paramList)
|
|
{
|
|
List<string> handleParamList = new List<string>();
|
|
foreach (string item in paramList)
|
|
{
|
|
if (!string.IsNullOrWhiteSpace(item))
|
|
{
|
|
string fieldValue = ReplaceHelper.ReplaceUserInfo(item);
|
|
string firstChar = fieldValue.Substring(0, 1);
|
|
switch (firstChar)
|
|
{
|
|
case "@": // sql处理
|
|
{
|
|
string value = MainImpl.GetResult(this._controlObj.ReplaceControlValue(fieldValue.Replace("@", ""))) + "";
|
|
handleParamList.Add(value);
|
|
}
|
|
break;
|
|
case "{": // 字段特殊替换
|
|
{
|
|
|
|
handleParamList.Add(this._controlObj.ReplaceControlValue(item));
|
|
}
|
|
break;
|
|
case "#": // 需要传入的sql语句
|
|
handleParamList.Add(this._controlObj.ReplaceControlValue(fieldValue.Replace("#", "")));
|
|
break;
|
|
case "[": //[FormTitle_格式数据
|
|
if (fieldValue.StartsWith("[FormTitle_"))
|
|
{
|
|
handleParamList.Add(this._controlObj.ReplaceControlValue(fieldValue.Replace("[FormTitle_", "")));
|
|
}
|
|
else
|
|
{
|
|
handleParamList.Add(this._controlObj.ReplaceControlValue(fieldValue));
|
|
}
|
|
break;
|
|
default:
|
|
if (BaseGridView != null && BaseGridView.GetFocusedDataRow() != null)
|
|
{
|
|
DataRow parentitem = BaseGridView.GetFocusedDataRow();
|
|
fieldValue = ReplaceHelper.ReplaceRowParam(parentitem, item) + "";
|
|
}
|
|
handleParamList.Add(this._controlObj.ReplaceControlValue(fieldValue));
|
|
break;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
handleParamList.Add(item);
|
|
}
|
|
}
|
|
|
|
return handleParamList;
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:执行存储过程</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2017-10-31 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
/// <param name="procName">Name of the proc.</param>
|
|
/// <param name="paramList">The parameter list.</param>
|
|
/// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns>
|
|
private bool ExecProcedure(string procName, List<string> paramList)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(procName))
|
|
{
|
|
MessageUtil.Show(ResourceKeys.OperFault + "未配置执行存储过程.");
|
|
return false;
|
|
}
|
|
else
|
|
{
|
|
bool reaultValue = true;
|
|
List<string> procParams = ReplaceHelper.GetParamFields(procName);
|
|
if (procParams.Count == 0)
|
|
{
|
|
MessageUtil.Show(ResourceKeys.OperFault + "存储过程配置错误.");
|
|
return false;
|
|
}
|
|
|
|
string[] paramStr = procParams[0].Replace("{", "").Replace("}", "").Split(',');
|
|
|
|
List<SqlParameter> sqlParamList = new List<SqlParameter>();
|
|
SqlParameter pMsg = new SqlParameter("@msg", SqlDbType.VarChar, 2000);
|
|
for (int i = 0; i < paramStr.Length; i++)
|
|
{
|
|
string item = paramStr[i];
|
|
if (paramStr[i].Equals("@msg", StringComparison.OrdinalIgnoreCase))
|
|
{
|
|
pMsg.Direction = ParameterDirection.InputOutput;
|
|
pMsg.Value = "";
|
|
sqlParamList.Add(pMsg);
|
|
}
|
|
else
|
|
{
|
|
string paramStr1 = paramStr[i];
|
|
SqlParameter param = new SqlParameter(string.Format("{0}", paramStr1), SqlDbType.VarChar);
|
|
param.Value = paramList[i];
|
|
sqlParamList.Add(param);
|
|
}
|
|
}
|
|
|
|
SqlParameter returnValue = new SqlParameter("@return", SqlDbType.Int, 4);
|
|
returnValue.Direction = ParameterDirection.ReturnValue;
|
|
sqlParamList.Add(returnValue);
|
|
|
|
int result = MainImpl.ExecProcedure(procName.Replace(procParams[0], ""), sqlParamList.ToArray());
|
|
int rValue = Convert.ToInt32(returnValue.Value);
|
|
|
|
switch (rValue)
|
|
{
|
|
case -1:
|
|
MessageUtil.Show(ResourceKeys.OperFault + "\n" + pMsg.Value);
|
|
reaultValue = false;
|
|
break;
|
|
case 99:
|
|
MessageUtil.Show(pMsg.Value + "");
|
|
break;
|
|
case 9999:
|
|
FrmPrompt frmPrompt = new FrmPrompt(pMsg.Value + "");
|
|
DialogResult dialogResult = frmPrompt.ShowDialog();
|
|
if (dialogResult == DialogResult.OK)
|
|
{
|
|
SqlParameter param = sqlParamList.FirstOrDefault(x => "@msg".Equals(x.ParameterName));
|
|
param.Value = frmPrompt.PromptMsg;
|
|
|
|
this.ExecProcedure(procName, paramList);
|
|
}
|
|
break;
|
|
default:
|
|
MessageUtil.Show(ResourceKeys.OperSuccess);
|
|
break;
|
|
}
|
|
return reaultValue;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:执行sql语句</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2017-10-31 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
/// <param name="sqlValue">The SQL value.</param>
|
|
/// <param name="rowData">The row data.</param>
|
|
private bool ExecSqlValue(string sqlValue)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(sqlValue))
|
|
{
|
|
MessageUtil.Show(ResourceKeys.OperFault + "未配置执行sql语句");
|
|
return false;
|
|
}
|
|
else
|
|
{
|
|
MainImpl.GetResult(this._controlObj.ReplaceControlValue(sqlValue));
|
|
MessageUtil.Show(ResourceKeys.OperSuccess);
|
|
}
|
|
return true;
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:执行动态链接库</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2017-11-01 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
/// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns>
|
|
private bool ExecDynamicLinkLibary(GridRightMenuModel model, List<string> paramList, DataRow rowItem)
|
|
{
|
|
issuccess = true;
|
|
if (string.IsNullOrWhiteSpace(model.DllName))
|
|
{
|
|
MessageUtil.Show(ResourceKeys.OperFault + "未配置动态链接库.");
|
|
return false;
|
|
}
|
|
else
|
|
{
|
|
switch (model.DllName.ToLower())
|
|
{
|
|
case "iexplore.exe": // 调用ie浏览器
|
|
string url = (paramList[0] + Uri.EscapeUriString(paramList[1])).Replace("#", "%23");
|
|
Process.Start("iexplore.exe", url);
|
|
break;
|
|
case "lstest.exe": // 调用附件下载
|
|
StringBuilder dfile = new StringBuilder();
|
|
StringBuilder rfile = new StringBuilder();
|
|
|
|
int hwnd = 0;
|
|
|
|
dfile.Append(paramList[0] + paramList[1]);
|
|
rfile = DelphiHelper.DownloadAttach(dfile, hwnd);
|
|
rfile.Clear();
|
|
rfile.Append(PubUtil.FileDownLoadTempPath + Path.GetFileName(dfile.ToString()));
|
|
if (File.Exists(rfile.ToString()))
|
|
{
|
|
Process.Start(rfile.ToString(), "");
|
|
}
|
|
break;
|
|
default:
|
|
List<string> str = new List<string>
|
|
{
|
|
_model.FormText,
|
|
ERPInfo.Instance.UserId,
|
|
ERPInfo.Instance.UserName,
|
|
"3",
|
|
_model.ModuleCode,
|
|
paramList[0],
|
|
paramList[1],
|
|
paramList[2],
|
|
paramList[3],
|
|
paramList[4],
|
|
paramList[5],
|
|
paramList[6],
|
|
paramList[7],
|
|
paramList[8],
|
|
paramList[9]
|
|
};
|
|
string maintabFocusedRowJson = "";
|
|
if (BaseGridView != null && BaseGridView.GetFocusedDataRow() != null)
|
|
{
|
|
maintabFocusedRowJson = BaseGridView.GetFocusedDataRow().ToJsonObject(); // 假设 ToJsonObject() 是将对象转换为 JSON 字符串的方法
|
|
}
|
|
str.Add(maintabFocusedRowJson); // 现在可以添加元素了,因为 str 是 List<string>
|
|
// 假设你需要将 List<string> 转回字符串数组,可以这样操作
|
|
string[] strArray = str.ToArray();
|
|
IForm form = FormHelper.LoadDllForm(model.DllName, strArray);
|
|
if (form == null)
|
|
{
|
|
MessageUtil.Show(ResourceKeys.DyncmicDllNotFount);
|
|
return false;
|
|
}
|
|
if (form.SubForm == null)
|
|
{
|
|
MessageUtil.Show(ResourceKeys.DyncmicDllInitFault);
|
|
return false;
|
|
}
|
|
form.SubForm.WindowState = model.MaxWindow ? FormWindowState.Maximized : FormWindowState.Normal;
|
|
form.SubForm.Text = model.MenuName;
|
|
if (form.SubForm is BaseForm)
|
|
{
|
|
(form.SubForm as BaseForm).ParentView = this.BaseGridView;
|
|
}
|
|
form.SubForm.ShowDialog();
|
|
if (DynamicLinkAfter != null)
|
|
{
|
|
ApplyArgs applyArgs = new ApplyArgs();
|
|
applyArgs.MemuModel = model;
|
|
if (form.SubForm.Tag != null && form.SubForm.Tag is FormDialogModel)
|
|
{
|
|
applyArgs.DialogModel = form.SubForm.Tag as FormDialogModel;
|
|
}
|
|
DynamicLinkAfter(this, applyArgs);
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期� |