private void dgDocsGrid_DropRecord(object sender, DevExpress.Xpf.Core.DropRecordEventArgs e)
        {
            dgDocsGrid.tableView.FocusedRowHandle = e.TargetRowHandle > 0 ? e.TargetRowHandle - 1 : -1;
            string[] errors = null;

            if (e.Data.GetDataPresent(DataFormats.FileDrop))
            {
                var files = e.Data.GetData(DataFormats.FileDrop) as string[];
                if (files == null || files.Length == 0)
                {
                    return;
                }

                errors = Utility.DropFilesToGrid(dgDocsGrid, files, false);
            }
            else if (e.Data.GetDataPresent("FileGroupDescriptor"))
            {
                errors = Utility.DropOutlookMailsToGrid(dgDocsGrid, e.Data, false);
            }

            if (errors != null && errors.Length > 0)
            {
                var cwErrorBox = new CWErrorBox(errors, true);
                cwErrorBox.Show();
            }
        }
Esempio n. 2
0
        void SendInvoice(IEnumerable <CreditorInvoiceLocal> invoiceEmails)
        {
            int icount = invoiceEmails.Count();

            UnicontaClient.Pages.CWSendInvoice cwSendInvoice = new UnicontaClient.Pages.CWSendInvoice();
#if !SILVERLIGHT
            cwSendInvoice.DialogTableId = 2000000063;
#endif
            cwSendInvoice.Closed += async delegate
            {
                if (cwSendInvoice.DialogResult == true)
                {
                    busyIndicator.IsBusy      = true;
                    busyIndicator.BusyContent = Uniconta.ClientTools.Localization.lookup("SendingWait");
                    InvoiceAPI    Invapi = new InvoiceAPI(api);
                    List <string> errors = new List <string>();

                    var sendInBackgroundOnly = CWSendInvoice.sendInBackgroundOnly;
                    foreach (var inv in invoiceEmails)
                    {
                        var errorCode = await Invapi.SendInvoice(inv, cwSendInvoice.Emails, cwSendInvoice.sendOnlyToThisEmail, sendInBackgroundOnly);

                        sendInBackgroundOnly = true;
                        if (errorCode != ErrorCodes.Succes)
                        {
                            var standardError = await api.session.GetErrors(errorCode);

                            var stformattedErr = UtilDisplay.GetFormattedErrorCode(errorCode, standardError);
                            var errorStr       = string.Format("{0}({1}): \n{2}", Uniconta.ClientTools.Localization.lookup("InvoiceNumber"), inv.InvoiceNum,
                                                               Uniconta.ClientTools.Localization.lookup(stformattedErr));
                            errors.Add(errorStr);
                        }
                    }

                    busyIndicator.IsBusy = false;
                    if (errors.Count == 0)
                    {
                        UnicontaMessageBox.Show(string.Format(Uniconta.ClientTools.Localization.lookup("SendEmailMsgOBJ"), icount == 1 ? Uniconta.ClientTools.Localization.lookup("Invoice") :
                                                              Uniconta.ClientTools.Localization.lookup("Invoices")), Uniconta.ClientTools.Localization.lookup("Message"));
                    }
                    else
                    {
                        CWErrorBox errorDialog = new CWErrorBox(errors.ToArray(), true);
                        errorDialog.Show();
                    }
                }
            };
            cwSendInvoice.Show();
        }
        /// <summary>
        /// Loads Voucher page2 with the files dropped
        /// </summary>
        /// <param name="filePaths"></param>
        public void LoadPageOnFileDrop(string[] filePaths)
        {
            browseControl.Visibility = Visibility.Collapsed;
            try
            {
                List <string> failedFiles = null;
                var           fileInfos   = UtilDisplay.CreateSelectedFileInfo(filePaths, out failedFiles);
                if (failedFiles != null && failedFiles.Count > 0)
                {
                    var cwErrorBox = new CWErrorBox(failedFiles.ToArray(), true);
                    cwErrorBox.Show();
                }

                txedVoucherComments.Text        = fileInfos.Length > 1 ? string.Empty : fileInfos.SingleOrDefault()?.FileName;
                browseControl.SelectedFileInfos = fileInfos.Length > 0 ? fileInfos : null;
            }
            catch (Exception ex)
            {
                UnicontaMessageBox.Show(string.Format(Uniconta.ClientTools.Localization.lookup("FileError"), ex.Message), Uniconta.ClientTools.Localization.lookup("Exception"));
            }
        }
