Exemple #1
0
        public static String StartCompressByOicApprove(IAS.DAL.Interfaces.IIASPersonEntities ctx, List <DTO.GenLicenseDetail> LicenseDetail, String userName, String zipName)
        {
            string _netDrive     = ConfigurationManager.AppSettings["DEFAULT_NET_DRIVE"];
            string _userNetDrive = ConfigurationManager.AppSettings["USER_NET_DRIVE"];
            string _passNetDrive = ConfigurationManager.AppSettings["PASS_NET_DRIVE"];
            String _compressPath = ConfigurationManager.AppSettings["COMPRESS_FOLDER"].ToString();
            String imageTypeCode = ConfigurationManager.AppSettings["CODE_ATTACH_PHOTO"].ToString();

            NASDrive nasDrive = new NASDrive(_netDrive, _userNetDrive, _passNetDrive);
            // กำหนด รหัส TypeImage สำหรับค้นหา
            Boolean       IsNotCreateFolder = true;
            DirectoryInfo zipFolder         = null;

            foreach (var item in LicenseDetail)
            {
                AG_IAS_LICENSE_D           LD        = ctx.AG_IAS_LICENSE_D.FirstOrDefault(s => s.ID_CARD_NO == item.ID_CARD_NO && s.UPLOAD_GROUP_NO == item.UPLOAD_GROUP_NO);
                AG_IAS_LICENSE_H           LH        = ctx.AG_IAS_LICENSE_H.Single(w => w.UPLOAD_GROUP_NO == LD.UPLOAD_GROUP_NO);
                AG_IAS_LICENSE_TYPE_R      licenType = ctx.AG_IAS_LICENSE_TYPE_R.Single(s => s.LICENSE_TYPE_CODE == LH.LICENSE_TYPE_CODE);
                AG_IAS_ATTACH_FILE_LICENSE attach    = Helpers.GetIASConfigHelper.GetAttachLicensePhoto(ctx, LD.ID_CARD_NO, LD.UPLOAD_GROUP_NO);

                if (attach == null)
                {
                    nasDrive.Dispose();
                    throw new ApplicationException(String.Format("ไม่พบ รูปสำหรับทำใบอนุญาติของ {0} {1} {2}", LD.NAMES, LD.LASTNAME, LD.ID_CARD_NO));
                }

                if (IsNotCreateFolder)
                {
                    zipFolder = CreateDirectory(Path.Combine(_netDrive, _compressPath),
                                                (String.IsNullOrEmpty(zipName)) ? DateTime.Now.ToString("yyyy-MM-dd-hhmmss") : zipName,
                                                0);
                    IsNotCreateFolder = false;
                }
                AddLicenseRequest(ctx, _netDrive, zipFolder, LD, LH, licenType, attach);
            }

            String zipfileName = "";

            if (!IsNotCreateFolder)
            {
                using (ZipFile zip = new ZipFile())
                {
                    zip.AddDirectory(zipFolder.FullName); // recurses subdirectories
                    zipfileName = zipFolder.FullName + ".zip";
                    zip.Save(zipfileName);
                    zipfileName = zipfileName.Replace(_netDrive, "");
                }

                if (Directory.Exists(zipFolder.FullName))
                {
                    Directory.Delete(zipFolder.FullName, true);
                }
            }
            nasDrive.Dispose();
            return(zipfileName);
        }
