Пример #1
0
    public void Begin(string sKind0)
    {
        string[] sArr;
        using (NSysDB.NTSQL.SQL1 query = new NSysDB.NTSQL.SQL1())
        { query.ReturnArr(out sArr); }
        string sFPathN      = sArr[0];
        string sFPathP      = sArr[1];
        string sFPathY      = sArr[2];
        string sPaPartition = sArr[3];

        //Console.WriteLine(sFPathN);

        //抓 B0401D*.* 的所有檔案
        foreach (string OkFName in System.IO.Directory.GetFileSystemEntries(sFPathN, sKind0 + "*.*"))
        {
            Console.WriteLine("檔案名稱1:" + OkFName);
            string sPgSN = DateTime.Now.ToString("yyyyMMddHHmmssfff");

            try
            {
                System.IO.File.Move(OkFName, OkFName.Replace(sFPathN, sFPathP));
                string OkFNameP = OkFName.Replace(sFPathN, sFPathP);

                string line    = "";
                int    counter = 0;

                using (System.IO.StreamReader txtFile = new System.IO.StreamReader(OkFNameP, System.Text.Encoding.Default))
                {
                    Console.WriteLine("檔案名稱2:" + OkFNameP);

                    using (NSysDB.NTSQL.SQL1 query = new NSysDB.NTSQL.SQL1())
                    {
                        //開始匯入
                        query.GoLogsAll(sPgSN, System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName, OkFName, "", "", 1);
                    }

                    while ((line = txtFile.ReadLine()) != null)
                    {
                        if (line.Trim() != "")
                        {
                            //Console.WriteLine(line);
                            string[] CutS  = { sPaPartition };
                            string[] charA = line.Split(CutS, StringSplitOptions.None);

                            //字串尾要分號//共13個分號
                            if (charA.Length == 13)
                            {
                                Console.WriteLine("折讓證明單號碼:" + charA[0].ToString());
                                //for (int i = 0; i < charA.Length-1; i++)
                                //{
                                //    Console.WriteLine("Index : {0}, 字串 : {1}", (i + 1), charA[i]);
                                //}

                                using (NSysDB.NTSQL.SQL1 query = new NSysDB.NTSQL.SQL1())
                                {
                                    try
                                    {
                                        if (query.Kind1SelectTbl3("B0401DSN", "MAllowanceNumber='" + charA[0].ToString() + "' And DAllowanceSequenceNumber='" + charA[10].ToString() + "'", "B0401D") == 0)
                                        {
                                            if (charA[1].ToString().Trim() != "" && charA[2].ToString().Trim() != "")
                                            {
                                                System.Collections.Hashtable data = new System.Collections.Hashtable();
                                                data["MAllowanceNumber"]        = charA[0].ToString().Trim();
                                                data["DOriginalInvoiceDate"]    = charA[1].ToString().Trim();
                                                data["DOriginalInvoiceNumber"]  = charA[2].ToString().Trim();
                                                data["DOriginalSequenceNumber"] = charA[3].ToString().Trim();
                                                data["DOriginalDescription"]    = charA[4].ToString().Trim();
                                                data["DQuantity"]  = charA[5].ToString().Trim();
                                                data["DUnit"]      = charA[6].ToString().Trim();
                                                data["DUnitPrice"] = charA[7].ToString().Trim();
                                                data["DAmount"]    = charA[8].ToString().Trim();
                                                data["DTax"]       = charA[9].ToString().Trim();

                                                data["DAllowanceSequenceNumber"] = charA[10].ToString().Trim();
                                                data["DTaxType"] = charA[11].ToString().Trim();

                                                data["TxFileNmae"] = OkFName.ToString().Trim();
                                                query.InsertDataNonKey("B0401D", data);
                                                data = null;
                                            }
                                            else
                                            {
                                                query.GoLogsAll(sPgSN, System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName, OkFName, "[MAllowanceNumber:" + charA[0].ToString().Trim() + "][DAllowanceSequenceNumber:" + charA[10].ToString().Trim() + "]", (counter + 1).ToString(), 17);

                                                query.GoToSTemp("B0401D", " MAllowanceNumber='" + charA[0].ToString() + "' ");
                                                query.GoToSTemp("B0401H", " MAllowanceNumber='" + charA[0].ToString() + "' ");
                                            }
                                        }
                                        else
                                        {
                                            query.GoLogsAll(sPgSN, System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName, OkFName, "[MAllowanceNumber:" + charA[0].ToString().Trim() + "][DAllowanceSequenceNumber:" + charA[10].ToString().Trim() + "]", (counter + 1).ToString(), 16);

                                            query.GoToSTemp("B0401D", " MAllowanceNumber='" + charA[0].ToString() + "' ");
                                            query.GoToSTemp("B0401H", " MAllowanceNumber='" + charA[0].ToString() + "' ");
                                        }
                                    }
                                    catch (Exception ex)
                                    {
                                        query.GoLogsAll(sPgSN, System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName, OkFName, ex.ToString(), (counter + 1).ToString(), 11);

                                        query.GoToSTemp("B0401D", " MAllowanceNumber='" + charA[0].ToString() + "' ");
                                        query.GoToSTemp("B0401H", " MAllowanceNumber='" + charA[0].ToString() + "' ");
                                    }
                                }
                            }
                            else
                            {
                                using (NSysDB.NTSQL.SQL1 query = new NSysDB.NTSQL.SQL1())
                                {
                                    query.GoLogsAll(sPgSN, System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName, OkFName, "", (counter + 1).ToString(), 12);
                                }
                            }

                            Console.WriteLine("間隔數:" + charA.Length.ToString());
                            counter++;
                        }
                    }

                    using (NSysDB.NTSQL.SQL1 query = new NSysDB.NTSQL.SQL1())
                    {
                        //結束匯入
                        query.GoLogsAll(sPgSN, System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName, OkFName, "", "", 2);
                    }
                }
                Console.WriteLine("筆數:" + counter.ToString());

                System.IO.File.Move(OkFNameP, OkFNameP.Replace(sFPathP, sFPathY).Replace(".txt", "_" + sPgSN + ".txt"));
            }
            catch (Exception ex)
            {
                using (NSysDB.NTSQL.SQL1 query = new NSysDB.NTSQL.SQL1())
                {
                    query.GoLogsAll(sPgSN, System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName, OkFName, "此檔案已存於:" + sFPathP + " [" + ex + "]", "", 13);
                }
            }
            //try
            //{
            //    //檔案已存在的FileMove
            //    Console.WriteLine(OkFName);
            //    Console.WriteLine(OkFName.Replace(sFPathN, sFPathY));

            //    System.IO.File.Move(OkFName, OkFName.Replace(sFPathN, sFPathY) + sPgSN);
            //    //Exception未處理,檔案已存在時,無法建立該檔案。
            //}
            //catch (Exception ex)
            //{
            //    Console.WriteLine("檔案已存在!!");
            //    using (NSysDB.NTSQL.SQL1 query = new NSysDB.NTSQL.SQL1())
            //    {
            //        query.GoLogsAll(sPgSN, System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName, OkFName, ex.ToString(), "", 13);
            //    }
            //}
        }

        //}
        //catch (Exception ex)
        //{
        //    using (NSysDB.NTSQL.SQL1 query = new NSysDB.NTSQL.SQL1())
        //    {
        //        // query.GoException(sPgSN, ex.ToString(), "[" + GetType().Assembly.Location + "] [" + System.Reflection.MethodInfo.GetCurrentMethod().ToString() + "]");
        //        query.GoLogsAll(sPgSN, System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName, "", ex.ToString(), "", 14);
        //    }
        //}
    }
