public void Manipulations()
        {
            CommaDelimitedStringCollection c = new CommaDelimitedStringCollection();

            c.Add("1");
            Assert.Equal("1", c.ToString());

            c.Add("2");
            c.Add("3");
            Assert.Equal("1,2,3", c.ToString());

            c.Remove("2");
            Assert.Equal("1,3", c.ToString());

            c.Insert(1, "2");
            Assert.Equal("1,2,3", c.ToString());

            c.Clear();
            Assert.Null(c.ToString());

            string[] foo = new string[3];
            foo[0] = "1";
            foo[1] = "2";
            foo[2] = "3";
            c.AddRange(foo);
            Assert.Equal("1,2,3", c.ToString());
        }
        public void ConvertTo()
        {
            CommaDelimitedStringCollectionConverter cv  = new CommaDelimitedStringCollectionConverter();
            CommaDelimitedStringCollection          col = new CommaDelimitedStringCollection();

            col.Add("hi");
            col.Add("bye");

            Assert.AreEqual("hi,bye", cv.ConvertTo(null, null, col, typeof(string)), "A1");
        }
Esempio n. 3
0
        private OracleCommand GetInsertCommand(object entity)
        {
            if (ConnectionMode == Enums.Mode.UnitOfWork && !insertCommands.Where(a => a.Equals(entity)).Any())
            {
                insertCommands.Add(entity);
                return(null);
            }

            OracleCommand cmd         = new OracleCommand();
            string        commandText = string.Empty;
            CommaDelimitedStringCollection columns    = new CommaDelimitedStringCollection();
            CommaDelimitedStringCollection parameters = new CommaDelimitedStringCollection();

            foreach (var prop in entity.GetType().GetProperties())
            {
                var value        = prop.GetValue(entity, null);
                var seq          = prop.GetCustomAttributes(false).Where(a => a is SequenceAttribute).FirstOrDefault();
                var defaultValue = prop.GetCustomAttributes(false).Where(a => a is DefaultValueAttribute).FirstOrDefault();
                columns.Add(String.Format("{0}", prop.Name));
                if (seq != null)
                {
                    parameters.Add(String.Format("{0}.{1}.NextVal", _schemmaName, (seq as SequenceAttribute).SequenceName));
                }
                else
                {
                    if (defaultValue == null)
                    {
                        parameters.Add(String.Format(":{0}", prop.Name));
                        if (prop.PropertyType.Name.StartsWith("Nullable") && value == null)
                        {
                            cmd.Parameters.Add(new OracleParameter(prop.Name, DBNull.Value));
                        }
                        else
                        {
                            cmd.Parameters.Add(new OracleParameter(prop.Name, value));
                        }
                    }
                    else
                    {
                        parameters.Add(String.Format("{0}", (defaultValue as DefaultValueAttribute).Value.ToString()));
                    }
                }
            }

            commandText = String.Format("INSERT INTO {0}.{1} ({2}) VALUES ({3})",
                                        _schemmaName,
                                        entity.GetType().Name,
                                        columns.ToString(),
                                        parameters.ToString());
            cmd.CommandText = commandText.ToString();
            return(cmd);
        }
