using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;

namespace ChuPiao.Common.Models
{
    /// <summary>
    /// 彩票机时段报表
    /// </summary>
    public class R_MachineReportEntity
    {
        #region Model
        private int _r_id;
        private DateTime _r_starttime = new DateTime(1900, 1, 1);
        private DateTime _r_endtime = new DateTime(1900, 1, 1);
        private decimal _r_salemoney = 0;
        private int _r_saleticket = 0;
        private decimal _r_encashmoney = 0;
        private int _r_encashticket = 0;
        private string _r_zxmacnumber = "";
        private DateTime _r_querytime = new DateTime(1900, 1, 1);
        private string _r_prntext = "";

        private decimal _r_returnmoney = 0;
        /// <summary>
        /// 主键ID
        /// </summary>
        public int R_Id
        {
            set { _r_id = value; }
            get { return _r_id; }
        }
        /// <summary>
        /// 开始时间
        /// </summary>
        public DateTime R_StartTime
        {
            set { _r_starttime = value; }
            get { return _r_starttime; }
        }
        /// <summary>
        /// 截止时间
        /// </summary>
        public DateTime R_EndTime
        {
            set { _r_endtime = value; }
            get { return _r_endtime; }
        }
        /// <summary>
        /// 销售金额
        /// </summary>
        public decimal R_SaleMoney
        {
            set { _r_salemoney = value; }
            get { return _r_salemoney; }
        }
        /// <summary>
        /// 销售票数
        /// </summary>
        public int R_SaleTicket
        {
            get { return _r_saleticket; }
            set { _r_saleticket = value; }
        }
        /// <summary>
        /// 兑奖金额
        /// </summary>
        public decimal R_EncashMoney
        {
            set { _r_encashmoney = value; }
            get { return _r_encashmoney; }
        }
        /// <summary>
        /// 兑奖票数
        /// </summary>
        public int R_EncashTicket
        {
            get { return _r_encashticket; }
            set { _r_encashticket = value; }
        }
        /// <summary>
        /// 机器号
        /// </summary>
        public string R_ZxMacNumber
        {
            set { _r_zxmacnumber = value; }
            get { return _r_zxmacnumber; }
        }
        /// <summary>
        /// 报表查询时间
        /// </summary>
        public DateTime R_QueryTime
        {
            set { _r_querytime = value; }
            get { return _r_querytime; }
        }
        /// <summary>
        /// 电子票文本
        /// </summary>
        public string R_PrnText
        {
            get { return _r_prntext; }
            set { _r_prntext = value; }
        }

        /// <summary>
        /// 退票金额（作为兑奖数据，区别在于中心结算时，退票金额不算佣金）
        /// </summary>
        public decimal R_ReturnMoney
        {
            get { return _r_returnmoney; }
            set { _r_returnmoney = value; }
        }

        #endregion Model

        
        public R_MachineReportEntity()
        {

        }
        public R_MachineReportEntity(XmlNode xmlNode)
        {
            if(xmlNode==null)
            {
                return;
            }
            XmlNode node = xmlNode.SelectSingleNode("id");
            if(node!=null)
            {
                int.TryParse(node.InnerText, out _r_id);
            }
            node = xmlNode.SelectSingleNode("starttime");
            if (node != null)
            {
                DateTime.TryParse(node.InnerText, out _r_starttime);
            }
            node = xmlNode.SelectSingleNode("endtime");
            if (node != null)
            {
                DateTime.TryParse(node.InnerText, out _r_endtime);
            }
            node = xmlNode.SelectSingleNode("salemoney");
            if (node != null)
            {
                decimal.TryParse(node.InnerText, out _r_salemoney);
            }
            node = xmlNode.SelectSingleNode("saleticket");
            if (node != null)
            {
                int.TryParse(node.InnerText, out _r_saleticket);
            }
            node = xmlNode.SelectSingleNode("encashmoney");
            if (node != null)
            {
                decimal.TryParse(node.InnerText, out _r_encashmoney);
            }
            node = xmlNode.SelectSingleNode("encashticket");
            if (node != null)
            {
                int.TryParse(node.InnerText, out _r_encashticket);
            }
            node = xmlNode.SelectSingleNode("zxmacnumber");
            if (node != null)
            {
                _r_zxmacnumber = node.InnerText;
            }
            node = xmlNode.SelectSingleNode("querytime");
            if (node != null)
            {
                DateTime.TryParse(node.InnerText, out _r_querytime);
            }
            node = xmlNode.SelectSingleNode("prntext");
            if (node != null)
            {
                _r_prntext = node.InnerText;
            }

            node = xmlNode.SelectSingleNode("returnmoney");
            if (node != null)
            {
                decimal.TryParse(node.InnerText, out _r_returnmoney);
            }
        }
        public string Pack()
        {
            StringBuilder dataBuilder = new StringBuilder();
            dataBuilder.Append("<machinereport>");
            dataBuilder.AppendFormat("<id>{0}</id>",_r_id);
            dataBuilder.AppendFormat("<starttime>{0}</starttime>",_r_starttime);
            dataBuilder.AppendFormat("<endtime>{0}</endtime>",_r_endtime);
            dataBuilder.AppendFormat("<salemoney>{0}</salemoney>",_r_salemoney);
            dataBuilder.AppendFormat("<saleticket>{0}</saleticket>",_r_saleticket);
            dataBuilder.AppendFormat("<encashmoney>{0}</encashmoney>",_r_encashmoney);
            dataBuilder.AppendFormat("<encashticket>{0}</encashticket>",_r_encashticket);
            dataBuilder.AppendFormat("<returnmoney>{0}</returnmoney>", _r_returnmoney);
            dataBuilder.AppendFormat("<zxmacnumber>{0}</zxmacnumber>",_r_zxmacnumber);
            dataBuilder.AppendFormat("<querytime>{0}</querytime>",_r_querytime);
            dataBuilder.AppendFormat("<prntext>{0}</prntext>",_r_prntext);
            dataBuilder.Append("</machinereport>");
            return dataBuilder.ToString();
        }
    }
}
