Пример #1
0
        public void CityBankTextFile_CanLoadFile_AndValidateData()
        {
            DTO.UploadData data = ReadDataFromFile();

            IAS.DAL.Interfaces.IIASPersonEntities ctx = DAL.DALFactory.GetPersonContext();

            CityFileHeader header = BankFileFactory.ConcreateCityBankFileTransfer(ctx, "test.txt", data);

            Assert.IsNotNull(header);
            Assert.AreEqual(header.CityFileBoxHeaders.Count(), 3);
            Assert.AreEqual(header.CityFileOverFlows.Count(), 7);
            Assert.AreEqual(header.CityFileBatchHeaders.Count(), 6);
            Assert.AreEqual(header.CityFileDetails.Count(), 6);
            Assert.AreEqual(header.CityFileBatchTotals.Count(), 6);
            Assert.AreEqual(header.CityFileTotals.Count(), 3);


            Assert.AreEqual(header.CityFileTotals.ElementAt(0).CityFileDetails.Count(), 1);
            Assert.AreEqual(header.CityFileTotals.ElementAt(1).CityFileDetails.Count(), 3);
            Assert.AreEqual(header.CityFileTotals.ElementAt(2).CityFileDetails.Count(), 2);

            Int32 rownum = (1 + header.CityFileBoxHeaders.Count()
                            + header.CityFileOverFlows.Count()
                            + header.CityFileBatchHeaders.Count()
                            + header.CityFileDetails.Count()
                            + header.CityFileBatchTotals.Count()
                            + header.CityFileTotals.Count()
                            + 1);

            Assert.AreEqual(header.RowCount, rownum);


            DTO.UploadResult <DTO.SummaryBankTransaction, DTO.BankTransaction> uploadResult = header.ValidateData();
        }
Пример #2
0
        public static DTO.UploadData ReadFileUpload(String rawData)
        {
            DTO.UploadData data = new DTO.UploadData
            {
                Body = new List <string>()
            };
            //Stream rawData = FileUpload1.PostedFile.InputStream;
            using (StreamReader sr = new StreamReader(rawData, System.Text.Encoding.GetEncoding("TIS-620")))
            {
                string line = sr.ReadLine().Trim();
                if (line != null && line.Length > 0)
                {
                    if (line.Substring(0, 1) == "H")
                    {
                        data.Header = line;
                    }
                    else
                    {
                        throw new ApplicationException(Resources.errorApplicantFileHelper_001);
                    }
                }
                while ((line = sr.ReadLine()) != null)
                {
                    if (line.Trim().Length > 0)
                    {
                        data.Body.Add(line.Trim());
                    }
                }
            }

            return(data);
        }
Пример #3
0
 private DTO.UploadData GetUploadDatafromVariable()
 {
     DTO.UploadData uploadData = new DTO.UploadData()
     {
         Header    = _header,
         Body      = _lines,
         IsCSVFile = true
     };
     return(uploadData);
 }
        public void LicenseRequest_UploadFile_ValidationTest()
        {
            IAS.DAL.Interfaces.IIASPersonEntities ctx = DAL.DALFactory.GetPersonContext();
            DTO.UserProfile userProfile = CreateUserProfile();

            DTO.UploadData data     = ReadDataFromFile("ขอใหม่ - li01_1001_84.csv");
            String         fileName = "testData.txt";
            //LicenseFileHeader licenseHeader = LicenseFileFactory.ConcreateLicenseRequest(ctx, userProfile, fileName, data, "11");


            var res = CreateLicenseDataResponse();


            //res.DataResponse = licenseHeader.ValidateDataOfKTB();
            //if (res.IsError)
            //{
            //    throw new ApplicationException(res.ErrorMsg);
            //}

            //AG_IAS_TEMP_PAYMENT_HEADER payment_g_t = new AG_IAS_TEMP_PAYMENT_HEADER();
            //licenseHeader.MappingToEntity<CityFileHeader, AG_IAS_TEMP_PAYMENT_HEADER>(payment_g_t);
            //ctx.AG_IAS_TEMP_PAYMENT_HEADER.AddObject(payment_g_t);

            //foreach (CityFileDetail item in licenseHeader.CityFileDetails)
            //{
            //    AG_IAS_TEMP_PAYMENT_DETAIL detail = new AG_IAS_TEMP_PAYMENT_DETAIL();
            //    item.MappingToEntity<AG_IAS_TEMP_PAYMENT_DETAIL>(detail);
            //    ctx.AG_IAS_TEMP_PAYMENT_DETAIL.AddObject(detail);
            //}


            //ctx.AG_IAS_TEMP_PAYMENT_TOTAL.AddObject(licenseHeader.GetAG_IAS_TEMP_PAYMENT_TOTAL());

            //try
            //{
            //    using (var ts = new TransactionScope())
            //    {
            //        ctx.SaveChanges();
            //        ts.Complete();
            //    }
            //}
            //catch (Exception ex)
            //{

            //    throw;
            //}
        }
