Exemplo n.º 1
0
        public FinanceResponse DoTest()
        {
            var uid = SerialNoService.GetUUID();
            int i   = 1;

            while (i < 1000)
            {
                logger.Debug(uid + ":" + i);
                Thread.Sleep(10);
                i++;
            }
            return(CreateResponse(FinanceResult.SUCCESS));
        }
Exemplo n.º 2
0
        public HttpResponseMessage Export(CashflowSheetExportRequest request)
        {
            ExcelExportor exportor             = new ExcelExportor(new CashflowExportHandler());
            Dictionary <string, string> filter = request.filter;
            var lst = service.ListSheet(filter);
            var dt  = EntityConvertor <CashflowSheetItem> .ToDataTable(lst);

            MemoryStream ms = new MemoryStream();

            exportor.Export(ms, dt, ".xls");

            string relativePath = AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
            string sPath        = Path.Combine(Path.GetFullPath(relativePath), "Cache");

            if (!Directory.Exists(sPath))
            {
                Directory.CreateDirectory(sPath);
            }
            string fileName = SerialNoService.GetUUID() + ".xls";
            string filePath = Path.Combine(sPath, fileName);

            using (FileStream fs = new FileStream(filePath, FileMode.Create, FileAccess.Write))
            {
                byte[] data = ms.ToArray();
                fs.Write(data, 0, data.Length);
                fs.Flush();
            }
            ms.Close();
            ms.Dispose();

            var stream = new FileStream(filePath, FileMode.Open);
            HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK);

            response.Content = new StreamContent(stream);
            response.Content.Headers.ContentType        = new MediaTypeHeaderValue("application/vnd.ms-excel");
            response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
            {
                FileName = fileName
            };

            //System.IO.File.Delete(filePath);

            return(response);
        }
Exemplo n.º 3
0
        public FinanceResponse Upload(HttpRequestMessage request)
        {
            try
            {
                string       relativePath = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
                string       path         = Path.GetFullPath(relativePath + ".Cache/") + SerialNoService.GetUUID() + ".xls";
                FileStream   fs           = new FileStream(path, FileMode.Append);
                BinaryWriter w            = new BinaryWriter(fs);
                fs.Position = fs.Length;
                request.Content.CopyToAsync(fs).Wait();
                w.Close();
                fs.Close();

                var    query = request.GetQueryNameValuePairs();
                string name  = "";
                foreach (var kv in query)
                {
                    if (kv.Key == "name")
                    {
                        name = kv.Value;
                        break;
                    }
                }

                IImportHandler dtl = null;
                switch (name)
                {
                case "BalanceSheet":
                    dtl = new BalanceSheetDTL();
                    break;

                case "ProfitSheet":
                    dtl = new ProfitSheetDTL();
                    break;
                }
                if (dtl == null)
                {
                    return(CreateResponse(FinanceResult.SYSTEM_ERROR));
                }

                dtl.SetFileName(path);
                ExcelImportor importor = new ExcelImportor(long.Parse(Tid), dtl);
                importor.Import();

                return(CreateResponse(FinanceResult.SUCCESS));
            }
            catch
            {
                return(CreateResponse(FinanceResult.SYSTEM_ERROR));
            }
        }