关闭子窗体返回值到父窗体,父窗体中数据无法刷新
金蝶云社区-zhouwb88
zhouwb88
1人赞赏了该文章 3,951次浏览 未经作者许可,禁止转载编辑于2015年02月25日 10:22:47

移动表单开发中,关闭子窗体返回值到父窗体,父窗体中数据无法刷新。具体代码如下:

子窗体的代码如下:
[code]///


/// 点击事件
///

///
public override void ButtonClick(ButtonClickEventArgs e)
{
base.ButtonClick(e);
switch (e.Key)
{
case "FBDZ_SAVE"://保存
try
{
string FMustQty = this.View.Model.GetValue("FMustQty").ToString();
double DmustQty = double.Parse(FMustQty == "" ? "0" : FMustQty);
RealQty = this.View.Model.GetValue("FRealQty").ToString();
double DRealQty = double.Parse(RealQty == "" ? "0" : RealQty);
if (DmustQty > DRealQty)
{
this.View.ShowMessage("实发数量不能小于应发数量。");
return;
}
if (DRealQty <= 0)
{
this.View.ShowMessage("实发数量不能小于0。");
return;
}
_data.Add(new KeyValuePair(materillSeq, DRealQty));
this.View.ShowMessage("修改成功。");
this.View.Close();
}
catch
{
this.View.ShowMessage("修改失败。实发数量非法。");
}
break;
}
}

///


/// 关闭时刷新父窗体
///

///
public override void BeforeClosed(BeforeClosedEventArgs e)
{
FormResult frt = new FormResult(_data);
this.View.ReturnToParentWindow(frt);
base.BeforeClosed(e);
}[/code]

父窗体代码如下:
[code]public override void EntityRowDoubleClick(EntityRowClickEventArgs e)
{
//修改实发数量
base.EntityRowDoubleClick(e);
if (e.Key.EqualsIgnoreCase("FMLVMainEntity"))
{
DynamicObject rowObj = this.View.Model.GetEntityDataObject(this.View.BillBusinessInfo.GetEntity("FMLVMainEntity"), e.Row - 1);
if (rowObj != null)
{
MobileShowParameter parameter = new MobileShowParameter();
parameter.PKey = rowObj["Id"].ToString();
parameter.FormId = "BDZ_RealQtyModify";
parameter.ParentPageId = this.View.PageId;
parameter.CustomParams.Add("FMaterialName", rowObj["FMaterialName"].ToString());
parameter.CustomParams.Add("FSpec", rowObj["FSpec"].ToString());
parameter.CustomParams.Add("FBDZ_CK", rowObj["FBDZ_CK"].ToString());
parameter.CustomParams.Add("FBDZ_MaterialSeq", rowObj["FBDZ_Matielot"].ToString());
parameter.CustomParams.Add("FBDZ_MustQty", rowObj["FBDZ_MustQty"].ToString());
parameter.CustomParams.Add("FBDZRealQty", rowObj["FBDZRealQty"].ToString());
parameter.CustomComplexParams.Add("ScanList", ScanList);
Action frt = new Action(getReturnData);
this.View.ShowForm(parameter, frt);
}
}
}

///


/// 获取子窗体的返回值
///

///
void getReturnData(FormResult frt)
{
List> _ReturnData = frt.ReturnData as List>;
if (null == _ReturnData || _ReturnData.Count == 0) return;
foreach (var item in _ReturnData)
{
if (listMaterialRealQty.Where(o => o.Key == item.Key).Count() > 0)
{
double realqty = listMaterialRealQty.Where(o => o.Key == item.Key).FirstOrDefault().Value;
this.listMaterialRealQty.Remove(new KeyValuePair(item.Key, realqty));
this.listMaterialRealQty.Add(new KeyValuePair(item.Key, item.Value));
}
else
this.listMaterialRealQty.Add(new KeyValuePair(item.Key, item.Value));
}
this.bindListView();
this.Model.SetValue("FBarCode", null);
this.View.UpdateView("F_BDZ_RealQy");
}[/code][code]///
/// 查询物料信息
///

