예제 #1
0
        /// <summary>
        /// Gets the exchange rates of the specified currencies
        /// </summary>
        /// <param name="FromCurrency">First currency</param>
        /// <param name="ToCurrency">Second currency</param>
        /// <returns>The exchange rate from the first currency to the second</returns>
        public static double ExchangeRate(CurrencyObj FromCurrency, CurrencyObj ToCurrency)
        {
            WebRequest      webrequest         = WebRequest.Create("http://www.webservicex.net/CurrencyConvertor.asmx/ConversionRate?FromCurrency=" + FromCurrency.ShortName + "&ToCurrency=" + ToCurrency.ShortName);
            HttpWebResponse response           = (HttpWebResponse)webrequest.GetResponse();
            Stream          dataStream         = response.GetResponseStream();
            StreamReader    reader             = new StreamReader(dataStream);
            string          responseFromServer = reader.ReadToEnd();
            XmlDocument     doc = new XmlDocument();

            doc.LoadXml(responseFromServer);
            double value = double.Parse(doc.InnerText, CultureInfo.InvariantCulture);

            reader.Close();
            dataStream.Close();
            response.Close();
            return(value);
        }
예제 #2
0
        /// <summary>
        /// Changes the account's currency to the given one
        /// </summary>
        /// <param name="d">The given currency</param>
        /// <param name="convert">Convert all the operations to the given currency</param>
        public void ChangeCurrency(CurrencyObj d, bool convert = true)
        {
            if (!convert)
            {
                Currency = d;
            }
            else
            {
                _ops.All(x =>
                {
                    x.Credit = Currency.ToCur(d, (double)x.Credit);
                    x.Debit  = Currency.ToCur(d, (double)x.Debit);
                    return(true);
                });

                Currency = d;
            }
        }
예제 #3
0
        public static void Init()
        {
            switch (CrediNET.Properties.Settings.Default.Lang.Name)
            {
            case "en-US":

                Euro      = new CurrencyObj("Euro", "€", "EUR");
                US_Dollar = new CurrencyObj("American dollar", "$", "USD");
                AU_Dollar = new CurrencyObj("Australian dollar", "$", "AUD");
                CA_Dollar = new CurrencyObj("Canadian dollar", "$", "CAD");
                CHI_Yuan  = new CurrencyObj("Chinese Yuan", "¥", "CNY");
                JAP_Yen   = new CurrencyObj("Japanese Yen", "¥", "JPY");
                SWI_Franc = new CurrencyObj("Swiss franc", "Fr", "CHF");

                break;

            default:            //case "fr-FR"

                Euro      = new CurrencyObj("Euro", "€", "EUR");
                US_Dollar = new CurrencyObj("Dollar américain", "$", "USD");
                AU_Dollar = new CurrencyObj("Dollar australien", "$", "AUD");
                CA_Dollar = new CurrencyObj("Dollar canadien", "$", "CAD");
                CHI_Yuan  = new CurrencyObj("Yuan chinois", "¥", "CNY");
                JAP_Yen   = new CurrencyObj("Yen japonais", "¥", "JPY");
                SWI_Franc = new CurrencyObj("Franc suisse", "Fr", "CHF");

                break;
            }

            BaseUnit = new CurrencyObj("Base unit", "BU", "BU", 1);

            All = new List <CurrencyObj>()
            {
                Euro, US_Dollar, AU_Dollar, CA_Dollar, CHI_Yuan, JAP_Yen, SWI_Franc
            };
        }
예제 #4
0
        public static Account FromSQLite(string filepath)
        {
            Account cb;

            SQLiteConnection dbc = new SQLiteConnection("Data Source=" + filepath + ";Version=3;");

            dbc.Open();

            // account
            SQLiteDataReader acrd = new SQLiteCommand("select * from Account", dbc).ExecuteReader();

            acrd.Read();
            cb      = new Account(DateTime.ParseExact(acrd["crdate"].ToString(), "dd/MM/yyyy", CultureInfo.InvariantCulture), filepath);
            cb.Name = acrd["name"].ToString();
            cb.DefPassMd5(acrd["passe"].ToString());
            CurrencyObj dvs = Currencies.All.First(x => x.ShortName == acrd["devise"].ToString());

            cb.ChangeCurrency(dvs, false);


            SQLiteDataReader oprd = new SQLiteCommand("select * from Operations", dbc).ExecuteReader();

            while (oprd.Read())
            {
                Operation op = new Operation(oprd["id"].ToString());
                op.Date       = DateTime.ParseExact(oprd["date"].ToString(), "dd/MM/yyyy", CultureInfo.InvariantCulture);
                op.Commentary = oprd["comm"].ToString();
                op.Credit     = decimal.Parse(oprd["cred"].ToString(), culture.NumberFormat);
                op.Debit      = decimal.Parse(oprd["deb"].ToString(), culture.NumberFormat);
                op.Type       = oprd["type"].ToString();
                op.Budget     = oprd["budget"].ToString();
                op.RmdOptID   = oprd["remid"].ToString();
                cb.Operations.Add(op);
            }

            SQLiteDataReader remrd = new SQLiteCommand("select * from ReminderOperations", dbc).ExecuteReader();

            while (remrd.Read())
            {
                ReminderOperation op = new ReminderOperation(remrd["id"].ToString());
                op.DueDate            = DateTime.ParseExact(remrd["date"].ToString(), "dd/MM/yyyy", CultureInfo.InvariantCulture);
                op.Commentary         = remrd["comm"].ToString();
                op.Credit             = decimal.Parse(remrd["cred"].ToString(), culture.NumberFormat);
                op.Debit              = decimal.Parse(remrd["deb"].ToString(), culture.NumberFormat);
                op.Type               = remrd["type"].ToString();
                op.Budget             = remrd["budget"].ToString();
                op.NbOfRepetition     = int.Parse(remrd["nbrep"].ToString());
                op.RepetitionType     = (ReminderOperation.ERepititionType)(int.Parse(remrd["typerep"].ToString()));
                op.AutomaticallyAdded = remrd["auto"].ToString() == "1";
                cb.ReminderOperations.Add(op);
            }

            cb.Budgets.Clear();
            SQLiteDataReader btrd = new SQLiteCommand("select * from Budgets", dbc).ExecuteReader();

            while (btrd.Read())
            {
                cb.Budgets.Add(btrd["name"].ToString(), ColorTranslator.FromHtml(btrd["color"].ToString()).ToWPFColor());
            }

            dbc.Close();
            return(cb);
        }
