private void BtnAccountEdit_Click(object sender, RoutedEventArgs e)
        {
            SaverDefaultValue valSaver = new SaverDefaultValue();

            if (cbAccount.SelectedItem == null)
            {
                return;
            }
            Account   account = cbAccount.SelectedItem as Account;
            EditValue wnd     = new EditValue();

            wnd.Value = account.Name;
            wnd.ShowDialog();
            if (wnd.Value == null)
            {
                return;
            }
            if (wnd.DialogResult == true)
            {
                using (DataModelContainer db = new DataModelContainer())
                {
                    Account val = db.AccountSet.FirstOrDefault(a => a.Id == account.Id);
                    val.Name = wnd.Value;
                    db.SaveChanges();
                    cbAccount.ItemsSource  = db.AccountSet.ToList();
                    cbAccount.SelectedItem = val;
                    if (wnd.Default)
                    {
                        valSaver.dic["account"] = val.Id;
                        valSaver.Save();
                    }
                }
            }
        }
        private void BtnOperationEdit_Click(object sender, RoutedEventArgs e)
        {
            SaverDefaultValue valSaver = new SaverDefaultValue();

            if (cbOperation.SelectedItem == null)
            {
                return;
            }
            OperationName operationName = cbOperation.SelectedItem as OperationName;
            EditValue     wnd           = new EditValue();

            wnd.Value = operationName.Name;
            wnd.ShowDialog();
            if (wnd.Value == null)
            {
                return;
            }
            if (wnd.DialogResult == true)
            {
                using (DataModelContainer db = new DataModelContainer())
                {
                    OperationName val = db.OperationNameSet.FirstOrDefault(a => a.Id == operationName.Id);
                    val.Name = wnd.Value;
                    db.SaveChanges();
                    cbOperation.ItemsSource  = db.OperationNameSet.ToList();
                    cbOperation.SelectedItem = val;
                    if (wnd.Default)
                    {
                        valSaver.dic["operation"] = val.Id;
                        valSaver.Save();
                    }
                }
            }
        }
        private void BtnAccountAdd_Click(object sender, RoutedEventArgs e)
        {
            SaverDefaultValue valSaver = new SaverDefaultValue();
            EditValue         wnd      = new EditValue();

            wnd.ShowDialog();
            if (wnd.Value == null)
            {
                return;
            }
            if (wnd.DialogResult == true)
            {
                using (DataModelContainer db = new DataModelContainer())
                {
                    Account val = new Account()
                    {
                        Name = wnd.Value
                    };
                    db.AccountSet.Add(val);
                    db.SaveChanges();
                    cbAccount.ItemsSource  = db.AccountSet.ToList();
                    cbAccount.SelectedItem = val;
                    if (wnd.Default)
                    {
                        valSaver.dic["account"] = db.AccountSet.FirstOrDefault(p => p.Name == wnd.Value).Id;
                        valSaver.Save();
                    }
                }
            }
        }
Example #4
0
        private void LoadData()
        {
            SaverDefaultValue valSaver = new SaverDefaultValue();

            using (DataModelContainer db = new DataModelContainer())
            {
                cbAccount.ItemsSource = db.AccountSet.ToList();
                if (valSaver.dic.ContainsKey("account"))
                {
                    int id  = valSaver.dic["account"];
                    var val = db.AccountSet.FirstOrDefault(a => a.Id == id);
                    if (val != null)
                    {
                        cbAccount.SelectedItem = val;
                    }
                    else
                    {
                        cbAccount.SelectedIndex = 0;
                    }
                }
                else
                {
                    cbAccount.SelectedIndex = 0;
                }
            }
            LoadSum(cbAccount.SelectedItem as Account);
        }
