Example #1
0
 private void gridView4_KeyDown(object sender, KeyEventArgs e)
 {
     if (e.KeyCode == Keys.Delete)
     {
         DialogResult result = FormUtility.MsgDelete();
         CurrencyUnit unit   = utility.GetSelectedItem <CurrencyUnit>();
         int          index  = gridView4.GetSelectedRows()[0];
         if (result == DialogResult.Yes)
         {
             try
             {
                 using (IUnitOfWork uow = new UnitOfWork())
                 {
                     uow.CurrencyUnitRepository.Remove(unit);
                     uow.Commit();
                 }
                 gridView4.DeleteRow(index);
                 labelNotify1.SetText(UI.removesuccess, ToolBoxCS.LabelNotify.EnumStatus.Success);
             }
             catch
             {
                 labelNotify1.SetText(UI.removefailed, ToolBoxCS.LabelNotify.EnumStatus.Failed);
             }
         }
     }
 }
Example #2
0
 public static Money Of(decimal amount, CurrencyUnit unit)
 {
     return(new Money()
     {
         Amount = amount, Unit = unit
     });
 }
        private void FillFromExcelDocument(string fileName, XElement xDeclarationsHolder)
        {
            var etbUnit = new CurrencyUnit("ETB");

            Instance.Units.Add(etbUnit);

            var quarter1Of2018        = new DurationPeriod(new DateTime(2018, 1, 1), new DateTime(2018, 3, 31));
            var startOfQuarter1Of2018 = new InstantPeriod(new DateTime(2017, 12, 31));
            var endOfQuarter1Of2018   = new InstantPeriod(new DateTime(2018, 3, 31));

            Instance.Periods.Add(quarter1Of2018);
            Instance.Periods.Add(startOfQuarter1Of2018);
            Instance.Periods.Add(endOfQuarter1Of2018);

            var wsi = new Entity
            {
                Id = "wsi",
                IdentifierScheme = new Uri("http://www.sec.gov/CIK"),
                Identifier       = "WSI",
                Name             = "Walia Steel Industry PLC"
            };

            Instance.Entities.Add(wsi);

            var package   = new ExcelPackage(new FileInfo(fileName));
            var worksheet = package.Workbook.Worksheets[1];

            ExcelRangeBase conceptCell         = worksheet.Cells["B2"];
            ExcelRangeBase valueCell           = worksheet.Cells["C2"];
            ExcelRangeBase startDateCell       = worksheet.Cells["D2"];
            ExcelRangeBase dateOrEndDateCell   = worksheet.Cells["E2"];
            ExcelRangeBase explicitMembersCell = worksheet.Cells["F2"];

            while (conceptCell.Value != null && valueCell.Value != null)
            {
                var concept = conceptCell.GetValue <string>();
                var value   = valueCell.Value;
                var period  = startDateCell.Value == null || string.IsNullOrEmpty(startDateCell.Value.ToString()) ?
                              new InstantPeriod(dateOrEndDateCell.GetValue <DateTime>()) :
                              (Period) new DurationPeriod(startDateCell.GetValue <DateTime>(), dateOrEndDateCell.GetValue <DateTime>());

                var conceptName = ToXName(concept, xDeclarationsHolder);
                var fact        = new Fact(conceptName, wsi, period)
                {
                    Unit          = etbUnit,
                    Value         = value.ToString(),
                    BalanceMethod = BalanceMethod.Algebraic
                };

                AddExplicitMembers(fact, explicitMembersCell.Value, xDeclarationsHolder);

                Instance.Facts.Add(fact);

                conceptCell         = conceptCell.Offset(1, 0);
                valueCell           = valueCell.Offset(1, 0);
                startDateCell       = startDateCell.Offset(1, 0);
                dateOrEndDateCell   = dateOrEndDateCell.Offset(1, 0);
                explicitMembersCell = explicitMembersCell.Offset(1, 0);
            }
        }
