public IEnumerable <IResult> Save()
        {
            var saveFileResult = new SaveFileResult(DisplayName);

            yield return(saveFileResult);

            saveFileResult.Write(Text);
        }
示例#2
0
        public IEnumerable <IResult> Save()
        {
            var save = new SaveFileResult(DisplayName);

            yield return(save);

            save.Write(OrderLine.SendReport(Lines, groupByAddress: IsUpdate));
        }
示例#3
0
        public IEnumerable <IResult> Save()
        {
            var ext    = Path.GetExtension(Filename.Value);
            var result = new SaveFileResult(new[] { Tuple.Create(ext, ext) }, CurrentItem.Value.FileName);

            yield return(result);

            File.Copy(Filename.Value, result.Dialog.FileName);
        }
        public SaveFileResult ReplaceOpenXML([FromBody] dynamic content)
        {
            var pdf            = new PDF();
            var serverAddr     = $"{this.Request.Scheme}://{this.Request.Host}{this.Request.PathBase}/";
            var targetPdfName  = pdf.CreatePDFReport(content, serverAddr);
            var returnResponse = new SaveFileResult();

            returnResponse.FileName = targetPdfName;
            ReportUtils reportUtils = new ReportUtils();

            reportUtils.DeleteOldFiles();

            return(returnResponse);
        }
示例#5
0
        public static SaveFileResult SaveFile(FileUpload FileUpload, string filename, string SaveFilePath, int MaxKBSize, params string[] Extensions)
        {
            SaveFileResult result = null;

            result = new SaveFileResult();
            if ((FileUpload != null) && FileUpload.HasFile)
            {
                if (string.IsNullOrEmpty((SaveFilePath ?? "").Trim()))
                {
                    result.Msg = "未設定儲存路徑";
                    return(result);
                }
                if ((MaxKBSize > 0) && (FileUpload.PostedFile.ContentLength > (MaxKBSize * 0x400)))
                {
                    result.Msg = "超出大小限制";
                    return(result);
                }
                if (Extensions.Length > 0)
                {
                    bool flag = false;
                    foreach (string str in Extensions)
                    {
                        if (Path.GetExtension(FileUpload.FileName).ToLower() == ("." + str.ToLower()))
                        {
                            flag = true;
                            break;
                        }
                    }
                    if (!flag)
                    {
                        result.Msg = "不是允許的副檔名";
                        return(result);
                    }
                }
                if (Strings.Right(SaveFilePath, 1) != "/")
                {
                    SaveFilePath = SaveFilePath + "/";
                }
                SetFolder(SaveFilePath);
                string str2 = filename + Path.GetExtension(FileUpload.FileName);
                string str3 = HttpContext.Current.Server.MapPath(SaveFilePath + str2);
                FileUpload.SaveAs(str3);
                FileUpload.Dispose();
                result.Result = true;
                result.Msg    = SaveFilePath + str2;
            }
            return(result);
        }
 public static SaveFileResult SaveFile(FileUpload FileUpload, string filename, string SaveFilePath, int MaxKBSize, params string[] Extensions)
 {
     SaveFileResult result = null;
     result = new SaveFileResult();
     if ((FileUpload != null) && FileUpload.HasFile)
     {
         if (string.IsNullOrEmpty((SaveFilePath ?? "").Trim()))
         {
             result.Msg = "未設定儲存路徑";
             return result;
         }
         if ((MaxKBSize > 0) && (FileUpload.PostedFile.ContentLength > (MaxKBSize * 0x400)))
         {
             result.Msg = "超出大小限制";
             return result;
         }
         if (Extensions.Length > 0)
         {
             bool flag = false;
             foreach (string str in Extensions)
             {
                 if (Path.GetExtension(FileUpload.FileName).ToLower() == ("." + str.ToLower()))
                 {
                     flag = true;
                     break;
                 }
             }
             if (!flag)
             {
                 result.Msg = "不是允許的副檔名";
                 return result;
             }
         }
         if (Strings.Right(SaveFilePath, 1) != "/")
         {
             SaveFilePath = SaveFilePath + "/";
         }
         SetFolder(SaveFilePath);
         string str2 = filename + Path.GetExtension(FileUpload.FileName);
         string str3 = HttpContext.Current.Server.MapPath(SaveFilePath + str2);
         FileUpload.SaveAs(str3);
         FileUpload.Dispose();
         result.Result = true;
         result.Msg = SaveFilePath + str2;
     }
     return result;
 }
        public JsonResult SaveFile()
        {
            _log.WriteInfo("开始请求接口【file/save】");
            SaveFileResult result = new SaveFileResult();

            try
            {
                var request = GetFilterRequest.GetParams(HttpContext.ApplicationInstance.Request);
                if (!request.Status)
                {
                    result.code    = request.code;
                    result.message = request.message;
                    result.details = request.details;
                    result.hint    = request.hint;
                }
                else
                {
                    var fileName             = request.FileId == "1000" ? "TestFile.docx" : (request.FileId == "1001" ? "TestFile_v1.docx" : "TestFile_v2.docx");
                    HttpFileCollection files = HttpContext.ApplicationInstance.Request.Files;
                    foreach (string key in files.AllKeys)
                    {
                        HttpPostedFile file = files[key];
                        if (string.IsNullOrEmpty(file.FileName) == false)
                        {
                            file.SaveAs(Server.MapPath("~/Files/") + fileName);
                        }
                    }

                    result.file = new WPSFileModel
                    {
                        download_url = $"{ConfigurationManager.AppSettings["WPSTokenUrl"]}/Files/{fileName}",
                        id           = request.FileId,
                        name         = request.Params["_w_fileName"].ToString()
                    };
                }
            }
            catch (Exception ex)
            {
                _log.WriteError("【系统异常】-【" + ex.Message + "】", ex);
                result.code    = (int)Enumerator.ErrorCode.ServerError;
                result.message = Enumerator.ErrorCode.ServerError.ToString();
                result.details = result.hint = EnumExtension.GetDescription(Enumerator.ErrorCode.ServerError);
            }
            _log.WriteInfo("请求接口【file/save】完成,返回数据:" + JsonConvert.SerializeObject(result));
            return(Json(result));
        }
