将函数从代码移到业务逻辑层类

时间:2012-07-04 09:25:20

标签: c# asp.net code-behind business-logic-layer

我正在使用ASP.NET Web Forms/C#

我在code behind中使用此功能,根据状态DropDownList选择填充城市DropDownList

这是我的功能。

public void CityFill(int index,int id)
        {
            //This function calls GetCities method which will get all cities of a state.
            var city = CustomerBLL.GetCities(index);



            //If id=0 then clear all dropdown before filling
            //or else they get appended.
            if (id == 0)
            {
                NewCustomerddlResidentialCity.Items.Clear();
                NewCustomerddlOfficeCity.Items.Clear();
                NewCustomerddlNativeCity.Items.Clear();
                NewCustomerddlNomineeCity.Items.Clear();
            }
            else
            {
                //If 1 then clear residential city
                if(id==1)
                    NewCustomerddlResidentialCity.Items.Clear();

                //If 2 then clear Office city.
                if(id==2)
                    NewCustomerddlOfficeCity.Items.Clear();

                //If id=3 then clear Native City.
                if(id==3)
                    NewCustomerddlNativeCity.Items.Clear();

                //If id=4 then clear Nominee City
                if(id==4)
                    NewCustomerddlNomineeCity.Items.Clear();
            }

            //Loop through all the cities in st object
            foreach (var c in city)
            {
                //If id=0 then fill all dropdowns
                if (id == 0)
                {
                    NewCustomerddlResidentialCity.Items.Add(c.city_name.Trim());
                    NewCustomerddlOfficeCity.Items.Add(c.city_name.Trim());
                    NewCustomerddlNativeCity.Items.Add(c.city_name.Trim());
                    NewCustomerddlNomineeCity.Items.Add(c.city_name.Trim());
                }
                else
                {
                    //If 1 then fill Res City
                    if(id==1)
                    NewCustomerddlResidentialCity.Items.Add(c.city_name.Trim());

                    //If 2 then fill Off City
                    if(id==2)
                    NewCustomerddlOfficeCity.Items.Add(c.city_name.Trim());

                    //If 3 then fill nat city
                    if(id==3)
                    NewCustomerddlNativeCity.Items.Add(c.city_name.Trim());

                    //If 4 then fill nominee city
                    if(id==4)
                    NewCustomerddlNomineeCity.Items.Add(c.city_name.Trim());

                }
            }
        }

传递给函数的参数是index和id。 索引是状态SelectedIndex的{​​{1}}。 id是需要填写哪个城市DropDownList

这是BLL类

DropDownList

我需要将函数从代码移到BLL类。

我该怎么做呢。

任何人都可以帮我解决这个问题吗? 欢迎任何建议。

1 个答案:

答案 0 :(得分:1)

我建议不要在BLL课程中执行此操作。请勿将其强制为BLL,因为它旨在从表示逻辑中分离数据访问逻辑。