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; /// /// 服务器地址 /// public string ServerAddress; /// /// 数据库名称 /// public string ServerDBName; /// /// 右键菜单ID /// public string RightMenuID; /// /// 主键Key /// public string PrimaryKey; /// /// 主键值 /// public string PrimaryValue; /// /// 用户ID /// public string UserID; /// /// 用户名 /// public string UserName; /// /// 模块编号 /// public string ModuleCode; /// /// 用户密码 /// public string Password; public FrmMain() { InitializeComponent(); } /// /// 说明:窗口加载 /// 创建人:龚宇超 /// 创建日期: /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The sender. /// The instance containing the event data. 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 paramListEx = mRightModel.ParamList; List 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); } } /// /// 说明:处理右键菜单10个扩展参数 /// 创建人:龚宇超 /// 创建日期:2017-10-30 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The parameter list. protected virtual List HandleRightMenuParams(List paramList, DataRow rowData) { List handleParamList = new List(); 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; } } }