Example #4
0
 public Location(string name, CurrencyUnit currencyUnit, decimal?latitude = null, decimal?longitude = null)
 {
     Name         = name;
     Latitude     = latitude;
     Longitude    = longitude;
     CurrencyUnit = currencyUnit;
 }
Example #5
0
        public List <CurrencyUnit> GetCurrencyUnitsByCurrency(string language, string currencyID)
        {
            List <CurrencyUnit> theList = new List <CurrencyUnit>();
            CurrencyUnit        theData = null;

            try
            {
                CurrencyDS.CurrencyUnitsForCurrencyDataTable theTable = theAdapter.GetCurrencyUnitByCurrency(language, currencyID);

                if (theTable != null && theTable.Rows.Count > 0)
                {
                    foreach (CurrencyDS.CurrencyUnitsForCurrencyRow theRow in theTable.Rows)
                    {
                        theData = FillRecord(theRow);
                        theList.Add(theData);
                    }
                }
            }
            catch (Exception exc)
            {
                log.Error("Ocurrió un error al obtener la lista de CurrencyUnits de la Base de Datos", exc);
                throw exc;
            }

            return(theList);
        }
Example #6
0
        public override void WriteIntro(Entity entity, CurrencyUnit unit)
        {
            Substitute(_document, Placeholders.Entity, entity.Name);
            Substitute(_document, Placeholders.Currency, unit.Iso4217Code);

            var scaleText = Math.Pow(10, _settings.Scale).ToString("N0", _settings.Culture);

            Substitute(_document, Placeholders.Scale, scaleText);
        }
        public override void WriteIntro(Entity entity, CurrencyUnit unit)
        {
            _xBody.Substitute(EntityId, entity.Name);
            _xBody.Substitute(CurrencyId, unit.Iso4217Code);

            var scaleText = Math.Pow(10, _settings.Scale).ToString("N0", _settings.Culture);

            _xBody.Substitute(ScaleId, scaleText);
        }
        public CurrencyPair(CurrencyUnit @base, CurrencyUnit counter)
        {
            Contract.Requires(() => @base != null, $"{nameof(@base)} may not be null");
            Contract.Requires(() => counter != null, $"{nameof(counter)} may not be null");

            Symbol  = $"{@base.Symbol.ToUpper()}/{counter.Symbol.ToUpper()}";
            Base    = @base;
            Counter = counter;
        }
        public decimal GetRate(CurrencyUnit unitFrom, CurrencyUnit unitTo, DateTime date)
        {
            // we ignore date

            return
                (unitFrom == CurrencyUnit.EUR && unitTo == CurrencyUnit.PLN ? 0.25m :
                 unitFrom == CurrencyUnit.EUR && unitTo == CurrencyUnit.GBP ? 1.1m :
                 1);
        }
Example #10
0
        private static CurrencyUnit FillRecord(CurrencyDS.CurrencyUnitsForCurrencyRow row)
        {
            CurrencyUnit theNewRecord = new CurrencyUnit(
                row.currencyID,
                row.currencyUnitID,
                row.name,
                row.IshasMeasureNull() ? false : row.hasMeasure);

            return(theNewRecord);
        }
 /// <summary>
 /// Creates a Vehicle object using a DataRow. Used when retrieving vehicles from the database.
 /// </summary>
 /// <param name="dataRow">A DataRow object with data fetched from the database.</param>
 public Vehicle(DataRow dataRow)
 {
     VehicleID                  = Convert.ToInt32(dataRow["VEHICLE_ID"]);
     NameShort                  = dataRow["NAME"].ToString();
     PriceOriginal              = float.Parse(dataRow["PRICE_ORIGINAL"].ToString());
     ConsumptionCityOriginal    = float.Parse(dataRow["CONSUMPTION_CITY_ORIGINAL"].ToString());
     ConsumptionHighwayOriginal = float.Parse(dataRow["CONSUMPTION_HIGHWAY_ORIGINAL"].ToString());
     ConsumptionUnitOriginal    = (ConsumptionUnit)Convert.ToInt32(dataRow["CONSUMPTION_UNIT_INDEX_ORIGINAL"]);
     CurrencyUnitOriginal       = (CurrencyUnit)Convert.ToInt32(dataRow["CURRENCY_UNIT_INDEX_ORIGINAL"]);
 }