Esempio n. 4
0
        private OracleCommand GetMappedInsertCommand(object entity, KeyValuePair <Mapper, Type> map)
        {
            if (ConnectionMode == Enums.Mode.UnitOfWork && !insertCommands.Where(a => a.Equals(entity)).Any())
            {
                insertCommands.Add(entity);
                return(null);
            }

            OracleCommand cmd                    = new OracleCommand();
            string        commandText            = string.Empty;
            CommaDelimitedStringCollection col   = new CommaDelimitedStringCollection();
            CommaDelimitedStringCollection param = new CommaDelimitedStringCollection();

            col.AddRange(map.Key.Columns.Select(a => a.ColumnName).ToArray());
            foreach (var column in map.Key.Columns)
            {
                var prop  = entity.GetType().GetProperty(column.ColumnName);
                var value = prop.GetValue(entity, null);
                if (String.IsNullOrWhiteSpace(column.DefaultValue))
                {
                    if (string.IsNullOrWhiteSpace(column.SequenceName))
                    {
                        param.Add(String.Format(":{0}", column.ColumnName));
                        if (column.Nullable && value == null)
                        {
                            cmd.Parameters.Add(new OracleParameter(column.ColumnName, DBNull.Value));
                        }
                        else
                        {
                            cmd.Parameters.Add(new OracleParameter(column.ColumnName, value));
                        }
                    }
                    else
                    {
                        param.Add(String.Format("{0}.{1}.NextVal", _schemmaName, column.SequenceName));
                    }
                }
                else
                {
                    param.Add(column.DefaultValue);
                }
            }
            commandText = String.Format("INSERT INTO {0}.{1} ({2}) VALUES ({3})",
                                        _schemmaName,
                                        entity.GetType().Name,
                                        col.ToString(),
                                        param.ToString());
            cmd.CommandText = commandText.ToString();
            return(cmd);
        }
        private Dictionary <int, CommaDelimitedStringCollection> GetDatabase()
        {
            var contents = GetFileContents(DATABASE_PATH);
            var commaStr = new CommaDelimitedStringCollection();

            commaStr.AddRange(contents.Split(','));
            var db = new Dictionary <int, CommaDelimitedStringCollection>();

            var id         = 0;
            var collection = new CommaDelimitedStringCollection();

            for (var i = 0; i < commaStr.Count; i++)
            {
                var str = commaStr[i];
                if (str.Contains(":"))
                {
                    collection.Add(str.Split(':')[1]);
                    if (i > 0)
                    {
                        db.Add(id, collection);
                    }
                    collection = new CommaDelimitedStringCollection();
                    id         = int.Parse(str.Split(':')[0]);
                }
                else
                {
                    collection.Add(str);
                }
            }

            return(db);
        }
        public void RO_Add()
        {
            CommaDelimitedStringCollection c = new CommaDelimitedStringCollection();

            c.SetReadOnly();
            Assert.Throws <ConfigurationErrorsException>(() => c.Add("hi"));
        }
        private string SelectFieldNamesForEntity(int entityId)
        {
            string sqlText = @"SELECT name 
                               FROM dbo.AdvancedFields 
                               WHERE entity_id = @entity_id ";

            CommaDelimitedStringCollection commaStr = new CommaDelimitedStringCollection();

            using (SqlConnection conn = GetConnection())
                using (OpenCbsCommand cmd = new OpenCbsCommand(sqlText, conn))
                {
                    cmd.AddParam("@entity_id", entityId);

                    using (OpenCbsReader reader = cmd.ExecuteReader())
                    {
                        if (reader.Empty)
                        {
                            return(string.Empty);
                        }
                        while (reader.Read())
                        {
                            commaStr.Add(reader.GetString("name"));
                        }
                    }
                }

            return(commaStr.ToString());
        }
Esempio n. 8
0
        public void RO_Add()
        {
            CommaDelimitedStringCollection c = new CommaDelimitedStringCollection();

            c.SetReadOnly();
            c.Add("hi");
        }
Esempio n. 9
0
        public void RO_Insert()
        {
            CommaDelimitedStringCollection c = new CommaDelimitedStringCollection();

            c.Add("hi");
            c.SetReadOnly();
            c.Insert(0, "bye");
        }
Esempio n. 10
0
        private CommaDelimitedStringCollection MemorySavingDoubleBufferCheck()
        {
            CommaDelimitedStringCollection memSaving = new CommaDelimitedStringCollection();

            if (cbMemoryAppList.Checked)
            {
                memSaving.Add("dgvAppList");
            }
            if (cbMemoryAppListRules.Checked)
            {
                memSaving.Add("dgvAppListRules");
            }
            if (cbMemoryUnassignedAppList.Checked)
            {
                memSaving.Add("dgvUnassignedList");
            }
            return(memSaving);
        }
Esempio n. 11
0
        private string GetRolesDelimitedByComma(List <RolDto> roles)
        {
            CommaDelimitedStringCollection list = new CommaDelimitedStringCollection();

            foreach (RolDto rol in roles)
            {
                list.Add(rol.Codigo);
            }
            return(list.ToString());
        }
Esempio n. 12
0
        public static string ConvertStringListToCommaSeparatedString(this List <string> list)
        {
            var coll = new CommaDelimitedStringCollection();

            foreach (var s in list)
            {
                coll.Add(s);
            }
            return(coll.ToString());
        }
Esempio n. 13
0
        private static void GetColumns <T>(Expression <Func <T, object> > order, CommaDelimitedStringCollection cols)
        {
            if (order == null)
            {
                return;
            }
            var orders = order.Body.Type.GetProperties();

            foreach (var da in orders)
            {
                cols.Add(da.Name);
            }
        }
        public override string GetInQueryValues(string values, bool encode)
        {
            CommaDelimitedStringCollection strings = new CommaDelimitedStringCollection();

            string[] textArray = values.Split(new char[] { ',' });
            foreach (string text2 in textArray)
            {
                string text = text2.Trim();
                if (!string.IsNullOrEmpty(text))
                {
                    strings.Add(this.Parameters.GetParameter(text));
                }
            }
            return(strings.ToString());
        }