Пример #5
0
        public void KTBBankFile_Upload_File_bank_20131106()
        {
            IAS.DAL.Interfaces.IIASPersonEntities ctx = DAL.DALFactory.GetPersonContext();

            String filename = "bank_20131106.txt";


            DTO.UploadData data       = ReadDataFromFile(filename);
            BankFileHeader bankHeader = BankFileFactory.ConcreateKTBFileTransfer(ctx, filename, data);

            var res = new DTO.ResponseService <DTO.UploadResult <DTO.SummaryBankTransaction, DTO.BankTransaction> >();

            res.DataResponse = bankHeader.ValidateData();
            if (res.IsError)
            {
                throw new ApplicationException(res.ErrorMsg);
            }
        }
Пример #6
0
        public void CityBank_Upload_Can_Commit_ToEntity()
        {
            IAS.DAL.Interfaces.IIASPersonEntities ctx = DAL.DALFactory.GetPersonContext();
            DTO.UploadData data       = ReadDataFromFile();
            String         fileName   = "testData.txt";
            CityFileHeader bankHeader = BankFileFactory.ConcreateCityBankFileTransfer(ctx, fileName, data);

            var res = new DTO.ResponseService <DTO.UploadResult <DTO.SummaryBankTransaction, DTO.BankTransaction> >();

            res.DataResponse = bankHeader.ValidateData();
            if (res.IsError)
            {
                throw new ApplicationException(res.ErrorMsg);
            }

            AG_IAS_TEMP_PAYMENT_HEADER payment_g_t = new AG_IAS_TEMP_PAYMENT_HEADER();

            bankHeader.MappingToEntity <CityFileHeader, AG_IAS_TEMP_PAYMENT_HEADER>(payment_g_t);
            ctx.AG_IAS_TEMP_PAYMENT_HEADER.AddObject(payment_g_t);

            foreach (CityFileDetail item in bankHeader.CityFileDetails)
            {
                AG_IAS_TEMP_PAYMENT_DETAIL detail = new AG_IAS_TEMP_PAYMENT_DETAIL();
                item.MappingToEntity <AG_IAS_TEMP_PAYMENT_DETAIL>(detail);
                ctx.AG_IAS_TEMP_PAYMENT_DETAIL.AddObject(detail);
            }


            ctx.AG_IAS_TEMP_PAYMENT_TOTAL.AddObject(bankHeader.GetAG_IAS_TEMP_PAYMENT_TOTAL());

            try
            {
                using (var ts = new TransactionScope())
                {
                    ctx.SaveChanges();
                    ts.Complete();
                }
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Пример #7
0
        private static DTO.UploadData ReadDataFromFile()
        {
            FileInfo fileCity = new FileInfo(@"D:\OIC\IAS\IAS.DataServiceTest\SimpleFile\Industrial_Generic_Deposit_Handoff_xxxxxx_19072011.txt");


            var res = new DTO.ResponseService <DTO.UploadResult <DTO.SummaryBankTransaction, DTO.BankTransaction> >();

            if (!fileCity.Exists)
            {
                throw new ApplicationException(Resources.errorKTBFileTextFileUploadTest_001);
            }

            //เปลี่ยนสไตล์ของวันที่เป็นแบบไทย เพื่อแสดงค่าที่เป็นปี พ.ศ.
            Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("th-TH");

            DTO.UploadData data = new DTO.UploadData
            {
                Body = new List <string>()
            };


            FileStream filestream = new FileStream(fileCity.FullName, FileMode.Open);

            using (StreamReader sr = new StreamReader(filestream, System.Text.Encoding.GetEncoding("TIS-620")))
            {
                string line;
                while ((line = sr.ReadLine()) != null)
                {
                    if (line.Length > 0)
                    {
                        data.Body.Add(line);
                    }
                }
            }
            return(data);
        }
Пример #8
0
        InsertAndCheckApplicantGroupUpload(DTO.UploadData data, string fileName,
                                           DTO.RegistrationType regType,
                                           string testingNo, string examPlaceCode, DTO.UserProfile userProfile)
        {
            var res = new DTO.ResponseService <DTO.SummaryReceiveApplicant>();
            var ctx = new IASPersonEntities();

            res.DataResponse = new DTO.SummaryReceiveApplicant();

            //res.DataResponse.Header = new List<DTO.UploadHeader>();
            //res.DataResponse.Detail = new List<DTO.ApplicantTemp>();



            try
            {
                DTO.ApplicantUploadRequest request = new DTO.ApplicantUploadRequest()
                {
                    FileName      = fileName,
                    TestingNo     = testingNo,
                    UploadData    = data,
                    UserProfile   = userProfile,
                    ExamPlaceCode = examPlaceCode
                };
                IAS.DAL.Interfaces.IIASPersonEntities     ctx2     = DAL.DALFactory.GetPersonContext();
                DTO.ResponseService <ApplicantFileHeader> response = ApplicantFileFactory.ConcreateApplicantFileRequest(ctx2, request);

                if (response.IsError)
                {
                    res.ErrorMsg = response.ErrorMsg;
                    LoggerFactory.CreateLog().Fatal("ApplicantService_InsertAndCheckApplicantGroupUpload", response.ErrorMsg);
                }
                if (response.DataResponse == null)
                {
                    res.ErrorMsg = Resources.errorApplicantFileHeader_001;
                }

                AG_IAS_APPLICANT_HEADER_TEMP applicantHeadTemp = new AG_IAS_APPLICANT_HEADER_TEMP();
                response.DataResponse.MappingToEntity <ApplicantFileHeader, AG_IAS_APPLICANT_HEADER_TEMP>(applicantHeadTemp);
                ctx.AG_IAS_APPLICANT_HEADER_TEMP.AddObject(applicantHeadTemp);

                var examLicense = ctx.AG_EXAM_LICENSE_R.Where(w => w.TESTING_NO == request.TestingNo).FirstOrDefault();
                foreach (ApplicantFileDetail detail in response.DataResponse.ApplicantFileDetails)
                {
                    AG_IAS_APPLICANT_DETAIL_TEMP detailTemp = new AG_IAS_APPLICANT_DETAIL_TEMP();
                    detail.EXAM_PLACE_CODE = examLicense.EXAM_PLACE_CODE;
                    detail.MappingToEntity <ApplicantFileDetail, AG_IAS_APPLICANT_DETAIL_TEMP>(detailTemp);
                    ctx.AG_IAS_APPLICANT_DETAIL_TEMP.AddObject(detailTemp);
                }
                using (TransactionScope ts = new TransactionScope())
                {
                    ctx.SaveChanges();
                    ts.Complete();
                }

                DTO.SummaryReceiveApplicant summarize = response.DataResponse.ValidateDataOfData();
                res.DataResponse = summarize;
            }
            catch (Exception)
            {
                res.ErrorMsg = Resources.errorApplicantFileHeader_001;
                LoggerFactory.CreateLog().Fatal("ApplicantService_InsertAndCheckApplicantGroupUpload", res.ErrorMsg);
            }

            return(res);
        }
Пример #9
0
        public static DTO.ResponseService <DTO.UploadData> ReadDataFromFile(String filename)
        {
            DTO.ResponseService <DTO.UploadData> res = new DTO.ResponseService <DTO.UploadData>();

            string _netDrive     = ConfigurationManager.AppSettings["DEFAULT_NET_DRIVE"];
            string _userNetDrive = ConfigurationManager.AppSettings["USER_NET_DRIVE"];
            string _passNetDrive = ConfigurationManager.AppSettings["PASS_NET_DRIVE"];


            using (NASDrive nasDrive = new NASDrive(_netDrive, _userNetDrive, _passNetDrive))
            {
                FileInfo fileLicense = new FileInfo(Path.Combine(_netDrive, filename));

                if (!fileLicense.Exists)
                {
                    res.ErrorMsg = Resources.errorDataLicenseRequestReaderHelper_001;
                    return(res);
                }

                //เปลี่ยนสไตล์ของวันที่เป็นแบบไทย เพื่อแสดงค่าที่เป็นปี พ.ศ.
                Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("th-TH");

                DTO.UploadData data = new DTO.UploadData
                {
                    Body = new List <string>()
                };


                FileStream filestream = new FileStream(fileLicense.FullName, FileMode.Open);
                using (StreamReader sr =
                           new StreamReader(filestream,
                                            System.Text.Encoding.GetEncoding("TIS-620")))
                {
                    string line = sr.ReadLine();


                    if (line != null && line.Length > 0)
                    {
                        if (line.Substring(0, 1) == "H")
                        {
                            data.Header = line;
                        }
                        // else
                        // {
                        //res.ErrorMsg = Resources.errorDataLicenseRequestReaderHelper_002;
                        //return res;
                        //}
                        // }
                        // else
                        // {
                        //  res.ErrorMsg = Resources.errorExamService_046;
                        // return res;
                    }

                    while ((line = sr.ReadLine()) != null)
                    {
                        if (line != null && line.Length > 0 && !String.IsNullOrEmpty(line))
                        {
                            if (line.Substring(0, 1) == "H")
                            {
                                data.Header = line;
                            }



                            else if (line.Trim().Length > 0 && line.Substring(0, 11) != "ลำดับข้อมูล" && !line.Substring(0, 11).StartsWith("ลำดับ"))
                            {
                                data.Body.Add(line.Trim());
                            }
                        }
                    }

                    if (data.Body.Count == 0)
                    {
                        res.ErrorMsg = Resources.errorDataLicenseRequestReaderHelper_003;
                        return(res);
                    }
                }

                res.DataResponse = data;
            }



            return(res);
        }
Пример #10
0
        //public static BankFileHeader ConcreateBankFileTranfer(IAS.DAL.IASPersonEntities ctx, String fileName, DTO.UploadData data)
        //{
        //    if (data.Body.FirstOrDefault().Substring(0,1)=="H")
        //    {
        //        return ConcreateKTBFileTransfer(ctx, fileName, data);
        //    }
        //}

        #region CityBank File Upload
        public static CityFileHeader ConcreateCityBankFileTransfer(IAS.DAL.Interfaces.IIASPersonEntities ctx, String fileName, DTO.UploadData data)
        {
            String         id     = OracleDB.GetGenAutoId();
            CityFileHeader header = new CityFileHeader(ctx, id, fileName);
            Int32          numrow = 0;

            foreach (String record in data.Body)
            {
                numrow++;
                switch (record.Substring(0, 1))
                {
                case "1": CreateCityBankHeader(header, record, numrow);
                    break;

                case "2": header.AddBoxHeader(new CityFileBoxHeader());
                    break;

                case "4": header.AddOverFlow(new CityFileOverFlow());
                    break;

                case "5": header.AddBatchHeader(new CityFileBatchHeader());
                    break;

                case "6": header.AddDetail(CreateCityBankDetail(ctx, record, numrow));
                    break;

                case "7": header.AddBatchTotal(new CityFileBatchTotal());
                    break;

                case "8": header.SetTotal(CreateCityBankTotal(record, numrow));
                    break;

                case "9":
                    header.RowCount = Convert.ToInt32(record.Substring(1, 6));
                    break;

                default:
                    break;
                }
            }

            return(header);
        }
Пример #11
0
        public static BankFileHeader ConcreateKTBFileTransfer(IAS.DAL.Interfaces.IIASPersonEntities ctx, String fileName, DTO.UploadData data)
        {
            String         id     = OracleDB.GetGenAutoId();
            BankFileHeader header = new BankFileHeader(ctx, id, fileName);

            foreach (String record in data.Body)
            {
                switch (record.Substring(0, 1))
                {
                case "H": CreateKTBHeader(header, record);
                    break;

                case "D": header.AddDetail(CreateKTBDetail(record));
                    break;

                case "T": header.SetTotal(CreateKTBTotal(record));
                    break;

                default:
                    break;
                }
            }

            return(header);
        }
        private static DTO.UploadData ReadDataFromFile(String filename)
        {
            var res = new DTO.ResponseService <DTO.UploadLicenseResult <
                                                   DTO.UploadHeader,
                                                   DTO.ReceiveLicenseDetail,
                                                   DTO.AttachFileDetail> >();

            res.DataResponse = new DTO.UploadLicenseResult <DTO.UploadHeader, DTO.ReceiveLicenseDetail, DTO.AttachFileDetail>();

            FileInfo fileLicense = new FileInfo(Path.Combine(@"D:\OIC\IAS\IAS.DataServiceTest\SimpleFile\", filename));

            if (!fileLicense.Exists)
            {
                throw new ApplicationException(Resources.errorKTBFileTextFileUploadTest_001);
            }

            //เปลี่ยนสไตล์ของวันที่เป็นแบบไทย เพื่อแสดงค่าที่เป็นปี พ.ศ.
            Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("th-TH");

            DTO.UploadData data = new DTO.UploadData
            {
                Body = new List <string>()
            };


            FileStream filestream = new FileStream(fileLicense.FullName, FileMode.Open);

            using (StreamReader sr =
                       new StreamReader(filestream,
                                        System.Text.Encoding.GetEncoding("TIS-620")))
            {
                string line = sr.ReadLine().Trim();

                if (line != null && line.Length > 0)
                {
                    if (line.Substring(0, 1) == "H")
                    {
                        data.Header = line;
                    }
                    else
                    {
                        //res.ErrorMsg = "บรรทัดแรกต้องเป็น Header เท่านั้น!";
                        res.ErrorMsg = Resources.errorLicenseRequestFileUploadTest_001;
                        throw new ApplicationException(Resources.errorLicenseRequestFileUploadTest_001);
                    }
                }
                else
                {
                    res.ErrorMsg = Resources.errorLicenseRequestFileUploadTest_002;
                    throw new ApplicationException(Resources.errorLicenseRequestFileUploadTest_002);
                }

                while ((line = sr.ReadLine()) != null)
                {
                    if (line.Trim().Length > 0)
                    {
                        data.Body.Add(line.Trim());
                    }
                }

                if (data.Body.Count == 0)
                {
                    res.ErrorMsg = Resources.errorLicenseRequestFileUploadTest_003;
                    throw new ApplicationException(Resources.errorLicenseRequestFileUploadTest_003);
                }
            }
            return(data);
        }
Пример #13
0
        UploadData(string fileName, Stream rawData, string userId, String selbankCode)
        {
            var res = new DTO.ResponseService <DTO.UploadResult <DTO.SummaryBankTransaction, DTO.BankTransaction> >();

            if (rawData == null)
            {
                res.ErrorMsg = Resources.errorApplicantBiz_001;
                return(res);
            }

            //เปลี่ยนสไตล์ของวันที่เป็นแบบไทย เพื่อแสดงค่าที่เป็นปี พ.ศ.
            Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("th-TH");

            DTO.UploadData data = new DTO.UploadData
            {
                Body = new List <string>()
            };

            try
            {
                using (StreamReader sr = new StreamReader(rawData, System.Text.Encoding.GetEncoding("TIS-620")))
                {
                    String type = "";

                    String headline = sr.ReadLine();
                    if (!String.IsNullOrEmpty(headline))
                    {
                        String bankcode = "";

                        if (headline.Substring(0, 1) == "H")
                        {
                            if (headline.Length != 256)
                            {
                                throw new ApplicationException(Resources.errorPaymentBiz_001);
                            }
                            bankcode = headline.Substring(7, 3);
                        }
                        else if (headline.Substring(0, 1) == "1")
                        {
                            bankcode = headline.Substring(33, 3);
                        }
                        else
                        {
                            throw new ApplicationException(Resources.errorPaymentBiz_001);
                        }


                        type = headline.Substring(0, 1);

                        if (bankcode != selbankCode)
                        {
                            throw new ApplicationException(Resources.errorPaymentBiz_002);
                        }

                        data.Body.Add(headline);
                    }
                    else
                    {
                        res.ErrorMsg = Resources.errorPaymentBiz_001;
                        return(res);
                    }

                    Boolean IsBreak    = false;
                    Boolean IsHaveData = false;
                    string  line;
                    while ((line = sr.ReadLine()) != null)
                    {
                        if (line != null && line.Length > 0)
                        {
                            String recordType = line.Substring(0, 1);

                            if (type == "H")
                            {
                                if (line.Length != 256)
                                {
                                    throw new ApplicationException(Resources.errorPaymentBiz_001);
                                }
                                if (recordType == " ")
                                {
                                    res.ErrorMsg = Resources.errorPaymentBiz_001;
                                    return(res);
                                }
                                else if (recordType == "D")
                                {
                                    data.Body.Add(line);
                                    IsHaveData = true;
                                }
                                else if (recordType == "T")
                                {
                                    if (IsHaveData)
                                    {
                                        data.Body.Add(line);
                                        IsBreak = true;
                                    }
                                    else
                                    {
                                        res.ErrorMsg = Resources.errorPaymentBiz_001;
                                        return(res);
                                    }
                                }
                                else
                                {
                                    res.ErrorMsg = Resources.errorPaymentBiz_001;
                                    return(res);
                                }
                            }
                            else if (type == "1")
                            {
                                if (recordType == " ")
                                {
                                    res.ErrorMsg = Resources.errorPaymentBiz_001;
                                    return(res);
                                }
                                else if (recordType == "2" ||
                                         recordType == "4" ||
                                         recordType == "5" ||
                                         recordType == "7"
                                         )
                                {
                                    data.Body.Add(line);
                                }
                                else if (recordType == "6")
                                {
                                    data.Body.Add(line);
                                    IsHaveData = true;
                                }
                                else if (recordType == "8")
                                {
                                    if (IsHaveData)
                                    {
                                        data.Body.Add(line);
                                        IsHaveData = false;
                                    }
                                    else
                                    {
                                        res.ErrorMsg = Resources.errorPaymentBiz_001;
                                        return(res);
                                    }
                                }
                                else if (recordType == "9")
                                {
                                    data.Body.Add(line);
                                    IsBreak = true;
                                }
                                else
                                {
                                    res.ErrorMsg = Resources.errorPaymentBiz_001;
                                    return(res);
                                }
                            }
                        }

                        if (IsBreak)
                        {
                            break;
                        }
                    }

                    res = svc.InsertAndCheckPaymentUpload(data, fileName, userId);
                }
            }
            catch (IOException ex)
            {
                res.ErrorMsg = Resources.errorPaymentBiz_001;
            }
            catch (Exception ex)
            {
                res.ErrorMsg = Resources.errorPaymentBiz_001;
            }

            return(res);
        }