示例#8
0
        public async Task <SaveFileResult> SaveFile(IList <byte> fileContent, string folderPath, string fileName)
        {
            var result = new SaveFileResult();

            try
            {
                Directory.CreateDirectory(folderPath);
                var filePath = Path.Combine(folderPath, fileName);

                using var fileStream = System.IO.File.Create(filePath);
                await fileStream.WriteAsync(fileContent.ToArray());

                result.IsSuccessful = true;
            }
            catch
            {
                result.ErrorMessage = $"Failed to upload Project Document {fileName}";
            }

            return(result);
        }
示例#9
0
        public Task <SaveFileResult> SaveFile(IFormFile file)
        {
            return(Task.Run(async() =>
            {
                try
                {
                    var request = FilterRequestForWPS(Request);
                    if (!request.Status)
                    {
                        return new SaveFileResult {
                            code = request.code, msg = request.msg
                        };
                    }

                    using (var stream = System.IO.File.Create("保存的文件名"))
                    {
                        await file.CopyToAsync(stream);
                    }

                    var result = new SaveFileResult
                    {
                        file = new WPSFileModel
                        {
                            download_url = "新的文件下载链接",
                            id = request.FileId,
                            name = request.Params["_w_fileName"].ToString()
                        }
                    };
                    return result;
                }
                catch (Exception ex)
                {
                    _logger.Error("save file failed: ", ex);
                    return new SaveFileResult {
                        code = 403, msg = "保存出现异常"
                    };
                }
            }));
        }
示例#10
0
        public FilesStatus FilesStatus(string basePath, string fileName, long fileLength, string type,
                                       SaveFileResult saveFileResult)
        {
            var filesStatus = new FilesStatus
            {
                Id           = saveFileResult.Id,
                SiteId       = saveFileResult.SiteId,
                Name         = fileName,
                Type         = type,
                PropertyName = saveFileResult.PropertyName,
                Size         = fileLength
            };

            if (!string.IsNullOrEmpty(saveFileResult.Url))
            {
                filesStatus.Url = basePath + "api/file/get/" + saveFileResult.SiteId + "/" + saveFileResult.Id +
                                  "/ImageUploaded/" + fileName;
            }
            filesStatus.DeleteUrl = basePath + "api/file/delete/" + saveFileResult.SiteId + "/" + saveFileResult.Id +
                                    "/" + fileName;
            filesStatus.DeleteType   = "DELETE";
            filesStatus.ThumbnailUrl = basePath + "api/file/get/" + saveFileResult.SiteId + "/" + saveFileResult.Id +
                                       "/ImageThumb/" + fileName;
            filesStatus.IsTemporary = true;

            filesStatus.Detail = new FileDetail
            {
                ImageSize = saveFileResult.ImageUploadedSize,
                Url       = filesStatus.Url,
                Size      = fileLength
            };
            filesStatus.Detail =
                new FileDetail {
                ImageSize = saveFileResult.ImageThumbSize, Url = filesStatus.ThumbnailUrl
            };

            return(filesStatus);
        }
示例#11
0
        public IEnumerable <IResult> Save()
        {
            var formats = new[] {
                Tuple.Create("Rich Text Format (*.rtf)", ".rtf"),
                Tuple.Create("Текстовый документ (*.txt)", ".txt"),
            };
            var dialog = new SaveFileResult(formats, DisplayName);

            yield return(dialog);

            var doc = BuildDocument();

            var range = new TextRange(doc.ContentStart, doc.ContentEnd);

            using (var stream = File.Create(dialog.Dialog.FileName)) {
                var format = DataFormats.Rtf;
                if (Path.GetExtension(dialog.Dialog.FileName).Match(".txt"))
                {
                    format = DataFormats.Text;
                }
                range.Save(stream, format);
            }
        }
