Focus in 3tier application
hello
i want focus on proper textbox after data validation in bll. correct way?
1- returning different value , decide in presentation layer(in way need evaluate returned value again - once in bll , in ui)
2- set focus on proper textbox bll.
thank you
the ui should be unware of bll , the bll unaware of ui. missing another piece you should put into place sits between ui , bll part of presentation layer.
http://www.codeproject.com/articles/228214/understanding-basics-of-ui-design-pattern-mvc-mvp
https://en.wikipedia.org/wiki/model%e2%80%93view%e2%80%93presenter
you should watch entire show feel.
http://polymorphicpodcast.com/shows/mv-patterns/
watching above show first should link below. , can find other links mvpvm.
http://aviadezra.blogspot.com/2009/08/mvp-mvvm-winforms-data-binding.html
below mvp being applied windows forms ui solution n-tier being applied tutorial given ado.net entity framework. may come point stop thinking using datasets, datatables , tableadapters , learn how use objects dto(s) being sent tiers , other types of objects, bll objects , dao objects. should learn how use list<t>.
https://en.wikipedia.org/wiki/data_transfer_object
a dto based off of using auto properties. dtoemployee without class constructor.
https://msdn.microsoft.com/en-us/library/bb384054.aspx?f=255&mspperror=-2147217396
https://en.wikipedia.org/wiki/data_access_object
http://www.tutorialspoint.com/design_pattern/data_access_object_pattern.htm
it's showing dao usage in java, can applied c# or vb, because java , .net oo language platforms.
the use of mvp little different, since bll , dal sitting behind wcf web service , service layer making calls wcf web service.
the interface.........................
using system.collections.generic;
using system.windows.forms;
{
public interface iauthorview :iview
{
int idx { get; set; }
list<dtoauthor> dtoauthors { get; set; }
label lblauthorid { get; set; }
textbox tbxfirstname { get; set; }
textbox tbxlastname { get; set; }
}
}
the form/the view..............................
using system.collections.generic;
using system.windows.forms;
using bll.dto;
using demowindowsformapp.presenters;
using demowindowsformapp.views;
using services;
{
public partial class authorview : form, iauthorview
{
#region members
private authorviewpresenter mpresenter;
#endregion
{
mpresenter = new authorviewpresenter(this, theservice1.instance);
initializecomponent();
}
public list<dtoauthor> dtoauthors { get; set; }
public label lblauthorid
{
{ return lblauthorid; }
set { lblauthorid = value; }
}
{
{ return tbxfirstname; }
set { tbxfirstname = value; }
}
{
{ return tbxlastname; }
set { tbxlastname = value; }
}
{
mpresenter.load();
}
{
mpresenter.btnfirstclick();
}
{
mpresenter.btnprevclick();
}
{
mpresenter.btnnextclick();
}
{
mpresenter.btnlastclick();
}
{
mpresenter.btnclearclick();
}
{
mpresenter.btnupdateclick();
}
{
mpresenter.btnnewclick();
}
{
mpresenter.btnsendclick();
}
}
}
the presenter....................
using system.collections.generic;
using demowindowsformapp.views;
using bll.dto;
using services.iservices;
{
public class authorviewpresenter
{
private readonly iauthorview mview;
private readonly iservice1 mservice;
{
mview = view;
mservice = theservice;
}
{
var authors = mservice.getauthorswhere();
mview.dtoauthors = authors;
mview.idx = 0;
}
{
mview.idx = 0;
populatefields(mview.dtoauthors, mview.idx);
}
{
if(mview.idx == 0)
{
populatefields(mview.dtoauthors, mview.idx);
}
else
{
mview.idx -= 1;
populatefields(mview.dtoauthors, mview.idx);
}
}
{
if (mview.idx == mview.dtoauthors.count - 1)
{
populatefields(mview.dtoauthors, mview.idx);
}
else
{
mview.idx += 1;
populatefields(mview.dtoauthors, mview.idx);
}
}
{
mview.idx = mview.dtoauthors.count - 1;
populatefields(mview.dtoauthors, mview.idx);
}
{
var author = mview.dtoauthors[mview.idx];
author.lastname = mview.tbxlastname.text;
author.isupdate = true;
}
{
mview.tbxfirstname.text = "";
mview.tbxlastname.text = "";
mview.lblauthorid.text = "author not saved yet.";
}
{
var atleastoneauthor = (from in mview.dtoauthors.where(a => a.isupdate
|| a.authorid == -1)
select a).firstordefault();
{
mview.dtoauthors = mservice.saveauthors(mview.dtoauthors);
populatefields(mview.dtoauthors, mview.idx);
}
}
public void btnnewclick()
{
if (mview.tbxfirstname.text != ""
&& mview.tbxlastname.text != "")
{
var author = new dtoauthor
{
authorid = -1,
firstname = mview.tbxfirstname.text,
lastname = mview.tbxlastname.text,
isupdate = false
};
mview.idx = mview.dtoauthors.count - 1;
}
}
private void populatefields(list<dtoauthor> authors, int idx)
{
var author = authors[idx];
mview.tbxfirstname.text = author.firstname;
mview.tbxlastname.text = author.lastname;
}
}
}
Visual Studio Languages , .NET Framework > Visual C#
Comments
Post a Comment