0

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

我有这个功能,它根据州选择code behind填充城市。DropDownListDropDownList

这是我的功能。

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。index 属于SelectedIndexState DropDownList。id是DropDownList需要填写的城市。

这是BLL类

namespace CwizBankApp
{
    public class CustomerBLL
    {
        public IList<mem_city> GetCities(int index)
        {
            using (var db = new DataClasses1DataContext())
            {
                var city = db.mem_cities.Where(c => c.state_id.Equals(index)).ToList();
                return city;
            }
        }
    }
}

我需要将函数从后面的代码移动到 BLL 类。

我该怎么做。

谁能帮我解决这个问题?欢迎任何建议。

4

1 回答 1

1

我建议不要在 BLL 课程中执行此操作。不要强迫它使用 BLL,因为它旨在将数据访问逻辑与表示逻辑分开。

于 2012-07-04T09:30:56.493 回答