using DevExpress.ExpressApp;
using DevExpress.ExpressApp.Actions;
using DevExpress.ExpressApp.Utils;
using EntityFirst.Module.BusinessObjects;
using System;
using System.Collections.Generic;
using System.Linq;
// namespaces...
namespace EntityFirst.Module.Controllers
{
    // public classes...
    public partial class CompanyController : ViewController
    {
        // public constructors...
        public CompanyController()
        {
            InitializeComponent();
            FilterByCompany.Items.Clear();
            var item = new ChoiceActionItem(CaptionHelper.GetMemberCaption(typeof(Employee), "Company 1"), 1);
            FilterByCompany.Items.Add(item);
            var item_2 = new ChoiceActionItem(CaptionHelper.GetMemberCaption(typeof(Employee), "Company 2"), 2);
            FilterByCompany.Items.Add(item_2);

            FilterByCompany.SelectedIndex = 0;
            Global_Attributes.CompanyFilter = 1;
        }
        // private methods...
        private void CompanyController_Activated(object sender, EventArgs e)
        {
            foreach (var item in FilterByCompany.Items)
            {
                if (Convert.ToInt32(item.Data) == Global_Attributes.CompanyFilter)
                {
                    FilterByCompany.SelectedItem = item;
                }
            }
        }
        private void FilterByCompany_Execute(object sender, SingleChoiceActionExecuteEventArgs e)
        {
            Global_Attributes.CompanyFilter = Convert.ToInt32(FilterByCompany.SelectedItem.Data);
            ObjectSpace.Refresh();
        }
        // protected methods...
        protected override void OnActivated()
        {
            base.OnActivated();
        }
        protected override void OnDeactivated()
        {
            base.OnDeactivated();
        }
        protected override void OnViewControlsCreated()
        {
            base.OnViewControlsCreated();
        }
    }
}
