public IDnsDocument ExportResponse(IDnsResponseContext context, IDnsResponseAggregationMode aggregationMode, IDnsResponseExportFormat format, string args)
        {
            using (StringWriter sw = new StringWriter())
            {
                DataSet ds       = GetResponseDataSet(context, aggregationMode);
                string  filename = EXPORT_BASENAME + "_" + context.Request.Model.Name + "_" + context.Request.RequestID.ToString() + "." + format.ID;

                switch (format.ID)
                {
                case "xlsx":
                    ExcelHelper.ToExcel(ds, filename, HttpContext.Current.Response);
                    break;

                case "csv":
                    ExcelHelper.ToCSV(ds, sw);
                    break;
                }

                return(Dns.Document(
                           name: filename,
                           mimeType: GetMimeType(filename),
                           isViewable: false,
                           kind: DocumentKind.User,
                           Data: Encoding.UTF8.GetBytes(sw.ToString())
                           ));
            }
        }
Beispiel #2
0
        public IDnsDocument ExportResponse(IDnsResponseContext context, IDnsResponseAggregationMode aggregationMode, IDnsResponseExportFormat format, string args)
        {
            using (StringWriter sw = new StringWriter())
            {
                DataSet ds = GetResponseDataSet(context);

                switch (format.ID)
                {
                case "xls":
                    using (HtmlTextWriter htw = new HtmlTextWriter(sw))
                    {
                        DataGrid dg = new DataGrid();
                        dg.DataSource = ds.Tables[0];
                        dg.DataBind();
                        dg.RenderControl(htw);
                    }
                    break;

                case "csv":
                    DataTable dt        = ds.Tables[0];
                    int       iColCount = dt.Columns.Count;
                    for (int i = 0; i < iColCount; i++)
                    {
                        sw.Write(dt.Columns[i]);
                        if (i < iColCount - 1)
                        {
                            sw.Write(",");
                        }
                    }
                    sw.Write(sw.NewLine);

                    // Now write all the rows.
                    foreach (DataRow dr in dt.Rows)
                    {
                        for (int i = 0; i < iColCount; i++)
                        {
                            if (!Convert.IsDBNull(dr[i]))
                            {
                                sw.Write(dr[i].ToString());
                            }
                            if (i < iColCount - 1)
                            {
                                sw.Write(",");
                            }
                        }
                        sw.Write(sw.NewLine);
                    }
                    break;
                }

                string filename = EXPORT_BASENAME + "_" + context.Request.Model.Name + "_" + context.Request.RequestID.ToString() + "." + format.ID;
                return(Dns.Document(
                           name: filename,
                           mimeType: GetMimeType(filename),
                           isViewable: false,
                           kind: DocumentKind.User,
                           Data: Encoding.UTF8.GetBytes(sw.ToString())
                           ));
            }
        }
Beispiel #3
0
        public IDnsDocument ExportResponse(IDnsResponseContext context, IDnsResponseAggregationMode aggregationMode, IDnsResponseExportFormat format, string args)
        {
            using (var db = new DataContext())
            {
                string reqDoc = FixDocumentContent(System.Text.UTF8Encoding.UTF8.GetString(context.Request.Documents.Where(d => d.Name == REQUEST_ARGS_FILENAME).FirstOrDefault().GetData(db)));
                using (StringWriter sw = new StringWriter())
                {
                    DataSet ds       = GetResponseDataSet(context, reqDoc, aggregationMode);
                    string  filename = EXPORT_BASENAME + "_" + context.Request.Model.Name + "_" + context.Request.RequestID.ToString() + "." + format.ID;

                    switch (format.ID)
                    {
                    case "xlsx":
                        ExcelHelper.ToExcel(ds, filename, HttpContext.Current.Response);
                        break;

                    case "csv":
                        ExcelHelper.ToCSV(ds, sw);
                        break;
                    }

                    return(Dns.Document(
                               name: filename,
                               mimeType: GetMimeType(filename),
                               isViewable: false,
                               kind: DocumentKind.User,
                               Data: Encoding.UTF8.GetBytes(sw.ToString())
                               ));
                }
            }
        }
        public DnsRequestTransaction EditRequestPost(IDnsRequestContext request, IDnsPostContext post)
        {
            var m       = post.GetModel <Medical.Models.MedicalRequestModel>();
            var sqlText = GenerateSqlQuery(m);

            if (string.IsNullOrEmpty(sqlText))
            {
                return(DnsRequestTransaction.Failed("Failed to create the SQL Query"));
            }

            var sqlTextBytes = Encoding.UTF8.GetBytes(sqlText);
            var doc          = Dns.Document("SQL Text", "text/plain", () => new MemoryStream(sqlTextBytes), () => sqlTextBytes.Length);
            var existingDoc  = request.Documents.FirstOrDefault();

            return(new DnsRequestTransaction
            {
                NewDocuments = existingDoc != null ? null : new[] { doc },
                UpdateDocuments = existingDoc == null ? null :
                                  new[] { new { existingDoc, doc } }.ToDictionary(x => x.existingDoc, x => x.doc),
                RemoveDocuments = request.Documents.Skip(1)
            });
        }
        public IDnsDocument ExportResponse(IDnsResponseContext context, IDnsResponseAggregationMode aggregationMode, IDnsResponseExportFormat format, string args)
        {
            using (StringWriter sw = new StringWriter())
            {
                string filename = EXPORT_BASENAME + "_" + context.Request.Model.Name + "_" + context.Request.RequestID.ToString() + "." + format.ID;
                var    DMDocs   = new SortedDictionary <string, List <Document> >();

                var lDocs = (from r in context.DataMartResponses
                             from doc in r.Documents
                             orderby r.DataMart.ID
                             select new
                {
                    Doc = doc,
                    Name = doc.Name,
                    ID = doc.ID,
                    DataMartName = r.DataMart.Name,
                    RevisionVersion = doc.RevisionVersion
                });

                var docs = from r in lDocs
                           group r by r.DataMartName into grp
                           select new KeyValuePair <string, Document>
                           (
                    grp.FirstOrDefault().DataMartName,
                    grp.OrderByDescending(p => p.RevisionVersion).FirstOrDefault().Doc
                           );

                ZipHelper.DownloadZipToBrowser(HttpContext.Current, docs, filename);

                return(Dns.Document(
                           name: filename,
                           mimeType: FileHelper.GetMimeType(filename),
                           isViewable: false,
                           kind: DocumentKind.User,
                           Data: Encoding.UTF8.GetBytes(sw.ToString())
                           ));
            }
        }
