using System;
using System.Collections.Generic;
using System.Windows.Forms;
using ChuPiao.AutoPrint.Desktop.Properties;
using ChuPiao.AutoPrint.Services;
using ChuPiao.AutoPrint.Services.AutoEncash;
using ChuPiao.Common.Enums;
using ChuPiao.Common.Models;
using ChuPiao.Common.Utils;

namespace ChuPiao.AutoPrint.Desktop.AutoEncash
{
    public class AutoEncashToolStrip : ToolStrip
    {
        public System.Windows.Forms.ToolStripButton toolStripButtonSelect;
        private System.Windows.Forms.ToolStripSeparator toolStripSeparator2;
        private System.Windows.Forms.ToolStripLabel toolStripLabelBoxLotType;
        public ToolStripComboBox toolStripComboBoxLotType;
        public System.Windows.Forms.ToolStripLabel toolStripLabelAbbdate;
        public System.Windows.Forms.ToolStripTextBox toolStripTextBoxAbbdate;
        public System.Windows.Forms.ToolStripLabel toolStripLabelExpect;
        public ToolStripComboBox toolStripComboBoxExpectFrom;
        public System.Windows.Forms.ToolStripLabel toolStripLabelTo;
        public ToolStripComboBox toolStripComboBoxExpectTo;
        private System.Windows.Forms.ToolStripLabel toolStripLabelType;
        public ToolStripComboBox toolStripComboBoxType;
        private System.Windows.Forms.ToolStripLabel toolStripLabelOption;
        public ToolStripComboBox toolStripComboBoxOption;
        private System.Windows.Forms.ToolStripSeparator toolStripSeparator3;
        public ToolStripButton toolStripButtonLoad;
        public ToolStripButton toolStripButtonLoadBig;
        public ToolStripButton toolStripButtonStart;
        public ToolStripButton toolStripButtonStop;
        public ToolStripButton toolStripButtonEncashConfig;
        //private System.Windows.Forms.ToolStripSeparator toolStripSeparator4;
        public AutoEncashToolStrip()
        {
            this.toolStripButtonSelect = new ToolStripButton("反选");
            this.toolStripSeparator2 = new ToolStripSeparator();
            this.toolStripLabelBoxLotType=new ToolStripLabel("彩种");
            this.toolStripComboBoxLotType = new ToolStripComboBox();
            this.toolStripComboBoxLotType.DropDownStyle = ComboBoxStyle.DropDownList;
            this.toolStripLabelAbbdate = new ToolStripLabel("日期/期号");
            this.toolStripTextBoxAbbdate = new ToolStripTextBox();
            this.toolStripLabelExpect=new ToolStripLabel("期号");
            this.toolStripComboBoxExpectFrom = new ToolStripComboBox();
            this.toolStripComboBoxExpectFrom.DropDownStyle = ComboBoxStyle.DropDownList;
            this.toolStripLabelTo = new ToolStripLabel("-");
            this.toolStripComboBoxExpectTo = new ToolStripComboBox();
            this.toolStripComboBoxExpectTo.DropDownStyle = ComboBoxStyle.DropDownList;
            this.toolStripLabelType = new ToolStripLabel("加载方式");
            this.toolStripComboBoxType = new ToolStripComboBox();
            this.toolStripComboBoxType.DropDownStyle = ComboBoxStyle.DropDownList;
            this.toolStripLabelOption = new ToolStripLabel("兑奖选项");
            this.toolStripComboBoxOption = new ToolStripComboBox();
            this.toolStripComboBoxOption.DropDownStyle = ComboBoxStyle.DropDownList;
            this.toolStripSeparator3=new ToolStripSeparator();
            this.toolStripButtonLoad = new ToolStripButton("加载机器兑奖票");
            this.toolStripButtonLoadBig = new ToolStripButton("加载中心兑奖票");
            this.toolStripButtonStart = new ToolStripButton("开始打印");
            this.toolStripButtonStop = new ToolStripButton("停止打印");
            //this.toolStripButtonEncashConfig = new ToolStripButton("兑奖配置");

            this.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
            
            this.toolStripLabelBoxLotType,
                this.toolStripComboBoxLotType,
                this.toolStripLabelAbbdate,
               this.toolStripTextBoxAbbdate,
            //    this.toolStripLabelExpect,
            //    this.toolStripComboBoxExpectFrom,
            //    this.toolStripLabelTo,
            //    this.toolStripComboBoxExpectTo,
            //    this.toolStripLabelType,
            //    this.toolStripComboBoxType,
            //    this.toolStripLabelOption,
            //    this.toolStripComboBoxOption,
                this.toolStripButtonSelect,
            
            this.toolStripSeparator2,
            this.toolStripButtonLoad,this.toolStripButtonLoadBig,this.toolStripSeparator3,
            this.toolStripButtonStart,
            this.toolStripButtonStop});

            //this.toolStripButtonSelect.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text;