Exemple #2
0
        private static void AddLicenseRequest(IAS.DAL.Interfaces.IIASPersonEntities ctx, String _netDrive,
                                              DirectoryInfo zipFolder, AG_IAS_SUBPAYMENT_H_T SubPaymentHT, AG_IAS_SUBPAYMENT_D_T subPaymentDT,
                                              AG_IAS_LICENSE_D licenD, AG_IAS_LICENSE_H licenH, AG_IAS_LICENSE_TYPE_R licenType, AG_IAS_ATTACH_FILE_LICENSE attach)
        {
            String        filePath = String.Format(@"{0}\{1}\{2}\{3}", zipFolder.FullName, ((String.IsNullOrEmpty(licenH.COMP_CODE))?"0000": licenH.COMP_CODE), SubPaymentHT.PETITION_TYPE_CODE, licenType.LICENSE_TYPE_CODE);
            DirectoryInfo dirInfo  = new DirectoryInfo(Path.Combine(_netDrive, filePath));

            if (!dirInfo.Exists)
            {
                dirInfo.Create();
            }

            FileInfo fileInfo = new FileInfo(Path.Combine(dirInfo.FullName, "1.txt"));

            if (!fileInfo.Exists)
            {
                using (System.IO.StreamWriter file = new System.IO.StreamWriter(fileInfo.FullName, true, Encoding.GetEncoding(874)))
                {
                    file.WriteLine("ชื่อรูป,เลขที่ใบอนุญาต,เลขบัตรประชาชน,ชื่อ,สกุล,วันที่ออกใบอนุญาต,วันที่หมดอายุ,บริษัท,ประเภทใบอนุญาต,");
                }
            }


            using (System.IO.StreamWriter file = new System.IO.StreamWriter(fileInfo.FullName, true, Encoding.GetEncoding(874)))
            {
                file.WriteLine(String.Format("{0},{1},{2},{3},{4},\"{5}\",\"{6}\",{7},{8},", subPaymentDT.ID_CARD_NO,
                                             WordSpacing(subPaymentDT.LICENSE_NO),
                                             WordSpacing(subPaymentDT.ID_CARD_NO),
                                             String.Format("{0} {1}", licenD.TITLE_NAME, licenD.NAMES),
                                             licenD.LASTNAME,
                                             ((DateTime)licenD.LICENSE_DATE).ToString("dd/MM/yyy", CultureInfo.CreateSpecificCulture("th-TH")),
                                             ((DateTime)licenD.LICENSE_EXPIRE_DATE).ToString("dd/MM/yyy", CultureInfo.CreateSpecificCulture("th-TH")),
                                             licenH.COMP_NAME,
                                             licenType.LICENSE_TYPE_NAME));
            }



            Int32  start     = attach.ATTACH_FILE_PATH.LastIndexOf('.');
            Int32  len       = attach.ATTACH_FILE_PATH.Length;
            String extension = attach.ATTACH_FILE_PATH.Substring(attach.ATTACH_FILE_PATH.LastIndexOf('.'), len - start);

            MoveFileResponse response = FileManagerService.RemoteFileCommand(new MoveFileRequest()
            {
                CurrentContainer = "",
                CurrentFileName  = attach.ATTACH_FILE_PATH,
                TargetContainer  = String.Format(@"{0}\{1}", dirInfo.FullName.Replace(_netDrive, ""), "images"),
                TargetFileName   = String.Format("{0}{1}", licenD.ID_CARD_NO, extension)
            }).Action();

            if (response.Code != "0000")
            {
                throw new ApplicationException(response.Message);
            }
        }
 private void CreateAttachFileLicense(AG_IAS_LICENSE_D license, String userId)
 {
     for (int i = 1; i <= 3; i++)
     {
         String fullName = String.Format(@"AttachFile\{0}\{1}_{2}.jpg", userId, license.ID_CARD_NO, i.ToString("00"));
         _attachLicenses.Add(new AG_IAS_ATTACH_FILE_LICENSE()
         {
             ID_ATTACH_FILE   = OracleDB.GetGenAutoId(),
             ID_CARD_NO       = license.ID_CARD_NO,
             ATTACH_FILE_PATH = fullName,
             FILE_STATUS      = "A",
             GROUP_LICENSE_ID = license.UPLOAD_GROUP_NO
         });
     }
 }
        private AG_IAS_LICENSE_D CreateLicenseD(AG_IAS_LICENSE_H h, String seq, String lencenseNo, DateTime licenseStart,
                                                DateTime licenseEnd, String idCard, String titleName, String names, String lastName, String userId)
        {
            AG_IAS_LICENSE_D license = new AG_IAS_LICENSE_D()
            {
                UPLOAD_GROUP_NO     = h.UPLOAD_GROUP_NO,
                SEQ_NO              = seq,
                LICENSE_NO          = lencenseNo,
                LICENSE_DATE        = licenseStart,
                LICENSE_EXPIRE_DATE = licenseEnd,
                ID_CARD_NO          = idCard,
                TITLE_NAME          = titleName,
                NAMES    = names,
                LASTNAME = lastName
            };

            CreateAttachFileLicense(license, userId);
            return(license);
        }
        private AG_IAS_SUBPAYMENT_D_T CreateSubPaymentDT(AG_IAS_SUBPAYMENT_H_T ht, String paymentNo, String idCard,
                                                         String status, String receiptNo, DateTime receiptDate)
        {
            AG_IAS_LICENSE_D licenD = LicenseDs.Single(l => l.ID_CARD_NO == idCard);
            AG_IAS_LICENSE_H licenH = LicenseHs.Single(l => l.UPLOAD_GROUP_NO == licenD.UPLOAD_GROUP_NO);

            return(new AG_IAS_SUBPAYMENT_D_T()
            {
                PAYMENT_NO = paymentNo,
                HEAD_REQUEST_NO = ht.HEAD_REQUEST_NO,
                ID_CARD_NO = licenD.ID_CARD_NO,
                LICENSE_NO = licenD.LICENSE_NO,
                LICENSE_TYPE_CODE = licenH.LICENSE_TYPE_CODE,
                RECORD_STATUS = status,
                RECEIPT_NO = receiptNo,
                RECEIPT_DATE = receiptDate,
                UPLOAD_GROUP_NO = licenD.UPLOAD_GROUP_NO,
                SEQ_NO = licenD.SEQ_NO
            });
        }
        public void TestSelect_PaymentRequestLicense_From_MockData()
        {
            String zipName = "TestZip6";

            DirectoryInfo zipFolder = CreateDirectory(Path.Combine(_netDrive, _oicPath), zipName, 0);

            //ดึงข้อมูลการเงินจากธนาคารใน Temp ตาม BatchID
            IEnumerable <AG_IAS_PAYMENT_G_T> paymentGTs = GetPaymentGTs();

            foreach (AG_IAS_PAYMENT_G_T paymentGT in paymentGTs)
            {
                //หาข้อมูลที่ Sub Payment Head
                IEnumerable <AG_IAS_SUBPAYMENT_H_T> subPaymentHTs = GetSubPaymentHead(paymentGT);

                foreach (AG_IAS_SUBPAYMENT_H_T SubPaymentHT in subPaymentHTs)
                {
                    IEnumerable <AG_IAS_SUBPAYMENT_D_T> subPaymentDTs = GetSubPaymentDetails(SubPaymentHT);


                    foreach (AG_IAS_SUBPAYMENT_D_T subPaymentDT in subPaymentDTs)
                    {
                        AG_IAS_LICENSE_D licenD = LicenseDs.SingleOrDefault(w => w.UPLOAD_GROUP_NO == subPaymentDT.UPLOAD_GROUP_NO &&
                                                                            w.SEQ_NO == subPaymentDT.SEQ_NO);
                        AG_IAS_LICENSE_H licenH = LicenseHs.Single(w => w.UPLOAD_GROUP_NO == licenD.UPLOAD_GROUP_NO);

                        AG_IAS_LICENSE_TYPE_R licenType = LicenseTypeRs.Single(l => l.LICENSE_TYPE_CODE == subPaymentDT.LICENSE_TYPE_CODE);

                        AG_IAS_ATTACH_FILE_LICENSE attach = AttachLicenses.Single(a => a.ID_CARD_NO == licenD.ID_CARD_NO &&
                                                                                  a.GROUP_LICENSE_ID == licenD.UPLOAD_GROUP_NO &&
                                                                                  a.ATTACH_FILE_PATH.EndsWith("03.jpg"));
                        AddLicenseRequest(zipFolder, SubPaymentHT, subPaymentDT, licenD, licenH, licenType, attach);
                    }
                }
            }

            using (ZipFile zip = new ZipFile())
            {
                zip.AddDirectory(zipFolder.FullName); // recurses subdirectories
                zip.Save(zipFolder.FullName + ".zip");
            }
        }
