Welcome to 3Dev Blogs Sign in | Join | Help
<May 2008>
SuMoTuWeThFrSa
27282930123
45678910
11121314151617
18192021222324
25262728293031
1234567

Navigation

Syndication

Eventos con .NET Remoting Parte III

Proyecto Cliente

Form1.cs

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

using System.Runtime.Remoting;

using System.Runtime.Remoting.Channels;

using System.Runtime.Remoting.Channels.Tcp;

using CommonAssembly;

using Entidades;

namespace DemosEventosRemoting

{

public partial class Form1 : Form

{

private string sucursal="";

public Form1(string _sucursal)

{

InitializeComponent();

sucursal = _sucursal;

this.Text = sucursal;

}

IOrder _orderObject;

private void Form1_Load(object sender, EventArgs e)

{

RemotingConfiguration.Configure("DemosEventosRemoting.exe.config",false);

WellKnownClientTypeEntry[] entry = RemotingConfiguration.GetRegisteredWellKnownClientTypes();

_orderObject = (IOrder)Activator.GetObject( entry[0].ObjectType

,entry[0].ObjectUrl);

AgregarEventHandler o = new AgregarEventHandler(refrescarLista);

_orderObject.AddOnAgregarEvent(o);

List<Person> prs = _orderObject.getPersons();

bindingSource1.DataSource = prs;

}

Person person;

public void refrescarLista(object o, ArgumentosEventArgs e)

{

string s = e.Sucursal;

if (s == sucursal)

{

person = e.Person;

this.BeginInvoke(new MethodInvoker(delegate()

{

bindingSource1.Add(person);

}));

}

}

//private void Pintar()

//{

// bindingSource1.Add(person);

//}

private void btnOK_Click(object sender, EventArgs e)

{

Form2 fr = new Form2(_orderObject, sucursal);

fr.Show();

}

private void Form1_FormClosing(object sender, FormClosingEventArgs e)

{

AgregarEventHandler o = new AgregarEventHandler(refrescarLista);

_orderObject.AddOnRemoveEvent(o);

}

}

}

 

Form2.cs

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

using CommonAssembly;

using Entidades;

namespace DemosEventosRemoting

{

public partial class Form2 : Form

{

public Form2()

{

InitializeComponent();

}

IOrder _orderObject;

string sucursal = "";

public Form2(IOrder orderObject,string _sucursal)

{

_orderObject = orderObject;

sucursal = _sucursal;

InitializeComponent();

}

private void button1_Click(object sender, EventArgs e)

{

Person p = new Person();

p.Nombre = textBox1.Text;

p.Apellido = textBox2.Text;

p.Edad = Convert.ToInt32(textBox3.Text);

p.Direccion = textBox4.Text;

_orderObject.Insertar(p,sucursal);

}

}

}

 

Formulario SetSucursal

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

namespace DemosEventosRemoting

{

public partial class SetSucursal : Form

{

public SetSucursal()

{

InitializeComponent();

}

private void button1_Click(object sender, EventArgs e)

{

string s = comboBox1.Text;

Form1 fr = new Form1(s);

fr.Show();

}

}

}

 

Program.cs

 

using System;

using System.Collections.Generic;

using System.Windows.Forms;

namespace DemosEventosRemoting

{

static class Program

{

/// <summary>

/// The main entry point for the application.

/// </summary>

[STAThread]

static void Main()

{

Application.EnableVisualStyles();

Application.SetCompatibleTextRenderingDefault(false);

Application.Run(new SetSucursal());

}

}

}

Published Thursday, May 01, 2008 8:17 PM by jfrancia

Comments

No Comments

Anonymous comments are disabled
Powered by Community Server, by Telligent Systems