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); }
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); }
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); } }