Camstar Records On Commonly Used CS

本文内容仅做参考并不完全通用,测试环境为OpcenterEXCR2410,其中数据均为演示所用无实际意义

更新日志

时间轴

2025-06-27

  1. 页面初始化
  2. 添加分类:页面、控件、表格、服务、其它
  3. 添加方法:页面-清空页面某个WP中所有控件(需要注册)
  4. 添加方法:控件-常用控件的注册
  5. 添加方法:表格-获取特定类型的ItemList表格中的数据并判空
  6. 添加方法:服务-调用Designer中的服务
  7. 添加方法:其它-执行JS代码

2025-07-02

  1. 删除方法:页面-清空页面某个WP中所有控件(需要注册)
  2. 添加方法:页面-清空页面某个WP中所有控件
  3. 修改方法:控件-常用控件的注册
  4. 添加方法:页面-使用Label报错
  5. 添加方法:服务-调用Designer中的服务并获取返回值

2025-07-29

  1. 添加方法:其它-提取SQL
  2. 添加方法:页面-服务提交成功后页面刷新

2026-04-19

  1. 添加方法:服务-接口中调用服务进行建模的创建或更新

页面

清空页面某个WP中所有控件

1
2
3
4
5
6
7
8
9
10
11
private void ClearPageData()
{
var blankWP = Page.FindIForm("BlankWP") as WebPartBase;
foreach (var control in blankWP.CamstarControls)
{
if (control.ClientID.EndsWith("_Btn_Packaging") || control.ClientID.EndsWith("_ContainerName"))
continue;

control.ClearData();
}
}

使用Label报错

1
2
3
4
5
6
7
8
9
10
11
//-
Page.DisplayMessage(cpsPublic.Getlabelvalue("wzmProductionCheck_E0001"), false);

//--
result.ExceptionData.Description = cpsPublic.Getlabelvalue("wzmPackaging_E0002");
return result;

//---
var notification = cpsPublic.Getlabelvalue("wzmRemainGlueTempUse_E0003", new List<string>() { _RemainGlueLot.Data.ToString() });
result.ExceptionData.Description = notification;
return result;

服务提交成功后页面刷新

1
2
3
4
5
6
7
8
public override void PostExecute(OM.ResultStatus status, OM.Service serviceData)
{
base.PostExecute(status, serviceData);
if (status.IsSuccess)
{
Page.ClearValues();
}
}

控件

常用控件的注册

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
protected virtual CWC.ContainerList _Container { get { return Page.FindCamstarControls<CWC.ContainerList>().FirstOrDefault(c => c.ID == "ContainerStatus_ContainerName"); } }

protected virtual ContainerListGrid _Container => Page.FindCamstarControl("wzmPackaging_wzmContainer") as ContainerListGrid;

protected virtual TextBox _ContainerName => Page.FindCamstarControl("ContainerName") as TextBox;

protected virtual Button _UnloadBtn => Page.FindCamstarControl("Button-Unload") as Button;

protected virtual CheckBox _IsAuto => Page.FindCamstarControl("wzmPackagingAutoSpilt_wzmIsAutoGenerate") as CheckBox;

protected virtual DropDownList _MfgOrder => Page.FindCamstarControl("wzmMfgOrder") as DropDownList;

protected virtual NamedObject _PackagingUOM => Page.FindCamstarControl("wzmPackaging_wzmPackagingUOM") as NamedObject;

protected virtual RevisionedObject _OldProduct => Page.FindCamstarControl("wzmPNChange_wzmOldProduct") as RevisionedObject;

protected virtual JQDataGrid _PackagingLotInfo => Page.FindCamstarControl("wzmPackaging_wzmPackagingLotInfo") as JQDataGrid;

表格

获取特定类型的ItemList表格中的数据并判空

1
if (_AutoSplitDetails.Data is IEnumerable<wzmAutoSplitDetails> details && details.Any())

服务

调用Designer中的服务

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
protected virtual ResultStatus MaterialUnloadRecord(List<string> unloadList)
{
var result = new ResultStatus { IsSuccess = false, ExceptionData = new ExceptionDataType() };

try
{
var profile = FrameworkManagerUtil.GetFrameworkSession().CurrentUserProfile;
var RCUSvc = new wzmResourceComponentUnloadService(profile);

var details = new List<wzmResourceComponentUnloadD>();
unloadList.ForEach(f =>
{
details.Add(new wzmResourceComponentUnloadD
{
ListItemAction = ListItemAction.Add,
wzmUnloadContainer = new ContainerRef(f)
});
});
var RCUSvcData = new WCF.ObjectStack.wzmResourceComponentUnload
{
wzmResource = new NamedObjectRef(_Resource.Data.ToString()),
wzmResourceComponentUnloadD = details.ToArray()
};

result = RCUSvc.ExecuteTransaction(RCUSvcData, new wzmResourceComponentUnload_Request { Info = new wzmResourceComponentUnload_Info() }, out _);

return result;
}
catch (Exception ex)
{
PageReset();
result.ExceptionData.Description = ex.Message;
return result;
}
}

