コード例 #1
0
ファイル: Program.cs プロジェクト: hlakmal/MissingFiles
        static byte[] GenerateEPF_EVEMP(etf_epf_record tran)
        {
            //Generate EVEMP.TXT File
            StringBuilder evemp = new StringBuilder();

            evemp.Append(tran.etreg.Trim().Substring(0, 1));//ZnCode(1)

            string initialString        = tran.etreg.Trim();
            Regex  nonNumericCharacters = new Regex(@"[^0-9]");
            string numericOnlyString    = nonNumericCharacters.Replace(initialString, String.Empty);

            evemp.Append(numericOnlyString.Trim().PadLeft(6, Convert.ToChar(" ")));                                                                  //Employer Number(6)
            evemp.Append(tran.etfrpd);                                                                                                               //Contribution Year and Month(6)
            evemp.Append("1".PadLeft(2, Convert.ToChar(" ")));                                                                                       //Data Submission Number(1)
            evemp.Append(string.Format("{0:0.00}", Convert.ToDouble(tran.etamt.Trim())).Trim().PadLeft(12, Convert.ToChar(" ")));                    //Total Contribution Amount(12)(11.2)
            evemp.Append(tran.etnomb.Trim().PadLeft(5, Convert.ToChar(" ")));                                                                        //Number of Members contributed for(5)
            evemp.Append("2");                                                                                                                       //Mode of Payment(1)[1=Cheque,2=Cash,3=Money Order,4=Direct Debit]
            evemp.Append((tran.etbkcd + tran.etbrcd.Trim().PadLeft(3, Convert.ToChar("0")) + tran.etacct).Trim().PadRight(20, Convert.ToChar(" "))); //Payment Reference(20) [BankCode(4)BranchCode(3)AccountNumber(Rest)]
            evemp.Append(tran.etadat.Trim().PadLeft(10, Convert.ToChar(" ")));                                                                       //Date of Payment(10)[yyyymmdd]
            evemp.Append(tran.etdcd);                                                                                                                //District office Code

            List <byte> list = new List <byte>();

            foreach (char ch in evemp.ToString().ToCharArray())
            {
                list.Add((byte)((int)ch));
            }

            byte[] buffer = list.ToArray();
            return(buffer);
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: hlakmal/MissingFiles
        static List <etf_epf_record> GetListETF(string filter = "")
        {
            System.Data.Odbc.OdbcConnection l_objConnection = new System.Data.Odbc.OdbcConnection();
            System.Data.Odbc.OdbcCommand    l_objCmd        = new System.Data.Odbc.OdbcCommand();
            System.Data.Odbc.OdbcDataReader l_objRdr        = null;
            l_objConnection.ConnectionString = "DSN=PRODDSN_LIVE;PWD=INTERNET;UID=INTERNET";
            l_objConnection.Open();
            l_objCmd.Connection  = l_objConnection;
            l_objCmd.CommandType = CommandType.Text;

            string sql = string.Empty;

            if (string.IsNullOrEmpty(filter))
            {
                sql = "select etref,etreg,etamt,etpflg,etdate,ettime,etptyp,etfrpd,ettopd,etnomb,etbkcd,etbrcd,etacct,etdcd,etadat,etcopr,ettran from inetprddt1.etp1000 where etdate>='20170801' and etdate<='20170831' and  etref like 'CBCETF%' order by etdate";
            }
            else
            {
                sql = "select etref,etreg,etamt,etpflg,etdate,ettime,etptyp,etfrpd,ettopd,etnomb,etbkcd,etbrcd,etacct,etdcd,etadat,etcopr,ettran from inetprddt1.etp1000 where etdate>='20170801' and etdate<='20170831' and  etref like 'CBCETF%' and etref in " + filter + " order by etdate";
            }

            l_objCmd.CommandText = sql;

            if (l_objRdr != null)
            {
                l_objRdr.Close();
            }
            l_objRdr = l_objCmd.ExecuteReader();

            List <etf_epf_record> list = new List <etf_epf_record>();


            if (l_objRdr.HasRows)
            {
                while (l_objRdr.Read())
                {
                    etf_epf_record file = new etf_epf_record();
                    file.etref  = l_objRdr["etref"].ToString().Trim();
                    file.etreg  = l_objRdr["etreg"].ToString().Trim();
                    file.etamt  = l_objRdr["etamt"].ToString().Trim();
                    file.etpflg = l_objRdr["etpflg"].ToString().Trim();
                    file.etdate = l_objRdr["etdate"].ToString().Trim();
                    file.ettime = l_objRdr["ettime"].ToString().Trim();
                    file.etptyp = l_objRdr["etptyp"].ToString().Trim();
                    file.etfrpd = l_objRdr["etfrpd"].ToString().Trim(); //From Period
                    file.ettopd = l_objRdr["ettopd"].ToString().Trim(); //To Period
                    file.etnomb = l_objRdr["etnomb"].ToString().Trim(); //EMployeed
                    file.etadat = l_objRdr["etadat"].ToString().Trim();
                    file.etcopr = l_objRdr["etcopr"].ToString().Trim();
                    file.ettran = l_objRdr["ettran"].ToString().Trim();
                    list.Add(file);
                }
            }

            return(list);
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: hlakmal/MissingFiles
        static void Main(string[] args)
        {
            //Get Directory Informations of the Root directory of the Default Files upload folder
            //string filter = "('CBCEPF96972','CBCEPF96978','CBCEPF97052','CBCEPF97871','CBCEPF97885','CBCEPF98163','CBCEPF98166')";
            List <etf_epf_record> RefListEPF      = GetListEPF();
            List <etf_epf_record> RefListETF      = GetListETF();
            List <filePath>       AllFilePathsEPF = GetAllFileList(@"D:\EPFETF\Deployments\AUG_2017\AUG_2017_LIVE_ETF");
            List <filePath>       AllFilePathsETF = GetAllFileList(@"D:\EPFETF\Deployments\AUG_2017\AUG_2017_LIVE_ETF");
            int mode = 1; // mode=0 Match reference with file name, mode=1 Match reference with file content


            switch (mode)
            {
            case 0:     // mode=0 Match reference with file name
                //EPF
                foreach (var tran in RefListEPF)
                {
                    List <filePath> has = AllFilePathsEPF.FindAll(file => file.fullPath.Contains(tran.etref));

                    if (has.Count > 0)
                    {
                        etf_epf_record record = tran;
                        record.count = has.Count;
                        foreach (var item in has)
                        {
                            record.files += item.fullPath + ",";
                        }
                        ResultListEPF.Add(record);
                    }
                    else
                    {
                        etf_epf_record record = tran;
                        record.count = has.Count;
                        ResultListEPF.Add(record);
                    }
                }

                //ETF
                foreach (var tran in RefListETF)
                {
                    List <filePath> has = AllFilePathsETF.FindAll(file => file.fullPath.Contains(tran.etref));

                    if (has.Count > 0)
                    {
                        etf_epf_record record = tran;
                        record.count = has.Count;
                        foreach (var item in has)
                        {
                            record.files += item.fullPath + ",";
                        }
                        ResultListETF.Add(record);
                    }
                    else
                    {
                        etf_epf_record record = tran;
                        record.count = has.Count;
                        ResultListETF.Add(record);
                    }
                }
                break;

            case 1:     //mode=1 Match reference with file content

                //EPF
                foreach (var tran in RefListEPF)
                {
                    List <filePath> has = AllFilePathsEPF.FindAll(file => file.fullPath.Contains(tran.etref));

                    if (has.Count > 0)
                    {
                        etf_epf_record record = tran;
                        record.count = has.Count;
                        foreach (var item in has)
                        {
                            if (item.fullPath.Contains("EVEMP"))      //EVEMC CBCEPF  EVEMP
                            {
                                FileStream _fs      = new FileStream(item.fullPath, FileMode.Open, FileAccess.Read);
                                Byte[]     fileByte = new byte[_fs.Length];
                                _fs.Read(fileByte, 0, System.Convert.ToInt32(_fs.Length));

                                try
                                {
                                    //string[] result = GetEpfFileInformation(_fs, tran.etreg, tran.etfrpd.Substring(0, 4), tran.etfrpd.Substring(4, 2), tran.etamt, tran.etnomb);
                                    string[] result = GetEpfPaymentFileInformation(_fs, tran.etreg, tran.etfrpd, tran.etamt, tran.etnomb);
                                    record.summary += result[0] + "^" + result[1] + ",";
                                }
                                catch (Exception ex)
                                {
                                    record.errors += ex.Message + "^";
                                }
                                record.files += item.fullPath + "^";
                                _fs.Close();
                                _fs.Dispose();
                            }
                            //else
                            //{
                            //    record.files += item.fullPath + "^";
                            //}
                        }

                        ResultListEPF.Add(record);
                    }
                    else
                    {
                        etf_epf_record record = tran;
                        record.count = has.Count;
                        ResultListEPF.Add(record);
                    }
                }

                //ETF
                foreach (var tran in RefListETF)
                {
                    List <filePath> has = AllFilePathsETF.FindAll(file => file.fullPath.Contains(tran.etref));

                    if (has.Count > 0)
                    {
                        etf_epf_record record = tran;
                        record.count = has.Count;
                        foreach (var item in has)
                        {
                            FileStream _fs      = new FileStream(item.fullPath, FileMode.Open, FileAccess.Read);
                            Byte[]     fileByte = new byte[_fs.Length];
                            _fs.Read(fileByte, 0, System.Convert.ToInt32(_fs.Length));

                            try
                            {
                                string[] result = GetEtfFileInformation(_fs, tran.etreg, tran.etfrpd + tran.ettopd, tran.etamt, tran.etnomb, 1);
                                record.summary += result[0] + "^" + result[1] + ",";
                            }
                            catch (Exception ex)
                            {
                                record.errors += ex.Message + "^";
                            }

                            record.files += item.fullPath + "^";

                            _fs.Close();
                            _fs.Dispose();
                        }
                        ResultListETF.Add(record);
                    }
                    else
                    {
                        etf_epf_record record = tran;
                        record.count = has.Count;
                        ResultListETF.Add(record);
                    }
                }

                break;
            }


            var logPath = @"D:\EPFETF\Deployments\AUG_2017\AUG_2017_LIVE_ETF";

            logPath = logPath + "/" + System.DateTime.Now.ToString("yyyyMMdd HHmmss") + "EPF.csv";
            if (string.IsNullOrEmpty(logPath))
            {
                return;
            }
            var fs = new FileStream(logPath, FileMode.Append, FileAccess.Write, FileShare.ReadWrite);
            var sw = new StreamWriter(fs);

            foreach (var item in ResultListEPF)
            {
                sw.WriteLine(item.etref + "," + item.etreg + "," + item.count + "," + item.etnomb + "," + item.etamt + "," + item.etdate + "," + item.ettime + "," + item.etpflg + "," + item.etptyp + "," + item.etcopr + "," + item.summary + "," + item.files + "," + item.errors);
                Console.WriteLine(item.etref + ":" + item.count.ToString());
            }

            sw.Flush();
            sw.Close(); sw.Dispose();
            fs.Close(); fs.Dispose();


            logPath = @"D:\EPFETF\Deployments\AUG_2017\AUG_2017_LIVE_ETF";
            logPath = logPath + "/" + System.DateTime.Now.ToString("yyyyMMdd HHmmss") + "ETF.csv";
            if (string.IsNullOrEmpty(logPath))
            {
                return;
            }
            var fs1 = new FileStream(logPath, FileMode.Append, FileAccess.Write, FileShare.ReadWrite);
            var sw1 = new StreamWriter(fs1);

            foreach (var item in ResultListETF)
            {
                sw1.WriteLine(item.etref + "," + item.etreg + "," + item.count + "," + item.etnomb + "," + item.etamt + "," + item.etdate + "," + item.ettime + "," + item.etpflg + "," + item.etptyp + "," + item.etcopr + "," + item.summary + "," + item.files + "," + item.errors);
                Console.WriteLine(item.etref + ":" + item.count.ToString());
            }

            sw1.Flush();
            sw1.Close(); sw1.Dispose();

            fs1.Close(); fs1.Dispose();



            //foreach (var item in RefList)
            //{
            //    DirSearch(@"D:\EPFETF\EPFETFdata\EPFETFdata", item);
            //    Console.WriteLine(item.etref + ":" + ResultList.Count.ToString());
            //}
            //Console.WriteLine(ResultList.Count);
        }