Example #12
0
        public void UpdateBalance()
        {
            if (isValid2)
            {
                tbBlance.Text = (accountBalance = _GetBalance(cbAccount.SelectedItem)).AmountInCreacoin.Amount.ToString();

                if (isValid4 && isValid5)
                    TotalValidate();
            }

            Validate();
        }
Example #13
0
        // Added for symmetry, but use with care.
        public TCurrency ToCurrency <TCurrency>() where TCurrency : Currency <TCurrency>
        {
            TCurrency unit = CurrencyUnit.OfType <TCurrency>();

            if (Code != unit.Code)
            {
                throw new InvalidCastException(
                          Format.Current(Strings_Money.CurrencyMismatch, Code, unit.Code));
            }

            return(unit);
        }
Example #14
0
        private void gridView4_DoubleClick(object sender, EventArgs e)
        {
            GridView    gridView = sender as GridView;
            GridHitInfo info     = gridView.CalcHitInfo(gridView.GridControl.PointToClient(MousePosition));

            if (info.InRow || info.InRowCell)
            {
                CurrencyUnit        unit = utility.GetSelectedItem <CurrencyUnit>();
                frmEditCurrencyUnit obj  = new frmEditCurrencyUnit(unit);
                obj.updateCurrencyUnit = InsertOrUpdate;
                obj.ShowDialog();
            }
        }
Example #15
0
        public void UpdateBalance()
        {
            if (isValid2)
            {
                tbBlance.Text = (accountBalance = _GetBalance(cbAccount.SelectedItem)).AmountInCreacoin.Amount.ToString();

                if (isValid4 && isValid5)
                {
                    TotalValidate();
                }
            }

            Validate();
        }
        /// <summary>Constructor helper</summary>
        /// <param name="baseVal">Value exclusive or inclusive VAT</param>
        /// <param name="vatRate">VAT rate (in %)</param>
        /// <param name="currencyUnit">Price currency</param>
        /// <param name="base">Specification of 1st parameter: exclusive/inclusive VAT</param>
        /// <exception cref = "PriceException">Thrown when VAT rate is negative</exception>
        private void Create(decimal baseVal, decimal vatRate, CurrencyUnit currencyUnit, PriceBase @base = PriceBase.Excl)
        {
            if (vatRate < 0)
            {
                throw new PriceException(PriceException.VAT_RATE_NEGATIVE);
            }

            VATrate = vatRate;

            exclVAT = @base == PriceBase.Excl ? baseVal : baseVal / VATfactor;

            if (!IsZero)
            {
                CurrencyUnit = currencyUnit.ThrowIfNull(nameof(currencyUnit));
            }
        }