Пример #2
0
    public void Begin(string sKind0, string identityKey)
    {
        Dictionary <string, List <string> > pdfNumList = new Dictionary <string, List <string> >();

        //try
        //{
        string[] sArr;
        using (NSysDB.NTSQL.SQL1 query = new NSysDB.NTSQL.SQL1())
        { query.ReturnArr(out sArr); }
        string sFPathN      = sArr[0];
        string sFPathP      = sArr[1];
        string sFPathY      = sArr[2];
        string sPaPartition = sArr[3];
        //Console.WriteLine(sFPathN);
        string sKind0UpperCase = sKind0.ToUpper();

        //抓 B0401H*.* 的所有檔案
        foreach (string OkFName in System.IO.Directory.GetFileSystemEntries(sFPathN, sKind0 + "*.*"))
        {
            Console.WriteLine("檔案名稱1:" + OkFName);
            string sPgSN = DateTime.Now.ToString("yyyyMMddHHmmssfff");

            try
            {
                System.IO.File.Move(OkFName, OkFName.Replace(sFPathN, sFPathP));
                string OkFNameP = OkFName.Replace(sFPathN, sFPathP);

                string line    = "";
                int    counter = 0;

                using (System.IO.StreamReader txtFile = new System.IO.StreamReader(OkFNameP, System.Text.Encoding.Default))
                {
                    Console.WriteLine("檔案名稱2:" + OkFNameP);

                    using (NSysDB.NTSQL.SQL1 query = new NSysDB.NTSQL.SQL1())
                    {
                        //開始匯入
                        query.GoLogsAll(sPgSN, System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName, OkFName, "", "", 1);
                    }

                    while ((line = txtFile.ReadLine()) != null)
                    {
                        if (line.Trim() != "")
                        {
                            //Console.WriteLine(line);
                            string[] CutS  = { sPaPartition };
                            string[] charA = line.Split(CutS, StringSplitOptions.None);

                            //字串尾要分號//共24個分號
                            if (charA.Length == 24)
                            {
                                Console.WriteLine("折讓證明單號碼:" + charA[0].ToString());
                                //for (int i = 0; i < charA.Length-1; i++)
                                //{
                                //    Console.WriteLine("Index : {0}, 字串 : {1}", (i + 1), charA[i]);
                                //}

                                using (NSysDB.NTSQL.SQL1 query = new NSysDB.NTSQL.SQL1())
                                {
                                    try
                                    {
                                        if (query.Kind1SelectTbl3("D0401SN", "MAllowanceNumber='" + charA[0].ToString() + "'", "D0401H") == 0)
                                        {
                                            System.Collections.Hashtable data = new System.Collections.Hashtable();

                                            data["MAllowanceNumber"] = charA[0].ToString().Trim();
                                            data["MAllowanceDate"]   = charA[1].ToString().Trim();

                                            data["MSIdentifier"]      = charA[2].ToString().Trim();
                                            data["MSName"]            = charA[3].ToString().Trim();
                                            data["MSAddress"]         = charA[4].ToString().Trim();
                                            data["MSPersonInCharge"]  = charA[5].ToString().Trim();
                                            data["MSTelephoneNumber"] = charA[6].ToString().Trim();
                                            data["MSFacsimileNumber"] = charA[7].ToString().Trim();
                                            data["MSEmailAddress"]    = charA[8].ToString().Trim();
                                            data["MSCustomerNumber"]  = charA[9].ToString().Trim();
                                            data["MSRoleRemark"]      = charA[10].ToString().Trim();

                                            data["MBIdentifier"]      = charA[11].ToString().Trim();
                                            data["MBName"]            = charA[12].ToString().Trim();
                                            data["MBAddress"]         = charA[13].ToString().Trim();
                                            data["MBPersonInCharge"]  = charA[14].ToString().Trim();
                                            data["MBTelephoneNumber"] = charA[15].ToString().Trim();
                                            data["MBFacsimileNumber"] = charA[16].ToString().Trim();
                                            data["MBEmailAddress"]    = charA[17].ToString().Trim();
                                            data["MBCustomerNumber"]  = charA[18].ToString().Trim();
                                            data["MBRoleRemark"]      = charA[19].ToString().Trim();

                                            data["MAllowanceType"] = charA[20].ToString().Trim();
                                            data["ATaxAmount"]     = charA[21].ToString().Trim();
                                            data["ATotalAmount"]   = charA[22].ToString().Trim();

                                            data["TxFileNmae"] = OkFName.ToString().Trim();
                                            query.InsertDataNonKey("D0401H", data);
                                            data = null;
                                            if (!pdfNumList.ContainsKey(sKind0UpperCase))
                                            {
                                                pdfNumList[sKind0UpperCase] = new List <string>();
                                            }
                                            pdfNumList[sKind0UpperCase].Add(charA[0].ToString().Trim());
                                        }
                                        else
                                        {
                                            query.GoLogsAll(sPgSN, System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName, OkFName, "[折讓證明單號碼:" + charA[0].ToString() + "][此折讓證明單號碼已存在!!", (counter + 1).ToString(), 11);
                                        }
                                    }
                                    catch (Exception ex)
                                    {
                                        query.GoLogsAll(sPgSN, System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName, OkFName, ex.ToString(), (counter + 1).ToString(), 11);
                                    }
                                }
                            }
                            else
                            {
                                using (NSysDB.NTSQL.SQL1 query = new NSysDB.NTSQL.SQL1())
                                {
                                    query.GoLogsAll(sPgSN, System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName, OkFName, "", (counter + 1).ToString(), 12);
                                }
                            }

                            Console.WriteLine("間隔數:" + charA.Length.ToString());
                            counter++;
                        }
                    }

                    using (NSysDB.NTSQL.SQL1 query = new NSysDB.NTSQL.SQL1())
                    {
                        //結束匯入
                        query.GoLogsAll(sPgSN, System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName, OkFName, "", "", 2);
                    }
                }
                Console.WriteLine("筆數:" + counter.ToString());

                System.IO.File.Move(OkFNameP, OkFNameP.Replace(sFPathP, sFPathY).Replace(".txt", "_" + sPgSN + ".txt"));
            }
            catch (Exception ex)
            {
                using (NSysDB.NTSQL.SQL1 query = new NSysDB.NTSQL.SQL1())
                {
                    query.GoLogsAll(sPgSN, System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName, OkFName, "此檔案已存於:" + sFPathP + " [" + ex + "]", "", 13);
                }
            }

            //try
            //{
            //    //檔案已存在的FileMove
            //    Console.WriteLine(OkFName);
            //    Console.WriteLine(OkFName.Replace(sFPathN, sFPathY));

            //    System.IO.File.Move(OkFName, OkFName.Replace(sFPathN, sFPathY) + sPgSN);
            //    //Exception未處理,檔案已存在時,無法建立該檔案。
            //}
            //catch (Exception ex)
            //{
            //    Console.WriteLine("檔案已存在!!");
            //    using (NSysDB.NTSQL.SQL1 query = new NSysDB.NTSQL.SQL1())
            //    {
            //        query.GoLogsAll(sPgSN, System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName, OkFName, ex.ToString(), "", 13);
            //    }
            //}
        }
        using (NSysDB.NTSQL.SQL1 query = new NSysDB.NTSQL.SQL1())
        {
            foreach (var inv in pdfNumList)
            {
                foreach (var item in inv.Value)
                {
                    Hashtable hashTable = new Hashtable();
                    hashTable["PRINT_METHOD"]   = inv.Key;
                    hashTable["PRINT_EINV_NUM"] = item;
                    //hashTable["MAKE_FILE_DATE"] = DateTime.UtcNow;
                    hashTable["WRITE_DATE"] = DateTime.UtcNow;
                    hashTable["IDEN_KEY"]   = identityKey;
                    string insertMsg = query.InsertDataNonKey("PRINT_TEMP", hashTable);
                }
            }
        }
        //}
        //catch (Exception ex)
        //{
        //    using (NSysDB.NTSQL.SQL1 query = new NSysDB.NTSQL.SQL1())
        //    {
        //        // query.GoException(sPgSN, ex.ToString(), "[" + GetType().Assembly.Location + "] [" + System.Reflection.MethodInfo.GetCurrentMethod().ToString() + "]");
        //        query.GoLogsAll(sPgSN, System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName, "", ex.ToString(), "", 14);
        //    }
        //}
    }
