using System.Text;
using System.Text.RegularExpressions;

namespace ChuPiao.AutoPrint.Machine.Models
{
    /// <summary>
    /// 抓取数据的信息
    /// </summary>
    public class CaptureDataInfo
    {
        public CaptureDataInfo(byte[] captureDataBytes)
        {
            _captureDataBytes = captureDataBytes;
            //_captureDataString = Encoding.GetEncoding("gb2312").GetString(_captureDataBytes);
            _captureDataString = Encoding.GetEncoding("GB18030").GetString(_captureDataBytes);

            

            //去掉无效字符
            _captureDataString = Regex.Replace(_captureDataString, @"U\?\0[\s\S]{1}", "");   //天津盒子
            _captureDataString = Regex.Replace(_captureDataString, @"钶[\s\S]{2}", "");     //湖北盒子

            //湖北元字有乱码
            _captureDataString = _captureDataString.Replace(@"灶\?@\?", "元").Replace("灶?@?", "元");

            //广西“其它”有乱码             (3:3)@60.00元+(平祁?@渌?@175.0元+(2:4)@60           (负祁?渌?)@50.00元     (平祁?@渌?)@
            Regex re = new Regex(@"祁.*?渌.*?@");
            _captureDataString = re.Replace(_captureDataString, "其它)@");

            //_captureDataString = _captureDataString.Replace(@"祁?@渌?", "其它)").Replace(@"祁?渌?", "其它");

        }
        private byte[] _captureDataBytes;
        private string _captureDataString;
        /// <summary>
        /// 抓取数据的二进制格式
        /// </summary>
        public byte[] CaptureDataBytes
        {
            get { return _captureDataBytes; }
            set { _captureDataBytes = value; }
        }
        /// <summary>
        /// 抓取数据的字符串格式
        /// </summary>
        public string CaptureDataString
        {
            get { return _captureDataString; }
            set { _captureDataString = value; }
        }
    }
}
