Ejemplo n.º 1
0
        private void loadCalendar()
        {
            CompteActuel.populateForcastOperations();
            calReminder.Items.Clear();
            var today = mthCalReminder.SelectionStart;
            var numberOfDaysInMonth = DateTime.DaysInMonth(today.Year, today.Month);

            var startOfMonth = new DateTime(today.Year, today.Month, 1);
            var endOfMonth   = new DateTime(today.Year, today.Month, numberOfDaysInMonth);

            //Filter only reminder operations that fit the calendar
            var ops = ReminderOperation.filterOperation(CompteActuel.ForecastOperations, startOfMonth, endOfMonth);

            calReminder.SetViewRange(startOfMonth, endOfMonth);
            foreach (var item in ops)
            {
                var cal = new CalendarItem(calReminder, item.Date, item.Date, item.Budget);
                cal.ApplyColor(Color.FromName(CompteActuel.Budgets[item.Budget].ToKnownColor().ToString()));
                calReminder.Items.Add(cal);
            }
        }
Ejemplo n.º 2
0
        private void btnModifyReminder_Click(object sender, EventArgs e)
        {
            var frm = new FrmReminderOperation(CompteActuel, false, true,
                                               CompteActuel.ReminderOperations.First(x => x.ID == lvReminderOps.SelectedItems[0].Text));

            if (frm.ShowDialog() == DialogResult.OK)
            {
                var op = new ReminderOperation(lvReminderOps.SelectedItems[0].Text)
                {
                    Type               = frm.cbxType.SelectedItem.ToString(),
                    Credit             = frm.mupCredit.Value,
                    Debit              = frm.mupDebit.Value,
                    Budget             = frm.cbxBudget.SelectedText,
                    DueDate            = frm.mcDate.SelectionStart,
                    Commentary         = frm.txtComm.Text,
                    NbOfRepetition     = (int)frm.nudNbOfRepetitions.Value,
                    RepetitionType     = (ReminderOperation.ERepititionType)frm.cbxRepetitionType.SelectedIndex,
                    AutomaticallyAdded = frm.cbAddOperations.Checked
                };

                var a =
                    CompteActuel.ReminderOperations.IndexOf(
                        CompteActuel.ReminderOperations.First(x => x.ID == lvReminderOps.SelectedItems[0].Text));
                CompteActuel.ReminderOperations.RemoveAll(x => x.ID == lvReminderOps.SelectedItems[0].Text);
                CompteActuel.ReminderOperations.Insert(a, op);

                //Delete old normal operations
                ReminderOperation.deleteNormalOperations(CompteActuel, op.ID);

                LoadReminderOps();

                if (frm.cbAddOperations.Checked)
                {
                    //Add normal operations generated from the reminder operation
                    op.addNormalOperations(CompteActuel);
                }
            }
        }
Ejemplo n.º 3
0
        private void btnAddReminder_Click(object sender, EventArgs e)
        {
            var frm = new FrmReminderOperation(CompteActuel);

            if (frm.ShowDialog() != DialogResult.OK)
            {
                return;
            }
            var op = new ReminderOperation
            {
                Type               = frm.cbxType.SelectedItem.ToString(),
                Credit             = frm.mupCredit.Value,
                Debit              = frm.mupDebit.Value,
                Budget             = frm.cbxBudget.SelectedText,
                DueDate            = frm.mcDate.SelectionStart,
                Commentary         = frm.txtComm.Text,
                NbOfRepetition     = frm.nudNbOfRepetitions.Value,
                RepetitionType     = (ReminderOperation.ERepititionType)frm.cbxRepetitionType.SelectedIndex,
                AutomaticallyAdded = frm.cbAddOperations.Checked
            };

            //Add new reminder operation
            CompteActuel.ReminderOperations.Add(op);

            LoadReminderOps();

            if (frm.cbAddOperations.Checked)
            {
                //Add normal operations generated from the reminder operation
                op.addNormalOperations(CompteActuel);
            }
            else
            {
                ReminderOperation.deleteNormalOperations(CompteActuel, op.ID);
            }
        }
Ejemplo n.º 4
0
 private void btnDeleteReminder_Click(object sender, EventArgs e)
 {
     CompteActuel.ReminderOperations.RemoveAll(x => x.ID == lvReminderOps.SelectedItems[0].Text);
     ReminderOperation.deleteNormalOperations(CompteActuel, lvReminderOps.SelectedItems[0].Text);
     LoadReminderOps();
 }
