コード例 #1
0
        public async override Task InitQuery()
        {
            await dgVouchersGrid.Filter(null);

            var defaultFilterString = "Contains([Envelope],'false')";

            dgVouchersGrid.FilterString    = defaultFilterString;
            dgVoucherFolderGrid.Visibility = Visibility.Visible;
            removedRowIds = new List <int>();

            switch (envelopeAction)
            {
            case "Create":
                dgVouchersGrid.Visibility = Visibility.Visible;
                break;

            case "Edit":
                var dapi  = new DocumentAPI(api);
                var items = (VouchersClient[])await dapi.GetEnvelopeContent(voucherClient, false);

                dgVoucherFolderGrid.ItemsSource = items.ToList();     // we need to do a toList, so we can update the list
                var rowIds = items.Select(p => p.RowId).ToList();
                if (rowIds.Count > 0)
                {
                    dgVouchersGrid.FilterString = GetFilterString(defaultFilterString, rowIds);
                }
                dgVouchersGrid.Visibility = Visibility.Visible;
                break;
            }
        }
コード例 #2
0
 void InitPage()
 {
     InitializeComponent();
     localMenu.dataGrid                 = dgVoucherApproveGrid;
     dgVoucherApproveGrid.api           = api;
     dgVoucherApproveGrid.BusyIndicator = busyIndicator;
     SetRibbonControl(localMenu, dgVoucherApproveGrid);
     localMenu.OnItemClicked += localMenu_OnItemClicked;
     docApi = new DocumentAPI(api);
     if (api.CompanyEntity != null && !api.CompanyEntity.Project)
     {
         Project.Visible    = Project.ShowInColumnChooser = false;
         PrCategory.Visible = PrCategory.ShowInColumnChooser = false;
     }
 }
コード例 #3
0
        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("&nbsp;", 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("&nbsp;", 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;
        }
コード例 #4
0
        async private void _LoadInitMaster(UnicontaBaseEntity corasauMaster, VouchersClient voucherClient, int RowId, bool setFocus)
        {
            try
            {
                if (voucherClient == null)
                {
                    if (RowId != 0)
                    {
                        voucherClient = new VouchersClient();
                        voucherClient.SelectRowId(RowId);
                        // we will now enter api.read
                    }
                    else
                    {
                        busyIndicator.IsBusy = true;
                        var voucher = await api.Query <VouchersClient>(corasauMaster);

                        voucherClient = voucher?.FirstOrDefault();
                        if (voucherClient?._Data != null)
                        {
                            VoucherCache.SetGlobalVoucherCache(voucherClient);
                        }
                    }
                }

                if (voucherClient._Data == null)
                {
                    busyIndicator.IsBusy = true;
                    var result = await UtilDisplay.GetData(voucherClient, api);

                    if (result != 0)
                    {
                        busyIndicator.IsBusy = false;
                        UtilDisplay.ShowErrorCode(result);
                        return;
                    }
                }

                this.documentViewer.Children.Clear();

                brdMetaInfo.Visibility = Visibility.Visible;
                if (voucherClient._Envelope)
                {
                    btnPrev.IsEnabled    = false;
                    busyIndicator.IsBusy = true;
                    var dapi = new DocumentAPI(api);
                    envelopes = (VouchersClient[])await dapi.GetEnvelopeContent(voucherClient, true);

                    gridPrevNext.Visibility = Visibility.Visible;
                    if (envelopes != null && envelopes.Length > 0)
                    {
                        totalBlk.Text = NumberConvert.ToString(envelopes.Length);
                        MoveToVoucherAtIndex(selectedIndex, setFocus);

                        /*
                         * currentBlk.Text = NumberConvert.ToString(selectedIndex + 1);
                         * var doc = envelopes[selectedIndex];
                         * this.documentViewer.Children.Add(UtilDisplay.LoadControl(doc.Buffer, doc._Fileextension, false, setFocus));
                         */
                    }
                    else
                    {
                        totalBlk.Text   = "0";
                        currentBlk.Text = "0";
                    }
                    busyIndicator.IsBusy = false;
                }
                else
                {
                    busyIndicator.IsBusy = false;
                    this.documentViewer.Children.Add(UtilDisplay.LoadControl(voucherClient, false, setFocus));
                }
            }
            catch (Exception ex)
            {
                brdMetaInfo.Visibility = Visibility.Visible;
                this.documentViewer.Children.Add((UtilDisplay.LoadDefaultControl(string.Format("{0}. {1} : {2}", Uniconta.ClientTools.Localization.lookup("InvalidDocSave"),
                                                                                               Uniconta.ClientTools.Localization.lookup("ViewerFailed"), ex.Message))));
                busyIndicator.IsBusy = false;
            }
            SetMetaInfo(voucherClient);
        }
コード例 #5
0
        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("&nbsp;", 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;
        }
コード例 #6
0
        async private void Save()
        {
            var result      = false;
            var documentApi = new DocumentAPI(api);

            try
            {
                switch (action)
                {
                case "Create":
                    var newlist = (IEnumerable <VouchersClient>)dgVoucherFolderGrid.ItemsSource;
                    if (newlist != null)
                    {
                        CWCreateFolder createFolderDialog = new CWCreateFolder();
                        createFolderDialog.Closing += async delegate
                        {
                            if (createFolderDialog.DialogResult == true)
                            {
                                voucherClient.Text    = createFolderDialog.FolderName;
                                voucherClient.Content = createFolderDialog.ContentType;
                                var createResult = await documentApi.CreateEnvelope(voucherClient, newlist);

                                // Folder now contains a full record with the content.
                                if (createResult == ErrorCodes.Succes)
                                {
                                    globalEvents.OnRefresh(TabControls.VoucherFolderPage);
                                    CloseDockItem();
                                }
                                else
                                {
                                    UtilDisplay.ShowErrorCode(ErrorCodes.CouldNotSave);
                                }
                            }
                        };
                        result = true;
                        createFolderDialog.Show();
                    }
                    break;

                case "Edit":

                    //Removing the Items
                    if (removedRowIds.Count > 0)
                    {
                        var allVouchers = (IEnumerable <VoucherExtendedClient>)dgVouchersGrid.ItemsSource;
                        var listRemove  = new List <VouchersClient>();
                        foreach (var id in removedRowIds)
                        {
                            var tempVoucher = allVouchers.Where(r => r.RowId == id).SingleOrDefault();
                            if (tempVoucher != null)
                            {
                                listRemove.Add(tempVoucher);
                            }
                        }

                        var removeResult = await documentApi.RemoveFromEnvelope(voucherClient, listRemove);

                        result = (removeResult == ErrorCodes.Succes);
                    }

                    //Adding the Items

                    var appendList = (IEnumerable <VouchersClient>)dgVoucherFolderGrid.ItemsSource;
                    if (appendList != null)
                    {
                        var appendResult = await documentApi.AppendToEnvelope(voucherClient, appendList);

                        result = (appendResult == ErrorCodes.Succes);
                    }

                    break;
                }
            }
            catch (Exception ex)
            {
                documentApi.ReportException(ex, "Envelopes, Action=" + action);
                result = false;
            }
            if (action != "Create")
            {
                if (result)
                {
                    CloseDockItem();
                }
                else
                {
                    UtilDisplay.ShowErrorCode(ErrorCodes.CouldNotSave);
                }
            }
        }