业务需求:资产卡片使用分配表体添加项目字段,资产卡片变更选择卡片时将项目字段携带到使用分配前和使用分配后,审核后能更新到资产卡片上
具体实现:a、扩展资产卡片,添加自定义字段
b、扩展资产卡片变更单,添加自定义字段
c、编写资产卡片变更单表单插件实现选取卡片时携带自字段字段,
public override void DataChanged(DataChangedEventArgs e)
{
base.DataChanged(e);
if (e.Field.Key.EqualsIgnoreCase("FAlterId")|| e.Field.Key.EqualsIgnoreCase("FPeriodEnddate"))
{
DynamicObject alterObject = this.View.Model.GetValue("FAlterId") as DynamicObject;
if (alterObject!=null)
{
string number = alterObject["Number"].ToString();
StringBuilder strSql = new StringBuilder();
strSql.AppendFormat("/*dialect*/select v1.FSEQ,v1.F_ZYF_ASSISTANT,v2.FNUMBER,v1.FASSETNO from t_fa_card v0 ");
strSql.AppendFormat(" inner join t_fa_allocation v1 on v0.FALTERID=v1.FALTERID ");
strSql.AppendFormat(" inner join T_BAS_ASSISTANTDATAENTRY v2 on v2.FENTRYID=v1.F_ZYF_ASSISTANT and v2.fid='5ecf90682947c3' ");
strSql.AppendFormat(" where FISNEWREC=2 and v0.FNUMBER= '{0}'", number);
DynamicObjectCollection dy= DBUtils.ExecuteDynamicObject(this.Context, strSql.ToString());
DynamicObject billObj = this.View.Model.DataObject;
DynamicObjectCollection preAllocateObj = billObj["PreAllocateEntity"] as DynamicObjectCollection;
DynamicObjectCollection allocateObj = billObj["AllocateEntity"] as DynamicObjectCollection;
int preRowCount=this.View.Model.GetEntryRowCount("FPreAllocateEntity");
int allRowCount = this.View.Model.GetEntryRowCount("FAllocateEntity");
for (int row = 0; row < preRowCount; row++)
{
string preSeq = preAllocateObj[row]["SEQ"].ToString();
foreach (var item in dy)
{
if (item["FSEQ"].ToString().Equals(preSeq))
{
this.View.Model.SetItemValueByID("F_ZYF_Assistant", item["F_ZYF_ASSISTANT"], row);
}
}
}
for (int row = 0; row < allRowCount; row++)
{
string allSeq = allocateObj[row]["SEQ"].ToString();
foreach (var item in dy)
{
if (item["FSEQ"].ToString().Equals(allSeq))
{
this.View.Model.SetItemValueByNumber("F_ZYF_Assistant1", item["FNUMBER"].ToString(), row);
}
}
}
this.View.UpdateView();
}
}
}
注这里只能用this.View.UpdateView()刷新整个表单,不能只刷新使用分配表体或是单独自定义字段
读取卡片数据时可以使用元数据加载表单数据,此处就直接sql取了
d、编写卡片变更审核插件
public override void EndOperationTransaction(EndOperationTransactionArgs e)
{
base.EndOperationTransaction(e);
if (this.FormOperation.Operation.EqualsIgnoreCase("Audit"))
{
List<string> sqlArray = new List<string>();
foreach (var item in e.DataEntitys)
{
long id = Convert.ToInt64(item["id"]);
long afterAlterId = Convert.ToInt64(item["AfterAlterId"]);//变更后Id
string billno = item["billno"].ToString();
long alterId = (item["AlterId"] as DynamicObject)!=null? Convert.ToInt64((item["AlterId"] as DynamicObject)["Id"]): 0; //卡片ID
StringBuilder strSql = new StringBuilder();
strSql.AppendFormat("/*dialect*/update v1 set F_ZYF_ASSISTANT=v0.F_ZYF_Assistant1 from T_FA_ChangeAlloc v0 ");
strSql.AppendFormat(" inner join t_fa_allocation v1 on v0.FSEQ = v1.FSEQ and v0.FPREALLOCASSETNO = v1.FASSETNO ");
strSql.AppendFormat(" where v0.fid = {0} and FALTERID = {1}",id, afterAlterId);
DBUtils.Execute(this.Context, strSql.ToString());
}
}
}
7.5版本审核时能取到变更后的AfterAlterId,但7.2版本不行。如果是7.2版本,则需要使用下面代码
public override void EndOperationTransaction(EndOperationTransactionArgs e)
{
base.EndOperationTransaction(e);
if (this.FormOperation.Operation.EqualsIgnoreCase("Audit"))
{
List<string> sqlArray = new List<string>();
foreach (var item in e.DataEntitys)
{
long id = Convert.ToInt64(item["id"]);
StringBuilder strSql = new StringBuilder();
strSql.AppendFormat("/*dialect*/update v1 set v1.F_BDI_t_GCXM_DA=v0.F_BDI_t_GCXM_DA1,v1.F_BDI_t_GCXM_DXGC=v0.F_BDI_t_GCXM_DXGC1 from T_FA_ChangeAlloc v0 ");
strSql.AppendFormat(" inner join t_fa_allocation v1 on v0.FSEQ = v1.FSEQ and v0.FPREALLOCASSETNO = v1.FASSETNO ");
strSql.AppendFormat(" inner join t_fa_card v2 on v2.FALTERID = v1.FALTERID ");
strSql.AppendFormat(" where v0.fid = {0} and FISNEWREC=2", id);
DBUtils.Execute(this.Context, strSql.ToString());
}
}
}
实现效果:
变更前:资产卡片
变更前:资产卡片变更单
变更后:变更单审核
变更后:卡片
推荐阅读