예제 #5
0
        /// <summary>
        /// Gets the account from XML code
        /// </summary>
        /// <param name="xml">XML code</param>
        /// <param name="filepath">Filename</param>
        /// <returns>The account from XML code</returns>
        public static Account FromXmlCode(string xml, string filepath)
        {
            Account cb;

            byte[] encodedString = Encoding.UTF8.GetBytes(xml);

            MemoryStream ms = new MemoryStream(encodedString);

            ms.Flush();
            ms.Position = 0;

            var d = XDocument.Load(ms);

            var c = d.Element("Compte");

            cb      = new Account(DateTime.ParseExact(c.Element("CrDate").Value, "dd/MM/yyyy", CultureInfo.InvariantCulture), filepath);
            cb.Name = c.Element("Nom").Value;
            cb.DefPassMd5(c.Element("Passe").Value);
            CurrencyObj dvs = Currencies.All.First(x => x.ShortName == c.Element("Devise").Value);

            cb.ChangeCurrency(dvs, false);

            foreach (XElement a in c.Element("Operations").Nodes())
            {
                Operation op = new Operation(a.Attribute("ID").Value);
                op.Date       = DateTime.ParseExact(a.Attribute("Date").Value, "dd/MM/yyyy", CultureInfo.InvariantCulture);
                op.Commentary = a.Attribute("Comm").Value;
                op.Credit     = decimal.Parse(a.Attribute("Cre").Value, culture.NumberFormat);
                op.Debit      = decimal.Parse(a.Attribute("Deb").Value, culture.NumberFormat);
                op.Type       = a.Attribute("Type").Value;
                op.Budget     = a.Attribute("Budget").Value;
                if (a.Attribute("ReminderOperationID") != null)
                {
                    op.RmdOptID = a.Attribute("ReminderOperationID").Value;
                }
                else
                {
                    op.RmdOptID = "";
                }
                cb.Operations.Add(op);
            }

            if (c.Element("ReminderOperations") != null)
            {
                foreach (XElement a in c.Element("ReminderOperations").Nodes())
                {
                    ReminderOperation op = new ReminderOperation(a.Attribute("ID").Value);
                    op.DueDate        = DateTime.ParseExact(a.Attribute("Date").Value, "dd/MM/yyyy", CultureInfo.InvariantCulture);
                    op.Commentary     = a.Attribute("Comm").Value;
                    op.Credit         = decimal.Parse(a.Attribute("Cre").Value, culture.NumberFormat);
                    op.Debit          = decimal.Parse(a.Attribute("Deb").Value, culture.NumberFormat);
                    op.Type           = a.Attribute("Type").Value;
                    op.Budget         = a.Attribute("Budget").Value;
                    op.NbOfRepetition = decimal.Parse(a.Attribute("NbOfRepetition").Value);
                    op.RepetitionType = (ReminderOperation.ERepititionType)decimal.Parse(a.Attribute("TypeOfRepetition").Value);
                    if (a.Attribute("AutomaticallyAdded") != null)
                    {
                        op.AutomaticallyAdded = bool.Parse(a.Attribute("AutomaticallyAdded").Value);
                    }
                    cb.ReminderOperations.Add(op);
                }
            }

            cb.Budgets.Clear();
            foreach (XElement b in c.Element("Budgets").Nodes())
            {
                cb.Budgets.Add(b.Value, b.Attribute("color") == null ? Colors.White : ColorTranslator.FromHtml(b.Attribute("color").Value).ToWPFColor());
            }

            return(cb);
        }
예제 #6
0
        /// <summary>
        /// Convertit un montant d'une devise vers une autre.
        /// </summary>
        /// <param name="b">From this currency</param>
        /// <param name="d">To this currency</param>
        /// <param name="montant">Amount</param>
        /// <returns>Amount in the destination currency</returns>
        public static decimal ToCur(this CurrencyObj b, CurrencyObj d, double montant)
        {
            double rt = ExchangeRate(b, d);

            return((decimal)(montant * rt));
        }