|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using Signum.Entities;
using Signum.Utilities.DataStructures;
using System.Collections.ObjectModel;
using Signum.Utilities;
using System.Windows.Controls;
using System.ComponentModel;
using Signum.Entities.Reflection;
namespace Signum.Windows
{
public class AdminBase:Window
{
public virtual object GetEntities()
{
throw new NotImplementedException();
}
public virtual void SetEntities(object value)
{
throw new NotImplementedException();
}
public virtual void RetrieveEntities()
{
throw new NotImplementedException();
}
/// <summary>
/// Could be called Async
/// </summary>
public virtual object SaveEntities(object value)
{
throw new NotImplementedException();
}
public virtual void UpdateInterface()
{
throw new NotImplementedException();
}
public virtual Button GetSaveButton()
{
throw new NotImplementedException();
}
public void Retrieve()
{
RetrieveEntities();
UpdateInterface();
}
public virtual bool HasChanges()
{
var entidades = (List<IdentifiableEntity>)GetEntities();
return DirectedGraph<Modifiable>.Union(entidades.Select(e => GraphExplorer.FromRoot(e))).Any(a => a.SelfModified);
}
protected void Reload_Click(object sender, RoutedEventArgs e)
{
if (!HasChanges() || MessageBox.Show(Properties.Resources.ThereAreChangesContinue, Properties.Resources.ThereAreChanges,
MessageBoxButton.OKCancel, MessageBoxImage.Question, MessageBoxResult.OK) == MessageBoxResult.OK)
{
Retrieve();
}
}
public bool AssertErrors()
{
string error = Errors();
if (error.HasText())
{
MessageBox.Show(Properties.Resources.ImpossibleToSaveIntegrityCheckFailed + error, Properties.Resources.ThereAreErrors, MessageBoxButton.OK, MessageBoxImage.Error);
return false;
}
return true;
}
public virtual string Errors()
{
var entidades = (List<IdentifiableEntity>)GetEntities();
return entidades.Select(a => a.FullIntegrityCheck()).Where(e => e.HasText()).ToString("\r\n");
}
protected override void OnClosing(CancelEventArgs e)
{
if (HasChanges())
{
var result = MessageBox.Show(Properties.Resources.SaveChanges, Properties.Resources.ThereAreChanges,
MessageBoxButton.YesNoCancel, MessageBoxImage.Question, MessageBoxResult.No);
if (result == MessageBoxResult.Cancel)
{
e.Cancel = true;
}
else if (result == MessageBoxResult.Yes)
{
if (AssertErrors())
{
SetEntities(SaveEntities(GetEntities()));
UpdateInterface();
}
else
e.Cancel = true;
}
else if (result == MessageBoxResult.No)
{
return;
}
}
base.OnClosing(e);
}
protected void Close_Click(object sender, RoutedEventArgs e)
{
this.Close();
}
protected void Save_Click(object sender, RoutedEventArgs e)
{
if (!HasChanges())
{
MessageBox.Show(Properties.Resources.NoChangeHaveBeenFound, Properties.Resources.NoChanges, MessageBoxButton.OK, MessageBoxImage.Hand );
return;
}
if (!AssertErrors())
return;
object value = GetEntities();
Button button = GetSaveButton();
button.IsEnabled = false;
Async.Do(this,
() => value = SaveEntities(value),
() => { SetEntities(value); UpdateInterface(); },
() => button.IsEnabled = true);
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
I'm Computer Scientist, one of the founders of Signum Software, and the lead developer behind Signum Framework.
www.signumframework.com
I love programming in C#, Linq, Compilers, Algorithms, Functional Programming, Computer Graphics, Maths...