Web API中Crystal报表中列表对象内的列表对象,但列表内列表未显示

时间:2019-06-20 09:19:27

标签: c# asp.net wcf asp.net-web-api model-view-controller

使用webApi在Crystal报表中的列表对象内的列表对象。

 private RailCommerceDBEntities db = new RailCommerceDBEntities();
       [HttpGet]
        public HttpResponseMessage ExportReport()//ParameterReport preport
        {
            string format = string.Empty;
            //format = preport.Format;
            format = ".pdf";
            List<TaskReports> model = new List<TaskReports>();
            //if (preport.Issue == null)
            //{
            //    preport.Issue = "";
            //}
            //if (preport.OfficerResponsible == null)
            //{
            //    preport.OfficerResponsible = "";
            //}
            // var data = db.spsantoshTaskTrackingAnupTe(preport.TaskID, preport.Issue, preport.Designation, preport.TaskCoordinator, preport.OfficerResponsible, preport.FollowedBy, preport.DecisionFromDate, preport.DecisionToDate, preport.Priority, preport.Category, preport.DeadlineFromDate, preport.DeadlineToDate, preport.Attachment).ToList();
            // var data = db.spsantosh(null, "", null, null, "", null, null, null, null, null, null, null, null).ToList();
            var data = db.spCrystalReport(null, "", null, null, "", null, null, null, null, null, null, null, null).ToList();
            string[] arr = new string[100];
            List<OfficerRemark> myCollection = new List<OfficerRemark>();
            //List<FinalList> lst = new List<FinalList>();
            //dynamic Values=null;


            var rd = new ReportDocument();
            int counter = 0;
            foreach (var details in data)
            {


                counter = counter + 1;
                TaskReports obj = new TaskReports();
                obj.SNO = counter;
                obj.TaskID = details.TaskID;
                var OfficeID = details.OfficerID.Split(',');
                foreach (var item in OfficeID)
                {
                    if (item != "null")
                    {
                        var item1 = Convert.ToInt32(item);
                        var Values = db.sp_RemarkBasedOnOfficerIDs(details.TaskID, item1).ToList();
                        foreach (var itemOff in Values)
                        {
                            OfficerRemark objofficer = new OfficerRemark();
                            objofficer.TaskID = Convert.ToInt32(itemOff.TaskID);
                            objofficer.IsRemarkUpdate = itemOff.IsRemarkUpdate;
                            objofficer.Remark = itemOff.Remark;
                            objofficer.RemarkUpdateDate = Convert.ToString(itemOff.RemarkUpdateDate);
                            objofficer.RemarkUpdatedBy = Convert.ToInt32(itemOff.RemarkUpdatedBy);
                            objofficer.UserName = itemOff.UserName;
                            myCollection.Add(objofficer);
                        }
                        // myCollection.Add(Values);
                    }
                }

                obj.Issue = details.Issue;

                if (details.ActionJS != null)
                {
                    obj.ActionJs = details.ActionJS;
                }


                if (details.ActionUpdateDate != null)
                {
                    obj.ActionTCDateHistory = Convert.ToString(details.ActionUpdateDate);
                }

                //obj.ActionJs = details.ActionJs;
                obj.FollowedByName = details.FollowedByName;
                obj.GroupByName = details.GroupByName;

                obj.AllDeadline = details.AllDeadline;
                if (details.AttachFileIDs != null)
                {
                    //obj.Counter = Path.Combine(System.Web.Hosting.HostingEnvironment.MapPath("/UserImage/attachment.png"));
                }


                obj.IsAJSUpdate = details.IsActionJSUpdate;
                obj.IsRemarkUpdate = details.IsRemarkUpdate;

                foreach (var item in myCollection)
                {
                    if (item.TaskID == obj.TaskID)
                    {
                        obj.AditionalComments = new List<ActionTestOne>();
                        obj.ActionOC = new List<ActionTestOne>();
                        obj.RemarkOCDateHistory = new List<ActionTestOne>();
                        ActionTestOne ac = new ActionTestOne();
                        //ActionOCOne aco = new ActionOCOne();
                        // ActionUpdate ad = new ActionUpdate();
                        ac.ActionOC = item.UserName;
                        ac.AditionalComment = item.Remark;
                        ac.RemarkUpdateDate = item.RemarkUpdateDate;
                        obj.AditionalComments.Add(ac);
                        obj.ActionOC.Add(ac);
                        obj.RemarkOCDateHistory.Add(ac);
                    }

                }



                obj.DateOFDecision = Convert.ToString(details.DateOFDecision);
                obj.OfficerResponsible = details.OfficerResponsible;
                obj.PriorityName = details.PriorityName;
                obj.Statuss = Convert.ToInt32(details.Statuss);
                obj.StatusTpye = details.StatusTpye + '(' + Convert.ToString(obj.Statuss) + ')';
                obj.TaskCoordinator = details.TaskCoordinator;
                DateTime objcu = DateTime.Now;
                obj.Counter = Convert.ToString(objcu);
                model.Add(obj);

            }


            //rd.Load(Path.Combine(System.Web.Hosting.HostingEnvironment.MapPath("~/Report/TaskTrReport.rpt")));
            rd.Load(Path.Combine(System.Web.Hosting.HostingEnvironment.MapPath("~/Report/TaskTrackReport.rpt")));

            ConnectionInfo connectInfo = new ConnectionInfo()
            {
                ServerName = "103.14.97.209",
                DatabaseName = "RailCommerceDB",
                UserID = "UP3M5m6Tb4",
                Password = "UP3M5m6Tb4"
            };
            rd.SetDatabaseLogon("UP3M5m6Tb4", "UP3M5m6Tb4");
            //System.Web.UI.WebControls.Table tbl = new System.Web.UI.WebControls.Table
            foreach (Table tbl in rd.Database.Tables)
            {
                tbl.LogOnInfo.ConnectionInfo = connectInfo;
                tbl.ApplyLogOnInfo(tbl.LogOnInfo);
            }


            **rd.SetDataSource(model);**

            var stream = rd.ExportToStream(ExportFormatType.PortableDocFormat);


            HttpResponseMessage httpResponseMessage = Request.CreateResponse(HttpStatusCode.OK);
            httpResponseMessage.Content = new StreamContent(stream);
            httpResponseMessage.Content.Headers.ContentDisposition = new System.Net.Http.Headers.ContentDispositionHeaderValue("attachment");
            httpResponseMessage.Content.Headers.ContentDisposition.FileName = "CIMDashboard_Report" + format + "";
            httpResponseMessage.Content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/octet-stream");

            return httpResponseMessage;

        }