示例#12
0
 protected void SaveToFileCommand()
 {
     if (PrintResult == null)
     {
         var result = new SaveFileResult(new[] {
             Tuple.Create("Файл PNG (*.png)", ".png")
         });
         result.Execute(new ActionExecutionContext());
         if (result.Success)
         {
             if (result.Dialog.FilterIndex == 1)
             {
                 var paginator = Document.DocumentPaginator;
                 for (int i = 0; i < paginator.PageCount; i++)
                 {
                     var bitmap = PrintHelper.ToBitmap(paginator, i, true);
                     var bmf    = BitmapFrame.Create(bitmap);
                     var enc    = new PngBitmapEncoder();
                     enc.Frames.Add(bmf);
                     using (var fs = result.Stream($"_{i + 1}")) {
                         enc.Save(fs);
                     }
                 }
             }
         }
     }
     else
     {
         var result = new SaveFileResult(new[] {
             Tuple.Create("Файл PNG (*.png)", ".png"),
             Tuple.Create("Файл RTF (*.rtf)", ".rtf")
         });
         result.Execute(new ActionExecutionContext());
         if (result.Success)
         {
             if (result.Dialog.FilterIndex == 1)
             {
                 var paginator = PrintResult.GetPaginator(PageRangeSelection.AllPages, new PageRange(0)) as WrapDocumentPaginator;
                 paginator.ComputePageCount();
                 for (int i = 0; i < paginator.PageCount; i++)
                 {
                     var bitmap = PrintHelper.ToBitmap(paginator, i, true);
                     var bmf    = BitmapFrame.Create(bitmap);
                     var enc    = new PngBitmapEncoder();
                     enc.Frames.Add(bmf);
                     using (var fs = result.Stream($"_{i + 1}")) {
                         enc.Save(fs);
                     }
                 }
             }
             else if (result.Dialog.FilterIndex == 2)
             {
                 var printDoc = PrintResult.Docs.First().Value;
                 using (var writer = result.Writer()) {
                     var rtfString = PrintHelper.ToRtfString(printDoc.Item2.Build(), Orientation);
                     writer.WriteLine(rtfString);
                 }
             }
         }
     }
 }
示例#13
0
        public IEnumerable <IResult> Save()
        {
            var result = new SaveFileResult(new[] {
                Tuple.Create("Отчет (*.dbf)", ".dbf"),
                Tuple.Create("Excel (*.xls)", ".xls"),
                Tuple.Create("Расширенный Excel (*.xls)", ".xls"),
                Tuple.Create("Excel (*.scv)", ".csv"),
                Tuple.Create("Здоровые люди (*.scv)", ".csv"),
            });
            var lines = Lines.Value.Where(x => x.BatchLine != null);

            yield return(result);

            if (result.Dialog.FilterIndex == 1)
            {
                using (var writer = result.Writer()) {
                    var table  = new DataTable();
                    var column = table.Columns.Add("KOD");
                    column.ExtendedProperties.Add("scale", (byte)9);

                    column = table.Columns.Add("NAME");
                    column.ExtendedProperties.Add("scale", (byte)100);

                    column = table.Columns.Add("KOL", typeof(double));
                    column.ExtendedProperties.Add("presision", 17);
                    column.ExtendedProperties.Add("scale", 3);

                    column = table.Columns.Add("PRICE", typeof(double));
                    column.ExtendedProperties.Add("presision", 17);
                    column.ExtendedProperties.Add("scale", 3);

                    column = table.Columns.Add("NOM_ZAK");
                    column.ExtendedProperties.Add("scale", (byte)10);

                    column = table.Columns.Add("NOM_AU");
                    column.ExtendedProperties.Add("scale", (byte)6);

                    var goodLines = lines.Where(l => l.OrderLine != null);
                    foreach (var line in goodLines)
                    {
                        var parsedServiceFields = line.BatchLine.ParsedServiceFields.Select(f => f.Value).FirstOrDefault();
                        table.Rows.Add(
                            line.OrderLine.Code,
                            line.OrderLine.ProductSynonym,
                            line.OrderLine.Count,
                            line.OrderLine.ResultCost,
                            line.OrderLine.Id,
                            parsedServiceFields);
                    }
                    Dbf2.Save(table, writer);
                }
            }
            else if (result.Dialog.FilterIndex == 2 || result.Dialog.FilterIndex == 3)
            {
                var exportServiceFields = result.Dialog.FilterIndex == 3;
                using (var writer = result.Writer()) {
                    ExportExcel(writer.BaseStream, lines, exportServiceFields);
                }
            }
            else if (result.Dialog.FilterIndex == 4)
            {
                using (var writer = result.Writer()) {
                    ExportCsv(writer, lines);
                }
            }
            else
            {
                using (var writer = result.Writer()) {
                    writer.WriteLine("Номер;Аптека;Дата;Код;Товар;ЗаводШК;Производитель;Количество");
                    foreach (var line in ReportLines.Value.Where(x => x.BatchLine != null))
                    {
                        var reportLine = line.BatchLine.ParsedServiceFields.Where(f => f.Key == "ReportData")
                                         .Select(f => f.Value)
                                         .FirstOrDefault();
                        writer.WriteLine(reportLine);
                    }
                }
            }
        }