Esempio n. 4
0
        private bool ValidatePayments(IEnumerable <DebtorTransDirectDebit> queryPaymentTrans, bool paymentMerged, DebtorPaymentFormat debPaymFormat, bool validateOnly = false, bool skipPrevalidate = false)
        {
            var paymentHelper = Common.DirectPaymentHelperInstance(debPaymFormat);

            paymentHelper.DirectDebitId = debPaymFormat._CredDirectDebitId;

            if (skipPrevalidate == false)
            {
                var preValErrors = new List <DirectPaymentError>();
                paymentHelper.PreValidate(api.CompanyEntity, BankAccountCache, JournalCache, debPaymFormat, out preValErrors);

                if (preValErrors.Count() > 0)
                {
                    var preErrors = new List <string>();
                    foreach (DirectPaymentError error in preValErrors)
                    {
                        preErrors.Add(error.Message);
                    }

                    if (preErrors.Count() != 0)
                    {
                        CWErrorBox cwError = new CWErrorBox(preErrors.ToArray());
                        cwError.Show();
                        return(false);
                    }
                }
            }

            var valErrors = new List <DirectPaymentError>();

            paymentHelper.ValidatePayments(api.CompanyEntity, queryPaymentTrans, debPaymFormat, MandateCache, paymentMerged, out valErrors);

            foreach (var rec in queryPaymentTrans.Where(s => s._PaymentStatus != PaymentStatusLevel.FileSent))
            {
                rec.ErrorInfo = Common.VALIDATE_OK;
            }

            foreach (DirectPaymentError error in valErrors)
            {
                var rec = queryPaymentTrans.Where(s => s.PrimaryKeyId == error.RowId).First();
                if (rec.ErrorInfo == Common.VALIDATE_OK)
                {
                    rec.ErrorInfo = error.Message;
                }
                else
                {
                    rec.ErrorInfo += Environment.NewLine + error.Message;
                }
            }

            if (queryPaymentTrans.Where(s => s.ErrorInfo == Common.VALIDATE_OK).Count() == 0 && validateOnly == false)
            {
                if (doMergePaym == false)
                {
                    UnicontaMessageBox.Show(Uniconta.ClientTools.Localization.lookup("NoRecordSelected"), Uniconta.ClientTools.Localization.lookup("Message"));
                }
                return(false);
            }

            if (validateOnly)
            {
                var countErr = queryPaymentTrans.Where(s => (s.ErrorInfo != Common.VALIDATE_OK) && (s.ErrorInfo != null)).Count();

                if (countErr == 0)
                {
                    UnicontaMessageBox.Show(Uniconta.ClientTools.Localization.lookup("ValidateNoError"), Uniconta.ClientTools.Localization.lookup("Validation"), MessageBoxButton.OK, MessageBoxImage.Information);
                }
                else
                {
                    UnicontaMessageBox.Show(string.Format(Uniconta.ClientTools.Localization.lookup("ValidateFailInLines"), countErr), Uniconta.ClientTools.Localization.lookup("Validation"), MessageBoxButton.OK, MessageBoxImage.Warning);
                }
            }

            return(true);
        }
