//첨부파일 추가
        public Response AttachFile(string CorpNum, MgtKeyType KeyType, string MgtKey, string FilePath,
                                   string UserID = null)
        {
            if (string.IsNullOrEmpty(value: MgtKey))
            {
                throw new PopbillException(code: -99999999, Message: "문서번호가 입력되지 않았습니다.");
            }
            if (string.IsNullOrEmpty(value: FilePath))
            {
                throw new PopbillException(code: -99999999, Message: "파일경로가 입력되지 않았습니다.");
            }

            List <UploadFile> files = new List <UploadFile>();

            UploadFile file = new UploadFile
            {
                FieldName = "Filedata",
                FileName  = System.IO.Path.GetFileName(path: FilePath),
                FileData  = new FileStream(path: FilePath, mode: FileMode.Open, access: FileAccess.Read)
            };


            files.Add(item: file);

            return(httppostFile <Response>("/Taxinvoice/" + KeyType.ToString() + "/" + MgtKey + "/Files", CorpNum, null,
                                           files, null, UserID));
        }
        public List <AttachedFile> GetFiles(String CorpNum, MgtKeyType KeyType, String MgtKey)
        {
            if (String.IsNullOrEmpty(MgtKey))
            {
                throw new PopbillException(-99999999, "관리번호가 입력되지 않았습니다.");
            }

            return(httpget <List <AttachedFile> >("/Taxinvoice/" + KeyType.ToString() + "/" + MgtKey + "/Files", CorpNum, null));
        }
        public Response Delete(String CorpNum, MgtKeyType KeyType, String MgtKey, String UserID)
        {
            if (String.IsNullOrEmpty(MgtKey))
            {
                throw new PopbillException(-99999999, "관리번호가 입력되지 않았습니다.");
            }

            return(httppost <Response>("/Taxinvoice/" + KeyType.ToString() + "/" + MgtKey, CorpNum, UserID, null, "DELETE"));
        }
        public TaxinvoiceInfo GetInfo(String CorpNum, MgtKeyType KeyType, String MgtKey)
        {
            if (String.IsNullOrEmpty(MgtKey))
            {
                throw new PopbillException(-99999999, "관리번호가 입력되지 않았습니다.");
            }

            return(httpget <TaxinvoiceInfo>("/Taxinvoice/" + KeyType.ToString() + "/" + MgtKey, CorpNum, null));
        }
        //상세정보 확인 (XML)
        public TaxinvoiceXML GetXML(string CorpNum, MgtKeyType KeyType, string MgtKey, string UserID = null)
        {
            if (string.IsNullOrEmpty(MgtKey))
            {
                throw new PopbillException(-99999999, "문서번호가 입력되지 않았습니다.");
            }

            return(httpget <TaxinvoiceXML>("/Taxinvoice/" + KeyType.ToString() + "/" + MgtKey + "?XML", CorpNum, UserID));
        }
        //국세청 즉시 전송
        public Response SendToNTS(string CorpNum, MgtKeyType KeyType, string MgtKey, string UserID = null)
        {
            if (string.IsNullOrEmpty(MgtKey))
            {
                throw new PopbillException(-99999999, "문서번호가 입력되지 않았습니다.");
            }

            return(httppost <Response>("/Taxinvoice/" + KeyType.ToString() + "/" + MgtKey, CorpNum, null, "NTS", null,
                                       UserID));
        }
        public String GetEPrintURL(String CorpNum, MgtKeyType KeyType, String MgtKey, String UserID)
        {
            if (String.IsNullOrEmpty(MgtKey))
            {
                throw new PopbillException(-99999999, "관리번호가 입력되지 않았습니다.");
            }

            URLResponse response = httpget <URLResponse>("/Taxinvoice/" + KeyType.ToString() + "/" + MgtKey + "?TG=EPRINT", CorpNum, UserID);

            return(response.url);
        }
        public List <TaxinvoiceInfo> GetInfos(String CorpNum, MgtKeyType KeyType, List <String> MgtKeyList)
        {
            if (MgtKeyList == null || MgtKeyList.Count == 0)
            {
                throw new PopbillException(-99999999, "관리번호 목록이 입력되지 않았습니다.");
            }

            String PostData = toJsonString(MgtKeyList);

            return(httppost <List <TaxinvoiceInfo> >("/Taxinvoice/" + KeyType.ToString(), CorpNum, null, PostData, null));
        }
        //세금계산서 메일링크 URL
        public string GetMailURL(string CorpNum, MgtKeyType KeyType, string MgtKey, string UserID)
        {
            if (string.IsNullOrEmpty(MgtKey))
            {
                throw new PopbillException(-99999999, "문서번호가 입력되지 않았습니다.");
            }

            URLResponse response = httpget <URLResponse>("/Taxinvoice/" + KeyType.ToString() + "/" + MgtKey + "?TG=MAIL",
                                                         CorpNum, UserID);

            return(response.url);
        }
        public String GetMassPrintURL(String CorpNum, MgtKeyType KeyType, List <String> MgtKeyList, String UserID)
        {
            if (MgtKeyList == null || MgtKeyList.Count == 0)
            {
                throw new PopbillException(-99999999, "관리번호 목록이 입력되지 않았습니다.");
            }

            String PostData = toJsonString(MgtKeyList);

            URLResponse response = httppost <URLResponse>("/Taxinvoice/" + KeyType.ToString() + "?Print", CorpNum, UserID, PostData, null);

            return(response.url);
        }
        //수정 - String JSON
        public Response Update(string CorpNum, MgtKeyType KeyType, string MgtKey, string taxinvoice,
                               string UserID = null)
        {
            if (string.IsNullOrEmpty(MgtKey))
            {
                throw new PopbillException(-99999999, "문서번호가 입력되지 않았습니다.");
            }
            if (string.IsNullOrEmpty(taxinvoice))
            {
                throw new PopbillException(-99999999, "세금계산서 정보가 입력되지 않았습니다.");
            }

            return(httppost <Response>("/Taxinvoice/" + KeyType.ToString() + "/" + MgtKey, CorpNum, taxinvoice, "PATCH",
                                       null, UserID));
        }
        public Response SendEmail(String CorpNum, MgtKeyType KeyType, String MgtKey, String Receiver, String UserID)
        {
            if (String.IsNullOrEmpty(MgtKey))
            {
                throw new PopbillException(-99999999, "관리번호가 입력되지 않았습니다.");
            }

            ResendRequest request = new ResendRequest();

            request.receiver = Receiver;

            String PostData = toJsonString(request);

            return(httppost <Response>("/Taxinvoice/" + KeyType.ToString() + "/" + MgtKey, CorpNum, UserID, PostData, "EMAIL"));
        }
        //첨부파일 삭제
        public Response DeleteFile(string CorpNum, MgtKeyType KeyType, string MgtKey, string FileID,
                                   string UserID = null)
        {
            if (string.IsNullOrEmpty(MgtKey))
            {
                throw new PopbillException(-99999999, "문서번호가 입력되지 않았습니다.");
            }
            if (string.IsNullOrEmpty(FileID))
            {
                throw new PopbillException(-99999999, "파일 아이디가 입력되지 않았습니다.");
            }

            return(httppost <Response>("/Taxinvoice/" + KeyType.ToString() + "/" + MgtKey + "/Files/" + FileID, CorpNum,
                                       null, "DELETE", null, UserID));
        }
        public Response CancelRequest(String CorpNum, MgtKeyType KeyType, String MgtKey, String Memo, String UserID)
        {
            if (String.IsNullOrEmpty(MgtKey))
            {
                throw new PopbillException(-99999999, "관리번호가 입력되지 않았습니다.");
            }

            MemoRequest request = new MemoRequest();

            request.memo = Memo;

            String PostData = toJsonString(request);

            return(httppost <Response>("/Taxinvoice/" + KeyType.ToString() + "/" + MgtKey, CorpNum, UserID, PostData, "CANCELREQUEST"));
        }
        public Response Update(String CorpNum, MgtKeyType KeyType, String MgtKey, Taxinvoice taxinvoice, String UserID)
        {
            if (String.IsNullOrEmpty(MgtKey))
            {
                throw new PopbillException(-99999999, "관리번호가 입력되지 않았습니다.");
            }

            if (taxinvoice == null)
            {
                throw new PopbillException(-99999999, "세금계산서 정보가 입력되지 않았습니다.");
            }

            String PostData = toJsonString(taxinvoice);

            return(httppost <Response>("/Taxinvoice/" + KeyType.ToString() + "/" + MgtKey, CorpNum, UserID, PostData, "PATCH"));
        }
        //팩스 전송
        public Response SendFAX(string CorpNum, MgtKeyType KeyType, string MgtKey, string Sender, string Receiver,
                                string UserID = null)
        {
            if (string.IsNullOrEmpty(MgtKey))
            {
                throw new PopbillException(-99999999, "문서번호가 입력되지 않았습니다.");
            }

            ResendRequest request = new ResendRequest {
                sender = Sender, receiver = Receiver
            };

            string PostData = toJsonString(request);

            return(httppost <Response>("/Taxinvoice/" + KeyType.ToString() + "/" + MgtKey, CorpNum, PostData,
                                       "FAX", null, UserID));
        }
        public Response Issue(String CorpNum, MgtKeyType KeyType, String MgtKey, String Memo, String EmailSubject, bool ForceIssue, String UserID)
        {
            if (String.IsNullOrEmpty(MgtKey))
            {
                throw new PopbillException(-99999999, "관리번호가 입력되지 않았습니다.");
            }

            IssueRequest request = new IssueRequest();

            request.memo         = Memo;
            request.emailSubject = EmailSubject;
            request.forceIssue   = ForceIssue;

            String PostData = toJsonString(request);

            return(httppost <Response>("/Taxinvoice/" + KeyType.ToString() + "/" + MgtKey, CorpNum, UserID, PostData, "ISSUE"));
        }
        //역발행요청 거부
        public Response Refuse(string CorpNum, MgtKeyType KeyType, string MgtKey, string Memo = null,
                               string UserID = null)
        {
            if (string.IsNullOrEmpty(MgtKey))
            {
                throw new PopbillException(-99999999, "문서번호가 입력되지 않았습니다.");
            }

            MemoRequest request = new MemoRequest {
                memo = Memo
            };

            string PostData = toJsonString(request);

            return(httppost <Response>("/Taxinvoice/" + KeyType.ToString() + "/" + MgtKey, CorpNum, PostData, "REFUSE",
                                       null, UserID));
        }
        //발행
        public IssueResponse Issue(string CorpNum, MgtKeyType KeyType, string MgtKey, bool ForceIssue = false,
                                   string Memo = null, string EmailSubject = null, string UserID = null)
        {
            if (string.IsNullOrEmpty(MgtKey))
            {
                throw new PopbillException(-99999999, "문서번호가 입력되지 않았습니다.");
            }

            IssueRequest request = new IssueRequest {
                memo = Memo, emailSubject = EmailSubject, forceIssue = ForceIssue
            };

            string PostData = toJsonString(request);

            return(httppost <IssueResponse>("/Taxinvoice/" + KeyType.ToString() + "/" + MgtKey, CorpNum, PostData, "ISSUE",
                                            null, UserID));
        }
        public bool CheckMgtKeyInUse(String CorpNum, MgtKeyType KeyType, String MgtKey)
        {
            if (String.IsNullOrEmpty(MgtKey))
            {
                throw new PopbillException(-99999999, "관리번호가 입력되지 않았습니다.");
            }

            try
            {
                TaxinvoiceInfo response = httpget <TaxinvoiceInfo>("/Taxinvoice/" + KeyType.ToString() + "/" + MgtKey, CorpNum, null);

                return(string.IsNullOrEmpty(response.itemKey) == false);
            }
            catch (PopbillException pe)
            {
                if (pe.code == -11000005)
                {
                    return(false);
                }

                throw pe;
            }
        }
        public Response AttachFile(String CorpNum, MgtKeyType KeyType, String MgtKey, String FilePath, String UserID)
        {
            if (String.IsNullOrEmpty(MgtKey))
            {
                throw new PopbillException(-99999999, "관리번호가 입력되지 않았습니다.");
            }
            if (String.IsNullOrEmpty(FilePath))
            {
                throw new PopbillException(-99999999, "파일경로가 입력되지 않았습니다.");
            }

            List <UploadFile> files = new List <UploadFile>();

            UploadFile file = new UploadFile();

            file.FieldName = "Filedata";
            file.FileName  = System.IO.Path.GetFileName(FilePath);
            file.FileData  = new FileStream(FilePath, FileMode.Open, FileAccess.Read);

            files.Add(file);

            return(httppostFile <Response>("/Taxinvoice/" + KeyType.ToString() + "/" + MgtKey + "/Files", CorpNum, UserID, null, files, null));
        }