星空报表开发在简易账表添加其它单据体并展示数据原创
金蝶云社区-承宣
承宣
9人赞赏了该文章 130次浏览 未经作者许可,禁止转载编辑于2023年11月24日 17:18:47

星空的简易账表有1张自带的单据体,用于展示报表数据,但如果想再增加1个单据体甚至更多单据体展示报表数据,目前系统没法在GetReportTitles(IRptParams filter)方法中对其它单据体进行赋值,遇到此类需求一般开发人员会考虑用动态表单实现,但把动态表单的查询条件毕竟与简易账表不同,在报表中放动态表单有格格不入之嫌,在前段的报表开发中,我也遇到了此类问题,通过不断调试,找到了一个可以在简易账表添加其它单据体并写入数据方法。

实现方法主要是通过放入多行文本,把其它单据体的展示数据在服务器插件的ReportTitles GetReportTitles(IRptParams filter)方法中,用Json格式保存起来,然后在表单插件的AfterBindData(EventArgs e)方法中取出来并解释写到其它单据体中。

 

1、 在简易账表中添加1个多行文本,注意设置长度为-1

image.png

       添加1个单据体

image.png

2、 在服务器插件的ReportTitles GetReportTitles(IRptParams filter)中写入JSon格式的值

 

            JSONArray itemArr = new JSONArray();

 //添加LIVE PROGRAMME TOTAL信息

                    JSONObject objLive = new JSONObject();

                    objLive.Put("FEnType", 0);

                    objLive.Put("FEnItem", "LIVE PROGRAMME TOTAL:");

                    objLive.Put("FEnAmt", Convert.ToDecimal(dr["FLiveProgTotal"]));

                    itemArr.Add(objLive);

                    //添加FILM PROGRAMME TOTAL信息

                    JSONObject objFilm = new JSONObject();

                    objLive.Put("FEnType", 0);

                    objFilm.Put("FEnItem", "FILM PROGRAMME TOTAL:");

                    objFilm.Put("FEnAmt", Convert.ToDecimal(dr["FFilmProgTotal"]));

                    itemArr.Add(objFilm);

//从数据库查询json项目值

  string mySql = @"

               select FPromotionNo,isnull(sum(FTalentCost),0) promotionAmt

                from {0} group by FPromotionNo";

  string  sql = string.Format(mySql, tmpName);

            using (IDataReader dr = DBUtils.ExecuteReader(this.Context, sql))

            {

                while (dr.Read())

                {

                    if (!dr["FPromotionNo"].IsNullOrEmpty() && !dr["promotionAmt"].IsNullOrEmpty())

                    {

                     

                        //添加Promotion汇总数据

                        JSONObject obj = new JSONObject();

                        obj.Put("FEnType", 1);

                        obj.Put("FEnItem", dr["FPromotionNo"].ToString()+ ":");

                        obj.Put("FEnAmt", Convert.ToDecimal(dr["promotionAmt"]));

                        itemArr.Add(obj);

                    }

                }

            }

 //添加汇总行数据

            JSONObject objTotal = new JSONObject();

            objTotal.Put("FEnType", 2);

            objTotal.Put("FEnItem", "GRAND TOTAL:");

            objTotal.Put("FEnAmt", grandTotal);

            itemArr.Add(objTotal);

 

            JSONObject returnJson = new JSONObject();

            returnJson.Put("itemArr", itemArr);

            //设置多行文本的Json信息

            result.AddTitle("FPromotionJson", returnJson.ToJSONString());

3、 在表单插件的void AfterBindData(EventArgs e)方法读取多行文本值,解释并写入单据体

           //删除单据体数据

            this.View.Model.DeleteEntryData("FPromotionEntity");           

            string promotionJsonStr = string.Empty;

            ReportTitles titles = (this.View.Model as ISysReportModel).GetReportTitles();

            foreach (var title in titles) {

                if ("FPromotionJson".EqualsIgnoreCase(title.TitleKey)) {

                    //获取多行文本 【FPromotionJson】的数据

                    promotionJsonStr = title.TitleValue;

                    break;

                }

            }           

            if (!promotionJsonStr.IsNullOrEmptyOrWhiteSpace())

            {

                JSONObject promotionJson = JSONObject.Parse(promotionJsonStr);

                if (!promotionJson.IsNullOrEmptyOrWhiteSpace())

                {                  

                    JSONArray dataList = (JSONArray)promotionJson.Get("itemArr");

                    int fcount = 0;

                    JSONObject entryJson = null;

                    for (int j = 0; j < dataList.Count; j++)

                    {

                        entryJson = JSONObject.Parse(dataList.GetJsonString(j));

                        this.View.Model.CreateNewEntryRow("FPromotionEntity");

                        fcount = this.View.Model.GetEntryRowCount("FPromotionEntity") -1;

                        this.View.Model.SetValue("FEnItem", entryJson.GetString("FEnItem"), fcount);

                        this.View.Model.SetValue("FEnAmt", entryJson.GetValue("FEnAmt", Decimal.MinValue), fcount);

                    }

                    this.View.UpdateView("FPromotionEntity");

                }              

            }

实现效果如下

image.png

                                                                              (本文完)


赞 9