private bool FormatModel(string entityContent, BusinessDataSetting setting, out ScanModel model)
        {
            model = new ScanModel();
            List <string> dataList        = entityContent.Split(new string[] { setting.FileSpilit }, StringSplitOptions.None).ToList();
            List <string> titleColumnList = setting.TitleColumn.Split(new string[] { setting.FileSpilit }, StringSplitOptions.None).ToList();

            if (string.IsNullOrEmpty(string.Join("", dataList).Trim()) == false)
            {
                if (dataList.Count < titleColumnList.Count)
                {
                    throw new Exception("导入文件格式出错");
                }
                model.DeviceId        = dataList[0];
                model.ModelNumber     = dataList[1];
                model.HardwareVersion = dataList[2];
                model.QRCodeFormat    = dataList[3];
                model.EncryptedQRCode = dataList[4];
                if (titleColumnList.Contains("ScanTime"))
                {
                    model.ScanTime = dataList[5];
                    model.Barcode  = dataList[6];
                }
                return(true);
            }
            else
            {
                return(false);
            }
        }
        private void LoadPO(string poNumber = "")
        {
            if (string.IsNullOrEmpty(poNumber) == false)
            {
                BusinessDataSetting setting = DataSettingList.FirstOrDefault(c => c.FileType == "Data");
                string po      = poNumber + "." + setting.FileExtension;
                string strPath = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"ScanLogs";
                POMACList.Clear();
                if (!Directory.Exists(strPath))
                {
                    return;
                }
                strPath = strPath + "\\" + po;

                if (File.Exists(strPath) == false)
                {
                    return;
                }
                string content = "";
                using (FileStream fs = new FileStream(strPath, FileMode.Open, FileAccess.Read))
                {
                    StreamReader thisStreamReader = new StreamReader(fs, Encoding.UTF8);
                    content = thisStreamReader.ReadToEnd();
                    thisStreamReader.Close();
                }

                List <string> dataList = content.Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries).ToList();

                //format string to Model
                foreach (string entityContent in dataList)
                {
                    if (dataList.IndexOf(entityContent) >= setting.DataIndex)
                    {
                        ScanModel model;
                        if (FormatModel(entityContent, setting, out model))
                        {
                            POMACList.Add(model);
                        }
                    }
                }
            }
            //else
            //{
            //
            //    POMACList.Clear();
            //}
            //POMACList.AddRange(barcodeArray);

            this.RefreshDataGrid();
            this.RefreshUI();
        }
        private void ImportFile(string fileName)
        {
            BusinessDataSetting setting = DataSettingList.FirstOrDefault(c => c.FileType == "Import");
            string strPath = fileName;

            if (File.Exists(strPath) == false)
            {
                return;
            }
            string content = "";

            using (FileStream fs = new FileStream(strPath, FileMode.Open, FileAccess.Read))
            {
                StreamReader thisStreamReader = new StreamReader(fs, Encoding.UTF8);
                content = thisStreamReader.ReadToEnd();
                thisStreamReader.Close();
            }

            List <string> dataList = content.Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries).ToList();

            POMACList.Clear();
            //format string to Model
            foreach (string entityContent in dataList)
            {
                if (dataList.IndexOf(entityContent) >= setting.DataIndex)
                {
                    try
                    {
                        ScanModel model;
                        if (FormatModel(entityContent, setting, out model))
                        {
                            POMACList.Add(model);
                        }
                    }
                    catch (Exception ex)
                    {
                        throw new Exception(string.Format("Row {0}:{1}", dataList.IndexOf(entityContent), entityContent), ex.InnerException);
                    }
                }
            }
            //POMACList.AddRange(barcodeArray);
        }
        public static void SaveData(string ponumber, List <ScanModel> dataList, string exportFileName = "")
        {
            BusinessDataSetting setting = DataSettingList.FirstOrDefault(c => c.FileType == "Data");
            string fileName             = ponumber + "." + setting.FileExtension;
            string strPath = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"ScanLogs";



            strPath = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"ScanLogs";

            if (!Directory.Exists(strPath))
            {
                Directory.CreateDirectory(strPath);
            }
            strPath = strPath + "\\" + fileName;

            if (string.IsNullOrEmpty(exportFileName) == false)
            {
                strPath = exportFileName;
            }

            //format datalist to string
            StringBuilder sb = new StringBuilder();

            sb.AppendLine(setting.TitleColumn);
            foreach (ScanModel entity in dataList)
            {
                sb.AppendLine(string.Format("{1}{0}{2}{0}{3}{0}{4}{0}{5}{0}{6}{0}{7}", setting.FileSpilit, entity.DeviceId, entity.ModelNumber, entity.HardwareVersion, entity.QRCodeFormat, entity.EncryptedQRCode, entity.ScanTime, entity.Barcode));
            }

            using (FileStream fs = new FileStream(strPath, FileMode.OpenOrCreate, FileAccess.Write))
            {
                StreamWriter thisStreamWriter = new StreamWriter(fs, Encoding.UTF8);
                //thisStreamWriter.BaseStream.Seek(0, SeekOrigin.End);
                thisStreamWriter.Write(sb.ToString());
                thisStreamWriter.Flush();
                thisStreamWriter.Close();
            }
        }