            this.toolStripButtonStart.Image = Resources.Run;
            this.toolStripButtonStop.Image = Resources.Stop;

            toolStripTextBoxAbbdate.Text = DateTime.Now.AddDays(-1).ToString("yyyyMMdd");
            toolStripLabelAbbdate.Visible = true;
            toolStripTextBoxAbbdate.Visible = true;

            toolStripComboBoxLotType.SelectedIndexChanged += new EventHandler(toolStripComboBoxLotType_SelectedIndexChanged);

            //M_LotTypeService lotTypeService=new M_LotTypeService();
            //List<M_LotTypeEntity> lotTypeList = lotTypeService.GetLotTypeList();
            //if(lotTypeList!=null && lotTypeList.Count>0)
            //{
            foreach (int lotid in LotPlayTypeHashTable.LotTypeHashTable.Keys)
            {
                M_LotTypeEntity lotEntity = new M_LotTypeEntity();
                lotEntity.L_LotId = lotid;
                lotEntity.L_LotName = LotPlayTypeHashTable.LotTypeHashTable[lotid].ToString();
                this.toolStripComboBoxLotType.Items.Add(lotEntity);
            }
            if (toolStripComboBoxLotType.Items.Count > 0)
            {
                this.toolStripComboBoxLotType.SelectedIndex = 0;
            }
            //}
            EnumDescription[] encashTypeList = EnumDescription.GetFieldTexts(typeof(EncashLoadType));
            this.toolStripComboBoxType.Items.Clear();
            if(encashTypeList.Length>0)
            {
                foreach (EnumDescription enumDescription in encashTypeList)
                {
                    this.toolStripComboBoxType.Items.Add(enumDescription);
                }
                if (toolStripComboBoxType.Items.Count>0)
                {
                    this.toolStripComboBoxType.SelectedIndex = 0;
                }
            }
            EnumDescription[] encashOptionList = EnumDescription.GetFieldTexts(typeof(EncashOption));
            this.toolStripComboBoxOption.Items.Clear();
            if (encashOptionList.Length > 0)
            {
                foreach (EnumDescription enumDescription in encashOptionList)
                {
                    this.toolStripComboBoxOption.Items.Add(enumDescription);
                }
                if (toolStripComboBoxOption.Items.Count>0)
                {
                    this.toolStripComboBoxOption.SelectedIndex = 0;
                }
            }
        }

        void toolStripComboBoxLotType_SelectedIndexChanged(object sender, EventArgs e)
        {
            //加载彩种期号列表
            try
            {
                M_LotTypeEntity lotTypeEntity = toolStripComboBoxLotType.SelectedItem as M_LotTypeEntity;
                if (lotTypeEntity != null)
                {
                    //if (lotTypeEntity.L_LotId == (int)Lottype.Jz || lotTypeEntity.L_LotId == (int)Lottype.Jl || lotTypeEntity.L_LotId == (int)Lottype.Jm)
                    //{
                        toolStripLabelAbbdate.Visible = true;
                        toolStripTextBoxAbbdate.Visible = true;
                        toolStripLabelExpect.Visible = false;
                        toolStripComboBoxExpectFrom.Visible = false;
                        toolStripComboBoxExpectTo.Visible = false;
                    //}
                    //else
                    //{
                    //    toolStripLabelAbbdate.Visible = false;
                    //    toolStripTextBoxAbbdate.Visible = false;
                    //    toolStripLabelExpect.Visible = true;
                    //    toolStripComboBoxExpectFrom.Visible = true;
                    //    toolStripComboBoxExpectTo.Visible = true; 
                    //    //L_ExpectService expectService = new L_ExpectService();
                    //    //List<L_ExpectEntity> list = expectService.GetNewlyExpectList(lotTypeEntity.L_LotId); 
                        
                    //    //if (list != null && list.Count > 0)
                    //    //{
                    //    //    toolStripComboBoxExpectFrom.Items.Clear();
                    //    //    toolStripComboBoxExpectTo.Items.Clear();
                    //    //    int selectedIndex = 0;
                    //    //    int i = 0;
                    //    //    foreach (L_ExpectEntity entity in list)
                    //    //    {
                    //    //        if (entity.E_Active == 1)
                    //    //        {
                    //    //            selectedIndex = i;
                    //    //        }
                    //    //        toolStripComboBoxExpectFrom.Items.Add(entity);
                    //    //        toolStripComboBoxExpectTo.Items.Add(entity);
                    //    //        i++;
                    //    //    }
                    //    //    toolStripComboBoxExpectFrom.SelectedIndex = selectedIndex;
                    //    //    toolStripComboBoxExpectTo.SelectedIndex = selectedIndex;
                    //    //}
                    //}
                }
            }
            catch (Exception exception)
            {
                MessageService.ShowError(string.Concat("加载自动兑奖期号列表异常。错误信息：", exception.Message));
            }
        }

        
    }
}
