5c53ca5957
SVN-Revision: r484
334 lines
15 KiB
C#
334 lines
15 KiB
C#
using Lskj.Business.Impl;
|
|
using Lskj.Control;
|
|
using Lskj.Core;
|
|
using Lskj.Util;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Data.SqlClient;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Windows.Forms;
|
|
|
|
namespace Lskj.PubApiSetModule
|
|
{
|
|
public partial class FrmMain : BaseForm
|
|
{
|
|
public DynamicApiSetModel Model;
|
|
public SqlDataAdapter SendMainAdapterObj;
|
|
public SqlDataAdapter SendDetailAdapterObj;
|
|
public FrmMain()
|
|
{
|
|
InitializeComponent();
|
|
this.Load += OnFrmMainLoad;
|
|
}
|
|
/// <summary>
|
|
/// 初始化时
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void OnFrmMainLoad(object sender, EventArgs e)
|
|
{
|
|
InitlizeSpiltLocation();
|
|
InitEventApiTable();
|
|
InitEventApiPmsTable();
|
|
InitEvents();
|
|
InitColumnsData();
|
|
InitApiTabDataSource();
|
|
}
|
|
/// <summary>
|
|
/// 初始化事件
|
|
/// </summary>
|
|
private void InitEvents()
|
|
{
|
|
splitControlSend.SplitterPositionChanged += OnSplitContainerPositionChanged; ;
|
|
sendMainView.FocusedRowObjectChanged += OnSendMainViewFocusedRowObjectChanged;
|
|
btnApiAdd.Click += OnBtnAddClick;
|
|
btnApiDelete.Click += OnBtnDeleteClick;
|
|
btnApiSave.Click += OnBtnSaveClick;
|
|
btnPmsAdd.Click += OnBtnAddClick;
|
|
btnPmsDelete.Click += OnBtnDeleteClick;
|
|
btnPmsSave.Click += OnBtnSaveClick;
|
|
}
|
|
/// <summary>
|
|
/// 添加按钮点击
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void OnBtnAddClick(object sender, EventArgs e)
|
|
{
|
|
if (sender == btnApiAdd)
|
|
{
|
|
sendMainView.AddNewRow();
|
|
}
|
|
else if (sender == btnPmsAdd)
|
|
{
|
|
sendDetailView.AddNewRow();
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 删除按钮点击
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void OnBtnDeleteClick(object sender, EventArgs e)
|
|
{
|
|
if (sender == btnApiDelete)
|
|
{
|
|
sendMainView.DeleteRow(sendMainView.FocusedRowHandle);
|
|
}
|
|
else if (sender == btnPmsDelete)
|
|
{
|
|
sendDetailView.DeleteRow(sendDetailView.FocusedRowHandle);
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 保存按钮点击
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void OnBtnSaveClick(object sender, EventArgs e)
|
|
{
|
|
if (sender == btnApiSave)
|
|
{
|
|
sendMainView.UpdateCurrentRow();
|
|
if (sendMainView.DataSource != null && sendMainView.DataSource is DataTable sourceTable)
|
|
{
|
|
SendMainAdapterObj.Update(sourceTable);
|
|
}
|
|
}
|
|
else if (sender == btnPmsSave)
|
|
{
|
|
sendDetailView.UpdateCurrentRow();
|
|
if (sendDetailView.DataSource != null && sendDetailView.DataSource is DataTable sourceTable)
|
|
{
|
|
SendDetailAdapterObj.Update(sourceTable);
|
|
}
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 选中行改变时
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void OnSendMainViewFocusedRowObjectChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowObjectChangedEventArgs e)
|
|
{
|
|
if (e.Row is DataRowView dataRowView)
|
|
{
|
|
DataRow focusedRow = dataRowView.Row;
|
|
string apiId = focusedRow["id"] + "";
|
|
InitApiPmsTabDataSource(apiId);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 初始化接口主表数据源
|
|
/// </summary>
|
|
private void InitApiTabDataSource()
|
|
{
|
|
//SendMain
|
|
SendMainAdapterObj = BaseImpl.GetAdapterResult("select * from p_systemeventapitab");
|
|
DataTable sendMainTable = new DataTable();
|
|
SendMainAdapterObj.Fill(sendMainTable);
|
|
sendGcMain.DataSource = sendMainTable;
|
|
//SendDetail
|
|
SendDetailAdapterObj = BaseImpl.GetAdapterResult("select * from p_systemeventapipmstab");
|
|
DataTable sendDetailTable = new DataTable();
|
|
SendMainAdapterObj.Fill(sendDetailTable);
|
|
sendGcDetail.DataSource = sendDetailTable;
|
|
}
|
|
/// <summary>
|
|
/// 初始化接口明细表数据源
|
|
/// </summary>
|
|
private void InitApiPmsTabDataSource(string apiId)
|
|
{
|
|
//SendDetail
|
|
SendDetailAdapterObj = BaseImpl.GetAdapterResult($"select * from p_systemeventapipmstab where apiid = '{apiId}'");
|
|
DataTable sendDetailTable = new DataTable();
|
|
SendMainAdapterObj.Fill(sendDetailTable);
|
|
sendGcDetail.DataSource = sendDetailTable;
|
|
}
|
|
/// <summary>
|
|
/// 初始化表格列
|
|
/// </summary>
|
|
private void InitColumnsData()
|
|
{
|
|
#region 主表
|
|
idColumn.OptionsColumn.AllowEdit = false;
|
|
//reqDataType
|
|
reqDataTypeComboBox.Items.Add(new ComBoxModel() { Value = 1, Text = "Json" });
|
|
reqDataTypeComboBox.Items.Add(new ComBoxModel() { Value = 0, Text = "Text" });
|
|
reqDataTypeComboBox.Items.Add(new ComBoxModel() { Value = 2, Text = "Xml" });
|
|
//resDataType
|
|
resDataTypeComboBox.Items.Add(new ComBoxModel() { Value = 1, Text = "Json" });
|
|
resDataTypeComboBox.Items.Add(new ComBoxModel() { Value = 0, Text = "Text" });
|
|
resDataTypeComboBox.Items.Add(new ComBoxModel() { Value = 2, Text = "Xml" });
|
|
//method
|
|
methodComboBox.Items.Add(new ComBoxModel() { Value = 0, Text = "Get" });
|
|
methodComboBox.Items.Add(new ComBoxModel() { Value = 1, Text = "Post" });
|
|
//actionType
|
|
actionTypeComboBox.Items.Add(new ComBoxModel() { Value = 0, Text = "手动触发" });
|
|
actionTypeComboBox.Items.Add(new ComBoxModel() { Value = 1, Text = "循环触发" });
|
|
//eType
|
|
eTypeComboBox.Items.Add(new ComBoxModel() { Value = "AfterModuleDataChange", Text = "数据改变后" });
|
|
eTypeComboBox.Items.Add(new ComBoxModel() { Value = "BeforeModuleDataChange", Text = "数据改变前" });
|
|
eTypeComboBox.Items.Add(new ComBoxModel() { Value = "AfterModuleContextMenu", Text = "右键执行后" });
|
|
eTypeComboBox.Items.Add(new ComBoxModel() { Value = "BeforeModuleContextMenu", Text = "右键执行前" });
|
|
eTypeComboBox.Items.Add(new ComBoxModel() { Value = "AfterModuleAuditStateChange", Text = "审核执行后" });
|
|
eTypeComboBox.Items.Add(new ComBoxModel() { Value = "BeforeModuleAuditStateChange", Text = "审核执行前" });
|
|
//tokenType
|
|
tokenTypeComboBox.Items.Add(new ComBoxModel() { Value = "0", Text = "Token文本" });
|
|
tokenTypeComboBox.Items.Add(new ComBoxModel() { Value = "1", Text = "Cookie" });
|
|
//eTypeCode
|
|
eTypeCodeComboBox.Items.Add(new ComBoxModel() { Value = "1", Text = "新增" });
|
|
eTypeCodeComboBox.Items.Add(new ComBoxModel() { Value = "2", Text = "更新" });
|
|
eTypeCodeComboBox.Items.Add(new ComBoxModel() { Value = "3", Text = "删除" });
|
|
eTypeCodeComboBox.Items.Add(new ComBoxModel() { Value = "21", Text = "提交审核" });
|
|
eTypeCodeComboBox.Items.Add(new ComBoxModel() { Value = "31", Text = "审核" });
|
|
eTypeCodeComboBox.Items.Add(new ComBoxModel() { Value = "32", Text = "反审" });
|
|
//pmsType
|
|
pmsTypeComboBox.Items.Add(new ComBoxModel() { Value = "1", Text = "老版" });
|
|
pmsTypeComboBox.Items.Add(new ComBoxModel() { Value = "2", Text = "新版" });
|
|
//allowShowMsg
|
|
allowShowMsgComboBox.Items.Add(new ComBoxModel() { Value = "0", Text = "不提示" });
|
|
allowShowMsgComboBox.Items.Add(new ComBoxModel() { Value = "1", Text = "提示" });
|
|
//disableTag
|
|
disableTagComboBox.Items.Add(new ComBoxModel() { Value = "0", Text = "启用" });
|
|
disableTagComboBox.Items.Add(new ComBoxModel() { Value = "1", Text = "禁用" });
|
|
#endregion
|
|
#region 明细表
|
|
pmsIdColumn.OptionsColumn.AllowEdit = false;
|
|
//pmType
|
|
pmTypeComboBox.Items.Add(new ComBoxModel() { Value = "0", Text = "发送参数" });
|
|
pmTypeComboBox.Items.Add(new ComBoxModel() { Value = "2", Text = "Header参数" });
|
|
pmTypeComboBox.Items.Add(new ComBoxModel() { Value = "1", Text = "接收参数" });
|
|
//valueType
|
|
valueTypeComboBox.Items.Add(new ComBoxModel() { Value = "0", Text = "json值" });
|
|
valueTypeComboBox.Items.Add(new ComBoxModel() { Value = "1", Text = "json对象" });
|
|
valueTypeComboBox.Items.Add(new ComBoxModel() { Value = "2", Text = "json数组" });
|
|
//valueDataType
|
|
valueDataTypeComboBox.Items.Add(new ComBoxModel() { Value = "0", Text = "文本" });
|
|
valueDataTypeComboBox.Items.Add(new ComBoxModel() { Value = "1", Text = "整数" });
|
|
valueDataTypeComboBox.Items.Add(new ComBoxModel() { Value = "2", Text = "小数" });
|
|
//allowNull
|
|
allowNullComboBox.Items.Add(new ComBoxModel() { Value = "1", Text = "必填" });
|
|
allowNullComboBox.Items.Add(new ComBoxModel() { Value = "0", Text = "非必填" });
|
|
#endregion
|
|
}
|
|
/// <summary>
|
|
/// 构建数据表
|
|
/// </summary>
|
|
private bool InitEventApiTable()
|
|
{
|
|
try
|
|
{
|
|
Dictionary<string, string> colDic = new Dictionary<string, string>();
|
|
colDic.Add("title", "varchar(200)");
|
|
colDic.Add("url", "varchar(1000)");
|
|
colDic.Add("dllcoid", "varchar(100)");
|
|
colDic.Add("contextMenuId", "int");
|
|
colDic.Add("reqDataType", "int");
|
|
colDic.Add("resDataType", "int");
|
|
colDic.Add("method", "int");
|
|
colDic.Add("datasource", "varchar(8000)");
|
|
colDic.Add("actionType", "int");
|
|
colDic.Add("actionDelay", "int");
|
|
colDic.Add("eType", "varchar(1000)");
|
|
colDic.Add("finshAction", "varchar(8000)");
|
|
colDic.Add("orderValue", "int");
|
|
colDic.Add("isSucceedCond", "varchar(100)");
|
|
colDic.Add("tokenApiId", "int");
|
|
colDic.Add("tokenType", "int");
|
|
colDic.Add("dynamicToken", "varchar(200)");
|
|
colDic.Add("pmsType", "int");
|
|
colDic.Add("allowShowMsg", "int");
|
|
colDic.Add("ContentType", "varchar(200)");
|
|
string isExitApiTab = "select top 1 * from sysObjects where Id=OBJECT_ID(N'p_systemEventApiTab') and xtype='U'";
|
|
DataTable apiTab = SqlHelper.ExecuteDataTable(isExitApiTab);
|
|
if (apiTab.Rows.Count > 0)//存在日志表
|
|
{
|
|
DataTable columnsTab = SqlHelper.ExecuteDataTable(string.Format("select name from syscolumns where id=object_id('p_systemEventApiTab')"));
|
|
foreach (KeyValuePair<string, string> colunmField in colDic)
|
|
{
|
|
DataRow[] dataRows = columnsTab.Select().Where(n => (n["name"] + "").Equals(colunmField.Key)).ToArray();
|
|
if (dataRows.Length == 0)
|
|
{
|
|
string addColSql = string.Format("alter table p_systemEventApiTab add {0} {1}", colunmField.Key, colunmField.Value);
|
|
SqlHelper.ExecuteNonQuery(addColSql);//添加列
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
string createTabSql = "create table p_systemEventApiTab(id int IDENTITY(1,1) NOT NULL,{0})";
|
|
string createCol = string.Empty;
|
|
foreach (KeyValuePair<string, string> colunmField in colDic)
|
|
{
|
|
createCol += string.Format("{0} {1},", colunmField.Key, colunmField.Value);
|
|
}
|
|
createTabSql = string.Format(createTabSql, createCol.TrimEnd(','));
|
|
SqlHelper.ExecuteNonQuery(createTabSql);//创建表
|
|
}
|
|
return true;
|
|
}
|
|
catch (Exception)
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 构建数据表
|
|
/// </summary>
|
|
private bool InitEventApiPmsTable()
|
|
{
|
|
try
|
|
{
|
|
Dictionary<string, string> colDic = new Dictionary<string, string>();
|
|
colDic.Add("apiId", "int");
|
|
colDic.Add("title", "varchar(200)");
|
|
colDic.Add("pmType", "int");
|
|
colDic.Add("valueType", "int");
|
|
colDic.Add("pmsDataSource", "varchar(8000)");
|
|
colDic.Add("name", "varchar(100)");
|
|
colDic.Add("value", "varchar(8000)");
|
|
colDic.Add("valueDataType", "int");
|
|
colDic.Add("unionPmsId", "int");
|
|
colDic.Add("allowNull", "int");
|
|
string isExitApiTab = "select top 1 * from sysObjects where Id=OBJECT_ID(N'P_systemEventApiPmsTab') and xtype='U'";
|
|
DataTable apiTab = SqlHelper.ExecuteDataTable(isExitApiTab);
|
|
if (apiTab.Rows.Count > 0)//存在日志表
|
|
{
|
|
DataTable columnsTab = SqlHelper.ExecuteDataTable(string.Format("select name from syscolumns where id=object_id('P_systemEventApiPmsTab')"));
|
|
foreach (KeyValuePair<string, string> colunmField in colDic)
|
|
{
|
|
DataRow[] dataRows = columnsTab.Select().Where(n => (n["name"] + "").Equals(colunmField.Key)).ToArray();
|
|
if (dataRows.Length == 0)
|
|
{
|
|
string addColSql = string.Format("alter table P_systemEventApiPmsTab add {0} {1}", colunmField.Key, colunmField.Value);
|
|
SqlHelper.ExecuteNonQuery(addColSql);//添加列
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
string createTabSql = "create table P_systemEventApiPmsTab(id int IDENTITY(1,1) NOT NULL,{0})";
|
|
string createCol = string.Empty;
|
|
foreach (KeyValuePair<string, string> colunmField in colDic)
|
|
{
|
|
createCol += string.Format("{0} {1},", colunmField.Key, colunmField.Value);
|
|
}
|
|
createTabSql = string.Format(createTabSql, createCol.TrimEnd(','));
|
|
SqlHelper.ExecuteNonQuery(createTabSql);//创建表
|
|
}
|
|
return true;
|
|
}
|
|
catch (Exception)
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 设置分割条位置
|
|
|