Esempio n. 5
0
        private void OrderConfirmation(CompanyLayoutType docType)
        {
#if SILVERLIGHT
            confirmOrder = new List <InvoicePostingResult>();
#else
            confirmOrder = new Dictionary <InvoicePostingResult, DebtorOrderClient>();
#endif
            UnicontaClient.Pages.CWGenerateInvoice GenrateInvoiceDialog = new UnicontaClient.Pages.CWGenerateInvoice(false, Uniconta.ClientTools.Localization.lookup(docType.ToString()),
                                                                                                                     isShowInvoiceVisible: true, askForEmail: true, showInputforInvNumber: false, showInvoice: true, isShowUpdateInv: true, isQuickPrintVisible: true, isDebtorOrder: true, isPageCountVisible: false);
#if !SILVERLIGHT
            GenrateInvoiceDialog.DialogTableId = 2000000012;
#endif
            GenrateInvoiceDialog.SetInvPrintPreview(printPreview);
            GenrateInvoiceDialog.Closed += async delegate
            {
                if (GenrateInvoiceDialog.DialogResult == true)
                {
                    printPreview = GenrateInvoiceDialog.ShowInvoice;
                    busyIndicator.BusyContent = Uniconta.ClientTools.Localization.lookup("SendingWait");
                    busyIndicator.IsBusy      = true;
                    var           InvoiceDate    = GenrateInvoiceDialog.GenrateDate;
                    var           updateStatus   = GenrateInvoiceDialog.UpdateInventory;
                    InvoiceAPI    Invapi         = new InvoiceAPI(api);
                    int           cnt            = 0;
                    List <string> errorList      = new List <string>();
                    var           dgOrderVisible = dgMultiInvGrid.GetVisibleRows() as IEnumerable <DebtorOrderClient>;
                    foreach (var dbOrder in dgOrderVisible)
                    {
                        var result = await Invapi.PostInvoice(dbOrder, null, GenrateInvoiceDialog.GenrateDate, 0,
                                                              !updateStatus, new DebtorInvoiceClient(),
                                                              new DebtorInvoiceLines(), GenrateInvoiceDialog.SendByEmail, GenrateInvoiceDialog.ShowInvoice || GenrateInvoiceDialog.InvoiceQuickPrint, docType,
                                                              GenrateInvoiceDialog.Emails, GenrateInvoiceDialog.sendOnlyToThisEmail, null, null, GenrateInvoiceDialog.PostOnlyDelivered);

                        if (result != null && result.Err == 0 && (GenrateInvoiceDialog.ShowInvoice || GenrateInvoiceDialog.InvoiceQuickPrint))
                        {
                            DebtorOrders.Updatedata(dbOrder, docType);

                            var dc = dbOrder.Debtor;
                            if (dc == null)
                            {
                                await api.CompanyEntity.LoadCache(typeof(Debtor), api, true);

                                dc = dbOrder.Debtor;
                            }
                            DebtorOrders.SetDeliveryAdress(result.Header, dc, api);
#if SILVERLIGHT
                            confirmOrder.Add(result);
#else
                            confirmOrder.Add(result, dbOrder);
#endif
                            cnt++;
                        }
                        else
                        {
                            string error = string.Format("{0}:{1}", dbOrder._OrderNumber, Uniconta.ClientTools.Localization.lookup(result.Err.ToString()));
                            errorList.Add(error);
                        }
                    }
                    busyIndicator.IsBusy = false;
                    string updatedMsg = Uniconta.ClientTools.Localization.lookup("Succes");


                    if (!GenrateInvoiceDialog.IsSimulation)
                    {
                        updatedMsg = string.Format(Uniconta.ClientTools.Localization.lookup("RecordsUpdated"), cnt, Uniconta.ClientTools.Localization.lookup("DebtorOrders"));
                    }

                    int documentsPreviewPrint = confirmOrder.Count;
                    updatedMsg = updatedMsg + "\n" + string.Format(Uniconta.ClientTools.Localization.lookup("MulitDocPrintConfirmationMsg"), documentsPreviewPrint,
                                                                   string.Format("{0} {1}", Uniconta.ClientTools.Localization.lookup(docType.ToString()), Uniconta.ClientTools.Localization.lookup("Documents")));

                    if (errorList.Count == 0)
                    {
                        if ((GenrateInvoiceDialog.ShowInvoice || GenrateInvoiceDialog.InvoiceQuickPrint) && confirmOrder.Count > 0)
                        {
                            InitMultiplePreviewDocument(updatedMsg, docType, GenrateInvoiceDialog.InvoiceQuickPrint);
                        }
                    }
                    else
                    {
                        CWErrorBox errorDialog = new CWErrorBox(errorList.ToArray(), true);
                        errorDialog.Closed += delegate
                        {
                            if ((GenrateInvoiceDialog.ShowInvoice || GenrateInvoiceDialog.InvoiceQuickPrint) && confirmOrder.Count > 0)
                            {
                                InitMultiplePreviewDocument(updatedMsg, docType, GenrateInvoiceDialog.InvoiceQuickPrint);
                            }
                        };
                        errorDialog.Show();
                    }
                }
            };
            GenrateInvoiceDialog.Show();
        }
