记录下思路
/// <summary> /// 审核与弃审时顺推金额 /// </summary> /// <param name="subDataTable">需要处理的表数据</param> /// <param name="isApprove">是否审核</param> /// <param name="billTabelName">单据的表名</param> /// <param name="orderTabelName">订单的表名</param> /// <remarks>2015-06-04 add by fuwp </remarks> private void processBill(LibDataTable subDataTable, bool isApprove) { //如果没有表数据则返回空 if (subDataTable == null) return; DataRow[] selectRow = null; 存储SQL执行语句集合 //List<string> sqlList = new List<string>(); //发票金额 decimal decBillingMny = decimal.Zero; //string execsql = string.Empty; 主表 //string masterTableName = getBillType() == BillTypeEnum.SCM0800 ? "T_SCM_SALEOUT" : "T_SCM_PURCHASEIN"; //子表 string subTabelName = getBillType() == BillTypeEnum.SCM0800 ? "T_SCM_SALEOUT_B" : "T_SCM_PURCHASEIN_B"; //订单 string orderTabelName = getBillType() == BillTypeEnum.SCM0800 ? "T_SCM_SALEORDER_B" : "T_SCM_PURCHASEORDER_B"; BillTypeEnum fromtype = BillTypeEnum.SCM0010; //4张业务单据表体正数合计>表体负数合计 bool isPositive = false; object result=null; foreach (DataRow drs in this.Tables[1].Rows) { if (drs.RowState == DataRowState.Deleted) continue; //开票登记表.发票金额--->业务单据主表的开票金额 decBillingMny = LibSysUtils.ToDecimal(drs["BillingMny"]); fromtype = (BillTypeEnum)Enum.Parse(typeof(BillTypeEnum), drs["FromBillType"].ToString()); //发票金额还小于0 进货单、销售单的主表金额为负(整个子表的金额合计为负数,则需要先满足所有的正数,在计算负数) //或者进货退货单、销售退货单的主表金额为正(整个子表的金额合计为正数,则需要先满足所有的负数,在计算正数) //4张业务单据表体正数合计>表体负数合计. //找到单据的子表数据 selectRow = subDataTable.Select(string.Format("masterid='{0}'", drs["FromBillID"])); //退货情况取值0-x if (fromtype == BillTypeEnum.SCM0030 || fromtype == BillTypeEnum.SCM0150) //退货情况 decBillingMny = 0 - decBillingMny; isPositive = LibSysUtils.ToDecimal(decBillingMny) > 0; result = subDataTable.Compute("count(masterid)", string.Format("masterid='{0}' and {1}", drs["FromBillID"], isPositive ? "totalMny<0" : "totalMny>0")); if (LibSysUtils.ToInt32(result) > 0) { if (!isPositive) //表头为负、表体存在正负数情况 processBillByNegative(decBillingMny, selectRow, isApprove, subTabelName, orderTabelName); else //表头为正、表体存在正负数情况 positive processBillByPositive(decBillingMny, selectRow, isApprove, subTabelName, orderTabelName); } else { //表体全为正数或者表体全为负数 processBillBySameBody(decBillingMny, selectRow, isApprove, subTabelName, orderTabelName); } } } /// <summary> /// 审核与弃审时顺推金额 /// </summar