Example #5
0
        private void MenuItem_Click(object sender, RoutedEventArgs e)
        {
            YesNo wnd = new YesNo();

            wnd.ShowDialog();
            if (wnd.DialogResult == true)
            {
                GridRow row = dataGrid.SelectedItem as GridRow;
                using (DataModelContainer db = new DataModelContainer())
                {
                    db.OperationSet.Remove(db.OperationSet.FirstOrDefault(o => o.Id == row.Id));
                    db.SaveChanges();
                    LoadGrid();
                }
            }
        }
        private void BtnSave_Click(object sender, RoutedEventArgs e)
        {
            if (cbAccount.SelectedItem == null ||
                cbOperation.SelectedItem == null ||
                cbPerson.SelectedItem == null)
            {
                return;
            }
            using (DataModelContainer db = new DataModelContainer())
            {
                Operation op = new Operation();
                op.Date = DateTime.Parse(dpDate.Text);
                int id = (cbOperation.SelectedItem as OperationName).Id;
                op.OperationName = db.OperationNameSet.FirstOrDefault(o => o.Id == id);
                id         = (cbAccount.SelectedItem as Account).Id;
                op.Account = db.AccountSet.FirstOrDefault(o => o.Id == id);
                if (cbPerson.SelectedItem == null)
                {
                    op.Person = null;
                }
                else
                {
                    id        = (cbPerson.SelectedItem as Person).Id;
                    op.Person = db.PersonSet.FirstOrDefault(o => o.Id == id);
                }

                string pars = tbSum.Text;
                if (pars == "")
                {
                    op.Sum = 0;
                }
                else
                {
                    op.Sum = double.Parse(pars, NumberStyles.Any, CultureInfo.InvariantCulture);
                }
                if (operationToogle.IsChecked == null || operationToogle.IsChecked == false)
                {
                    op.Sum *= -1;
                }
                op.Comment = CommentTextBox.Text;

                db.OperationSet.Add(op);
                db.SaveChanges();
                DialogResult = true;
            }
        }
Example #7
0
 private void LoadSum(Account account)
 {
     if (account == null)
     {
         tblSum.Text = $"0 grn.";
         return;
     }
     using (DataModelContainer db = new DataModelContainer())
     {
         var    entry = db.OperationSet.Where(o => o.Account.Id == account.Id).ToList();
         double sum   = 0;
         if (entry.Count != 0)
         {
             sum = entry.Sum(o => o.Sum);
         }
         tblSum.Text = $"{sum.ToString("N0")} grn.";
     }
 }
Example #8
0
        private void LoadGrid()
        {
            if (Account == null)
            {
                return;
            }

            using (DataModelContainer db = new DataModelContainer()) {
                var grid = (from o in db.OperationSet
                            join n in db.OperationNameSet on o.OperationName.Id equals n.Id
                            join a in db.AccountSet on o.Account.Id equals a.Id
                            join p in db.PersonSet on o.Person.Id equals p.Id
                            where a.Id == Account.Id
                            select new GridRow {
                    Id = o.Id, Date = o.Date, Operation = n.Name, Person = p.Name, Sum = o.Sum, Comment = o.Comment
                }).ToList();

                dataGrid.ItemsSource = grid;
            }
        }
        private void LoadData()
        {
            using (DataModelContainer db = new DataModelContainer())
            {
                SaverDefaultValue valSaver = new SaverDefaultValue();
                cbAccount.ItemsSource   = db.AccountSet.ToList();
                cbOperation.ItemsSource = db.OperationNameSet.ToList();
                cbPerson.ItemsSource    = db.PersonSet.ToList();

                if (valSaver.dic.ContainsKey("account"))
                {
                    int id  = valSaver.dic["account"];
                    var val = db.AccountSet.FirstOrDefault(a => a.Id == id);
                    if (val != null)
                    {
                        cbAccount.SelectedItem = val;
                    }
                    else
                    {
                        cbAccount.SelectedIndex = 0;
                    }
                }
                else
                {
                    cbAccount.SelectedIndex = 0;
                }
                if (valSaver.dic.ContainsKey("operation"))
                {
                    int id  = valSaver.dic["operation"];
                    var val = db.OperationNameSet.FirstOrDefault(a => a.Id == id);
                    if (val != null)
                    {
                        cbOperation.SelectedItem = val;
                    }
                    else
                    {
                        cbOperation.SelectedIndex = 0;
                    }
                }
                else
                {
                    cbOperation.SelectedIndex = 0;
                }
                if (valSaver.dic.ContainsKey("person"))
                {
                    int id  = valSaver.dic["person"];
                    var val = db.PersonSet.FirstOrDefault(a => a.Id == id);
                    if (val != null)
                    {
                        cbPerson.SelectedItem = val;
                    }
                    else
                    {
                        cbPerson.SelectedIndex = 0;
                    }
                }
                else
                {
                    cbPerson.SelectedIndex = 0;
                }
            }
        }