Files
lserp_cs_6.0/插件库/Lskj.CallLibrary/FrmMain.cs
T
cyf ab56a9bcf7 基线 SVN r240
SVN-Revision: r240
2025-02-06 06:46:06 +00:00

233 lines
9.7 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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.Model;
using Lskj.Business.Impl;
using Lskj.Control;
using Lskj.Util;
using Lskj.Control.Model;
using Lskj.Core;
using Lskj.Data;
using System.Diagnostics;
using System.Text.RegularExpressions;
using Lskj.Business;
namespace Lskj.CallLibrary
{
public partial class FrmMain : Form
{
private GridRightMenuModel mRightModel;
private ModuleModel mBaseModel;
/// <summary>
/// 服务器地址
/// </summary>
public string ServerAddress;
/// <summary>
/// 数据库名称
/// </summary>
public string ServerDBName;
/// <summary>
/// 右键菜单ID
/// </summary>
public string RightMenuID;
/// <summary>
/// 主键Key
/// </summary>
public string PrimaryKey;
/// <summary>
/// 主键值
/// </summary>
public string PrimaryValue;
/// <summary>
/// 用户ID
/// </summary>
public string UserID;
/// <summary>
/// 用户名
/// </summary>
public string UserName;
/// <summary>
/// 模块编号
/// </summary>
public string ModuleCode;
/// <summary>
/// 用户密码
/// </summary>
public string Password;
public FrmMain()
{
InitializeComponent();
}
/// <summary>
/// <para>说明:窗口加载</para>
/// <para>创建人:龚宇超</para>
/// <para>创建日期: </para>
/// <para>修改人:</para>
/// <para>修改日期:</para>
/// <para>修改备注:</para>
/// <para>版本:1.0</para>
/// </summary>
/// <param name="sender">The sender.</param>
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
void OnLoad(object sender, EventArgs e)
{
try
{
DBConfig.Instance.CreateConnection();
DataRow modelRow = MainImpl.GetSystemdllTab(this.ModuleCode);
DataRow rightRow = BaseModuleImpl.GetBaseGridRightMenuByID(this.RightMenuID);
ERPInfo.Instance.UserId = this.UserID;
ERPInfo.Instance.UserName = this.UserName;
ERPInfo.Instance.Password = this.Password;
if (modelRow == null)
{
MessageUtil.Show("模块编号[" + this.ModuleCode + "],配置错误!\r\n该模块信息未找到!");
Application.Exit();
}
if (rightRow == null)
{
MessageUtil.Show("右键菜单[" + this.RightMenuID + "],配置错误!\r\n菜单信息未找到!");
Application.Exit();
}
this.mBaseModel = new ModuleModel(modelRow);
this.mRightModel = new GridRightMenuModel(rightRow);
if (string.IsNullOrEmpty(this.mBaseModel.MenuSql))
{
MessageUtil.Show("模块[" + this.ModuleCode + "],配置错误!\r\n未配置模块SQL");
Application.Exit();
}
string menuSQL = ReplaceHelper.ReplaceUserInfo(this.mBaseModel.MenuSql);//替换userid、username、groupid
bool isSelectStrat = menuSQL.Trim().StartsWith("select", StringComparison.OrdinalIgnoreCase);
string condSql = string.Empty;
string newMenuSql= this.mBaseModel.MenuSql;
string[] newPrimaryKey = PrimaryKey.Split('|');
string[] newPrimaryValue = PrimaryValue.Split('|');
if (newPrimaryKey.Length!= newPrimaryValue.Length)
{
MessageUtil.Show("配置错误!\r\n参数4与参数5数目不匹配!");
Application.Exit();
}
for (int i = 0; i < newPrimaryKey.Length; i++)
{
if (isSelectStrat) {
condSql += string.Format(" and {0}='{1}'", newPrimaryKey[i], newPrimaryValue[i]);
}else
{
newMenuSql= newMenuSql.Replace(newPrimaryKey[i], newPrimaryValue[i]);
}
}
menuSQL = isSelectStrat? ReplaceHelper.ReplaceWhereCond(this.mBaseModel.MenuSql) + condSql:newMenuSql;
DataTable table = BaseImpl.GetDataTableResult(menuSQL);
if (table != null && table.Rows.Count > 0)
{
DataRow rowItem = table.Rows[0];
// 实现功能:跨帐套审批单据。
// 1、根据右键菜单类型执行右键菜单,参考右键菜单实现,替换参数从rowItem里面替换
List<string> paramListEx = mRightModel.ParamList;
List<string> paramList = null;
paramList = this.HandleRightMenuParams(paramListEx, rowItem);
DBConfig.Instance.ServerName = this.ServerAddress;
DBConfig.Instance.DataBase = this.ServerDBName;
DBConfig.Instance.CreateConnection();
if (DelphiHelper.Delphi_Init(new StringBuilder(DBConfig.Instance.GetDelphiConnection())) == 0)
{
MessageUtil.Show(ResourceKeys.UnConnectServer + "[By Delphi]");
Application.Exit();
}
// 2、调用插件库之前需要设置服务器连接地址
// 固定传入参数(窗口标题、操作员ID、操作员名称、权限、模版编号)
string[] defaultArgs = string.Format(ModuleArgs.DefaultArgs, this.mBaseModel.MenuText, ERPInfo.Instance.UserId, ERPInfo.Instance.UserName, 1, paramList[1] + "").Split('~');
string[] menuArgs = new string[] { paramList[0] + "", paramList[1] + "", paramList[2] + "", paramList[3] + "", paramList[4] + "", paramList[5] + "" };
string[] args = defaultArgs.Concat(menuArgs).ToArray();
IForm form = FormHelper.LoadDllForm(mRightModel.DllName.ToLower().Equals("lskj.pubaccraditation.dll") ? ResourceDynamic.PubAccraditation : ResourceDynamic.BaseAccraditation, args);
form.SubForm.ShowDialog();
Application.Exit();
}
else
{
MessageUtil.Show("根据主键Key和Value未找到对应的数据行!");
Application.Exit();
}
}
catch (Exception ex)
{
string Message = ErrorMessage.PromptErrorMessage(ex);
MessageUtil.Show(Message,ex.Message);
Application.Exit();
}
finally
{
Lskj.Control.Model.AutoSizeChange.ControllInitializeSize(this);
}
}
/// <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>
protected virtual List<string> HandleRightMenuParams(List<string> paramList, DataRow rowData)
{
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(ReplaceHelper.ReplaceRowParam(rowData, fieldValue.Replace("@", ""))) + "";
handleParamList.Add(value);
}
break;
case "#": // 需要传入的sql语句
handleParamList.Add(ReplaceHelper.ReplaceRowParam(rowData, fieldValue.Replace("#", "")) + "");
break;
case "[": //[FormTitle_格式数据
if (fieldValue.StartsWith("[FormTitle_"))
{
handleParamList.Add(ReplaceHelper.ReplaceRowParam(rowData, fieldValue.Replace("[FormTitle_", "")) + "");
}
else
{
handleParamList.Add(ReplaceHelper.ReplaceRowParam(rowData, fieldValue) + "");
}
break;
case "$": //传入参数不需要任何处理
handleParamList.Add(fieldValue.Replace("$", "") + "");
break;
default:
handleParamList.Add(ReplaceHelper.ReplaceRowParam(rowData, fieldValue) + "");
break;
}
}
else
{
handleParamList.Add(item);
}
}
return handleParamList;
}
}
}