--------------------------------
 public class TaskReports
    {
        public int SrNo { get; set; }
        public int SNO { get; set; }

        public int TaskID { get; set; }
        public string ActionTaken { get; set; }
        public string Issue { get; set; }
        public int ActionUpdatedBy { get; set; }
        public string ActionUpdateDate { get; set; }
        public string OfficerResponsible { get; set; }
        public string DateOFDecision { get; set; }
        public string AttachFileIDs { get; set; }
        public string TaskCoordinator { get; set; }
        public string PriorityName { get; set; }
        public int Statuss { get; set; }
        public string StatusTpye { get; set; }
        public string AllDeadline { get; set; }
        //
        public string ActionTC { get; set; }
        public string ActionTCDateH { get; set; }
        //public List<string> ActionOC { get; set; }
        public List<ActionTestOne> ActionOC { get; set; }
        public string RemarkOCDH { get; set; }
        //Additional
        public string IsAJSUpdate { get; set; }
        public string IsRemarkUpdate { get; set; }
        public string Remark { get; set; }
        public int TaskOwnerID { get; set; }
        public string FollowedByName { get; set; }
        public string GroupByName { get; set; }
        public int RemarkUBy { get; set; }
        public string ActionJs { get; set; }
        public string CurrentDateTime { get; set; }
        public List<ActionTestOne> AditionalComments { get; set; }
        public string Counter { get; set; }
        public List<ActionTestOne> RemarkOCDateHistory { get; set; }
        public string ActionTCDateHistory { get; set; }
        //public string AditionalComments { get; set; }
        //public string ActionOC { get; set; }
        //public string RemarkUpdateDate { get; set; }
        //public string RemarkOCDateHistory { get; set; }

    }

    public class ActionTestOne
    {
        public string AditionalComment { get; set; }
        public string ActionOC { get; set; }
        public string RemarkUpdateDate { get; set; }
    }
--------------------------------------------------
 public class OfficerRemark
    {
        public int TaskID { get; set; }
        public int RemarkUpdatedBy { get; set; }
        public string Remark { get; set; }
        public string RemarkUpdateDate { get; set; }
        public string IsRemarkUpdate { get; set; }
        public string UserName { get; set; }
    }**
列表对象数据内的

列表对象未显示在Web api的Crystal报表中。请帮助我在Crystal报表中缺少的内容。 我的列表对象是模型,列表对象内部的名称是ExtrasComments和ActionOC,但数据未显示在Crystal报表中。

1 个答案:

答案 0 :(得分:0)

Crystal仅支持一层子报表嵌入。

报告可以包含一个子报告。但是子报表不能包含子报表。