Esempio n. 6
0
        private void GenerateInvoice()
        {
#if SILVERLIGHT
            invoicePosted = new List <InvoicePostingResult>();
#else
            invoicePosted = new Dictionary <InvoicePostingResult, DebtorOrderClient>();
#endif
            UnicontaClient.Pages.CWGenerateInvoice GenrateInvoiceDialog = new UnicontaClient.Pages.CWGenerateInvoice(true, string.Empty, false, true, true, isOrderOrQuickInv: true, isQuickPrintVisible: true, isPageCountVisible: false, isDebtorOrder: true);
#if !SILVERLIGHT
            GenrateInvoiceDialog.DialogTableId = 2000000011;
#endif
            GenrateInvoiceDialog.SetInvPrintPreview(printPreview);
            GenrateInvoiceDialog.Closed += async delegate
            {
                if (GenrateInvoiceDialog.DialogResult == true)
                {
                    printPreview = GenrateInvoiceDialog.ShowInvoice;
                    busyIndicator.BusyContent = Uniconta.ClientTools.Localization.lookup("SendingWait");
                    busyIndicator.IsBusy      = true;
                    var           InvoiceDate     = GenrateInvoiceDialog.GenrateDate;
                    InvoiceAPI    Invapi          = new InvoiceAPI(api);
                    int           cnt             = 0;
                    List <string> errorList       = new List <string>();
                    var           dbVisibleOrders = dgMultiInvGrid.GetVisibleRows() as IEnumerable <DebtorOrderClient>;
                    foreach (var dbOrder in dbVisibleOrders)
                    {
                        if (dbOrder._SubscriptionEnded != DateTime.MinValue && dbOrder._SubscriptionEnded < InvoiceDate)
                        {
                            continue;
                        }

                        var result = await Invapi.PostInvoice(dbOrder, null, InvoiceDate,
                                                              0, GenrateInvoiceDialog.IsSimulation, new DebtorInvoiceClient(),
                                                              new DebtorInvoiceLines(), GenrateInvoiceDialog.SendByEmail, (GenrateInvoiceDialog.ShowInvoice || GenrateInvoiceDialog.InvoiceQuickPrint || GenrateInvoiceDialog.GenerateOIOUBLClicked), 0,
                                                              GenrateInvoiceDialog.Emails, GenrateInvoiceDialog.sendOnlyToThisEmail, null, null, GenrateInvoiceDialog.PostOnlyDelivered);

                        if (result != null && result.Err == 0)
                        {
#if SILVERLIGHT
                            invoicePosted.Add(result);
#else
                            invoicePosted.Add(result, dbOrder);
#endif
                            cnt++;

                            var dc = dbOrder.Debtor;
                            if (dc == null)
                            {
                                await api.CompanyEntity.LoadCache(typeof(Debtor), api, true);

                                dc = dbOrder.Debtor;
                            }

                            DebtorOrders.SetDeliveryAdress(result.Header, dc, api);
                        }
                        else
                        {
                            string error = string.Format("{0}:{1}", dbOrder._OrderNumber, Uniconta.ClientTools.Localization.lookup(result.Err.ToString()));
                            errorList.Add(error);
                        }
                    }

                    busyIndicator.IsBusy = false;
                    string updatedMsg = Uniconta.ClientTools.Localization.lookup("Succes");
                    if (!GenrateInvoiceDialog.IsSimulation)
                    {
                        updatedMsg = string.Format(Uniconta.ClientTools.Localization.lookup("RecordsUpdated"), cnt, Uniconta.ClientTools.Localization.lookup("DebtorOrders"));
                    }

#if !SILVERLIGHT
                    if (GenrateInvoiceDialog.GenerateOIOUBLClicked && !GenrateInvoiceDialog.IsSimulation)
                    {
                        GenerateOIOXmlForAll(errorList, !GenrateInvoiceDialog.SendByEmail);
                    }
#endif
                    int previewInvoiceCount = invoicePosted.Count;
                    updatedMsg = updatedMsg + "\n" + string.Format(Uniconta.ClientTools.Localization.lookup("MulitDocPrintConfirmationMsg"), previewInvoiceCount, Uniconta.ClientTools.Localization.lookup("Invoices"));

                    if (errorList.Count == 0)
                    {
                        if ((GenrateInvoiceDialog.ShowInvoice || GenrateInvoiceDialog.InvoiceQuickPrint) && previewInvoiceCount > 0)
                        {
                            InitMultiplePreviewDocument(updatedMsg, CompanyLayoutType.Invoice, GenrateInvoiceDialog.InvoiceQuickPrint);
                        }
                    }
                    else
                    {
                        CWErrorBox errorDialog = new CWErrorBox(errorList.ToArray(), true);
                        errorDialog.Closed += delegate
                        {
                            if ((GenrateInvoiceDialog.ShowInvoice || GenrateInvoiceDialog.InvoiceQuickPrint) && previewInvoiceCount > 0)
                            {
                                InitMultiplePreviewDocument(updatedMsg, CompanyLayoutType.Invoice, GenrateInvoiceDialog.InvoiceQuickPrint);
                            }
                        };
                        errorDialog.Show();
                    }
                }
            };
            GenrateInvoiceDialog.Show();
        }
