chr
2024-08-07 22beee93f14d042aa184148c53efb79e23416526
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
 
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; }
}