private void AddVoucher(CreditorOrderClient selectedItem, string actionType) { var voucher = new VouchersClient(); voucher._Content = ContentTypes.PurchaseInvoice; voucher._PurchaseNumber = selectedItem._OrderNumber; voucher._Project = selectedItem._Project; voucher._Approver1 = selectedItem._Approver; voucher._CreditorAccount = selectedItem._InvoiceAccount ?? selectedItem._DCAccount; #if !SILVERLIGHT if (actionType == "DragDrop") { var dragDropWindow = new UnicontaDragDropWindow(false); dragDropWindow.Closed += delegate { if (dragDropWindow.DialogResult == true) { var fileInfo = dragDropWindow.FileInfoList?.SingleOrDefault(); if (fileInfo != null) { voucher._Data = fileInfo.FileBytes; voucher._Text = fileInfo.FileName; voucher._Fileextension = DocumentConvert.GetDocumentType(fileInfo.FileExtension); } Utility.ImportVoucher(selectedItem, api, voucher, true); } }; dragDropWindow.Show(); } else #endif Utility.ImportVoucher(selectedItem, api, voucher, false); }
public ActionResult UploadWord() { var files = Request.Form.Files; if (files.Count > 0 && files[0] != null) { var file = files[0]; string fileName = file.FileName; if (fileName != null && !Regex.IsMatch(Path.GetExtension(fileName), "doc|docx")) { return(ResultData(null, false, "文件格式不支持,只能上传doc或者docx的文档!")); } if (fileName != null) { string upload = _hostingEnvironment.WebRootPath + "/upload"; if (!Directory.Exists(upload)) { Directory.CreateDirectory(upload); } string resourceName = string.Empty.CreateShortToken(9); string ext = Path.GetExtension(fileName); string docPath = Path.Combine(upload, resourceName + ext); using (FileStream fs = new FileStream(docPath, FileMode.OpenOrCreate, FileAccess.ReadWrite)) { file.CopyTo(fs); } string htmlDir = docPath.Replace(".docx", "").Replace(".doc", ""); DocumentConvert.Doc2Html(docPath, htmlDir); string htmlfile = Path.Combine(htmlDir, "index.html"); string html = System.IO.File.ReadAllText(htmlfile).ReplaceHtmlImgSource("/upload/" + resourceName).ClearHtml().HtmlSantinizerStandard(); ThreadPool.QueueUserWorkItem(state => System.IO.File.Delete(htmlfile)); if (html.Length < 10) { Directory.Delete(htmlDir, true); System.IO.File.Delete(docPath); return(ResultData(null, false, "读取文件内容失败,请检查文件的完整性,建议另存后重新上传!")); } if (html.Length > 1000000) { Directory.Delete(htmlDir, true); System.IO.File.Delete(docPath); return(ResultData(null, false, "文档内容超长,服务器拒绝接收,请优化文档内容后再尝试重新上传!")); } return(ResultData(new { Title = Path.GetFileNameWithoutExtension(fileName), Content = html, ResourceName = resourceName + ext })); } } return(ResultData(null, false, "请先选择您需要上传的文件!")); }
private CompanyDocumentClient AddLogosToCompanyDocument(byte[] fileBytes, string fileExtension, CompanyDocumentUse documentUseFor) { var companyDoc = new CompanyDocumentClient(); companyDoc.UseFor = documentUseFor; companyDoc.DocumentData = fileBytes; companyDoc.DocumentType = DocumentConvert.GetDocumentType(fileExtension); return(companyDoc); }
void ExportFile(VouchersClient voucher, ZipOutputStream zipOutputStream) { byte[] attachment = voucher.Buffer; voucher._Data = null; voucher._LoadedData = null; if (attachment == null) { if (voucher._Url != null) { try { if (voucher.IsWebUrl) { #if !SILVERLIGHT attachment = new WebClient().DownloadData(voucher._Url); var ext = System.IO.Path.GetExtension(voucher._Url); if (ext != null) { voucher._Fileextension = DocumentConvert.GetDocumentType(DocumentConvert.GetExtension(ext)); } #endif } else { #if SILVERLIGHT attachment = UtilFunctions.LoadFile(voucher._Url); #else attachment = UtilFunctions.LoadFile(voucher._Url).GetAwaiter().GetResult(); #endif } if (attachment == null) { return; } } catch { return; } } else { return; } } // Write the data to the ZIP file var sb = StringBuilderReuse.Create(voucher._Text).Replace('/', '-').Replace('\\', '-'); sb.Append('_').Append(voucher.RowId).Append('.').Append(Enum.GetName(typeof(FileextensionsTypes), IdObject.get((byte)voucher._Fileextension))); var name = sb.ToStringAndRelease(); zipOutputStream.PutNextEntry(new ZipEntry(name)); zipOutputStream.Write(attachment, 0, attachment.Length); WriteLogLine(string.Format(Uniconta.ClientTools.Localization.lookup("ExportingFile"), name)); }
private void AddVoucher(GLTransClient selectedItem, string actionType) { CWAddVouchers addVouchersDialog = null; #if !SILVERLIGHT if (actionType == "DragDrop") { var dragDropWindow = new UnicontaDragDropWindow(false); dragDropWindow.Closed += delegate { if (dragDropWindow.DialogResult == true) { var vouchersClient = new VouchersClient(); var fileInfo = dragDropWindow.FileInfoList?.SingleOrDefault(); if (fileInfo != null) { vouchersClient._Data = fileInfo.FileBytes; vouchersClient._Text = fileInfo.FileName; vouchersClient._Fileextension = DocumentConvert.GetDocumentType(fileInfo.FileExtension); } addVouchersDialog = new CWAddVouchers(api, vouchersClient, true); } }; dragDropWindow.Show(); } else #endif addVouchersDialog = new CWAddVouchers(api, false, null); if (addVouchersDialog == null) { return; } addVouchersDialog.Closed += delegate { if (addVouchersDialog.DialogResult == true) { if (addVouchersDialog.VoucherRowIds.Length > 0 && addVouchersDialog.vouchersClient != null) { SaveAttachment(selectedItem, addVouchersDialog.vouchersClient); } } }; addVouchersDialog.Show(); }
void AttachDocuments() { if (fileBrowser == null) { fileBrowser = new FileBrowseControl(); } else { fileBrowser.SelectedFileInfos = null; } fileBrowser.IsMultiSelect = true; fileBrowser.BrowseFile(); var fileList = fileBrowser.SelectedFileInfos; if (fileList != null) { if (documents == null) { documents = new List <TableAddOnData>(); } foreach (var file in fileList) { documents.Add(new TableAddOnData { _Text = System.IO.Path.GetFileNameWithoutExtension(file.FileName), _DocumentType = DocumentConvert.GetDocumentType(file.FileExtension), _Data = file.FileBytes }); } } if (documents?.Count > 0) { var rb = (RibbonBase)localMenu.DataContext; attachDocMenu = UtilDisplay.GetMenuCommandByName(rb, "AttachDoc"); attachDocMenu.Caption = string.Format("{0} ({1})", string.Format(Uniconta.ClientTools.Localization.lookup("AttachOBJ"), Uniconta.ClientTools.Localization.lookup("Documents")), documents.Count); } }
private bool ValidateSave() { bool isSucess = false; #if !SILVERLIGHT if (browseControl?.FileName == null && !string.IsNullOrEmpty(voucherClientRow._Url)) { isSucess = true; var url = voucherClientRow._Url; var fileExt = voucherClientRow._Fileextension; var fileName = voucherClientRow._Text; if (!isFileExtManualSet) { if (url.StartsWith("http", StringComparison.OrdinalIgnoreCase) || url.StartsWith("www", StringComparison.OrdinalIgnoreCase)) { int indexOfExtention = voucherClientRow._Url.LastIndexOf('.'); var ext = DocumentConvert.GetDocumentType(url.Substring(indexOfExtention, url.Length - indexOfExtention)); fileExt = ext != FileextensionsTypes.UNK ? ext : FileextensionsTypes.WWW; } else if (!Utility.TryParseUrl(url, false, ref fileName, ref fileExt)) { isSucess = false; return(isSucess); } } voucherClientRow._Fileextension = fileExt; voucherClientRow._Text = fileName; return(isSucess); } #endif if (browseControl.IsMultiSelect) { #if SILVERLIGHT var lst = browseControl.SelectedFileInfos; #else var lst = browseControl.Split ? browseControl.LoadFileInfosBySplittingPDF() : browseControl.SelectedFileInfos; #endif if (lst == null && string.IsNullOrEmpty(voucherClientRow.Url)) { return(false); } var fileCount = lst.Count(); if (fileCount > 0) { multiVouchers = new VouchersClient[fileCount]; var iCtr = 0; foreach (var fileInfo in lst) { if (fileInfo == null) { continue; } var vc = Activator.CreateInstance(voucherClientRow.GetType()) as VouchersClient; vc.SetMaster(api.CompanyEntity); multiVouchers[iCtr++] = vc; vc._Fileextension = DocumentConvert.GetDocumentType(fileInfo.FileExtension); #if !SILVERLIGHT if (chkIncludeOnlyReference.IsChecked == true) { vc._Url = fileInfo.FilePath; } else #endif vc._Data = fileInfo.FileBytes; var text = txedVoucherComments.Text; if (string.IsNullOrEmpty(text)) { text = fileInfo.FileName; if (text != null) { // remove extension var ext = vc._Fileextension.ToString(); if (text.EndsWith(ext, StringComparison.CurrentCultureIgnoreCase)) { var len = text.Length - ext.Length - 1; // remove the . if (len > 0) { text = text.Substring(0, len); } } text = text.Replace('_', ' ').Trim(); } } vc._Text = text; FillVoucherInfo(vc); } isSucess = true; } } else { string fileExtension = browseControl.FileExtension; byte[] fileBytes = browseControl.FileBytes; if (fileBytes != null) { #if !SILVERLIGHT if (chkIncludeOnlyReference.IsChecked == true) { voucherClientRow.Url = browseControl.FilePath; } else #endif voucherClientRow._Data = fileBytes; voucherClientRow.Fileextension = DocumentConvert.GetDocumentType(fileExtension); } else if (!string.IsNullOrEmpty(voucherClientRow.Url)) { isSucess = true; } FillVoucherInfo(voucherClientRow); voucherClientRow.Text = ValidateComment(txedVoucherComments.Text); } return(isSucess); }
private bool ValidateSave() { bool isSucess = false; string fileExtension = browseControl.FileExtension; byte[] fileBytes = browseControl.FileBytes; if (fileBytes != null) { #if !SILVERLIGHT try { var img = System.Drawing.Image.FromStream(new MemoryStream(fileBytes)); } catch (Exception) { fileBytes = null; } #else string[] validExtensions = { "jpg", "bmp", "jpeg", "png" }; if (!string.IsNullOrEmpty(fileExtension) && !validExtensions.Contains(fileExtension)) { fileBytes = null; } #endif } if (cmbDocumentUse.SelectedItemValue == null) { UnicontaMessageBox.Show(string.Format("{0}: {1}", Uniconta.ClientTools.Localization.lookup("CompanyDocumentUse"), Uniconta.ClientTools.Localization.lookup("FieldHasinvalidValue")), Uniconta.ClientTools.Localization.lookup("Error")); isSucess = false; return(isSucess); } //Adding a new Record if (LoadedRow == null) { if (fileBytes != null) { companyDocumentClientRow.DocumentData = fileBytes; companyDocumentClientRow.DocumentUseFor = Convert.ToString(cmbDocumentUse.SelectedItemValue); companyDocumentClientRow.DocumentType = DocumentConvert.GetDocumentType(fileExtension); isSucess = true; } } else //editing a Record { if (fileBytes != null) { companyDocumentClientRow.DocumentData = fileBytes; companyDocumentClientRow.DocumentType = DocumentConvert.GetDocumentType(fileExtension); } isSucess = true; } if (companyDocumentClientRow.UseFor == CompanyDocumentUse.TopBarLogo) { if (fileBytes != null && fileBytes.Length > 100 * 1024) { isSucess = false; UnicontaMessageBox.Show(string.Format("{0} ({1})", Uniconta.ClientTools.Localization.lookup("MaxFileSizeLimit"), "100KB"), Uniconta.ClientTools.Localization.lookup("Error")); } } return(isSucess); }
public ActionResult UploadWord() { var files = Request.Files; if (files.Count > 0 && files[0] != null) { HttpPostedFileBase file = files[0]; string fileName = file.FileName; if (fileName != null && !Regex.IsMatch(Path.GetExtension(fileName), @"doc|docx")) { return(ResultData(null, false, "文件格式不支持,只能上传doc或者docx的文档!")); } if (fileName != null) { string upload = Request.MapPath("/upload"); if (!Directory.Exists(upload)) { Directory.CreateDirectory(upload); } string resourceName = string.Empty.CreateShortToken(9); string ext = Path.GetExtension(fileName); string docPath = Path.Combine(upload, resourceName + ext); file.SaveAs(docPath); string htmlDir = docPath.Replace(".docx", "").Replace(".doc", ""); DocumentConvert.Doc2Html(docPath, htmlDir); string htmlfile = Path.Combine(htmlDir, "index.html"); string html = System.IO.File.ReadAllText(htmlfile).ReplaceHtmlImgSource("/upload/" + resourceName).ClearHtml().HtmlSantinizerStandard(); MatchCollection matches = Regex.Matches(html, "<img.+?src=\"(.+?)\".+?>"); foreach (Match m in matches) { string src = m.Groups[1].Value; var(url, success) = CommonHelper.UploadImage(Server.MapPath(src)); if (success) { html = html.Replace(src, url); BackgroundJob.Enqueue(() => System.IO.File.Delete(Server.MapPath(src))); } } ThreadPool.QueueUserWorkItem(state => System.IO.File.Delete(htmlfile)); if (html.Length < 10) { Directory.Delete(htmlDir, true); System.IO.File.Delete(docPath); return(ResultData(null, false, "读取文件内容失败,请检查文件的完整性,建议另存后重新上传!")); } if (html.Length > 1000000) { Directory.Delete(htmlDir, true); System.IO.File.Delete(docPath); return(ResultData(null, false, "文档内容超长,服务器拒绝接收,请优化文档内容后再尝试重新上传!")); } return(ResultData(new { Title = Path.GetFileNameWithoutExtension(fileName), Content = html, ResourceName = resourceName + ext })); } } return(ResultData(null, false, "请先选择您需要上传的文件!")); }
private void frmRibbon_OnItemClicked(string ActionType) { if (ActionType == "Save") { if (!ValidateSave()) { Uniconta.ClientTools.Controls.UnicontaMessageBox.Show(Uniconta.ClientTools.Localization.lookup("NoFilesSelected"), Uniconta.ClientTools.Localization.lookup("Warning")); } else { #if !SILVERLIGHT if (!string.IsNullOrEmpty(browseControl?.FileName) && !(bool)chkIncludeOnlyReference.IsChecked) #else if (!string.IsNullOrEmpty(browseControl?.FileName)) #endif { int indexOfExtention = browseControl.FileName.IndexOf('.'); var nameOfFile = indexOfExtention > 0 ? browseControl.FileName.Substring(0, indexOfExtention) : browseControl.FileName; userDocsClientRow.DocumentType = DocumentConvert.GetDocumentType(browseControl.FileExtension); userDocsClientRow.Text = string.IsNullOrWhiteSpace(txedUserDocNotes.Text) ? nameOfFile : txedUserDocNotes.Text; userDocsClientRow._Url = null; } else if (!string.IsNullOrWhiteSpace(userDocsClientRow._Url)) { string fileName = txedUserDocNotes.Text; FileextensionsTypes fileExt = userDocsClientRow._DocumentType; if (!isFileExtManualSet) { var url = userDocsClientRow._Url; #if !SILVERLIGHT if (url.StartsWith("http", StringComparison.OrdinalIgnoreCase) || url.StartsWith("www", StringComparison.OrdinalIgnoreCase)) { int idxExtension = url.LastIndexOf('.'); var ext = DocumentConvert.GetDocumentType(url.Substring(idxExtension, url.Length - idxExtension)); fileExt = ext != FileextensionsTypes.UNK ? ext : FileextensionsTypes.WWW; } else #endif if (!Utility.TryParseUrl(url, isFieldsAvailableForEdit, ref fileName, ref fileExt)) { return; } } /* only updating if different */ if (userDocsClientRow.DocumentType != fileExt) { userDocsClientRow.DocumentType = fileExt; } userDocsClientRow.Text = fileName; } else { userDocsClientRow.Text = txedUserDocNotes.Text; } #if !SILVERLIGHT txtUrl.LostFocus -= txtUrl_LostFocus; #endif saveForm(); } } else { if (ActionType == "Delete") { api.CompanyEntity.AttachmentCacheDelete(userDocsClientRow); } frmRibbon_BaseActions(ActionType); } }