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中的服务并获取返回值

页面

清空页面某个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
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;
}
}

其它

执行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;