using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using ChuPiao.Common.Models;
using ChuPiao.AutoPrint.Configuration;
using ChuPiao.AutoPrint.Services.AutoPrint;
using ChuPiao.AutoPrint.Services;

namespace ChuPiao.AutoPrint.Desktop.Dialogs
{
    public partial class DlgMachineLot : Form
    {
        private M_MachineEntity _machine = null;

        public DlgMachineLot(M_MachineEntity machine)
        {
            InitializeComponent();

            _machine = machine;
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
        }

        private void DlgMachineLot_Load(object sender, EventArgs e)
        {
            this.Text = _machine.M_Number;


            if (_machine.M_LotStr.Contains("911,"))
            {
                chk_Jz.Checked = true;
            }

            if (_machine.M_LotStr.Contains("951,"))
            {
                chk_Jl.Checked = true;
            }

            if (_machine.M_LotStr.Contains("701,"))
            {
                chk_Lt.Checked = true;
            }

            if (_machine.M_LotStr.Contains("601,"))
            {
                chk_Sf.Checked = true;
            }

            if (_machine.M_LotStr.Contains("503,"))
            {
                chk_Hd.Checked = true;
            }
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            MachineXmlEntity machine = AutoPrintServiceManager.MachineXmlEntityDic[_machine.M_Number];

            string lotstr = "";
            if (chk_Jz.Checked)
            {
                lotstr += "911,";
            }
            if (chk_Jl.Checked)
            {
                lotstr += "951,";
            }
            if (chk_Lt.Checked)
            {
                lotstr += "701,";
            }
            if (chk_Sf.Checked)
            {
                lotstr += "601,";
            }
            if (chk_Hd.Checked)
            {
                lotstr += "503,";
            }

            machine.M_Lots = lotstr;
            _machine.M_LotStr = lotstr;

            MachineXmlConfig.SaveMachineList(new List<MachineXmlEntity>(AutoPrintServiceManager.MachineXmlEntityDic.Values));

            MessageService.ShowMessage("修改可出票彩种为["+lotstr+"]成功，立即生效！");
            this.DialogResult = DialogResult.OK;
        }
    }
}