调用Designer中的服务并获取返回值

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
protected virtual ResultStatus GeneratePackagingInfo()
{
var result = new ResultStatus { IsSuccess = false, ExceptionData = new ExceptionDataType() };

try
{
if (string.IsNullOrEmpty(_NumberingRuleid.Data?.ToString()))
{
ClearPageData();
result.ExceptionData.Description = cpsPublic.Getlabelvalue("wzmPackaging_E0003");
return result;
}

string lot = _ContainerName.Data?.ToString();
string queryText = @"
select
mo.mfgordername,
p.description,
u.uomname,
c.qty
from container c
inner join mfgorder mo on c.mfgorderid = mo.mfgorderid
inner join product p on c.productid = p.productid
inner join uom u on u.uomid = c.uomid
where c.containername = :Lot
";

var res = _db.QueryDataTable(queryText, new { Lot = lot });

if (res?.Rows.Count == 0)
{
ClearPageData();
result.ExceptionData.Description = cpsPublic.Getlabelvalue("wzmPackaging_E0002");
return result;
}

var profile = FrameworkManagerUtil.GetFrameworkSession().CurrentUserProfile;
var svc = new wzmPackagingService(profile);
var svcData = new OM.wzmPackaging
{
wzmNumberingRule = new NamedObjectRef(_NumberingRuleid.Data.ToString())
};
var svcReq = new wzmPackaging_Request
{
Info = new wzmPackaging_Info { wzmPackNR = new Info(true) }
};
wzmPackaging_Result svcResult;

result = svc.ExecuteTransaction(svcData, svcReq, out svcResult);

if (!result.IsSuccess)
{
ClearPageData();
result.ExceptionData.Description = cpsPublic.Getlabelvalue("wzmPackaging_E0004");
return result;
}

string prefix = svcResult.Value.wzmPackNR.ToString();

double qty = Convert.ToDouble(res.Rows[0]["qty"]);
string uom = res.Rows[0]["uomname"].ToString();
string desc = res.Rows[0]["description"].ToString();
string order = res.Rows[0]["mfgordername"].ToString();
double max = Convert.ToDouble(_PackagingMaxNum.Data);
double min = Convert.ToDouble(_PackagingMinNum.Data);

var lots = GenerateLots(prefix, qty, uom, order, desc, max, min);
_PackagingLotInfo.Data = lots.ToArray();

return result;
}
catch (Exception ex)
{
ClearPageData();
result.ExceptionData.Description = ex.Message;
return result;
}
}

接口中调用服务进行建模的创建或更新

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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
using Camstar.InterfaceSet.Models.CommonModel;
using Camstar.InterfaceSet.Models.ServiceModel.MES;
using System;
using Camstar.InterfaceSet.Results.Common;
using Camstar.WCF.ObjectStack;
using Camstar.WCF.Services;
using Camstar.InterfaceSet.Service.Common;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using UserDll;
using UserDll.Base;

