public IHttpActionResult AnalysisTemplate()
        {
            var tuple = AttachmentOperator.Instance.CommonSetting();
            var model = AttachmentOperator.Instance.CommonUpload(Guid.NewGuid().ToString(), tuple.Item1, tuple.Item2, tuple.Item3);

            AttachmentOperator.Instance.AddModel(model);
            var attachment = new Attachment();

            attachment.ConvertEntity(model);
            //by文件流生成配置信息(分析时因为还没有设置数据区域,所以默认第三行第一列)
            var tuples     = TemplateOperator.Instance.ReadSheetDataFromStream(tuple.Item3, new List <Tuple <string, int, int> >());
            var fileFormat = TemplateOperator.Instance.GetFormatType(model);

            if (fileFormat == SaveFormat.Unknown)
            {
                throw new BizException("文件格式未知");
            }
            //使用配置和文件流生成业务数据便于前台展示
            List <ViewSheet> list = TemplateOperator.Instance.ReadExcelData(tuple.Item3, fileFormat, tuples.Item1, tuples.Item2, new List <Lib.Model.TemplateConfigSelect>());

            return(BizResult(new
            {
                Attachment = attachment,
                Data = list
            }));
        }
Exemple #2
0
        public IHttpActionResult Upload(string businessId)
        {
            Guid ret = Guid.Empty;

            if (string.IsNullOrEmpty(businessId) || !Guid.TryParse(businessId, out ret))
            {
                throw new BizException("参数错误");
            }
            var tuple = AttachmentOperator.Instance.CommonSetting();
            var model = AttachmentOperator.Instance.CommonUpload(businessId, tuple.Item1, tuple.Item2, tuple.Item3);
            TaskCollectionData dcd = new TaskCollectionData();

            using (TransactionScope scope = TransactionScopeFactory.Create())
            {
                string errorMessage = "";
                var    result       = TemplateOperator.Instance.ReadTaskData(businessId, tuple.Item2, tuple.Item3, out dcd, out errorMessage);
                if (result != 3)
                {
                    return(BizResult(new
                    {
                        ResultType = result,
                        Message = errorMessage
                    }));
                }
                AttachmentOperator.Instance.AddModel(model);
                scope.Complete();
            }
            var attachment = new Attachment();

            attachment.ConvertEntity(model);
            return(BizResult(new
            {
                ResultType = 3,
                Attachment = attachment,
                Message = "上传成功",
                Sheets = dcd.Sheets.Select(x => new { SheetName = x.SheetName, SheetRowLength = x.Rows.Count }).ToList()
            }));
        }