点击事件写成公共方法
金蝶云社区-Zw814
Zw814
0人赞赏了该文章 615次浏览 未经作者许可,禁止转载编辑于2016年08月01日 19:15:36

点击事件是否可以写成公共方法?需求:条码规则新增界面,表体出现多条流水号时不能保存
下面代码为已成功的代码:
public class BarcodeRuleBill : AbstractBillPlugIn
{
public override void BarItemClick(Kingdee.BOS.Core.DynamicForm.PlugIn.Args.BarItemClickEventArgs e)
{
string strType = string.Empty;
int iCount=0,iSign = 0;
EntryEntity entryEntity = null;
DynamicObjectCollection docNow = null;
base.BarItemClick(e);
try
{
if (e.BarItemKey.ToUpper().Equals("tbSplitSave".ToUpper()) || e.BarItemKey.ToUpper().Equals("tbSave".ToUpper()))
{
entryEntity = this.Model.BillBusinessInfo.GetEntryEntity("FEntity");
if (entryEntity != null)
{
iCount = this.Model.GetEntryRowCount("FEntity");
docNow = this.Model.GetEntityDataObject(entryEntity);
foreach (DynamicObject doRow in docNow)
{
//判断表体行记录是否为空
if (doRow["FTYPE"] == null)
{
this.View.Model.DeleteEntryRow("FEntity",iCount);
continue;
}
strType = (doRow["FTYPE"] as DynamicObject)["FNAME"].ToString();
//类别为"流水号"时做记录
if (strType.Equals("流水号"))
{
iSign += 1;
}
if (iSign > 1)
{
this.View.ShowErrMessage("类别不能出现多条流水号!");
e.Cancel = true;
}
iCount++;
}
}
}
}
catch (Exception ex)
{
this.View.ShowErrMessage(ex.Message, "保存失败!", MessageBoxType.Notice);
}
}

下面为写的公共方法:
public static void ControlSerialNumber(Kingdee.BOS.Core.DynamicForm.PlugIn.Args.BarItemClickEventArgs e,Context ctx,string strGUID,string strBillNo)
{
string strType = string.Empty;
int iSign = 0;
IMetaDataService metadataService = Kingdee.BOS.App.ServiceHelper.GetService();
FormMetadata fmdPrintData = null;
DynamicObject[] doMaterialNo = null;
DynamicObjectCollection docCollection = null;
try
{
fmdPrintData = metadataService.Load(ctx, strGUID, true) as FormMetadata;
doMaterialNo = BusinessDataServiceHelper.Load(ctx, new object[] { strBillNo }, fmdPrintData.BusinessInfo.GetDynamicObjectType());
docCollection = doMaterialNo[0]["FEntity"] as DynamicObjectCollection;
foreach (DynamicObject doRow in docCollection)
{
strType = (doRow["FTYPE"] as DynamicObject)["FNAME"].ToString();

if (strType.Equals("流水号"))
{
iSign += 1;
}
if (iSign > 1)
{
throw new Exception("类别不能出现多条流水号!");
e.Cancel = true;
return;
}
}
}
catch (Exception ex)
{
throw new Exception("保存失败!\r\n" + ex.Message);
}
}

但是这样写好像不对。