namespace Camstar.InterfaceSet.Service.MES
{
public class MES_CreateLDCodeParaService
{
public ApiResult CreateLDCodePara(MES_CreateLDCodeParaReq req)
{
var ar = new ApiResult();

try
{
UserProfile userProfile = UserConfig.getUserProfileInstance();
ahLDCodeParameterMaintService service = new ahLDCodeParameterMaintService(userProfile);

string paraName = req.Name;
string ruleName = req.LDCodeRule;
if (string.IsNullOrEmpty(paraName))
{
ar.bSucc = false;
ar.strMsg = string.Format("镭雕打码参数建模创建失败!建模名称为空!");
AvaryLog.AddLog(LogLevel.Error, PubCommon.GetLineNum() + ar.strMsg, "CreateLDCodeParaServiceError");
return ar;
}
if (!string.IsNullOrEmpty(ruleName) && !checkRuleExist(ruleName))
{
ar.bSucc = false;
ar.strMsg = string.Format("镭雕打码参数建模创建失败!镭雕码规则{0}未定义!", ruleName);
AvaryLog.AddLog(LogLevel.Error, PubCommon.GetLineNum() + ar.strMsg, "CreateLDCodeParaServiceError");
return ar;
}

if (checkParaExist(paraName))
{
//更新
using (OracleDataOpt dataOpt = new OracleDataOpt(PubCommon.GetConStr("MES")))
{
string sql = @"SELECT COUNT(1) FROM AHLDCODEPARAMETER A INNER JOIN AHSTRIPCODEPARA D ON D.AHLDCODEPARAMETERID = A.AHLDCODEPARAMETERID WHERE A.AHLDCODEPARAMETERNAME = :Name";
int count = dataOpt.GetCount(sql, paraName);

ahLDCodeParameterMaint data = new ahLDCodeParameterMaint();
ahLDCodeParameterMaint data1 = new ahLDCodeParameterMaint();
ahLDCodeParameterChanges changes = new ahLDCodeParameterChanges();
data.ObjectToChange = new NamedObjectRef(paraName);
service.BeginTransaction();
service.Load(data);
List<ahStripCodeParaChanges> list = new List<ahStripCodeParaChanges>();

//先删除
if (count > 0)
{
for (int l = count - 1; l >= 0; l--)
{
ahStripCodeParaChanges details = new ahStripCodeParaChanges();
details.ListItemAction = ListItemAction.Delete;
details.ListItemIndex = l;
list.Add(details);
}
}
//再添加
if (req.StripCodePara != null && req.StripCodePara.Count > 0)
{
foreach (var item in req.StripCodePara)
{
ahStripCodeParaChanges details = new ahStripCodeParaChanges();
details.ListItemAction = ListItemAction.Add;

details.ahSeq = Convert.ToInt32(item.Seq);
details.ahCodeType = item.CodeType;
details.ahCodeAngle = item.CodeAngle;
details.ahCodeLength = item.CodeLength;
details.ahCodeWidth = item.CodeWidth;
details.ahLocationX = item.LocationX;
details.ahLocationY = item.LocationY;

list.Add(details);
}
}
changes.ahStripCodePara = list.ToArray();

if (!string.IsNullOrEmpty(ruleName))
changes.ahLDCodeRule = new NamedObjectRef(ruleName);
changes.ahPnlLocationX = req.PnlLocationX;
changes.ahPnlLocationY = req.PnlLocationY;
changes.ahPnlCodeAngle = req.PnlCodeAngle;
changes.ahPnlCodeLength = req.PnlCodeLength;
changes.ahPnlCodeWidth = req.PnlCodeWidth;
changes.ahALocationX = req.ALocationX;
changes.ahALocationY = req.ALocationY;
changes.ahBLocationX = req.BLocationX;
changes.ahBLocationY = req.BLocationY;
changes.ahCLocationX = req.CLocationX;
changes.ahCLocationY = req.CLocationY;
changes.ahDLocationX = req.DLocationX;
changes.ahDLocationY = req.DLocationY;
changes.ahStripCodeRule = req.StripCodeRule;

data1.ObjectChanges = changes;
service.ExecuteTransaction(data1);
ResultStatus resultStatus = service.CommitTransaction();
if (resultStatus.IsSuccess)
{
ar.bSucc = true;
ar.strMsg = "镭雕打码参数建模更新成功!" + resultStatus.Message;
AvaryLog.AddLog(LogLevel.Trace, paraName + "镭雕打码参数建模更新成功!", "CreateLDCodeParaServiceSuccess");
}
else
{
ar.bSucc = false;
ar.strMsg = "镭雕打码参数建模更新失败!" + resultStatus.ExceptionData.Description;
AvaryLog.AddLog(LogLevel.Trace, paraName + "镭雕打码参数建模更新失败!" + resultStatus.ExceptionData.Description, "CreateLDCodeParaServiceError");
}
}
}
else
{
//新增
ahLDCodeParameterMaint data = new ahLDCodeParameterMaint();
ahLDCodeParameterChanges changes = new ahLDCodeParameterChanges();
List<ahStripCodeParaChanges> list = new List<ahStripCodeParaChanges>();
changes.Name = paraName;

if (!string.IsNullOrEmpty(ruleName))
changes.ahLDCodeRule = new NamedObjectRef(ruleName);
changes.ahPnlLocationX = req.PnlLocationX;
changes.ahPnlLocationY = req.PnlLocationY;
changes.ahPnlCodeAngle = req.PnlCodeAngle;
changes.ahPnlCodeLength = req.PnlCodeLength;
changes.ahPnlCodeWidth = req.PnlCodeWidth;
changes.ahALocationX = req.ALocationX;
changes.ahALocationY = req.ALocationY;
changes.ahBLocationX = req.BLocationX;
changes.ahBLocationY = req.BLocationY;
changes.ahCLocationX = req.CLocationX;
changes.ahCLocationY = req.CLocationY;
changes.ahDLocationX = req.DLocationX;
changes.ahDLocationY = req.DLocationY;
changes.ahStripCodeRule = req.StripCodeRule;

if (req.StripCodePara != null && req.StripCodePara.Count > 0)
{
foreach (var item in req.StripCodePara)
{
ahStripCodeParaChanges details = new ahStripCodeParaChanges();

details.ahSeq = Convert.ToInt32(item.Seq);
details.ahCodeType = item.CodeType;
details.ahCodeAngle = item.CodeAngle;
details.ahCodeLength = item.CodeLength;
details.ahCodeWidth = item.CodeWidth;
details.ahLocationX = item.LocationX;
details.ahLocationY = item.LocationY;

list.Add(details);
}
}
changes.ahStripCodePara = list.ToArray();
data.ObjectChanges = changes;
service.BeginTransaction();
service.New();
service.ExecuteTransaction(data);
ResultStatus resultStatus = service.CommitTransaction();
if (resultStatus.IsSuccess)
{
ar.bSucc = true;
ar.strMsg = "镭雕打码参数建模创建成功!" + resultStatus.Message;
AvaryLog.AddLog(LogLevel.Trace, paraName + "镭雕打码参数建模创建成功!", "CreateLDCodeParaServiceSuccess");
}
else
{
ar.bSucc = false;
ar.strMsg = "镭雕打码参数建模创建失败!" + resultStatus.ExceptionData.Description;
AvaryLog.AddLog(LogLevel.Trace, paraName + "镭雕打码参数建模创建失败!" + resultStatus.ExceptionData.Description, "CreateLDCodeParaServiceError");
}
}
}
catch (Exception ex)
{
ar = new ApiResult("0001", "镭雕打码参数建模创建失败!" + ex.Message, "CreateLDCodeParaServiceError");
AvaryLog.AddLog(LogLevel.Error, ex.ToString(), "CreateLDCodeParaServiceError");
}

return ar;
}

private bool checkParaExist(string Name)
{
//根据名称检验参数建模是否存在
using (OracleDataOpt dataOpt = new OracleDataOpt(PubCommon.GetConStr("MES")))
{
string sql = @"SELECT COUNT(1) FROM AHLDCODEPARAMETER A WHERE A.AHLDCODEPARAMETERNAME = :Name";
int count = dataOpt.GetCount(sql, Name);
if (count > 0)
return true;
else
return false;
}
}

private bool checkRuleExist(string Name)
{
//根据名称检验规则建模是否存在
using (OracleDataOpt dataOpt = new OracleDataOpt(PubCommon.GetConStr("MES")))
{
string sql = @"SELECT COUNT(1) FROM AHLDCODERULE A WHERE A.AHLDCODERULENAME = :Name";
int count = dataOpt.GetCount(sql, Name);
if (count > 0)
return true;
else
return false;
}
}
}
}

