Esempio n. 1
0
        private void CallValidatePayment(bool useDialog = true)
        {
            if (useDialog)
            {
                CWDirectDebit cwwin = new CWDirectDebit(api, Uniconta.ClientTools.Localization.lookup("Validate"));
                cwwin.Closing += delegate
                {
                    if (cwwin.DialogResult == true)
                    {
                        ExpandCollapseAllGroups();

                        List <DebtorTransDirectDebit> ListDebTransPaym = new List <DebtorTransDirectDebit>();
                        int index = 0;
                        foreach (var rec in (IEnumerable <DebtorTransDirectDebit>)dgDebtorTranOpenGrid.ItemsSource)
                        {
                            int rowHandle = dgDebtorTranOpenGrid.GetRowHandleByListIndex(index);
                            index++;
                            if (dgDebtorTranOpenGrid.IsRowVisible(rowHandle) && rec._PaymentFormat == cwwin.PaymentFormat._Format && (rec._PaymentStatus == PaymentStatusLevel.None || rec._PaymentStatus == PaymentStatusLevel.Resend || rec._PaymentStatus == PaymentStatusLevel.StopPayment || rec._PaymentStatus == PaymentStatusLevel.FileSent))
                            {
                                ListDebTransPaym.Add(rec);
                            }
                            else
                            {
                                continue;
                            }
                        }

                        IEnumerable <DebtorTransDirectDebit> queryPaymentTrans = ListDebTransPaym.AsEnumerable();

                        ValidatePayments(queryPaymentTrans, doMergePaym, cwwin.PaymentFormat, true, false);
                    }
                };
                cwwin.Show();
            }
        }
Esempio n. 2
0
        private void MergePaym()
        {
            doMergePaym = !doMergePaym;
            if (doMergePaym)
            {
                CWDirectDebit cwwin = new CWDirectDebit(api, Uniconta.ClientTools.Localization.lookup("MergePayments"));

                cwwin.Closing += delegate
                {
                    if (cwwin.DialogResult == true)
                    {
                        if (cwwin.DialogResult != true)
                        {
                            setMergeUnMergePaym(doMergePaym);
                            return;
                        }

                        var debPaymentFormat = cwwin.PaymentFormat;

                        ExpandCollapseAllGroups();
                        List <DebtorTransDirectDebit> ListDebTransPaym = new List <DebtorTransDirectDebit>();
                        int index = 0;
                        foreach (var rec in (IEnumerable <DebtorTransDirectDebit>)dgDebtorTranOpenGrid.ItemsSource)
                        {
                            rec.ErrorInfo = string.Empty;
                            int rowHandle = dgDebtorTranOpenGrid.GetRowHandleByListIndex(index);
                            index++;
                            if (dgDebtorTranOpenGrid.IsRowVisible(rowHandle) && rec._PaymentFormat == debPaymentFormat._Format && (rec._PaymentStatus == PaymentStatusLevel.None || rec._PaymentStatus == PaymentStatusLevel.Resend || rec._PaymentStatus == PaymentStatusLevel.StopPayment))
                            {
                                ListDebTransPaym.Add(rec);
                            }
                            else
                            {
                                continue;
                            }
                        }

                        IEnumerable <DebtorTransDirectDebit> queryPaymentTrans = ListDebTransPaym.AsEnumerable();

                        ValidatePayments(queryPaymentTrans, false, debPaymentFormat);

                        //var transToBeMerged = dgDebtorTranOpenGrid.GetVisibleRows() as IEnumerable<DebtorTransDirectDebit>;

                        if (Common.MergePayment(api.CompanyEntity, queryPaymentTrans))
                        {
                            setMergeUnMergePaym(doMergePaym);
                        }
                    }
                };
                cwwin.Show();
            }
            else
            {
                setMergeUnMergePaym(doMergePaym);
            }
        }