///
private void bindListView()
{
if (MaterialObj == null) return;
this.View.Model.DeleteEntryData("FMLVMainEntity");
DynamicObjectCollection marterialInfo = MaterialObj["SAL_OUTSTOCKENTRY"] as DynamicObjectCollection;
this.Model.BeginIniti();
double MustQty = 0, sumMustQty = 0;//应发数量
double RealQty = 0, sumRealQty = 0;//实发数量
foreach (DynamicObject item in marterialInfo)
{
MustQty = double.Parse(item["MustQty"].ToString());
sumMustQty += MustQty;
RealQty = double.Parse(item["RealQty"].ToString());
sumRealQty += RealQty;
DynamicObject dyObjMarterial = item["MaterialID"] as DynamicObject;
if (dyObjMarterial == null) continue;
string MaterialName = dyObjMarterial["Name"] == null ? "" : dyObjMarterial["Name"].ToString();
string Specification = dyObjMarterial["Specification"] == null ? "" : dyObjMarterial["Specification"].ToString();
//仓库
string StockName = string.Empty;
DynamicObject dyObjStock = item["StockID"] as DynamicObject;
if (dyObjStock != null)
{
StockName = dyObjStock["Name"] == null ? "" : dyObjStock["Name"].ToString();
}
//仓位
string StockLocName = string.Empty;
DynamicObject dyObjStockLocId = item["StockLocID"] as DynamicObject;
if (dyObjStockLocId != null)
{
//StockLocName = dyObjStockLocId["Id"] == null ? "" : dyObjStockLocId["Id"].ToString();
if ((dyObjStockLocId[3] as DynamicObject) != null)
{
StockLocName = (dyObjStockLocId[3] as DynamicObject)["Name"] == null ? "" : (dyObjStockLocId[3] as DynamicObject)["Name"].ToString();
}
if ((dyObjStockLocId[5] as DynamicObject) != null)
{
StockLocName += (dyObjStockLocId[5] as DynamicObject)["Name"] == null ? "" : "." + (dyObjStockLocId[5] as DynamicObject)["Name"].ToString();
}
if ((dyObjStockLocId[7] as DynamicObject) != null)
{
StockLocName += (dyObjStockLocId[7] as DynamicObject)["Name"] == null ? "" : "." + (dyObjStockLocId[7] as DynamicObject)["Name"].ToString();
}
}
//单位
string UnitName = string.Empty;
DynamicObject dyObjUnitID = item["UnitID"] as DynamicObject;
if (dyObjUnitID != null)
{
UnitName = dyObjUnitID["Name"] == null ? "" : dyObjUnitID["Name"].ToString();
}

string MaterialID = item["MaterialID_Id"].ToString();
string lotid = item["Lot_Id"].ToString();
string Seq = item["Seq"].ToString();//分录编号
string FRealQty = string.Empty;
string MaterialIDAndSeq = MaterialID + "#" + Seq;
if (listMaterialRealQty.Count > 0 && listMaterialRealQty.Where(o => o.Key == MaterialIDAndSeq).Count() > 0)
{
FRealQty = listMaterialRealQty.Where(o => o.Key == MaterialIDAndSeq).FirstOrDefault().Value.ToString();
}
string RealOutQty = double.Parse(FRealQty == "" ? "0" : FRealQty).ToString("0.00");
//创建数据行并赋值
int currentrowindex = this.Model.GetEntryRowCount("FMLVMainEntity");
this.View.Model.CreateNewEntryRow("FMLVMainEntity");
this.Model.SetValue("FMaterialName", MaterialName, currentrowindex);
this.Model.SetValue("FSpec", Specification, currentrowindex);
this.Model.SetValue("FQty", MustQty > 0 ? MustQty.ToString("0.00") + "(应发); " : RealQty.ToString("0.00") + "(实发); ", currentrowindex);
this.Model.SetValue("F_BDZ_RealQy", RealOutQty + "(拣货)", currentrowindex);
this.Model.SetValue("F_BDZ_UnitName", UnitName, currentrowindex);
this.Model.SetValue("FBDZ_CK", StockName + ";" + StockLocName, currentrowindex);
this.Model.SetValue("FBDZ_Matielot", MaterialIDAndSeq, currentrowindex);
this.Model.SetValue("FBDZ_MustQty", MustQty.ToString("0.00"), currentrowindex);
this.Model.SetValue("FBDZRealQty", RealOutQty, currentrowindex);

if (!listMaterialid.Contains(new KeyValuePair(MaterialID, lotid)))
listMaterialid.Add(new KeyValuePair(MaterialID, lotid));

//应发数量
if (!listMaterialMustQty.Contains(new KeyValuePair(MaterialIDAndSeq, MustQty > 0 ? MustQty : RealQty)))
listMaterialMustQty.Add(new KeyValuePair(MaterialIDAndSeq, MustQty > 0 ? MustQty : RealQty));
}
this.Model.EndIniti();
IEntryState state = this.View.GetEntryState("FMLVMainEntity");
state.CurrentPageIndex = 0;
this.View.UpdateView("FMLVMainEntity");
this.View.GetControl("FMLVMainEntity").setSelection(200);
}[/code]