Esempio n. 15
0
        public static string ConvertBookmakListToCommaSeparatedString(this ReadOnlyCollection <BookmarkInfo> bookmarks)
        {
            var coll = new CommaDelimitedStringCollection();

            //var actioncoll = new CommaDelimitedStringCollection();
            foreach (var b in bookmarks)
            {
                //actioncoll.Clear();
                //foreach (string s in b.BookMarkActions)
                //{
                //    actioncoll.Add(s);
                //}
                //var output = b.Name + (actioncoll.Count > 0 ? "-" + actioncoll.ToString() : "");
                coll.Add(b.BookmarkName);
            }
            return(coll.ToString());
        }
        public override String GetInQueryValues(string values, bool encode)
        {
            CommaDelimitedStringCollection csv = new CommaDelimitedStringCollection();

            String[] split = values.Split(',');
            String   temp;

            foreach (string value in split)
            {
                temp = value.Trim();
                if (!string.IsNullOrEmpty(temp))
                {
                    csv.Add(Parameters.GetParameter(temp));
                }
            }
            return(csv.ToString());
        }
Esempio n. 17
0
        public static string Encode(string[] values, bool surround)
        {
            if ((values == null) || (values.Length < 1))
            {
                return(NULL);
            }
            CommaDelimitedStringCollection strings = new CommaDelimitedStringCollection();

            foreach (string text in values)
            {
                if (!string.IsNullOrEmpty(text))
                {
                    strings.Add(Encode(text.Trim(), surround));
                }
            }
            return(strings.ToString());
        }
Esempio n. 18
0
        /// <summary>
        /// Encodes the specified values for use in SQL expressions and
        /// optionally surrounds the value with single-quotes.
        /// </summary>
        /// <param name="values"></param>
        /// <param name="surround"></param>
        /// <returns></returns>
        public static String Encode(String[] values, bool surround)
        {
            if (values == null || values.Length < 1)
            {
                return(SqlUtil.NULL);
            }

            CommaDelimitedStringCollection csv = new CommaDelimitedStringCollection();

            foreach (String value in values)
            {
                if (!String.IsNullOrEmpty(value))
                {
                    csv.Add(SqlUtil.Encode(value.Trim(), surround));
                }
            }

            return(csv.ToString());
        }
Esempio n. 19
0
        private OracleCommand GetMappedUpdateCommand(object entity, KeyValuePair <Mapper, Type> map)
        {
            if (ConnectionMode == Enums.Mode.UnitOfWork && !insertCommands.Where(a => a.Equals(entity)).Any())
            {
                updateCommands.Add(entity);
                return(null);
            }
            OracleCommand cmd         = new OracleCommand();
            string        commandText = string.Empty;
            CommaDelimitedStringCollection columns = new CommaDelimitedStringCollection();

            StringBuilder where = new StringBuilder();
            foreach (var column in map.Key.Columns)
            {
                var prop  = entity.GetType().GetProperty(column.ColumnName);
                var value = prop.GetValue(entity, null);
                if (column.IsPk)
                {
                    where.Append(String.Format("{0} = :{0} AND", column.ColumnName));
                    cmd.Parameters.Add(new OracleParameter(column.ColumnName, value));
                }
                else
                {
                    columns.Add(String.Format("{0} = :{0},", column.ColumnName));
                    if (column.Nullable && value == null)
                    {
                        cmd.Parameters.Add(new OracleParameter(column.ColumnName, DBNull.Value));
                    }
                    else
                    {
                        cmd.Parameters.Add(new OracleParameter(column.ColumnName, value));
                    }
                }
            }
            where.Remove(where.Length - 3, 3);
            commandText = String.Format("UPDATE {0}.{1} SET {2} WHERE {3}",
                                        _schemmaName,
                                        entity.GetType().Name,
                                        columns.ToString(),
                                        where.ToString());
            cmd.CommandText = commandText;
            return(cmd);
        }
