예제 #1
0
        protected void UploadAttachFiles()
        {
            try
            {
                using (FileService.FileTransferServiceClient svc = new FileService.FileTransferServiceClient())
                {
                    MoveFileResponse response = new MoveFileResponse();

                    foreach (AttachFilesIAS.AttachFile attatch in this.AttachFiles)
                    {
                        String container = String.Format(@"{0}\{1}", AttachFileContainer, this.ID_CARD_NO);

                        String newFileName = this.ID_CARD_NO + "_"
                                             + Convert.ToInt32(attatch.ATTACH_FILE_TYPE).ToString("00")
                                             + "." + attatch.EXTENSION;

                        //response = svc.MoveFile(new MoveFileRequest() {
                        //                                CurrentContainer = "",
                        //                                CurrentFileName = attatch.ATTACH_FILE_PATH,
                        //                                TargetContainer = container,
                        //                                TargetFileName = newFileName });
                        if (response.Code != "0000")
                        {
                            throw new RegistrationException(response.Message);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw new RegistrationException(ex.Message);
            }
        }
예제 #2
0
        public void Print(string FileName)
        {
            using (FileService.FileTransferServiceClient svc = new FileService.FileTransferServiceClient())
            {
                try
                {
                    DownloadFileResponse response = svc.DownloadFile(new DownloadFileRequest()
                    {
                        TargetContainer = "", TargetFileName = FileName
                    });

                    if (response.Code == "0000")
                    {
                        if (response.ContentType == "application/pdf")
                        {
                            String fileName = response.FileName.Substring(response.FileName.IndexOf(@"\"));
                            if (String.IsNullOrEmpty(fileName))
                            {
                                ViewDocument(response.FileByteStream, Convert.ToInt64(response.Length), response.ContentType);
                            }
                            else
                            {
                                ViewDocument(response.FileByteStream, Convert.ToInt64(response.Length), response.ContentType, fileName);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    Response.Write(ex.Message);
                }
            }
        }
예제 #3
0
        public virtual void AddAttach(DTO.PersonAttatchFile attachFile, Stream fileSteam)
        {
            if (_attachFiles.Where(a => a.REGISTRATION_ID == attachFile.REGISTRATION_ID && a.ATTACH_FILE_TYPE == attachFile.ATTACH_FILE_TYPE).Count() > 0)
            {
                throw new PersonalIssueException(Resources.errorBasePersonal_001);
            }
            using (FileService.FileTransferServiceClient svc = new FileService.FileTransferServiceClient())
            {
                UploadFileResponse response = new UploadFileResponse();

                String fs_Attach = String.Format(@"{0}\{1}", AttachFileContainer, attachFile.REGISTRATION_ID);

                String newFileName = this.ID_CARD_NO + "_"
                                     + Convert.ToInt32(attachFile.ATTACH_FILE_TYPE).ToString("00")
                                     + "." + GetExtensionFile(attachFile.FileName);
                //response = svc.UploadFile(new UploadFileRequest() {
                //                                TargetContainer = fs_Attach,
                //                                TargetFileName = newFileName,
                //                                FileStream = fileSteam
                //                            });
                if (response.Code != "0000")
                {
                    throw new PersonalIssueException(response.Message);
                }

                attachFile.ATTACH_FILE_PATH = response.TargetFullName;
                attachFile.ID = IAS.BLL.Helpers.GenerateIdHelper.GetGenAutoId();
                _attachFiles.Add(attachFile);
            }
        }
예제 #4
0
        private void AddAttechFile(DTO.AttachFile attachFile)
        {
            if (((List <DTO.AttachFile>)Session["AttachFiles"]).Where(a => a.AttechType == attachFile.AttechType).Count() > 0)
            {
                throw new ApplicationException(Resources.errorTestUploadData_002);
            }
            else
            {
                using (svc = new FileService.FileTransferServiceClient()) {
                    UploadFileResponse response  = new UploadFileResponse();
                    Stream             fileStrem = fUpload.PostedFile.InputStream;
                    response = svc.UploadFile(new UploadFileRequest()
                    {
                        TargetContainer = attachFile.TargetContainer,
                        TargetFileName  = attachFile.TargetFileName,
                        FileStream      = fileStrem
                    });

                    attachFile.TargetFullName = CryptoBase64.Encryption(response.TargetFullName);
                    ((List <DTO.AttachFile>)Session["AttachFiles"]).Add(attachFile);
                    gv.DataSource = ((List <DTO.AttachFile>)Session["AttachFiles"]);
                    gv.DataBind();
                }
            }
        }
예제 #5
0
        protected void btnDownload_Click(object sender, EventArgs e)
        {
            using (svc = new FileService.FileTransferServiceClient()) {
                DownloadFileResponse response   = new DownloadFileResponse();
                DTO.AttachFile       attachFile = ((List <DTO.AttachFile>)Session["AttachFiles"]).FirstOrDefault();
                String container = "";
                String fileName  = "";
                response = svc.DownloadFile(new DownloadFileRequest()
                {
                    TargetContainer = container, TargetFileName = attachFile.TargetFullName
                });

                Page.Response.Clear();
                Page.Response.BufferOutput = true;
                Page.Response.ContentType  = response.ContentType;


                // Append header
                //Page.Response.AppendHeader("Content-Disposition", "attachment; filename=" + response.FileName);

                // Write the file to the Response
                const int bufferLength = 10000;
                byte[]    buffer       = new Byte[bufferLength];
                int       length       = 0;
                Stream    download     = null;

                try
                {
                    download = response.FileByteStream; // GetFile(fileName);

                    do
                    {
                        if (Page.Response.IsClientConnected)
                        {
                            length = download.Read(buffer, 0, bufferLength);
                            Page.Response.OutputStream.Write(buffer, 0, length);


                            buffer = new Byte[bufferLength];
                        }
                        else
                        {
                            length = -1;
                        }
                    }while (length > 0);

                    Page.Response.Flush();
                    Page.Response.End();
                }
                finally
                {
                    if (download != null)
                    {
                        download.Close();
                    }
                }
            }
        }
예제 #6
0
        public virtual void AddAttach(FileInfo fileInfo, String attachType)
        {
            if (_attachFiles.Where(a => a.ATTACH_FILE_TYPE == attachType).Count() > 0)
            {
                throw new RegistrationException(Resources.errorBasePersonal_001);
            }
            if (!fileInfo.Exists)
            {
                throw new RegistrationException(Resources.errorBaseRegistration_003);
            }

            // ------------ Init Data --------------
            String container = String.Format(@"{0}\{1}", TempFileContainer, this.ID);

            String   fileName = String.Format("{0}_{1:00}{2}", this.ID_CARD_NO, Convert.ToInt32(attachType), fileInfo.Extension);
            DateTime curDate  = DateTime.Now;

            AttachFilesIAS.AttachFile attachFile = new AttachFilesIAS.AttachFile()
            {
                ID = IAS.BLL.Helpers.GenerateIdHelper.GetGenAutoId(),
                ATTACH_FILE_TYPE = attachType,
                REGISTRATION_ID  = this.ID,
                CREATED_BY       = this.ID_CARD_NO,
                CREATED_DATE     = curDate,
                UPDATED_BY       = this.ID_CARD_NO,
                UPDATED_DATE     = curDate,
                FILE_STATUS      = AttachFileStatus.Active.Value(),
                ATTACH_FILE_PATH = String.Format(@"{0}\{1}", container, fileName)
            };
            //-----------------------------------------



            // -------------- Upload File To Temp--------------------------------
            using (FileService.FileTransferServiceClient svc = new FileService.FileTransferServiceClient())
            {
                UploadFileResponse response = new UploadFileResponse();


                //response = svc.UploadFile(new UploadFileRequest() {
                //                                TargetContainer = attachFile.ATTACH_CONTAINER,
                //                                TargetFileName = attachFile.ATTACH_FILE_NAME,
                //                                FileStream = fileInfo.Create()
                //                            });
                if (response.Code != "0000")
                {
                    throw new RegistrationException(response.Message);
                }

                attachFile.ATTACH_FILE_PATH = response.TargetFullName;
                _attachFiles.Add(attachFile);
            }
            // ------------------------------------------------------------------
        }
        public void DownloadPDF(string FileName)
        {
            DownloadFileResponse download;

            using (FileService.FileTransferServiceClient fileService = new FileService.FileTransferServiceClient())
            {
                download = fileService.DownloadFile(new DownloadFileRequest()
                {
                    TargetContainer = "",
                    TargetFileName  = FileName
                });

                ShowDocument(download.FileByteStream, (long)download.Length, download.ContentType);
            }
        }
예제 #8
0
        protected void Page_Load(object sender, EventArgs e)
        {
            using (FileService.FileTransferServiceClient svc = new FileService.FileTransferServiceClient())
            {
                try
                {
                    String targetImage = Request.QueryString["targetImage"].ToString();

                    DownloadFileResponse response = svc.DownloadFile(new DownloadFileRequest()
                    {
                        TargetContainer = "", TargetFileName = CryptoBase64.Decryption(targetImage)
                    });

                    if (response.Code == "0000")
                    {
                        Int32  index    = response.FileName.LastIndexOf(@"\");
                        String filename = response.FileName.Substring((index > 0) ? index + 1 : 0);
                        if (response.ContentType == Utils.ContentTypeHelper.MimeType(".pdf") ||
                            response.ContentType == Utils.ContentTypeHelper.MimeType(".doc") ||
                            response.ContentType == Utils.ContentTypeHelper.MimeType(".docx") ||
                            response.ContentType == Utils.ContentTypeHelper.MimeType(".xls") ||
                            response.ContentType == Utils.ContentTypeHelper.MimeType(".xlsx"))

                        {
                            ShowDocument(response.FileByteStream, Convert.ToInt64(response.Length), response.ContentType, filename);
                        }
                        else if (response.ContentType == "application/octet-stream" &&
                                 (filename.Substring(filename.LastIndexOf('.')) == ".docx" ||
                                  filename.Substring(filename.LastIndexOf('.')) == ".doc" ||
                                  filename.Substring(filename.LastIndexOf('.')) == ".xls" ||
                                  filename.Substring(filename.LastIndexOf('.')) == ".xlsx"
                                 ))
                        {
                            ShowDocument(response.FileByteStream, Convert.ToInt64(response.Length),
                                         Utils.ContentTypeHelper.MimeType(filename.Substring(filename.LastIndexOf('.'))), filename);
                        }
                        else
                        {
                            ShowImage(response.FileByteStream, Convert.ToInt64(response.Length), response.ContentType, filename);
                        }
                    }
                }
                catch (Exception ex)
                {
                    Response.Write(ex.Message);
                }
            }
        }
예제 #9
0
        public virtual void DeleteAttach(String id)
        {
            if (_attachFiles.Where(a => a.ID == id).Count() <= 0)
            {
                throw new RegistrationException(Resources.errorBaseRegistration_004);
            }

            AttachFilesIAS.AttachFile attachFile = AttachFiles.Where(a => a.ID == id).Single();
            using (FileService.FileTransferServiceClient svc = new FileService.FileTransferServiceClient())
            {
                //DeleteFileResponse response = svc.DeleteFile(new DeleteFileRequest() { TargetFileName = attachFile.ATTACH_FILE_PATH });
                //if (response.Code != "0000")
                //    throw new RegistrationException(response.Message);

                _attachFiles.Remove(attachFile);
            }
        }
예제 #10
0
        protected void gv_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            using (svc = new FileService.FileTransferServiceClient())
            {
                String targetfile = gv.Rows[e.RowIndex].Cells[7].Text;

                DeleteFileResponse response = svc.DeleteFile(new DeleteFileRequest()
                {
                    TargetFileName = targetfile
                });

                DTO.AttachFile file = ((List <DTO.AttachFile>)Session["AttachFiles"]).Where(a => a.AttechType == gv.Rows[e.RowIndex].Cells[1].Text.Trim()).FirstOrDefault();
                ((List <DTO.AttachFile>)Session["AttachFiles"]).Remove(file);
                gv.DataSource = ((List <DTO.AttachFile>)Session["AttachFiles"]);
                gv.DataBind();
                Label1.Text = response.Message;
            }
        }
예제 #11
0
        public virtual void DeleteAttach(DTO.PersonAttatchFile attachFile)
        {
            if (_attachFiles.Where(a => a.ID == attachFile.ID &&
                                   a.REGISTRATION_ID == attachFile.REGISTRATION_ID &&
                                   a.ATTACH_FILE_TYPE == attachFile.ATTACH_FILE_TYPE).Count() <= 0)
            {
                throw new PersonalIssueException(Resources.errorBaseRegistration_004);
            }

            using (FileService.FileTransferServiceClient svc = new FileService.FileTransferServiceClient())
            {
                //DeleteFileResponse response = svc.DeleteFile(new DeleteFileRequest()
                //{
                //    TargetFileName = attachFile.ATTACH_FILE_PATH
                //});
                //if (response.Code != "0000")
                //    throw new PersonalIssueException(response.Message);

                _attachFiles.Remove(attachFile);
            }
        }
예제 #12
0
        public virtual AttachFilesIAS.AttachFile GetAttach(String id, ref Stream fileStrem)
        {
            AttachFilesIAS.AttachFile attachFile = new AttachFilesIAS.AttachFile();

            if (_attachFiles.Where(a => a.ID == id).Count() <= 0)
            {
                throw new RegistrationException(Resources.errorBaseRegistration_004);
            }

            attachFile = _attachFiles.Where(a => a.ID == id).Single();

            using (FileService.FileTransferServiceClient svc = new FileService.FileTransferServiceClient())
            {
                //DownloadFileResponse response = svc.DownloadFile(new DownloadFileRequest() { TargetContainer = "", TargetFileName = attachFile.ATTACH_FILE_PATH });
                //if (response.Code != "0000")
                //    throw new RegistrationException(response.Message);

                //fileStrem = response.FileByteStream;
            }

            return(attachFile);
        }
예제 #13
0
        public void Download(string FileName)
        {
            DownloadFileResponse download;

            using (FileService.FileTransferServiceClient fileService = new FileService.FileTransferServiceClient())
            {
                download = fileService.DownloadFile(new DownloadFileRequest()
                {
                    TargetContainer = "",
                    TargetFileName  = FileName
                });
                Int32 indexS = download.FileName.IndexOf(@"\");
                if (indexS <= 0)
                {
                    ShowDocument(download.FileByteStream, (long)download.Length, download.ContentType);
                }
                else
                {
                    ShowDocument(download.FileByteStream, (long)download.Length, download.ContentType, download.FileName.Substring(indexS + 1));
                }
            }
        }
예제 #14
0
        public virtual DTO.PersonAttatchFile GetAttach(string id, string type, ref Stream fileStrem)
        {
            DTO.PersonAttatchFile attachFile = new DTO.PersonAttatchFile();
            if (_attachFiles.Where(a => a.ATTACH_FILE_TYPE == type).Count() <= 0)
            {
                throw new PersonalIssueException(Resources.errorBaseRegistration_004);
            }

            attachFile = _attachFiles.Where(a => a.ATTACH_FILE_TYPE == type).FirstOrDefault();
            using (FileService.FileTransferServiceClient svc = new FileService.FileTransferServiceClient())
            {
                //DownloadFileResponse response = svc.DownloadFile(new DownloadFileRequest() {
                //                                                    TargetContainer = "",
                //                                                    TargetFileName = attachFile.ATTACH_FILE_PATH });
                //if (response.Code != "0000")
                //    throw new PersonalIssueException(response.Message);

                //fileStrem = response.FileByteStream;
            }


            return(attachFile);
        }
예제 #15
0
        protected void gv_SelectedIndexChanged(object sender, EventArgs e)
        {
            DTO.AttachFile attachFile = ((List <DTO.AttachFile>)Session["AttachFiles"]).FirstOrDefault();
            String         container  = "";
            String         fileName   = gv.Rows[gv.SelectedIndex].Cells[7].Text;


            using (svc = new FileService.FileTransferServiceClient())
            {
                DownloadFileResponse response = new DownloadFileResponse();

                response = svc.DownloadFile(new DownloadFileRequest()
                {
                    TargetContainer = container, TargetFileName = IAS.Utils.CryptoBase64.Decryption(fileName)
                });
                if (response.Code == "0000")
                {
                    ShowImage(response.FileByteStream, Convert.ToInt64(response.Length));
                }
            }
            //    Page.Response.Clear();
            //    Page.Response.BufferOutput = true;
            //    Page.Response.ContentType = response.ContentType;



            //    // Append header
            //    Page.Response.AppendHeader("Content-Disposition", "attachment; filename=" + response.FileName);

            //    // Write the file to the Response
            //    //const int bufferLength = Convert.ToInt32(response.Length);
            //    byte[] buffer = new Byte[Convert.ToInt32(response.Length)];
            //    //int length = 0;
            //    //Stream download = null;
            //    //response.FileByteStream.Write(buffer, 0, Convert.ToInt32(response.Length));
            //    //myImage.ImageUrl = Convert.ToBase64String(buffer).ToString();

            //    using (var memoryStream = new MemoryStream())
            //    {
            //        response.FileByteStream.CopyTo(memoryStream);
            //        buffer = memoryStream.ToArray();
            //    }

            //    myImage.ImageUrl = Convert.ToBase64String(buffer).ToString();

            //    //try
            //    //{
            //    //    download = response.FileByteStream; // etFile(fileName);

            //    //    do
            //    //    {
            //    //        if (Page.Response.IsClientConnected)
            //    //        {
            //    //            length = download.Read(buffer, 0, bufferLength);
            //    //            Page.Response.OutputStream.Write(buffer, 0, length);
            //    //            myImage.ImageUrl = Convert.ToBase64String(buffer).ToString();
            //    //            buffer = new Byte[bufferLength];
            //    //        }
            //    //        else
            //    //        {
            //    //            length = -1;
            //    //        }
            //    //    }
            //    //    while (length > 0);

            //    //    Page.Response.Flush();
            //    //    Page.Response.End();
            //    //}
            //    //finally
            //    //{
            //    //    if (download != null)
            //    //        download.Close();
            //    //}
            //}
        }
예제 #16
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            MoveFileResponse response = new MoveFileResponse();

            try
            {
                using (svc = new FileService.FileTransferServiceClient())
                {
                    IList <DTO.AttachFile> attachFiles = ((IList <DTO.AttachFile>)Session["AttachFiles"]);

                    foreach (DTO.AttachFile item in attachFiles)
                    {
                        String target = AttachFileContainer + @"\" + item.ID;
                        response = svc.MoveFile(new MoveFileRequest()
                        {
                            CurrentContainer = "",
                            CurrentFileName  = CryptoBase64.Decryption(item.TargetFullName),
                            TargetContainer  = target,
                            TargetFileName   = item.TargetFileName
                        });

                        if (response.Code != "0000")
                        {
                            throw new ApplicationException(response.Message);
                        }

                        item.TargetFullName = response.TargetFullName;
                    }

                    gv.DataSource = attachFiles;
                    gv.DataBind();
                }
            }
            catch (Exception ex)
            {
                response.Message = ex.Message;
                response.Code    = "0001";
            }



            //IList<DTO.AttachFile> attachFiles = ((IList<DTO.AttachFile>)Session["AttechFiles"]).ToList();
            //foreach (DTO.AttachFile item in AttachFiles)
            //{
            ////svc = new FileService.FileTransferServiceClient();
            //svc = new FileService.FileTransferServiceClient();
            //UploadFileResponse response = new UploadFileResponse();

            //string res = svc.UploadFile(item.TargetFolder, item.ID, item.DataStream, out response.Code, out response.Message, out response.Certificate);
            //BLL.FileBiz biz = new BLL.FileBiz();
            //string targetFolder = IAS.BLL.Helpers.GenerateIdHelper.GetGenAutoId();
            ////biz.UploadToTemp(fUpload.PostedFile.InputStream, fUpload.FileName, targetFolder, fUpload.FileName);
            //biz.UploadToTemp(item.DataStream, item.FileName, item.TargetFolder, item.FileName);
            //Response.Write("Success");

            //IAS.FileService.FileUploadMessage fileUploadMessage = new IAS.FileService.FileUploadMessage();

            //var res = new DTO.ResponseService<string>();
            //var resMsg = new FileService.FileUploadMessage();
            //try
            //{
            //    resMsg.FileByteStream = item.DataStream;
            //    resMsg.Metadata = new FileMetaData
            //    {
            //        localFilename = item.FileName,
            //        remoteFilename = item.ID,
            //        targetFolder = string.Format(item.FileName + @"\{0}\", item.ID),
            //    };

            //    svc.UploadFile(ref resMsg.Metadata, ref resMsg.FileByteStream);
            //    res.DataResponse = resMsg.Metadata.resMsg;
            //}
            //catch (Exception ex)
            //{
            //    res.ErrorMsg = "กรุณาติดต่อผู้ดูแลระบบ"; // +resMsg.Metadata.resMsg;
            //}

            //}
        }