其它

执行JS代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
var src = @"
var table = document.getElementById('ctl00_WebPartManager_MaterialsRequirementWP_MaterialRequirementsGrid');
if (table) {
console.log('table founded');
var tbody = table.getElementsByTagName('tbody')[0];
if (tbody) {
console.log('tbody founded');
var selectedRow = tbody.querySelector('tr[aria-selected=""true""]');
if (selectedRow) {
selectedRow.removeAttribute('aria-selected');
}
} else {
console.log('tbody not found');
}
} else {
console.log('table not found');
}
";
ScriptManager.RegisterStartupScript(this, Page.GetType(), "clearSelectedRow", src, true);
RenderToClient = true;

提取SQL

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
private const string SqlMainQuery = @"
SELECT
info.wzmsequenceno,
mo.mfgordername,
pb.productname || ':' || p.productrevision AS pressproduct,
info.wzmpndescription,
mo.reportingfactoryid,
f.factoryname,
p.wzmgluefamilyid,
p.wzmthicknesslower,
p.wzmthicknessupper,
mo.mfglineid,
p.wzmradialsize,
p.wzmweftsize
FROM wzmsubstrateimportinfo info
INNER JOIN product p ON info.wzmpressproductid = p.productid
INNER JOIN productbase pb ON p.productbaseid = pb.productbaseid
INNER JOIN mfgorder mo ON mo.mfgorderid = info.wzmpressmfgorderid
INNER JOIN factory f ON f.factoryid = mo.reportingfactoryid
WHERE info.wzmsequenceno = (
SELECT info.wzmsequenceno
FROM wzmsubstrateimportinfo info
INNER JOIN mfgorder mo ON info.wzmpressmfgorderid = mo.mfgorderid
WHERE mo.mfgordername = :MfgOrderName
)
";