Esempio n. 20
0
        /// <summary>
        /// Updates and returns the value of the DataParameter object.
        /// </summary>
        /// <param name="context">The current System.Web.HttpContext of the request.</param>
        /// <param name="control">The System.Web.UI.Control that the parameter is bound to.</param>
        /// <returns>A System.Object that represents the updated and current value of the parameter.</returns>
        protected override Object Evaluate(HttpContext context, Control control)
        {
            String value = String.Empty;

            if (_dataSource == null && control != null)
            {
                _dataSource = control.FindControl(DataSourceID) as IListDataSource;
            }
            if (_dataSource != null)
            {
                IEnumerable entityList = _dataSource.GetEntityList();

                if (entityList != null)
                {
                    CommaDelimitedStringCollection values = new CommaDelimitedStringCollection();
                    String propertyName = PropertyName ?? EntityKeyName;
                    IList  list         = EntityUtil.GetEntityList(entityList);
                    Object temp;

                    foreach (Object item in list)
                    {
                        temp = EntityUtil.GetPropertyValue(item, EntityKeyName);

                        if (temp != null)
                        {
                            values.Add(String.Format("'{0}'", temp));
                        }
                    }

                    if (values.Count > 0)
                    {
                        value = String.Format("{0} IN ({1})", propertyName, values.ToString());
                    }
                }
            }

            return(value);
        }