Example #17
0
        public void Slice()
        {
            // Arrange
            var entity = new Entity {
                IdentifierScheme = new Uri("http://www.sec.gov/CIK"), Identifier = "WSI", Id = "wsi", Name = "Walia Steel Industry PLC"
            };
            var unit          = new CurrencyUnit("CHF");
            var duration1     = new DurationPeriod(new DateTime(2017, 1, 1), new DateTime(2017, 12, 31));
            var instant1Start = new InstantPeriod(new DateTime(2016, 12, 31));
            var duration2     = new DurationPeriod(new DateTime(2018, 1, 1), new DateTime(2018, 12, 31));

            var concept1 = new Item {
                Name = "concept1"
            };

            var duration1Fact = new Fact(concept1.Name, entity, duration1)
            {
                Unit = unit, Value = "2017", BalanceMethod = BalanceMethod.Algebraic
            };
            var instant1StartFact = new Fact(concept1.Name, entity, instant1Start)
            {
                Unit = unit, Value = "2017.1", BalanceMethod = BalanceMethod.Algebraic
            };
            var duration2Fact = new Fact(concept1.Name, entity, duration2)
            {
                Unit = unit, Value = "2018", BalanceMethod = BalanceMethod.Algebraic
            };
            var facts = new[] { duration1Fact, instant1StartFact, duration2Fact };

            var factSet = new FactSet(facts);

            var duration1Aspect     = new PeriodAspect(duration1);
            var instant1StartAspect = new PeriodAspect(instant1Start);

            var duration1Member = new Member(duration1Aspect);

            duration1Member.RelatedAspects.Add(new RelatedAspect(instant1StartAspect, RelatedAspectRoles.PeriodStart));

            // Act
            var slicedFactSetIncludingRelatedAspects = factSet.Slice(duration1Member, true);
            var slicedFactSetExcludingRelatedAspects = factSet.Slice(duration1Member, false);

            // Assert
            Assert.AreEqual(facts.Length, factSet.FactModels.Count);
            Assert.AreEqual(2, slicedFactSetIncludingRelatedAspects.FactModels.Count);
            Assert.AreEqual(1, slicedFactSetExcludingRelatedAspects.FactModels.Count);
        }
Example #18
0
        //half the amount of const by /the inverse amount
        //

        public double Conversion(CurrencyUnit currencyNew)
        {
            switch (Currency)
            {
            case CurrencyUnit.USD:
                switch (currencyNew)
                {
                case CurrencyUnit.EUR:
                    return(Amount * USDtoEUR);

                case CurrencyUnit.CNY:
                    return(Amount * USDtoCNY);

                default:
                    return(0.0);
                }

            case CurrencyUnit.EUR:
                switch (currencyNew)
                {
                case CurrencyUnit.USD:
                    return(Amount * EURtoUSD);

                case CurrencyUnit.CNY:
                    return(Amount * EURtoCNY);

                default:
                    return(0.0);
                }

            case CurrencyUnit.CNY:
                switch (currencyNew)
                {
                case CurrencyUnit.EUR:
                    return(Amount * CNYtoEUR);

                case CurrencyUnit.USD:
                    return(Amount * CNYtoUSD);

                default:
                    return(1.0);
                }
            }
            return(99);
        }
        public static float GetLocalPriceValue(float originalValue, CurrencyUnit originalUnit)
        {
            // These exchange rates are hardcoded and temporary until I write an automatic fetcher of exchange rates.
            const float EUR_TO_USD_RATE   = 1.11f;
            const float EUR_TO_POUND_RATE = 0.85f;
            const float USD_TO_POUND_RATE = 0.77f;

            float convertedValue = originalValue;

            if (originalUnit == CurrencyUnit.EURO)
            {
                if (CurrencyUnit == CurrencyUnit.US_DOLLAR)
                {
                    convertedValue *= EUR_TO_USD_RATE;
                }
                else if (CurrencyUnit == CurrencyUnit.POUND)
                {
                    convertedValue *= EUR_TO_POUND_RATE;
                }
            }
            else if (originalUnit == CurrencyUnit.US_DOLLAR)
            {
                if (CurrencyUnit == CurrencyUnit.EURO)
                {
                    convertedValue *= 1 / EUR_TO_USD_RATE;
                }
                else if (CurrencyUnit == CurrencyUnit.POUND)
                {
                    convertedValue *= USD_TO_POUND_RATE;
                }
            }
            else if (originalUnit == CurrencyUnit.POUND)
            {
                if (CurrencyUnit == CurrencyUnit.EURO)
                {
                    convertedValue *= 1 / EUR_TO_POUND_RATE;
                }
                else if (CurrencyUnit == CurrencyUnit.US_DOLLAR)
                {
                    convertedValue *= 1 / USD_TO_POUND_RATE;
                }
            }

            return((float)Math.Round(convertedValue, 2));
        }
