private void browseControl_FileSelected() { browseUrl = browseControl.FilePath; if (chkIncludeOnlyReference.IsChecked == true && !string.IsNullOrEmpty(browseUrl)) { userDocsClientRow.Url = browseUrl; string fileName = txedUserDocNotes.Text; FileextensionsTypes fileExt = userDocsClientRow._DocumentType; if (Utility.TryParseUrl(browseUrl, isFieldsAvailableForEdit, ref fileName, ref fileExt)) { userDocsClientRow.DocumentType = fileExt; } } }
public static void ViewInProgram(byte[] voucherData, FileextensionsTypes voucherExtension) { if (voucherData == null || voucherData.Length == 0) { return; } string fileName = System.IO.Path.GetTempFileName() + "." + voucherExtension; using (FileStream fs = new FileStream(fileName, FileMode.Create, FileAccess.Write, FileShare.None)) { fs.Write(voucherData, 0, voucherData.Length); fs.Flush(); fs.Close(); } #if SILVERLIGHT //for OOB try { if (Application.Current.IsRunningOutOfBrowser) { var shell = AutomationFactory.CreateObject("Shell.Application"); shell.ShellExecute(fileName, null, null, null, 1); } } catch (Exception ex) { BasePage.session.ReportException(ex, "VoucherPage3_OOB", 0); } #endif #if !SILVERLIGHT try { Process process = new Process(); process.StartInfo.FileName = fileName; process.StartInfo.UseShellExecute = true; process.Start(); } catch (Exception excp) { BasePage.session.ReportException(excp, "VoucherPage3", 0); } #endif }
public int ImportEmailBilag() { MimeMessage message; int antalbilag = 0; clsParam objParam = null; using (var imap_client = new ImapClient()) { imap_client.Connect("outlook.office365.com", 993, true); imap_client.AuthenticationMechanisms.Remove("XOAUTH"); imap_client.Authenticate(clsApp.ImapUser, clsApp.ImapPW); var HafsjoldDataBilag = imap_client.GetFolder("_HafsjoldDataBilag"); var HafsjoldDataBilagArkiv = imap_client.GetFolder("_HafsjoldDataBilagArkiv"); HafsjoldDataBilag.Open(FolderAccess.ReadWrite); var results = HafsjoldDataBilag.Search(SearchQuery.All); antalbilag = results.Count(); foreach (var result in results) { message = HafsjoldDataBilag.GetMessage(result); MemoryStream msMail = new MemoryStream(); message.WriteTo(msMail); List <VouchersClient> documents = new List <VouchersClient>(); VouchersClient mail = new VouchersClient() { Fileextension = FileextensionsTypes.EML, Text = "e-Mail", VoucherAttachment = msMail.ToArray(), DocumentDate = DateTime.Now, }; var task1 = m_api.Insert(mail); task1.Wait(); var res1 = task1.Result; documents.Add(mail); foreach (var msg_attachment in message.Attachments) { if (msg_attachment is MimePart) { var bSaveAttachment = true; FileextensionsTypes type = FileextensionsTypes.PDF; switch (msg_attachment.ContentType.MediaSubtype.ToUpper()) { case "PDF": type = FileextensionsTypes.PDF; break; case "JPEG": type = FileextensionsTypes.JPEG; break; case "TXT": type = FileextensionsTypes.TXT; break; case "PLAIN": type = FileextensionsTypes.TXT; break; case "MSWORD": type = FileextensionsTypes.DOC; break; case "VND.OPENXMLFORMATS-OFFICEDOCUMENT.SPREADSHEETML.SHEET": type = FileextensionsTypes.XLSX; break; default: type = FileextensionsTypes.UNK; break; } var part = (MimePart)msg_attachment; MemoryStream msstream = new MemoryStream(); part.Content.DecodeTo(msstream); byte[] arrStream = msstream.ToArray(); if (type == FileextensionsTypes.UNK) { if (arrStream[0] == 0x25 && arrStream[1] == 0x50 && arrStream[2] == 0x44 && arrStream[3] == 0x46) // PDF Magic number { type = FileextensionsTypes.PDF; } else if (Path.GetExtension(part.FileName.ToUpper()) == ".MSG") { type = FileextensionsTypes.MSG; using (var msg = new MsgReader.Outlook.Storage.Message(msstream)) { var MessageBody = msg.BodyText; var msgtext = Regex.Replace(MessageBody, "<[^>]*>", String.Empty).Replace(" ", String.Empty).Trim(); string[] splitstring = { "\r\n" }; string[] arrParams = msgtext.Split(splitstring, StringSplitOptions.RemoveEmptyEntries); objParam = new clsParam(arrParams); } bSaveAttachment = false; } } if (bSaveAttachment) { VouchersClient attm = new VouchersClient() { Fileextension = type, Text = (msg_attachment as MimePart).FileName, VoucherAttachment = arrStream, DocumentDate = DateTime.Now, }; var task3 = m_api.Insert(attm); task3.Wait(); var res3 = task3.Result; documents.Add(attm); } } else if (msg_attachment is MessagePart) { var msgpart = msg_attachment as MessagePart; var MessageBody = msgpart.Message.HtmlBody; if (string.IsNullOrEmpty(MessageBody)) { MessageBody = msgpart.Message.TextBody; } var msgtext = Regex.Replace(MessageBody, "<[^>]*>", String.Empty).Replace(" ", String.Empty).Trim(); string[] splitstring = { "\r\n" }; string[] arrParams = msgtext.Split(splitstring, StringSplitOptions.RemoveEmptyEntries); objParam = new clsParam(arrParams); } } if (documents.Count > 0) { VouchersClient folder = new VouchersClient() { _Fileextension = FileextensionsTypes.DIR, _Text = message.Subject, _DocumentDate = DateTime.Now, }; var ref3 = folder.PrimaryKeyId; var task4 = m_api.Insert(folder); task4.Wait(); var res4 = task4.Result; var ref1 = folder.PrimaryKeyId; DocumentAPI docapi = new DocumentAPI(m_api); var task5 = docapi.CreateFolder(folder, documents); task5.Wait(); var res5 = task5.Result; var ref2 = folder.PrimaryKeyId; int DocumentRef = ref2; if (ref1 != ref2) //Delete ref1 { var crit = new List <PropValuePair>(); var pair = PropValuePair.GenereteWhereElements("PrimaryKeyId", typeof(int), ref1.ToString()); crit.Add(pair); var task6 = m_api.Query <VouchersClient>(crit); task6.Wait(); var col = task6.Result; if (col.Count() == 1) { var rec = col[0]; m_api.DeleteNoResponse(rec); } } if (objParam == null) { objParam = new clsParam() { Delsystem = "Finans", Tekst = "Ukendt post", Kontotype = "Finans", Konto = "5820", Modkontotype = "Finans", Modkonto = "9900", Kredit = 0.00 }; } switch (objParam.Delsystem.ToLower()) { case "finans": InsertFinansJournal(message, DocumentRef, objParam); break; case "kreditor": InsertKøbsOrder(message, DocumentRef, objParam); break; default: break; } // move email to arkiv var newId = HafsjoldDataBilag.MoveTo(result, HafsjoldDataBilagArkiv); } } HafsjoldDataBilag.Close(); imap_client.Disconnect(true); } return(antalbilag);// message; }
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); } }
public int ImportEmailBilag() { MimeMessage message; int antalbilag = 0; clsParam objParam = null; using (var imap_client = new ImapClient()) { imap_client.Connect("imap.gigahost.dk", 993, true); imap_client.AuthenticationMechanisms.Remove("XOAUTH"); imap_client.Authenticate(clsApp.GigaHostImapUser, clsApp.GigaHostImapPW); var Puls3060Bilag = imap_client.GetFolder("_Puls3060Bilag"); var Puls3060BilagArkiv = imap_client.GetFolder("_Puls3060BilagArkiv"); Puls3060Bilag.Open(FolderAccess.ReadWrite); var results = Puls3060Bilag.Search(SearchQuery.All); antalbilag = results.Count(); foreach (var result in results) { message = Puls3060Bilag.GetMessage(result); List <VouchersClient> documentlist = new List <VouchersClient>(); if (message.Body.ContentType.MimeType == "application/ms-tnef") { antalbilag--; continue; } MemoryStream msMail = new MemoryStream(); message.WriteTo(msMail); VouchersClient mail = new VouchersClient() { Fileextension = FileextensionsTypes.EML, Text = "e-Mail", VoucherAttachment = msMail.ToArray(), DocumentDate = DateTime.Now, }; var task1 = m_api.Insert(mail); task1.Wait(); var res1 = task1.Result; documentlist.Add(mail); foreach (var msg_attachment in message.Attachments) { if (msg_attachment is MimePart) { FileextensionsTypes type = FileextensionsTypes.PDF; switch (msg_attachment.ContentType.MediaSubtype.ToUpper()) { case "PDF": type = FileextensionsTypes.PDF; break; case "JPEG": type = FileextensionsTypes.JPEG; break; case "TXT": type = FileextensionsTypes.TXT; break; case "PLAIN": type = FileextensionsTypes.TXT; break; case "MSWORD": type = FileextensionsTypes.DOC; break; case "VND.OPENXMLFORMATS-OFFICEDOCUMENT.SPREADSHEETML.SHEET": type = FileextensionsTypes.XLSX; break; default: type = FileextensionsTypes.UNK; break; } var part = (MimePart)msg_attachment; MemoryStream msstream = new MemoryStream(); part.ContentObject.DecodeTo(msstream); byte[] arrStream = msstream.ToArray(); if (type == FileextensionsTypes.UNK) { if (arrStream[0] == 0x25 && arrStream[1] == 0x50 && arrStream[2] == 0x44 && arrStream[3] == 0x46) // PDF Magic number { type = FileextensionsTypes.PDF; } } VouchersClient attm = new VouchersClient() { Fileextension = type, Text = (msg_attachment as MimePart).FileName, VoucherAttachment = arrStream, DocumentDate = DateTime.Now, }; var task3 = m_api.Insert(attm); task3.Wait(); var res3 = task3.Result; documentlist.Add(attm); } else if (msg_attachment is MessagePart) { string wmsgtext; var msgpart = msg_attachment as MessagePart; if (string.IsNullOrEmpty(msgpart.Message.HtmlBody)) { wmsgtext = msgpart.Message.TextBody; } else { wmsgtext = msgpart.Message.HtmlBody; } var msgtext = Regex.Replace(wmsgtext, "<[^>]*>", String.Empty).Replace(" ", String.Empty).Trim(); string[] splitstring = { "\r\n" }; string[] arrParams = msgtext.Split(splitstring, StringSplitOptions.RemoveEmptyEntries); objParam = new clsParam(arrParams); } } if (documentlist.Count > 0) { VouchersClient folder = new VouchersClient() { _Fileextension = FileextensionsTypes.DIR, _Text = message.Subject, _DocumentDate = DateTime.Now }; var ref3 = folder.PrimaryKeyId; var task4 = m_api.Insert(folder); task4.Wait(); var res4 = task4.Result; var ref1 = folder.PrimaryKeyId; DocumentAPI docapi = new DocumentAPI(m_api); var task5 = docapi.CreateFolder(folder, documentlist); task5.Wait(); var res5 = task5.Result; var ref2 = folder.PrimaryKeyId; //*********************** folder.PostingInstruction = "Puls3060Import"; var taskUpdateFolder = m_api.Update(folder); taskUpdateFolder.Wait(); var Err = taskUpdateFolder.Result; //*********************** int DocumentRef = ref2; if (ref1 != ref2) //Delete ref1 { var crit = new List <PropValuePair>(); var pair = PropValuePair.GenereteWhereElements("PrimaryKeyId", typeof(int), ref1.ToString()); crit.Add(pair); var task6 = m_api.Query <VouchersClient>(crit); task6.Wait(); var col = task6.Result; if (col.Count() == 1) { var rec = col[0]; m_api.DeleteNoResponse(rec); } } //*************************************************************** /* * if (objParam == null) * { * objParam = new clsParam() * { * Delsystem = "Kreditor", * Tekst = "Ukendt post", * Kontotype = "Kreditor", * Konto = "100000", * Modkontotype = "Finans", * Modkonto = "9900", * Kredit = 0.00 * }; * } * * switch (objParam.Delsystem.ToLower()) * { * case "finans": * InsertFinansJournal(message, DocumentRef, objParam); * break; * * case "kreditor": * InsertKøbsOrder(message, DocumentRef, objParam); * break; * * default: * break; * } */ //*************************************************************** // move email to arkiv var newId = Puls3060Bilag.MoveTo(result, Puls3060BilagArkiv); } } Puls3060Bilag.Close(); imap_client.Disconnect(true); } return(antalbilag);// message; }