Esempio n. 21
0
        /// <summary>
        /// Returns only those principals already added to an operation. Given a list of principals, you might want to
        /// know which one(s) have been included for a specific operation.
        /// </summary>
        public CommaDelimitedStringCollection FindIncludedPrincipals(string[] principals, string operation)
        {
            var includedPrincipals = new CommaDelimitedStringCollection();

            var key = StringHelper.Sanitize(operation);

            if (key == null || !_principals.ContainsKey(key))
            {
                return(includedPrincipals);
            }

            var value = _principals[key];

            foreach (var principal in principals)
            {
                var p = StringHelper.Sanitize(principal);
                if (value.Contains(p))
                {
                    includedPrincipals.Add(p);
                }
            }

            return(includedPrincipals);
        }
        protected void StartWorkflowButtonClick(object sender, EventArgs e)
        {
            var ids = Request["ids"].Split(',').ToList().ConvertAll(Convert.ToInt32);

            var workflowConfigId = Convert.ToInt32(AvailableCriteriaDropDownList.SelectedValue);
            var comment          = string.IsNullOrEmpty(InstantiationCommentTextBox.Text) ? TheGlobalisationService.GetString("no_comment_supplied") : InstantiationCommentTextBox.Text;

            // TODO: custom workflow variables?

            Log.Info(string.Format("Instantiating workflow {0}: {1}", workflowConfigId, comment));

            var inst = TheWorkflowInstanceService.Instantiate(workflowConfigId, comment);

            var flags = new CommaDelimitedStringCollection();

            foreach (ListItem item in FlagsCheckBoxList.Items)
            {
                if (item.Selected)
                {
                    flags.Add(TheGlobalisationService.GetString(item.Text));
                }
            }

            inst.Flags = flags.ToString();

            foreach (var id in ids)
            {
                ((UmbracoWorkflowInstance)inst).CmsNodes.Add(id);
            }

            TheWorkflowInstanceService.Update(inst);
            TheWorkflowInstanceService.Start(inst.Id);

            TheWorkflowRuntime.RunWorkflows();
            SavedLiteral.Visible = true;
        }
        private static StringCollection ValidateTable(DataTable table)
        {
            var problems = new CommaDelimitedStringCollection();

            if (!table.Columns.Contains("Principal"))
            {
                problems.Add("Missing Column: Principal");
            }

            if (!table.Columns.Contains("Operation"))
            {
                problems.Add("Missing Column: Operation");
            }

            if (!table.Columns.Contains("Resource"))
            {
                problems.Add("Missing Column: Resource");
            }

            for (var i = 0; i < table.Rows.Count; i++)
            {
                if (table.Rows[i].IsNull("Principal"))
                {
                    problems.Add(string.Format("Missing Principal on Row {0:n0}", i + 1));
                }

                if (table.Rows[i].IsNull("Operation"))
                {
                    problems.Add(string.Format("Missing Operation on Row {0:n0}", i + 1));
                }

                if (table.Rows[i].IsNull("Resource"))
                {
                    problems.Add(string.Format("Missing Resource on Row {0:n0}", i + 1));
                }
            }

            return(problems);
        }
        private async void ReadFromBilagscan(UnicontaBaseEntity selectedItem)
        {
#if !SILVERLIGHT
            if (!readingFromBilagscan)
            {
                readingFromBilagscan = true;

                bool processLines = false;
                var  accessToken  = await Bilagscan.Account.GetBilagscanAccessToken(api);

                var noOfVouchers    = 0;
                var companySettings = await api.Query <CompanySettingsClient>();

                var orgNo = companySettings.FirstOrDefault()._OrgNumber;

                var journal = dgGldailyJournal.SelectedItem as GLDailyJournalClient;

                //  UnicontaBaseEntity[] baseEntityArray = new UnicontaBaseEntity[1] { selectedItem };

                using (var client = new HttpClient())
                {
                    client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
                    var response = await client.GetAsync($"https://api.bilagscan.dk/v1/organizations/" + orgNo.ToString() + "/vouchers?seen=false&count=100&offset=0&sorts=-upload_date&status=successful");

                    var content = await response.Content.ReadAsStringAsync();

                    var vouchers = Bilagscan.Voucher.GetVouchers(content);

                    var credCache = api.CompanyEntity.GetCache(typeof(Uniconta.DataModel.Creditor)) ?? await api.CompanyEntity.LoadCache(typeof(Uniconta.DataModel.Creditor), api);

                    var offsetCache = api.CompanyEntity.GetCache(typeof(Uniconta.DataModel.GLAccount)) ?? await api.CompanyEntity.LoadCache(typeof(Uniconta.DataModel.GLAccount), api);

                    var vouchersSeen = new CommaDelimitedStringCollection();

                    var master = new List <UnicontaBaseEntity>
                    {
                        journal
                    };

                    var newLines       = new List <UnicontaBaseEntity>();
                    var updateCreditor = new List <UnicontaBaseEntity>();

                    if (vouchers?.data != null)
                    {
                        var creditors = credCache.GetKeyStrRecords as Uniconta.DataModel.Creditor[];

                        foreach (var voucher in vouchers.data)
                        {
                            vouchersSeen.Add(NumberConvert.ToString(voucher.id));
                            var journalLine = new GLDailyJournalLineClient()
                            {
                                Approved        = false,
                                ForceSettlement = false
                            };

                            var postingType = BilagscanVoucherType.Invoice;

                            var hint = Bilagscan.Voucher.GetHint(voucher.note);

                            var bilagscanRefID = voucher.id;
                            journalLine.ReferenceNumber = bilagscanRefID != 0 ? NumberConvert.ToString(bilagscanRefID) : null;

                            var bsItem = voucher.header_fields.Where(hf => string.Compare(hf.code, "voucher_number", true) == 0).FirstOrDefault();
                            if (bsItem != null)
                            {
                                journalLine.Invoice = bsItem.value;
                            }

                            bsItem = voucher.header_fields.Where(hf => string.Compare(hf.code, "voucher_type", true) == 0).FirstOrDefault();
                            if (bsItem != null)
                            {
                                switch (bsItem.value)
                                {
                                case "invoice": postingType = BilagscanVoucherType.Invoice; break;

                                case "creditnote": postingType = BilagscanVoucherType.Creditnote; break;

                                case "receipt": postingType = BilagscanVoucherType.Receipt; break;
                                }
                            }

                            var creditorCVR = string.Empty;
                            bsItem = voucher.header_fields.Where(hf => string.Compare(hf.code, "company_vat_reg_no", true) == 0).FirstOrDefault();
                            if (bsItem != null)
                            {
                                creditorCVR = bsItem.value;
                            }

                            bsItem = voucher.header_fields.Where(hf => string.Compare(hf.code, "total_amount_incl_vat", true) == 0).FirstOrDefault();
                            if (bsItem != null)
                            {
                                journalLine.Amount = Math.Abs(NumberConvert.ToDoubleNoThousandSeperator(bsItem.value));

                                if (postingType != BilagscanVoucherType.Creditnote)
                                {
                                    journalLine.Amount = -journalLine.Amount;
                                }
                            }

                            CountryCode countryCode = CountryCode.Denmark;
                            bsItem = voucher.header_fields.Where(hf => string.Compare(hf.code, "country", true) == 0).FirstOrDefault();
                            if (bsItem != null)
                            {
                                CountryISOCode countryISO;
                                countryCode = CountryCode.Denmark; //default
                                if (Enum.TryParse(bsItem.value, true, out countryISO))
                                {
                                    countryCode = (CountryCode)countryISO;
                                }
                            }

                            bsItem = voucher.header_fields.Where(hf => string.Compare(hf.code, "invoice_date", true) == 0).FirstOrDefault();
                            if (bsItem != null)
                            {
                                var invoiceDate = bsItem.value == string.Empty ? GetSystemDefaultDate() : StringSplit.DateParse(bsItem.value, DateFormat.ymd);
                                journalLine.Date = invoiceDate;

                                if (journalLine.Date == DateTime.MinValue)
                                {
                                    journalLine.Date = GetSystemDefaultDate();
                                }
                            }

                            bsItem = voucher.header_fields.Where(hf => string.Compare(hf.code, "payment_date", true) == 0).FirstOrDefault();
                            if (bsItem != null)
                            {
                                var paymentDate = bsItem.value == string.Empty ? DateTime.MinValue : StringSplit.DateParse(bsItem.value, DateFormat.ymd);
                                journalLine._DueDate = paymentDate;
                            }

                            bsItem = voucher.header_fields.Where(hf => string.Compare(hf.code, "currency", true) == 0).FirstOrDefault();
                            if (bsItem != null)
                            {
                                Currencies currencyISO;
                                if (!Enum.TryParse(bsItem.value, true, out currencyISO))
                                {
                                    currencyISO = Currencies.DKK; //default
                                }
                                journalLine._Currency = (byte)currencyISO;
                            }

                            string bbanAcc = null;
                            bsItem = voucher.header_fields.Where(hf => string.Compare(hf.code, "payment_account_number", true) == 0).FirstOrDefault();
                            if (bsItem != null)
                            {
                                bbanAcc = bsItem.value;
                            }

                            string bbanRegNum = null;
                            bsItem = voucher.header_fields.Where(hf => string.Compare(hf.code, "payment_reg_number", true) == 0).FirstOrDefault();
                            if (bsItem != null)
                            {
                                bbanRegNum = bsItem.value;
                            }

                            string ibanNo = null;
                            bsItem = voucher.header_fields.Where(hf => string.Compare(hf.code, "payment_iban", true) == 0).FirstOrDefault();
                            if (bsItem != null)
                            {
                                ibanNo = bsItem.value;
                            }

                            string swiftNo = null;
                            bsItem = voucher.header_fields.Where(hf => string.Compare(hf.code, "payment_swift_bic", true) == 0).FirstOrDefault();
                            if (bsItem != null)
                            {
                                swiftNo = bsItem.value;
                            }

                            string paymentCodeId = null;
                            bsItem = voucher.header_fields.Where(hf => string.Compare(hf.code, "payment_code_id", true) == 0).FirstOrDefault();
                            if (bsItem != null)
                            {
                                paymentCodeId = bsItem.value;
                            }

                            string paymentId = null;
                            bsItem = voucher.header_fields.Where(hf => string.Compare(hf.code, "payment_id", true) == 0).FirstOrDefault();
                            if (bsItem != null)
                            {
                                paymentId = bsItem.value;
                            }

                            string jointPaymentId = null;
                            bsItem = voucher.header_fields.Where(hf => string.Compare(hf.code, "joint_payment_id", true) == 0).FirstOrDefault();
                            if (bsItem != null)
                            {
                                jointPaymentId = bsItem.value;
                            }

                            var paymentMethod = PaymentTypes.VendorBankAccount;
                            switch (paymentCodeId)
                            {
                            case "71": paymentMethod = PaymentTypes.PaymentMethod3; break;

                            case "73": paymentMethod = PaymentTypes.PaymentMethod4; break;

                            case "75": paymentMethod = PaymentTypes.PaymentMethod5; break;

                            case "04":
                            case "4": paymentMethod = PaymentTypes.PaymentMethod6; break;
                            }

                            if (paymentMethod != PaymentTypes.VendorBankAccount && (paymentId != null || jointPaymentId != null))
                            {
                                journalLine._PaymentMethod = paymentMethod;
                                journalLine._PaymentId     = string.Format("{0} +{1}", paymentId, jointPaymentId);
                            }
                            else if (bbanRegNum != null && bbanAcc != null)
                            {
                                journalLine._PaymentMethod = PaymentTypes.VendorBankAccount;
                                journalLine._PaymentId     = string.Format("{0}-{1}", bbanRegNum, bbanAcc);
                            }
                            else if (swiftNo != null && ibanNo != null)
                            {
                                journalLine._PaymentMethod = PaymentTypes.IBAN;
                                journalLine._PaymentId     = ibanNo;
                            }

                            journalLine.SettleValue = "Voucher";

                            Uniconta.DataModel.Creditor creditor = null;

                            if (hint != null)
                            {
                                journalLine._DocumentRef = hint.RowId;
                                //if (hint.CreditorAccount != null)
                                //    creditor = (Uniconta.DataModel.Creditor)credCache.Get(hint.CreditorAccount);
                                //if (hint.Amount != 0)
                                //    journalLine.Amount = hint.Amount;
                                //if (hint.Currency != null && hint.Currency != "-")
                                //    journalLine.Currency = hint.Currency;
                                //if (hint.PaymentId != null)
                                //{
                                //    journalLine._PaymentId = hint.PaymentId;
                                //    journalLine.PaymentMethod = hint.PaymentMethod;
                                //}
                            }

                            journalLine._AccountType = 2;

                            var creditorCVRNum = Regex.Replace(creditorCVR, "[^0-9]", string.Empty);

                            if (creditorCVRNum != string.Empty)
                            {
                                creditor = creditors.Where(s => (Regex.Replace(s._LegalIdent ?? string.Empty, "[^0-9.]", "") == creditorCVRNum)).FirstOrDefault();
                            }

                            if (creditorCVRNum == string.Empty)
                            {
                                journalLine.Text = Uniconta.ClientTools.Localization.lookup("NotValidVatNo");
                            }
                            else if (creditor == null)
                            {
                                var newCreditor = new CreditorClient()
                                {
                                    _Account       = creditorCVR,
                                    _LegalIdent    = creditorCVR,
                                    _PaymentMethod = journalLine._PaymentMethod,
                                    _PaymentId     = journalLine._PaymentId,
                                    _SWIFT         = swiftNo
                                };

                                CompanyInfo companyInformation = null;
                                try
                                {
                                    companyInformation = await CVR.CheckCountry(creditorCVR, countryCode);
                                }
                                catch (Exception ex)
                                {
                                    UnicontaMessageBox.Show(ex);
                                    return;
                                }

                                if (companyInformation != null)
                                {
                                    if (companyInformation.life != null)
                                    {
                                        newCreditor._Name = companyInformation.life.name;
                                    }

                                    if (companyInformation.address != null)
                                    {
                                        newCreditor._Address1 = companyInformation.address.CompleteStreet;
                                        newCreditor._ZipCode  = companyInformation.address.zipcode;
                                        newCreditor._City     = companyInformation.address.cityname;
                                        newCreditor._Country  = companyInformation.address.Country;
                                    }

                                    if (companyInformation.contact != null)
                                    {
                                        newCreditor._Phone        = companyInformation.contact.phone;
                                        newCreditor._ContactEmail = companyInformation.contact.email;
                                    }

                                    journalLine.Text = newCreditor.Name;
                                }
                                else
                                {
                                    newCreditor.Name = Uniconta.ClientTools.Localization.lookup("NotValidVatNo");
                                }

                                await api.Insert(newCreditor);

                                journalLine.Account = creditorCVR;
                            }
                            else
                            {
                                if (!string.IsNullOrEmpty(creditor._PostingAccount))
                                {
                                    var account = (GLAccountClient)offsetCache.Get(creditor._PostingAccount);
                                    if (!string.IsNullOrEmpty(account.Vat))
                                    {
                                        var dailyJournal = (GLDailyJournalClient)master[0];
                                        if (dailyJournal.TwoVatCodes)
                                        {
                                            journalLine._OffsetVat = account.Vat;
                                        }
                                        else
                                        {
                                            journalLine._Vat = account.Vat;
                                        }
                                    }

                                    journalLine._OffsetAccount = creditor._PostingAccount;
                                }
                                else
                                {
                                    journalLine.Vat = creditor._Vat;
                                }


                                if (journalLine._DueDate == DateTime.MinValue && creditor._Payment != string.Empty)
                                {
                                    var paymentTermsCache = api.GetCache(typeof(PaymentTerm)) ?? await api.LoadCache(typeof(PaymentTerm));

                                    var paymentTerm = (PaymentTerm)paymentTermsCache.Get(creditor._Payment);

                                    if (paymentTerm != null)
                                    {
                                        journalLine._DueDate = paymentTerm.GetDueDate(journalLine.DueDate);
                                    }
                                }

                                journalLine.Account = creditor._Account;
                                journalLine.Text    = creditor._Name;

                                if (creditor._SWIFT == null && swiftNo != null)
                                {
                                    creditor._SWIFT = swiftNo;
                                    updateCreditor.Add(creditor);
                                }
                            }

                            journalLine.SetMaster(master[0]);
                            newLines.Add(journalLine);

                            noOfVouchers += 1;
                        }
                    }
                    var errorCode = await api.Insert(newLines);

                    api.UpdateNoResponse(updateCreditor);

                    if (vouchersSeen.Count != 0)
                    {
                        // Mark voucher as seen
                        string serializedRequest = "{ \"vouchers\": [ " + vouchersSeen.ToString() + " ] }";
                        var    vContent          = new StringContent(serializedRequest, Encoding.UTF8, "application/json");
                        response = await client.PostAsync($"https://api.bilagscan.dk/v1/organizations/" + NumberConvert.ToString(orgNo) + "/vouchers/seen", vContent);

                        var res = await response.Content.ReadAsStringAsync();
                    }
                }

                if (noOfVouchers == 0)
                {
                    UnicontaMessageBox.Show(string.Format(Uniconta.ClientTools.Localization.lookup("StillProcessingTryAgain"), Uniconta.ClientTools.Localization.lookup("Bilagscan")), Uniconta.ClientTools.Localization.lookup("Bilagscan"), MessageBoxButton.OK, MessageBoxImage.Information);
                }
                else
                {
                    var messageText = string.Concat(string.Format("{0} {1}", Uniconta.ClientTools.Localization.lookup("NumberOfImportedVouchers"), noOfVouchers),
                                                    Environment.NewLine, Environment.NewLine,
                                                    string.Format(Uniconta.ClientTools.Localization.lookup("GoTo"), Uniconta.ClientTools.Localization.lookup("Journallines")), "?");
                    if (UnicontaMessageBox.Show(messageText, Uniconta.ClientTools.Localization.lookup("BilagscanRead"), MessageBoxButton.OKCancel, MessageBoxImage.Information) == MessageBoxResult.OK)
                    {
                        AddDockItem(TabControls.GL_DailyJournalLine, journal, null, null, true);
                    }
                }
                readingFromBilagscan = false;
            }
#endif
        }