Example #20
0
 // covert currency amount to another currency
 public double Convert(CurrencyUnit toCurrency)
 {
     if (Currency == toCurrency)             // no change
     {
         return(Amount);
     }
     else
     {
         if (toCurrency == CurrencyUnit.Dollar)
         {
             return(Amount * EuroToDollarRate);
         }
         else                                // convert to euro
         {
             return(Amount * DollarToEuroRate);
         }
     }
 }
Example #21
0
        public CurrencyUnit GetCurrencyUnitsById(string language, string currencyId, string currencyUnitId)
        {
            CurrencyUnit theData = null;

            try
            {
                CurrencyDS.CurrencyUnitsForCurrencyDataTable theTable = theAdapter.GetCurrencyUnitByID(language, currencyId, currencyUnitId);

                if (theTable != null && theTable.Rows.Count > 0)
                {
                    theData = FillRecord(theTable[0]);
                }
            }
            catch (Exception exc)
            {
                log.Error("Ocurrió un error al obtener un CurrencyUnit de la Base de Datos", exc);
                throw exc;
            }

            return(theData);
        }
Example #22
0
        public void Aspects_Contains()
        {
            // Arrange
            var entity = new Entity {
                IdentifierScheme = new Uri("http://www.sec.gov/CIK"), Identifier = "WSI", Id = "wsi", Name = "Walia Steel Industry PLC"
            };
            var unit    = new CurrencyUnit("CHF");
            var period1 = new DurationPeriod(new DateTime(2017, 1, 1), new DateTime(2017, 12, 31));
            var period2 = new DurationPeriod(new DateTime(2018, 1, 1), new DateTime(2018, 12, 31));

            var concept1 = new Item {
                Name = "concept1"
            };
            var concept2 = new Item {
                Name = "concept2"
            };

            var fact1 = new Fact(concept1.Name, entity, period1)
            {
                Unit = unit, Value = "2017", BalanceMethod = BalanceMethod.Algebraic
            };
            var fact2 = new Fact(concept1.Name, entity, period2)
            {
                Unit = unit, Value = "2018", BalanceMethod = BalanceMethod.Algebraic
            };
            var facts = new[] { fact1, fact2 };

            var factSet = new FactSet(facts);

            var period1Aspect = new PeriodAspect(period1);

            // Act
            var factModel1            = factSet.FactModels.Single(fm => fm.Fact == fact1);
            var containsPeriod1Aspect = factModel1.Aspects.Contains(period1Aspect);

            // Assert
            Assert.AreEqual(true, containsPeriod1Aspect);
        }
Example #23
0
 public Money(double amt, CurrencyUnit c)
 {
     Currency = c;
     Amount   = amt;
 }