Esempio n. 3
0
        async void CreateMandates(IList debtors)
        {
            var mandateCache = api.GetCache(typeof(Uniconta.DataModel.DebtorPaymentMandate)) ?? await api.LoadCache(typeof(Uniconta.DataModel.DebtorPaymentMandate));

            CWDirectDebit cwwin = new CWDirectDebit(api, string.Format(Uniconta.ClientTools.Localization.lookup("CreateOBJ"), Uniconta.ClientTools.Localization.lookup("Mandates")), true);

            cwwin.Closing += delegate
            {
                if (cwwin.DialogResult == true)
                {
                    var lstDebtors = debtors.Cast <Uniconta.ClientTools.DataModel.DebtorClient>();
                    var lstInsert  = new List <Uniconta.DataModel.DebtorPaymentMandate>();
                    var lstUpdate  = new List <Uniconta.DataModel.Debtor>();

                    bool mandateIsDebtor = cwwin.PaymentFormat._UseDebtorAccAsMandate;

                    foreach (var rec in lstDebtors)
                    {
                        var mandate = (Uniconta.DataModel.DebtorPaymentMandate)mandateCache?.Get(rec._Account);
                        if (mandate != null)
                        {
                            continue;
                        }

                        var newMandate = new Uniconta.DataModel.DebtorPaymentMandate();
                        newMandate.SetMaster(rec);
                        newMandate._AltMandateId = mandateIsDebtor ? rec._Account : null;
                        newMandate._Scheme       = cwwin.directDebitScheme;
                        newMandate._StatusInfo   = string.Format("({0}) {1}", Uniconta.DirectDebitPayment.Common.GetTimeStamp(), Uniconta.ClientTools.Localization.lookup("Created"));;
                        lstInsert.Add(newMandate);

                        if (rec.PaymentFormat != cwwin.PaymentFormat._Format)
                        {
                            rec.PaymentFormat = cwwin.PaymentFormat._Format;
                            lstUpdate.Add(rec);
                        }
                    }

                    if (lstInsert.Count > 0)
                    {
                        api.InsertNoResponse(lstInsert);
                        UnicontaMessageBox.Show(string.Format(Uniconta.ClientTools.Localization.lookup("RecordsUpdated"), lstInsert.Count, Uniconta.ClientTools.Localization.lookup("Mandates")), Uniconta.ClientTools.Localization.lookup("Information"));
                    }

                    if (lstUpdate.Count > 0)
                    {
                        api.UpdateNoResponse(lstUpdate);
                    }
                }
            };
            cwwin.Show();
        }
        private void RegisterMandate(IList lstMandates)
        {
            CWDirectDebit cwwin = new CWDirectDebit(api, Uniconta.ClientTools.Localization.lookup("Register"), true);

            cwwin.Closing += delegate
            {
                if (cwwin.DialogResult == true)
                {
                    var debPaymentFormat = cwwin.PaymentFormat;
                    var schemeType       = cwwin.directDebitScheme;

                    if (debPaymentFormat._ExportFormat == (byte)Uniconta.DataModel.DebtorPaymFormatType.NetsBS)
                    {
                        UnicontaMessageBox.Show("Denne funktion understøttes ikke af Uniconta", Uniconta.ClientTools.Localization.lookup("Register"));
                        return;
                    }

                    List <DebtorMandateDirectDebit> LstDebMandate = new List <DebtorMandateDirectDebit>();
                    foreach (var s in lstMandates.Cast <DebtorMandateDirectDebit>())
                    {
                        if ((s._Status == Uniconta.DataModel.MandateStatus.None ||
                             s._Status == Uniconta.DataModel.MandateStatus.Unregistered ||
                             s._Status == Uniconta.DataModel.MandateStatus.Unregister ||
                             s._Status == Uniconta.DataModel.MandateStatus.Error) && s.PaymentFormat == debPaymentFormat._Format)
                        {
                            LstDebMandate.Add(s);
                        }
                    }

                    if (LstDebMandate.Count == 0)
                    {
                        UnicontaMessageBox.Show(Uniconta.ClientTools.Localization.lookup("NoRecordSelected"), Uniconta.ClientTools.Localization.lookup("Error"));
                        return;
                    }

                    IEnumerable <DebtorMandateDirectDebit> queryDebMandate = LstDebMandate.AsEnumerable();
                    if (ValidateMandate(queryDebMandate, debPaymentFormat, Uniconta.DataModel.MandateStatus.Register))
                    {
                        try
                        {
                            Common.CreateMandateFile(api, queryDebMandate.Where(s => s.ErrorInfo == Common.VALIDATE_OK), DebtorCache, debPaymentFormat, Uniconta.DataModel.MandateStatus.Register, schemeType);
                        }
                        catch (Exception ex)
                        {
                            UnicontaMessageBox.Show(ex);
                        }
                    }
                }
            };
            cwwin.Show();
        }
        private void ChangeMandateId(IList lstMandates)
        {
            CWDirectDebit cwwin = new CWDirectDebit(api, string.Format(Uniconta.ClientTools.Localization.lookup("ChangeOBJ"), Uniconta.ClientTools.Localization.lookup("Mandates")));

            cwwin.Closing += delegate
            {
                if (cwwin.DialogResult == true)
                {
                    var debPaymentFormat = cwwin.PaymentFormat;
                    if (debPaymentFormat._ExportFormat != (byte)Uniconta.DataModel.DebtorPaymFormatType.NetsLS && debPaymentFormat._ExportFormat != (byte)Uniconta.DataModel.DebtorPaymFormatType.NetsBS)
                    {
                        UnicontaMessageBox.Show(string.Format("Function not available for Payment format '{0}'", (Uniconta.DataModel.DebtorPaymFormatType)debPaymentFormat._ExportFormat), string.Format(Uniconta.ClientTools.Localization.lookup("ChangeOBJ"), Uniconta.ClientTools.Localization.lookup("Mandates")));
                        return;
                    }

                    dgDebtorPaymentMandate.Columns.GetColumnByName("OldMandateId").Visible = true;

                    List <DebtorMandateDirectDebit> LstDebMandate = new List <DebtorMandateDirectDebit>();
                    var qrMandates = lstMandates.Cast <DebtorMandateDirectDebit>();
                    foreach (var s in qrMandates)
                    {
                        if (s.PaymentFormat == debPaymentFormat._Format)
                        {
                            LstDebMandate.Add(s);
                        }
                    }
                    if (LstDebMandate.Count == 0)
                    {
                        UnicontaMessageBox.Show(Uniconta.ClientTools.Localization.lookup("NoRecordSelected"), Uniconta.ClientTools.Localization.lookup("Error"));
                        return;
                    }

                    IEnumerable <DebtorMandateDirectDebit> queryDebMandate = LstDebMandate.AsEnumerable();
                    if (ValidateMandate(queryDebMandate, debPaymentFormat, Uniconta.DataModel.MandateStatus.Change))
                    {
                        try
                        {
                            Uniconta.DirectDebitPayment.Common.CreateMandateFile(api, queryDebMandate.Where(s => s.ErrorInfo == Common.VALIDATE_OK), DebtorCache, debPaymentFormat, Uniconta.DataModel.MandateStatus.Change);
                        }
                        catch (Exception ex)
                        {
                            UnicontaMessageBox.Show(ex);
                        }
                    }
                }
            };
            cwwin.Show();
        }
        private void UnregisterMandate(IList lstMandates)
        {
            CWDirectDebit cwwin = new CWDirectDebit(api, Uniconta.ClientTools.Localization.lookup("UnRegister"));

            cwwin.Closing += delegate
            {
                if (cwwin.DialogResult == true)
                {
                    var debPaymentFormat = cwwin.PaymentFormat;

                    List <DebtorMandateDirectDebit> LstDebMandate = new List <DebtorMandateDirectDebit>();

                    var qrMandates = lstMandates.Cast <DebtorMandateDirectDebit>();

                    foreach (var rec in qrMandates.Where(s => (s.PaymentFormat == cwwin.PaymentFormat._Format && (s._Status == Uniconta.DataModel.MandateStatus.Registered))))
                    {
                        LstDebMandate.Add(rec);
                    }

                    if (LstDebMandate.Count() == 0)
                    {
                        UnicontaMessageBox.Show(Uniconta.ClientTools.Localization.lookup("NoRecordSelected"), Uniconta.ClientTools.Localization.lookup("Error"));
                        return;
                    }

                    IEnumerable <DebtorMandateDirectDebit> queryDebMandate = LstDebMandate.AsEnumerable();
                    if (ValidateMandate(queryDebMandate, debPaymentFormat, Uniconta.DataModel.MandateStatus.Unregister))
                    {
                        try
                        {
                            Common.CreateMandateFile(api, queryDebMandate.Where(s => s.ErrorInfo == Common.VALIDATE_OK), DebtorCache, debPaymentFormat, Uniconta.DataModel.MandateStatus.Unregister);
                        }
                        catch (Exception ex)
                        {
                            UnicontaMessageBox.Show(ex.Message, Uniconta.ClientTools.Localization.lookup("Exception"));
                        }
                    }
                }
            };
            cwwin.Show();
        }
        private void CallValidateMandate()
        {
            CWDirectDebit cwwin = new CWDirectDebit(api, Uniconta.ClientTools.Localization.lookup("Validate"));

            cwwin.Closing += delegate
            {
                if (cwwin.DialogResult == true)
                {
                    List <DebtorMandateDirectDebit> LstDebMandate = new List <DebtorMandateDirectDebit>();
                    int index = 0;
                    foreach (var rec in (IEnumerable <DebtorMandateDirectDebit>)dgDebtorPaymentMandate.ItemsSource)
                    {
                        int rowHandle = dgDebtorPaymentMandate.GetRowHandleByListIndex(index);
                        index++;
                        if (dgDebtorPaymentMandate.IsRowVisible(rowHandle) && rec.PaymentFormat == cwwin.PaymentFormat._Format && rec._Status == Uniconta.DataModel.MandateStatus.None)
                        {
                            LstDebMandate.Add(rec);
                        }
                        else
                        {
                            continue;
                        }

                        if (LstDebMandate.Count == 0)
                        {
                            UnicontaMessageBox.Show(Uniconta.ClientTools.Localization.lookup("NoRecordSelected"), Uniconta.ClientTools.Localization.lookup("Warning"));
                            return;
                        }
                    }

                    IEnumerable <DebtorMandateDirectDebit> queryDebMandate = LstDebMandate.AsEnumerable();

                    ValidateMandate(queryDebMandate, cwwin.PaymentFormat, Uniconta.DataModel.MandateStatus.Register, true);
                }
            };
            cwwin.Show();
        }