Exemple #7
0
        public static LicensePetitionType1314Request ConcreateLicensePetitionType1314Request(AG_IAS_SUBPAYMENT_D_T subDetail, AG_IAS_LICENSE_D licenseD)
        {
            LicensePetitionType1314Request licenseRequest1314 = new LicensePetitionType1314Request()
            {
                SEQ_NO             = subDetail.SEQ_NO,                 // row["SEQ_NO"].ToString(),
                UPLOAD_GROUP_NO    = subDetail.UPLOAD_GROUP_NO,        // row["UPLOAD_GROUP_NO"].ToString(),
                PETITION_TYPE_CODE = subDetail.PETITION_TYPE_CODE,
                RECEIPT_DATE       = (DateTime)subDetail.RECEIPT_DATE, // Convert.ToDateTime(row["receipt_date"]),
                RECEIPT_NO         = subDetail.RECEIPT_NO,             // row["receipt_no"].ToString(),
                REQUEST_NO         = licenseD.REQUEST_NO,
                PAYMENT_NO         = subDetail.PAYMENT_NO,             // row["payment_no"].ToString(),
                LICENSE_NO         = licenseD.LICENSE_NO,
                AREA = (licenseD.AREA_CODE.Length >= 2)? licenseD.AREA_CODE.Substring(0, 2) : ""
            };

            return(licenseRequest1314);
        }
        public static void LicensePetitionType(IAS.DAL.Interfaces.IIASPersonEntities ctx, OracleConnection Connection, LicensePetitionType11Request licenseRequest)
        {
            Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("th-TH");
            String LicenseNo = GenLicenseNumber.AG_LICENSE_RUNNING(ctx, (DateTime)licenseRequest.RECEIPT_DATE, licenseRequest.LICENSE_TYPE_CODE); // Convert.ToDateTime(dt.Rows[i]["receipt_date"]), dt.Rows[i]["license_type_code"].ToString());


            var License = new DAL.AG_LICENSE_T
            {
                LICENSE_NO        = LicenseNo,
                LICENSE_DATE      = licenseRequest.RECEIPT_DATE,
                EXPIRE_DATE       = licenseRequest.EXPIRATION_DATE,
                LICENSE_TYPE_CODE = licenseRequest.LICENSE_TYPE_CODE,
                NEW_LICENSE_NO    = null,
                LICENSE_ACTOR     = null,
                DATE_LICENSE_ACT  = licenseRequest.RECEIPT_DATE,
                REMARK            = null,
                UNIT_LINK_RENEW   = null,
                START_UL_DATE     = null,
                EXPIRE_UL_DATE    = null,
                UNIT_LINK_STATUS  = null
            };

            ctx.AG_LICENSE_T.AddObject(License);

            //Check Null
            AG_IAS_LICENSE_D entLicenseD = ctx.AG_IAS_LICENSE_D.FirstOrDefault(a => a.SEQ_NO == licenseRequest.SEQ_NO && a.UPLOAD_GROUP_NO == licenseRequest.UPLOAD_GROUP_NO);

            if (entLicenseD != null)
            {
                entLicenseD.LICENSE_NO          = LicenseNo;
                entLicenseD.LICENSE_DATE        = DateTime.Now;
                entLicenseD.LICENSE_EXPIRE_DATE = licenseRequest.EXPIRATION_DATE;
            }

            //Check Null
            AG_IAS_SUBPAYMENT_D_T entSubpaymentD = ctx.AG_IAS_SUBPAYMENT_D_T.FirstOrDefault(a => a.SEQ_NO == licenseRequest.SEQ_NO && a.UPLOAD_GROUP_NO == licenseRequest.UPLOAD_GROUP_NO);

            if (entSubpaymentD != null)
            {
                entSubpaymentD.LICENSE_NO = LicenseNo;
            }


            OracleCommand objCmd = new OracleCommand()
            {
                Connection  = Connection,
                CommandText = "IAS_UPDATE_11",
                CommandType = CommandType.StoredProcedure
            };

            objCmd.Parameters.Add("P_id_card_no", OracleDbType.Varchar2).Value        = SetValue(licenseRequest.ID_CARD_NO);
            objCmd.Parameters.Add("P_license_type_code", OracleDbType.Varchar2).Value = SetValue(licenseRequest.LICENSE_TYPE_CODE);
            objCmd.Parameters.Add("P_license_no", OracleDbType.Varchar2).Value        = SetValue(LicenseNo);
            objCmd.Parameters.Add("COMP_CODE", OracleDbType.Varchar2).Value           = SetValue(licenseRequest.COMP_CODE);
            objCmd.Parameters.Add("P_RECEIPT_DATE", OracleDbType.Date).Value          = licenseRequest.RECEIPT_DATE;
            objCmd.Parameters.Add("P_REQUEST_NO", OracleDbType.Varchar2).Value        = SetValue(entLicenseD.REQUEST_NO);
            objCmd.Parameters.Add("P_PAYMENT_NO", OracleDbType.Varchar2).Value        = SetValue(licenseRequest.PAYMENT_NO);
            objCmd.Parameters.Add("P_testing_no", OracleDbType.Varchar2).Value        = SetValue(licenseRequest.TESTING_NO);
            objCmd.Parameters.Add("P_RECEIPT_NO", OracleDbType.Varchar2).Value        = SetValue(licenseRequest.RECEIPT_NO);
            objCmd.ExecuteNonQuery();
        }
