Skip to content

Instantly share code, notes, and snippets.

@jfromaniello
Created April 21, 2010 21:21
Show Gist options
  • Save jfromaniello/374411 to your computer and use it in GitHub Desktop.
Save jfromaniello/374411 to your computer and use it in GitHub Desktop.
//Esto en el presenter
public interface ICajaEditarView
: IView
{
Caja Caja { get; set; }
void SetCuentasContables (IEnumerable<CuentaContable> cuentas)
void PuntosVenta (IEnumerable<PuntoVenta> puntosDeVenta)
event EventHandler AceptarClicked;
event EventHandler CancelarClicked;
}
[PersistenceConversational]
public class CajaEditarPresenter
: PresenterTipado<ICajaEditarView>, IInitializablePresenter
{
private readonly IDao<Caja> daoCaja;
private readonly IDaoReadOnly<CuentaContable> daoCuentaContable;
private readonly IDaoReadOnly<PuntoVenta> daoPuntoVenta;
public CajaEditarPresenter(
IDaoFactory daoFactory,
ICajaEditarView cajaEditarView)
{
daoCaja = daoFactory.GetDaoOf<Caja>();
daoCuentaContable = daoFactory.GetDaoReadOnlyOf<CuentaContable>();
daoPuntoVenta = daoFactory.GetDaoReadOnlyOf<PuntoVenta>();
View = cajaEditarView;
View.AceptarClicked += ViewAceptarClicked;
View.CancelarClicked += ViewCancelarClicked;
}
#region IInitializablePresenter Members
public void Initialize()
{
View.SetCuentasContables(daoCuentaContable.GetCuentasImputables().ToList());
View.SetPuntosVenta(daoPuntoVenta.RetrieveAll().OrderBy(p => p.Nombre).ToList());
View.Caja = new Caja();
}
#endregion
[PersistenceConversation(Exclude = true)]
public override void Activate()
{
ViewManager.ShowDialog(View);
}
[PersistenceConversation(ConversationEndMode = EndMode.Abort)]
private void ViewCancelarClicked(object sender, EventArgs e)
{
View.Close();
}
[PersistenceConversation(ConversationEndMode = EndMode.End)]
private void ViewAceptarClicked(object sender, EventArgs e)
{
daoCaja.MakePersistent(View.Caja);
View.Close();
}
public void Initialize(int id)
{
View.Caja = daoCaja.Get(id);
}
}
//Este es el código behind del form.... El form implementa la interfaz definida en el proyecto del presenter.
public partial class CajaEditar
: XtraForm, ICajaEditarView
{
public CajaEditar()
{
InitializeComponent();
}
#region ICajaEditarView Members
public void SetCuentasContables(IEnumerable<CuentaContable> cuentas)
{
cuentaContableBindingSource.DataSource = cuentas;
}
public void SetPuntosVenta(IEnumerable<PuntoVenta> puntosDeVenta)
{
puntoVentaBindingSource.DataSource = puntosDeVenta;
}
public event EventHandler AceptarClicked
{
add { AceptarButton.Click += value; }
remove { AceptarButton.Click -= value; }
}
public event EventHandler CancelarClicked
{
add { CancelarButton.Click += value; }
remove { CancelarButton.Click -= value; }
}
public Caja Caja
{
get { return (Caja) cajaBindingSource.DataSource; }
set { cajaBindingSource.DataSource = value; }
}
#endregion
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment