示例#1
0
文件: Mapper.cs 项目: fgma75/epiinfo
        internal static ReportInfoBO ToReportInfoBO(SurveyReportsInfo reportInfo)
        {
            ReportInfoBO ReportInfoBO = new ReportInfoBO();

            ReportInfoBO.CreatedDate = reportInfo.DateCreated;
            ReportInfoBO.EditedDate  = (DateTime)reportInfo.DateEdited;
            if (!string.IsNullOrEmpty(reportInfo.ReportId.ToString()))
            {
                ReportInfoBO.ReportId = reportInfo.ReportId.ToString();
            }
            if (!string.IsNullOrEmpty(reportInfo.SurveyId.ToString()))
            {
                ReportInfoBO.SurveyId = reportInfo.SurveyId.ToString();
            }
            ReportInfoBO.ReportVersion = reportInfo.ReportVersion;


            ReportInfoBO.DataSource = reportInfo.DataSource;
            ReportInfoBO.Gadgets    = new List <GadgetBO>();
            foreach (var item in reportInfo.SurveyReports.OrderBy(x => x.GadgetNumber))
            {
                ReportInfoBO.Gadgets.Add(ToGadgetBO(item));
            }

            ReportInfoBO.RecordCount = reportInfo.RecordCount;
            return(ReportInfoBO);
        }
示例#2
0
文件: Mapper.cs 项目: fgma75/epiinfo
        internal static SurveyReportsInfo ToReportInfoEF(ReportInfoBO reportInfo)
        {
            SurveyReportsInfo SurveyReport = new SurveyReportsInfo();

            SurveyReport.DateCreated = reportInfo.CreatedDate;
            SurveyReport.DateEdited  = reportInfo.EditedDate;
            if (!string.IsNullOrEmpty(reportInfo.ReportId.ToString()))
            {
                SurveyReport.ReportId = Guid.Parse(reportInfo.ReportId);
            }
            if (!string.IsNullOrEmpty(reportInfo.SurveyId.ToString()))
            {
                SurveyReport.SurveyId = Guid.Parse(reportInfo.SurveyId);
            }
            SurveyReport.ReportVersion = reportInfo.ReportVersion;


            SurveyReport.DataSource  = reportInfo.DataSource;
            SurveyReport.RecordCount = reportInfo.RecordCount;

            SurveyReport.SurveyReports = ToGadgetsEF(reportInfo.Gadgets);


            return(SurveyReport);
        }
示例#3
0
        public void PublishReport(ReportInfoBO ReportInfo)
        {
            try
            {
                var SurveyId = Guid.Parse(ReportInfo.SurveyId);
                //var GadgetId = Guid.Parse(ReportInfo.GadgetId);
                var ReportId = Guid.Parse(ReportInfo.ReportId);
                using (var Context = DataObjectFactory.CreateContext())
                {
                    if (!ReportExist(SurveyId, ReportId))
                    {
                        SurveyReportsInfo ReportEntity = Mapper.ToReportInfoEF(ReportInfo);

                        Context.SurveyReportsInfoes.Add(ReportEntity);

                        Context.SaveChanges();
                    }
                    else
                    {
                        var Query = from SurveyReportInfo in Context.SurveyReportsInfoes
                                    where SurveyReportInfo.ReportId == ReportId
                                    select SurveyReportInfo;

                        var DataRow = Query.Single();
                        DataRow.DateEdited    = DateTime.Now;
                        DataRow.RecordCount   = ReportInfo.RecordCount;
                        DataRow.ReportVersion = ReportInfo.ReportVersion + 1;
                        DataRow.DataSource    = ReportInfo.DataSource;
                        Context.SaveChanges();

                        // update Gadget
                        foreach (var gadget in ReportInfo.Gadgets)
                        {
                            var GadgetId    = Guid.Parse(gadget.GadgetId);
                            var GadgetQuery = from SurveyReport in Context.SurveyReports
                                              where SurveyReport.ReportId == ReportId && SurveyReport.GadgetId == GadgetId
                                              select SurveyReport;
                            if (GadgetQuery != null && GadgetQuery.Count() > 0)
                            {
                                var GadgetDataRow = GadgetQuery.Single();
                                GadgetDataRow.DateEdited = DateTime.Now;

                                GadgetDataRow.GadgetVersion = gadget.GadgetVersion + 1;
                                GadgetDataRow.ReportHtml    = gadget.ReportHtml;
                                Context.SaveChanges();
                            }
                            else
                            {
                                List <SurveyReport> ReportEntity = Mapper.ToGadgetsEF(ReportInfo.Gadgets);
                                foreach (var item in ReportEntity)
                                {
                                    Context.SurveyReports.Add(item);
                                }
                                Context.SaveChanges();
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw (ex);
            }
        }