Esempio n. 8
0
        private void ExportFile()
        {
            GetNextPaymentFileId();

            CWDirectDebit cwwin = new CWDirectDebit(api, Uniconta.ClientTools.Localization.lookup("Export"));

            cwwin.Closing += async delegate
            {
                if (cwwin.DialogResult == true)
                {
                    var debPaymentFormat = cwwin.PaymentFormat;

                    ExpandCollapseAllGroups();
                    List <DebtorTransDirectDebit> ListDebTransPaym = new List <DebtorTransDirectDebit>();
                    int index = 0;
                    foreach (var rec in (IEnumerable <DebtorTransDirectDebit>)dgDebtorTranOpenGrid.ItemsSource)
                    {
                        int rowHandle = dgDebtorTranOpenGrid.GetRowHandleByListIndex(index);
                        index++;
                        if (dgDebtorTranOpenGrid.IsRowVisible(rowHandle) && rec._PaymentFormat == debPaymentFormat._Format && (rec._PaymentStatus == PaymentStatusLevel.None || rec._PaymentStatus == PaymentStatusLevel.Resend || rec._PaymentStatus == PaymentStatusLevel.StopPayment))
                        {
                            ListDebTransPaym.Add(rec);
                        }
                        else
                        {
                            continue;
                        }
                    }

                    IEnumerable <DebtorTransDirectDebit> queryPaymentTrans = ListDebTransPaym.AsEnumerable();

                    if (queryPaymentTrans.Count() == 0)
                    {
                        UnicontaMessageBox.Show(Uniconta.ClientTools.Localization.lookup("NoRecordSelected"), Uniconta.ClientTools.Localization.lookup("Warning"));
                        return;
                    }

                    if (ValidatePayments(queryPaymentTrans, doMergePaym, debPaymentFormat, false, false))
                    {
                        try
                        {
                            List <DebtorTransDirectDebit> paymentListMerged = null;
                            var dictPaym = new Dictionary <String, DebtorTransDirectDebit>();
                            DebtorTransDirectDebit mergePayment;

                            var  paymNumSeqRefId  = nextPaymentRefId;
                            bool stopPaymentTrans = false;
                            bool netsBS           = false;

                            if (doMergePaym)
                            {
                                queryPaymentTrans = queryPaymentTrans.OrderBy(x => x.MergeDataId).OrderBy(x => x.Invoice).ToList();
                            }

                            foreach (var rec in queryPaymentTrans.Where(s => s.ErrorInfo == Common.VALIDATE_OK))
                            {
                                stopPaymentTrans = rec._PaymentStatus == PaymentStatusLevel.StopPayment;
                                netsBS           = debPaymentFormat._ExportFormat == (byte)DebtorPaymFormatType.NetsBS;

                                if (doMergePaym || stopPaymentTrans)
                                {
                                    var keyValue = stopPaymentTrans ? rec.PaymentRefId.ToString() : rec.MergeDataId;

                                    if (dictPaym.TryGetValue(keyValue, out mergePayment))
                                    {
                                        mergePayment.MergedAmount += netsBS ? rec.Amount : rec.PaymentAmount;
                                        mergePayment.hasBeenMerged = true;

                                        if (rec.TransactionText != null)
                                        {
                                            mergePayment.TransactionText += mergePayment.TransactionText != null?string.Format("{0}{1}{2}{3}", Environment.NewLine, Environment.NewLine, Environment.NewLine, rec.TransactionText) : rec.TransactionText;
                                        }

                                        if (stopPaymentTrans)
                                        {
                                            rec.MergeDataId  = rec.PaymentRefId.ToString();
                                            rec.PaymentRefId = rec.PaymentRefId;
                                        }
                                        else
                                        {
                                            if (keyValue == Common.MERGEID_SINGLEPAYMENT)
                                            {
                                                paymNumSeqRefId++;
                                            }

                                            rec.PaymentRefId = paymNumSeqRefId;
                                        }
                                    }
                                    else
                                    {
                                        if (!stopPaymentTrans)
                                        {
                                            paymNumSeqRefId++;
                                            rec._PaymentRefId = paymNumSeqRefId;
                                        }

                                        mergePayment = new DebtorTransDirectDebit();
                                        StreamingManager.Copy(rec, mergePayment);
                                        mergePayment.MergeDataId     = keyValue;
                                        mergePayment._PaymentRefId   = rec._PaymentRefId;
                                        mergePayment.MergedAmount    = netsBS ? rec.Amount : rec.PaymentAmount;
                                        mergePayment.TransactionText = rec.TransactionText;

                                        mergePayment.ErrorInfo = rec.ErrorInfo;

                                        dictPaym.Add(keyValue, mergePayment);
                                    }
                                    paymentListMerged = dictPaym.Values.ToList();
                                }
                                else
                                {
                                    paymNumSeqRefId++;
                                    rec.MergedAmount = 0;
                                    rec.PaymentRefId = paymNumSeqRefId;
                                }
                            }

                            List <DebtorTransDirectDebit> paymentList = null;
                            if (doMergePaym)
                            {
                                paymentList = paymentListMerged.Where(s => s.MergeDataId != Uniconta.ClientTools.Localization.lookup("Excluded") && s.MergeDataId != Common.MERGEID_SINGLEPAYMENT && s._PaymentStatus != PaymentStatusLevel.StopPayment).ToList();
                                foreach (var rec in queryPaymentTrans.Where(s => (s.MergeDataId == Common.MERGEID_SINGLEPAYMENT && s._PaymentStatus != PaymentStatusLevel.StopPayment)))
                                {
                                    paymentList.Add(rec);
                                }
                            }
                            else
                            {
                                paymentList = queryPaymentTrans.Where(s => s.ErrorInfo == Common.VALIDATE_OK && s._PaymentStatus != PaymentStatusLevel.StopPayment).ToList();
                            }

                            if (paymentListMerged != null)
                            {
                                foreach (var rec in paymentListMerged.Where(s => (s._PaymentStatus == PaymentStatusLevel.StopPayment)))
                                {
                                    paymentList.Add(rec);
                                }
                            }

                            var paymentListTotal = queryPaymentTrans.Where(s => s.ErrorInfo == Common.VALIDATE_OK).ToList();

                            var err = await Common.CreatePaymentFile(api, paymentList, MandateCache, DebtorCache, nextPaymentFileId, debPaymentFormat, BankAccountCache);

                            if (err != ErrorCodes.Succes)
                            {
                                UtilDisplay.ShowErrorCode(err);
                            }
                            else
                            {
                                Common.InsertPaymentReference(paymentListTotal.Where(s => s.ErrorInfo == Common.VALIDATE_OK).ToList(), api, nextPaymentFileId);
                            }
                        }
                        catch (Exception ex)
                        {
                            UnicontaMessageBox.Show(ex.Message, Uniconta.ClientTools.Localization.lookup("Exception"));
                        }
                    }
                }
            };
            cwwin.Show();
        }
        private void ImportMandate()
        {
            CWDirectDebit cwwin = new CWDirectDebit(api, string.Format(Uniconta.ClientTools.Localization.lookup("Load"), Uniconta.ClientTools.Localization.lookup("Mandates")));

            cwwin.Closing += delegate
            {
                if (cwwin.DialogResult == true)
                {
                    try
                    {
                        var debtorPaymentFormat = cwwin.PaymentFormat;
                        if (debtorPaymentFormat._ExportFormat != (byte)Uniconta.DataModel.DebtorPaymFormatType.NetsLS && debtorPaymentFormat._ExportFormat != (byte)Uniconta.DataModel.DebtorPaymFormatType.NetsBS)
                        {
                            UnicontaMessageBox.Show(string.Format("Function not available for Payment format '{0}'", (Uniconta.DataModel.DebtorPaymFormatType)debtorPaymentFormat._ExportFormat), string.Format(Uniconta.ClientTools.Localization.lookup("Load"), Uniconta.ClientTools.Localization.lookup("Mandates")));
                            return;
                        }

                        var sfd             = UtilDisplay.LoadOpenFileDialog;
                        var userClickedSave = sfd.ShowDialog();
                        if (userClickedSave != true)
                        {
                            return;
                        }

                        List <DebtorMandateDirectDebit> mandateLst = new List <DebtorMandateDirectDebit>();
                        int index = 0;
                        foreach (var rec in (IEnumerable <DebtorMandateDirectDebit>)dgDebtorPaymentMandate.ItemsSource)
                        {
                            int rowHandle = dgDebtorPaymentMandate.GetRowHandleByListIndex(index);
                            index++;
                            if (!dgDebtorPaymentMandate.IsRowVisible(rowHandle))
                            {
                                continue;
                            }

                            mandateLst.Add(rec);
                        }

                        var lines = File.ReadAllLines(sfd.FileName).Select(a => a.Split(';'));

                        var updateRecords = new List <UnicontaBaseEntity>();
                        var cnt           = 0;
                        foreach (var rec in lines)
                        {
                            if (debtorPaymentFormat._ExportFormat == (byte)DebtorPaymFormatType.NetsBS)
                            {
                                if (rec.Length < 3)
                                {
                                    continue;
                                }

                                var debtorAccValue  = rec.GetValue(0).ToString();
                                var oldMandateValue = rec.GetValue(1).ToString();
                                var agreementId     = rec.GetValue(2).ToString();

                                var mandate = mandateLst.FirstOrDefault(s => s.DCAccount == debtorAccValue);
                                if (mandate != null)
                                {
                                    var debtor = mandate.Debtor;
                                    debtor._PaymentFormat = debtorPaymentFormat.Format;
                                    updateRecords.Add(debtor);

                                    var statusInfoText = string.Format("({0}) Mandate agreement id set to {1}\n{2}", Uniconta.DirectDebitPayment.Common.GetTimeStamp(), agreementId, mandate.StatusInfo);

                                    mandate.OldMandateId = oldMandateValue;
                                    mandate._AgreementId = agreementId;
                                    mandate._StatusInfo  = Uniconta.DirectDebitPayment.Common.StatusInfoTruncate(statusInfoText);

                                    updateRecords.Add(mandate);
                                    cnt++;
                                }
                            }
                            else
                            {
                                if (rec.Length < 2)
                                {
                                    continue;
                                }

                                var debtorAccValue  = rec.GetValue(0).ToString();
                                var oldMandateValue = rec.GetValue(1).ToString();

                                var mandate = mandateLst.FirstOrDefault(s => s.DCAccount == debtorAccValue);
                                if (mandate != null)
                                {
                                    var debtor = mandate.Debtor;
                                    debtor._PaymentFormat = debtorPaymentFormat.Format;
                                    updateRecords.Add(debtor);

                                    mandate.OldMandateId = oldMandateValue;
                                    cnt++;
                                }
                            }
                        }

                        dgDebtorPaymentMandate.Columns.GetColumnByName("OldMandateId").Visible = true;

                        if (cnt == 0)
                        {
                            if (debtorPaymentFormat._ExportFormat == (byte)DebtorPaymFormatType.NetsBS)
                            {
                                UnicontaMessageBox.Show(string.Format("Couldn't find any match in the file.\n" +
                                                                      "Note:\nColumn 1 = Customer account\nColumn 2 = Old MandateId\nColumn 3 = AgreementId\nUse a semicolon as field delimiter"), Uniconta.ClientTools.Localization.lookup("Error"));
                            }
                            else
                            {
                                UnicontaMessageBox.Show(string.Format("Couldn't find any match in the file.\n" +
                                                                      "Note:\nColumn 1 = Customer account\nColumn 2 = Old MandateId\nUse a semicolon as field delimiter"), Uniconta.ClientTools.Localization.lookup("Error"));
                            }
                        }
                        else
                        {
                            if (updateRecords != null && updateRecords.Count != 0)
                            {
                                api.Update(updateRecords);
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        UnicontaMessageBox.Show(e, Uniconta.ClientTools.Localization.lookup("Exception"));
                    }
                }
            };
            cwwin.Show();
        }
        private void ActivateMandateId(IList lstMandates)
        {
            CWDirectDebit cwwin = new CWDirectDebit(api, string.Format(Uniconta.ClientTools.Localization.lookup("Activate")), showActivateWarning: true);

            cwwin.Closing += delegate
            {
                if (cwwin.DialogResult == true)
                {
                    var debPaymentFormat = cwwin.PaymentFormat;
                    if (debPaymentFormat._ExportFormat != (byte)Uniconta.DataModel.DebtorPaymFormatType.NetsLS && debPaymentFormat._ExportFormat != (byte)Uniconta.DataModel.DebtorPaymFormatType.NetsBS)
                    {
                        UnicontaMessageBox.Show(string.Format("{0} '{1}'", Uniconta.ClientTools.Localization.lookup("NonSupportSEPA"), (Uniconta.DataModel.DebtorPaymFormatType)debPaymentFormat._ExportFormat), Uniconta.ClientTools.Localization.lookup("Activate")); //TODO:Test denne
                        return;
                    }

                    List <DebtorMandateDirectDebit> LstDebMandate = new List <DebtorMandateDirectDebit>();
                    var qrMandates = lstMandates.Cast <DebtorMandateDirectDebit>();
                    foreach (var s in qrMandates)
                    {
                        if (s.PaymentFormat == debPaymentFormat._Format)
                        {
                            LstDebMandate.Add(s);
                        }
                    }
                    if (LstDebMandate.Count == 0)
                    {
                        UnicontaMessageBox.Show(Uniconta.ClientTools.Localization.lookup("NoRecordSelected"), Uniconta.ClientTools.Localization.lookup("Error"));
                        return;
                    }

                    IEnumerable <DebtorMandateDirectDebit> queryDebMandate = LstDebMandate.AsEnumerable();
                    if (ValidateMandate(queryDebMandate, debPaymentFormat, Uniconta.DataModel.MandateStatus.Registered))
                    {
                        try
                        {
                            var lstUpdate = new List <DebtorMandateDirectDebit>();
                            foreach (var rec in queryDebMandate)
                            {
                                if (rec == null)
                                {
                                    continue;
                                }

                                var statusInfoTxt = rec._StatusInfo;

                                statusInfoTxt        = string.Format("({0}) Mandate registered manually\n{1}", Common.GetTimeStamp(), statusInfoTxt);
                                rec.MandateStatus    = AppEnums.MandateStatus.ToString((int)Uniconta.DataModel.MandateStatus.Registered);
                                rec.CancellationDate = DateTime.MinValue;
                                rec.ActivationDate   = DateTime.Today;

                                rec._StatusInfo = Common.StatusInfoTruncate(statusInfoTxt);

                                lstUpdate.Add(rec);
                            }
                            api.UpdateNoResponse(lstUpdate);
                        }
                        catch (Exception ex)
                        {
                            UnicontaMessageBox.Show(ex);
                        }
                    }
                }
            };
            cwwin.Show();
        }
        async void ImportFile()
        {
            CWDirectDebit             cwwin            = new CWDirectDebit(api, Uniconta.ClientTools.Localization.lookup("Upload File"));
            DebtorPaymentFormatClient debPaymentFormat = null;

            cwwin.Closing += delegate
            {
                if (cwwin.DialogResult == true)
                {
                    debPaymentFormat = cwwin.PaymentFormat;
                }
            };
            cwwin.Show();

            if (debPaymentFormat == null)
            {
                return;
            }

            ErrorCodes error     = ErrorCodes.Succes;
            var        showError = false;

            try
            {
                var sfd             = UtilDisplay.LoadOpenFileDialog;
                var userClickedSave = sfd.ShowDialog();
                if (userClickedSave != true)
                {
                    return;
                }

                var nextPaymentFileIdTest = 1;

                using (var stream = File.Open(sfd.FileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                {
                    using (var sr = new StreamReader(stream))
                    {
                        var filecontentText = await sr.ReadToEndAsync();

                        var debPaymFile = new DebtorPaymentFile
                        {
                            _Created           = DateTime.Now,
                            _CredDirectDebitId = debPaymentFormat._CredDirectDebitId,
                            _Filename          = sfd.SafeFileName,
                            _Data       = Encoding.GetEncoding("iso-8859-1").GetBytes(filecontentText),
                            _FileId     = string.Format("{0}_{1}_{2}", debPaymentFormat._Format, DateTime.Now.ToString("yyMMdd"), nextPaymentFileIdTest.ToString().PadLeft(5, '0')),
                            _Format     = debPaymentFormat._Format,
                            _StatusInfo = string.Format("{0} return file", debPaymentFormat._Format),
                            _Status     = DebtorPaymentStatus.Pending,
                            _Output     = false
                        };
                        showError = true;
                        error     = await api.Insert(debPaymFile);
                    }
                }
                gridRibbon_BaseActions("RefreshGrid");
            }
            catch (Exception ex)
            {
                if (showError)
                {
                    UnicontaMessageBox.Show(ex.Message + "\n" + error, Uniconta.ClientTools.Localization.lookup("Execption"));
                }
                else
                {
                    UnicontaMessageBox.Show(ex.Message, Uniconta.ClientTools.Localization.lookup("Exception"));
                }
            }
        }