Ejemplo n.º 5
0
        public FrmReminderOperation(Account compte, bool vir = false, bool edit = false, ReminderOperation op = null)
        {
            InitializeComponent();

            compte.Budgets.All(x =>
            {
                cbxBudget.Items.Add(new ColorComboBox.ColorInfo(x.Key, x.Value));
                return(true);
            });
            cbxBudget.SelectedIndex = 0;
            Program.Types.ForEach(y => cbxType.Items.Add(y));
            cbxType.SelectedIndex           = 0;
            cbxRepetitionType.SelectedIndex = 0;

            if (vir)
            {
                cbxType.SelectedItem = "VIR";
                cbxType.Enabled      = false;
            }

            if (edit)
            {
                switch (Settings.Default.Lang.Name)
                {
                case "en-US":
                    Text = en_US.Operation_Edit;
                    break;

                case "de-DE":
                    Text = de_DE.Operation_Edit;
                    break;

                case "vi-VN":
                    Text = vi_VN.Operation_Edit;
                    break;

                default:     //case "fr-FR":
                    Text = fr_FR.Operation_Edit;
                    break;
                }
            }

            if (op != null)
            {
                cbxType.SelectedItem   = op.Type;
                mupCredit.Value        = op.Credit;
                mupDebit.Value         = op.Debit;
                cbxBudget.SelectedItem =
                    cbxBudget.Items.OfType <ColorComboBox.ColorInfo>().First(x => x.Text == op.Budget);
                mcDate.SelectionStart           = op.DueDate;
                mcDate.SelectionEnd             = op.DueDate;
                txtComm.Text                    = op.Commentary;
                nudNbOfRepetitions.Value        = op.NbOfRepetition;
                cbxRepetitionType.SelectedIndex = (int)op.RepetitionType;
                cbAddOperations.Checked         = op.AutomaticallyAdded;
            }
        }
Ejemplo n.º 6
0
        public static Account FromSQLite(string filepath)
        {
            var dbc = new SQLiteConnection("Data Source=" + filepath + ";Version=3;");

            dbc.Open();

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

            acrd.Read();
            var cb =
                new Account(DateTime.ParseExact(acrd["crdate"].ToString(), "dd/MM/yyyy", CultureInfo.InvariantCulture),
                            filepath)
            {
                Name = acrd["name"].ToString()
            };

            cb.DefPassMd5(acrd["passe"].ToString());
            var dvs = Currencies.All.First(x => x.ShortName == acrd["devise"].ToString());

            cb.ChangeCurrency(dvs, false);


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

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

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

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

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

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

            dbc.Close();
            return(cb);
        }
Ejemplo n.º 7
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)
        {
            var encodedString = Encoding.UTF8.GetBytes(xml);

            var ms = new MemoryStream(encodedString);

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

            var d = XDocument.Load(ms);

            var c  = d.Element("Compte");
            var cb =
                new Account(DateTime.ParseExact(c.Element("CrDate").Value, "dd/MM/yyyy", CultureInfo.InvariantCulture),
                            filepath)
            {
                Name = c.Element("Nom").Value
            };

            cb.DefPassMd5(c.Element("Passe").Value);
            var dvs = Currencies.All.First(x => x.ShortName == c.Element("Devise").Value);

            cb.ChangeCurrency(dvs, false);

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

            if (c.Element("ReminderOperations") != null)
            {
                foreach (XElement a in c.Element("ReminderOperations").Nodes())
                {
                    var op = new ReminderOperation(a.Attribute("ID").Value)
                    {
                        DueDate =
                            DateTime.ParseExact(a.Attribute("Date").Value, "dd/MM/yyyy", CultureInfo.InvariantCulture),
                        Commentary     = a.Attribute("Comm").Value,
                        Credit         = decimal.Parse(a.Attribute("Cre").Value, culture.NumberFormat),
                        Debit          = decimal.Parse(a.Attribute("Deb").Value, culture.NumberFormat),
                        Type           = a.Attribute("Type").Value,
                        Budget         = a.Attribute("Budget").Value,
                        NbOfRepetition = decimal.Parse(a.Attribute("NbOfRepetition").Value),
                        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 ? Color.White : ColorTranslator.FromHtml(b.Attribute("color").Value));
            }

            return(cb);
        }