﻿using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using LJH.Inventory.BusinessModel;
using LJH.Inventory.BLL;
using LJH.Inventory.BusinessModel.SearchCondition;
using LJH.GeneralLibrary.Core.DAL;

namespace LJH.Inventory.UI.Controls
{
    public partial class ProductColorComboBox : System.Windows.Forms.ComboBox
    {
        public ProductColorComboBox()
        {
            InitializeComponent();
        }

        public ProductColorComboBox(IContainer container)
        {
            container.Add(this);

            InitializeComponent();
        }

        #region 公共方法
        public void Init(ItemClass pc)
        {
            var con = new ProductSearchCondition() { Classes = new List<ItemClass>() { pc } };
            Init(con);
        }

        public void Init(List<ItemClass> pcs)
        {
            var con = new ProductSearchCondition() { Classes = pcs };
            Init(con);
        }

        public void Init(SearchCondition con)
        {
            this.Items.Clear();
            var items = new ProductBLL(AppSettings.Current.ConnStr).GetAllColors(con);
            if (items != null && items.Count > 0)
            {
                this.Items.Add(string.Empty);
                items = (from it in items
                         where !string.IsNullOrEmpty(it)
                         orderby it ascending
                         select it).ToList();
                foreach (var item in items)
                {
                    this.Items.Add(item);
                }
            }
        }
        #endregion
    }
}