Exemple #9
0
        public static String StartCompressByPayment(IAS.DAL.Interfaces.IIASPersonEntities ctx, DateTime findDate, String userName, String zipName)
        {
            string _netDrive     = ConfigurationManager.AppSettings["DEFAULT_NET_DRIVE"];
            string _userNetDrive = ConfigurationManager.AppSettings["USER_NET_DRIVE"];
            string _passNetDrive = ConfigurationManager.AppSettings["PASS_NET_DRIVE"];
            String _compressPath = ConfigurationManager.AppSettings["COMPRESS_FOLDER"].ToString();
            String imageTypeCode = ConfigurationManager.AppSettings["CODE_ATTACH_PHOTO"].ToString();

            NASDrive nasDrive;

            nasDrive = new NASDrive(_netDrive, _userNetDrive, _passNetDrive);



            // กำหนด รหัส TypeImage สำหรับค้นหา


            Boolean IsNotCreateFolder = true;


            DirectoryInfo zipFolder = null;

            //ดึงข้อมูลการเงินจากธนาคารใน Temp ตาม BatchID
            IEnumerable <AG_IAS_PAYMENT_G_T> paymentGTs = GetPaymentGTs(ctx, findDate);

            foreach (AG_IAS_PAYMENT_G_T paymentGT in paymentGTs)
            {
                //หาข้อมูลที่ Sub Payment Head
                IEnumerable <AG_IAS_SUBPAYMENT_H_T> subPaymentHTs = GetSubPaymentHead(ctx, paymentGT);

                foreach (AG_IAS_SUBPAYMENT_H_T SubPaymentHT in subPaymentHTs)
                {
                    IEnumerable <AG_IAS_SUBPAYMENT_D_T> subPaymentDTs = GetSubPaymentDetails(ctx, SubPaymentHT);


                    foreach (AG_IAS_SUBPAYMENT_D_T subPaymentDT in subPaymentDTs) // milk มาทำ เพิ่ม if else กันกรณีหลุด ไม่มีค่าแล้วเป็นข้อความ error
                    {
                        if ((subPaymentDT.UPLOAD_GROUP_NO != null) && (subPaymentDT.SEQ_NO != null))
                        {
                            AG_IAS_LICENSE_D licenD = ctx.AG_IAS_LICENSE_D.SingleOrDefault(w => w.UPLOAD_GROUP_NO == subPaymentDT.UPLOAD_GROUP_NO &&
                                                                                           w.SEQ_NO == subPaymentDT.SEQ_NO);
                            AG_IAS_LICENSE_H licenH = ctx.AG_IAS_LICENSE_H.Single(w => w.UPLOAD_GROUP_NO == licenD.UPLOAD_GROUP_NO);

                            if (subPaymentDT.LICENSE_TYPE_CODE != null)
                            {
                                if (licenD.OIC_APPROVED_BY != null)
                                {
                                    String whereType = String.Format("_{0}.", imageTypeCode);
                                    AG_IAS_LICENSE_TYPE_R      licenType = ctx.AG_IAS_LICENSE_TYPE_R.Single(l => l.LICENSE_TYPE_CODE == subPaymentDT.LICENSE_TYPE_CODE);
                                    AG_IAS_ATTACH_FILE_LICENSE attach    = ctx.AG_IAS_ATTACH_FILE_LICENSE.SingleOrDefault(a => a.ID_CARD_NO == licenD.ID_CARD_NO &&
                                                                                                                          a.GROUP_LICENSE_ID == licenD.UPLOAD_GROUP_NO &&
                                                                                                                          a.ATTACH_FILE_PATH.Contains(whereType));

                                    if (attach == null)
                                    {
                                        nasDrive.Dispose();
                                        throw new ApplicationException(String.Format("ไม่พบ รูปสำหรับทำใบอนุญาติของ {0} {1} {2}", licenD.NAMES, licenD.LASTNAME, licenD.ID_CARD_NO));
                                    }



                                    if (IsNotCreateFolder)
                                    {
                                        zipFolder = CreateDirectory(Path.Combine(_netDrive, _compressPath),
                                                                    (String.IsNullOrEmpty(zipName)) ? findDate.ToString("yyyy-MM-dd-hhmmss") : zipName,
                                                                    0);
                                        IsNotCreateFolder = false;
                                    }
                                    AddLicenseRequest(ctx, _netDrive, zipFolder, SubPaymentHT, subPaymentDT, licenD, licenH, licenType, attach);
                                }
                            }
                            else
                            {
                                throw new ApplicationException(String.Format("ไม่พบประเภทใบอนุญาตของ {0}{1} {2} {3}", licenD.TITLE_NAME, licenD.NAMES, licenD.LASTNAME, licenD.ID_CARD_NO));
                            }
                        }
                        else
                        {
                            throw new ApplicationException(String.Format("ไม่พบเลขอ้างอิงในการอัพโหลดเอกสารของ หมายเลขบัตรประชาชน {0} ", subPaymentDT.ID_CARD_NO));
                        }
                    }
                }
            }


            String zipfileName = "";

            if (!IsNotCreateFolder)
            {
                using (ZipFile zip = new ZipFile())
                {
                    zip.AddDirectory(zipFolder.FullName); // recurses subdirectories
                    zipfileName = zipFolder.FullName + ".zip";
                    zip.Save(zipfileName);
                    zipfileName = zipfileName.Replace(_netDrive, "");
                }
            }
            nasDrive.Dispose();
            return(zipfileName);
        }
        public void TestSelect_PaymentRequestLicense_From_DAL()
        {
            IAS.DAL.Interfaces.IIASPersonEntities ctx = DAL.DALFactory.GetPersonContext();
            IList <AG_IAS_LICENSE_H> _licenseHs       = new List <AG_IAS_LICENSE_H>();
            IList <AG_IAS_LICENSE_D> _licenseDs       = new List <AG_IAS_LICENSE_D>();

            _licenseTypeRs  = ctx.AG_IAS_LICENSE_TYPE_R.ToList();
            _petitionTypeRs = ctx.AG_IAS_PETITION_TYPE_R.ToList();

            String        zipName   = "TestZip";
            DirectoryInfo zipFolder = CreateDirectory(_netDrive, zipName, 0);

            //ดึงข้อมูลการเงินจากธนาคารใน Temp ตาม BatchID
            var paymentGTs = ctx.AG_IAS_PAYMENT_G_T.Where(f => f.STATUS == "P" && f.GROUP_REQUEST_NO == "999999561000000040")
                             .ToList();

            foreach (AG_IAS_PAYMENT_G_T paymentGT in paymentGTs)
            {
                //หาข้อมูลที่ Sub Payment Head
                //var subPaymentHTs = ctx.AG_IAS_SUBPAYMENT_H_T
                //                    .Where(w => w.GROUP_REQUEST_NO == paymentGT.GROUP_REQUEST_NO &&
                //                              (w.STATUS != null && w.STATUS == "P"))
                //                    .ToList();
                var subPaymentHTs = ctx.AG_IAS_SUBPAYMENT_H_T
                                    .Where(w => w.GROUP_REQUEST_NO == paymentGT.GROUP_REQUEST_NO &&
                                           (w.STATUS != null && w.STATUS == "P") &&
                                           (
                                               w.PETITION_TYPE_CODE == "11" ||
                                               w.PETITION_TYPE_CODE == "13" ||
                                               w.PETITION_TYPE_CODE == "14" ||
                                               w.PETITION_TYPE_CODE == "15" ||
                                               w.PETITION_TYPE_CODE == "16" ||
                                               w.PETITION_TYPE_CODE == "17" ||
                                               w.PETITION_TYPE_CODE == "18"
                                           )
                                           ).ToList();


                foreach (AG_IAS_SUBPAYMENT_H_T SubPaymentHT in subPaymentHTs)
                {
                    IEnumerable <AG_IAS_SUBPAYMENT_D_T> subPaymentDTs =
                        ctx.AG_IAS_SUBPAYMENT_D_T.Where(w => w.HEAD_REQUEST_NO == SubPaymentHT.HEAD_REQUEST_NO &&
                                                        !String.IsNullOrEmpty(w.RECEIPT_NO));


                    foreach (AG_IAS_SUBPAYMENT_D_T subPaymentDT in subPaymentDTs)
                    {
                        AG_IAS_LICENSE_D licenD = ctx.AG_IAS_LICENSE_D.SingleOrDefault(w => w.UPLOAD_GROUP_NO == subPaymentDT.UPLOAD_GROUP_NO &&
                                                                                       w.SEQ_NO == subPaymentDT.SEQ_NO);
                        AG_IAS_LICENSE_H licenH = ctx.AG_IAS_LICENSE_H.Single(w => w.UPLOAD_GROUP_NO == licenD.UPLOAD_GROUP_NO);

                        AG_IAS_ATTACH_FILE_LICENSE attach = ctx.AG_IAS_ATTACH_FILE_LICENSE.Single(a => a.ID_CARD_NO == licenD.ID_CARD_NO &&
                                                                                                  a.GROUP_LICENSE_ID == licenD.UPLOAD_GROUP_NO &&
                                                                                                  a.ATTACH_FILE_PATH.EndsWith("03.jpg"));
                        AG_IAS_LICENSE_TYPE_R licenType = LicenseTypeRs.Single(l => l.LICENSE_TYPE_CODE == subPaymentDT.LICENSE_TYPE_CODE);


                        String        filePath = String.Format(@"{0}\{1}\{2}", zipFolder.FullName, SubPaymentHT.PETITION_TYPE_CODE, licenType.LICENSE_TYPE_NAME);
                        DirectoryInfo dirInfo  = new DirectoryInfo(Path.Combine(_netDrive, filePath));
                        if (!dirInfo.Exists)
                        {
                            dirInfo.Create();
                        }

                        FileInfo fileInfo = new FileInfo(Path.Combine(dirInfo.FullName, "1.txt"));
                        if (!fileInfo.Exists)
                        {
                            using (System.IO.StreamWriter file = fileInfo.CreateText())
                            {
                                file.WriteLine("ชื่อรูป,เลขที่ใบอนุญาต,เลขบัตรประชาชน,ชื่อ,สกุล,วันที่ออกใบอนุญาต,วันที่หมดอายุ,บริษัท,ประเภทใบอนุญาต,");
                            }
                        }


                        using (System.IO.StreamWriter file = fileInfo.AppendText())
                        {
                            file.WriteLine(String.Format("{0},{1},{2},{3},{4},{5},{6},{7},{8},", subPaymentDT.ID_CARD_NO,
                                                         WordSpacing(subPaymentDT.LICENSE_NO),
                                                         WordSpacing(subPaymentDT.ID_CARD_NO),
                                                         String.Format("{0} {1}", licenD.TITLE_NAME, licenD.NAMES),
                                                         licenD.LASTNAME,
                                                         ((DateTime)licenD.LICENSE_DATE).ToString("dd/MM/yyy", CultureInfo.CreateSpecificCulture("th-TH")),
                                                         ((DateTime)licenD.LICENSE_EXPIRE_DATE).ToString("dd/MM/yyy", CultureInfo.CreateSpecificCulture("th-TH")),
                                                         licenH.COMP_NAME,
                                                         licenType.LICENSE_TYPE_NAME));
                        }
                    }
                }
            }
        }