Beispiel #6
0
        public DnsRequestTransaction EditRequestPost(IDnsRequestContext request, IDnsPostContext post)
        {
            System.Collections.Generic.List <Lpp.Dns.IDnsDocument>           newDocuments    = new System.Collections.Generic.List <Lpp.Dns.IDnsDocument>();
            System.Collections.Generic.List <Lpp.Dns.IDnsPersistentDocument> removeDocuments = new System.Collections.Generic.List <Lpp.Dns.IDnsPersistentDocument>();
            var m = post.GetModel <PubHealthModel>();

            string docContents = ""; // m.MinDate + "|" + m.MaxDate;

            newDocuments.Add(Dns.Document(request.Header.Name, "text/plain", true, Document.DocumentKind_Request, () => new MemoryStream(GetBytes(docContents)), () => docContents.Length));
            IDnsPersistentDocument doc = request.Documents.FirstOrDefault(s => s.Kind == Document.DocumentKind_Request);

            if (doc != null)
            {
                removeDocuments.Add(doc);
            }

            return(new DnsRequestTransaction
            {
                NewDocuments = newDocuments,
                UpdateDocuments = null,
                RemoveDocuments = removeDocuments
            });
        }
Beispiel #7
0
        public IDnsDocument ExportResponse(IDnsResponseContext context, IDnsResponseAggregationMode aggregationMode, IDnsResponseExportFormat format, string args)
        {
            using (StringWriter sw = new StringWriter())
            {
                string filename = EXPORT_BASENAME + "_" + context.Request.Model.Name + "_" + context.Request.RequestID.ToString() + "." + format.ID;
                SortedDictionary <string, List <Document> > DMDocs = new SortedDictionary <string, List <Document> >();

                #region "TO BE MOVED TO QUERYBUILDER UI"

                //#region "Generate a List of Documents Keyed on DataMarts for Aggregation"

                ////IEnumerable<IDnsPersistentDocument> docs = null;
                //var docs = from r in context.DataMartResponses
                //           from doc in r.Documents
                //           orderby r.DataMart.Id
                //           select new { Id = r.DataMart.Id, Document = doc };

                //foreach (var item in docs)
                //{
                //    if (!DMDocs.ContainsKey(item.Id.ToString())) DMDocs.Add(item.Id.ToString(), new List<IDnsPersistentDocument>());
                //    DMDocs[item.Id.ToString()].Add(item.Document);
                //}

                //#endregion

                ////Aggregate and Download
                //Workbook AggregatedWorkBook = null;
                //try
                //{
                //    AggregatedWorkBook = AggregateDocuments(DMDocs);
                //    if (AggregatedWorkBook != null)
                //    {
                //        //present for download.
                //        string DownloadFileName = filename;
                //        //string DownloadPath = System.Web.Configuration.WebConfigurationManager.AppSettings["DownloadFolder"]+ @"\" + DownloadFileName;
                //        AggregatedWorkBook.Save(HttpContext.Current.Response, DownloadFileName, ContentDisposition.Attachment, new XlsSaveOptions(SaveFormat.Excel97To2003));
                //        HttpContext.Current.Response.Flush();
                //        HttpContext.Current.Response.End();
                //    }
                //}
                //catch (Exception ex)
                //{
                //    sw.WriteLine("Error Encountered During Aggregation Process.");
                //    sw.WriteLine(ex.Message);
                //    sw.WriteLine(ex.StackTrace);
                //}


                #endregion

                //IEnumerable<IDnsPersistentDocument> docs = null;
                var docs = from r in context.DataMartResponses
                           from doc in r.Documents
                           orderby r.DataMart.ID
                           select new KeyValuePair <string, Document>(r.DataMart.Name, doc);

                DownloadZipToBrowser(docs);

                return(Dns.Document(
                           name: filename,
                           mimeType: GetMimeType(filename),
                           isViewable: false,
                           kind: DocumentKind.User,
                           Data: Encoding.UTF8.GetBytes(sw.ToString())
                           ));
            }
        }