|
using Newtonsoft.Json;
|
using Newtonsoft.Json.Converters;
|
using PdmSwPlugin.PDM;
|
using PdmSwPlugin.Test.Model;
|
using PdmSwPlugin.Util;
|
using PdmSwPlugin.Util.Entity;
|
using SolidWorks.Interop.sldworks;
|
using System;
|
using System.Collections.Generic;
|
using System.Runtime.InteropServices;
|
using System.Windows.Documents;
|
|
namespace PdmSwPlugin.Test.UIHandler
|
{
|
[ClassInterface(ClassInterfaceType.AutoDual)]
|
[ComVisible(true)]
|
public class TestWebModel
|
{
|
|
public SldWorks SwApp { get; set; }
|
public PdmControl pdm { get; set; }
|
|
public TestWebModel(SldWorks swApp, PdmControl pdm)
|
{
|
SwApp = swApp;
|
this.pdm = pdm;
|
}
|
|
public string test(string data, int a, double b)
|
{
|
var res = pdm.RefreshBomList(SwApp.IActiveDoc2);
|
return JsonUtil.Serialize(res);
|
}
|
|
public string search(string dataStr)
|
{
|
try
|
{
|
SearchParam param = JsonUtil.Deserialize<SearchParam>(dataStr);
|
|
string sql = "Select * FROM table WHERE 1=1";
|
|
if (param.startTime != null) sql += $" AND start_time >= {param.startTime}";
|
if (param.endTime != null) sql += $" AND start_time >= {param.endTime}";
|
|
foreach (SearchItem item in param.searchItems)
|
{
|
if (!string.IsNullOrEmpty(item.value)) sql += $" AND {item.name} {item.opt} {item.value}";
|
}
|
|
// doSomething
|
return ResultData.ok(new List<Dictionary<string, string>>() {
|
new Dictionary<string, string>(){
|
{ "sql",sql}
|
}
|
});
|
}
|
catch (Exception e)
|
{
|
return ResultData.error(e.Message);
|
}
|
}
|
|
public string GetSearchItem(string itemId)
|
{
|
try
|
{
|
int len = new Random().Next(10);
|
List<SearchItem> items = new List<SearchItem>(len);
|
for (int i = 0; i < len; i++)
|
{
|
items.Add(
|
new SearchItem()
|
{
|
name = itemId + i,
|
opt = "=",
|
value = ""
|
}
|
);
|
}
|
return ResultData.ok(items).ToString();
|
}
|
catch (Exception e)
|
{
|
return ResultData.error(e.Message).ToString();
|
}
|
}
|
}
|
}
|
|
public class SearchItem
|
{
|
public string id { get; set; }
|
public string name { get; set; }
|
public string opt { get; set; }
|
public string value { get; set; }
|
}
|
|
|
public class DateTimeFormatConverter : IsoDateTimeConverter
|
{
|
public DateTimeFormatConverter(string format)
|
{
|
DateTimeFormat = format;
|
}
|
}
|
|
public class SearchParam
|
{
|
[JsonConverter(typeof(DateTimeFormatConverter), "yyyy-MM-dd HH:ss:mm")]
|
public DateTime? startTime { get; set; }
|
[JsonConverter(typeof(DateTimeFormatConverter), "yyyy-MM-dd HH:ss:mm")]
|
public DateTime? endTime { get; set; }
|
public List<SearchItem> searchItems { get; set; }
|
}
|
|
|
[ComVisible(true)]
|
public class TestData
|
{
|
public string name { get; set; }
|
}
|