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 bll.dto;
using system.collections.generic;
using system.windows.forms;
namespace demowindowsformapp.views
{
    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;
using system.collections.generic;
using system.windows.forms;
using bll.dto;
using demowindowsformapp.presenters;
using demowindowsformapp.views;
using services;
namespace demowindowsformapp
{
    public partial class authorview : form, iauthorview
    {
        #region members
        private authorviewpresenter mpresenter;
        #endregion
        public authorview()
        {
            mpresenter = new authorviewpresenter(this, theservice1.instance);
            initializecomponent();
        }
        public int idx { get; set; }
     
        public list<dtoauthor> dtoauthors { get; set; }
       
        public label lblauthorid
        {
            { return lblauthorid; }
            set { lblauthorid = value; }
        }
        public textbox tbxfirstname
        {
            { return tbxfirstname; }
            set { tbxfirstname = value; }
        }
        public textbox tbxlastname
        {
            { return tbxlastname; }
            set { tbxlastname = value; }
        }
        private void authorview_load(object sender, eventargs e)
        {
            mpresenter.load();
        }
        private void btnfirst_click(object sender, eventargs e)
        {
            mpresenter.btnfirstclick();
        }
        private void btnprev_click(object sender, eventargs e)
        {
            mpresenter.btnprevclick();
        }
        private void btnnext_click(object sender, eventargs e)
        {
            mpresenter.btnnextclick();
        }
        private void btnlast_click(object sender, eventargs e)
        {
            mpresenter.btnlastclick();
        }
        private void btnclear_click(object sender, eventargs e)
        {
            mpresenter.btnclearclick();
        }
        private void btnupdate_click(object sender, eventargs e)
        {
            mpresenter.btnupdateclick();
        }
        private void btnnew_click(object sender, eventargs e)
        {
            mpresenter.btnnewclick();
        }
        private void btnsend_click(object sender, eventargs e)
        {
            mpresenter.btnsendclick();
        }
       
    }
}

the presenter....................

using system.linq;
using system.collections.generic;
using demowindowsformapp.views;
using bll.dto;
using services.iservices;
namespace demowindowsformapp.presenters
{
    public class authorviewpresenter
    {
        private readonly iauthorview mview;
        private readonly iservice1 mservice;
        #region constructor
        public authorviewpresenter(iauthorview view, iservice1  theservice)
        {
            mview = view;
            mservice = theservice;
        }
        #endregion
        #region public methods
        public void load()
        {
         
            var authors = mservice.getauthorswhere();
            mview.dtoauthors = authors;
            mview.idx = 0;
            populatefields(mview.dtoauthors, mview.idx);
        }
        public void btnfirstclick()
        {
            mview.idx = 0;
            populatefields(mview.dtoauthors, mview.idx);
        }
        public void btnprevclick()
        {
            if(mview.idx == 0)
            {
                populatefields(mview.dtoauthors, mview.idx);
            }
            else
            {
                mview.idx -= 1;
                populatefields(mview.dtoauthors, mview.idx);
            }
        }
        public void btnnextclick()
        {
            if (mview.idx == mview.dtoauthors.count - 1)
            {
                populatefields(mview.dtoauthors, mview.idx);
            }
            else
            {
                mview.idx += 1;
                populatefields(mview.dtoauthors, mview.idx);
            }
        }
        public void btnlastclick()
        {
            mview.idx = mview.dtoauthors.count - 1;
            populatefields(mview.dtoauthors, mview.idx);
        }
        public void btnupdateclick()
        {
            var author = mview.dtoauthors[mview.idx];
            author.firstname = mview.tbxfirstname.text;
            author.lastname = mview.tbxlastname.text;
            author.isupdate = true;
        }
        public void btnclearclick()
        {
            mview.tbxfirstname.text = "";
            mview.tbxlastname.text = "";
            mview.lblauthorid.text = "author not saved yet.";
        }
        public void btnsendclick()
        {
            var atleastoneauthor = (from in mview.dtoauthors.where(a => a.isupdate
                                     || a.authorid == -1)
                                    select a).firstordefault();
            if (atleastoneauthor != null)
            {
                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.dtoauthors.add(author);
                mview.idx = mview.dtoauthors.count - 1;
            }
        }
        #endregion
        #region private methods
       
        private void populatefields(list<dtoauthor> authors, int idx)
        {
            var author = authors[idx];
            mview.lblauthorid.text = author.authorid.tostring();
            mview.tbxfirstname.text = author.firstname;
            mview.tbxlastname.text = author.lastname;
        }
        #endregion
    }
}



Visual Studio Languages  ,  .NET Framework  >  Visual C#



Comments

Popular posts from this blog

Azure DocumentDB Owner resource does not exist

BizTalk Server 2013 Azure VM Log Shipping and HA for hosts

How to Share webservice object to all user