单据列表中批量“审核”功能不能正确执行二开服务插件
金蝶云社区-愚公移山
愚公移山
0人赞赏了该文章 1,029次浏览 未经作者许可,禁止转载编辑于2015年12月04日 08:14:34

我二次开发的单据,在单据中执行审核操作时,能完全正确地处理审核操作中的插件程序,但在单据列表中批量选取单据进行审核操作时,只能正确执行第一个单据中的插件程序,后面的单据不执行插件中的程序,但最还是能将单据状态改为“审核状态”。
注意:我的插件中采用的事务是:

EndOperationTransaction,
操作事务结束插件,此插件在事务内运行,出错后系统会回滚事务。
下面为插件源代码:
[System.ComponentModel.Description("委外转移单审核操作计算外协存货量")]
public class wwzyconfirm : AbstractOperationServicePlugIn
{
public override void EndOperationTransaction(EndOperationTransactionArgs e)
{
base.EndOperationTransaction(e);
StringBuilder sb = new StringBuilder();
string billno = "", djlx = this.BusinessInfo.GetForm().ToString(), stable = "", billtype = "";
foreach (DynamicObject obj in e.DataEntitys)
{
if (obj.DynamicObjectType.ToString() == "BillHead")
{
billno = obj["BillNo"].ToString();
billtype = billno.Substring(7, 4);
break;
}
}
stable = this.BusinessInfo.RootTable.Entity.TableName.ToString();
sb.AppendLine(string.Format("/*dialect*/ update AJL_PRD_PGDHDJLIST_true set fbillstatus='C',F_AJL_CONFIRMDATE =a.FAPPROVEDATE from {0} a where AJL_PRD_PGDHDJLIST_true.F_AJL_DJBH='{1}' and AJL_PRD_PGDHDJLIST_true.F_AJL_DJBH =a.FBILLNO ", stable, billno));
DataSet ds = Kingdee.BOS.App.Data.DBUtils.ExecuteDataSet(this.Context, "select a.fpgdh,a.fgx,a.fqty,a.fmovetime from AJL_Prd_workmove_body a inner join AJL_Prd_workmove_head b on a.FID =b.FID where b.FBILLNO ='" + billno + "'");
foreach (DataRow row in ds.Tables[0].Rows)
{
string pgdh = row["fpgdh"].ToString();
string gx = row["fgx"].ToString();
decimal qty = Convert.ToDecimal(row["fqty"]);
string indate = row["fmovetime"].ToString();
try //防止未入工序时出错
{
string[] sArray = Regex.Split(gx, ";", RegexOptions.IgnoreCase);
for (int i = 0; i < sArray.Length; i++)
{
string seq = sArray.Substring(0, sArray.IndexOf("("));
switch (billtype )
{
//转出工序累计转移数量
case "AB31": //委外发出
case "AB35": //委外报损
case "AB34": //委外盘亏
sb.AppendLine(string.Format(" update ajl_prd_pgd_body set FJGOUTQTY=FJGOUTQTY+{0} where fid={1} and fgxxh={2}", qty, pgdh, seq));
//计算最新转移日期
sb.AppendLine(" update ajl_prd_pgd_body set ajl_prd_pgd_body.FLASTOUT=a.fdate from (");
if (i == 0)
{
sb.AppendLine(string.Format(" select max(a.fmovetime) as fdate from AJL_Prd_workmove_body a inner join AJL_Prd_workmove_head b on a.FID =b.FID where a.FPGDH in (select a.FPGDH from AJL_Prd_workmove_body a inner join AJL_Prd_workmove_head b on a.FID =b.FID where b.FBILLNO ='{0}' and b.FDOCUMENTSTATUS='C') and a.FGX like '%{1}(%' and a.FPGDH={2} and b.fbillno like '%AC1[12]%'", billno, seq, pgdh));
}
else
{
sb.AppendLine(string.Format(" select max(a.fmovetime) as fdate from AJL_Prd_workmove_body a inner join AJL_Prd_workmove_head b on a.FID =b.FID where a.FPGDH in (select a.FPGDH from AJL_Prd_workmove_body a inner join AJL_Prd_workmove_head b on a.FID =b.FID where b.FBILLNO ='{0}' and b.FDOCUMENTSTATUS='C') and a.FGX like '%;{1}(%' and a.FPGDH={2} and b.fbillno like '%AC1[12]%'", billno, seq, pgdh));
}
sb.AppendLine(string.Format(" ) a where ajl_prd_pgd_body.fid={0} and fgxxh={1} ", pgdh, seq));
break;
//委外退货扣减工序转移数量
case "AB36"://委外退货
sb.AppendLine(string.Format(" update ajl_prd_pgd_body set FJGOUTQTY=FJGOUTQTY-{0} where fid={1} and fgxxh={2}", qty, pgdh, seq));
break;
//委外盘盈、委外收入无需处理
}
}
}
catch { }
}
//转出方在制数量处理
switch (billtype)
{
case "AB31": //委外发出扣本厂车间在制数量
sb.AppendLine(" update AJL_STK_PgdInDept set AJL_STK_PgdInDept.FQTY_DEPT =AJL_STK_PgdInDept.FQTY_DEPT - a.fqty from ");
sb.AppendLine(string.Format(" (select a.foutdeptid,a.foutorgid,b.fpgdh,b.fqty,a.FSUPPLIER_SUP from AJL_Prd_workmove_head a inner join AJL_Prd_workmove_body b on a.FID =b.FID where a.FBILLNO ='{0}' ) a ", billno));
sb.AppendLine(" where AJL_STK_PgdInDept.FPGDH=a.fpgdh and AJL_STK_PgdInDept.FDEPTID =a.foutdeptid and AJL_STK_PgdInDept.FOUTORGID_DEPT =a.FOUTORGID ");
break;
case "AB35": //委外报损
case "AB34": //委外盘亏
case "AB32": //委外收入
sb.AppendLine(" update AJL_STK_PgdInDept set AJL_STK_PgdInDept.FQTY_DEPT =AJL_STK_PgdInDept.FQTY_DEPT - a.fqty from ");
sb.AppendLine(string.Format(" (select a.FSUPID,a.foutorgid,b.fpgdh,b.fqty,a.FSUPPLIER_SUP from AJL_Prd_workmove_head a inner join AJL_Prd_workmove_body b on a.FID =b.FID where a.FBILLNO ='{0}' ) a ", billno));
sb.AppendLine(" where AJL_STK_PgdInDept.FPGDH=a.fpgdh and AJL_STK_PgdInDept.SupplierId =a.FSUPID and AJL_STK_PgdInDept.FOUTORGID_DEPT =a.FOUTORGID and AJL_STK_PgdInDept.Sup_subid=a.FSUPPLIER_SUP");
break;
case "AB36": //委外退货
sb.AppendLine(" update AJL_STK_PgdInDept set AJL_STK_PgdInDept.FQTY_DEPT =AJL_STK_PgdInDept.FQTY_DEPT + a.fqty from ");
sb.AppendLine(string.Format(" (select a.FSUPID,a.foutorgid,b.fpgdh,b.fqty,a.FSUPPLIER_SUP from AJL_Prd_workmove_head a inner join AJL_Prd_workmove_body b on a.FID =b.FID where a.FBILLNO ='{0}' ) a ", billno));
sb.AppendLine(" where AJL_STK_PgdInDept.FPGDH=a.fpgdh and AJL_STK_PgdInDept.SupplierId =a.FSUPID and AJL_STK_PgdInDept.FOUTORGID_DEPT =a.FOUTORGID and AJL_STK_PgdInDept.Sup_subid=a.FSUPPLIER_SUP");
break;
case "AB33": //委外盘盈无需处理
break;
}
//转入方在制数量处理
switch (billtype )
{
case "AB31": //委外发出增加供应商在制数量
case "AB33"://委外盘盈
case "AB36"://委外退货
//有存货记录时直接增加数量
sb.AppendLine(" update AJL_STK_PgdInDept set AJL_STK_PgdInDept.FQTY_DEPT =AJL_STK_PgdInDept.FQTY_DEPT + a.fqty from ");
sb.AppendLine(string.Format(" (select a.FSUPID,a.finorgid,b.fpgdh,b.fqty,a.FSUPPLIER_SUP from AJL_Prd_workmove_head a inner join AJL_Prd_workmove_body b on a.FID =b.FID where a.FBILLNO ='{0}' ) a ", billno));
sb.AppendLine(" where AJL_STK_PgdInDept.FPGDH=a.fpgdh and AJL_STK_PgdInDept.SupplierId =a.FSUPID and AJL_STK_PgdInDept.FOUTORGID_DEPT =a.finorgid and AJL_STK_PgdInDept.Sup_subid=a.FSUPPLIER_SUP");
//车间无存货记录时直接增加存货记录
sb.AppendLine(" insert into AJL_STK_PgdInDept(FPGDH,FMATERIAL_DEPT ,FBOMID_DEPT ,FQTY_DEPT ,SupplierId ,FOUTORGID_DEPT,Sup_subid )");
sb.AppendLine(string.Format(" select b.fpgdh,b.fmaterialid,b.fbomid,b.fqty,a.FSUPID,a.finorgid,a.FSUPPLIER_SUP from AJL_Prd_workmove_head a inner join AJL_Prd_workmove_body b on a.FID=b.FID where a.FBILLNO ='{0}' and a.FSUPID<>0 ", billno));
sb.AppendLine(" and not exists(select FPGDH from AJL_STK_PgdInDept where FPGDH =b.FPGDH and FOUTORGID_DEPT = a.FOUTORGID and SupplierId =a.FSUPID and Sup_SubId =a.FSUPPLIER_SUP ) ");
break;
case "AB32"://委外收入
case "AB35": //委外报损
//有存货记录时直接增加数量
sb.AppendLine(" update AJL_STK_PgdInDept set AJL_STK_PgdInDept.FQTY_DEPT =AJL_STK_PgdInDept.FQTY_DEPT + a.fqty from ");
sb.AppendLine(string.Format(" (select a.FINDEPTID,a.finorgid,b.fpgdh,b.fqty,a.FSUPPLIER_SUP from AJL_Prd_workmove_head a inner join AJL_Prd_workmove_body b on a.FID =b.FID where a.FBILLNO ='{0}' ) a ", billno));
sb.AppendLine(" where AJL_STK_PgdInDept.FPGDH=a.fpgdh and AJL_STK_PgdInDept.FDEPTID =a.FINDEPTID and AJL_STK_PgdInDept.FOUTORGID_DEPT =a.finorgid ");
//车间无存货记录时直接增加存货记录
sb.AppendLine(" insert into AJL_STK_PgdInDept(FPGDH,FMATERIAL_DEPT ,FBOMID_DEPT ,FQTY_DEPT ,Fdeptid ,FOUTORGID_DEPT)");
sb.AppendLine(string.Format(" select b.fpgdh,b.fmaterialid,b.fbomid,b.fqty,a.FINDEPTID,a.finorgid from AJL_Prd_workmove_head a inner join AJL_Prd_workmove_body b on a.FID=b.FID where a.FBILLNO ='{0}' ", billno));
sb.AppendLine(" and not exists(select FPGDH from AJL_STK_PgdInDept where FPGDH=b.FPGDH and FINORGID =a.FINORGID and FDEPTID =a.FINDEPTID ) ");
break;
case "AB34": //委外盘亏无需处理
break;
}
Kingdee.BOS.App.Data.DBUtils.Execute(this.Context, sb.ToString());
}
}