Example #24
0
        private Instance LoadInstanceFromExcelDocument(string fileName)
        {
            XNamespace bSharpNamespace = "http://banan-it.com/taxonomy/2018-07-05/bsharp";
            XNamespace ifrsNamespace   = "http://xbrl.ifrs.org/taxonomy/2017-03-09/ifrs-full";

            var xDeclarationsHolder = new XElement("dummy",
                                                   new XAttribute(XNamespace.Xmlns + "ifrs-full", ifrsNamespace),
                                                   new XAttribute(XNamespace.Xmlns + "banan", bSharpNamespace));

            var instance = new Instance();

            var etbUnit = new CurrencyUnit("ETB");

            instance.Units.Add(etbUnit);

            var quarter1Of2018        = new DurationPeriod(new DateTime(2018, 1, 1), new DateTime(2018, 3, 31));
            var startOfQuarter1Of2018 = new InstantPeriod(new DateTime(2017, 12, 31));
            var endOfQuarter1Of2018   = new InstantPeriod(new DateTime(2018, 3, 31));

            instance.Periods.Add(quarter1Of2018);
            instance.Periods.Add(startOfQuarter1Of2018);
            instance.Periods.Add(endOfQuarter1Of2018);

            var wsi = new Entity
            {
                Id = "wsi",
                IdentifierScheme = new Uri("http://www.sec.gov/CIK"),
                Identifier       = "WSI",
                Name             = "Walia Steel Industry PLC"
            };

            instance.Entities.Add(wsi);

            var package   = new ExcelPackage(new FileInfo(fileName));
            var worksheet = package.Workbook.Worksheets[1];

            ExcelRangeBase conceptCell         = worksheet.Cells["B2"];
            ExcelRangeBase valueCell           = worksheet.Cells["C2"];
            ExcelRangeBase startDateCell       = worksheet.Cells["D2"];
            ExcelRangeBase dateOrEndDateCell   = worksheet.Cells["E2"];
            ExcelRangeBase explicitMembersCell = worksheet.Cells["F2"];

            while (conceptCell.Value != null && valueCell.Value != null)
            {
                var concept = conceptCell.GetValue <string>();
                var value   = valueCell.Value;
                var period  = startDateCell.Value == null || string.IsNullOrEmpty(startDateCell.Value.ToString()) ?
                              new InstantPeriod(dateOrEndDateCell.GetValue <DateTime>()) :
                              (Period) new DurationPeriod(startDateCell.GetValue <DateTime>(), dateOrEndDateCell.GetValue <DateTime>());

                var conceptName = ToXName(concept, xDeclarationsHolder);
                var fact        = new Fact(conceptName, wsi, period)
                {
                    Unit          = etbUnit,
                    Value         = value.ToString(),
                    BalanceMethod = BalanceMethod.Algebraic
                };

                AddExplicitMembers(fact, explicitMembersCell.Value, xDeclarationsHolder);

                instance.Facts.Add(fact);

                conceptCell         = conceptCell.Offset(1, 0);
                valueCell           = valueCell.Offset(1, 0);
                startDateCell       = startDateCell.Offset(1, 0);
                dateOrEndDateCell   = dateOrEndDateCell.Offset(1, 0);
                explicitMembersCell = explicitMembersCell.Offset(1, 0);
            }
            return(instance);
        }
Example #25
0
 public TransactionOutputContext(long _bIndex, int _txIndex, int _txOutIndex, CurrencyUnit _amount, Sha256Ripemd160Hash _address, Ecdsa256KeyPair _keyPair)
 {
     bIndex = _bIndex;
     txIndex = _txIndex;
     txOutIndex = _txOutIndex;
     amount = _amount;
     address = _address;
     keyPair = _keyPair;
 }
Example #26
0
File: Core.cs Project: pizyumi/CREA
 public void RaiseUnusableBalanceUpdated(CurrencyUnit cu) { UnusableBalanceUpdated(this, cu); }
 /// <summary>Constructor</summary>
 /// <param name="baseVal">Value exclusive or inclusive VAT</param>
 /// <param name="vatRate">VAT rate (in %)</param>
 /// <param name="currencyUnit">Price currency</param>
 /// <param name="base">Specification of 1st parameter: exclusive/inclusive VAT</param>
 /// <exception cref = "PriceException">Thrown when VAT rate is negative</exception>
 public Price(decimal baseVal, decimal vatRate, CurrencyUnit currencyUnit, PriceBase @base = PriceBase.Excl) =>
Example #28
0
 public static Money Zero(CurrencyUnit currencyUnit)
 {
     return(new Money(currencyUnit, 0));
 }
