Esempio n. 1
0
        static SourceData()
        {
            string fileName = Application.StartupPath + @"\data.svd";

            using (CurrencyFileReader fileReader = new CurrencyFileReader(fileName))
            {
                FileHeader fileHeader = fileReader.FileHeader;
                SourceData.Value = fileReader.Read(false).First();
            }
        }
Esempio n. 2
0
        public void ReadHeaderTest()
        {
            string             file   = @"F:\Working Folder\Project\CurrencyStore\4.Documents\项目参考资料\20130507.SVD";
            CurrencyFileReader target = new CurrencyFileReader(file); // TODO: Initialize to an appropriate value
            FileHeader         actual;

            actual = target.FileHeader;
            Assert.IsNotNull(actual);
            var lst = target.Read(false).ToArray();

            Assert.IsTrue(actual.SumRecords == lst.Length);
            target.Dispose();
        }
Esempio n. 3
0
        private UploadResult ImportDataFile(string fileName, bool isIgnoreAlreadyUpload)
        {
            UploadResult result = new UploadResult();

            using (CurrencyFileReader fileReader = new CurrencyFileReader(fileName))
            {
                FileHeader fileHeader = fileReader.FileHeader;
                IEnumerable <CurrencyInfo> dataList = fileReader.Read(isIgnoreAlreadyUpload).ToList();

                /**/

                IDeviceService deviceService = ServiceFactory.GetService <IDeviceService>();

                bool deviceExists = deviceService.CheckExists_Info(new DeviceInfo()
                {
                    DeviceNumber = fileHeader.MachineSN
                });

                result.FileType     = fileHeader.FileType;
                result.DeviceNumber = fileHeader.MachineSN;
                result.DeviceStatus = deviceExists ? "已入库" : "未入库";

                if (!deviceExists)
                {
                    DeviceInfo deviceInfo = new DeviceInfo()
                    {
                        OrgId           = 0,
                        ModelCode       = 0,
                        KindCode        = 0,
                        DeviceNumber    = fileHeader.MachineSN,
                        SoftwareVersion = fileHeader.SoftVersion,
                        OnLineTime      = DateTime.Now,
                        DeviceStatus    = 1,
                    };

                    deviceService.Save_Info(deviceInfo);
                }

                /**/

                result.TotalCount         = fileHeader.SumRecords;
                result.AlreadyUploadCount = fileHeader.UploadRecord;

                if (isIgnoreAlreadyUpload)
                {
                    result.ShouldSaveCount = result.TotalCount - result.AlreadyUploadCount;
                }

                else
                {
                    result.ShouldSaveCount = result.TotalCount;
                }

                /**/

                ICurrencyService currencyService = ServiceFactory.GetService <ICurrencyService>();

                int bufferCount            = 500;
                int maxCount               = dataList.Count();
                List <CurrencyInfo> buffer = null;

                for (int i = 0; i <= maxCount / bufferCount; i++)
                {
                    buffer = dataList.Skip(i * bufferCount).Take(bufferCount).ToList();

                    if (buffer.Count() > 0)
                    {
                        currencyService.BatchSave_Info(buffer);
                    }
                }

                result.SuccessSaveCount = maxCount;
            }

            return(result);
        }