发货通知单的移动表单开发
金蝶云社区-钱宇梁
钱宇梁
0人赞赏了该文章 1,020次浏览 未经作者许可,禁止转载编辑于2016年10月11日 16:19:12

public class MobileBillPlugIn : AbstractMobilePlugin
{
protected FormMetadata _sourceBillMetadata = null;
private const string formId = "SAL_DELIVERYNOTICE";//8fee2eaa-c3eb-49d6-a38c-4a84a88dbce7 SAL_DELIVERYNOTICE
private DynamicObject[] activityInfos;
private BusinessInfo _businessInfo;
public FormMetadata SourceBillMetadata
{
get
{
if (_sourceBillMetadata == null)
{
_sourceBillMetadata = MetaDataServiceHelper.Load(this.Context, "SAL_DELIVERYNOTICE") as FormMetadata;
}
return _sourceBillMetadata;
}
}

protected DynamicObject _sourceObject = null;
public DynamicObject SourceObject
{
get
{
if (_sourceObject == null)
{
var srcBusinessInfo = SourceBillMetadata.BusinessInfo;
_sourceObject = new DynamicObject(srcBusinessInfo.GetDynamicObjectType());

}
return _sourceObject;
}
set
{
_sourceObject = value;
}
}

protected Dictionary _mobKey2SrcKey = null;
public Dictionary MobKey2SrcKey
{
get
{
if (_mobKey2SrcKey == null)
{
_mobKey2SrcKey = new Dictionary();
//_mobKey2SrcKey.Add("F_GZJH_MASTER", "FCreatorId");
_mobKey2SrcKey.Add("F_PAEZ_CUST", "FCustomerID");//客户
_mobKey2SrcKey.Add("F_PAEZ_goodsORG", "FDeliveryOrgID");//发货组织
_mobKey2SrcKey.Add("F_PAEZ_SALESORG", "FSaleOrgId");//销售组织
_mobKey2SrcKey.Add("F_PAEZ_BILLTYPE", "FBillTypeID");//单据类型
_mobKey2SrcKey.Add("F_PAEZ_Date", "FDate");//日期
//_mobKey2SrcKey.Add("F_PAEZ_BIBIE", "FSettleCurrID");//币别
//_mobKey2SrcKey.Add("FCustMatID", "FCustMatID");
//_mobKey2SrcKey.Add("F_PAEZ_Decimal", "FQty");
}
return _mobKey2SrcKey;
}
}

public override void OnLoad(EventArgs e)
{
base.OnLoad(e);

//如果传入内码,加载完整数据包
var srcBusinessInfo = SourceBillMetadata.BusinessInfo;
var openParameter = (this.View.OpenParameter as MobileOpenParameter);
if (openParameter != null && openParameter.PkValue != null)
{
this.SourceObject = BusinessDataServiceHelper.LoadSingle(this.Context, openParameter.PkValue, srcBusinessInfo, null);
}
//把源单数据同步赋值给当前移动表单的数据包
if (openParameter != null && openParameter.PkValue != null)
{

var dynamicObject = this.SourceObject;
foreach (var kv in MobKey2SrcKey)
{
var mobKey = kv.Key;
var srcKey = kv.Value;
var mobField = this.View.BusinessInfo.GetField(mobKey);
var srcField = srcBusinessInfo.GetField(srcKey);
//请保证元数据mobField和srcField字段类型一致
if (mobField == null || srcField == null
|| !this.Model.DataObject.DynamicObjectType.Properties.ContainsKey(mobField.PropertyName)) continue;

this.Model.DataObject[mobField.PropertyName] = dynamicObject[srcField.PropertyName];
if (mobField is BaseDataField && this.Model.DataObject[mobField.PropertyName] is DynamicObject)
{
this.Model.DataObject[mobField.PropertyName + "_Id"] = (this.Model.DataObject[mobField.PropertyName] as DynamicObject)["Id"];
}
}
//单据体(单据体行集合属性本身只读,可以通过单据体集合提供的方法,添加行、删除行)
DynamicObjectCollection entityRows = this.SourceObject["SAL_DELIVERYNOTICEENTRY"] as DynamicObjectCollection;//
// DynamicObjectCollection dy = this.Model.DataObject["FMobileListViewEntity"] as DynamicObjectCollection;
int i = 0;
this.Model.BeginIniti();
int rowIndex = this.Model.GetEntryRowCount("FMobileListViewEntity");
foreach (var entityRow in entityRows)
{
DynamicObject CustMatID = (DynamicObject)entityRow["MaterialID"];
String qty = Convert.ToString(entityRow["Qty"]);
DynamicObject UnitID = (DynamicObject)entityRow["UnitID"];
DynamicObject BaseUnitID = (DynamicObject)entityRow["BaseUnitID"];
this.View.Model.CreateNewEntryRow("FMobileListViewEntity");
this.Model.SetValue("FMaterialID", CustMatID, i);
this.Model.SetValue("F_PAEZ_Decimal", qty, i);
this.Model.SetValue("FUnitID", UnitID, i);
this.Model.SetValue("FBaseUnitID", BaseUnitID, i);
i++;
}
this.Model.EndIniti();
this.View.UpdateView("FMobileListViewEntity");
this.View.UpdateView("FMaterialID");
this.View.UpdateView("F_PAEZ_Decimal");
this.View.UpdateView("FUnitID");
this.View.UpdateView("FBaseUnitID");
this.Model.DataChanged = true;
}
}
上面代码中this.SourceObject = BusinessDataServiceHelper.LoadSingle(this.Context, openParameter.PkValue, srcBusinessInfo, null);获取一个单据的数据包,但是获得的SourceObject其中的数据相当有限, srcBusinessInfo中单据头至少有上百个字段,而SourceObject中实际存储的只有几十个字段,那剩下的字段数据如何获取,我这边实际碰到的问题是要加载发货通知单中的“结算币别”字段,但在SourceObject中找了很多遍发现并没有该字段,想请教下各位老师和大神结算币别这个字段的数据如何获取,也包括没有在SourceObject的其他字段存放在哪,如何获取,谢谢了