Пример #3
0
    public void Begin(string sKind0)
    {
        //try
        //{
        string[] sArr;
        using (NSysDB.NTSQL.SQL1 query = new NSysDB.NTSQL.SQL1())
        { query.ReturnArr(out sArr); }
        string sFPathN      = sArr[0];
        string sFPathP      = sArr[1];
        string sFPathY      = sArr[2];
        string sPaPartition = sArr[3];

        //Console.WriteLine(sFPathN);

        //抓 D0501*.* 的所有檔案
        foreach (string OkFName in System.IO.Directory.GetFileSystemEntries(sFPathN, sKind0 + "*.*"))
        {
            Console.WriteLine("檔案名稱1:" + OkFName);
            string sPgSN = DateTime.Now.ToString("yyyyMMddHHmmssfff");

            try
            {
                System.IO.File.Move(OkFName, OkFName.Replace(sFPathN, sFPathP));
                string OkFNameP = OkFName.Replace(sFPathN, sFPathP);

                string line    = "";
                int    counter = 0;

                using (System.IO.StreamReader txtFile = new System.IO.StreamReader(OkFNameP, System.Text.Encoding.Default))
                {
                    Console.WriteLine("檔案名稱2:" + OkFNameP);

                    using (NSysDB.NTSQL.SQL1 query = new NSysDB.NTSQL.SQL1())
                    {
                        //開始匯入
                        query.GoLogsAll(sPgSN, System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName, OkFName, "", "", 1);
                    }

                    while ((line = txtFile.ReadLine()) != null)
                    {
                        if (line.Trim() != "")
                        {
                            //Console.WriteLine(line);
                            string[] CutS  = { sPaPartition };
                            string[] charA = line.Split(CutS, StringSplitOptions.None);

                            //字串尾要分號//共9個分號
                            if (charA.Length == 9)
                            {
                                Console.WriteLine("作廢折讓證明單號碼:" + charA[0].ToString());
                                //for (int i = 0; i < charA.Length-1; i++)
                                //{
                                //    Console.WriteLine("Index : {0}, 字串 : {1}", (i + 1), charA[i]);
                                //}

                                using (NSysDB.NTSQL.SQL1 query = new NSysDB.NTSQL.SQL1())
                                {
                                    try
                                    {
                                        if (query.Kind1SelectTbl3("D0501SN", "CancelAllowanceNumber='" + charA[0].ToString() + "'", "D0501") == 0)
                                        {
                                            System.Collections.Hashtable data = new System.Collections.Hashtable();

                                            data["CancelAllowanceNumber"] = charA[0].ToString().Trim();
                                            data["AllowanceDate"]         = charA[1].ToString().Trim();
                                            data["BuyerId"]    = charA[2].ToString().Trim();
                                            data["SellerId"]   = charA[3].ToString().Trim();
                                            data["CancelDate"] = charA[4].ToString().Trim();

                                            data["CancelTime"]   = charA[5].ToString().Trim();
                                            data["CancelReason"] = charA[6].ToString().Trim();
                                            data["Remark"]       = charA[7].ToString().Trim();

                                            data["TxFileNmae"] = OkFName.ToString().Trim();
                                            query.InsertDataNonKey("D0501", data);
                                            data = null;
                                        }
                                        else
                                        {
                                            query.GoLogsAll(sPgSN, System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName, OkFName, "[折讓證明單號碼:" + charA[0].ToString() + "][此折讓證明單已存在!!", (counter + 1).ToString(), 11);
                                        }
                                    }
                                    catch (Exception ex)
                                    {
                                        query.GoLogsAll(sPgSN, System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName, OkFName, "[折讓證明單號碼:" + charA[0].ToString() + "][字串有例外錯誤!!]" + ex.ToString(), (counter + 1).ToString(), 11);
                                    }
                                }
                            }
                            else
                            {
                                using (NSysDB.NTSQL.SQL1 query = new NSysDB.NTSQL.SQL1())
                                {
                                    query.GoLogsAll(sPgSN, System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName, OkFName, "", (counter + 1).ToString(), 12);
                                }
                            }

                            Console.WriteLine("間隔數:" + charA.Length.ToString());
                            counter++;
                        }
                    }

                    using (NSysDB.NTSQL.SQL1 query = new NSysDB.NTSQL.SQL1())
                    {
                        //結束匯入
                        query.GoLogsAll(sPgSN, System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName, OkFName, "", "", 2);
                    }
                }
                Console.WriteLine("筆數:" + counter.ToString());

                System.IO.File.Move(OkFNameP, OkFNameP.Replace(sFPathP, sFPathY).Replace(".txt", "_" + sPgSN + ".txt"));
            }
            catch (Exception ex)
            {
                using (NSysDB.NTSQL.SQL1 query = new NSysDB.NTSQL.SQL1())
                {
                    query.GoLogsAll(sPgSN, System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName, OkFName, "此檔案已存於:" + sFPathP + " [" + ex + "]", "", 13);
                }
            }
        }
    }