Example #29
0
File: Core.cs Project: pizyumi/CREA
        public void NewTransaction(IAccount iAccount, Sha256Ripemd160Hash address, CurrencyUnit amount, CurrencyUnit fee)
        {
            if (!isSystemStarted)
                throw new InvalidOperationException("core_not_started");

            Account account = iAccount as Account;
            if (account == null)
                throw new ArgumentException("iaccount_type");

            utxodb.Open();

            List<Utxo> utxosList = blockChain.GetAllUtxos(account.Address.Hash);
            utxosList.Sort((a, b) =>
            {
                if (a.blockIndex < b.blockIndex)
                    return -1;
                else if (a.blockIndex > b.blockIndex)
                    return 1;

                if (a.txIndex < b.txIndex)
                    return -1;
                else if (a.txIndex > b.txIndex)
                    return 1;

                if (a.txOutIndex < b.txOutIndex)
                    return -1;
                else if (a.txOutIndex > b.txOutIndex)
                    return 1;

                return 0;
            });
            Utxo[] utxos = utxosList.ToArray();

            utxodb.Close();

            List<TransactionInput> usedTxInList = new List<TransactionInput>();
            foreach (var unconfirmedTh in transactionHistories.unconfirmedTransactionHistories.ToArray())
                for (int i = 0; i < unconfirmedTh.prevTxOuts.Length; i++)
                    if (unconfirmedTh.prevTxOuts[i].Address.Equals(account.Address.Hash))
                        usedTxInList.Add(unconfirmedTh.transaction.TxInputs[i]);
            usedTxInList.Sort((a, b) =>
            {
                if (a.PrevTxBlockIndex < b.PrevTxBlockIndex)
                    return -1;
                else if (a.PrevTxBlockIndex > b.PrevTxBlockIndex)
                    return 1;

                if (a.PrevTxIndex < b.PrevTxIndex)
                    return -1;
                else if (a.PrevTxIndex > b.PrevTxIndex)
                    return 1;

                if (a.PrevTxOutputIndex < b.PrevTxOutputIndex)
                    return -1;
                else if (a.PrevTxOutputIndex > b.PrevTxOutputIndex)
                    return 1;

                return 0;
            });
            TransactionInput[] usedTxIns = usedTxInList.ToArray();

            List<Utxo> unusedUtxosList = new List<Utxo>();

            int position = -1;
            for (int i = 0; i < usedTxIns.Length; i++)
            {
                bool flag = false;
                while (position < utxos.Length)
                {
                    position++;

                    if (usedTxIns[i].PrevTxBlockIndex == utxos[position].blockIndex && usedTxIns[i].PrevTxIndex == utxos[position].txIndex && usedTxIns[i].PrevTxOutputIndex == utxos[position].txOutIndex)
                    {
                        flag = true;

                        break;
                    }
                    else
                        unusedUtxosList.Add(utxos[position]);
                }

                if (!flag)
                    throw new InvalidOperationException();
            }

            long rawFeeAndAmount = amount.rawAmount + fee.rawAmount;

            List<Utxo> useUtxosList = new List<Utxo>();
            long rawFeeAndAmountAndChange = 0;

            bool flag2 = false;
            foreach (var utxo in unusedUtxosList)
            {
                useUtxosList.Add(utxo);

                if ((rawFeeAndAmountAndChange += utxo.amount.rawAmount) > rawFeeAndAmount)
                {
                    flag2 = true;

                    break;
                }
            }

            if (!flag2)
                for (int i = position + 1; i < utxos.Length; i++)
                {
                    useUtxosList.Add(utxos[i]);

                    if ((rawFeeAndAmountAndChange += utxos[i].amount.rawAmount) > rawFeeAndAmount)
                    {
                        flag2 = true;

                        break;
                    }
                }

            if (!flag2)
                throw new InvalidOperationException();

            Utxo[] useUtxos = useUtxosList.ToArray();

            TransactionInput[] txIns = new TransactionInput[useUtxos.Length];
            for (int i = 0; i < txIns.Length; i++)
            {
                txIns[i] = new TransactionInput();
                txIns[i].LoadVersion0(useUtxos[i].blockIndex, useUtxos[i].txIndex, useUtxos[i].txOutIndex, account.Ecdsa256KeyPair.pubKey);
            }

            long rawChange = rawFeeAndAmountAndChange - rawFeeAndAmount;

            TransactionOutput[] txOuts = new TransactionOutput[rawChange == 0 ? 1 : 2];
            txOuts[0] = new TransactionOutput();
            txOuts[0].LoadVersion0(address, amount);
            if (rawChange != 0)
            {
                txOuts[1] = new TransactionOutput();
                txOuts[1].LoadVersion0(account.Address.Hash, new CurrencyUnit(rawChange));
            }

            TransactionOutput[] prevTxOuts = new TransactionOutput[useUtxos.Length];
            for (int i = 0; i < prevTxOuts.Length; i++)
                prevTxOuts[i] = blockChain.GetMainBlock(txIns[i].PrevTxBlockIndex).Transactions[txIns[i].PrevTxIndex].TxOutputs[txIns[i].PrevTxOutputIndex];

            Ecdsa256PrivKey[] privKeys = new Ecdsa256PrivKey[useUtxos.Length];
            for (int i = 0; i < privKeys.Length; i++)
                privKeys[i] = account.Ecdsa256KeyPair.privKey;

            TransferTransaction ttx = new TransferTransaction();
            ttx.LoadVersion0(txIns, txOuts);
            ttx.Sign(prevTxOuts, privKeys);

            creaNodeTest.DiffuseNewTransaction(ttx);
        }
 /// <summary>Constructor</summary>
 /// <param name="baseVal">Amount exclusive or inclusive VAT</param>
 /// <param name="vatRate">VAT rate (in %)</param>
 /// <param name="currencyUnit">Currency Unit used</param>
 /// <param name="measureUnit">Measure Unit used (default: QuantityUnit.Item)</param>
 /// <param name="base">Specification of 1st parameter: exclusive/inclusive VAT</param>
 /// <exception cref = "PriceException">Thrown when VAT rate is negative</exception>
 public UnitPrice(decimal baseAmount, decimal vatRate, CurrencyUnit currencyUnit, MeasureUnit measureUnit, PriceBase @base = PriceBase.Excl) :
     base(baseAmount, vatRate, currencyUnit, @base) =>
