------ #### SuperDesign V3.0.2412.2001 - *.[新增]新增程序更新日志设置和自动发布功能。 - *.[修复]修复Post数据格式不正确时双击文本框会导致软件闪退的BUG。
175 lines
6.6 KiB
C#
175 lines
6.6 KiB
C#
using Newtonsoft.Json.Linq;
|
|
using ryCommon;
|
|
using ryCommonDb;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
using System.Xml.Linq;
|
|
using 开发辅助工具.Manager;
|
|
|
|
namespace 开发辅助工具.Tools.API
|
|
{
|
|
public partial class FrmAddPostParam : Form
|
|
{
|
|
public FrmAddPostParam()
|
|
{
|
|
InitializeComponent();
|
|
OlvTitle.AspectGetter = delegate (object x) { return ((PostInfo)x).Title; };
|
|
OlvParamName.AspectGetter = delegate (object x) { return ((PostInfo)x).ParamName; };
|
|
OlvParamValue.AspectGetter = delegate (object x) { return ((PostInfo)x).ParamValue; };
|
|
OlvDesc.AspectGetter = delegate (object x) { return ((PostInfo)x).Desc; };
|
|
}
|
|
public string Url { get; set; } = "";
|
|
private void BtnCancel_Click(object sender, EventArgs e)
|
|
{
|
|
DialogResult = DialogResult.Cancel;
|
|
}
|
|
public PostInfo SelectedItem { get; set; } = null;
|
|
private void BtnOK_Click(object sender, EventArgs e)
|
|
{
|
|
if (LvPostData.SelectedObject == null) { return; }
|
|
SelectedItem = (PostInfo)LvPostData.SelectedObject;
|
|
DialogResult= DialogResult.OK;
|
|
}
|
|
|
|
private void LvPostData_DoubleClick(object sender, EventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
private void LvPostData_CellEditFinishing(object sender, BrightIdeasSoftware.CellEditEventArgs e)
|
|
{
|
|
var row = (PostInfo)e.RowObject;
|
|
if (e.Cancel) { return; }
|
|
if (e.Column == OlvTitle)
|
|
{
|
|
row.Title = e.NewValue.ToString();
|
|
}
|
|
else if (e.Column == OlvParamValue)
|
|
{
|
|
row.ParamValue = e.NewValue.ToString();
|
|
}
|
|
else if (e.Column == OlvDesc)
|
|
{
|
|
row.Desc = e.NewValue.ToString();
|
|
}
|
|
IDbInterface db = Itrycn_Db.CreateDataProvider(Itrycn_Db.dataType);
|
|
if (db.ConnDb(Itrycn_Db.User_SQLConn) == 1)
|
|
{
|
|
RyQuickSQL mySQL = new RyQuickSQL("api");
|
|
mySQL.AddField("Url",Url);
|
|
DataSet ds = db.ReadData("select * from api where Url=@Url", mySQL);
|
|
var json_post = "";
|
|
if (ds.HaveData())
|
|
{
|
|
json_post = ds.GetFirstRowData()["Postdata"].ToString();
|
|
}
|
|
JObject jo;
|
|
if (json_post.Length == 0) { jo = new JObject(); }
|
|
else { jo = JObject.Parse(json_post); }
|
|
Dictionary<string, PostInfo> dict_post = new Dictionary<string, PostInfo>();
|
|
if (jo.ContainsKey("list"))
|
|
{
|
|
JArray jarr = JArray.Parse(jo["list"].ToString());
|
|
for (int i = 0; i < jarr.Count; i++)
|
|
{
|
|
var item = jarr[i];
|
|
var param_name = item["paramname"].ToString("");
|
|
if (!dict_post.ContainsKey(param_name))
|
|
{
|
|
dict_post.Add(param_name, new PostInfo()
|
|
{
|
|
Title = item["title"].ToString(""),
|
|
ParamName = param_name,
|
|
Desc = item["desc"].ToString(""),
|
|
ParamValue = item["paramvalue"].ToString(""),
|
|
IsAdd = false
|
|
});
|
|
}
|
|
}
|
|
}
|
|
if (dict_post.ContainsKey(row.ParamName))
|
|
{
|
|
dict_post[row.ParamName] = row;
|
|
}
|
|
else
|
|
{
|
|
dict_post.Add(row.ParamName, row);
|
|
}
|
|
JObject jo_new = new JObject();
|
|
JArray jarr_new = new JArray();
|
|
foreach (var item in dict_post)
|
|
{
|
|
JObject jo_item = new JObject
|
|
{
|
|
{ "paramname", item.Value.ParamName },
|
|
{ "title", item.Value.Title },
|
|
{ "paramvalue", item.Value.ParamValue },
|
|
{ "desc", item.Value.Desc }
|
|
};
|
|
jarr_new.Add(jo_item);
|
|
}
|
|
jo_new.Add("list", jarr_new);
|
|
mySQL.AddField("Postdata", jo_new.ToString());
|
|
if (db.ExecuteNonQuery(mySQL.GetUpdateSQL() + " where Url=@Url", mySQL) == 0)
|
|
{
|
|
}
|
|
}
|
|
db.Free();
|
|
}
|
|
|
|
private void LvPostData_CellClick(object sender, BrightIdeasSoftware.CellClickEventArgs e)
|
|
{
|
|
if(e.ClickCount==2 && e.Column==OlvParamName)
|
|
{
|
|
BtnOK.PerformClick();
|
|
}
|
|
}
|
|
|
|
private void 删除该参数ToolStripMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
var row = (PostInfo)LvPostData.SelectedObject;
|
|
if (row == null) { return; }
|
|
IDbInterface db = Itrycn_Db.CreateDataProvider(Itrycn_Db.dataType);
|
|
if (db.ConnDb(Itrycn_Db.User_SQLConn) == 1)
|
|
{
|
|
RyQuickSQL mySQL = new RyQuickSQL("api");
|
|
mySQL.AddField("Url", Url);
|
|
DataSet ds = db.ReadData("select * from api where Url=@Url", mySQL);
|
|
var json_post = "";
|
|
if (ds.HaveData())
|
|
{
|
|
json_post = ds.GetFirstRowData()["Postdata"].ToString();
|
|
}
|
|
JObject jo;
|
|
if (json_post.Length == 0) { jo = new JObject(); }
|
|
else { jo = JObject.Parse(json_post); }
|
|
if (jo.ContainsKey("list"))
|
|
{
|
|
JArray jarr = JArray.Parse(jo["list"].ToString());
|
|
for (int i = 0; i < jarr.Count; i++)
|
|
{
|
|
var item = jarr[i];
|
|
var param_name = item["paramname"].ToString("");
|
|
if(param_name==row.ParamName)
|
|
{
|
|
jarr.Remove(item);
|
|
break;
|
|
}
|
|
}
|
|
jo["list"] = jarr;
|
|
}
|
|
mySQL.AddField("Postdata", jo.ToString());
|
|
db.ExecuteNonQuery(mySQL.GetUpdateSQL() + " where Url=@Url", mySQL);
|
|
}
|
|
db.Free();
|
|
}
|
|
}
|
|
}
|