Esempio n. 25
0
        /// <summary>
        /// Converts the generic parameters.
        /// </summary>
        /// <param name="node">The node.</param>
        /// <param name="methodName">Name of the method.</param>
        /// <param name="attribute">attribute = name / param / typeparam.</param>
        /// <returns>converted name</returns>
        public static string ConvertGenericParameters(XElement node, string methodName, string attribute)
        {
            //Seperate the method name and paramaeters (ex: Func(a,b) = [Func] + [a,b])
            var methodParams = methodName.Split('(', ')');
            var stringList   = new CommaDelimitedStringCollection();

            if (methodParams.Count() > 1)
            {
                //Store the method name. the method name is Dynamo.Test.Test(int).
                //so splitting by . to get the method name as Test(int)
                methodName = methodParams[0].Split('.').Last();
                //Split the Parameters (ex: (a,b) = [a], [b])
                methodParams = methodParams[1].Split(',');
                int i = 0;
                foreach (var param in node.Elements(attribute))
                {
                    //when you add a parameter to a function, there is a possibility that comment is
                    //not updated immediately. In that case add the param name to only those parameters
                    //in the method name
                    if (methodParams.Count() > i)
                    {
                        //Extract only the classname , not the entire namespace
                        var className = string.Empty;
                        if (methodParams[i].Contains("Dynamo"))
                        {
                            className = methodParams[i].Split('.').Last();
                            className = className.ConstructUrl(methodParams[i]);
                        }
                        else
                        {
                            className = methodParams[i].Split('.').Last();
                        }

                        stringList.Add(className.MarkDownFormat("Italic") + " " + param.Attribute("name").Value);
                    }
                    i++;
                }
                //case 1: Param tag on the method.
                if (stringList.Count > 0)
                {
                    methodName = methodName + "(" + stringList + ")";
                }
                //case 1: No Param tag on the method.
                else
                {
                    methodName = methodName + "(" + methodParams[0] + ")";
                }

                //add api_stability as super script. If there is no stability tag
                //then add a default value.
                methodName = "&nbsp;&nbsp;" + methodName;
                methodName = CheckAndAppendStability(node, methodName);
            }
            else
            {
                if (methodName.Contains("."))
                {
                    methodName = methodName.Split('.').Last();
                    methodName = methodName + "( )";
                }
                methodName = "&nbsp;&nbsp;" + methodName;
                methodName = CheckAndAppendStability(node, methodName);
            }

            return(methodName);
        }