动态表单相关踩坑记录23.04.19
近期在搞动态表单相关的,这块社区教程还是比较丰富的,踩坑后问题也不大
### 业务场景:打开销售订单,点击按钮,弹出动态表单
#### 1.增加按钮
编辑、批量编辑字段属性、菜单集合、添加按钮
#### 2.新增动态表单,并配置页面
emmm……好吧
![image-20230412092819194.webp](/download/01006fb1934d22134bea91a7f8c0f23adb0f.webp)
#### 3.单据测试一直都不行,看了下社区好像也没有啥可参考,有哪位大神知道怎么搞的不?
看过资料好像有说是用administrator账号的原因?
![image-20230412113808894.webp](/download/01004a3f270159f54b8eae03062ea27690a2.webp)
4.前端打开是可以的
![image-20230412114156192.webp](/download/010088f42a7ad9ba4687a9ca8be50201fc22.webp)
### 业务场景:根据销售订单查询销售出库单
#### 1.SQL语句
--销售出库单
select * from T_SAL_OUTSTOCK where FBILLNO = 'XSCKD000036'
--FID 100060
--销售出库单据体
select * from T_SAL_OUTSTOCKENTRY where FID = 100060
--销售出库单
select * from T_SAL_OUTSTOCKENTRY t1 inner join T_SAL_OUTSTOCK t2
on t2.FID = t1.FID
where t2.FBILLNO = 'XSCKD000036'
--
select t2.FBILLNO,* from T_SAL_OUTSTOCKENTRY t1 inner join T_SAL_OUTSTOCK t2
on t2.FID = t1.FID
where t2.FBILLNO = 'XSCKD000036'
--物料表
select * from T_BD_MATERIAL where FMATERIALID = 100322
--单据编号、物料编码(根据销售出库单单据编号获取对应的物料编号)
select t2.FBILLNO,t3.FNUMBER from T_SAL_OUTSTOCKENTRY t1
inner join T_SAL_OUTSTOCK t2 on t2.FID = t1.FID
left join T_BD_MATERIAL t3 on t3.FMATERIALID = t1.FMATERIALID
where t2.FBILLNO = 'XSCKD000036'
--物料名称
select * from T_BD_MATERIAL_L
--
select t2.FBILLNO,t3.FNUMBER,t4.FNAME from T_SAL_OUTSTOCKENTRY t1
inner join T_SAL_OUTSTOCK t2 on t2.FID = t1.FID
left join T_BD_MATERIAL t3 on t3.FMATERIALID = t1.FMATERIALID
left join T_BD_MATERIAL_L t4 on t4.FMATERIALID = t1.FMATERIALID AND t4.FLOCALEID = 2052
where t2.FBILLNO = 'XSCKD000036'
select t2.FBILLNO,t3.FNUMBER,t4.FNAME,t1.FREALQTY from T_SAL_OUTSTOCKENTRY t1
inner join T_SAL_OUTSTOCK t2 on t2.FID = t1.FID
left join T_BD_MATERIAL t3 on t3.FMATERIALID = t1.FMATERIALID
left join T_BD_MATERIAL_L t4 on t4.FMATERIALID = t1.FMATERIALID AND t4.FLOCALEID = 2052
where t2.FBILLNO = 'XSCKD000036'
--销售出库单,订单单号
select FSoorDerno,* from T_SAL_OUTSTOCKENTRY_R
select t2.FBILLNO,t3.FNUMBER,t4.FNAME,t1.FREALQTY,t5.FSOORDERNO from T_SAL_OUTSTOCKENTRY t1
inner join T_SAL_OUTSTOCK t2 on t2.FID = t1.FID
left join T_BD_MATERIAL t3 on t3.FMATERIALID = t1.FMATERIALID
left join T_BD_MATERIAL_L t4 on t4.FMATERIALID = t1.FMATERIALID AND t4.FLOCALEID = 2052
inner join T_SAL_OUTSTOCKENTRY_R t5 on t5.FENTRYID = t1.FID
where t2.FBILLNO = 'XSCKD000036'
![image-20230417101033874.webp](/download/0100202749d9d86a4a71b15dde9cebf6662e.webp)
#### 2.代码
官方提示说DBUtils.ExecuteDataSet方法已过期,就用DBUtils.ExecuteDynamicObject搞了下
public override void OnLoad(EventArgs e)
{
base.OnLoad(e);
//接收传递过来的参数
//从TestFormPlugIn.cs的BarItemClick()中传递过来的
//DynamicFormShowParameter form = new DynamicFormShowParameter();
//form.FormId = "k5e67ca60f42947cfbed164cd90280d43";
//form.CustomParams.Add("FBillNo", Convert.ToString(this.View.Model.GetValue("FBillNo")));
FBillNo = this.View.OpenParameter.GetCustomParameter("FBillNo").ToString();
string sql = string.Format(@"/*dialect*/select t1.FID,t2.FBILLNO,t3.FNUMBER,t4.FNAME,t1.FREALQTY,t5.FSOORDERNO from T_SAL_OUTSTOCKENTRY t1
inner join T_SAL_OUTSTOCK t2 on t2.FID = t1.FID
left join T_BD_MATERIAL t3 on t3.FMATERIALID = t1.FMATERIALID
left join T_BD_MATERIAL_L t4 on t4.FMATERIALID = t1.FMATERIALID AND t4.FLOCALEID = 2052
inner join T_SAL_OUTSTOCKENTRY_R t5 on t5.FENTRYID = t1.FID
where FSOORDERNO = '{0}'"
, FBillNo);
//dt = DBUtils.ExecuteDataSet(this.Context, sql).Tables[0];
//if (dt.Rows.Count > 0)
//{
// //给单据体赋值,构造动态表单
// Entity entity = this.View.BillBusinessInfo.GetEntity("F_WNZJ_Entity");
// //转换成行
// DynamicObjectCollection rows = this.Model.GetEntityDataObject(entity);
// //把加载的数据加入到单据体行集合中
// for (int i = 0; i < dt.Rows.Count; i++)
// {
// //每一行的值定义成DynamicObject类型
// DynamicObject row = new DynamicObject(entity.DynamicObjectType);
// entity.SeqDynamicProperty.SetValue(row, i + 1);
// //出库单号
// row["F_WNZJ_Text"] = dt.Rows[i]["FBILLNO"].ToString();
// //物料编码
// row["F_WNZJ_Text1"] = dt.Rows[i]["FNUMBER"].ToString();
// //物料名称
// row["F_WNZJ_Text2"] = dt.Rows[i]["FNAME"].ToString();
// //出库数量
// row["F_WNZJ_Text3"] = dt.Rows[i]["FREALQTY"].ToString();
// rows.Add(row);
// }
//}
DynamicObjectCollection dyOC = DBUtils.ExecuteDynamicObject(this.Context, sql);
if (dyOC.Count > 0)
{
//给单据体赋值,构造动态表单
Entity entity = this.View.BillBusinessInfo.GetEntity("F_WNZJ_Entity");
//转换成行
DynamicObjectCollection rows = this.Model.GetEntityDataObject(entity);
int j = 0;
foreach (DynamicObject o in dyOC)
{
//每一行的值定义成DynamicObject类型
DynamicObject row = new DynamicObject(entity.DynamicObjectType);
entity.SeqDynamicProperty.SetValue(row, j + 1);
//出库单号
row["F_WNZJ_Text"] = o["FBILLNO"].ToString();
//物料编码
row["F_WNZJ_Text1"] = o["FNUMBER"].ToString();
//物料名称
row["F_WNZJ_Text2"] = o["FNAME"].ToString();
//出库数量
row["F_WNZJ_Text3"] = o["FREALQTY"].ToString();
//出库数量
row["F_WNZJ_Text4"] = o["FID"].ToString();
rows.Add(row);
}
}
}
#### 3.效果
![image-20230417143631212.webp](/download/0100c781508489984ab1ab437a2f719e5c33.webp)
### 业务场景:双击单据体行打开销售订单
/// <summary>
/// 单据体行双击事件
/// </summary>
/// <param name="e"></param>
public override void EntityRowDoubleClick(EntityRowClickEventArgs e)
{
base.EntityRowDoubleClick(e);
//打开单据查看实例
BillShowParameter para = new BillShowParameter();
para.OpenStyle.ShowType = Kingdee.BOS.Core.DynamicForm.ShowType.NonModal;
para.FormId = "SAL_OUTSTOCK";
para.Status = OperationStatus.VIEW;
para.PKey = this.View.Model.GetValue("F_WNZJ_Text4", e.Row).ToString();
para.ParentPageId = this.View.ParentFormView.PageId;
this.View.ShowForm(para);
}
![image-20230417143852240.webp](/download/0100b995bbdf88c94f398661c259febbda1e.webp)
### 业务场景:动态表单反写数据
#### 1.点击返回数据按钮
public override void BarItemClick(BarItemClickEventArgs e)
{
base.BarItemClick(e);
//定义一个计数器
int count = 0;
if (e.BarItemKey.Equals("WNZJ_tbButton_Return"))
{
//获取动态表单的值
//定义一个函数
//获取动态表单的单据体F_WNZJ_Entity
Entity entity = this.View.BillBusinessInfo.GetEntity("F_WNZJ_Entity");
//将取得的单据体转换成列表集合(读取全部行)
DynamicObjectCollection entityDataObject = this.View.Model.GetEntityDataObject(entity);
//定义一个接收dymat
DynamicObjectCollection dymat = new DynamicObjectCollection(entity.DynamicObjectType, null);
foreach (DynamicObject current in entityDataObject)
{
//复选框F_WNZJ_CheckBox,转换成大写
if(current["F_WNZJ_CheckBox"].ToString().ToUpper() == "TRUE")
{
dymat.Add(current);
count++;
}
}
if(count == 0)
{
this.View.ShowMessage("请选择数据行");
return;
}
if(count > 1)
{
this.View.ShowMessage("只能选择一行");
return;
}
if(count == 1)
{
//返回主表界面
this.View.ReturnToParentWindow(dymat);
this.View.Close();
}
}
}
#### 2.读取返回数据
//32.2打开动态表单页面
if (e.BarItemKey.Equals("WNZJ_tbButtonOP"))
{
DynamicFormShowParameter form = new DynamicFormShowParameter();
form.FormId = "k5e67ca60f42947cfbed164cd90280d43";
//
form.CustomParams.Add("FBillNo", Convert.ToString(this.View.Model.GetValue("FBillNo")));
//1.直接弹窗
//this.View.ShowForm(form);
//2.动态接收数据,返回的数据都放在result上面
this.View.ShowForm(form,delegate(FormResult result)
{
//定义接收值,转换成DynamicObjectCollection类型
DynamicObjectCollection returnData = (DynamicObjectCollection)result.ReturnData;
if (returnData != null)
{
//把整个单据拆分成一行一行
DynamicObject entryRow = returnData[0];
//把接收回来的值进行赋值
//物料编码
this.View.Model.SetValue("F_WNZJ_WLBM", entryRow["F_WNZJ_Text1"]);
//物料名称
this.View.Model.SetValue("F_WNZJ_WLMC", entryRow["F_WNZJ_Text2"]);
//出库单号
this.View.Model.SetValue("F_WNZJ_CKDH", entryRow["F_WNZJ_Text"]);
//出库数量
this.View.Model.SetValue("F_WNZJ_CKSL", entryRow["F_WNZJ_Text3"]);
//出库FID
this.View.Model.SetValue("F_WNZJ_CKID", entryRow["F_WNZJ_Text4"]);
}
});
}
#### 3.执行效果
![image-20230418115207197.webp](/download/01003433c8d9f55a48bd8513c5a89ad553d5.webp)
### 业务场景:根据参数修改页面内容
/// <summary>
/// 初始化,对其他界面传来的参数进行处理,对控件某些属性进行处理
/// 这里不宜对数据DataModel进行处理
/// </summary>
/// <param name="e"></param>
public override void OnInitialize(InitializeEventArgs e)
#### 触发时机:请求加载页面时触发,此时Model还没有初始化,还是个空对象,但是View已初始化
#### 应用场景:请求打开一个页面时,可以在此事件中初始化当前插件的全局属性,也可以修改当前页面的控件属性值(控件大小、字段标题、表单标题等等)
#### 1.传递参数
form.CustomParams.Add("F_WNZJ_CheckBox", Convert.ToString(this.View.Model.GetValue("F_WNZJ_CheckBox")));
#### 2. OnInitialize
public override void OnInitialize(InitializeEventArgs e)
{
//
base.OnInitialize(e);
//接收传递过来的值
string sfrk = this.View.OpenParameter.GetCustomParameter("F_WNZJ_CheckBox").ToString();
if(sfrk == "True")
{
//
LocaleValue title = new LocaleValue("采购入库查询");
this.View.SetFormTitle(title);
//出库单号的标题,改成入库单号
this.View.GetControl("F_WNZJ_Text").Text = "(改)入库单号";
this.View.GetControl("F_WNZJ_Text3").Text = "(改)采购入库数量";
//动态赋值,不加载原先的值
this.View.SendDynamicFormAction(View);
}
}
#### 3.效果
![image-20230418173428477.webp](/download/01000336ea6f8f394131a9bd17707767ac50.webp)
### 业务场景:权限校验
#### 1.业务代码
//获取用户登录的全部信息 this.Context
//校验查看权限 PermissionConst.View
PermissionAuthResult IResult = PermissionServiceHelper.FuncPermissionAuth(
this.Context,
new BusinessObject()
{
Id = "SAL_OUTSTOCK"
},
PermissionConst.View);
if (IResult.Passed)
{
//打开单据查看实例
BillShowParameter para = new BillShowParameter();
para.OpenStyle.ShowType = Kingdee.BOS.Core.DynamicForm.ShowType.NonModal;
para.FormId = "SAL_OUTSTOCK";
para.Status = OperationStatus.VIEW;
para.PKey = this.View.Model.GetValue("F_WNZJ_Text4", e.Row).ToString();
para.ParentPageId = this.View.ParentFormView.PageId;
this.View.ShowForm(para);
}
else
{
this.View.ShowMessage("没有查看权限");
return;
}
####
### 业务场景:CreateNewData事件
#### 触发时机:View已完成初始化,开始进入Model数据对象(Model.DataObject)初始化
#### 应用场景:插件自定义Model.DataObject数据包,插件如构建此数据包,即忽略平台构建默认数据包
public override void CreateNewData(BizDataEventArgs e)
{
base.CreateNewData(e);
//接收传递过来的参数
//从TestFormPlugIn.cs的BarItemClick()中传递过来的
//DynamicFormShowParameter form = new DynamicFormShowParameter();
//form.FormId = "k5e67ca60f42947cfbed164cd90280d43";
//form.CustomParams.Add("FBillNo", Convert.ToString(this.View.Model.GetValue("FBillNo")));
FBillNo = this.View.OpenParameter.GetCustomParameter("FBillNo").ToString();
string sql = string.Format(@"/*dialect*/select t1.FID,t2.FBILLNO,t3.FNUMBER,t4.FNAME,t1.FREALQTY,t5.FSOORDERNO from T_SAL_OUTSTOCKENTRY t1
inner join T_SAL_OUTSTOCK t2 on t2.FID = t1.FID
left join T_BD_MATERIAL t3 on t3.FMATERIALID = t1.FMATERIALID
left join T_BD_MATERIAL_L t4 on t4.FMATERIALID = t1.FMATERIALID AND t4.FLOCALEID = 2052
inner join T_SAL_OUTSTOCKENTRY_R t5 on t5.FENTRYID = t1.FID
where FSOORDERNO = '{0}'"
, FBillNo);
DynamicObjectCollection dyOC = DBUtils.ExecuteDynamicObject(this.Context, sql);
if (dyOC.Count > 0)
{
//创建界面需要的数据对象
e.BizDataObject = new DynamicObject(this.View.OpenParameter.FormMetaData.BusinessInfo.GetDynamicObjectType());
//获取该业务对象的数据包
BusinessInfo info = this.View.OpenParameter.FormMetaData.BusinessInfo;
//获取整个单据体信息
Entity entity = info.GetEntity("F_WNZJ_Entity");
//列
Field FOutBillNo = info.GetField("F_WNZJ_Text");
Field FNUMBER = info.GetField("F_WNZJ_Text1");
Field FNAME = info.GetField("F_WNZJ_Text2");
Field FREALQTY = info.GetField("F_WNZJ_Text3");
Field FID = info.GetField("F_WNZJ_Text4");
//定义单据集合
DynamicObjectCollection rows = (DynamicObjectCollection)entity.DynamicProperty.GetValue(e.BizDataObject);
int j = 0;
foreach (DynamicObject o in dyOC)
{
//每一行的值定义成DynamicObject类型
DynamicObject row = new DynamicObject(entity.DynamicObjectType);
entity.SeqDynamicProperty.SetValue(row, j + 1);
FOutBillNo.DynamicProperty.SetValue(row, o["FBILLNO"].ToString());
FNUMBER.DynamicProperty.SetValue(row, o["FNUMBER"].ToString());
FNAME.DynamicProperty.SetValue(row, o["FNAME"].ToString());
FREALQTY.DynamicProperty.SetValue(row, o["FREALQTY"].ToString());
FID.DynamicProperty.SetValue(row, o["FID"].ToString());
rows.Add(row);
}
}
}
### 业务场景:BeforeUpdateValue
#### 触发时机:更新字段值前触发
#### 应用场景:界面字段值更新时允许用户对即将录入的值做检查
#### 备注:马上触发值更新事件需要在BOSIDE中选择”即时触发值更新事件"属性
public override void BeforeUpdateValue(BeforeUpdateValueEventArgs e)
{
switch (e.Key.ToUpperInvariant())
{
//case "FXXX":通过字段的Key[大写]来区分不同的控件的数据变化功能,如果要阻止该次变化,可以用e.Cancel = true;
// e.Cancel = true;
// break;
case "F_WNZJ_DATE":
if(e.Value != "")
{
//取得值
DateTime date1 = Convert.ToDateTime(e.Value);
//获取当前时间
DateTime now = Convert.ToDateTime(DateTime.Now);
TimeSpan ts = date1 - now;
if(ts.Days < 0)
{
this.View.Model.SetValue("F_WNZJ_Date", "");
e.Cancel = true;
this.View.ShowMessage("输入的日期不能小于当前日期");
}
}
break;
default:
break;
}
}
### 业务场景:AfterDeleteRow
#### 触发时机:分录行删除后触发
#### 应用场景:删除分录行之后,根据业务需要修改字段值或控件可见性、可用性、修改其他相关信息
public override void AfterBindData(EventArgs e)
{
base.AfterBindData(e);
//打开单据加载后,调用求和事件
this.View.Model.SetValue("F_WNZJ_Decimal", this.GetSumQty());
//刷新字段
this.View.UpdateView("F_WNZJ_Decimal");
}
public override void AfterDeleteRow(AfterDeleteRowEventArgs e)
{
base.AfterDeleteRow(e);
//每删除一次调用求和事件
this.View.Model.SetValue("F_WNZJ_Decimal", this.GetSumQty());
//刷新字段
this.View.UpdateView("F_WNZJ_Decimal");
}
public double GetSumQty()
{
Double Qty = 0.0;
//获取单据体所有信息
Entity entity = this.View.BillBusinessInfo.GetEntity("F_WNZJ_Entity");
//获取到集合里面
DynamicObjectCollection dyOC = this.View.Model.GetEntityDataObject(entity);
if(dyOC!= null)
{
//常规的搞法,循环取值
//for (int i = 0; i < dyOC.Count; i++)
//{
// if(Convert.ToString(this.View.Model.GetValue("F_WNZJ_Text3", i))!="")
// {
// Qty += Convert.ToDouble(this.View.Model.GetValue("F_WNZJ_Text3", i));
// }
//}
//换了写法看看
Qty = dyOC.Sum(x => Convert.ToDouble(x["F_WNZJ_Text3"]));
}
return Qty;
}
![image-20230419150557400.webp](/download/0100bee7309fbb5c4812854e5bc619996bb7.webp)
关于运行单据/列表测试的时候提示“用户登录失败,会话标识[XXXXXX]无效”的问题,经过测试发现如果我不启动开发环境的话就是正常的,启用了开发环境之后就不行了,大家注意下
动态表单相关踩坑记录23.04.19
近期在搞动态表单相关的,这块社区教程还是比较丰富的,踩坑后问题也不大### 业务场景:打开销售订单,点击按钮,弹出动态表单#### 1.增...
点击下载文档
本文2024-09-16 17:14:42发表“云星空知识”栏目。
本文链接:https://wenku.my7c.com/article/kingdee-k3cloud-14464.html
您需要登录后才可以发表评论, 登录登录 或者 注册
最新文档
热门文章