Example #31
0
 public Money(CurrencyUnit currencyUnit, decimal amount)
 {
     this.CurrencyUnit = currencyUnit;
     this.Amount       = amount;
 }
Example #32
0
 public frmEditCurrencyUnit(CurrencyUnit cu)
 {
     InitializeComponent();
     this.cu = cu;
 }
Example #33
0
 public abstract void WriteIntro(Entity entity, CurrencyUnit unit);
Example #34
0
    private string GetValue(decimal value, string unit, string currency, string currencyUnit)
    {
        if (value == decimal.MinValue)
        {
            return("-");
        }
        if (unit == "TIME")
        {
            try
            {
                KPIDataTime datatime = KPIDataTimeBLL.GetKPIDataTimeFromValue(value);
                return(datatime.TimeDescription);
            }
            catch (Exception ex)
            {
                log.Error("Error getting datatime for measurement value", ex);
            }
            return("-");
        }
        else if (unit == "PERCENT")
        {
            return((value != 0 ? value.ToString("#.##") : "0") + " %");
        }
        else if (unit == "MONEY")
        {
            string lang = LanguageUtilities.GetLanguageFromContext();
            string name = "";
            try
            {
                CurrencyUnitBLL cuBll      = new CurrencyUnitBLL();
                CurrencyBLL     cBll       = new CurrencyBLL();
                List <Currency> currencies = cBll.GetCurrencys(lang);
                CurrencyUnit    cu         = cuBll.GetCurrencyUnitsById(lang, currency, currencyUnit);
                Currency        selected   = null;
                foreach (var item in currencies)
                {
                    if (item.CurrencyID == currency)
                    {
                        selected = item;
                        break;
                    }
                }
                string currencyUnitLabel = currencyUnit == "DOL" ? "" : cu.Name + " " + Resources.KpiStats.OfLabel + " ";

                if (selected != null)
                {
                    name = currencyUnitLabel + selected.Name;
                }
                else
                {
                    name = currencyUnitLabel + currency;
                }
            }
            catch (Exception ex)
            {
                log.Error("Error getting currency data", ex);
            }
            return((value != 0 ? value.ToString("#.##") : "0") + " " + name);
        }
        else if (unit == "INT")
        {
            return(Convert.ToInt32(value).ToString());
        }
        else
        {
            return(value != 0 ? value.ToString("#.##") : "0");
        }
    }