Ejemplo n.º 1
0
        public void OpenReceiptEntryExecute(Transaction trans)
        {
            var win     = new SaveWindow();
            var winVm   = new SaveWindowVM();
            var control = new TransactionEntry();
            var exists  = Repository.Transactions.Contains(trans);
            var vm      = new TransactionEntryVM(trans, Repository.Accounts.OrderBy(t => t.Name), Repository.Accounts.OrderBy(t => t.Name));

            winVm.IsSaveVisible = !exists;

            winVm.Save += (s, e) =>
            {
                if (!exists)
                {
                    Repository.Add(trans);
                }

                Repository.UpdateAccountBalances(DateTime.Now.Date);

                win.Close();
            };

            win.SizeToContent   = SizeToContent.WidthAndHeight;
            win.DataContext     = winVm;
            control.DataContext = vm;
            win.WindowContents  = control;
            win.ShowDialog();
        }
Ejemplo n.º 2
0
        public void OpenObjectEntry <T>(T obj) where T : ModelBase
        {
            var modelName       = obj.GetType().Name;
            var win             = new SaveWindow();
            var winVm           = new SaveWindowVM();
            var assembly        = System.Reflection.Assembly.GetExecutingAssembly();
            var controlType     = assembly.GetType(string.Format("WpfApplication.UserControls.{0}Entry", modelName));
            var controlInstance = controlType.GetConstructor(new Type[] { }).Invoke(new object[] { }) as FrameworkElement;
            var vmType          = assembly.GetType(string.Format("WpfApplication.ViewModels.{0}EntryVM", modelName));
            var vmInstance      = vmType.GetConstructor(new Type[] { obj.GetType() }).Invoke(new object[] { obj });
            var exists          = Repository.Exists(obj);

            winVm.IsSaveVisible = !exists;
            winVm.Save         += (s, e) =>
            {
                if (!exists)
                {
                    Repository.Add(obj);
                }

                win.Close();
            };

            win.DataContext             = winVm;
            controlInstance.DataContext = vmInstance;
            win.WindowContents          = controlInstance;
            win.Title         = string.Format("New {0}", modelName);
            win.SizeToContent = SizeToContent.WidthAndHeight;
            win.ShowDialog();
        }