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.Common.Utils;
using ChuPiao.Common.Communication.GtdJson.Packs;
using ChuPiao.Common.Communication.GtdJson;

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

        public DlgDaySales(M_MachineEntity machine)
        {
            InitializeComponent();

            _machine = machine;
        }

        private void DlgDaySales_Load(object sender, EventArgs e)
        {
            this.Text += "----" + _machine.M_Number;
            this.dateTimePicker1.Value = DateTime.Now;
            this.dataGridView1.AutoGenerateColumns = false;

            query();
        }

        private void query()
        {
            int ticket = 0;
            decimal money = 0.0M;
            List<DaySalesEntity> list = new List<DaySalesEntity>();
            DaySalesEntity entity;
            foreach (int lotid in LotPlayTypeHashTable.LotTypeHashTable.Keys)
            {
                try
                {
                    A10004GetSales pack = new A10004GetSales();
                    pack.AgentId = _machine.M_Number;
                    pack.Salt = _machine.M_Salt;
                    pack.LotId = lotid;
                    pack.AbbDate = Int32.Parse(this.dateTimePicker1.Value.ToString("yyyyMMdd"));
                    A10004GetSalesRet packRet = PackManager.Instance.Send(pack) as A10004GetSalesRet;

                    entity = new DaySalesEntity();
                    entity.Lot = LotPlayTypeHashTable.LotTypeHashTable[lotid].ToString();
                    entity.Ticket = packRet.Ticket;
                    entity.Money = packRet.Money;
                    list.Add(entity);

                    ticket += packRet.Ticket;
                    money += packRet.Money;
                    
                }
                catch (Exception ex)
                {
                    LogUtil.LogInfo(ex.ToString());
                }
            }

            this.dataGridView1.DataSource = list;
            this.label1.Text = string.Format("ºÏ¼Æ£º{0} ÕÅ {1:0} Ôª", ticket, money);

        }

        private void startAutoBtn_Click(object sender, EventArgs e)
        {
            query();
        }
    }

    public class DaySalesEntity
    {
        private string lot;
        /// <summary>
        /// 2019-07-11
        /// </summary>
        public string Lot
        {
            get { return lot; }
            set { lot = value; }
        }

        private int ticket;
        /// <summary>
        /// 4001
        /// </summary>
        public int Ticket
        {
            get { return ticket; }
            set { ticket = value; }
        }

        private decimal money;
        /// <summary>
        /// 4001
        /// </summary>
        public decimal Money
        {
            get { return money; }
            set { money = value; }
        }
    }

}