Exemplo n.º 1
0
        byte[] IOffice.ExportExcel(string fileName)
        {
            var svc = ExecutingContext.GetService <IProductionService>("ProductionService");

            var ds = svc.LoadAllProducts();

            byte[] bytes = null;

            //if (fileName.EndsWith(".xls")) {

            var tempFileName = Context.MapPath(@"~\" + fileName);

            Aspectize.ExcelHelper.SaveToFile(tempFileName, ds);

            bytes = File.ReadAllBytes(tempFileName);

            File.Delete(tempFileName);

            //} else {

            //    var xlSvc = ExecutingContext.GetService<IAspectizeExcel>("AspectizeExcel");

            //    bytes = xlSvc.ToExcel(ds, null);
            //}

            ExecutingContext.SetHttpDownloadFileName(fileName);

            return(bytes);
        }
Exemplo n.º 2
0
        //-------------------------------------------------------------------------------------------------------------------------------
        public byte[] GetExportForExcel(string keyExport, string strLibelle)
        {
            AspectizeUser  aspectizeUser = ExecutingContext.CurrentUser;
            IEntityManager em            = EntityManager.FromDataSet(DataSetHelper.Create());

            if (aspectizeUser.IsAuthenticated)
            {
                int nTimosSessionId = (int)aspectizeUser[CUserTimosWebApp.c_champSessionId];

                ITimosServiceForAspectize serviceClientAspectize = (ITimosServiceForAspectize)C2iFactory.GetNewObject(typeof(ITimosServiceForAspectize));
                CResultAErreur            result = serviceClientAspectize.GetSession(nTimosSessionId);
                if (!result)
                {
                    throw new SmartException(1100, "Votre session a expiré, veuillez vous reconnecter");
                }

                try
                {
                    IFileService fs           = ExecutingContext.GetService <IFileService>("TimosFileService");
                    string       relativePath = keyExport + ".json";
                    string       fullPath     = fs.GetFileUrl(relativePath);
                    fullPath = fullPath.Substring(16);
                    if (File.Exists(fullPath))
                    {
                        byte[]  buffer      = fs.ReadBytes(relativePath);
                        string  jsonLecture = Encoding.ASCII.GetString(buffer);
                        DataSet dsExport    = JsonConvert.DeserializeObject <DataSet>(jsonLecture);
                        if (dsExport != null)
                        {
                            IAspectizeExcel aspectizeExcel = ExecutingContext.GetService <IAspectizeExcel>("AspectizeExcel");
                            var             bytes          = aspectizeExcel.ToExcel(dsExport, null);
                            ExecutingContext.SetHttpDownloadFileName(string.Format(strLibelle + " {0:yyyyMMddHHmm}.xlsx", File.GetLastWriteTime(fullPath)));
                            return(bytes);
                        }
                    }
                }
                catch (Exception ex)
                {
                    throw new SmartException(1010,
                                             "Erreur GetExportForExcel(nTimosSessionId = " + nTimosSessionId + ", keyExport = " + keyExport + ")" +
                                             Environment.NewLine +
                                             ex.Message);
                }
            }
            else
            {
                throw new SmartException(1100, "Votre session a expiré, veuillez vous reconnecter");
            }
            return(new byte[] { });
        }
Exemplo n.º 3
0
        byte[] ILoadDataService.DownloadAttachment(Guid workItemId, Guid attachmentId)
        {
            IDataManager dm = EntityManager.FromDataBaseService("MyDataService");

            var fileService = ExecutingContext.GetService <IFileService>("MyFileService");

            var attachment = dm.GetEntity <Attachment>(attachmentId);

            string pathFile = string.Format(@"{0:N}/{1:N}", workItemId, attachment.Id);

            ExecutingContext.SetHttpDownloadFileName(attachment.FileName);

            return(fileService.ReadBytes(pathFile));
        }