using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Data;
using Kingdee.K3.SCM.Sal.Report;
using Kingdee.BOS;
using Kingdee.BOS.Util;
using Kingdee.BOS.Contracts;
using Kingdee.BOS.App.Data;
using Kingdee.BOS.Core.List;
using Kingdee.BOS.Core.Report;
using Kingdee.BOS.Orm.DataEntity;
using Kingdee.BOS.Contracts.Report;
using Kingdee.BOS.Core.CommonFilter;
using Kingdee.BOS.Core.Report.PlugIn;
namespace Kingdee.K3.SCM.App.Sal.Report.Bgextend
{
///
/// 销售出库明细表增加利润和利率字段
///
[Description("增加利润和利率字段")]
public class SaleOutStockDetailRptExtend : SaleOutStockDetailRpt
{
private string[] customRptTempTableNames;
//开始日期
private string startDate;
//结束日期
private string endDate;
///
/// 重载取数插件
/// 应付单扩展
///
///
///
public override void BuilderReportSqlAndTempTable(IRptParams filter, string tableName)
{
//设置全部变量值
this.setFilterValue(filter);
//设置精度控制
SetDecimal();
//创建临时表,用于存放自己的数据
IDBService dbservice = Kingdee.BOS.App.ServiceHelper.GetService
customRptTempTableNames = dbservice.CreateTemporaryTableName(this.Context, 1);
string strTable = customRptTempTableNames[0];
//调用基类的方法,获取初步的查询结果到临时表
base.BuilderReportSqlAndTempTable(filter, strTable);
//对初步的查询结果进行处理,然后写回基类默认的存放查询结果的临时表
StringBuilder sb = new StringBuilder();
string strSql = "select o.*,(FLCNOTAXOUTSTOCKAMOUNT-FLCOUTSTOCKTATALCOSTAMOUNT) as F_bg_Profit,(FNOTAXOUTSTOCKAMOUNT-FOUTSTOCKTATALCOSTAMOUNT) as F_bg_Profit_Settlement,s.FTAXRATE as F_bg_TaxRate into {0} "
+ " from {1} o left join (select FTAXRATE,fbillno from T_SAL_OUTSTOCK outstock left join T_SAL_OUTSTOCKENTRY_F outstockf on outstockf.FID=outstock.FID where fdate BETWEEN '" + startDate + "' and '" + endDate + "' "
+ " union all "
+ " select FTAXRATE,fbillno from T_SAL_RETURNSTOCK RETURNSTOCK left join T_SAL_RETURNSTOCKENTRY_F RETURNSTOCKF on RETURNSTOCKF.FID=RETURNSTOCK.FID where fdate BETWEEN '" + startDate + "' and '" + endDate + "' ) s on o.fbillnumber=s.FBILLNO ";
sb.AppendFormat(strSql, tableName, strTable);
DBUtils.Execute(this.Context, sb.ToString());
}
///
/// 设置精度控制
///
public void SetDecimal()
{
List
list.Add(new DecimalControlField
{
ByDecimalControlFieldName = "F_bg_Profit",
DecimalControlFieldName = "FLCAMOUNTPRECISION"
});
list.Add(new DecimalControlField
{
ByDecimalControlFieldName = "F_bg_Profit_Settlement",
DecimalControlFieldName = "FLCAMOUNTPRECISION"
});
base.ReportProperty.DecimalControlFieldList = list;
}
///
/// 设置统计列
///
///
///
public override List
{
List
summarys.Add(new Kingdee.BOS.Core.Report.SummaryField("F_bg_Profit", Kingdee.BOS.Core.Enums.BOSEnums.Enu_SummaryType.SUM));
summarys.Add(new Kingdee.BOS.Core.Report.SummaryField("F_bg_Profit_Settlement", Kingdee.BOS.Core.Enums.BOSEnums.Enu_SummaryType.SUM));
return summarys;
}
///
/// 设置全局变量值
///
public void setFilterValue(IRptParams filter)
{
DynamicObject doFilter = filter.FilterParameter.CustomFilter;
this.startDate = (this.GetDataByKey(doFilter, "StartDate") == string.Empty) ? DateTime.Now.ToString("yyyy-MM-dd") : this.GetDataByKey(doFilter, "StartDate");
this.endDate = (this.GetDataByKey(doFilter, "EndDate") == string.Empty) ? DateTime.Now.ToString("yyyy-MM-dd") : this.GetDataByKey(doFilter, "EndDate");
}
// 获取DynamicObject数据包中指定key的值
private string GetDataByKey(DynamicObject doFilter, string sKey)
{
string sReturnValue = string.Empty;
if (doFilter != null && doFilter[sKey] != null && !string.IsNullOrWhiteSpace(Convert.ToString(doFilter[sKey])))
{
sReturnValue = Convert.ToString(doFilter[sKey]);
}
return sReturnValue;
}
///
/// 当关闭报表时,触发事件删除临时表
///
public override void CloseReport()
{
if (customRptTempTableNames.IsNullOrEmptyOrWhiteSpace())
{
return;
}
IDBService service = Kingdee.BOS.App.ServiceHelper.GetService
//删除临时表
service.DeleteTemporaryTableName(this.Context, customRptTempTableNames);
base.CloseReport();
}
}
}
推荐阅读