コード例 #1
0
ファイル: GenQRcode.cs プロジェクト: ekarincodizm/IAS
        public static byte[] CreateQRcode(string PDF_path, string UID)
        {
            ctx = DAL.DALFactory.GetPersonContext();

            string ImgPath = @"OIC\QRCodeIASWebSite.jpg";

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

            byte[] buffer = null;
            using (NASDrive nasDrive = new NASDrive(_netDrive, _userNetDrive, _passNetDrive))
            {
                Stream fileStream = new FileStream(_netDrive + "" + ImgPath, FileMode.Open);
                buffer = new Byte[fileStream.Length + 1];
                BinaryReader br = new BinaryReader(fileStream);
                buffer = br.ReadBytes(Convert.ToInt32((fileStream.Length)));
                br.Close();
            }
            return(buffer);


            //ReceiveNumber referanceNumber = new ReceiveNumber(_oicNumber, RunningNumber, DateTime.Now);
            //return referanceNumber;
        }
コード例 #2
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);
        }
コード例 #3
0
 protected void ConnectNetDrive()
 {
     this.nasDrive = new NASDrive(_netDrive, _userNetDrive, _passNetDrive);
 }
コード例 #4
0
        public static DTO.ResponseService <DTO.CompressFileDetail> ExtractFile(String compressFile)
        {
            DTO.ResponseService <DTO.CompressFileDetail> res = new DTO.ResponseService <DTO.CompressFileDetail>();
            res.DataResponse = new CompressFileDetail();
            res.DataResponse.AttatchFiles = new List <DTO.AttachFileDetail>();

            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))
            {
                //******************** ******* Check FileExist************************************/
                FileInfo compressFileInfo = new FileInfo(Path.Combine(_netDrive, compressFile));

                if (!compressFileInfo.Exists)
                {
                    res.ErrorMsg = Resources.errorExtractFileLicenseRequestHelper_001;
                    return(res);
                }

                //ถ้าไม่ใช่ไฟล์ .ZIP หรือ .RAR
                if (!".ZIP_.RAR".Contains(compressFileInfo.Extension.ToUpper()))
                {
                    res.ErrorMsg = Resources.errorExtractFileLicenseRequestHelper_002;
                    return(res);
                }
                //****************************************************************/


                String _targetFullPath = Path.GetDirectoryName(compressFileInfo.FullName);

                DirectoryInfo targetDirectory = new DirectoryInfo(_targetFullPath);
                if (!targetDirectory.Exists)
                {
                    targetDirectory.Create();
                }

                Utils.CompressFile cf = new Utils.CompressFile();

                bool result        = false;
                var  fileInRAR_Zip = new List <string>();

                if (compressFileInfo.Extension.ToUpper() == ".ZIP")
                {
                    fileInRAR_Zip = cf.GetFilesInZip(compressFileInfo.FullName);
                    result        = cf.ZipExtract(compressFileInfo.FullName, targetDirectory.FullName);
                }
                else if (compressFileInfo.Extension.ToUpper() == ".RAR")
                {
                    fileInRAR_Zip = cf.GetFilesInRar(compressFileInfo.FullName);
                    result        = cf.RarExtract(compressFileInfo.FullName, targetDirectory.FullName);
                }

                //ถ้าผลการ Extract File เกิดข้อผิดพลาด
                if (!result)
                {
                    res.ErrorMsg = Resources.errorExtractFileLicenseRequestHelper_003;
                    return(res);
                }


                if (fileInRAR_Zip.Count > 0)
                {
                    long count = 0;
                    for (int i = 0; i < fileInRAR_Zip.Count; i++)
                    {
                        string file = fileInRAR_Zip[i].Replace(@"/", @"\");

                        FileInfo fInfo = new FileInfo(Path.GetFullPath(file));

                        if (fInfo.Extension.ToUpper() == ".CSV")
                        {
                            count += 1;
                        }
                    }

                    if (count > 1)
                    {
                        res.ErrorMsg = Resources.errorExamService_046;
                        return(res);
                    }

                    //วนเก็บรายการใน Zip File
                    for (int i = 0; i < fileInRAR_Zip.Count; i++)
                    {
                        //เก็บรายการ Path จริงแปะเข้าไฟล์
                        string file = fileInRAR_Zip[i].Replace(@"/", @"\");

                        //string fullFilePath = tempFolder + @"\" + file;

                        FileInfo fInfo = new FileInfo(Path.GetFullPath(file));
                        if (fInfo.Extension.ToUpper() == ".CSV")
                        {
                            res.DataResponse.TextFilePath = Path.Combine(_targetFullPath, fInfo.Name).Replace(_netDrive, "");
                            res.DataResponse.ExtFile      = fInfo.Extension.ToUpper();
                        }
                        else
                        {
                            string[] ary     = fInfo.Name.Split('.');
                            string   fileExt = fInfo.Extension;
                            string   fName   = ary.Length > 0 ? ary[0] : string.Empty;

                            if (!string.IsNullOrEmpty(fName))
                            {
                                res.DataResponse.AttatchFiles.Add(new DTO.AttachFileDetail
                                {
                                    FileName     = fName,
                                    Extension    = fInfo.Extension,
                                    FullFileName = Path.Combine(_targetFullPath, fInfo.Name),
                                    MapFileName  = Path.Combine(_targetFullPath, fInfo.Name).Replace(_netDrive, ""),
                                    FileTypeCode = fName.Substring(fName.Length - 2)
                                });
                            }
                        }
                    }
                }
            }

            return(res);
        }
コード例 #5
0
ファイル: FileService.svc.cs プロジェクト: ekarincodizm/IAS
 private void ConnectNetDrive()
 {
     this.nasDrive = new NASDrive(netDrive, userNetDrive, passNetDrive);
 }
コード例 #6
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);
        }
コード例 #7
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);
        }
コード例 #8
0
        public static String StartCompressByOicApprove(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;

            DateTime startDate = new DateTime(findDate.Year, findDate.Month, findDate.Day, 0, 0, 0);
            DateTime endDate   = new DateTime(findDate.Year, findDate.Month, findDate.Day, 23, 59, 59);
            //ดึงข้อมูลการเงินจากธนาคารใน Temp ตาม BatchID
            IEnumerable <AG_IAS_LICENSE_D> licenseDs = ctx.AG_IAS_LICENSE_D.
                                                       Where(a => a.OIC_APPROVED_DATE >= startDate &&
                                                             a.OIC_APPROVED_DATE <= endDate);

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



                String whereType = String.Format("_{0}.", imageTypeCode);
                AG_IAS_LICENSE_TYPE_R licenType = ctx.AG_IAS_LICENSE_TYPE_R.Single(l => l.LICENSE_TYPE_CODE == licenH.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));
                AG_IAS_ATTACH_FILE_LICENSE attach = Helpers.GetIASConfigHelper.GetAttachLicensePhoto(ctx, licenD.ID_CARD_NO, licenD.UPLOAD_GROUP_NO);

                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, licenD, licenH, 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, "");
                }
            }
            nasDrive.Dispose();
            return(zipfileName);
        }