Exemplo n.º 1
0
        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();
                    }
                }
            }
        }
Exemplo n.º 2
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;
            }
        }