Пример #4
0
    public void Begin(string sKind0, string identityKey)
    {
        Dictionary <string, List <string> > pdfNumList = new Dictionary <string, List <string> >();

        string[] sArr;
        using (NSysDB.NTSQL.SQL1 query = new NSysDB.NTSQL.SQL1())
        { query.ReturnArr(out sArr); }
        string sFPathN      = sArr[0];
        string sFPathP      = sArr[1];
        string sFPathY      = sArr[2];
        string sPaPartition = sArr[3];
        //Console.WriteLine(sFPathN);
        string sKind0UpperCase = sKind0.ToUpper();

        //抓 A0401H*.* 的所有檔案
        foreach (string OkFName in System.IO.Directory.GetFileSystemEntries(sFPathN, sKind0 + "*.*"))
        {
            Console.WriteLine("檔案名稱1:" + OkFName);
            string sPgSN = DateTime.Now.ToString("yyyyMMddHHmmssfff");

            //try
            //{
            System.IO.File.Move(OkFName, OkFName.Replace(sFPathN, sFPathP));
            string OkFNameP = OkFName.Replace(sFPathN, sFPathP);

            string line    = "";
            int    counter = 0;

            using (System.IO.StreamReader txtFile = new System.IO.StreamReader(OkFNameP, System.Text.Encoding.Default))
            {
                Console.WriteLine("檔案名稱2:" + OkFNameP);

                using (NSysDB.NTSQL.SQL1 query = new NSysDB.NTSQL.SQL1())
                {
                    //Log_開始匯入
                    query.GoLogsAll(sPgSN, System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName, OkFName, "", "", 1);
                }



                while ((line = txtFile.ReadLine()) != null)
                {
                    if (line.Trim() != "")
                    {
                        //Console.WriteLine(line);

                        //string[] charA = line.Split(';');
                        //string[] CutS = { ";" };
                        string[] CutS  = { sPaPartition };
                        string[] charA = line.Split(CutS, StringSplitOptions.None);

                        //字串尾要分號//共48個分號
                        if (charA.Length == 48)
                        {
                            Console.WriteLine("發票號碼:" + charA[0].ToString());
                            //for (int i = 0; i < charA.Length-1; i++)
                            //{
                            //    Console.WriteLine("Index : {0}, 字串 : {1}", (i + 1), charA[i]);
                            //}

                            using (NSysDB.NTSQL.SQL1 query = new NSysDB.NTSQL.SQL1())
                            {
                                //try
                                //{

                                if (query.Kind1SelectTbl3("A0401SN", "MInvoiceNumber='" + charA[0].ToString() + "'", "A0401H") == 0)
                                {
                                    if (charA[12].ToString().Trim() != "0000000000")
                                    {
                                        if (charA[13].ToString().Trim() != "0000")
                                        {
                                            int n;
                                            if (int.TryParse(charA[36].ToString().Trim(), out n))
                                            {
                                                if (int.TryParse(charA[37].ToString().Trim(), out n))
                                                {
                                                    if (int.TryParse(charA[38].ToString().Trim(), out n))
                                                    {
                                                        if (int.TryParse(charA[41].ToString().Trim(), out n))
                                                        {
                                                            if (int.TryParse(charA[42].ToString().Trim(), out n))
                                                            {
                                                                if (int.TryParse(charA[43].ToString().Trim(), out n))
                                                                {
                                                                    System.Collections.Hashtable data = new System.Collections.Hashtable();

                                                                    //if (charA[12].ToString().Trim() == "0000000000")
                                                                    //{ data["ACKind"] = "C0401H"; }
                                                                    //else
                                                                    //{ data["ACKind"] = "A0401H"; }
                                                                    //data["ACKind"] = sKind0.ToUpper().Substring(0, 6);

                                                                    data["MInvoiceNumber"] = charA[0].ToString().Trim();
                                                                    data["MInvoiceDate"]   = charA[1].ToString().Trim();
                                                                    data["MInvoiceTime"]   = charA[2].ToString().Trim();

                                                                    data["MSIdentifier"]      = charA[3].ToString().Trim();
                                                                    data["MSName"]            = charA[4].ToString().Trim();
                                                                    data["MSAddress"]         = charA[5].ToString().Trim();
                                                                    data["MSPersonInCharge"]  = charA[6].ToString().Trim();
                                                                    data["MSTelephoneNumber"] = charA[7].ToString().Trim();
                                                                    data["MSFacsimileNumber"] = charA[8].ToString().Trim();
                                                                    data["MSEmailAddress"]    = charA[9].ToString().Trim();
                                                                    data["MSCustomerNumber"]  = charA[10].ToString().Trim();
                                                                    data["MSRoleRemark"]      = charA[11].ToString().Trim();

                                                                    data["MBIdentifier"]      = charA[12].ToString().Trim();
                                                                    data["MBName"]            = charA[13].ToString().Trim();
                                                                    data["MBAddress"]         = charA[14].ToString().Trim();
                                                                    data["MBPersonInCharge"]  = charA[15].ToString().Trim();
                                                                    data["MBTelephoneNumber"] = charA[16].ToString().Trim();
                                                                    data["MBFacsimileNumber"] = charA[17].ToString().Trim();
                                                                    data["MBEmailAddress"]    = charA[18].ToString().Trim();
                                                                    data["MBCustomerNumber"]  = charA[19].ToString().Trim();
                                                                    data["MBRoleRemark"]      = charA[20].ToString().Trim();

                                                                    data["MCheckNumber"]          = charA[21].ToString().Trim();
                                                                    data["MBuyerRemark"]          = charA[22].ToString().Trim();
                                                                    data["MMainRemark"]           = charA[23].ToString().Trim();
                                                                    data["MCustomsClearanceMark"] = charA[24].ToString().Trim();
                                                                    data["MCategory"]             = charA[25].ToString().Trim();
                                                                    data["MRelateNumber"]         = charA[26].ToString().Trim();
                                                                    data["MInvoiceType"]          = charA[27].ToString().Trim();
                                                                    data["MGroupMark"]            = charA[28].ToString().Trim();
                                                                    data["MDonateMark"]           = charA[29].ToString().Trim();
                                                                    data["MCarrierType"]          = charA[30].ToString().Trim();
                                                                    data["MCarrierId1"]           = charA[31].ToString().Trim();
                                                                    data["MCarrierId2"]           = charA[32].ToString().Trim();
                                                                    data["MPrintMark"]            = charA[33].ToString().Trim();
                                                                    data["MNPOBAN"]       = charA[34].ToString().Trim();
                                                                    data["MRandomNumber"] = charA[35].ToString().Trim();

                                                                    data["ASalesAmount"]        = charA[36].ToString().Trim();
                                                                    data["AFreeTaxSalesAmount"] = charA[37].ToString().Trim();
                                                                    data["AZeroTaxSalesAmount"] = charA[38].ToString().Trim();
                                                                    data["ATaxType"]            = charA[39].ToString().Trim();
                                                                    data["ATaxRate"]            = charA[40].ToString().Trim();
                                                                    data["ATaxAmount"]          = charA[41].ToString().Trim();
                                                                    data["ATotalAmount"]        = charA[42].ToString().Trim();
                                                                    data["ADiscountAmount"]     = charA[43].ToString().Trim();

                                                                    data["AOriginalCurrencyAmount"] = charA[44].ToString().Trim();
                                                                    data["AExchangeRate"]           = charA[45].ToString().Trim();
                                                                    data["ACurrency"] = charA[46].ToString().Trim();

                                                                    data["TxFileNmae"] = OkFName.ToString().Trim();
                                                                    query.InsertDataNonKey("A0401H", data);
                                                                    data = null;
                                                                    if (!pdfNumList.ContainsKey(sKind0UpperCase))
                                                                    {
                                                                        pdfNumList[sKind0UpperCase] = new List <string>();
                                                                    }
                                                                    pdfNumList[sKind0UpperCase].Add(charA[0].ToString());
                                                                }
                                                                else
                                                                {
                                                                    query.GoLogsAll(sPgSN, System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName, OkFName, "[發票號碼:" + charA[0].ToString() + "][ADiscountAmount要>=0且不能有小數]", (counter + 1).ToString(), 11);
                                                                }
                                                            }
                                                            else
                                                            {
                                                                query.GoLogsAll(sPgSN, System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName, OkFName, "[發票號碼:" + charA[0].ToString() + "][ATotalAmount要>=0且不能有小數]", (counter + 1).ToString(), 11);
                                                            }
                                                        }
                                                        else
                                                        {
                                                            query.GoLogsAll(sPgSN, System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName, OkFName, "[發票號碼:" + charA[0].ToString() + "][ATaxAmount要>=0且不能有小數]", (counter + 1).ToString(), 11);
                                                        }
                                                    }
                                                    else
                                                    {
                                                        query.GoLogsAll(sPgSN, System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName, OkFName, "[發票號碼:" + charA[0].ToString() + "][AZeroTaxSalesAmount要>=0且不能有小數]", (counter + 1).ToString(), 11);
                                                    }
                                                }
                                                else
                                                {
                                                    query.GoLogsAll(sPgSN, System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName, OkFName, "[發票號碼:" + charA[0].ToString() + "][AFreeTaxSalesAmount要>=0且不能有小數]", (counter + 1).ToString(), 11);
                                                }
                                            }
                                            else
                                            {
                                                query.GoLogsAll(sPgSN, System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName, OkFName, "[發票號碼:" + charA[0].ToString() + "][ASalesAmount要>=0且不能有小數]", (counter + 1).ToString(), 11);
                                            }
                                        }
                                        else
                                        {
                                            query.GoLogsAll(sPgSN, System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName, OkFName, "[發票號碼:" + charA[0].ToString() + "][買方營業人名稱須<>0000]", (counter + 1).ToString(), 11);
                                        }
                                    }
                                    else
                                    {
                                        query.GoLogsAll(sPgSN, System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName, OkFName, "[發票號碼:" + charA[0].ToString() + "][買方營業人統一編號須<>0000000000]", (counter + 1).ToString(), 11);
                                    }
                                }
                                else
                                {
                                    query.GoLogsAll(sPgSN, System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName, OkFName, "[發票號碼:" + charA[0].ToString() + "][此發票號碼已存在!!", (counter + 1).ToString(), 11);
                                }
                                //}
                                //catch (Exception ex)
                                //{
                                //    query.GoLogsAll(sPgSN, System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName, OkFName, "[發票號碼:" + charA[0].ToString() + "][字串有例外錯誤!!]" + ex.ToString(), (counter + 1).ToString(), 11);
                                //}
                            }
                        }
                        else
                        {
                            using (NSysDB.NTSQL.SQL1 query = new NSysDB.NTSQL.SQL1())
                            {
                                query.GoLogsAll(sPgSN, System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName, OkFName, "", (counter + 1).ToString(), 12);
                            }
                        }

                        Console.WriteLine("間隔數:" + charA.Length.ToString());

                        counter++;
                    }
                }

                //結束匯入
                using (NSysDB.NTSQL.SQL1 query = new NSysDB.NTSQL.SQL1())
                {
                    query.GoLogsAll(sPgSN, System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName, OkFName, "", "", 2);
                }
            }

            Console.WriteLine("筆數:" + counter.ToString());


            System.IO.File.Move(OkFNameP, OkFNameP.Replace(sFPathP, sFPathY).Replace(".txt", "_" + sPgSN + ".txt"));

            //}
            //catch (Exception ex)
            //{
            //    using (NSysDB.NTSQL.SQL1 query = new NSysDB.NTSQL.SQL1())
            //    {
            //        query.GoLogsAll(sPgSN, System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName, OkFName, "此檔案已存於:" + sFPathP + " [" + ex + "]", "", 13);
            //    }
            //}
        }
        using (NSysDB.NTSQL.SQL1 query = new NSysDB.NTSQL.SQL1())
        {
            foreach (var inv in pdfNumList)
            {
                foreach (var item in inv.Value)
                {
                    Hashtable hashTable = new Hashtable();
                    hashTable["PRINT_METHOD"]   = inv.Key;
                    hashTable["PRINT_EINV_NUM"] = item;
                    //hashTable["MAKE_FILE_DATE"] = DateTime.UtcNow;
                    hashTable["WRITE_DATE"] = DateTime.UtcNow;
                    hashTable["IDEN_KEY"]   = identityKey;
                    string insertMsg = query.InsertDataNonKey("PRINT_TEMP", hashTable);
                }
            }
        }
        //Console.ReadLine();
    }