Esempio n. 7
0
        private void PickList()
        {
#if SILVERLIGHT
            packListPosted = new List <InvoicePostingResult>();
#else
            packListPosted = new Dictionary <InvoicePostingResult, DebtorOrderClient>();
#endif
            var cwPickingList = new CWGeneratePickingList(false, false);
#if !SILVERLIGHT
            cwPickingList.DialogTableId = 2000000024;
#endif
            cwPickingList.Closed += async delegate
            {
                if (cwPickingList.DialogResult == true)
                {
                    var selectedDate = cwPickingList.SelectedDate;
                    busyIndicator.BusyContent = Uniconta.ClientTools.Localization.lookup("LoadingMsg");
                    busyIndicator.IsBusy      = true;
                    InvoiceAPI Invapi          = new InvoiceAPI(api);
                    int        cnt             = 0;
                    var        errorList       = new List <string>();
                    var        dbVisibleOrders = dgMultiInvGrid.GetVisibleRows() as IEnumerable <DebtorOrderClient>;
                    foreach (var dbOrder in dbVisibleOrders)
                    {
                        var result = await Invapi.PostInvoice(dbOrder, null, selectedDate, 0, false, new DebtorInvoiceClient(), new DebtorInvoiceLines(), false, cwPickingList.ShowDocument || cwPickingList.PrintDocument,
                                                              CompanyLayoutType.PickingList);

                        if (result.Err == ErrorCodes.Succes)
                        {
#if SILVERLIGHT
                            packListPosted.Add(result);
#else
                            packListPosted.Add(result, dbOrder);
#endif
                            cnt++;
                        }
                        else
                        {
                            string error = string.Format("{0}:{1}", dbOrder.OrderNumber, Uniconta.ClientTools.Localization.lookup(result.Err.ToString()));
                            errorList.Add(error);
                        }
                    }
                    busyIndicator.IsBusy = false;

                    int    picklistPreviewCount = packListPosted.Count;
                    string updatedMsg           = string.Format(Uniconta.ClientTools.Localization.lookup("MulitDocPrintConfirmationMsg"), picklistPreviewCount,
                                                                string.Format("{0} {1}", Uniconta.ClientTools.Localization.lookup(CompanyLayoutType.PickingList.ToString()), Uniconta.ClientTools.Localization.lookup("Documents")));

                    if (errorList.Count == 0)
                    {
                        InitMultiplePreviewDocument(updatedMsg, CompanyLayoutType.PickingList, cwPickingList.PrintDocument);
                    }
                    else
                    {
                        CWErrorBox errorDialog = new CWErrorBox(errorList.ToArray(), true);
                        errorDialog.Closed += delegate { InitMultiplePreviewDocument(updatedMsg, CompanyLayoutType.PickingList, cwPickingList.PrintDocument); };
                        errorDialog.Show();
                    }
                }
            };
            cwPickingList.Show();
        }
        private void GenerateInvoice()
        {
#if !SILVERLIGHT
            invoicePosted = new Dictionary <InvoicePostingResult, ProjectClient>();
#elif SILVERLIGHT
            invoicePosted = new List <InvoicePostingResult>();
#endif
            var generateProjectInvoice = new CWProjectGenerateInvoice(api, BasePage.GetSystemDefaultDate(), true, true, false, true, false, true, true, true);
#if SILVERLIGHT
            generateProjectInvoice.Height = 360.0d;
#else
            generateProjectInvoice.DialogTableId = 2000000050;
#endif
            generateProjectInvoice.Closed += async delegate
            {
                if (generateProjectInvoice.DialogResult == true)
                {
                    busyIndicator.BusyContent = Uniconta.ClientTools.Localization.lookup("SendingWait");
                    busyIndicator.IsBusy      = true;

                    var invoiceApi = new Uniconta.API.Project.InvoiceAPI(api);
                    int count      = 0;
                    var errorlist  = new List <string>();
                    var projects   = dgProjectMultiLineGrid.GetVisibleRows() as IEnumerable <ProjectClient>;

                    foreach (var proj in projects)
                    {
                        var result = await invoiceApi.PostInvoice(proj, null, generateProjectInvoice.GenrateDate, generateProjectInvoice.IsSimulation, generateProjectInvoice.FromDate, generateProjectInvoice.ToDate,
                                                                  generateProjectInvoice.InvoiceCategory, new DebtorInvoiceClient(), new InvTransClient(), generateProjectInvoice.SendByEmail, true, Uniconta.DataModel.CompanyLayoutType.Invoice,
                                                                  generateProjectInvoice.EmailList, generateProjectInvoice.SendOnlyEmail, new GLTransClient(), null);

                        if (result != null && result.Err == 0)
                        {
#if !SILVERLIGHT
                            invoicePosted.Add(result, proj);
#elif SILVERLIGHT
                            invoicePosted.Add(result);
#endif
                            count++;
                        }
                        else
                        {
                            var error = string.Format("{0}:{1}", proj._Number, Uniconta.ClientTools.Localization.lookup(result.Err.ToString()));
                            errorlist.Add(error);
                        }
                    }
                    busyIndicator.IsBusy = false;
                    string updateMsg     = Uniconta.ClientTools.Localization.lookup("Success");

                    if (!generateProjectInvoice.IsSimulation)
                    {
                        updateMsg = string.Format(Uniconta.ClientTools.Localization.lookup("RecordsUpdated"), count, Uniconta.ClientTools.Localization.lookup("Project"));
                    }
                    if (errorlist.Count == 0)
                    {
                        if (UnicontaMessageBox.Show(updateMsg, Uniconta.ClientTools.Localization.lookup("Message"), MessageBoxButton.OK) == MessageBoxResult.OK)
                        {
                            if (generateProjectInvoice.ShowInvoice)
                            {
                                ShowMultipleInvoicePreview();
                            }
                        }
                    }
                    else
                    {
                        var errorDialog     = new CWErrorBox(errorlist.ToArray(), true);
                        errorDialog.Closed += delegate
                        {
                            ShowMultipleInvoicePreview();
                        };
                        errorDialog.Show();
                    }
                }
            };
            generateProjectInvoice.Show();
        }
        private void CreateMulitOrder(bool IsMultiOrder = true)
        {
            var cwCreateOrder = new CWCreateOrderFromProject(api);

#if !SILVERLIGHT
            cwCreateOrder.DialogTableId = 2000000052;
#endif
            cwCreateOrder.Closed += async delegate
            {
                if (cwCreateOrder.DialogResult == true)
                {
                    busyIndicator.BusyContent = Uniconta.ClientTools.Localization.lookup("LoadingMsg");
                    busyIndicator.IsBusy      = true;

                    IList projectList = null;

                    if (!IsMultiOrder)
                    {
                        var Arr = Array.CreateInstance(dgProjectMultiLineGrid.TableTypeUser, 1);
                        Arr.SetValue(dgProjectMultiLineGrid.SelectedItem, 0);
                        projectList = Arr;
                    }
                    else
                    {
                        projectList = dgProjectMultiLineGrid.GetVisibleRows();
                    }

                    var invoiceApi      = new Uniconta.API.Project.InvoiceAPI(api);
                    var debtorOrderType = api.CompanyEntity.GetUserTypeNotNull(typeof(DebtorOrderClient));
                    var errorlist       = new List <string>();
                    DebtorOrderClient debtorOrderInstance = null;
                    foreach (var proj in projectList)
                    {
                        var selectedItem = proj as ProjectClient;
                        debtorOrderInstance = Activator.CreateInstance(debtorOrderType) as DebtorOrderClient;
                        var result = await invoiceApi.CreateOrderFromProject(debtorOrderInstance, selectedItem._Number, CWCreateOrderFromProject.InvoiceCategory, CWCreateOrderFromProject.GenrateDate,
                                                                             CWCreateOrderFromProject.FromDate, CWCreateOrderFromProject.ToDate);

                        if (result != Uniconta.Common.ErrorCodes.Succes)
                        {
                            var error = string.Format("{0}: {1} - {2}", Uniconta.ClientTools.Localization.lookup("Project"), selectedItem._Number, Uniconta.ClientTools.Localization.lookup(result.ToString()));
                            errorlist.Add(error);
                        }
                    }
                    busyIndicator.IsBusy = false;

                    if (errorlist.Count > 1)
                    {
                        var errorDialog = new CWErrorBox(errorlist.ToArray(), true);
                        errorDialog.Show();
                    }
                    else if (!IsMultiOrder && errorlist.Count == 0)
                    {
                        ShowOrderLines(debtorOrderInstance);
                    }
                    else if (errorlist.Count == 1)
                    {
                        UnicontaMessageBox.Show(errorlist[0], Uniconta.ClientTools.Localization.lookup("Error"), MessageBoxButton.OK);
                    }

                    else
                    {
                        UnicontaMessageBox.Show(Uniconta.ClientTools.Localization.lookup("SalesOrderCreated"), Uniconta.ClientTools.Localization.lookup("Message"), MessageBoxButton.OK);
                    }
                }
            };
            cwCreateOrder.Show();
        }
        private bool ValidateMandate(IEnumerable <DebtorMandateDirectDebit> queryDebMandate, DebtorPaymentFormat debPaymFormat, MandateStatus mandateStatus, bool validateOnly = false)
        {
            try
            {
                var mandateHelper = Common.MandateHelperInstance(debPaymFormat);
                mandateHelper.DirectDebitId = debPaymFormat._CredDirectDebitId;

                var preValErrors = new List <MandateError>();
                var result       = mandateHelper.PreValidateMandates(api.CompanyEntity, debPaymFormat, out preValErrors);

                if (result == DirectMandateResults.Error)
                {
                    var preErrors = new List <string>();
                    foreach (MandateError error in preValErrors)
                    {
                        preErrors.Add(error.Message);
                    }

                    if (preErrors.Count != 0)
                    {
                        CWErrorBox cwError = new CWErrorBox(preErrors.ToArray());
                        cwError.Show();
                        return(false);
                    }
                }

                var valErrors = new List <MandateError>();
                if (mandateStatus == Uniconta.DataModel.MandateStatus.Register)
                {
                    mandateHelper.ValidateRegister(api.CompanyEntity, queryDebMandate, DebtorCache, debPaymFormat, out valErrors);
                }
                else if (mandateStatus == Uniconta.DataModel.MandateStatus.Unregister)
                {
                    mandateHelper.ValidateUnregister(api.CompanyEntity, queryDebMandate, DebtorCache, debPaymFormat, out valErrors);
                }
                else if (mandateStatus == Uniconta.DataModel.MandateStatus.Registered)
                {
                    mandateHelper.ValidateActivate(api.CompanyEntity, queryDebMandate, DebtorCache, debPaymFormat, out valErrors);
                }
                else
                {
                    mandateHelper.ValidateChange(api.CompanyEntity, queryDebMandate, DebtorCache, debPaymFormat, out valErrors);
                }

                foreach (var rec in queryDebMandate)
                {
                    rec.ErrorInfo = Common.VALIDATE_OK;
                }

                foreach (MandateError error in valErrors)
                {
                    var recErr = queryDebMandate.First(s => s.RowId == error.RowId);

                    if (recErr.ErrorInfo == Common.VALIDATE_OK)
                    {
                        recErr.ErrorInfo = error.Message;
                    }
                    else
                    {
                        recErr.ErrorInfo += Environment.NewLine + error.Message;
                    }
                }

                if (queryDebMandate.Any(s => s.ErrorInfo == Common.VALIDATE_OK) == false && validateOnly == false)
                {
                    UnicontaMessageBox.Show(Uniconta.ClientTools.Localization.lookup("NoRecordSelected"), Uniconta.ClientTools.Localization.lookup("Warning"));
                    return(false);
                }

                if (validateOnly)
                {
                    var countErr = queryDebMandate.Where(s => (s.ErrorInfo != Common.VALIDATE_OK) && (s.ErrorInfo != null)).Count();
                    var infoTxt  = countErr != 0 ? string.Format(Uniconta.ClientTools.Localization.lookup("ValidateFailInLines"), countErr) : Uniconta.ClientTools.Localization.lookup("ValidateNoError");
                    UnicontaMessageBox.Show(infoTxt, Uniconta.ClientTools.Localization.lookup("Warning"));
                }
            }
            catch (Exception ex)
            {
                UnicontaMessageBox.Show(ex);
            }

            return(true);
        }